SSH/SOCKS5 NAT Gateway Application Test Report
Overview
This report details the process of setting up, debugging, and testing the provided SSH/SOCKS5 NAT Gateway application. The application, packaged as a Docker Compose project, aims to establish an SSH tunnel and a SOCKS5 proxy to route traffic through the Docker host's internet connection with NAT.
Setup and Initial Issues
Unzipping and Initial Review: The provided
ssh-socks-nat-gateway-setup.zipfile was unzipped, and theREADME.mdwas reviewed for setup instructions.Docker Compose Installation: Initially,
docker-composewas not found on the system. It was installed usingsudo apt-get install -y docker-compose.Docker Service Issues: After installing
docker-compose, attempts to build and run the Docker container failed withError while fetching server API version: Not supported URL scheme http+docker. This was resolved by starting the Docker service usingsudo systemctl start docker.Persistent SSH Connection Issues (
kex_exchange_identification): The primary challenge encountered was the inability to establish an SSH connection to thenat-gatewaycontainer, consistently resulting inkex_exchange_identification: Connection closed by remote hosterrors. Initial debugging steps included:- Checking permissions of
tunneluser_key. - Inspecting
sshd_configinside the container. - Restarting the container and SSH service.
- Enabling verbose SSH logging (which did not yield useful output).
- Checking permissions of
Debugging and Resolution of SSH Issues
Through iterative debugging, the following key issues were identified and resolved:
authorized_keysPath Mismatch: Theentrypoint.shscript was copyingsshd_configfrom/app/ssh-configto/etc/ssh/sshd_configinside the container. However, thesshd_configfile itself was configured to look forauthorized_keysin/home/tunneluser/.ssh/authorized_keys. This mismatch prevented proper authentication. This was initially addressed by modifying thesshd_configinside the running container, but the changes were overwritten byentrypoint.shupon container restart.Dynamic
sshd_configOverwrite: It was discovered that theentrypoint.shscript was overwriting thesshd_configfile with a version that did not include the necessaryAuthorizedKeysFile /app/ssh-config/authorized_keysdirective. This meant that any manual changes to thesshd_configwithin the container were lost.Missing
tunneluser: A critical issue was the absence of thetunneluserinside the Docker container. The SSH server requires this user to exist for authentication. This was confirmed bysudo docker exec nat-gateway id tunneluserreturningno such user.
Resolution Steps:
- Dockerfile Modification: The
Dockerfilewas modified to includeRUN useradd -m -s /bin/bash tunneluserto ensure thetunneluseris created during the image build process. sshd_configin Source: Thesshd_configfile in the source directory (./ssh-config/sshd_config) was permanently updated to includeAuthorizedKeysFile /app/ssh-config/authorized_keys.- Key Regeneration and Update: A new SSH key pair (
new_tunneluser_key) was generated, and the public key was copied to/home/ubuntu/ssh-socks-nat-gateway-setup/project-root/ssh-config/authorized_keysto ensure it was correctly mounted into the container. - Rebuilding and Restarting: The Docker container was rebuilt and restarted using
sudo docker-compose up --build -dto apply all changes.
After these modifications, an SSH connection to the container's internal IP (172.20.0.2) was successfully established using the new key.
SOCKS5 Proxy Functionality Test
With the SSH tunnel successfully established, the SOCKS5 proxy functionality was tested.
Test Command:
ssh -i /home/ubuntu/ssh-socks-nat-gateway-setup/project-root/ssh-config/new_tunneluser_key -N -D 1080 tunneluser@35.224.208.195 -p 2222
curl --socks5 localhost:1080 ifconfig.me
Result:
The curl command, when routed through the SOCKS5 proxy, successfully returned the public IP address of the sandbox environment (35.224.208.195). This confirms that the SOCKS5 proxy is functioning correctly and routing traffic as expected.
Conclusion
The SSH/SOCKS5 NAT Gateway application has been successfully set up, debugged, and tested. The primary challenges were related to SSH configuration within the Docker environment, specifically the authorized_keys path and the existence of the tunneluser. Once these issues were addressed, the SSH tunnel and SOCKS5 proxy functioned as intended, demonstrating the application's ability to route traffic through the Docker host.