Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use piping-server to foward TCP port with socat/netcat #689

Open
bhzhu203 opened this issue Jul 30, 2022 · 14 comments
Open

How to use piping-server to foward TCP port with socat/netcat #689

bhzhu203 opened this issue Jul 30, 2022 · 14 comments
Labels
question Further information is requested

Comments

@bhzhu203
Copy link

I know that piping-server can for foward VNC stream with special NoVNC. But how to do with common TCP stream ? Thanks

@nwtgck
Copy link
Owner

nwtgck commented Aug 1, 2022

Suppose you have two machines named "server host" which serves 22 port and "client host", and you want to use the 22 port in the server host as a new 2222 port in the client host. The following commands forward the 22 port in the server host to the 2222 port in the client host.

curl -sSN https://ppng.io/aaa | nc localhost 22 | curl -sSNT - https://ppng.io/bbb
curl -sSN https://ppng.io/bbb | nc -lp 2222 | curl -sSNT - https://ppng.io/aaa

See Secure TCP tunnel from anywhere with curl and nc for single connection - DEV Community for more details.

@nwtgck nwtgck added the question Further information is requested label Aug 1, 2022
@m2acgi
Copy link

m2acgi commented Sep 15, 2022

You need go-piping-tunnel https://github.com/nwtgck/go-piping-tunnel

@nwtgck
Copy link
Owner

nwtgck commented Sep 16, 2022

Thanks @m2acgi

piping-tunnel is available on cross-platform including Windows and Android. It provides multiplexers, yamux and pmux. pmux is experimental. piping-tunnel is useful in enviroments which doesn't have netcat and curl.

@bhzhu203
Copy link
Author

yamux having something to improve :
if the connection disconnected , it is hard to reconnect

@nwtgck
Copy link
Owner

nwtgck commented Sep 27, 2022

@bhzhu203 Thanks for the report. I'd like to know details.

Could you see "Universal end-to-end encryption over SSH" section in Secure TCP tunnel from anywhere with curl and nc for single connection? It describes another way to multiplex TCP connection over SSH. The way requires SSH server and SSH client.

@bhzhu203
Copy link
Author

bhzhu203 commented Sep 30, 2022

@bhzhu203 Thanks for the report. I'd like to know details.

Could you see "Universal end-to-end encryption over SSH" section in Secure TCP tunnel from anywhere with curl and nc for single connection? It describes another way to multiplex TCP connection over SSH. The way requires SSH server and SSH client.

The command only can be used one time (can not reconnect), and can not be used next time (the command line can not be reused)

curl -sSN dns.abc.com:9999/12 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - dns.abc.com:9999/13
[INFO] Waiting for 1 receiver(s)...
2022/09/30 17:04:01 [ERR] yamux: keepalive failed: i/o deadline reached
Error: keepalive timeout
keepalive timeout[INFO] A receiver was connected.
[INFO] Start sending to 1 receiver(s)...
[INFO] Sent successfully!
curl: (23) Failed writing body (0 != 12)
root@sg-v:~# /usr/bin/yamux --help
Multiplexer

Usage:
  /usr/bin/yamux [flags]

Examples:

yamux localhost 80
yamux -l 8080


Flags:
  -h, --help       help for /usr/bin/yamux
  -l, --listen     listens
  -u, --udp        UDP
  -U, --unixsock   uses Unix-domain socket
      --version    show version
root@sg-v:~# curl -sSN dns.abc.com:9999/12 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - dns.abc.com:9999/13
[INFO] Waiting for 1 receiver(s)...
curl: (18) transfer closed with outstanding read data remaining
Error: EOF
EOF[INFO] A receiver was connected.
[INFO] Start sending to 1 receiver(s)...
[INFO] Sent successfully!
root@sg-v:~# curl -sSN dns.abc.com:9999/12 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - dns.abc.com:9999/13
[INFO] 1 receiver(s) has/have been connected.
[INFO] Start sending to 1 receiver(s)...
curl: (18) transfer closed with outstanding read data remaining
Error: EOF
EOF[INFO] Sent successfully!
root@sg-v:~# curl -sSN dns.abc.com:9999/12 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - dns.abc.com:9999/13
[INFO] 1 receiver(s) has/have been connected.
[INFO] Start sending to 1 receiver(s)...
[INFO] Sent successfully!
curl: (18) transfer closed with outstanding read data remaining
Error: EOF
EOFroot@sg-v:~# curl -sSN dns.abc.com:9999/12 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - dns.abc.com:9999/13
[INFO] 1 receiver(s) has/have been connected.
[INFO] Start sending to 1 receiver(s)...
curl: (18) transfer closed with outstanding read data remaining
Error: EOF
EOF[INFO] Sent successfully!

client command line :

curl -sSN 10.10.10.196:8888/13 | /usr/bin/yamux -ul 2000 | curl -sSNT - 10.10.10.196:8888/12

server : piping-server-rust 0.12.1

@nwtgck
Copy link
Owner

nwtgck commented Sep 30, 2022

Could you tell me what you want to do?
Do you want to forward an UDP port not TCP?
What is the URL of Piping Server?

@bhzhu203
Copy link
Author

bhzhu203 commented Oct 7, 2022

Could you tell me what you want to do? Do you want to forward an UDP port not TCP? What is the URL of Piping Server?

port forawrd for an UDP VPN (peervpn)

UDP port

tmp.selleroa.top:9999

@nwtgck
Copy link
Owner

nwtgck commented Oct 7, 2022

The command should be like the following.

# server host (in VPN)
curl -sSN https://ppng.io/aaa656 | yamux -u tmp.selleroa.top 9999 | curl -sSNT - https://ppng.io/bbb656
# client host (localhost:19999 is forwared VPN endpont)
curl -sSN https://ppng.io/bbb656 | yamux -ul 19999 | curl -sSNT - https://ppng.io/aaa656

You can replace https://ppng.io with your Piping Server.

@bhzhu203
Copy link
Author

There is a problems of "Another sender has been connected" on piping-server-rust

root@sg-v:~# curl -sSN https://p.seller.top/nick1 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - https://p.seller.top/nick123
2022/10/10 19:36:42 [ERR] yamux: Invalid protocol version: 91
Error: invalid protocol version
invalid protocol version[ERROR] Another sender has been connected on '/nick123'.
root@sg-v:~# curl -sSN https://p.seller.top/nick1 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - https://p.seller.top/nick123
2022/10/10 19:36:50 [ERR] yamux: Invalid protocol version: 91
Error: invalid protocol version
invalid protocol version[ERROR] Another sender has been connected on '/nick123'.
root@sg-v:~# curl -sSN https://p.seller.top/nick1 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - https://p.seller.top/nick123
2022/10/10 19:36:53 [ERR] yamux: Invalid protocol version: 91
Error: invalid protocol version
invalid protocol version[ERROR] Another sender has been connected on '/nick123'.
root@sg-v:~# curl -sSN https://p.seller.top/nick1 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - https://p.seller.top/nick123
2022/10/10 19:36:55 [ERR] yamux: Invalid protocol version: 91
Error: invalid protocol version
invalid protocol version[ERROR] Another sender has been connected on '/nick123'.
root@sg-v:~# curl -sSN https://p.seller.top/nick1 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - https://p.seller.top/nick123
2022/10/10 19:37:16 [ERR] yamux: Invalid protocol version: 91
Error: invalid protocol version
invalid protocol version[ERROR] Another sender has been connected on '/nick123'.
root@sg-v:~# curl -sSN https://p.seller.top/nick1 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - https://p.seller.top/nick123
2022/10/10 19:37:22 [ERR] yamux: Invalid protocol version: 91
Error: invalid protocol version
invalid protocol version[ERROR] Another sender has been connected on '/nick123'.

@nwtgck
Copy link
Owner

nwtgck commented Oct 10, 2022

@bhzhu203 Could you give the command in the other side? It might have a problem.

@bhzhu203
Copy link
Author

bhzhu203 commented Oct 11, 2022

@bhzhu203 Could you give the command in the other side? It might have a problem.

Doesn't need run other side.

run this "curl -sSN https://p.seller.top/nick1 | /usr/bin/yamux -u 127.0.0.1 2000 | curl -sSNT - https://p.seller.top/nick123" on one side , then "Ctrl+C" and rerun , will reproduce this

The server is piping-server-rust

@nwtgck
Copy link
Owner

nwtgck commented Oct 11, 2022

@bhzhu203 Thanks. You need to change the both paths nick1 and nich123. The original Piping Server (this repository) can detect TCP closes but Rust version doesn't.

@bhzhu203
Copy link
Author

bhzhu203 commented Oct 24, 2022

It is not easy to make the two connections reconnect automatically, while one line disconnected or be reset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants