Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global socks proxy support #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/single-threaded-proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def parse_args():
help='where to store and load generated certificates')
arg_parser.add_argument('--onion-tor-socks-proxy', dest='onion_tor_socks_proxy',
default=None, help='host:port of tor socks proxy, used only to connect to .onion sites')
arg_parser.add_argument('--global-socks-proxy', dest='global_socks_proxy',
default=None, help='host:port of socks proxy, used to connect to all sites (overrides --onion-tor-socks-proxy')
arg_parser.add_argument('--version', action='version',
version="warcprox {}".format(warcprox.__version__))
arg_parser.add_argument('-v', '--verbose', dest='verbose', action='store_true')
Expand Down
5 changes: 5 additions & 0 deletions warcprox/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ def _build_arg_parser(prog):
default=None, help=(
'host:port of tor socks proxy, used only to connect to '
'.onion sites'))
arg_parser.add_argument(
'--global-socks-proxy', dest='global_socks_proxy',
default=None, help=(
'host:port of socks proxy, used to connect to '
'all sites (overrides --onion-tor-socks-proxy)'))
arg_parser.add_argument(
'--crawl-log-dir', dest='crawl_log_dir', default=None, help=(
'if specified, write crawl log files in the specified '
Expand Down
11 changes: 10 additions & 1 deletion warcprox/mitmproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,16 @@ def _determine_host_port(self):

def _connect_to_remote_server(self):
# Connect to destination
if self.onion_tor_socks_proxy_host and self.hostname.endswith('.onion'):
if self.global_socks_proxy_host:
self.logger.info(
"using socks proxy at %s:%s to connect to %s",
self.global_socks_proxy_host,
self.global_socks_proxy_port or 1080, self.hostname)
self._remote_server_sock = socks.socksocket()
self._remote_server_sock.set_proxy(
socks.SOCKS5, addr=self.global_socks_proxy_host,
port=self.global_socks_proxy_port, rdns=True)
elif self.onion_tor_socks_proxy_host and self.hostname.endswith('.onion'):
self.logger.info(
"using tor socks proxy at %s:%s to connect to %s",
self.onion_tor_socks_proxy_host,
Expand Down
9 changes: 9 additions & 0 deletions warcprox/warcproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,15 @@ def __init__(
WarcProxyHandler.onion_tor_socks_proxy_host = options.onion_tor_socks_proxy
WarcProxyHandler.onion_tor_socks_proxy_port = None

if options.global_socks_proxy:
try:
host, port = options.global_socks_proxy.split(':')
WarcProxyHandler.global_socks_proxy_host = host
WarcProxyHandler.global_socks_proxy_port = int(port)
except ValueError:
WarcProxyHandler.global_socks_proxy_host = options.global_socks_proxy
WarcProxyHandler.global_socks_proxy_port = None

http_server.HTTPServer.__init__(
self, server_address, WarcProxyHandler, bind_and_activate=True)

Expand Down