# UMDCTF 2023
---
###### tags: `CTF`
## 1. Terps Ticketing System
***Description: Welcome to the Terps Ticketing System! We're currently giving out tickets for the UMDCTF going on right now. Just enter some information and grab your ticket!***

Thử nhập `name` và `email` thì website chuyển hướng đến một `Ticket` ngẫu nhiên

Đáp vào BurpSuite

Website render `Ticket` theo giá trị biến `num` truyền vào nên mình thử Brute Force giá trị của biến `num`. Mình thấy giá trị của `num` không bao giờ vượt quá 1000 nên Brute Force từ 1 đến 1000

Payload `num = 0` có độ dài response khá lớn nên mình kiểm tra thử

Okay Flag = `UMDCTF{d0nt_b3_@n_id0r_@lw@ys_s3cur3_ur_tick3ts}`
## 2. pop calc

Website cho một máy tính như trên, ctrl+u để đọc source code
```javascript=
const expressionInput = document.getElementById('expression');
function appendToExpression(value) {
expressionInput.value += value;
}
function clearExpression() {
expressionInput.value = '';
}
function calculate() {
provided = expressionInput.value
const xhr = new XMLHttpRequest();
xhr.open('POST', '/', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
expressionInput.value = xhr.responseText
};
xhr.onerror = function () {
expressionInput.value = "[ERROR]"
};
xhr.send("calc="+provided);
}
```
Hàm `calculate` sử dụng phương thức `XMLHttpRequest` để POST dữ liệu từ biến `provided` lên server. Ném vào BurpSuite

Trông khá quen đúng không, thử thêm dấu `{` xem

Okay đây là lỗ hổng SSTI. Thử với payload `{{7*'7'}}`

Nó hoạt động, vậy có thể xác định được server đang sử dụng `Jinja2` hoặc `Twig`. Thử tìm một vài payload trên [HackTricks](https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection), mình tìm được payload sau:
```
{{ namespace.__init__.__globals__.os.popen('ls').read() }}
```

`cat flag.txt` là done

Flag = `UMDCTF{wh3n_an_app_giv3s_u_ssti_p0p_calc}`