Ubuntu安裝Proxychains


本文由 簡悅 SimpRead 轉碼, 原文地址 https://cloud.tencent.com/developer/article/1157554

Proxychains 是 Linux 上一款全局代理工具,通過 Hook Socket 函數實現透明代理,這和 Windows 上的 Proxifier 有點類似。 在 Ubuntu 上安裝 Proxychains 的方法是:

apt-get install proxychains

安裝的是 3.1 版本,配置文件的路徑是:/etc/proxychains.conf,內容如下:

# proxychains.conf  VER 3.1
#
#        HTTP, SOCKS4, SOCKS5 tunneling proxifier with DNS.
#

# The option below identifies how the ProxyList is treated.
# only one option should be uncommented at time,
# otherwise the last appearing option will be accepted
#
#dynamic_chain
#
# Dynamic - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# at least one proxy must be online to play in chain
# (dead proxies are skipped)
# otherwise EINTR is returned to the app
#
strict_chain
#
# Strict - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# all proxies must be online to play in chain
# otherwise EINTR is returned to the app
#
#random_chain
#
# Random - Each connection will be done via random proxy
# (or proxy chain, see  chain_len) from the list.
# this option is good to test your IDS :)

# Make sense only if random_chain
#chain_len = 2

# Quiet mode (no output from library)
#quiet_mode

# Proxy DNS requests - no leak for DNS data
proxy_dns 

# Some timeouts in milliseconds
tcp_read_time_out 15000
tcp_connect_time_out 8000

# ProxyList format
#       type  host  port [user pass]
#       (values separated by 'tab' or 'blank')
#
#
#        Examples:
#
#               socks5  192.168.67.78   1080    lamer   secret
#               http    192.168.89.3    8080    justu   hidden
#               socks4  192.168.1.49    1080
#               http    192.168.39.93   8080
#
#
#       proxy types: http, socks4, socks5
#        ( auth types supported: "basic"-http  "user/pass"-socks )
#
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks4         127.0.0.1 9050

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 命令其實是個腳本文件,內容如下:

#!/bin/sh
echo "ProxyChains-3.1 (http://proxychains.sf.net)"
if [ $# = 0 ] ; then
        echo "  usage:"
        echo "          proxychains 
 
 
 
         
          
  
  
   [args]"
        exit
fi
export LD_PRELOAD=libproxychains.so.3
exec "$@"
 
 
 
         

它的目的是設置 LD_PRELOAD 環境變量,以便創建的新進程會加載 libproxychains.so.3,這個 so 的作用是 Hook Socket 函數。因此,也可以在當前 shell 中執行:

export LD_PRELOAD=libproxychains.so.3

這樣之后執行的命令都會使用代理訪問。

不過這個版本有個問題,配置代理后所有的連接都會走代理,包括對回環地址的訪問。這並不是我們所期望的,幸好有個版本提供了解決方案。

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

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

localnet 127.0.0.0/255.0.0.0

安裝后的命令是 proxychains4,因此可以和舊版本命令並存。這樣對於回環地址就可以繞過代理,使用直連了。

相對於 Proxifier 而言,這種方式還是弱了一點,畢竟有時候我們還是需要根據不同的情況使用不同的代理服務器。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM