Ubuntu安装Proxychains

Proxychains是Linux上一款全局代理工具,通过Hook Socket函数实现透明代理,这和Windows上的Proxifier有点类似。
在Ubuntu上安装Proxychains的方法是:

apt-get install proxychains

安装的是3.1版本,配置文件的路径是:/etc/proxychains.conf,内容如下:

  1. # proxychains.conf VER 3.1
  2. #
  3. # HTTP, SOCKS4, SOCKS5 tunneling proxifier with DNS.
  4. #
  5. # The option below identifies how the ProxyList is treated.
  6. # only one option should be uncommented at time,
  7. # otherwise the last appearing option will be accepted
  8. #
  9. #dynamic_chain
  10. #
  11. # Dynamic - Each connection will be done via chained proxies
  12. # all proxies chained in the order as they appear in the list
  13. # at least one proxy must be online to play in chain
  14. # (dead proxies are skipped)
  15. # otherwise EINTR is returned to the app
  16. #
  17. strict_chain
  18. #
  19. # Strict - Each connection will be done via chained proxies
  20. # all proxies chained in the order as they appear in the list
  21. # all proxies must be online to play in chain
  22. # otherwise EINTR is returned to the app
  23. #
  24. #random_chain
  25. #
  26. # Random - Each connection will be done via random proxy
  27. # (or proxy chain, see chain_len) from the list.
  28. # this option is good to test your IDS :)
  29. # Make sense only if random_chain
  30. #chain_len = 2
  31. # Quiet mode (no output from library)
  32. #quiet_mode
  33. # Proxy DNS requests - no leak for DNS data
  34. proxy_dns
  35. # Some timeouts in milliseconds
  36. tcp_read_time_out 15000
  37. tcp_connect_time_out 8000
  38. # ProxyList format
  39. # type host port [user pass]
  40. # (values separated by 'tab' or 'blank')
  41. #
  42. #
  43. # Examples:
  44. #
  45. # socks5 192.168.67.78 1080 lamer secret
  46. # http 192.168.89.3 8080 justu hidden
  47. # socks4 192.168.1.49 1080
  48. # http 192.168.39.93 8080
  49. #
  50. #
  51. # proxy types: http, socks4, socks5
  52. # ( auth types supported: "basic"-http "user/pass"-socks )
  53. #
  54. [ProxyList]
  55. # add proxy here ...
  56. # meanwile
  57. # defaults set to "tor"
  58. socks4 127.0.0.1 9050
COPY

Proxychains支持HTTP(HTTP-Connect)、SOCKS4和SOCKS5三种类型的代理,需要注意的是:配置代理服务器只能使用ip地址,不能使用域名,否则会连不上。

Proxychains支持3种模式:

  1. 动态模式
    按照配置的代理顺序连接,不存活的代理服务器会被跳过
  2. 严格模式
    按照配置的代理顺序连接,必须保证所有代理服务器都是存活的,否则会连接失败
  3. 随机模式
    随机选择一台代理服务器连接,也可以使用代理链

如果不需要代理DNS的话,可以注释掉proxy_dns这行。

使用的时候在命令行前加上proxychains即可。

root@ubuntu-pc:~# proxychains telnet www.baidu.com 80
ProxyChains-3.1 (http://proxychains.sf.net)
Trying 14.215.177.37…
|R-chain|-<>-10.0.0.10:8080-<><>-14.215.177.37:80-<><>-OK
Connected to www.a.shifen.com.
Escape character is ‘^]’.

proxychains命令其实是个脚本文件,内容如下:

  1. #!/bin/sh
  2. echo "ProxyChains-3.1 (http://proxychains.sf.net)"
  3. if [ $# = 0 ] ; then
  4. echo " usage:"
  5. echo " proxychains <prog> [args]"
  6. exit
  7. fi
  8. export LD_PRELOAD=libproxychains.so.3
  9. exec "$@"
COPY

它的目的是设置LD_PRELOAD环境变量,以便创建的新进程会加载libproxychains.so.3,这个so的作用是Hook Socket函数。因此,也可以在当前shell中执行:

  1. export LD_PRELOAD=libproxychains.so.3
COPY

这样之后执行的命令都会使用代理访问。

不过这个版本有个问题,配置代理后所有的连接都会走代理,包括对回环地址的访问。这并不是我们所期望的,幸好有个版本提供了解决方案。

git clone https://github.com/rofl0r/proxychains
cd proxychains
./configure
make
make install

安装后在配置文件中加入:

localnet 127.0.0.0/255.0.0.0

安装后的命令是proxychains4,因此可以和旧版本命令并存。这样对于回环地址就可以绕过代理,使用直连了。

相对于Proxifier而言,这种方式还是弱了一点,毕竟有时候我们还是需要根据不同的情况使用不同的代理服务器。

分享
0 comments
Anonymous
Markdown is supported

Be the first guy leaving a comment!