Skip to content

Commit

Permalink
1031
Browse files Browse the repository at this point in the history
  • Loading branch information
joizel committed Oct 31, 2017
1 parent 9945ec2 commit b084b62
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 205 deletions.
30 changes: 14 additions & 16 deletions docs/wargame/pwnable/lob1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
digraph foo {
a -> b -> c -> d -> e;

a [shape=box, label="argv[1]"];
a [shape=box, label="dummy * 260 + envp address"];
b [shape=box, color=lightblue, label="strcpy"];
c [shape=box, label="Buffer Overflow"];
d [shape=box, label="RET"];
e [shape=box, label="getenv address"];
d [shape=box, label="envp address"];
e [shape=box, label="dummy * 100 + shellcode"];
}


Expand Down Expand Up @@ -49,10 +49,10 @@ Vulnerabliity Vector
---------------
Buffer (256byte)
SFP (4byte)
RET (4byte) <- strcpy overflow
argc (4byte) <- 0x00000002
argv[0] (4byte) <- argv[0] 주소
argv[1] (4byte) <- argv[1] 주소
RET (4byte)
argc (4byte)
argv (4byte)
envp (4byte) <
---------------
HIGH
===============
Expand Down Expand Up @@ -102,7 +102,7 @@ exploit
|
환경 변수 주소값 확인
환경 변수 주소 값 확인
------------------------------------------------------------------------------------------------------------

다음과 같이 소스코드를 작성하여 shellcode 환경 변수에 대한 주소 값을 획득.
Expand Down Expand Up @@ -132,7 +132,7 @@ exploit
|
RET 주소를 환경 변수 주소로 덮어씌워 공격 진행
RET를 환경 변수 주소로 덮어씌워 공격 진행
------------------------------------------------------------------------------------------------------------


Expand All @@ -141,19 +141,17 @@ RET 주소를 환경 변수 주소로 덮어씌워 공격 진행
===============
LOW
---------------
Buffer (256byte) <- "\x90"*256
SFP (4byte) <- "\x90"*4
RET (4byte) <- shellcode 환경 변수 주소
argc (4byte) <- 0x00000002
argv[0] (4byte) <- argv[0] 주소
argv[1] (4byte) <- argv[1] 주소
Buffer (256byte) <- dummy
SFP (4byte) <- dummy
RET (4byte) <- envp address
envp (4byte) <- nopsled shellcode
---------------
HIGH
===============
|
오버플로우시 RET 주소를 환경 변수 주소로 변경하여 해당 쉘코드가 실행되도록 한다.
오버플로우시 RET 주소를 환경 변수 주소로 덮어씌워 해당 쉘코드가 실행되도록 한다.

.. code-block:: console
Expand Down
91 changes: 52 additions & 39 deletions docs/wargame/pwnable/lob10.rst
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
============================================================================================================
[lob] vampire
[redhat-lob] (10) skeleton
============================================================================================================

.. uml::

@startuml

start

:Source Analysis;

:Memory Structure;
.. graphviz::

:Segmentation fault;

:argv[1]의 주소값 변경;

:RET 주소를 argv[1] 주소로 변경하여 공격 진행;

stop
digraph foo {
a -> b -> c -> d -> e;

@enduml
a [shape=box, label="argv[1] value"];
b [shape=box, color=lightblue, label="strcpy"];
c [shape=box, label="Buffer Overflow"];
d [shape=box, label="RET"];
e [shape=box, label="program name address"];
}

|
Source Analysis
Source Code
============================================================================================================


해당 문제 소스코드는 다음과 같습니다.

.. code-block:: c
/*
The Lord of the BOF : The Fellowship of the BOF
- skeleton
- argv hunter
*/
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -85,21 +70,22 @@ Source Analysis
|
Memory Structure
Vulnerabliity Vector
============================================================================================================

스택 메모리 공간에 다음과 같이 들어가게 됩니다.
스택 메모리 공간에 다음과 같이 들어가게 된다.

.. code-block:: console
================
LOW
----------------
Buffer (40byte) <- strcpy
Buffer (40byte)
SFP (4byte)
RET (4byte)
argc (4byte)
argv (4byte)
RET (4byte) <- strcpy overflow
argc (4byte) <- 0x00000002
argv[0] (4byte) <- argv[0] address
argv[1] (4byte) <- argv[1] address
----------------
HIGH
================
Expand All @@ -109,12 +95,19 @@ Memory Structure
Segmentation fault
============================================================================================================

버퍼오버플로우가 일어나는 지점을 확인합니다.
Overflow condition

- environ을 초기화하여 환경 변수 사용를 통한 쉘코드 삽입이 불가능하다.
- argv[1] value의 47번째 문자가 "\\xbf"이어야 함
- argv[1] 값의 길이가 48 미만 이어야 함
- argv[0] 값, argv[1] 값을 초기화하여 argv[0], argv[1] 주소로 버퍼오버플로우를 진행할 수 없다.

※ 시작시 bash2 명령을 입력하고 bash2 쉘 상태에서 진행해야 합니다.

.. code-block:: console
※ 시작시 bash2 명령을 입력하고 bash2 쉘 상태에서 진행.
$ bash2
$ ./skeleton `python -c 'print "a"*47'`
stack is still your friend.
Expand All @@ -129,12 +122,12 @@ exploit
============================================================================================================


argv[0]에 쉘코드 삽입
프로그램 이름에 쉘코드 삽입
------------------------------------------------------------------------------------------------------------

기존에 사용한 쉘코드에는 \x2f 값이 있기 때문에 정상적으로 쉘코드가 동작하지 않습니다.
기존에 사용한 쉘코드에는 "\\x2f" 값이 있기 때문에 정상적으로 쉘코드가 동작하지 않는다.

\x2f가 없는 쉘코드로 파일명을 생성하도록 합니다.
"\\x2f"가 없는 쉘코드로 파일명을 생성하도록 한다.

.. code-block:: console
Expand Down Expand Up @@ -179,10 +172,30 @@ argv[0]에 쉘코드 삽입
program명 주소를 찾아서 RET로 덮어씌우면 됩니다.


RET 주소를 argv[0] 주소로 변경하여 공격 진행
RET 주소를 프로그램 이름이 존재하는 주소로 변경하여 공격 진행
------------------------------------------------------------------------------------------------------------

filename : nop(100 byte) + shellcode (39 byte)
.. code-block:: console
================
LOW
----------------
Buffer (40byte) <- "\x90"*40
SFP (4byte) <- "\x90"*4
RET (4byte) <- 프로그램 이름 주소
argc (4byte) <- 0x00000002
argv[0] (4byte) <- argv[0] 주소
argv[1] (4byte) <- argv[1] 주소
......
program name <- 프로그램 이름
NULL
----------------
HIGH
================
|
filename : nop(100 byte) + shellcode(39 byte)

argv[1] : nop(44 byte) + argv[0] address

Expand Down
54 changes: 33 additions & 21 deletions docs/wargame/pwnable/lob11.rst
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
============================================================================================================
[lob] skeleton
[redhat-lob] (11) golem
============================================================================================================

.. graphviz::

digraph foo {
a -> b -> c -> d -> e;

a [shape=box, label="argv[1] value"];
b [shape=box, color=lightblue, label="strcpy"];
c [shape=box, label="Buffer Overflow"];
d [shape=box, label="RET"];
e [shape=box, label="program name address"];
}

|
source code
============================================================================================================

해당 문제 소스코드는 다음과 같습니다.

.. code-block:: c
/*
The Lord of the BOF : The Fellowship of the BOF
- golem
- stack destroyer
*/
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -45,23 +50,25 @@ source code
memset(buffer+48, 0, 0xbfffffff - (int)(buffer+48));
}
|

Buffer Overflow
Vulnerabliity Vector
============================================================================================================

스택 메모리 공간에 다음과 같이 들어가게 됩니다.
스택 메모리 공간에 다음과 같이 들어가게 된다.

.. code-block:: console
================
LOW
----------------
Buffer (40byte) <- strcpy
Buffer (40byte)
SFP (4byte)
RET (4byte)
argc (4byte)
argv (4byte)
RET (4byte) <- strcpy overflow
argc (4byte) <- 0x00000002
argv[0] (4byte) <- argv[0] address
argv[1] (4byte) <- argv[1] address
----------------
HIGH
================
Expand All @@ -71,12 +78,16 @@ Buffer Overflow
Segmentation fault
============================================================================================================

strcpy로 인해 입력한 값이 버퍼보다 클 경우 오버플로우가 발생됩니다.
Overflow condition

- argv[1] value의 47번째 문자가 "\\xbf"이어야 함
- 사용한 메모리 전체 초기화로 인해, 프로그램에서 사용한 메모리 주소로 버퍼오버플로우를 진행할 수 없다

※ 시작시 bash2 명령을 입력하고 bash2 쉘 상태에서 진행해야 합니다.

.. code-block:: console
※ 시작시 bash2 명령을 입력하고 bash2 쉘 상태에서 진행
$ bash2
$ ./golem `python -c 'print "a"*47'`
stack is still your friend.
Expand All @@ -94,9 +105,9 @@ exploit
쉘코드 파일명을 공유 라이브러리로 등록
--------------------------------------------------------------------------------------------------------------

기존에 사용한 쉘코드에는 \x2f 값이 있기 때문에 정상적으로 쉘코드가 동작하지 않습니다.
기존에 사용한 쉘코드에는 "\\x2f" 값이 있기 때문에 정상적으로 쉘코드가 동작하지 않습니다.

\x2f가 없는 쉘코드로 파일명을 생성하도록 합니다.
"\\x2f"가 없는 쉘코드로 파일명을 생성하도록 합니다.

공유 라이브러리 영역에 쉘코드로 파일명을 등록합니다.

Expand Down Expand Up @@ -162,8 +173,9 @@ RET 주소를 공유 라이브러리 로드 주소로 변경하여 공격 진행
Buffer (40byte) <- "\x90"*40
SFP (4byte) <- "\x90"*4
RET (4byte) <- shared libc address
argc (4byte)
argv (4byte)
argc (4byte) <- 0x00000002
argv[0] (4byte) <- argv[0] 주소
argv[1] (4byte) <- argv[1] 주소
----------------
HIGH
================
Expand Down
23 changes: 16 additions & 7 deletions docs/wargame/pwnable/lob12.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
============================================================================================================
[lob] darkknight
[redhat-lob] (12) darknight
============================================================================================================

.. graphviz::

digraph foo {
a -> b -> c -> d -> e;

a [shape=box, label="argv[1] value"];
b [shape=box, color=lightblue, label="strcpy"];
c [shape=box, label="Buffer Overflow"];
d [shape=box, label="RET"];
e [shape=box, label="program name address"];
}

|
source code
============================================================================================================

해당 문제 소스코드는 다음과 같습니다.

.. code-block:: c
/*
The Lord of the BOF : The Fellowship of the BOF
- darkknight
- FPO
*/
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -35,6 +43,7 @@ source code
}
Buffer Overflow
============================================================================================================

Expand Down

0 comments on commit b084b62

Please sign in to comment.