changes
This commit is contained in:
+18
-19
@@ -41,7 +41,6 @@ LOGGING = {
|
||||
}
|
||||
config.dictConfig(LOGGING)
|
||||
|
||||
|
||||
class Logger:
|
||||
_instance = None
|
||||
def __init__(self):
|
||||
@@ -51,7 +50,7 @@ class Logger:
|
||||
self.logger = logging.getLogger('PythonProxy')
|
||||
self.logger.info('Initiating Proxy logger!')
|
||||
|
||||
def log(self, message:str):
|
||||
def info(self, message:str):
|
||||
self.logger.info(message)
|
||||
|
||||
def critical(self, message:str):
|
||||
@@ -113,9 +112,9 @@ def connectionHandle(client_socket, client_address):
|
||||
client_socket.close()
|
||||
return
|
||||
|
||||
if "CONNECT" in raw_request:
|
||||
client_socket.sendall(b"HTTP/1.1 200 Connection Established\r\n\r\n")
|
||||
request = client_socket.recv(16 * 1024)
|
||||
# if "CONNECT" in raw_request:
|
||||
# client_socket.sendall(b"HTTP/1.1 200 Connection Established\r\n\r\n")
|
||||
# request = client_socket.recv(16 * 1024)
|
||||
|
||||
request_url = raw_request.split(' ')[1]
|
||||
request_host = ""
|
||||
@@ -134,11 +133,11 @@ def connectionHandle(client_socket, client_address):
|
||||
request_host = request_host.split(':')[0]
|
||||
|
||||
if "monitorando" in request_url:
|
||||
body = "<HTML><HEAD><TITLE>403</TITLE><meta charset=\"UTF-8\"></HEAD> <BODY>Acesso não autorizado!</BODY> </HTML>"
|
||||
body = open('forbidden.html', 'r').read()
|
||||
client_socket.sendall(b"HTTP/1.1 403 Forbidden\r\n\r\n")
|
||||
client_socket.sendall(body.encode())
|
||||
client_socket.close()
|
||||
logger.log(f"REQUEST [{client_address[0]}:{client_address[1]}] to [{request_host}:{request_port}] - 403")
|
||||
logger.info(f"REQUEST [{client_address[0]}:{client_address[1]}] to [{request_host}:{request_port}] - 403 Forbidden")
|
||||
return
|
||||
|
||||
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
@@ -146,7 +145,7 @@ def connectionHandle(client_socket, client_address):
|
||||
server_socket.send(request)
|
||||
|
||||
while True:
|
||||
triple = select.select([client_socket, server_socket], [], [], 20)[0]
|
||||
triple = select.select([client_socket, server_socket], [], [], 10)[0]
|
||||
if not len(triple):
|
||||
break
|
||||
try:
|
||||
@@ -159,9 +158,9 @@ def connectionHandle(client_socket, client_address):
|
||||
status_code = data.decode().split('\r\n')[0].split(' ')[1:]
|
||||
status_code = ' '.join(status_code)
|
||||
if is_valid_status_code(status_code):
|
||||
logger.log(f"REQUEST [{client_address[0]}:{client_address[1]}] to [{request_host}:{request_port}] - {status_code}")
|
||||
logger.info(f"PROXY [{client_address[0]}:{client_address[1]}] to [{request_host}:{request_port}] - {status_code}")
|
||||
except UnicodeDecodeError:
|
||||
logger.log(f"REQUEST [{client_address[0]}:{client_address[1]}] to [{request_host}:{request_port}]")
|
||||
logger.info(f"PROXY [{client_address[0]}:{client_address[1]}] to [{request_host}:{request_port}]")
|
||||
pass
|
||||
|
||||
client_socket.send(data)
|
||||
@@ -182,28 +181,28 @@ def verify_code_integrity():
|
||||
import sys
|
||||
|
||||
content = None
|
||||
md5_hash = None
|
||||
shas256_hash = None
|
||||
|
||||
with open(sys.argv[0], 'rb') as f:
|
||||
content = f.read()
|
||||
|
||||
with open('proxy.py.md5', 'r') as f:
|
||||
md5_hash = f.read()
|
||||
with open('proxy.sha256sum', 'r') as f:
|
||||
shas256_hash = f.read()
|
||||
|
||||
hash = hashlib.md5(content).hexdigest()
|
||||
hash = hashlib.sha256(content).hexdigest()
|
||||
|
||||
if hash != md5_hash:
|
||||
print('ERROR: proxy.py has been tampered with!')
|
||||
if hash != shas256_hash:
|
||||
print('ERRO: Código do proxy está diferente!')
|
||||
exit(1)
|
||||
|
||||
print('[Code Integrity] proxy.py is verified!')
|
||||
print('Arquivo do proxy verificado!')
|
||||
|
||||
if __name__ == '__main__':
|
||||
verify_code_integrity()
|
||||
# verify_code_integrity()
|
||||
|
||||
try:
|
||||
ser = Server(host="0.0.0.0", port=8080)
|
||||
ser.start()
|
||||
except KeyboardInterrupt:
|
||||
print("Shutting down...")
|
||||
print("Desligando proxy...")
|
||||
exit(0)
|
||||
|
||||
Reference in New Issue
Block a user