233 words
1 minute
TCTT25 Programming: lucky_but_unlucky
lucky_but_unlucky - Programming Challenge
โจทย์
Challenge นี้เป็นโจทย์ Programming ที่ใช้ Python เกี่ยวกับ luck/random
ดาวน์โหลดไฟล์
| ไฟล์ | ดาวน์โหลด |
|---|---|
| lucky_but_unlucky.py | 📥 Download |
| All Files | 📦 GitHub Folder |
ไฟล์ที่ได้รับ
lucky_but_unlucky.py
import randomimport timerandom.seed(time.time())
def run(lucky): try: x = str(random.getrandbits(32)) a = input('Enter Your Name: ').replace('lucky' + x, '') if a != 'lucky' + x: return 'Exit #' + x b = input('Enter Number #1: ').translate(str.maketrans('0123456789', '#' * 10)) c = input('Enter Number #2: ').translate(str.maketrans('0123456789', '#' * 10)) if not b.isdigit() or not c.isdigit(): return 'Exit #' + str(random.getrandbits(32)) d = int(b) + lucky e = int(c) + lucky if d == e: return 'Exit #' + str(random.getrandbits(32)) f = float(b) - lucky g = float(c) - lucky if f != g: return 'Exit #' + str(random.getrandbits(32)) h = int(b) i = lucky + 1 if h == i: return 'Exit #' + str(random.getrandbits(32)) j = hash(h) k = hash(i) if j != k: return 'Exit #' + str(random.getrandbits(32)) #----------------------- return 'flag{xxx}' #----------------------- except: return 'Exit #' + str(random.getrandbits(32))
if __name__ == "__main__": count = 0 while True: count += 1 if count > 313: break lucky = random.getrandbits(32) answer = run(lucky % 10000) print(answer) if 'flag' in answer: break else: print('Lucky #' + str(lucky))แนวทางวิเคราะห์
- อ่านโค้ด - มี logic checks หลายชั้นที่ต้องผ่าน
- หา vulnerability - translate ทำให้ตัวเลขกลายเป็น # แต่ต้อง isdigit() ด้วย
- Exploit - หาค่าที่ผ่านทุก condition พร้อมกัน
ประเด็นที่ควรดู
- Random seed ใช้
time.time()สามารถ predict ได้ - translate เปลี่ยนตัวเลขเป็น
# - Logic contradiction ระหว่าง conditions
Tools ที่อาจใช้
| Tool | วัตถุประสงค์ |
|---|---|
| Python | รันและแก้โค้ด |
| pwntools | สำหรับ scripting exploit |
สถานะ
⏳ รอ Writeup - Challenge นี้ยังไม่มี writeup อย่างละเอียดใน repository
Credits
Challenge from TCTT25 | GitHub Repo
TCTT25 Programming: lucky_but_unlucky
https://blog.lukkid.dev/posts/tctt25-prog-lucky-but-unlucky/