发布于 2017-01-02 17:13:38
sshuttle客户端设置防火墙规则( Linux中的iptables,这就是为什么sshuttle客户端需要根权限)来将某些传出的TCP连接重定向到本地端口(默认为12300),在启动sshuttle时可以看到这个过程:
firewall manager: starting transproxy.
>> iptables -t nat -N sshuttle-12300
>> iptables -t nat -F sshuttle-12300
>> iptables -t nat -I OUTPUT 1 -j sshuttle-12300
>> iptables -t nat -I PREROUTING 1 -j sshuttle-12300
>> iptables -t nat -A sshuttle-12300 -j RETURN --dest 127.0.0.0/8 -p tcp
>> iptables -t nat -A sshuttle-12300 -j REDIRECT --dest 0.0.0.0/0 -p tcp --to-ports 12300 -m ttl ! --ttl 42当梭子离开时,删除iptables nat规则
>> iptables -t nat -D OUTPUT -j sshuttle-12300
>> iptables -t nat -D PREROUTING -j sshuttle-12300
>> iptables -t nat -F sshuttle-12300
>> iptables -t nat -X sshuttle-12300通过到sshuttle服务器的ssh连接获取和复用TCP内容,然后再将其解复用为连接。onaccept_tcpin函数在client.py中执行mux:
def onaccept_tcp(listener, method, mux, handlers):
global _extra_fd
try:
sock, srcip = listener.accept()
except socket.error as e:
if e.args[0] in [errno.EMFILE, errno.ENFILE]:
debug1('Rejected incoming connection: too many open files!\n')
# free up an fd so we can eat the connection
os.close(_extra_fd)
try:
sock, srcip = listener.accept()
sock.close()
finally:
_extra_fd = os.open('/dev/null', os.O_RDONLY)
return
else:
raise
dstip = method.get_tcp_dstip(sock)
debug1('Accept TCP: %s:%r -> %s:%r.\n' % (srcip[0], srcip[1],
dstip[0], dstip[1]))
if dstip[1] == sock.getsockname()[1] and islocal(dstip[0], sock.family):
debug1("-- ignored: that's my address!\n")
sock.close()
return
chan = mux.next_channel()
if not chan:
log('warning: too many open channels. Discarded connection.\n')
sock.close()
return
mux.send(chan, ssnet.CMD_TCP_CONNECT, b'%d,%s,%d' %
(sock.family, dstip[0].encode("ASCII"), dstip[1]))
outwrap = MuxWrapper(mux, chan)
handlers.append(Proxy(SockWrapper(sock, sock), outwrap))
expire_connections(time.time(), mux)您可以看到数据是如何在ssnet.py中打包的。
我在红袜中看到了同样的策略(我指的是设置防火墙规则),它的目的是将任何TCP连接重定向到SOCKS或HTTPS代理。
发布于 2017-01-02 12:55:29
正如声明中所说的,这不是TCP通过TCP协议。
这是TCP over TCP:
First application
First end of outer TCP connection
First end of inner TCP connection
Datagram/packet link
Send end of inner TCP connection
Second end of outer TCP connection
Second application 注意外部TCP连接是如何在内部TCP连接上进行的?
他们就是这么做的:
First application
First end of outer TCP connection
Outer end of First TCP connection
Inner end of First TCP connection
Byte stream link
Inner end of Second TCP connection
Outer end of Second TCP connection
Second application 注意没有通过内部TCP连接传输的外部TCP连接?没有TCP通过TCP。
有四种明显的方法可以做到:
https://stackoverflow.com/questions/41427123
复制相似问题