OpenWrt 广告植入原型搭建

第一步:准备固件

编译OpenWrt固件-选择Privoxy

配置user.filter, user.action, config文件。

config文件中需要指定监听都地址与端口号

[cpp]  view plain  copy
  1. root@YSWiFi:/etc/privoxy# cat config   
  2. confdir /etc/privoxy  
  3. logdir /var/log  
  4. filterfile default.filter  
  5. filterfile user.filter  
  6. #logfile privoxy  
  7. actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.  
  8. actionsfile default.action   # Main actions file  
  9. actionsfile user.action      # User customizations  
  10. listen-address  10.1.1.1:8118  
  11. toggle  1  
  12. enable-remote-toggle  1  
  13. enable-remote-http-toggle  0  
  14. enable-edit-actions 1  
  15. enforce-blocks 0  
  16. buffer-limit 4096  
  17. forwarded-connect-retries  0  
  18. accept-intercepted-requests 1  
  19. allow-cgi-request-crunching 0  
  20. split-large-forms 0  
  21. keep-alive-timeout 300  
  22. socket-timeout 300  
  23. permit-access  10.1.1.0/24  
  24. debug   1    # show each GET/POST/CONNECT request  
  25. debug   4096 # Startup banner and warnings  
  26. debug   8192 # Errors - *we highly recommended enabling this*  
  27. #admin-address privoxy-admin@example.com  
  28. #proxy-info-url http://www.example.com/proxy-service.html  
  29.   
  30. root@YSWiFi:/etc/privoxy#   

在user.action中注入广告脚本 xxx.js

具体参考我的脚本 https://gist.github.com/qianguozheng

user.filter中添加过滤规则

1. FILTER: block-weeds  
2. s|</head>|<script type="text/javascript" src="http://www.yourdomainname.com/ystest/js/hupu.js"></script>$0|  


user.action中调用过滤规则
1. {+filter{block-weeds}}  
2. .*  


将所有目标地址为80端口的请求转到8118端口
1. iptables -t nat -A PREROUTING -s 0.0.0.0/0.0.0.0 -p tcp --dport 80 -j REDIRECT --to-ports 8118  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值