当前位置: 首页 > news >正文

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

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

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

service  --status-all ;service   privoxy status ;service   privoxy stop ;
cd /etc/privoxy/;
rm user.filter;
touch user.filter;cat << EOF >./user.action
{+hide-user-agent{bai-du}}
/#{+header{Host2: Firefox22}}{+crunch-client-header{Host:} }
/{+add-header{Host: xxyyzz.bai-du.com}}
/{+block{block ip and domain which point to server itself}}
127.0.0.1
45.32.57.113
.example.com
EOFcat << EOF >./config
user-manual /usr/share/doc/privoxy/user-manual/
confdir /etc/privoxy
logdir /var/log/privoxy
actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.
actionsfile default.action   # Main actions file
actionsfile user.action      # User customizations
filterfile default.filter
filterfile user.filter      # User customizations
logfile privoxy.log
debug     1 # Log the destination for each request. See also debug 1024.
debug     2 # show each connection status
debug     4 # show tagging-related messages
debug     8 # show header parsing
debug   128 # debug redirects
debug   256 # debug GIF de-animation
debug   512 # Common Log Format
debug  1024 # Log the destination for requests Privoxy didn't let through, and the reason why.
debug  4096 # Startup banner and warnings
debug  8192 # Non-fatal errors
debug 65536 # Log applying actions
listen-address  0.0.0.0:8118
toggle  1
enable-remote-toggle  0
enable-remote-http-toggle  0
enable-edit-actions 0
enforce-blocks 1
buffer-limit 4096
enable-proxy-authentication-forwarding 0
forwarded-connect-retries  0
accept-intercepted-requests 1
allow-cgi-request-crunching 0
split-large-forms 0
keep-alive-timeout 5
tolerate-pipelining 1
socket-timeout 300
forward /  127.0.0.1:30080
EOF

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

启动privoxy:

service   privoxy start;service   privoxy status ;

实现的目的是:

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

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

使用curl测试:

root@fv-az1239-825:/tmp# curl --version
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
Release-Date: 2020-01-08
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
root@fv-az1239-825:/tmp# 
curl -v -p -x http://127.0.0.1:8118  http://cip.cc/
root@fv-az1239-825:/etc/privoxy# curl -v -p -x http://127.0.0.1:8118  http://cip.cc/
*   Trying 127.0.0.1:8118...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8118 (#0)
* allocate connect buffer!
* Establish HTTP proxy tunnel to cip.cc:80
> CONNECT cip.cc:80 HTTP/1.1
> Host: cip.cc:80
> User-Agent: curl/7.68.0
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.0 200 Connection Established
< Proxy-agent: Apache/2.4.41 (Ubuntu)
< 
* Proxy replied 200 to CONNECT request
* CONNECT phase completed!
* CONNECT phase completed!
* CONNECT phase completed!
> GET / HTTP/1.1
> Host: cip.cc
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: openresty
< Date: Thu, 31 Aug 2023 09:29:20 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
< X-cip-c: M
< 
IP      : 223.155.x.x
地址    : 中国  湖南  xx  
运营商  : 电信数据二  : 湖南省xx市 | 电信数据三  : 中国湖南省xx市 | 电信URL     : http://www.cip.cc/223.155.x.x
* Connection #0 to host 127.0.0.1 left intact
root@fv-az1239-825:/etc/privoxy# 

tcpdump 抓包的命令是:

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

试验成功.

http://www.lryc.cn/news/153750.html

相关文章:

  • 任意文件读取
  • 微信小程序餐饮外卖系统设计与实现
  • 一文速览嵌入式六大出口
  • 华为云云服务器评测 | 宝塔8.0镜像应用
  • 构建简单的Node.js HTTP服务器,发布公网远程访问的快速方法
  • ModaHub魔搭社区:向量数据库产业的现状与技术挑战
  • pmp和软件高项哪个含金量高?
  • 手把手教你用Vite构建第一个Vue3项目
  • 美创科技获通信网络安全服务能力评定(应急响应一级)认证!
  • 计算机视觉与人工智能在医美人脸皮肤诊断方面的应用
  • RCU501 RMP201-8 KONGSBERG 分布式处理单元
  • 说说 MVCC 的工作原理?
  • 微信小程序请求接口返回的二维码(图片),本地工具和真机测试都能显示,上线之后不显示问题
  • Python小知识 - 1. Python装饰器(decorator)
  • 如何访问GitHub
  • 【广州华锐互动】智能变电站AR仿真实训系统大大提高培训的效率和质量
  • 手写Mybatis:第11章-流程解耦,封装结果集处理器
  • 金融风控数据分析-信用评分卡建模(附数据集下载地址)
  • ceph对象三元素data、xattr、omap
  • 使用 BERT 进行文本分类 (03/3)
  • Leetcode Top 100 Liked Questions(序号236~347)
  • MySQL数据库学习【基础篇】
  • Kubernetes技术--k8s核心技术Service服务
  • OpenHarmony 应用 ArkUI 状态管理开发范例
  • 二、QTableWidget 类 clear() 和 clearContents() 的区别及程序崩溃原因分析
  • spring boot 项目中搭建 ElasticSearch 中间件 一 postman 操作 es
  • 设计模式—观察者模式(Observer)
  • 分类算法系列③:模型选择与调优 (Facebook签到位置预测)
  • PCL RANSAC分割提取多个空间圆
  • Java八股文学习笔记day01