-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
148 lines (114 loc) · 5.92 KB
/
main.py
File metadata and controls
148 lines (114 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import requests
from datetime import datetime, timezone, timedelta
import time as time_module
from proxies import ProxyManager
import os
proxy_manager = ProxyManager()
GLOBAL_USE_PROXY = False
BASE_HEADERS = {
'Accept': 'application/vnd.github.mercy-preview+json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36'
}
def make_request(url, headers=None, params=None):
global GLOBAL_USE_PROXY
current_headers = BASE_HEADERS.copy()
if headers:
current_headers.update(headers)
while True:
proxies_config = None
current_proxy_str = "None"
if GLOBAL_USE_PROXY:
res = proxy_manager.get_proxy()
if res:
current_proxy_str, proxies_config = res
else:
GLOBAL_USE_PROXY = False
try:
response = requests.get(url, headers=current_headers, proxies=proxies_config, params=params, timeout=5)
if response.status_code == 200:
return response
if response.status_code == 403:
print(f"\n[-] 403 Received. Activating/Rotating proxy mode...")
GLOBAL_USE_PROXY = True
time_module.sleep(0.5)
continue
return response
except requests.RequestException:
if GLOBAL_USE_PROXY:
print(f"[-] Proxy {current_proxy_str} failed, rotating...", end="\r")
else:
print(f"[-] Connection error. Activating proxy mode...")
GLOBAL_USE_PROXY = True
continue
def get_proxies_count():
if not os.path.exists('proxiesWithoutCheck.txt'):
return 0
with open('proxiesWithoutCheck.txt', 'r', encoding='utf-8') as f:
return sum(1 for _ in f)
limite_tiempo = datetime.now(timezone.utc) - timedelta(hours=24)
limite_iso = limite_tiempo.strftime('%Y-%m-%dT%H:%M:%SZ')
terminos = ['free-proxy', 'proxy-list', 'socks5-proxy', 'socks4-proxy']
reposCandidatos = []
PROXIES_LIMIT = 100000
current_count = get_proxies_count()
discovery_finished = current_count >= PROXIES_LIMIT
if discovery_finished:
print(f"[-] Initial count ({current_count}) already exceeds PROXIES_LIMIT. Skipping discovery phase.")
for term in terminos:
if discovery_finished: break
headers = {'Accept': 'application/vnd.github.mercy-preview+json'}
url = 'https://api.github.com/search/repositories'
params = {
'q': f'{term} pushed:>{limite_iso}',
'sort': 'updated',
'order': 'desc'
}
response = make_request(url, headers=headers, params=params)
if response and response.status_code == 200:
data = response.json()
items = data.get('items', [])
print(f"[*] Found {len(items)} repositories for: {term} (since {limite_iso})")
for repo in items:
if discovery_finished: break
updated_at = datetime.fromisoformat(repo['updated_at'].replace('Z', '+00:00'))
if updated_at > limite_tiempo:
if repo['id'] not in [r['id'] for r in reposCandidatos]:
url_contents = f'https://api.github.com/repos/{repo["full_name"]}/contents/'
response_contents = make_request(url_contents, headers=headers)
if response_contents and response_contents.status_code == 200:
data_contents = response_contents.json()
for item in data_contents:
if discovery_finished: break
if item['name'].endswith('.txt'):
print(f" [+] Checking file: {item['name']} in {repo['full_name']}")
response_file = make_request(item['download_url'], headers=headers)
if response_file and response_file.status_code == 200:
data_file = response_file.text
lines = data_file.strip().split('\n')
clean_proxies = []
for line in lines:
parts = line.strip().split(':')
if len(parts) >= 2:
ip = parts[0]
port = parts[1]
if ip.count('.') == 3 and ip.replace('.', '').isdigit():
clean_proxies.append(f"{ip}:{port}")
if clean_proxies:
with open('proxiesWithoutCheck.txt', 'a') as f:
for p in clean_proxies:
print(f"[+] found proxy: {p}")
f.write(p + "\n")
current_count += len(clean_proxies)
if current_count >= PROXIES_LIMIT:
print(f"[-] You have reached the limit of proxies setted in PROXIES_LIMIT ({current_count}), starting test mode")
discovery_finished = True
break
reposCandidatos.append(repo)
from concurrent.futures import ThreadPoolExecutor
proxy_manager.load_proxies()
total_to_test = len(proxy_manager.proxies)
print(f"[-] Starting test mode with {total_to_test} proxies (Multithreaded)...")
def quiet_test(proxy):
proxy_manager.test_proxy(proxy, quiet=True)
with ThreadPoolExecutor(max_workers=40) as executor:
executor.map(quiet_test, proxy_manager.proxies)