渗透过程
信息收集
拿到目的靶机的IP,先进行端口扫描
┌──(root㉿kali)-[~/桌面]
└─# nmap -A -sV -sC -Pn 10.129.165.49
Starting Nmap 7.92 ( https://nmap.org ) at 2022-08-22 15:31 CST
Nmap scan report for 10.129.165.49
Host is up (0.51s latency).
Not shown: 998 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 61:e4:3f:d4:1e:e2:b2:f1:0d:3c:ed:36:28:36:67:c7 (RSA)
| 256 24:1d:a4:17:d4:e3:2a:9c:90:5c:30:58:8f:60:77:8d (ECDSA)
|_ 256 78:03:0e:b4:a1:af:e5:c2:f9:8d:29:05:3e:29:c9:f2 (ED25519)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
|_http-title: Welcome
|_http-server-header: Apache/2.4.29 (Ubuntu)
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.92%E=4%D=8/22%OT=22%CT=1%CU=30215%PV=Y%DS=2%DC=T%G=Y%TM=6303312
OS:8%P=x86_64-pc-linux-gnu)SEQ(SP=FD%GCD=1%ISR=10E%TI=Z%CI=Z%II=I%TS=A)OPS(
OS:O1=M537ST11NW7%O2=M537ST11NW7%O3=M537NNT11NW7%O4=M537ST11NW7%O5=M537ST11
OS:NW7%O6=M537ST11)WIN(W1=FE88%W2=FE88%W3=FE88%W4=FE88%W5=FE88%W6=FE88)ECN(
OS:R=Y%DF=Y%T=40%W=FAF0%O=M537NNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS
OS:%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=
OS:Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=
OS:R%O=%RD=0%Q=)T7(R=N)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%R
OS:UCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S)
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
TRACEROUTE (using port 21/tcp)
HOP RTT ADDRESS
1 605.11 ms 10.10.16.1
2 280.22 ms 10.129.165.49
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 87.95 seconds
开放22 ssh远程登录端口及80 web服务端口 。因为22 端口存在认证,所以从 80端口入手
访问80端口后,使用小插件获取到 login 的敏感路径。(叫 findsomething ,火狐及Chrome均可在对应插件商店下载)
访问 http://10.129.165.49/cdn-cgi/login/
发现可使用 guest 账户登录。猜测进去后越权。
越权
网站使用 cookie 辨识用户,我们 按下 F12 ,发现了 user 与 role 参数。
尝试更改role 为admin,再访问 upload 功能,仍无法打开。则应是通过 user 的值判断是否为admin
那 admin 的值为多少呢? 我第一反应是爆破。后来发现思路不对。正确思路是在 account 模块下发现了
更改下方 user 的 value 值为 34322 ,访问 upload 模块
上马
文件上传点,上传一个php 的反弹shell。
先对 shell 文件做个修改
vim /usr/share/webshells/php/php-reverse-shell.php
修改下方 IP 为本机 IP
上传时,同时开启监听本地 1234端口
上传成功。一般情况下,上传之后的文件存放在 upload、uploads 目录下。这里我没有爆破目录,直接猜到了。
访问 http://10.129.165.49/uploads/php-reverse-shell.php,即可收到 shell
/var/www/html 是web服务的目录,即网站的目录。这里的 cdn-cgi目录下发现了 db.php
里面有连接数据库的账户密码
robert
M3g4C0rpUs3r!
在 robert 的用户目录,发现他的flag
提权
目前拿到的是www-data用户的bash的执行权(执行 whoami 查看即可)、以及一个数据库的账户密码。因为在 home 文件夹下也发现了此账户,猜测此账户的密码与其数据库密码一致。
配合最开始的ssh端口,想到先远程登录一下。
ssh robert@10.129.165.49
如果未开放ssh端口,仍要从 bash 转换为 伪终端,可执行
python3 -c "import pty; pty.spawn('/bin/bash')"
再切换到 robert账户。不过这样不稳定,毕竟还是基于反弹shell连接的。
如何获得 root 权限呢?在上一个靶场中,我们通过查看 powershell 的命令记录获取到 Administrator 的权限,这次使用 SUID提权的方法。
知识补充
在本靶场中,如果 robert 用户执行的文件从属于 root 用户,就会用root用户的权限执行文件。
查看 robert 所在用户组、搜索可执行的文件、并查看该文件有没有 s 权限
robert@oopsie:~$ id
uid=1000(robert) gid=1000(robert) groups=1000(robert),1001(bugtracker)
robert@oopsie:~$ find / -group bugtracker 2>/dev/null
/usr/bin/bugtracker
robert@oopsie:~$ ls -al /usr/bin/bugtracker
-rwsr-xr-- 1 root bugtracker 8792 Jan 25 2020 /usr/bin/bugtracker
发现是有的。那么执行此文件。
robert@oopsie:~$ /usr/bin/bugtracker
------------------
: EV Bug Tracker :
------------------
Provide Bug ID: 123
---------------
cat: /root/reports/123: No such file or directory
发现此程序的本质是 cat /root/reports/
那么 cat 命令就是用root执行的。
现在如果我们伪装 "/bin/bash" 为 cat,那么执行 此程序时,就会获得 root权限的shell
在 tmp 目录下新建了一个 cat 文件,并赋予执行权限。cat 文件的内容是打开命令终端
将 tmp 目录写入环境变量。那么 cat 命令 就被我们更新成 /bin/bash 了。root执行cat时,会打开终端
执行 bugtracker 文件
flag 文件在 /root/root.txt
此时查看就不要用 cat 了。因为被我们替换了。换 more
题目答案
1、With what kind of tool can intercept web traffic?
proxy
2、What is the path to the directory on the webserver that returns a login page?
/cdn-cgi/login
3、What can be modified in Firefox to get access to the upload page?
cookie
4、What is the access ID of the admin user?
34322
5、On uploading a file, what directory does that file appear in on the server?
/uploads
6、What is the file that contains the password that is shared with the robert user?
db.php
7、What executible is run with the option "-group bugtracker" to identify all files owned by the bugtracker group?
find
8、Regardless of which user starts running the bugtracker executable, what's user privileges will use to run?
root
9、What SUID stands for?
Set owner User ID
10、What is the name of the executable being called in an insecure manner?
cat
11、Submit user flag
f2c74ee8db7983851ab2a96a44eb7981
12、Submit root flag
af13b0bee69f8a877c3faf667f7beacf