uaf4b - CakeCTF2021

uaf4b - CakeCTF2021(My solver) uaf4b - CakeCTF2021(Official GitHub) 方針 Use after Free によって関数ポインタをsystem関数で書き換える。 CAWSAY 構造体について 重要なのは、main.cの47〜50行目の構造体である。 freed chunkでは、fn_dialogueがfd、messageがbkに割り当てられる。 typedef struct { void (*fn_dialogue)(char*); char *message; } COWSAY; また、main.cの167〜171行目で、 cowsay->fn_dialogue(cowsay->message);が実行されることに留意しておく。 case 1: /* Use cowsay */ printf("[+] You're trying to call 0x%016lx\n", (addr)cowsay->fn_dialogue); cowsay->fn_dialogue(cowsay->message); break; malloced chunk 実際にmallocされたときのHeap領域は次の図のようになっている。 freed chunk 次に、freeすると、次の図のようになる。 system("/bin/sh")を呼び出す この2つの図を見るとわかるように、関数ポインタfn_dialogueの位置にfdが割り当てられている。 つまり、fn_dialogueをsystemに、COWSAY->message = /bin/shにすれば、 system("/bin/sh")が呼び出される。 Solver from pwn import * context(os = 'linux', arch = 'amd64') context.log_level = 'debug' io = process("....

2022-05-02 · 1 分 · Me