[译]proxychain

原文地址: http://www.codeproject.com/Tips/634228/How-to-Use-Proxychains-Forwarding-Ports
http://www.backtrack-linux.org/forums/showthread.php?t=1496

本文将介绍如何使用proxychain和ssh来连接到一个使用了ssh的路由,然后通过路由将一个网络的流量通过proxychain转发到另一端
背景
我们将使用如下的网络结构

SOCKS Proxy-基础介绍
SOCKS是一个代理协议,它通常作为欺骗工具使用,通过它来绕过防火墙来访问被限制的内容。在我们的场景中,我们将使用SOCKS来创建一个在攻击者和路由之间的的隧道,通过这个隧道,我们可以发送流量并且流量可以出现在路由的另一端,在路由的内网中,就像流量来自路由。例如我们假设路由封锁了445端口,但是你想攻击内网服务器11.0.0.32的445端口漏洞。这时就需要SOCKS隧道。
你无法做到的:SOCKS是一个5层协议。它意味着它不关心在OSI模型中它之下的部分。也就是说你不能用隧道协议来操作5层之下。包括ping,ARP等。从攻击者的角度,它不支持nmap的半打开连接之类的扫描因为这些功能都工作在5层以下。
能做到的:运行msfconsole,HTTP, SMTP或其他应用层协议的工具。
如何使用SOCKS:在我们的例子中,我们假设我们拥有上图中路由的口令。使用这些口令,我们将会在我们的攻击机上设置一个SOCKS代理服务器,通过SOCKS隧道连接到路由。这样在内网中,将会认为数据来自路由。
Proxychains-如何使用
大多数人认为代理需要一台独立的主机,你连接到它,它会将你的流量转发。然而也可以将你本地电脑的一个程序的流量转发到另一个程序。这就睡Proxychains的工作方式。
Proxychains允许我们与SOCKS隧道交互。我们可以配置Proxychains成管道形式,例如将数据发送到网络,然后通过Proxychains,到我们的socks隧道,然后出路由进入内网。

创建SOCKS隧道使用Proxychains
1. 使用SSH搭建SOCKS服务器和SOCKS隧道
首先我们需要搭建SOCKS服务器和通往路由的SOCKS隧道。使用如下命令
root@whatever: ssh -NfD <local_listening_port> <username>@<router_ip> 

在我们的场景中
root@bt: ssh -NfD 9050 [email protected] 

选项:
-N:不执行远程命令。例如:不会打开一个像常用的SSH那样的命令行shell。
-f:在输入口令之后在后台运行ssh
-D:创建一个动态的应用层级别的端口转发隧道。这部分就是实际创建SOCKS服务器。它在你本地机器上打开在-D后面指定的端口号。在你本机中任何通往该端口的流量将会通过SOCKS隧道到达路由。
如果一切顺利,路由将会prompt出一个对话框来输入口令,在你输入口令后,ssh将会自动变成后台运行。如果在Linux中使用netstat -antpu或在Windows中使用netstat -ano将会看到有一个监听端口在9050

2.使用Proxychains
现在我们开始使用proxychain。在Linux中,Proxychains配置文件存储在/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

我们只关心最后一行,除非你把端口从9050改成其他的,否则你不必做任何改变。如果你想使用不同端口,你需要在—D选项后把端口从9050改成任何想要的值。除此之外,proxychain会首先检查你的工作目录,然后才是/etc/proxychains.conf。
使用方法:
root@whatever: proxychains <name_of_application>

例如你可以:
root@whatever: proxychains msfconsole 

不管在msfconsole中做了什么,首先将会通过9050端口,然后是SOCKS隧道,通过路由到达内网。

proxychain配置相关:
在/etc/proxychains.conf中将会看到proxychain支持的特性:
-dynamic_chain:根据添加的顺序来组合代理链,跳过无法连接的代理
-random_chain:以随机顺序来组合代理链
-strict_chain:根据添加顺序组合代理链,但是不跳过无法连接的代理。
引用
然后需要添加代理,在proxychains.conf文件中将会找到如下内容:
# 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

这些告诉你如何添加代理列表,可以使用空格或tab键分隔各列
然后将会看到[ProxyList],这就是我们设置代理的地方
引用
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks4  127.0.0.1 9050

在socks4 127.0.0.1 9050后面加上我们的代理( 这行为是ssh指定的端口)。运行命令:
proxychains firefox site.com
proxychains telnet target

猜你喜欢

转载自j4s0nh4ck.iteye.com/blog/2153975