Skip to content

Commit

Permalink
auto remote port
Browse files Browse the repository at this point in the history
  • Loading branch information
ab77 committed Jul 20, 2018
1 parent fe9a57c commit 9765828
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 118 deletions.
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,29 @@ EOF
&& mkdir -p /home/tunnel/.ssh\
&& cat ~/.ssh/authorized_keys > /home/tunnel/.ssh/authorized_keys

* download `random_tcp_port` script and set permissions
* create splash script and set permissions

wget -O /home/tunnel/random_tcp_port https://raw.githubusercontent.com/ab77/proxy-socks/master/extra/random_tcp_port
chmod +x /home/tunnel/random_tcp_port
chown tunnel:tunnel -hR /home/tunnel
```
cat << EOF > /home/tunnel/splash.sh
#!/bin/sh
echo '+--------------------------+'
echo '| |'
echo '| Nothing to see here... |'
echo '| |'
echo '+--------------------------+'
EOF
chmod +x /home/tunnel/splash.sh
chown tunnel:tunnel -hR /home/tunnel
```

* update sshd config and restart the service

```
cat << EOF >> /etc/ssh/sshd_config
Match User tunnel
ForceCommand /home/tunnel/random_tcp_port
ForceCommand /home/tunnel/splash.sh
EOF
service ssh restart
Expand All @@ -69,10 +79,10 @@ service ssh restart

|OS|release|
|---|---|
|Windows|[latest](https://github.com/ab77/proxy-socks/releases/download/v1.0.2/proxy-socks-setup-1.0.2.exe), [1.0.1](https://github.com/ab77/proxy-socks/releases/download/v1.0.1/proxy-socks-setup-1.0.1.exe), [1.0.0](https://github.com/ab77/proxy-socks/releases/download/v1.0.0/proxy-socks-setup-1.0.0.exe)|
|Linux (AppImage)|[latest](https://github.com/ab77/proxy-socks/releases/download/v1.0.2/proxy-socks-1.0.2-x86_64.AppImage), [1.0.1](https://github.com/ab77/proxy-socks/releases/download/v1.0.1/proxy-socks-1.0.1-x86_64.AppImage), [1.0.0](https://github.com/ab77/proxy-socks/releases/download/v1.0.0/proxy-socks-1.0.0-x86_64.AppImage)|
|Linux (Snap)|[latest](https://github.com/ab77/proxy-socks/releases/download/v1.0.2/proxy-socks_1.0.2_amd64.snap), [1.0.1](https://github.com/ab77/proxy-socks/releases/download/v1.0.1/proxy-socks_1.0.1_amd64.snap), [1.0.0](https://github.com/ab77/proxy-socks/releases/download/v1.0.0/proxy-socks_1.0.0_amd64.snap)|
|Mac OS X|[latest](https://github.com/ab77/proxy-socks/releases/download/v1.0.2/proxy-socks-1.0.2.dmg), [1.0.1](https://github.com/ab77/proxy-socks/releases/download/v1.0.1/proxy-socks-1.0.1.dmg), [1.0.0](https://github.com/ab77/proxy-socks/releases/download/v1.0.0/proxy-socks-1.0.0.dmg)|
|Windows|[latest](https://github.com/ab77/proxy-socks/releases/download/v1.0.3/proxy-socks-setup-1.0.3.exe), [1.0.2](https://github.com/ab77/proxy-socks/releases/download/v1.0.2/proxy-socks-setup-1.0.2.exe), [1.0.1](https://github.com/ab77/proxy-socks/releases/download/v1.0.1/proxy-socks-setup-1.0.1.exe), [1.0.0](https://github.com/ab77/proxy-socks/releases/download/v1.0.0/proxy-socks-setup-1.0.0.exe)|
|Linux (AppImage)|[latest](https://github.com/ab77/proxy-socks/releases/download/v1.0.3/proxy-socks-1.0.3-x86_64.AppImage), [1.0.2](https://github.com/ab77/proxy-socks/releases/download/v1.0.2/proxy-socks-1.0.2-x86_64.AppImage), [1.0.1](https://github.com/ab77/proxy-socks/releases/download/v1.0.1/proxy-socks-1.0.1-x86_64.AppImage), [1.0.0](https://github.com/ab77/proxy-socks/releases/download/v1.0.0/proxy-socks-1.0.0-x86_64.AppImage)|
|Linux (Snap)|[latest](https://github.com/ab77/proxy-socks/releases/download/v1.0.3/proxy-socks_1.0.3_amd64.snap), [1.0.2](https://github.com/ab77/proxy-socks/releases/download/v1.0.2/proxy-socks_1.0.2_amd64.snap), [1.0.1](https://github.com/ab77/proxy-socks/releases/download/v1.0.1/proxy-socks_1.0.1_amd64.snap), [1.0.0](https://github.com/ab77/proxy-socks/releases/download/v1.0.0/proxy-socks_1.0.0_amd64.snap)|
|Mac OS X|[latest](https://github.com/ab77/proxy-socks/releases/download/v1.0.3/proxy-socks-1.0.3.dmg), [1.0.2](https://github.com/ab77/proxy-socks/releases/download/v1.0.2/proxy-socks-1.0.2.dmg), [1.0.1](https://github.com/ab77/proxy-socks/releases/download/v1.0.1/proxy-socks-1.0.1.dmg), [1.0.0](https://github.com/ab77/proxy-socks/releases/download/v1.0.0/proxy-socks-1.0.0.dmg)|

* launch the app and note the forwarded port number

Expand All @@ -85,13 +95,13 @@ service ssh restart
# netstat -a -n -p | grep LISTEN | grep 127.0.0.1
tcp 0 0 127.0.0.1:{zzz} 0.0.0.0:* LISTEN 1234/sshd: tunnel

root@ubuntu:# curl ifconfig.co
root@ubuntu:# curl -4 ifconfig.co
{xxx}
root@ubuntu:# curl --socks5 127.0.0.1:{zzz} ifconfig.co

root@ubuntu:# curl -4 --socks5 127.0.0.1:{zzz} ifconfig.co
{yyy}

> you should see a random TCP port and two different public IPs if everything is working correctly
> you should see a random TCP port and two different public IPs if everything is working correctly
# next steps
Every new installation of the app, will attempt to make a connection to the remote server and forward a random port to the local proxy. These proxies can then be exposed on the public interface of the server using [HAProxy](http://www.haproxy.org/), [OpenVPN](https://openvpn.net/) or a combination of tools.
Expand Down
70 changes: 0 additions & 70 deletions extra/random_tcp_port

This file was deleted.

35 changes: 1 addition & 34 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,36 +223,6 @@ function save_config() {
fs.writeFileSync(configFile, JSON.stringify(app_config, null, 4), 'utf8')
}

function get_port(event) {
return new Promise(function (resolve, reject) {
let conn = new Client()
try {
conn.on('ready', function() {
conn.exec('', function(err, stream) {
if (err) {
console.log(err)
event.sender.send('stopped-client', err.message)
}
stream.on('close', function() {
conn.end()
}).on('data', function(data) {
resolve(parseInt(data.toString()))
}).on('error', function(err) {
console.log(err)
event.sender.send('stopped-client', err.message)
})
})
}).on('error', function(err) {
console.log(err)
event.sender.send('stopped-client', err.message)
}).connect(ssh_config)
} catch (err) {
console.log(err)
event.sender.send('stopped-client', err.message)
}
})
}

function forward_port(event, rport, lport) {
let net = require('net')
conn = new Client()
Expand Down Expand Up @@ -336,10 +306,7 @@ ipc.on('start-client', (event) => {
}
server.on('listening', function() {
let lport = server.address().port
let p = get_port(event)
p.then(function(rport) {
forward_port(event, rport, lport)
})
forward_port(event, 0, lport)
})
} else {
event.sender.send('started-client', 'Already running')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "proxy-socks",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"description": "Electron app containing SOCKSv5 server and SSH2 client",
"author": {
Expand Down

0 comments on commit 9765828

Please sign in to comment.