diff --git a/ProxyCat.py b/ProxyCat.py new file mode 100644 index 0000000..1ee3a58 --- /dev/null +++ b/ProxyCat.py @@ -0,0 +1,173 @@ +from http.server import BaseHTTPRequestHandler, HTTPServer +from concurrent.futures import ThreadPoolExecutor +import multiprocessing +import threading +import logoprint +import requests +import argparse +import logging +import socket +import select +import socks +import time + +logging.basicConfig(level=logging.INFO) +proxy_index, rotate_mode, rotate_interval = 0, 'cycle', 60 + +def load_proxies(file_path='ip.txt'): + with open(file_path, 'r') as file: + proxies = [line.strip().split('://') for line in file] + return [(p[0], *p[1].split(':')) for p in proxies] + +def rotate_proxies(proxies, interval): + global proxy_index + while True: + time.sleep(interval) + if rotate_mode == 'cycle': + proxy_index = (proxy_index + 1) % len(proxies) + elif rotate_mode == 'once' and proxy_index < len(proxies) - 1: + proxy_index += 1 + logging.info(f"切换到代理地址: {proxies[proxy_index]}") + +proxies = load_proxies() + +class ProxyHTTPRequestHandler(BaseHTTPRequestHandler): + def __init__(self, *args, **kwargs): + self.session = requests.Session() + adapter = requests.adapters.HTTPAdapter(pool_connections=1000, pool_maxsize=1000) + self.session.mount('http://', adapter) + self.session.mount('https://', adapter) + super().__init__(*args, **kwargs) + + def _update_proxy(self): + global proxy_index + protocol, host, port = proxies[proxy_index] + self.proxy_dict = {"http": f"{protocol}://{host}:{port}", "https": f"{protocol}://{host}:{port}"} + + def do_GET(self): self._proxy_request() + def do_POST(self): self._proxy_request() + def do_CONNECT(self): self._tunnel_request() + + def _proxy_request(self): + self._update_proxy() + data = self.rfile.read(int(self.headers['Content-Length'])) if 'Content-Length' in self.headers else None + headers = {key: val for key, val in self.headers.items()} + headers['Connection'] = 'keep-alive' + + try: + response = self.session.request(self.command, self.path, headers=headers, data=data, + proxies=self.proxy_dict, stream=True, timeout=(5, 27)) + self.send_response(response.status_code) + self.send_headers(response) + self.forward_content(response) + except Exception as e: + self.send_error(500, message=str(e)) + + def send_headers(self, response): + for key, value in response.headers.items(): + if key.lower() != 'connection': + self.send_header(key, value) + self.send_header('Connection', 'keep-alive') + self.end_headers() + + def forward_content(self, response): + for chunk in response.iter_content(chunk_size=4096): + if chunk: + self.wfile.write(chunk) + self.wfile.flush() + + def _tunnel_request(self): + self._update_proxy() + host, port = self.path.split(':') + try: + remote_socket = self._connect_via_proxy(host, int(port)) + self.send_response(200, 'Connection Established') + self.send_header('Connection', 'keep-alive') + self.end_headers() + self._forward_data(self.connection, remote_socket) + except Exception as e: + self.send_error(502, message=str(e)) + + def _connect_via_proxy(self, host, port): + protocol = proxies[proxy_index][0] + if protocol == 'http': + return self._connect_via_http_proxy(host, port) + elif protocol == 'socks5': + return self._connect_via_socks5_proxy(host, port) + else: + raise Exception("不支持的代理类型") + + def _connect_via_http_proxy(self, host, port): + proxy_connect = f"CONNECT {host}:{port} HTTP/1.1\r\nHost: {host}:{port}\r\nConnection: keep-alive\r\n\r\n" + remote_socket = socket.create_connection((proxies[proxy_index][1], int(proxies[proxy_index][2]))) + remote_socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024 * 4096) + remote_socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024 * 4096) + remote_socket.sendall(proxy_connect.encode()) + response = remote_socket.recv(4096).decode('utf-8') + if '200 Connection established' not in response: + raise Exception(f"无法通过 HTTP 代理建立连接: {response}") + return remote_socket + + def _connect_via_socks5_proxy(self, host, port): + remote_socket = socks.socksocket() + remote_socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024 * 4096) + remote_socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024 * 4096) + remote_socket.set_proxy(socks.SOCKS5, proxies[proxy_index][1], int(proxies[proxy_index][2])) + remote_socket.connect((host, port)) + return remote_socket + + def _forward_data(self, client_socket, remote_socket): + sockets = [client_socket, remote_socket] + while True: + read_sockets, _, error_sockets = select.select(sockets, [], sockets, 10) + if error_sockets: + break + for sock in read_sockets: + other_sock = client_socket if sock is remote_socket else remote_socket + data = sock.recv(4096) + if not data: + return + other_sock.sendall(data) + +def run(server_class=HTTPServer, handler_class=ProxyHTTPRequestHandler, port=1080, mode='cycle', interval=60): + global rotate_mode, rotate_interval + rotate_mode, rotate_interval = mode, interval + + server_address, max_workers = ('', port), multiprocessing.cpu_count() * 5 + executor = ThreadPoolExecutor(max_workers=max_workers) + server = server_class(server_address, handler_class) + thread = threading.Thread(target=rotate_proxies, args=(proxies, interval)) + thread.daemon = True + thread.start() + serve_requests(server, executor) + +def serve_requests(server, executor): + try: + while True: + request, client_address = server.get_request() + executor.submit(server.process_request, request, client_address) + except KeyboardInterrupt: + pass + finally: + executor.shutdown(wait=True) + server.server_close() + +def print_icpscan_banner(port, mode, interval): + logoprint.logos() + mode = '循环' if mode == 'cycle' else '单轮' + print("--------------------------------------------------------") + print("公众号:樱花庄的本间白猫") + print("博客:https://y.shironekosan.cn") + print("Github:https://github.com/honmashironeko/ProxyCat") + print("Gitcode:https://gitcode.com/honmashironeko/ProxyCat") + print("--------------------------------------------------------") + print(f"监听端口: {port}, 代理轮换模式: {mode}, 代理更换时间: {interval}秒") + print(f"初始代理地址: {proxies[proxy_index]}") +if __name__ == '__main__': + parser = argparse.ArgumentParser(description=logoprint.logos()) + parser.add_argument('-p', type=int, default=1080, help='监听端口') + parser.add_argument('-m', default='cycle', help='代理轮换模式:cycle 表示循环使用,once 表示用完即止') + parser.add_argument('-t', type=int, default=60, help='代理更换时间(秒)') + args = parser.parse_args() + print_icpscan_banner(port=args.p, mode=args.m, interval=args.t) + run(port=args.p, mode=args.m, interval=args.t) diff --git a/README.md b/README.md index e63ccc9..a1157e0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,71 @@ -# freeproxypool -一款部署于云端或本地的代理池中间件,可将静态代理IP灵活运用成隧道IP,提供固定请求地址,一次部署终身使用 +## 一、工具概述 + +渗透过程中总是遇到需要隐藏IP地址或者更换IP地址绕过安全设备的情况,但是市面上的隧道代理价格极其昂贵,普遍在20-40元/天,这高昂的费用令人难以接受。但是笔者注意到短效IP其实性价比很高,一个IP只需要几分钱,平均只需要0.5-3元/天。 + +综上所述,本工具应运而生!目的是在于将持续时间仅有1分钟-60分钟不等的短效IP转变成一个固定IP供其他工具使用,形成代理池服务器,部署一次即可永久使用。 + +经过前期调研,目前暂未发现一款开源的类似工具,仅有启明星辰公司注册了一个专利,因此非常希望大家能够帮忙分享分享本项目! + +## 二、安装依赖库 + +`pip install -r requirements.txt` + +如果pip安装速度慢,可以采用国内源进行安装: + +`pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/` + +## 三、工具使用 + +按照该格式`socks5://127.0.0.1:7890` or` http://127.0.0.1:7890` 一行一个填入ip.txt文件中。 + +如果您缺少合适的代理地址,恰巧又有几块钱的话可以联系作者,获取多家低价代理购买地址,(后续会编写全自动代理更换)为作者带来几毛钱的推荐收益~ + +本工具参数如下所示: + +``` +# python3 ProxyCat.py -h + |\ _,,,---,,_ by 本间白猫 +ZZZzz /,`.-'`' -. ;-;;,_ + |,4- ) )-,_. ,\ ( `'-' + '---''(_/--' `-'\_) ProxyCat + +用法: ProxyCat.py [-h] [-p P] [-m M] [-t T] + +参数: + -p P 监听端口 + -m M 代理轮换模式:cycle 表示循环使用,once 表示用完即止 + -t T 代理更换时间(秒) + 举例:python3 ProxyCat.py -p 1080 -m cycle -t 180 + 效果:监听108端口 代理轮换模式为循环使用 每180秒更换到下一个代理地址 +``` + + + +## 四、工具演示 + +![Clip_2024-08-21_20-24-48](./assets/Clip_2024-08-21_20-24-48.png) + +![Clip_2024-08-21_20-25-34](./assets/Clip_2024-08-21_20-25-34.png) + +## 五、免责申明 + +1. 如果您下载、安装、使用、修改本工具及相关代码,即表明您信任本工具 +2. 在使用本工具时造成对您自己或他人任何形式的损失和伤害,我们不承担任何责任 +3. 如您在使用本工具的过程中存在任何非法行为,您需自行承担相应后果,我们将不承担任何法律及连带责任 +4. 请您务必审慎阅读、充分理解各条款内容,特别是免除或者限制责任的条款,并选择接受或不接受 +5. 除非您已阅读并接受本协议所有条款,否则您无权下载、安装或使用本工具 +6. 您的下载、安装、使用等行为即视为您已阅读并同意上述协议的约束 + +## 六、更新日志 + +**2024/08/21** + +1. 工具首次发布 + +## 七、赞助开源 + +开源是免费的,全靠爱的力量!但是还是希望您在觉得工具不错的情况下,赞助一下作者的开发哦~ + +![Clip_2024-08-21_20-31-29](./assets/Clip_2024-08-21_20-31-29.png) + +![8c561f41df39b4d79a3719edaf8bed3](./assets/8c561f41df39b4d79a3719edaf8bed3.jpg) diff --git a/__pycache__/logoprint.cpython-311.pyc b/__pycache__/logoprint.cpython-311.pyc new file mode 100644 index 0000000..e71e7df Binary files /dev/null and b/__pycache__/logoprint.cpython-311.pyc differ diff --git a/assets/8c561f41df39b4d79a3719edaf8bed3.jpg b/assets/8c561f41df39b4d79a3719edaf8bed3.jpg new file mode 100644 index 0000000..eb2b8d9 Binary files /dev/null and b/assets/8c561f41df39b4d79a3719edaf8bed3.jpg differ diff --git a/assets/Clip_2024-08-21_20-24-48.png b/assets/Clip_2024-08-21_20-24-48.png new file mode 100644 index 0000000..b44a8d1 Binary files /dev/null and b/assets/Clip_2024-08-21_20-24-48.png differ diff --git a/assets/Clip_2024-08-21_20-25-34.png b/assets/Clip_2024-08-21_20-25-34.png new file mode 100644 index 0000000..6ce8e80 Binary files /dev/null and b/assets/Clip_2024-08-21_20-25-34.png differ diff --git a/assets/Clip_2024-08-21_20-31-29.png b/assets/Clip_2024-08-21_20-31-29.png new file mode 100644 index 0000000..80bc63c Binary files /dev/null and b/assets/Clip_2024-08-21_20-31-29.png differ diff --git a/ip.txt b/ip.txt new file mode 100644 index 0000000..ebf93c8 --- /dev/null +++ b/ip.txt @@ -0,0 +1,4 @@ +socks5://127.0.0.1:7890 +socks5://114.132.125.88:7777 +socks5://47.101.196.233:20002 +socks5://39.105.154.188:20202 diff --git a/logoprint.py b/logoprint.py new file mode 100644 index 0000000..c5e80e1 --- /dev/null +++ b/logoprint.py @@ -0,0 +1,58 @@ +import random + +logo1 = """ + |\ _,,,---,,_ by 本间白猫 +ZZZzz /,`.-'`' -. ;-;;,_ + |,4- ) )-,_. ,\ ( `'-' + '---''(_/--' `-'\_) ProxyCat +""" +logo2 = """ + * ,MMM8&&&. * + MMMM88&&&&& . + MMMM88&&&&&&& + * MMM88&&&&&&&& + MMM88&&&&&&&& + 'MMM88&&&&&&' + 'MMM8&&&' * + /\/|_ __/\\ + / -\ /- ~\ . ' + \ =_YT_ = / + /==*(` `\ ~ \ ProxyCat + / \ / `\ by 本间白猫 + | | ) ~ ( + / \ / ~ \\ + \ / \~ ~/ + _/\_/\_/\__ _/_/\_/\__~__/_/\_/\_/\_/\_/\_ + | | | | ) ) | | | (( | | | | | | + | | | |( ( | | | \\ | | | | | | + | | | | )_) | | | |))| | | | | | + | | | | | | | | (/ | | | | | | + | | | | | | | | | | | | | | | +""" +logo3 = """ + /\_/\ _ + /`` \ / ) + |n n |__ ( ( + =(Y =.'` `\ \ \\ + {`"` \ ) ) + { / |/ / + \\ ,( / / +ProxyCat) ) /-'\ ,_.' by 本间白猫 + (,(,/ ((,,/ +""" +logo4 = """ + .-o=o-. + , /=o=o=o=\ .--. + _|\|=o=O=o=O=| \\ + __.' a`\=o=o=o=(`\ / + '. a 4/`|.-""'`\ \ ;'`) .---. + \ .' / .--' |_.' / .-._) + by 本间白猫 `) _.' / /`-.__.' / + ProxyCat `'-.____; /'-.___.-' + `\"""` +""" + +logos_list = [logo1, logo2, logo3, logo4] +def logos(): + selected_logo = random.choice(logos_list) + print(selected_logo) \ No newline at end of file