mona.py 란 corelan 팀에서 파이썬으로 만든 취약점 분석 도구이다.

원래 이뮤니티 디버거에서 사용하기 위한 용도였지만 windbg에서도 pykd를 통해 사용 가능하다.


사용법은 디버거의 명령 라인에서 

!mona [명령어]

를 사용하면 된다.




!mona modules (!mona mod)


Base | Top | Size | Rebase | SafeSEH | ASLR | NXCompat | OS Dll | Ver, Modulename, Path


주소 시작 | 주소 끝 | 크기 | DLL 재배치 | SafeSEH 사용 여부 | ASLR 사용 여부 | NXCompat 사용 여부 | OS DLL인지 여부 | 버전과 모듈 이름 그리고 경로


위와 같이 익스플로잇 방어 기법들의 사용 여부와 기본적인 정보들을 보여준다.

참고로 Rebase는 DLL에서 사용하는 것으로서 보안 보다는 DLL의 특징에 의한 것이다. 취약점 공격 시에는 ASLR이나 같다고 할 수 있다.

그리고 NXCompat은 DEP라고 생각하면 된다.




!mona rop


ROP 생성을 도와준다.

rop -m [모듈] : 지정한 모듈에서 가젯 검색

rop -n : 널바이트로 시작하는 모듈을 제외하고 로드된 모든 가젯 검색.




!mona pattern_create [숫자] (pc 숫자)


[숫자]바이트의 정해진 패턴을 출력한다.

이 글을 볼 정도면 다 알겠지만 굳이 예를 들자면, 

주로 버퍼 오버플로우 검사 시에 A를 길게 써 넣어서 EIP가 A인 41414141로 바뀐 스택 버퍼 오버플로우가 발생했다고 하자. 

이 경우에 정확히 어느 주소에 ESP가 위치해서 EIP가 저걸로 바꼈는지 찾아야 할텐데 AAA..들의 나열 대신 저 정해진 패턴을 버퍼에 입력하면,

즉 Aa0Aa1Aa2....Ab9... 이런 내용을 버퍼로 넣었다고 치면 EIP에 들어온 내용을 검색해 보면 몇 번째 문자열에서 EIP의 주소가 바뀌게 되는 지를 알 수 있다.

참고로 C:\logs\ 의 경로에 프로세스 이름 별로 pattern.txt 파일에 위의 패턴이 저장되므로 복사해서 사용할 수 있다.




!mona pattern_offset [패턴]


패턴을 검색한다. 패턴은 4바이트를 집어넣어야 한다. 

예를들면 EIP에 들어온 값이 0x41613041이라고 하자.

그럼 !mona po 41613041을 친다.

이것은 문자열로 보면 Aa0A이기 때문에 결과는 오프셋이 0 즉, 처음이라고 나오게 된다.




이외에도 많은 명령어들이 존재한다.


? / eval                | Evaluate an expression

assemble / asm     | Convert instructions to opcode. Separate multiple instructions 

                           with #

bpseh / sehbp       | Set a breakpoint on all current SEH Handler function pointers

breakfunc / bf       | Set a breakpoint on an exported function in on or more dll's

breakpoint / bp     | Set a memory breakpoint on read/write or execute of a given address

bytearray / ba       | Creates a byte array, can be used to find bad characters

calltrace / ct         | Log all CALL instructions

compare / cmp      | Compare contents of a binary file with a copy in memory

config / conf         | Manage configuration file (mona.ini)

copy / cp             | Copy bytes from one location to another

deferbp / bu         | Set a deferred breakpoint

dump                  | Dump the specified range of memory to a file

egghunter / egg     | Create egghunter code

encode / enc         | Encode a series of bytes

filecompare / fc      | Compares 2 or more files created by mona using the same output commands

find / f                  | Find bytes in memory

findmsp / findmsf    | Find cyclic pattern in memory

findwild / fw           | Find instructions in memory, accepts wildcards

fwptr / fwp             | Find Writeable Pointers that get called

geteat / eat            | Show EAT of selected module(s)

getiat / iat              | Show IAT of selected module(s)

getpc                    | Show getpc routines for specific registers

gflags / gf              | Show current GFlags settings from PEB.NtGlobalFlag

header                 | Read a binary file and convert content to a nice 'header' string

heap                     | Show heap related information

help                      | show help

hidedebug / hd       | Attempt to hide the debugger

info                   | Show information about a given address in the context of the 

                          loaded application

infodump / if          | Dumps specific parts of memory to file

jmp / j                  | Find pointers that will allow you to jump to a register

jop                       | Finds gadgets that can be used in a JOP exploit

kb / kb                  | Manage Knowledgebase data

modules / mod        | Show all loaded modules and their properties

noaslr                    | Show modules that are not aslr or rebased

nosafeseh               | Show modules that are not safeseh protected

nosafesehaslr          | Show modules that are not safeseh protected, not aslr and 

                             not rebased

offset                     | Calculate the number of bytes between two addresses

pageacl / pacl          | Show ACL associated with mapped pages

pattern_create / pc    | Create a cyclic pattern of a given size

pattern_offset / po    | Find location of 4 bytes in a cyclic pattern

peb / peb               | Show location of the PEB

rop             | Finds gadgets that can be used in a ROP exploit and do ROP magic 

                   with them

ropfunc       | Find pointers to pointers (IAT) to interesting functions that can be 

                   used in your ROP chain

seh                       | Find pointers to assist with SEH overwrite exploits

sehchain / exchain   | Show the current SEH chain

skeleton        | Create a Metasploit module skeleton with a cyclic pattern for a 

                    given type of exploit

stackpivot             | Finds stackpivots (move stackpointer to controlled area)

stacks                  | Show all stacks for all threads in the running application

string / str            | Read or write a string from/to memory

suggest                | Suggest an exploit buffer structure

teb / teb               | Show TEB related information

unicodealign / ua   | Generate venetian alignment code for unicode stack buffer 

                           overflow

update / up          | Update mona to the latest version


자세한 세부 사항은 직접 찾아보자.


https://www.corelan.be/index.php/2011/07/14/mona-py-the-manual/

블로그 이미지

SanseoLab

,