Linux高性能服务器编程笔记 --Chapter4 HTTP代理服务器

分类:正向代理服务商、反向代理服务器和透明代理服务器

正向代理服务器:要求客户端自己设置代理服务器地址。客户的每次请求都将直接发送到该代理服务器,并由代理服务器来请求资源。

反向代理服务器:反向代理被设置在服务器端,因而客户端无需进行任何设置。反向代理指用代理服务器接受Internet上的连接请求,然后将请求转发给内部网络上的服务器,内部服务器将得到的结构返回客户端。

各大网站通常分区域设置了多个代理服务器,所以不同的地方ping同一个域名可能得到不同的IP地址

透明代理服务器 :透明代理只能设置在网关上。用户访问Internet的数据报必然都经过网关,如果网关上设置代理,则该代理对用户来说显然是透明的。


部署squid代理服务器How to Install Squid Proxy Server on Ubuntu 16.04

安装squid

squid的配置文件在 /etc/squid

dxt@DXT:/etc/squid$ ls
errorpage.css  squid.conf

创建 squid.conf的备份,以防出错需要回滚

dxt@DXT:/etc/squid$ sudo cp ./squid.conf ./squid.conf.bak
dxt@DXT:/etc/squid$ ls
errorpage.css  squid.conf  squid.conf.bak

Squid默认端口为3128 

修改 Squid的http_access,为了允许来自所有IP地址的外部访问HTTP代理服务器,我们需要编辑“http_access”指令。默认情况下,HTTP代理服务器不允许访问任何人,除非我们明确允许!

通过 grep查找 http_access所在位置

dxt@DXT:/etc/squid$  grep -n "http_access*" squid.conf

把1190行改为allow all

 


设置谁可以访问 Squid 代理服务器

在squid.conf末尾添加:

acl localnet src 192.168.1.0/24

http_access allow localnet

允许网络192.168.0.1上的所有机器通过该代理服务器来访问Web服务器

重启squid服务器

dxt@DXT:/etc/squid$ sudo service squid restart 


客户端:kali@kali 地址:192.168.152.128/24 

Squid代理服务器:dxt@DXT 地址192.168.1.209/24 :3128

客户端设置代理服务器地址:

设置环境变量

 

 查看环境变量:

 客户端获取百度index.html网页:

wget将通过http_proxy指定的代理服务器来访问Web服务

可以看到kali客户端会通过Squid代理(192.168.1.209:3128)获取网页

tcpdump抓包:

kali@kali:~$ sudo tcpdump -s 200 -i eth0 -ntX '(src 192.168.1.209 or dst 192.168.1.209) or (arp)'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 200 bytes
IP 192.168.152.128.33606 > 192.168.1.209.3128: Flags [S], seq 2684310663, win 64240, options [mss 1460,sackOK,TS val 315127673 ecr 0,nop,wscale 7], length 0
        0x0000:  4500 003c 2806 4000 4006 f713 c0a8 9880  E..<(.@.@.......
        0x0010:  c0a8 01d1 8346 0c38 9fff 5487 0000 0000  .....F.8..T.....
        0x0020:  a002 faf0 1bd1 0000 0204 05b4 0402 080a  ................
        0x0030:  12c8 7779 0000 0000 0103 0307            ..wy........
IP 192.168.1.209.3128 > 192.168.152.128.33606: Flags [S.], seq 1147679829, ack 2684310664, win 64240, options [mss 1460], length 0
        0x0000:  4500 002c 1762 0000 8006 07c8 c0a8 01d1  E..,.b..........
        0x0010:  c0a8 9880 0c38 8346 4468 3455 9fff 5488  .....8.FDh4U..T.
        0x0020:  6012 faf0 84bf 0000 0204 05b4 0000       `.............
IP 192.168.152.128.33606 > 192.168.1.209.3128: Flags [.], ack 1, win 64240, length 0
        0x0000:  4500 0028 2807 4000 4006 f726 c0a8 9880  E..((.@.@..&....
        0x0010:  c0a8 01d1 8346 0c38 9fff 5488 4468 3456  .....F.8..T.Dh4V
        0x0020:  5010 faf0 1bbd 0000                      P.......
IP 192.168.152.128.33606 > 192.168.1.209.3128: Flags [P.], seq 1:196, ack 1, win 64240, length 195
        0x0000:  4500 00eb 2808 4000 4006 f662 c0a8 9880  E...(.@[email protected]....
        0x0010:  c0a8 01d1 8346 0c38 9fff 5488 4468 3456  .....F.8..T.Dh4V
        0x0020:  5018 faf0 1c80 0000 4745 5420 6874 7470  P.......GET.http
        0x0030:  3a2f 2f77 7777 2e62 6169 6475 2e63 6f6d  ://www.baidu.com
        0x0040:  2f69 6e64 6578 2e68 746d 6c20 4854 5450  /index.html.HTTP
        0x0050:  2f31 2e31 0d0a 5573 6572 2d41 6765 6e74  /1.1..User-Agent
        0x0060:  3a20 5767 6574 2f31 2e32 302e 3320 286c  :.Wget/1.20.3.(l
        0x0070:  696e 7578 2d67 6e75 290d 0a41 6363 6570  inux-gnu)..Accep
        0x0080:  743a 202a 2f2a 0d0a 4163 6365 7074 2d45  t:.*/*..Accept-E
        0x0090:  6e63 6f64 696e 673a 2069 6465 6e74 6974  ncoding:.identit
        0x00a0:  790d 0a48 6f73 743a 2077 7777 2e62 6169  y..Host:.www.bai
        0x00b0:  6475 2e63 6f6d 0d0a                      du.com..
IP 192.168.1.209.3128 > 192.168.152.128.33606: Flags [.], ack 196, win 64240, length 0
        0x0000:  4500 0028 1763 0000 8006 07cb c0a8 01d1  E..(.c..........
        0x0010:  c0a8 9880 0c38 8346 4468 3456 9fff 554b  .....8.FDh4V..UK
        0x0020:  5010 faf0 9bb9 0000 0000 0000 0000       P.............
IP 192.168.1.209.3128 > 192.168.152.128.33606: Flags [P.], seq 1:2611, ack 196, win 64240, length 2610
        0x0000:  4500 0a5a 1764 0000 8006 fd97 c0a8 01d1  E..Z.d..........
        0x0010:  c0a8 9880 0c38 8346 4468 3456 9fff 554b  .....8.FDh4V..UK
        0x0020:  5018 faf0 25ef 0000 4854 5450 2f31 2e31  P...%...HTTP/1.1
        0x0030:  2032 3030 204f 4b0d 0a43 6f6e 7465 6e74  .200.OK..Content
        0x0040:  2d4c 656e 6774 683a 2032 3338 310d 0a43  -Length:.2381..C
        0x0050:  6f6e 7465 6e74 2d54 7970 653a 2074 6578  ontent-Type:.tex
        0x0060:  742f 6874 6d6c 0d0a 5365 7276 6572 3a20  t/html..Server:.
        0x0070:  6266 650d 0a44 6174 653a 2054 7565 2c20  bfe..Date:.Tue,.
        0x0080:  3233 204a 756e 2032 3032 3020 3130 3a30  23.Jun.2020.10:0
        0x0090:  363a 3539 2047 4d54 0d0a 582d 4361 6368  6:59.GMT..X-Cach
        0x00a0:  653a 204d 4953 5320 6672 6f6d 2044 5854  e:.MISS.from.DXT
        0x00b0:  0d0a 582d 4361 6368                      ..X-Cach
IP 192.168.152.128.33606 > 192.168.1.209.3128: Flags [.], ack 2611, win 62780, length 0
        0x0000:  4500 0028 2809 4000 4006 f724 c0a8 9880  E..((.@.@..$....
        0x0010:  c0a8 01d1 8346 0c38 9fff 554b 4468 3e88  .....F.8..UKDh>.
        0x0020:  5010 f53c 1bbd 0000                      P..<....
IP 192.168.152.128.33606 > 192.168.1.209.3128: Flags [F.], seq 196, ack 2611, win 62780, length 0
        0x0000:  4500 0028 280a 4000 4006 f723 c0a8 9880  E..((.@.@..#....
        0x0010:  c0a8 01d1 8346 0c38 9fff 554b 4468 3e88  .....F.8..UKDh>.
        0x0020:  5011 f53c 1bbd 0000                      P..<....
IP 192.168.1.209.3128 > 192.168.152.128.33606: Flags [.], ack 197, win 64239, length 0
        0x0000:  4500 0028 1766 0000 8006 07c8 c0a8 01d1  E..(.f..........
        0x0010:  c0a8 9880 0c38 8346 4468 3e88 9fff 554c  .....8.FDh>...UL
        0x0020:  5010 faef 9187 0000 0000 0000 0000       P.............
IP 192.168.1.209.3128 > 192.168.152.128.33606: Flags [FP.], seq 2611, ack 197, win 64239, length 0
        0x0000:  4500 0028 1767 0000 8006 07c7 c0a8 01d1  E..(.g..........
        0x0010:  c0a8 9880 0c38 8346 4468 3e88 9fff 554c  .....8.FDh>...UL
        0x0020:  5019 faef 917e 0000 0000 0000 0000       P....~........
IP 192.168.152.128.33606 > 192.168.1.209.3128: Flags [.], ack 2612, win 62780, length 0
        0x0000:  4500 0028 0000 4000 4006 1f2e c0a8 9880  E..(..@.@.......
        0x0010:  c0a8 01d1 8346 0c38 9fff 554c 4468 3e89  .....F.8..ULDh>.
        0x0020:  5010 f53c 9739 0000                      P..<.9..
cARP, Request who-has 192.168.152.2 tell 192.168.152.128, length 28
        0x0000:  0001 0800 0604 0001 000c 290c c44d c0a8  ..........)..M..
        0x0010:  9880 0000 0000 0000 c0a8 9802            ............
ARP, Reply 192.168.152.2 is-at 00:50:56:e6:96:7d, length 46
        0x0000:  0001 0800 0604 0002 0050 56e6 967d c0a8  .........PV..}..
        0x0010:  9802 000c 290c c44d c0a8 9880 0000 0000  ....)..M........
        0x0020:  0000 0000 0000 0000 0000 0000 0000       ..............


hosts文件:存储主机名有IP地址映射


 

猜你喜欢

转载自blog.csdn.net/qq_32095699/article/details/106918880