fddR1p official writeup (itc{flags} rev)
you get two files, vault and flag.enc. no source, no remote, you run it on your own box.
$ file ./vault
./vault: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked,
interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=5096f9ab0498f1820b69be07edd118e551594f09,
for GNU/Linux 3.2.0, stripped
$ checksec ./vault

stripped PIE with everything turned on. strings ./vault gives you nothing useful: no /proc, no TracerPid, no flag format.
so just run it, no debugger, and look at it from outside.
$ ./vault &
[1] 1161
$ cat /proc/1161/status | grep -i TracerPid

half a second in and vault is already being traced, by pid 1162, which we didn’t start. so there’s a second process, and it grabbed the ptrace slot before we could. keep that in mind, the whole challenge is built around it.
the two gates#
into IDA to see what runs before that second process appears. two functions decide whether you get anywhere.
_BOOL8 sub_144E()
{
int v1; // [rsp+Ch] [rbp-154h]
FILE *stream; // [rsp+10h] [rbp-150h]
size_t n; // [rsp+18h] [rbp-148h]
char s[16]; // [rsp+20h] [rbp-140h] BYREF
char filename[32]; // [rsp+30h] [rbp-130h] BYREF
char s1[264]; // [rsp+50h] [rbp-110h] BYREF
unsigned __int64 v7; // [rsp+158h] [rbp-8h]
v7 = __readfsqword(0x28u);
sub_13A9("u*(59u)?6<u).;./)", 17, 90, filename);
stream = fopen(filename, "r");
if ( !stream )
return 1;
sub_13A9(&unk_2028, 10, 90, s);
n = strlen(s);
v1 = 0;
while ( fgets(s1, 256, stream) )
{
if ( !strncmp(s1, s, n) )
{
v1 = atoi(&s1[n]);
break;
}
}
fclose(stream);
return v1 != 0;
}
this is why strings had nothing. both the path and the field name go through sub_13A9, a one-line xor with key 90 (0x5a). xor "u*(59u)?6<u).;./)" with 0x5a and you get /proc/self/status. the second blob is TracerPid:. so gate1 is the usual check: read your own status file, find TracerPid:, fail if it isn’t 0. if it can’t even open the file it also counts as traced.
alone, this takes ten seconds to beat. break after the call, set rax to 0, done. we did exactly that while testing it. but nothing calls gate1 directly.
_BOOL8 sub_15FC()
{
return sub_144E() || (unsigned int)sub_159F(&loc_1608, &loc_1618 - &loc_1608) != 199568121;
}
gate2 calls gate1, then hashes its own code from loc_1608 to loc_1618 and compares against 199568121 (0x0BE52AF9).
__int64 __fastcall sub_159F(__int64 a1, unsigned __int64 a2)
{
unsigned int v3; // [rsp+1Ch] [rbp-14h]
unsigned __int64 i; // [rsp+20h] [rbp-10h]
v3 = -2128831035;
for ( i = 0; i < a2; ++i )
v3 = 16777619 * (*(unsigned __int8 *)(a1 + i) ^ v3);
return v3;
}
FNV-1a. -2128831035 is 0x811C9DC5 as unsigned, the offset basis, and 16777619 is the FNV prime. the 16 bytes it hashes are the call to gate1 plus the test/je on its result, which is exactly where you’d put a breakpoint to patch the result. gdb’s breakpoint is a real 0xCC written into the code, the hash reads that byte like any other, the value changes and gate2 fails. no error message either, it exits silently just like when gate1 fails.
get past both and vault moves on to the part that matters.
a process with no file#
__int64 __fastcall sub_1661(int a1, __int64 a2)
{
unsigned int i; // [rsp+18h] [rbp-98h]
int fd; // [rsp+1Ch] [rbp-94h]
unsigned int v5; // [rsp+24h] [rbp-8Ch]
_BYTE *ptr; // [rsp+28h] [rbp-88h]
char *envp; // [rsp+30h] [rbp-80h] BYREF
int pipedes[2]; // [rsp+38h] [rbp-78h] BYREF
char *argv[5]; // [rsp+40h] [rbp-70h] BYREF
char buf; // [rsp+6Bh] [rbp-45h]
int v11; // [rsp+6Ch] [rbp-44h]
char s[16]; // [rsp+70h] [rbp-40h] BYREF
char v13[40]; // [rsp+80h] [rbp-30h] BYREF
unsigned __int64 v14; // [rsp+A8h] [rbp-8h]
v14 = __readfsqword(0x28u);
v11 = 398731935;
ptr = malloc((unsigned int)n);
if ( !ptr )
return 0xFFFFFFFFLL;
for ( i = 0; i < (unsigned int)n; ++i )
ptr[i] = s[(i & 3) - 4] ^ byte_4040[i];
fd = memfd_create(&unk_2082, 1);
if ( fd >= 0 )
{
if ( write(fd, ptr, (unsigned int)n) == (unsigned int)n )
{
free(ptr);
v5 = fork();
if ( !v5 )
{
snprintf(s, 0x10u, "%d", a1);
snprintf(v13, 0x20u, "%lx", a2);
argv[0] = (char *)&unk_2082;
argv[1] = s;
argv[2] = v13;
argv[3] = nullptr;
envp = nullptr;
fexecve(fd, argv, &envp);
_exit(1);
}
close(pipedes[0]);
prctl(1499557217, v5, 0, 0, 0);
write(pipedes[1], "x", 1);
close(pipedes[1]);
close(fd);
return v5;
}
else
{
free(ptr);
close(fd);
return 0xFFFFFFFFLL;
}
}
else
{
free(ptr);
return 0xFFFFFFFFLL;
}
}
this is why there’s no second binary next to vault.
s[(i & 3) - 4] reads weird, a negative index into s before anything is in it. look at the stack layout: v11 is at rbp-44h, s at rbp-40h. s[-4..-1] is v11. IDA picked s as the base for the access, so you get a negative index, but what the loop really does is ((char *)&v11)[i & 3]. the key is 398731935 = 0x17C42A9F, bytes 9f 2a c4 17, repeated over byte_4040.
so in order: xor-decode the payload onto the heap, memfd_create an anonymous fd, write the payload into it, fork, child fexecves straight from the fd. the parent calls prctl(PR_SET_PTRACER, child). with Yama in restricted mode a process can only trace its own descendants, and the child wants to trace its parent, so vault has to allow that child explicitly.
the guardian never touches a filesystem path. it’s bytes in vault’s data, then bytes in a memfd, then a running process.
the obvious move doesn’t work#
first thing anyone tries, attach gdb to vault:
$ gdb -q -p 1161

warning: process 1161 is already traced by process 1162. ptrace: Operation not permitted.
a process can have one tracer at a time, and root doesn’t change that. the guardian took the slot as soon as both gates passed, and it keeps it until it dies. so vault itself is off limits. attach to the guardian instead:
$ gdb -q -p 1162
nobody is tracing that one, so it attaches fine.
the key is on the guardian’s heap#
pwndbg> heap

two chunks besides top. the 0x290 one is glibc’s tcache struct, ignore it. the 0x30 one is what we want: a 32-byte malloc plus the 8-byte header, rounded up to 16, gives exactly 0x30. 32 bytes is also the size of an AES-256 key.
pwndbg> x/64xb 0x641ff3bfe290

32 bytes, high entropy, nothing printable. that’s the AES-256 key.
there was a real hole here in an earlier build, so here’s how it got closed. /proc/<guardian_pid>/exe is readable by anyone with the same uid, no ptrace needed, so you can cp the guardian binary right out of /proc. then objdump -s -j .rodata on it:
32 more high-entropy bytes, and you got them without attaching to anything. compare them with the key above, they share nothing. that’s only half of what it needs. the other half is in vault’s memory, and the guardian reads it with process_vm_readv after it seizes vault. that read goes through the same Yama check that stopped our gdb -p. no seize, no second half, no key.
if you think the .rodata bytes are the key, try decrypting with them first.
decrypt#
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
key = bytes.fromhex("c16a5fa0dc9afa637d6f53511f46fa859347ae8d6c7a54568b614d9827656f26")
data = open("flag.enc", "rb").read()
print(AESGCM(key).decrypt(data[:12], data[12:], None))flag.enc is a 12-byte nonce, then the AES-256-GCM ciphertext with the tag at the end. with the right key it decrypts. with the wrong key you get InvalidTag, and GCM won’t hand you half-decrypted garbage either. there’s no if (key_ok) print(flag) to patch anywhere in the binary. you need the real key, and the only process holding it is the guardian.
flag: itc{fddr1p_s31z3_th3_s1bl1ng_dr41n_1ts_h34p}
further reading#
- ptrace(2),
PTRACE_SEIZE/PTRACE_O_EXITKILL: man7.org/linux/man-pages/man2/ptrace.2.html - Yama and
PR_SET_PTRACER: kernel.org/doc/html/latest/admin-guide/LSM/Yama.html memfd_create(2): man7.org/linux/man-pages/man2/memfd_create.2.htmlprocess_vm_readv(2): man7.org/linux/man-pages/man2/process_vm_readv.2.html