Getting Access
Hack Responsibly.
Always ensure you have explicit permission to access any computer system before using any of the techniques contained in these documents. You accept full responsibility for your actions by applying any knowledge gained here.
TODO: description, methodology, and script prep for each section (issue #15)
Add description and methodology as needed for each section
Prep all code examples for scripting (replace IPs and ports with variables, etc.)
Ensure code examples' variables are appropriate for their respective programming language
Bind shells
Bind shells are used when the attacker connects directly to the victim.
socat
socat - TCP4:$victim_ip:$portEncrypted bind shell
To create an encrypted bind shell, first a self-signed certificate must be created. It must either be created on the victim machine, or transferred prior to using the bind shell.
openssl req -newkey rsa:2048 -nodes -keyout bind_shell.key -x509 -days 365 -out bind_shell.crt
cat bind_shell.key bind_shell.crt > bind_shell.pemThis command will create a new 2048-bit encryption key and certificate using the RSA algorithm. The certificate will be valid for 365 days. The key and certifcate information must be combined into one .pem file using cat.
Next, use socat to create the bind shell using this .pem certificate. verify=0 will be used to disable SSL verification. Since you are using SSL on port 443 you need to run the listener with sudo if the victim machine is running Linux.
Reverse Shells
Reverse shells are used when the attacker gets the victim machine to connect back to their machine. Useful when firewalls or other security devices prevent bind shells.
Reverse Shell as a Service - https://shell.now.sh
https://github.com/lukechilds/reverse-shell
Bash Reverse Shells
TCP:
UDP:
exec Reverse Shell
Python Reverse Shells
Using Socat UDP Listener
PHP Reverse Shell
PHP command injection webshell:
Ruby Reverse Shell
Telnet Reverse Shells
Netcat Reverse Shells
Socat Reverse Shell
-d increases verbosity of output
Golang Reverse Shell
Perl Reverse Shell
Awk Reverse Shell
NodeJS Reverse Shell
JavaScript Reverse Shell
Java Reverse Shell
C Reverse Shell
XTERM Reverse Shell
Meterpreter Reverse Shells
Linux Non-Staged reverse TCP
Linux Staged reverse TCP
Upgrading remote shells
After catching a shell through netcat, you are placed in a shell that has very limited functionality. If the remote machine has python or python3 installed you can easily upgrade to a fully functional TTY shell.
Note: To check if the shell is a TTY shell use the tty command.
Upgrade to fully interactive shell (python example):
When using some shells such as zsh or fish on the attacking machine your shell will break after you try to upgrade it using this method. Some of the things I have found that help mitigate this are:
Use
rlwrap nc -lvnpwhen setting up your listener,make sure not to put a space in your python pty command after the import,
type
stty size;stty raw -echo;fgall on one line.
Finally, as a last resort, you could just switch to bash instead when setting up your nc listener.
Other Languages:
Using "Script" to upgrade to a TTY
Upgrade from a basic shell to a bash TTY using script.
Using “Expect” To Get A TTY
If you’re lucky enough to have the Expect language installed just a few lines of code will get you a good enough TTY to run useful tools such as “ssh”, “su” and “login”.
Using socat
Another option is to upload the binary for socat to the victim machine and magically get a fully interactive shell. Download the appropriate binaries from https://github.com/andrew-d/static-binaries. Socat needs to be on both machines for this to work.
socat one-liner
This one-liner can be injected wherever you can get command injection for an instant reverse shell. Point the path to the binary to your local http server if internet access is limited on the victim.
Misc unsorted
Bash
Some versions of bash can send you a reverse shell (this was tested on Ubuntu 10.10):
Works more reliably when prefixed with
bash -c(thanks Ippsec!)
PERL
Here’s a shorter, feature-free version of the perl-reverse-shell:
There’s also an alternative PERL revere shell here. (broken link?)
Python
This was tested under Linux / Python 2.7:
PHP
This code assumes that the TCP connection uses file descriptor 3. This worked on my test system. If it doesn’t work, try 4, 5, 6…
If you want a .php file to upload, see the more featureful and robust php-reverse-shell.
Ruby
Netcat
Netcat is rarely present on production systems and even if it is there are several version of netcat, some of which don’t support the -e option.
If you have the wrong version of netcat installed, Jeff Price points out here that you might still be able to get your reverse shell back like this:
Java
xterm
One of the simplest forms of reverse shell is an xterm session. The following command should be run on the server. It will try to connect back to you (10.0.0.1) on TCP port 6001.
To catch the incoming xterm, start an X-Server (:1 – which listens on TCP port 6001). One way to do this is with Xnest (to be run on your system):
You’ll need to authorize the target to connect to you (command also run on your host):
Resources
If you like this content and would like to see more, please consider buying me a coffee!
Last updated