Merge pull request #175 from vbanos/random-tls-fingerprint

Thanks, @vbanos!
This commit is contained in:
Barbara Miller 2022-07-01 14:16:05 -07:00 committed by GitHub
commit 7958921053
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,6 +64,7 @@ import ssl
import warcprox import warcprox
import threading import threading
import datetime import datetime
import random
import socks import socks
import tempfile import tempfile
import hashlib import hashlib
@ -220,6 +221,28 @@ def via_header_value(orig, request_version):
via = via + '%s %s' % (request_version, 'warcprox') via = via + '%s %s' % (request_version, 'warcprox')
return via return via
# Ref and detailed description about cipher selection at
# https://github.com/urllib3/urllib3/blob/f070ec2e6f6c545f40d9196e5246df10c72e48e1/src/urllib3/util/ssl_.py#L170
SSL_CIPHERS = [
"ECDHE+AESGCM",
"ECDHE+CHACHA20",
"DH+AESGCM",
"ECDH+AES",
"DH+AES",
"RSA+AESGCM",
"RSA+AES",
"!aNULL",
"!eNULL",
"!MD5",
"!DSS",
"!AESCCM",
"DHE+AESGCM",
"DHE+CHACHA20",
"ECDH+AESGCM",
]
class MitmProxyHandler(http_server.BaseHTTPRequestHandler): class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
''' '''
An http proxy implementation of BaseHTTPRequestHandler, that acts as a An http proxy implementation of BaseHTTPRequestHandler, that acts as a
@ -301,6 +324,9 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
context = ssl.create_default_context() context = ssl.create_default_context()
context.check_hostname = False context.check_hostname = False
context.verify_mode = ssl.CERT_NONE context.verify_mode = ssl.CERT_NONE
# randomize TLS fingerprint to evade anti-web-bot systems
random.shuffle(SSL_CIPHERS)
context.set_ciphers(":".join(SSL_CIPHERS))
self._remote_server_conn.sock = context.wrap_socket( self._remote_server_conn.sock = context.wrap_socket(
self._remote_server_conn.sock, self._remote_server_conn.sock,
server_hostname=self.hostname) server_hostname=self.hostname)