0x01 介绍
一个简单的基于tcp 的代理。
功能:监听本地端口,接收本地连接,将数据传入远端服务器,并将服务器的返回信息回传给连接本地的连接
思路:
0x02 代码实现
# 一个简单的tcp代理
# 监听本地端口,将连接到本地端口的流量转发到远端
import socket
import sys
import threading
def usage():
print("Usage: python tcpsocks.py [localhost] [localport] [remotehost] [remoteport]")
print("Example: python tcpsocks.py 127.0.0.1 9000 x.x.x.x 9000")
sys.exit(0)
def lc_waiter_handler(local_waiter, localhost, localport, remotehost, remoteport):
# 创建一个连接远端服务的socket
inner_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
inner_socket.connect((remotehost, int(remoteport)))
exc