Agent: Set proxy schema for different OS

This commit is contained in:
Ilija Lazoroski 2021-10-06 15:13:09 +02:00
parent cafd983622
commit 87b882cb45
1 changed files with 22 additions and 16 deletions

View File

@ -22,6 +22,7 @@ from infection_monkey.config import GUID, WormConfiguration
from infection_monkey.network.info import local_ips
from infection_monkey.transport.http import HTTPConnectProxy
from infection_monkey.transport.tcp import TcpProxy
from infection_monkey.utils.environment import is_windows_os
requests.packages.urllib3.disable_warnings()
@ -113,27 +114,32 @@ class ControlClient(object):
logger.info("Starting tunnel lookup...")
proxy_find = tunnel.find_tunnel(default=default_tunnel)
if proxy_find:
proxy_address, proxy_port = proxy_find
logger.info("Found tunnel at %s:%s" % (proxy_address, proxy_port))
from infection_monkey.utils.environment import is_windows_os
logger.info(f"requests version: {requests.__version__}")
import urllib3
logger.info(f"urllib3 version: {urllib3.__version__}")
if is_windows_os():
ControlClient.proxies["https"] = "http://%s:%s" % (
proxy_address,
proxy_port,
)
else:
ControlClient.proxies["https"] = PROXY_SCHEMA % (proxy_address, proxy_port)
logger.info(ControlClient.proxies)
ControlClient.set_proxies(proxy_find)
return ControlClient.find_server()
else:
logger.info("No tunnel found")
return False
@staticmethod
def set_proxies(proxy_find):
"""
Note: Proxy schema changes! When upgrading to newer python version or
when urllib3 and requests are updated there is possibility that the proxy
schema is changed.
https://github.com/psf/requests/issues/5297
https://github.com/psf/requests/issues/5855
"""
proxy_address, proxy_port = proxy_find
logger.info("Found tunnel at %s:%s" % (proxy_address, proxy_port))
if is_windows_os():
ControlClient.proxies["https"] = "http://%s:%s" % (
proxy_address,
proxy_port,
)
else:
ControlClient.proxies["https"] = PROXY_SCHEMA % (proxy_address, proxy_port)
logger.info(ControlClient.proxies)
@staticmethod
def keepalive():
if not WormConfiguration.current_server: