当前位置:   article > 正文

ubuntu20.04使用privoxy进行http代理转http代理,并定制http代理头(hide-user-agent的使用方法)_ubuntu privoxy

ubuntu privoxy
  1. #sudo apt-get update;
  2. sudo apt install -y privoxy
  3. #sudo apt remove privoxy
  4. privoxy --version;
  1. root@fv-az1239-825:/tmp# privoxy --version
  2. Privoxy version 3.0.28 (https://www.privoxy.org/)
  3. root@fv-az1239-825:/tmp#

安装完毕后,先停止服务,修改配置文件,再启动服务.
 

  1. service --status-all ;
  2. service privoxy status ;
  3. service privoxy stop ;
  1. cd /etc/privoxy/;
  2. rm user.filter;
  3. touch user.filter;
  4. cat << EOF >./user.action
  5. {+hide-user-agent{bai-du}}
  6. /
  7. #{+header{Host2: Firefox22}}
  8. {+crunch-client-header{Host:} }
  9. /
  10. {+add-header{Host: xxyyzz.bai-du.com}}
  11. /
  12. {+block{block ip and domain which point to server itself}}
  13. 127.0.0.1
  14. 45.32.57.113
  15. .example.com
  16. EOF
  17. cat << EOF >./config
  18. user-manual /usr/share/doc/privoxy/user-manual/
  19. confdir /etc/privoxy
  20. logdir /var/log/privoxy
  21. actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.
  22. actionsfile default.action # Main actions file
  23. actionsfile user.action # User customizations
  24. filterfile default.filter
  25. filterfile user.filter # User customizations
  26. logfile privoxy.log
  27. debug 1 # Log the destination for each request. See also debug 1024.
  28. debug 2 # show each connection status
  29. debug 4 # show tagging-related messages
  30. debug 8 # show header parsing
  31. debug 128 # debug redirects
  32. debug 256 # debug GIF de-animation
  33. debug 512 # Common Log Format
  34. debug 1024 # Log the destination for requests Privoxy didn't let through, and the reason why.
  35. debug 4096 # Startup banner and warnings
  36. debug 8192 # Non-fatal errors
  37. debug 65536 # Log applying actions
  38. listen-address 0.0.0.0:8118
  39. toggle 1
  40. enable-remote-toggle 0
  41. enable-remote-http-toggle 0
  42. enable-edit-actions 0
  43. enforce-blocks 1
  44. buffer-limit 4096
  45. enable-proxy-authentication-forwarding 0
  46. forwarded-connect-retries 0
  47. accept-intercepted-requests 1
  48. allow-cgi-request-crunching 0
  49. split-large-forms 0
  50. keep-alive-timeout 5
  51. tolerate-pipelining 1
  52. socket-timeout 300
  53. forward / 127.0.0.1:30080
  54. EOF

注意最后一行:  forward /  127.0.0.1:30080   是上游的http代理

启动privoxy:

  1. service privoxy start;
  2. service privoxy status ;

实现的目的是:

本机tcp8118端口作为http代理服务器,用户的http代理请求,发送给tcp8118端口 privoxy修改http头部后,再发给127.0.0.1:30080这个代理服务器.

主要用来绕过有些代理服务器对user-agent或host有校验的情况下.

使用curl测试:

  1. root@fv-az1239-825:/tmp# curl --version
  2. curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
  3. Release-Date: 2020-01-08
  4. Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
  5. Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
  6. root@fv-az1239-825:/tmp#
curl -v -p -x http://127.0.0.1:8118  http://cip.cc/
  1. root@fv-az1239-825:/etc/privoxy# curl -v -p -x http://127.0.0.1:8118 http://cip.cc/
  2. * Trying 127.0.0.1:8118...
  3. * TCP_NODELAY set
  4. * Connected to 127.0.0.1 (127.0.0.1) port 8118 (#0)
  5. * allocate connect buffer!
  6. * Establish HTTP proxy tunnel to cip.cc:80
  7. > CONNECT cip.cc:80 HTTP/1.1
  8. > Host: cip.cc:80
  9. > User-Agent: curl/7.68.0
  10. > Proxy-Connection: Keep-Alive
  11. >
  12. < HTTP/1.0 200 Connection Established
  13. < Proxy-agent: Apache/2.4.41 (Ubuntu)
  14. <
  15. * Proxy replied 200 to CONNECT request
  16. * CONNECT phase completed!
  17. * CONNECT phase completed!
  18. * CONNECT phase completed!
  19. > GET / HTTP/1.1
  20. > Host: cip.cc
  21. > User-Agent: curl/7.68.0
  22. > Accept: */*
  23. >
  24. * Mark bundle as not supporting multiuse
  25. < HTTP/1.1 200 OK
  26. < Server: openresty
  27. < Date: Thu, 31 Aug 2023 09:29:20 GMT
  28. < Content-Type: text/html; charset=UTF-8
  29. < Transfer-Encoding: chunked
  30. < Connection: keep-alive
  31. < Vary: Accept-Encoding
  32. < X-cip-c: M
  33. <
  34. IP : 223.155.x.x
  35. 地址 : 中国 湖南 xx
  36. 运营商 : 电信
  37. 数据二 : 湖南省xx市 | 电信
  38. 数据三 : 中国湖南省xx市 | 电信
  39. URL : http://www.cip.cc/223.155.x.x
  40. * Connection #0 to host 127.0.0.1 left intact
  41. root@fv-az1239-825:/etc/privoxy#

tcpdump 抓包的命令是:

tcpdump -i  any -s0 -w /tmp/bb.pcap  tcp port 30080
  1. root@fv-az1239-825:/tmp# strings bb.pcap
  2. CONNECT cip.cc:80 HTTP/1.1
  3. User-Agent: bai-du
  4. Host: xxyyzz.bai-du.com
  5. HTTP/1.0 200 Connection Established
  6. Proxy-agent: Apache/2.4.41 (Ubuntu)
  7. GET / HTTP/1.1
  8. Host: cip.cc
  9. User-Agent: curl/7.68.0
  10. Accept: */*
  11. HTTP/1.1 200 OK
  12. Server: openresty
  13. Date: Thu, 31 Aug 2023 09:29:20 GMT
  14. Content-Type: text/html; charset=UTF-8
  15. Transfer-Encoding: chunked
  16. Connection: keep-alive
  17. Vary: Accept-Encoding
  18. X-cip-c: M
  19. IP : 223.155.x.x
  20. :
  21. |
  22. URL : http://www.cip.cc/223.155.x.x
  23. root@fv-az1239-825:/tmp#

试验成功.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/918375
推荐阅读
相关标签
  

闽ICP备14008679号