回滚代码

This commit is contained in:
cheney 2026-05-26 21:26:24 +08:00
parent d11390e453
commit 021738a8bb
2 changed files with 32 additions and 10 deletions

9
proxy/config.ini Normal file
View File

@ -0,0 +1,9 @@
[proxy]
target_host = superstar.geelytravel.com
target_port = 443
target_protocol = https
; target_host = zentao.sunyard.com.cn
; target_port = 9788
; target_protocol = http
b_host = localhost
b_port = 8080

View File

@ -3,12 +3,25 @@ import socket
import threading
import time
import sys
import configparser
import os
# Configuration
TARGET_HOST = "zentao.sunyard.com.cn"
TARGET_PORT = 9788
B_HOST = "localhost"
B_PORT = 8080
# Configuration from config.ini
CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'config.ini')
def load_config():
config = configparser.ConfigParser()
config.read(CONFIG_FILE)
target_host = config.get('proxy', 'target_host', fallback='zentao.sunyard.com.cn')
target_port = config.getint('proxy', 'target_port', fallback=9788)
target_protocol = config.get('proxy', 'target_protocol', fallback='http').lower()
b_host = config.get('proxy', 'b_host', fallback='localhost')
b_port = config.getint('proxy', 'b_port', fallback=8080)
return target_host, target_port, target_protocol, b_host, b_port
TARGET_HOST, TARGET_PORT, TARGET_PROTOCOL, B_HOST, B_PORT = load_config()
# Global lock for socket write operations
socket_write_lock = threading.Lock()
@ -69,9 +82,9 @@ def modify_request_headers(request_data):
line_str = line
if line_str.startswith("Origin:"):
new_lines.append("Origin: http://%s:%d" % (TARGET_HOST, TARGET_PORT))
new_lines.append("Origin: %s://%s:%d" % (TARGET_PROTOCOL, TARGET_HOST, TARGET_PORT))
elif line_str.startswith("Referer:"):
new_lines.append("Referer: http://%s:%d/" % (TARGET_HOST, TARGET_PORT))
new_lines.append("Referer: %s://%s:%d/" % (TARGET_PROTOCOL, TARGET_HOST, TARGET_PORT))
elif line_str.startswith("Host:"):
new_lines.append("Host: %s:%d" % (TARGET_HOST, TARGET_PORT))
elif line_str.lower().startswith("connection:"):
@ -90,7 +103,7 @@ def modify_request_headers(request_data):
modified_data = "\r\n".join(new_lines)
if path.startswith("/"):
new_path = "http://%s:%d%s" % (TARGET_HOST, TARGET_PORT, path)
new_path = "%s://%s:%d%s" % (TARGET_PROTOCOL, TARGET_HOST, TARGET_PORT, path)
if method and modified_data:
modified_data = modified_data.replace(path, new_path, 1)
@ -111,7 +124,7 @@ def handle_request(request_data):
if "\r\n\r\n" in modified_data:
body_size = len(modified_data) - modified_data.find("\r\n\r\n") - 4
log_info("System", "Request: %s %s%s - Body: %d bytes - ID: %s" % (method, "http://" + TARGET_HOST + ":" + str(TARGET_PORT), path, body_size, request_id))
log_info("System", "Request: %s %s://%s:%d%s - Body: %d bytes - ID: %s" % (method, TARGET_PROTOCOL, TARGET_HOST, TARGET_PORT, path, body_size, request_id))
target_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
target_sock.settimeout(30)
@ -282,7 +295,7 @@ def main():
print("=" * 60)
print(" Proxy Client (Run on Computer A)")
print("=" * 60)
print("Target website:", TARGET_HOST, ":", TARGET_PORT)
print("Target website:", TARGET_PROTOCOL, "://", TARGET_HOST, ":", TARGET_PORT)
print("Device B address:", B_HOST, ":", B_PORT)
print("=" * 60)
sys.stdout.flush()