Fred808 commited on
Commit
6c71751
·
verified ·
1 Parent(s): b9aa764

Upload 12 files

Browse files
Dockerfile ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:22.04
2
+
3
+ RUN apt-get update && apt-get install -y \
4
+ openssh-server \
5
+ dante-server \
6
+ iptables \
7
+ iproute2 \
8
+ net-tools \
9
+ curl \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Configure SSH
13
+ RUN mkdir -p /var/run/sshd
14
+ RUN useradd -m -s /bin/bash tunneluser
15
+
16
+ # Enable IP forwarding in /etc/sysctl.conf
17
+ RUN echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
18
+ RUN sysctl -p
19
+
20
+ WORKDIR /app
21
+
22
+ COPY . /app
23
+
24
+ RUN chmod +x entrypoint.sh
25
+
26
+ ENTRYPOINT ["./entrypoint.sh"]
27
+
28
+
README.md CHANGED
@@ -1,10 +1,110 @@
1
- ---
2
- title: NAT
3
- emoji: 🌖
4
- colorFrom: gray
5
- colorTo: gray
6
- sdk: docker
7
- pinned: false
8
- ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Docker-based SSH/SOCKS5 NAT Gateway
2
+
3
+ This project sets up a Docker-based NAT Gateway using SSH Tunneling and a SOCKS5 proxy on Ubuntu 22.04. It allows you to route traffic from connected clients through the SOCKS5 proxy, which then uses the Docker host's internet connection with NAT.
4
+
5
+ ## Project Structure
6
+
7
+ ```
8
+ project-root/
9
+ ├── Dockerfile
10
+ ├── docker-compose.yml
11
+ ├── entrypoint.sh
12
+ ├── ssh-config/ # Contains SSH server configuration and authorized_keys
13
+ │ ├── sshd_config
14
+ │ ├── authorized_keys
15
+ │ └── tunneluser_key # Private key for SSH tunneling (KEEP THIS SECURE!)
16
+ │ └── tunneluser_key.pub # Public key for SSH tunneling
17
+ └── socks5-config/ # Contains Dante SOCKS5 server configuration
18
+ └── danted.conf
19
+ ```
20
+
21
+ ## Setup Instructions
22
+
23
+ ### Prerequisites
24
+
25
+ - Docker installed on your Ubuntu 22.04 host.
26
+ - `docker-compose` (version 1.29.2 or later) installed.
27
+ - An SSH client on your local machine (e.g., OpenSSH client).
28
+
29
+ ### 1. Clone the Repository (or create files manually)
30
+
31
+ If you receive a zip file, extract it. Otherwise, create the `project-root` directory and the files as structured above.
32
+
33
+ ### 2. Build and Run the Docker Container
34
+
35
+ Navigate to the `project-root` directory in your terminal and run:
36
+
37
+ ```bash
38
+ sudo docker-compose up --build -d
39
+ ```
40
+
41
+ This command will:
42
+ - Build the Docker image (`ssh-socks-nat-gateway`).
43
+ - Start the `nat-gateway` service in detached mode (`-d`).
44
+ - Map host port `2222` to container SSH port `22`.
45
+ - Map host port `1080` to container SOCKS5 port `1080`.
46
+ - Mount the `ssh-config` and `socks5-config` directories into the container.
47
+ - Run the container with `NET_ADMIN` and `SYS_MODULE` capabilities and in privileged mode for network manipulation.
48
+
49
+ ### 3. Verify the Setup
50
+
51
+ 1. **Check Docker Container Status:**
52
+ ```bash
53
+ sudo docker ps
54
+ ```
55
+ You should see `nat-gateway` running.
56
+
57
+ 2. **Check Container Logs:**
58
+ ```bash
59
+ sudo docker logs nat-gateway
60
+ ```
61
+ Look for messages indicating:
62
+ - "Detected public IP: YOUR_HOST_PUBLIC_IP" (the IP of your host machine)
63
+ - "SSH server started."
64
+ - "Dante SOCKS5 server started."
65
+ - "iptables NAT rules set."
66
+
67
+ ### 4. Connect and Use the SOCKS5 Proxy
68
+
69
+ **A. Get your Host's Public IP:**
70
+
71
+ ```bash
72
+ curl ifconfig.me
73
+ ```
74
+
75
+ Let's assume your host's public IP is `YOUR_HOST_PUBLIC_IP` (e.g., `13.218.209.184`).
76
+
77
+ **B. Establish an SSH Tunnel (SOCKS5 Proxy) on your Local Machine:**
78
+
79
+ Open a terminal on your local machine (the one you want to route traffic from) and run the following command. Make sure you are in the directory where `tunneluser_key` is located.
80
+
81
+ ```bash
82
+ ssh -i ssh-config/tunneluser_key -N -D 1080 tunneluser@YOUR_HOST_PUBLIC_IP -p 2222
83
+ ```
84
+
85
+ - `-i ssh-config/tunneluser_key`: Specifies the private key for authentication.
86
+ - `-N`: Do not execute a remote command (just forward ports).
87
+ - `-D 1080`: Creates a dynamic SOCKS5 proxy on your local machine at port `1080`.
88
+ - `tunneluser@YOUR_HOST_PUBLIC_IP`: Connects to the SSH server on your Docker host as `tunneluser`.
89
+ - `-p 2222`: Specifies the SSH port on your Docker host.
90
+
91
+ Keep this terminal window open; the SSH tunnel will remain active as long as this command is running.
92
+
93
+ **C. Configure Your Applications/System to Use the SOCKS5 Proxy:**
94
+
95
+ Now, configure your applications (e.g., web browser, chat client) or your system's network settings to use a SOCKS5 proxy at `localhost:1080`.
96
+
97
+ - **Proxy Type:** SOCKS5
98
+ - **Proxy Host/Address:** `127.0.0.1` or `localhost`
99
+ - **Proxy Port:** `1080`
100
+
101
+ Once configured, all traffic from those applications will be routed through the SSH tunnel to your Docker container, and then out to the internet via the Docker host's NAT.
102
+
103
+ ## Important Notes
104
+
105
+ - **Security:** Running Docker containers in `privileged` mode and with `NET_ADMIN`/`SYS_MODULE` capabilities grants significant power. Ensure your host system is secure. The `tunneluser_key` is your private key; **keep it secure and do not share it.**
106
+ - **IP Forwarding:** The `Dockerfile` and `entrypoint.sh` ensure IP forwarding is enabled and iptables rules are set up for NAT.
107
+ - **SOCKS5 vs. VPN:** This setup provides a SOCKS5 proxy, which is application-layer. It's not a full VPN tunnel that routes all system traffic by default. You need to configure applications to use the proxy. For system-wide routing, you might need additional tools (e.g., `proxychains` on Linux/macOS) or system-level proxy settings.
108
+
109
+ This setup provides a flexible and relatively easy-to-manage NAT gateway using SSH and SOCKS5.
110
+
docker-compose.yml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ nat-gateway:
5
+ build: .
6
+ container_name: nat-gateway
7
+ privileged: true
8
+ cap_add:
9
+ - NET_ADMIN
10
+ - SYS_MODULE
11
+ ports:
12
+ - "2222:22" # SSH port
13
+ - "1080:1080" # SOCKS5 port
14
+ volumes:
15
+ - ./ssh-config:/app/ssh-config
16
+ - ./socks5-config:/app/socks5-config
17
+ restart: unless-stopped
18
+ networks:
19
+ - nat-network
20
+
21
+ networks:
22
+ nat-network:
23
+ driver: bridge
24
+ ipam:
25
+ config:
26
+ - subnet: 172.20.0.0/16
27
+
entrypoint.sh ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ echo "Starting SSH/SOCKS5 NAT Gateway setup..."
6
+
7
+ # Enable IP forwarding
8
+ echo 1 > /proc/sys/net/ipv4/ip_forward
9
+
10
+ # Fetch public IP
11
+ PUBLIC_IP=$(curl -s ifconfig.me)
12
+ if [ -z "$PUBLIC_IP" ]; then
13
+ echo "Error: Could not fetch public IP. Exiting."
14
+ exit 1
15
+ fi
16
+ echo "Detected public IP: $PUBLIC_IP"
17
+
18
+ # Configure SSH server
19
+ cp /app/ssh-config/sshd_config /etc/ssh/sshd_config
20
+ chmod 600 /etc/ssh/sshd_config
21
+
22
+ # Generate SSH host keys if they don't exist
23
+ if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
24
+ ssh-keygen -A
25
+ fi
26
+
27
+ # Start SSH service in debug mode and redirect output to a file
28
+ /usr/sbin/sshd -D -e -f /etc/ssh/sshd_config > /var/log/sshd_debug.log 2>&1 &
29
+
30
+ echo "SSH server started."
31
+
32
+ # Configure Dante SOCKS5 server
33
+ cp /app/socks5-config/danted.conf /etc/danted.conf
34
+ chmod 644 /etc/danted.conf
35
+
36
+ # Start Dante SOCKS5 server
37
+ /usr/sbin/danted -D &
38
+
39
+ echo "Dante SOCKS5 server started."
40
+
41
+ # Apply iptables rules for NAT using iptables-legacy
42
+ iptables-legacy -t nat -A POSTROUTING -o eth0 -j MASQUERADE
43
+ iptables-legacy -A FORWARD -i eth0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
44
+ iptables-legacy -A FORWARD -i eth0 -o eth0 -j ACCEPT
45
+
46
+ echo "iptables NAT rules set."
47
+
48
+ # Keep the container running
49
+ exec tail -f /dev/null
50
+
51
+
socks5-config/danted.conf ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dante SOCKS5 server configuration
2
+
3
+ # Log to syslog
4
+ logoutput: syslog
5
+
6
+ # Internal interface (where clients connect)
7
+ internal: 0.0.0.0 port = 1080
8
+
9
+ # External interface (where traffic exits)
10
+ external: eth0
11
+
12
+ # Authentication method
13
+ socksmethod: none
14
+
15
+ # Client rules
16
+ clientmethod: none
17
+
18
+ # User for running the daemon
19
+ user.privileged: root
20
+ user.unprivileged: nobody
21
+
22
+ # Client access rules
23
+ client pass {
24
+ from: 0.0.0.0/0 to: 0.0.0.0/0
25
+ log: error
26
+ }
27
+
28
+ # SOCKS rules
29
+ socks pass {
30
+ from: 0.0.0.0/0 to: 0.0.0.0/0
31
+ log: error
32
+ }
33
+
ssh-config/authorized_keys ADDED
@@ -0,0 +1 @@
 
 
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD6KDZV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MP9BIu2N6JRodQwviWzs/LzJcRJcSO0Ty8+q/01C9fpzv4NuoqpI4
48
+ tpIhjCpNUQUAAAATdWJ1bnR1QDgyMmJmY2ZlMzY0MQ==
49
+ -----END OPENSSH PRIVATE KEY-----
ssh-config/new_tunneluser_key.pub ADDED
@@ -0,0 +1 @@
 
 
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD6KDZVagru9IX8RpmmWm2hsp7sONnHQyBtQ8W46nvDmGEKSZIKUp1kAZGEkIYx2AoVjSCZepAfXzeHOr2PB/FHS0zBuDf8kAazzWOJNvcb4u/wVkAWUtKkEo68gQyewP107R8FcTednTUP10IrEGHw/esguWNcC+Exal/Nrl9XQd9xMPlnbteKu/vIIrWt1z3Tq4VEDFrbCT4o66Ek7BPPZ1Zsqiz2RVCdWaS74FzbL/tqafMVNooMfhCYkAON8ZQ4ocGdCh+/FZLluWXHNT53/b9bbN9aQnDEPYDhG+vEbOekD9yYGhSAFYLflSNXkHiMfDj6ahN3R5kuQrX6zMl4UzjKs3yqhH8P8RIP9JHEKnu+Q/gLpLcYMB+g8Kc/OUfZlNPCIcC0XpXWHg4j7MQZxVNFnKQTEIBY1LwN5WRuPq70klv3GQmZwILu1RhQxKOEd/cEt2TOb4KFJS+5nHU5QSezGIuH3mP7xq0PZFp3XdJDODWUPPbMTkZbwCYansP37ujKKffBy0NHdw3FBAelhlObcnf3Nsy6QMUmUuS8Y2uaERDhUXW4Hy7UK13sonpCgGse2XVs7GJVOVy1J5JgnVDSaXpg5z60AkthWLhK+UMCcrTCech5Ru80ujQIy7mYPzlfRme3UAd7YEOWbWMW9y7GXYsbH5eiEyXfRa8tQQ== ubuntu@822bfcfe3641
ssh-config/sshd_config ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Port 22
2
+ ListenAddress 0.0.0.0
3
+
4
+ # Authentication
5
+ PermitRootLogin no
6
+ PasswordAuthentication no
7
+ ChallengeResponseAuthentication no
8
+ UsePAM yes
9
+ X11Forwarding yes
10
+ PrintMotd no
11
+ AcceptEnv LANG LC_*
12
+ Subsystem sftp /usr/lib/openssh/sftp-server
13
+
14
+ # Allow only specific user for tunneling
15
+ AllowUsers tunneluser
16
+
17
+ # Configure for SOCKS5 proxy
18
+ GatewayPorts yes
19
+ AllowTcpForwarding yes
20
+ PermitTunnel no
21
+
22
+ # Path to authorized_keys for tunneluser
23
+ AuthorizedKeysFile /app/ssh-config/authorized_keys
24
+
ssh-config/tunneluser_key ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN OPENSSH PRIVATE KEY-----
2
+ b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn
3
+ NhAAAAAwEAAQAAAgEA1/+cgBAILpQUbDrEL7dcE265Fo70CXGQ8TVB4A9IL1OC7ul93SWM
4
+ HU0VaE/bUz5KQPSRUdwRT04kUO1zyecdDQGwd3erbPj3/a5QcaxomqjpHYHjSWzBE8xEdY
5
+ +jLvFlbOLHWREBxwN1EQp+6zLcmjJj1HZzYtwsLAWofsBaaj77+5Hat9maL8GyjN7Tz7wT
6
+ pPRVXZVnBDUtW9ErF/khW5BcwaKaOZzKnrfIhfraJUiE7/lV1F3xuhbU/HEgvjE1Jt6ckZ
7
+ FAjrJWFeWFo2sd9JEu/JTW1z/DPxUim7i+TLXLaMA1YMfruJ9KElAT/k2cPMAPZFH4AU8E
8
+ bjJoKzykD3br5+wjC8mgr4J2iNlgv9/Q4Q5PZFSnnt+Wz+dfzhy0W/0qtgOKslghbzvXdH
9
+ M9ta5uzAVtuirPW++mE24TuUHPX01nck6avv+uGBx4U5Uzx4Qj3E8IPZ3sZOMewLZZy8/B
10
+ jEVj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PPvBOk9FVdlWcENS1b0SsX+SFbkFzBopo5nMqet8iF+tolSITv+VXUXfG6FtT8cSC+MTUm3pyRkUCOslYV5YWjax30kS78lNbXP8M/FSKbuL5MtctowDVgx+u4n0oSUBP+TZw8wA9kUfgBTwRuMmgrPKQPduvn7CMLyaCvgnaI2WC/39DhDk9kVKee35bP51/OHLRb/Sq2A4qyWCFvO9d0cz21rm7MBW26Ks9b76YTbhO5Qc9fTWdyTpq+/64YHHhTlTPHhCPcTwg9nexk4x7AtlnLz8GMRWPFvRi+XD5v/eoBXmGXVeWuVDpdgAsDiu/miGsDAKvt/DpiLa8oqIsRu8JQFIqrIQ8fFg59lVH3+aC2wLsIYK4VJ05q1CUmFV0x6lZTSjgYa5E9ZJJ6CnRPqYZegXq2R2N5a4bRBtrlwF1DWce/mzYAmrVlD+GqXwdr1PxCpgO3LMwLMDBxBd2AilksD4HDEr/S1xGgq4to1Rm4Jw== ubuntu@f0730ff40bea
test_report.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SSH/SOCKS5 NAT Gateway Application Test Report
2
+
3
+ ## Overview
4
+
5
+ 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.
6
+
7
+ ## Setup and Initial Issues
8
+
9
+ 1. **Unzipping and Initial Review:** The provided `ssh-socks-nat-gateway-setup.zip` file was unzipped, and the `README.md` was reviewed for setup instructions.
10
+
11
+ 2. **Docker Compose Installation:** Initially, `docker-compose` was not found on the system. It was installed using `sudo apt-get install -y docker-compose`.
12
+
13
+ 3. **Docker Service Issues:** After installing `docker-compose`, attempts to build and run the Docker container failed with `Error while fetching server API version: Not supported URL scheme http+docker`. This was resolved by starting the Docker service using `sudo systemctl start docker`.
14
+
15
+ 4. **Persistent SSH Connection Issues (`kex_exchange_identification`):** The primary challenge encountered was the inability to establish an SSH connection to the `nat-gateway` container, consistently resulting in `kex_exchange_identification: Connection closed by remote host` errors. Initial debugging steps included:
16
+ * Checking permissions of `tunneluser_key`.
17
+ * Inspecting `sshd_config` inside the container.
18
+ * Restarting the container and SSH service.
19
+ * Enabling verbose SSH logging (which did not yield useful output).
20
+
21
+ ## Debugging and Resolution of SSH Issues
22
+
23
+ Through iterative debugging, the following key issues were identified and resolved:
24
+
25
+ 1. **`authorized_keys` Path Mismatch:** The `entrypoint.sh` script was copying `sshd_config` from `/app/ssh-config` to `/etc/ssh/sshd_config` inside the container. However, the `sshd_config` file itself was configured to look for `authorized_keys` in `/home/tunneluser/.ssh/authorized_keys`. This mismatch prevented proper authentication. This was initially addressed by modifying the `sshd_config` inside the running container, but the changes were overwritten by `entrypoint.sh` upon container restart.
26
+
27
+ 2. **Dynamic `sshd_config` Overwrite:** It was discovered that the `entrypoint.sh` script was overwriting the `sshd_config` file with a version that did not include the necessary `AuthorizedKeysFile /app/ssh-config/authorized_keys` directive. This meant that any manual changes to the `sshd_config` within the container were lost.
28
+
29
+ 3. **Missing `tunneluser`:** A critical issue was the absence of the `tunneluser` inside the Docker container. The SSH server requires this user to exist for authentication. This was confirmed by `sudo docker exec nat-gateway id tunneluser` returning `no such user`.
30
+
31
+ **Resolution Steps:**
32
+
33
+ * **Dockerfile Modification:** The `Dockerfile` was modified to include `RUN useradd -m -s /bin/bash tunneluser` to ensure the `tunneluser` is created during the image build process.
34
+ * **`sshd_config` in Source:** The `sshd_config` file in the source directory (`./ssh-config/sshd_config`) was permanently updated to include `AuthorizedKeysFile /app/ssh-config/authorized_keys`.
35
+ * **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_keys` to ensure it was correctly mounted into the container.
36
+ * **Rebuilding and Restarting:** The Docker container was rebuilt and restarted using `sudo docker-compose up --build -d` to apply all changes.
37
+
38
+ After these modifications, an SSH connection to the container's internal IP (`172.20.0.2`) was successfully established using the new key.
39
+
40
+ ## SOCKS5 Proxy Functionality Test
41
+
42
+ With the SSH tunnel successfully established, the SOCKS5 proxy functionality was tested.
43
+
44
+ **Test Command:**
45
+
46
+ ```bash
47
+ 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
48
+ curl --socks5 localhost:1080 ifconfig.me
49
+ ```
50
+
51
+ **Result:**
52
+
53
+ 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.
54
+
55
+ ## Conclusion
56
+
57
+ 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.
58
+
59
+