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

Brute (Solved After Event)

PreviousFree Flag (280 pts)NextWeb V1 (Solved After Event)

Last updated 18 days ago

No need fancy crypto trick just brute, and btw you have to spin up to 20 vms with multi-thread to make it fast enough

Kita diberikan beberapa file, yakni chall.py dan out.txt. Pada chall.py, terdapat kode sumber dari soal.

chall.py

from Crypto.Util.number import getStrongPrime
m = int.from_bytes("IFEST13{???}".encode())
p = getStrongPrime(1024)
q = getStrongPrime(1024)
n = p * q
print(f'{pow(m, 0x10001, n)}\n{n}\n{p >> 40}')

Intinya, ini adalah RSA biasa yang nilai p nya di-leak kecuali untuk 40-bit terakhirnya. Kita perlu me-recover 40-bit terakhir ini. Ini adalah textbook case dari Coppersmith Attack. Saya sebenarnya baru mempelajari ini dari , maka dari itu saya ucapkan terima kasih sebanyak-banyaknya atas ilmunya :).

Langsung saja ke kode solvernya. Challenge ini membutuhkan fungsi small_roots yang ada di SageMath. Oleh karena itu, kita bisa gunakan website untuk menjalankan kode Sage, atau menggunakan library Sage di dalam Python seperti yang saya praktekkan di bawah ini. Penjelasan pada kode saya terakan pada komentar-komentar yang ada.

solve.py

from sage.all import *
from Crypto.Util.number import *

# Remember when you have to use Python's int, Sage's Integer, and Sage PolynomialRing's IntegerMod as datatype

c = 10190308328132298810370792830407498649727116694895887482897571470790876671909417379902577324803848850655954471082089060952194185721425541632970106409477409460179454591137511596832421737353754768175974443794887211632429320728354925107321000890255988379005072889707213292319847199584075893238735146835736979402380614028245390503793552296747076984394930725251632591625471426901314091323869057780461687871597918704838734422002502048443745431116004254026457663052173884656414629831184831431248595040967979335625485086150017379359647307566607127100190320972594606082853976569219798608787775461446205014804326191379628416459
n = 22052867210059985056723988324723437469643935229284382742545572507193384098102119262228001598529023654073757846310755124262636633869347982051002191511240379141051585596043583392443536537486511985566413114358501620593150325155980714427378089922768898334419054390129931556129883835862579370606862267536439488040273973837168042166190169509259514869605813849934412879327376082076832835805173922914432614662509276644729233158638994237998916272949330215708015931366306430206836771702005645140291164351968902134211930508335582704492675362575695821618037439189132191250206861088835015459823510074661891457866577589023776648751
p_hi = 138398228938242977290956349154712526327465608129677172002562239407676097284597892604642541735116262199110899389173013415023231356739796256927576905061498760222434453315905920861684849512303589509164929424151033355318032546176479325956586655296074717479220347079941178337950508153135271887365359007
e = 65537
k_unknown_bits = 40
p_bit_length = 1024

# Get approximate value of p (with zero's on the last 40 bits)
p_approx = p_hi << k_unknown_bits
print(f"[*] 40 LSB bits of p_approx: {bin(p_approx)[2:][-40:]}")

# Define Ring mod n
R = PolynomialRing(Zmod(n), 'x_var')
x_var = R.gen()
poly = p_approx + x_var

# Upper bound for x_var is p_lo length (40 bits)
X_bound = 2**k_unknown_bits
beta = 0.5

# Find small roots
potential_p_lo_val = poly.small_roots(X=X_bound, beta=beta)
print(f"[*] Found {len(potential_p_lo_val)} small_roots values")
print(f"[*] small_roots = {potential_p_lo_val}")

# Go through all potential small roots
if not potential_p_lo_val:
	print("[-] No small_roots found. Exiting...")
else:
	for pos_p_lo in potential_p_lo_val:
		pos_p_lo = Integer(pos_p_lo)	# Change datatype from IntegerMod to Integer

		print(f"[*] Trying p_lo = {pos_p_lo}")
		
		# [1] Check if the candidate is within the boundary
		if not (0 <= pos_p_lo and pos_p_lo < X_bound):
			print("[-] Value of p_lo is out of bound")
			continue

		# [2] Check if the candidate calculates to the correct p
		pos_p = p_approx + pos_p_lo
		if (pos_p == 0) or (n % pos_p != 0):
			print("[-] Value of p_lo is incorrect")
			continue

		# [3] Decrypt the FLAG
		try:
			pos_q = n // pos_p
			print(f"[+] Found p = {pos_p}")
			print(f"[+] Found q = {pos_q}")
			phi = (pos_p-1)*(pos_q-1)
			d = pow(e,-1,phi)
			m = pow(c, d, n)
			print(f"[+] Found FLAG = {long_to_bytes(m)}")
		except Exception as e:
			print(e)
$ sage solve.py 
[*] 40 LSB bits of p_approx: 0000000000000000000000000000000000000000
[*] Found 1 small_roots values
[*] small_roots = [307143335585]
[*] Trying p_lo = 307143335585
[+] Found p = 152170461981203044138580018222860171483648966011319086281925541493885759794755162431349753477795696871153242407332984090443277761904418330933031999427592715238374825598836399798707345437190519440709648421600461011378200951012246668647337881673386523838896883273245813392691473455180122270797417610128336314017
[+] Found q = 144922128269440884691193969052877601732271046027622462528828552456155401850440263363345392437840052541235167051587359051054314257198207968414263143150653184708601934583747143373284586518556647550413291191561975196911578481725624854131586335162113599967650646081359560140388118421436124444909155273819195665103
[+] Found FLAG = b'happy_brute__as_long_as_possible_lol_it_wont_be_the_flag_isnt_it?'

Flag: IFEST13{happy_brute__as_long_as_possible_lol_it_wont_be_the_flag_isnt_it?}

🚩
🇮🇩
write-up milik tim Peserta
SageCell