Get a Pentest and security assessment of your IT network.

Cyber Security

HTTP Proxy Authentication

TL;DR

This guide shows how to add authentication (username and password) when connecting through an HTTP proxy server for tunneling, using common tools like SSH and curl. We’ll cover setting up SSH config files and passing credentials with curl.

SSH Tunneling with Proxy Authentication

  1. Edit your SSH configuration file: Open ~/.ssh/config in a text editor. If the file doesn’t exist, create it.
    nano ~/.ssh/config
  2. Add a host entry for your proxy: This tells SSH how to connect through the proxy.
    Host myproxy
     Hostname your.proxy.server
     User your_username
     ProxyCommand nc -X connect -x your.proxy.server:8080 %h %p

    Replace:

    • myproxy with a name you choose for the proxy connection.
    • your.proxy.server with the actual hostname or IP address of your proxy server.
    • your_username with your username for the proxy.
    • 8080 with the port number your HTTP proxy uses.
  3. Add a host entry for the target server: Configure SSH to use the proxy when connecting to your final destination.
    Host targetserver
     Hostname your.target.server
     User your_target_username
     ProxyCommand ssh myproxy nc %h %p

    Replace:

    • targetserver with a name for the target server connection.
    • your.target.server with the hostname or IP address of the target server.
    • your_target_username with your username on the target server.
  4. Connect to the target server: Now you can connect using SSH as normal.
    ssh targetserver

    SSH will prompt you for your proxy password when connecting through myproxy, and then for your target server password.

curl with HTTP Proxy Authentication

  1. Using the command line: Pass your username and password directly in the curl command.
    curl -x http://your_username:[email protected]:8080 https://www.example.com

    Replace:

    • your_username with your proxy username.
    • your_password with your proxy password.
    • your.proxy.server with the hostname or IP address of your proxy server.
    • 8080 with the port number your HTTP proxy uses.
  2. Using environment variables: Set the http_proxy and https_proxy environment variables.
    export http_proxy=http://your_username:[email protected]:8080
    curl https://www.example.com

    This will use the proxy with authentication for all curl requests.

  3. Using a .netrc file: Store your credentials in a ~/.netrc file (securely!).
    machine your.proxy.server login your_username password your_password

    Then use the following curl command:

    curl -x http://your.proxy.server https://www.example.com

    Ensure the ~/.netrc file has appropriate permissions (e.g., chmod 600 ~/.netrc) to protect your credentials.

Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation