66import logging
77import os
88import sys
9+ import requests
910from datetime import datetime
1011import time
1112import traceback
1213
13- __version__ = "1.8.2 "
14+ __version__ = "1.9 "
1415
1516os .system ("" )
1617
@@ -30,14 +31,15 @@ def __init__(self, src_ip, dst_domain, method):
3031
3132class ProxyServer :
3233
33- def __init__ (self , host , port , blacklist , log_access , log_err , no_blacklist , quiet , verbose ):
34+ def __init__ (self , host , port , blacklist , log_access , log_err , no_blacklist , auto_blacklist , quiet , verbose ):
3435
3536 self .host = host
3637 self .port = port
3738 self .blacklist = blacklist
3839 self .log_access_file = log_access
3940 self .log_err_file = log_err
4041 self .no_blacklist = no_blacklist
42+ self .auto_blacklist = auto_blacklist
4143 self .quiet = quiet
4244 self .verbose = verbose
4345
@@ -61,6 +63,7 @@ def __init__(self, host, port, blacklist, log_access, log_err, no_blacklist, qui
6163 self .tasks_lock = asyncio .Lock ()
6264
6365 self .blocked = []
66+ self .whitelist = []
6467 self .tasks = []
6568 self .server = None
6669
@@ -289,6 +292,16 @@ async def handle_connection(self, reader, writer):
289292 conn_info = ConnectionInfo (
290293 client_ip , host .decode (), method .decode ())
291294
295+ if method == b"CONNECT" and self .auto_blacklist :
296+ try :
297+ if host not in self .blocked and host not in self .whitelist :
298+ requests .get ('https://' + host .decode (), timeout = 3 )
299+ self .whitelist .append (host )
300+ except Exception : # pylint: disable=broad-except
301+ self .blocked .append (host )
302+ with open (self .blacklist , "a" , encoding = "utf-8" ) as f :
303+ f .write (host .decode () + "\n " )
304+
292305 async with self .connections_lock :
293306 self .active_connections [conn_key ] = conn_info
294307
@@ -465,6 +478,9 @@ def parse_args():
465478 blacklist_group .add_argument (
466479 "--no_blacklist" , action = "store_true" , help = "Use fragmentation for all domains"
467480 )
481+ blacklist_group .add_argument (
482+ "--autoblacklist" , action = "store_true" , help = "Automatic detection of blocked domains"
483+ )
468484
469485 parser .add_argument (
470486 "--log_access" , required = False , help = "Path to the access control log"
@@ -563,6 +579,7 @@ async def run(cls):
563579 args .log_access ,
564580 args .log_error ,
565581 args .no_blacklist ,
582+ args .autoblacklist ,
566583 args .quiet ,
567584 args .verbose ,
568585 )
0 commit comments