레이블이 메타스플로잇인 게시물을 표시합니다. 모든 게시물 표시
레이블이 메타스플로잇인 게시물을 표시합니다. 모든 게시물 표시

2013년 7월 28일 일요일

백트랙 개요


아래 글과 마찬가지로 일년전 백트랙을 처음 알았을때 만들었던 ppt 자료입니다. 

초보적인 메타스플로잇 명령어를 사용하는 법과 시연에 관해 설명하고 있는 자료인데, 

큰 정보는 얻으실 수 없을것 같지만, 해킹에 관심을 갖기 시작했으나

뭘 해야할지 모르시는 분들은 한번쯤 보시면 백트랙이 뭔지 아실수 있을거 같아 공유합니다.



2012년 8월 17일 금요일

해킹의 분류 [1] - 시스템 해킹


제가 발표때 쓰려고 만든 자료를 정리해보고자 합니다.

부족한 점이 많으니 틀린 부분이 있으면 지적해주시면 감사하겠습니다.


해킹을 분류 하는 방법에는 여러가지가 있을 수 있습니다.

그 중, 위의 그림에서처럼 시스템, 네트워크, 웹, 리버싱, 암호학, 무선랜과 같이

기술적인 부분으로 분류할 수도 있습니다.

일반적으로 해킹을 할 땐 저 카테코리에서 하나만 사용하진 않고,

두가지 이상을 사용해 해킹하는것이 일반적입니다.

저는 6가지 방법중 시스템, 네트워크, 리버싱, 그리고 무선랜 해킹의 개념과

최근 그 해킹 방법이 사용된 예, 그리고 기초적인 해킹 시연을 보여드리고자 합니다.



먼지 시스템 해킹은 시스템에 접근해 해킹을 하는것을 말합니다.

직접적으로 타겟에 접속해 취약점을 찾아내서 루트권한을 얻는것이 일반적입니다.

악성코드를 통해 해킹을 할 수도 있으며, 그 악성코드들은 쉘 코딩이나 버퍼오버플로우 기법을

이용하기도 합니다.


여기서 버퍼 오버 플로우란, 메모리를 다루는 데에 오류가 발생하여

잘못된 동작을 하는 프로그램 취약점 중 하나입니다.

이를 정확하게 이해하고, 사용하기 위해선 PE 구조와 같이 실행파일의 구조와

메모리를 어떻게 사용하는지에 대한 이해가 필요합니다.

여기선 그 모든것을 성명해 드리는 것은 어렵지만, 아주 간단한 예시를 보여드리겠습니다.

위의 코드는 C++로 짠 아주 간단한 코드입니다.

쭉 훑어 보시면 뭘 하는 프로그램인지 감을 잡으실 수 있을겁니다.


프로그램을 실행하고, 1을 입력하면 당연히 FAIL 이 출력됩니다.

하지만, 메모리 오버 플로우를 이용해 SUCCESS를 출력하게 만들 수 있습니다.


위에 그림에서처럼 입력받는 문자열의 크기 20을 넘어서는 인풋을 주면

그 인풋 값이 메모리의 다른 부분까지 덮어버려 프로그램이 정상적으로 실행되지 않게 합니다.

이렇게 간단한 예로는 버퍼 오버플로우의 위력을 이해하지 못하실 수 있습니다.

하지만 메모리를 해커가 원하는 코드로 덮어버리고, 그 코드를 실행시키게 되면,

시스템의 루트 권한을 쉽게 획득할 수 있습니다.


출처 :  http://maj3sty.tistory.com/

최근에 버퍼 오퍼 플로우 기법을 이용해 악성 HWP 파일을 만든 해킹 사례가 있었습니다.

이 악성코드는 일반적인 한글 파일로 배포 되었으며, 실행하면 정상적인 문서가 열리게 됩니다.


출처 :  http://maj3sty.tistory.com/
하지만 한글 파일을 실행하면 위의 과정처럼 Dropper를 생성하고 악성파을을 생성해

시스템 정보를 특정 서버로 전송하게 됩니다.

최근에 발견된 취약점이니 혹시 한글 프로그램을 업데이트 하시지 않으신 분은

업데이트를 속히 하시기 바랍니다.

이처럼, 버퍼 오버 플로우와 같이 시스템의 취약점을 공격하는 시스템 해킹은

매우 강력한 해킹 기법중 하나입니다.


그럼, 백트랙을 이용해서 간단한 시스템 해킹 과정을 보여드리겠습니다.

백트랙은 리눅스 여러 배포판 중 하나로 모의해킹 및 침투 보안에 특화되어 있는 배포판입니다.

모의 해킹과 침투를 할 수 있는 여러가지 도구들을 포함하고 있습니다.

지금은, 메타스플로잇 (Metasploit) 이란 프로그램을 사용하겠습니다.



메타스플로잇은 여러가지 공격 모듈들을 가지고 있습니다.

그 중 ms08_067 이라는 윈도우의 서비스 취약점을 사용하도록 하겠습니다.

위의 그림에서처럼 모듈을 선택하고, 페이로드를 선택하고,

공격 대상에 대한 옵션을 설정하면 공격을 할 준비가 끝납니다.

이제 exploit 명령어를 입력하면 알아서 취약점을 공략하고 윈도우 쉘을 획득하게 됩니다.

쉘을 획득한 후 여러가지를 할 수 있지만, 여기선 몇개의 폴더를 만들어 보겠습니다.


위의 그림처럼 mkdir 명령어를 입력해 폴더를 만들면

타겟의 시스템에서 제가 만든 폴더들을 볼 수 있습니다.

mkdir 명령어 이외에도 screenshot 등의 명령어를 사용하실 수 있습니다.

이밖에도 메타스플로잇을 통해서 브라우저 취약점, 자바 에플렛 취약점 등을 

이용해서 간단한 모의 해킹을 할 수 있습니다.


해킹의 분류 [2] - 네트워크 해킹 : http://carpedm20.blogspot.kr/2012/08/2_17.html








ps. 시스템 해킹 공부 자료


[System]



============[하]============

1. http://www.hackerschool.org/Sub_Html/HS_University/BOF/essential/00.html

상당히 어려운 BOF 기법을 기초부터 시작해서

차근차근 알려주는 강좌입니다.

BOF에 관심이 없으시더라도 꼭 한번 읽어보시기 바랍니다.


2. http://www.securitytube.net/video/1175

시스템 해킹을 실습해 볼 수 있게 해주는 Metasploit 강좌입니다.

참고로 Backtrack이랑 Metasploit은 동영상 강좌로

배우시는게 제일 빠릅니다.

유투브에 검색하시면 정말 많은 강좌들이 있으니 참고하시기 바랍니다.


3. http://www.offensive-security.com/metasploit-unleashed/Main_Page

Metasploit을 만든 회사에서 지원하는 튜토리얼입니다.


4. http://www.hackingdna.com/

Backtrack 강좌입니다.

파일 받기, 보내기, 스샷 찍기, 웹캠 실행 등..

여러분들의 환상은 Backtrack을 통해 충분히 채우실 수 있을겁니다.

Backtrack을 vmware에 설치하셔서 가상 환경에서만

실습하시기 바랍니다. (해킹은 불법입니다.)


5. http://www.hackingarticles.in/best-of-metasploit-meterpreter-script-meterpreter-cheat-sheet/

meterpreter 치트 시트


6. http://youtu.be/YFoWDETyrYghttp://youtu.be/ljnzQoE0KFc

메타스플로잇 윈도우7 해킹 시연


7. http://blog.naver.com/PostView.nhn?blogId=ka0r1&logNo=90165963416&redirect=Dlog&widgetTypeCall=true

쉘코드 작성 강좌


============[중]============


1. http://www.hackerschool.org/HS_Boards/view.php?id=Lib_system&page=1&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=hit&desc=desc&no=100

BOF의 기초를 알려주는 강좌입니다.

hackerschool BOF 강좌 보시고나서 보시면 이해도 잘되고

BOF에 대해 정말 많은걸 얻으실 수 있을겁니다.

2. http://devanix.tistory.com/129

BOF 원정대라고, BOF를 실습해 볼 수 있는 워게임이 있는데

그 워게임에 대한 강좌입니다.

BOF 이론 공부부 하시고나서 꼭 한번 실습해 보시기 바랍니다.


3. http://s3ize.blogspot.kr/2012/08/load-of-bof-level1.html

원정대 풀이


4. http://5a5in.com/wordpress/?p=1107

원정대 풀이


5. http://geundi.tistory.com/118

원정대 풀이


6. http://www.hackerschool.org/HS_Boards/data/Lib_system/omega1.txt
http://www.hackerschool.org/HS_Boards/data/Lib_system/omega2.txt

오메가 프로젝트






흔하지 않은 윈도우 공격 코드 작성 튜토리얼 번역글


8. http://cdpython.tistory.com/28

exploit-writing-tutorial-part-1-stack-based-overflows 의 다른 번역글


9. http://www.punter-infosec.com/exploit-writing-tutorials-for-pentesters/

공격 코드 작성 튜토리얼 모음


10. https://www.evernote.com/shard/s157/sh/9fcdb690-33c6-491f-93d4-dd30f490e8b4/a08fb07cb62728963057feef9054c7ad

공격코드를 metasploit 으로 포팅해 활용하는 방법

출처 : 네이버 카페 (기억이 잘 안남, 문제시 삭제)


11. Win32 Attack Local Shellcode 작성방법 [달고나]  Win32 Attack 2. Local Buffer Overflow

윈도우 기반 쉘코드 작성 튜토리얼 문서


12 http://exploit-exercises.com/

원정대과 다른 해외 시스템 해킹 워게임

난이도 별로 vm 이미지를 제공


ps2.  해킹 공부 자료 링크 : http://carpedm20.blogspot.kr/2012/09/blog-post.html

2012년 8월 14일 화요일

Metasploit unleashed - Msfconsole 명령어 [3]



metasploit-unleashed 튜토리얼 중 msfconsole 명령어 부분을 정리한 글입니다.



search

msfconsole은 강력한 검색 기능을 포함하고 있습니다. 만약 여러분이 찾고 있는 것이 있다면 'search' 명령어를 사용할 수 있습니다. 아래에 예시는 MS 취약점인 MS09-011를 찾는 경우입니다. msfconsole은 여러분이 검색하진 스트링을 모듈 이름, 설명, 레퍼런스 등에서 찾습니다. 메타스플로잇 모듈은 '-' 대신 '_'을 사용하니 'search' 명령어를 사용할 때 참고하시기 바랍니다.
msf > search ms09-001

Matching Modules
================

   Name                                      Disclosure Date  Rank    Description
   ----                                      ---------------  ----    -----------
   auxiliary/dos/windows/smb/ms09_001_write                   normal  Microsoft SRV.SYS WriteAndX Invalid DataOffset

help

여러분은 'help search' 명령어를 통해 더 정확한 검색을 위한 옵션을 볼 수 있습니다.
msf > help search
Usage: search [keywords]

Keywords:
  name      :  Modules with a matching descriptive name
  path      :  Modules with a matching path or reference name
  platform  :  Modules affecting this platform
  type      :  Modules of a specific type (exploit, auxiliary, or post)
  app       :  Modules that are client or server attacks
  author    :  Modules written by this author
  cve       :  Modules with a matching CVE ID
  bid       :  Modules with a matching Bugtraq ID
  osvdb     :  Modules with a matching OSVDB ID

Examples:
  search cve:2009 type:exploit app:client

msf > 

name

이름을 검색하시려면 search 뒤에 name: 을 입력하시면 됩니다.
msf > search name:illustrator

Matching Modules
================

   Name                                                  Disclosure Date  Rank   Description
   ----                                                  ---------------  ----   -----------
   exploit/windows/fileformat/adobe_illustrator_v14_eps  2009-12-03       great  Adobe Illustrator CS4 v14.0.0


msf > 

path

경로를검색하시려면 search 뒤에 path: 를 입력하시면 됩니다.
msf > search path:scada

Matching Modules
================

   Name                                                 Disclosure Date  Rank     Description
   ----                                                 ---------------  ----     -----------
   auxiliary/admin/scada/igss_exec_17                   2011-03-21       normal   Interactive Graphical SCADA System Remote Command Injection
   exploit/windows/scada/citect_scada_odbc              2008-06-11       normal   CitectSCADA/CitectFacilities ODBC Buffer Overflow
...snip...

platform

플랫폼란에서 검색하시려면 search 뒤에 platform: 을 입력하시면 됩니다.
msf > search platform:aix

Matching Modules
================

   Name                                  Disclosure Date  Rank    Description
   ----                                  ---------------  ----    -----------
   payload/aix/ppc/shell_bind_tcp                         normal  AIX Command Shell, Bind TCP Inline
   payload/aix/ppc/shell_find_port                        normal  AIX Command Shell, Find Port Inline
   payload/aix/ppc/shell_interact                         normal  AIX execve shell for inetd
...snip...

type

모듈이나 보조모듈을 검색하시려면 search 뒤에 type: 을 입력하시면 됩니다.
msf > search type:post

Matching Modules
================

   Name                                                Disclosure Date  Rank    Description
   ----                                                ---------------  ----    -----------
   post/linux/gather/checkvm                                            normal  Linux Gather Virtual Environment Detection
   post/linux/gather/enum_cron                                          normal  Linux Cron Job Enumeration
   post/linux/gather/enum_linux                                         normal  Linux Gather System Information
...snip...

author

저자의 이름을 검색하시려면 search 뒤에 author: 을 입력하시면 됩니다.
msf > search author:dookie

Matching Modules
================

   Name                                                       Disclosure Date  Rank     Description
   ----                                                       ---------------  ----     -----------
   exploit/osx/http/evocam_webserver                          2010-06-01       average  MacOS X EvoCam HTTP GET Buffer Overflow
   exploit/osx/misc/ufo_ai                                    2009-10-28       average  UFO: Alien Invasion IRC Client Buffer Overflow Exploit
   exploit/windows/browser/amaya_bdo                          2009-01-28       normal   Amaya Browser v11.0 bdo tag overflow
...snip...

multiple

여러가지 범위에서 검색하시려면 search 뒤에 여러개의 옵션을 차례로 입력하시면 됩니다.
msf > search cve:2011 author:jduck platform:linux

Matching Modules
================

   Name                                         Disclosure Date  Rank     Description
   ----                                         ---------------  ----     -----------
   exploit/linux/misc/netsupport_manager_agent  2011-01-08       average  NetSupport Manager Agent Remote Buffer Overflow


show

msfconsole 프롬프트 환경에서 show를 입력하시면 메타스플로잇의 모든 모듈을 보실 수 있습니다.
msf > show

Encoders
========

   Name                    Disclosure Date  Rank       Description
   ----                    ---------------  ----       -----------
   cmd/generic_sh                           good       Generic Shell Variable Substitution Command Encoder
   cmd/ifs                                  low        Generic ${IFS} Substitution Command Encoder
   cmd/printf_php_mq                        manual     printf(1) via PHP magic_quotes Utility Command Encoder
...snip...

show 명령어를 사용하는 방법에는 여러가지가 있지만, 여러분은 'show auxiliary', 'show exploits', 'show payloads', 'show encoders', 그리고 'show nops' 와 같은 명령어를 자주 사용하실 겁니다.


auxiliary

'show auxiliary' 명령어를 실행하면 메타스플로잇의 모든 보조 모듈을 보여줄 것입니다. 참고로 보조 모듈은 스케너, DoS 모듈, fuzzer 등을 포함합니다.
msf > show auxiliary
Auxiliary
=========

   Name                                                  Disclosure Date  Rank    Description
   ----                                                  ---------------  ----    -----------
   admin/2wire/xslt_password_reset                       2007-08-15       normal  2Wire Cross-Site Request Forgery Password Reset Vulnerability
   admin/backupexec/dump                                                  normal  Veritas Backup Exec Windows Remote File Access
   admin/backupexec/registry                                              normal  Veritas Backup Exec Server Registry Access
...snip...

exploits

'show exploits'는 메타스플로잇의 가장 핵심 부분이며 여러분이 가장 많이 사용하시고 관심을 가지실 명령어일 것입니다. 'show exploits'을 실행하시면 프레임워크가 가지고 있는 모든 exploit을 나열 합니다.
msf > show exploits

Exploits
========

   Name                                                           Disclosure Date  Rank       Description
   ----                                                           ---------------  ----       -----------
   aix/rpc_cmsd_opcode21                                          2009-10-07       great      AIX Calendar Manager Service Daemon (rpc.cmsd) Opcode 21 Buffer Overflow
   aix/rpc_ttdbserverd_realpath                                   2009-06-17       great      ToolTalk rpc.ttdbserverd _tt_internal_realpath Buffer Overflow (AIX)
   bsdi/softcart/mercantec_softcart                               2004-08-19       great      Mercantec SoftCart CGI Overflow
...snip...

payloads

'show payloads'는 메타스플로잇에서 사용 가능한 모든 플랫폼의 payload를 나열해 줍니다.
msf > show payloads

Payloads
========

   Name                                             Disclosure Date  Rank    Description
   ----                                             ---------------  ----    -----------
   aix/ppc/shell_bind_tcp                                            normal  AIX Command Shell, Bind TCP Inline
   aix/ppc/shell_find_port                                           normal  AIX Command Shell, Find Port Inline
   aix/ppc/shell_interact                                            normal  AIX execve shell for inetd
...snip...

payloads
여러분이 특정 exploit을 사용하고 있는 경우 'show payload' 명령어는 여러분이 선택하신 exploit에서 사용할 수 있는 payload만 나열할 것입니다. 예를들어, 윈도우 exploit에서는 리눅스 payload들은 보이지 않을 것 입니다.
msf  exploit(ms08_067_netapi) > show payloads

Compatible Payloads
===================

   Name                                             Disclosure Date  Rank    Description
   ----                                             ---------------  ----    -----------
   generic/custom                                                    normal  Custom Payload
   generic/debug_trap                                                normal  Generic x86 Debug Trap
   generic/shell_bind_tcp                                            normal  Generic Command Shell, Bind TCP Inline
...snip...

options
만약 여러분이 모듈을 선택하셨으면, 'show options' 명령어를 통해 여러분이 설정해야할 세팅 값들을 보실 수 있습니다. Setting 란에 yes 라고 되어 있는 부분은 여러분이 모듈을 사용하기 위해선 반드시 입력하거나 수정해야 할 부분입니다.
msf exploit(ms08_067_netapi) > show options

Module options:

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   RHOST                     yes       The target address
   RPORT    445              yes       Set the SMB service port
   SMBPIPE  BROWSER          yes       The pipe name to use (BROWSER, SRVSVC)


Exploit target:

   Id  Name
   --  ----
   0   Automatic Targeting

targets
여러분이 사용하시려는 exploit이 어떤 운영체제에서 사용할 수 있는지가 궁금하시면, 모듈을 선택하신 후 'show target' 명령어를 사용하시기 바랍니다.
msf  exploit(ms08_067_netapi) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Automatic Targeting
   1   Windows 2000 Universal
   10  Windows 2003 SP1 Japanese (NO NX)
   11  Windows 2003 SP2 English (NO NX)
   12  Windows 2003 SP2 English (NX)
...snip...

advanced
만약 여러분이 exploit을 좀 더 수정하고 싶을 때, 'show advanced' 명령어를 입력하시면 고급 설정들을 보실 수 있습니다.
msf exploit(ms08_067_netapi) > show advanced

Module advanced options:

   Name           : CHOST
   Current Setting:
   Description    : The local client address

   Name           : CPORT
   Current Setting:
   Description    : The local client port

...snip...

encoders

'show encoders' 명령어는 메타스플로잇에서 사용할 수 있는 인코더를 나열할 것입니다.
msf > show encoders
Compatible Encoders
===================

   Name                    Disclosure Date  Rank       Description
   ----                    ---------------  ----       -----------
   cmd/generic_sh                           good       Generic Shell Variable Substitution Command Encoder
   cmd/ifs                                  low        Generic ${IFS} Substitution Command Encoder
   cmd/printf_php_mq                        manual     printf(1) via PHP magic_quotes Utility Command Encoder
   generic/none                             normal     The "none" Encoder
   mipsbe/longxor                           normal     XOR Encoder
   mipsle/longxor                           normal     XOR Encoder
   php/base64                               great      PHP Base64 encoder
   ppc/longxor                              normal     PPC LongXOR Encoder
   ppc/longxor_tag                          normal     PPC LongXOR Encoder
   sparc/longxor_tag                        normal     SPARC DWORD XOR Encoder
   x64/xor                                  normal     XOR Encoder
   x86/alpha_mixed                          low        Alpha2 Alphanumeric Mixedcase Encoder
   x86/alpha_upper                          low        Alpha2 Alphanumeric Uppercase Encoder
   x86/avoid_utf8_tolower                   manual     Avoid UTF8/tolower
   x86/call4_dword_xor                      normal     Call+4 Dword XOR Encoder
   x86/context_cpuid                        manual     CPUID-based Context Keyed Payload Encoder
   x86/context_stat                         manual     stat(2)-based Context Keyed Payload Encoder
   x86/context_time                         manual     time(2)-based Context Keyed Payload Encoder
   x86/countdown                            normal     Single-byte XOR Countdown Encoder
   x86/fnstenv_mov                          normal     Variable-length Fnstenv/mov Dword XOR Encoder
   x86/jmp_call_additive                    normal     Jump/Call XOR Additive Feedback Encoder
   x86/nonalpha                             low        Non-Alpha Encoder
   x86/nonupper                             low        Non-Upper Encoder
   x86/shikata_ga_nai                       excellent  Polymorphic XOR Additive Feedback Encoder
   x86/single_static_bit                    manual     Single Static Bit
   x86/unicode_mixed                        manual     Alpha2 Alphanumeric Unicode Mixedcase Encoder
   x86/unicode_upper                        manual     Alpha2 Alphanumeric Unicode Uppercase Encoder

nops

마지막으로 'show nops' 명령어는 메타스플로잇이 제공하는 NOP Generators 를 보여줄 것입니다.
msf > show nops
NOP Generators
==============

   Name             Disclosure Date  Rank    Description
   ----             ---------------  ----    -----------
   armle/simple                      normal  Simple
   php/generic                       normal  PHP Nop Generator
   ppc/simple                        normal  Simple
   sparc/random                      normal  SPARC NOP generator
   tty/generic                       normal  TTY Nop Generator
   x64/simple                        normal  Simple
   x86/opty2                         normal  Opty2
   x86/single_byte                   normal  Single Byte

setg

모의 침투중에 여러번 변수 지정을 해 주는것 대신에, 여러분은 'setg' 명령어를 통해 msfconsole에서 전역 변수를 설정하실 수 있습니다. 전역변수가 설정되고 나면 여러분은 그 변수를 어떤 공격이나 모듈에서도 사용하실 수 있습니다. 또한 여러분은 다음번 msfconsole 실행에서도 이 전역 변수를 사용하실 수 있습니다. 하지만 여러분이 전역 변수를 설정하신 것을 잊지 않기 위해선, 반드시 공격을 수행하기 전에 옵션을 확인하는 과정을 잊지 마시기 바랍니다. 반대로 'unsetg' 명령어를 통해서 여러분이 설정하신 전역변수를 제거할 수 있습니다. 아래의 예시의 경우 모든 변수를 대문자로 사용하고 있지만, 메타스플로잇은 대문자와 소문자를 구분하지 않으므로 굳이 대문자를 사용하실 필요는 없습니다.
msf > setg LHOST 192.168.1.101
LHOST => 192.168.1.101
msf > setg RHOSTS 192.168.1.0/24
RHOSTS => 192.168.1.0/24
msf > setg RHOST 192.168.1.136
RHOST => 192.168.1.136

모든 변수를 설정하시고 나서 'save' 명령어를 입력하시면 여러분이 지정한 환경과 설정들이 모두 저장 됩니다. 이후 msfconsole을 실행할 때 마다 저장된 설정을 사용하실 수 있습니다.

msf > save
Saved configuration to: /root/.msf3/config
msf >

use

여러분이 특정 모듈을 사용하기로 결심했다면 'use' 명령어를 사용해 그 모듈을 선택하시기 바랍니다. 'use' 명령어는 여러분이 특정 모듈을 사용할 수 있는 환경을 제공하며, 이 환경에서만 제공하는 명령어를 사용할 수 있도록 합니다. 아래의 예시는 전역변수들이 이미 설정되어 있는 경우의 msfconsole을 보여줍니다.
msf > use dos/windows/smb/ms09_001_write
msf auxiliary(ms09_001_write) > show options

Module options:

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   RHOST                   yes       The target address
   RPORT  445              yes       Set the SMB service port

msf auxiliary(ms09_001_write) >



참고 : http://www.offensive-security.com/metasploit-unleashed/Msfconsole



Metasploit unleashed - msfconsole 명령어 [2]


metasploit-unleashed 튜토리얼 중 msfconsole 명령어 부분을 정리한 글입니다.


back

만약 여러분이 특정 모듈 사용이 끝나면, 혹은 실수로 잘못된 모듈을 선택했다면, 여러분은 'back' 멸령어를 사용해 그 전 상황으로 돌아가실 수 있습니다. 하지만 모듈을 사용중인 상황에서 모듈을 바로 바꿀수 있기 때문에, 굳이 back 명령어를 사용하지 않으셔도 됩니다. 그리고 변수들은 전역으로 설정되어 있을때만 유지되고 그렇지 않은 경우엔 보존되지 않습니다.
msf auxiliary(ms09_001_write) > back
msf >


check

check명령어는 실제로 exploit하는 대신 타겟이 여러분이 사용하려고 하는 공격에 취약한지 그렇지 않은지를 확인해 줍니다. 
msf exploit(ms04_045_wins) > show options

Module options:

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   RHOST  192.168.1.114    yes       The target address
   RPORT  42               yes       The target port


Exploit target:

   Id  Name
   --  ----
   0   Windows 2000 English


msf exploit(ms04_045_wins) > check
[-] Check failed: The connection was refused by the remote host (192.168.1.114:42)

connect

이것은 SSL, 프록시, 피봇, 그리고 파일 전송을 지원하는 netcat의 작은 사본입니다. 'connect' 명령어와 IP 주소, 그리고 포트 넘버를 입력하시면, 여러분은 netcat과 telnet과 같이 다른 호스트 네트워크에 접속할 수 있습니다.
msf > connect 192.168.1.1 23
[*] Connected to 192.168.1.1:23
DD-WRT v24 std (c) 2008 NewMedia-NET GmbH
Release: 07/27/08 (SVN revision: 10011)
DD-WRT login:

사용가능한 다른 옵션은 -h 를 입력하시면 보실 수 있습니다.
msf > connect -h
Usage: connect [options]  

Communicate with a host, similar to interacting via netcat, taking advantage of
any configured session pivoting.

OPTIONS:

    -C        Try to use CRLF for EOL sequence.
    -P   Specify source port.
    -S   Specify source address.
    -c   Specify which Comm to use.
    -h        Help banner.
    -i   Send the contents of a file.
    -p   List of proxies to use.
    -s        Connect with SSL.
    -u        Switch to a UDP socket.
    -w   Specify connect timeout.
    -z        Just try to connect, then return.

msf > 


irb

'irb' 명령어를 실행하면 명령어를 사용할 수 있고, 메타스플로잇 스크립트를 만들 수 있는 루비 인터프리터 셀을 제공합니다. 이 기능은 프레임 워크의 내부를 이해하는데 매우 유용한 기능입니다.
msf > irb
[*] Starting IRB shell...

>> puts "Hello, metasploit!"
Hello, metasploit!
=> nil
>> Framework::Version
=> "4.2.0-dev"
>> framework.modules.keys.length
=> 1579
>>


jobs

Jobs는 백그라운드에서 실행되고 있는 모듈을 말합니다. 'jobs' 명령어를 입력하시면 백그라운드에서 실행되고 있는 Job을 종료할 수 있습니다.
msf > jobs -h
Usage: jobs [options]

Active job manipulation and interaction.

OPTIONS:

    -K        Terminate all running jobs.
    -h        Help banner.
    -i   Lists detailed information about a running job.
    -k   Terminate the specified job name.
    -l        List all running jobs.
    -v        Print more detailed info.  Use with -i and -l

msf > 


load

'load' 명령어는 메타스플로잇의 'plugin 디렉토리에서 플러그인을 로드합니다. 변수들은 다음의 'key=val'와 같은 형식으로 입력하시면 쉘에 넘겨줄 수 있습니다.
msf > load
Usage: load  [var=val var=val ...]

Loads a plugin from the supplied path.  If path is not absolute, fist looks
in the user's plugin directory (/root/.msf4/plugins) then
in the framework root plugin directory (/opt/framework/msf3/plugins).
The optional var=val options are custom parameters that can be passed to plugins.

msf > load pcap_log
[*] PcapLog plugin loaded.
[*] Successfully loaded plugin: pcap_log


loadpath

'loadpath' 명령어는 여러분의 페이로드, 제로 데이 스크립트, 인코더와 같은 외부 모듈을 로드해 메타스플로잇이 사용 할 수 있도록  합니다.
msf > loadpath /home/secret/modules

Loaded 0 modules.


unload

'loadpath'와는 반대로 'unload'는 로드한 플러그인과 확장 명령어들을 언로드 합니다.
msf > unload pcap_log
Unloading plugin pcap_log...unloaded.

resource

'resource' 명령어는 실행파일을 로드해 msfconsole에서 사용할 수 있도록 합니다.
msf > resource
Usage: resource path1 [path2 ...]

Run the commands stored in the supplied files.  Resource files may also contain
ruby code between  tags.

See also: makerc

msf >
Karmetasploit과 같은 공격은 karma.rc 와 같은 리소스 파일을 사용합니다.
msf > resource karma.rc
[*] Processing karma.rc for ERB directives.
resource (karma.rc)> db_connect msf3:PASSWORD@127.0.0.1:7175/msf3
resource (karma.rc)> use auxiliary/server/browser_autopwn
...snip...

실행 파일을 msfconsole에 로드하면 파일 실행과 개발시간을 단축시켜주며 자동으로 여러가지 명령어를 실행할 수 있도록 도와줍니다. msfconsole의 콘솔환경에서 실행파일을 로드 하는 방법 외에, msfconsole을 실행할 때 '-r' 옵션을 사용해 로드하는 방법도 있습니다.

root@bt:~# echo version > version.rc
root@bt:~# msfconsole -r version.rc


 _                                                      _
/  \  / \        __                          _   __    /_/ __
| |\ /  | _____  \ \            ___   _____ | | /   \  _   \ \
| | \/| | | ___\ |- -|   /\    / __\ | -__/ | | | |  || | |- -|
|_|   | | | _|__  | |_  / -\ __\ \   | |    | |_ \__/ | |  | |_
      |/  |____/  \___\/ /\  \___/   \/      \__|     |_\  \___\


       =[ metasploit v4.2.0-dev [core:4.2 api:1.0]
+ -- --=[ 775 exploits - 411 auxiliary - 120 post
+ -- --=[ 238 payloads - 27 encoders - 8 nops
       =[ svn r14414 updated 6 days ago (2011.12.14)

[*] Processing version.rc for ERB directives.
resource (version.rc)> version
Framework: 4.2.0-dev.14161
Console  : 4.2.0-dev.14065
msf > 


route

"route" command in Metasploit allows you to route sockets through a session or 'comm', providing basic pivoting capabilities. To add a route, you pass the target subnet and network mask followed by the session (comm) number.
meterpreter > route -h
Usage: route [-h] command [args]

Display or modify the routing table on the remote machine.

Supported commands:

   add    [subnet] [netmask] [gateway]
   delete [subnet] [netmask] [gateway]
   list

meterpreter >
meterpreter > route

Network routes
==============

    Subnet           Netmask          Gateway
    ------           -------          -------
    0.0.0.0          0.0.0.0          172.16.1.254
    127.0.0.0        255.0.0.0        127.0.0.1
    172.16.1.0       255.255.255.0    172.16.1.100
    172.16.1.100     255.255.255.255  127.0.0.1
    172.16.255.255   255.255.255.255  172.16.1.100
    224.0.0.0        240.0.0.0        172.16.1.100
    255.255.255.255  255.255.255.255  172.16.1.100


info

'info'명령어는 특정 모듈의 옵션과 타겟, 그리고 기타 정보를 제공합니다. 여러분이 의도하지 않은 결과를 초래하는것을 원하지 않는다면, 모듈 사용전에 그 모듈의 정보를 확인하는 습관을 가집시다.
'info' 명령어는 다음과 같은 정보도 제공합니다:
  • 작성자와 문서의 라이센스 정보
  • Vulnerability references (ie: CVE, BID, etc)
  • 모듈이 가지고 있는 페이로드 제한 정보
msf  exploit(ms08_067_netapi) > info auxiliary/dos/windows/smb/ms09_001_write 

       Name: Microsoft SRV.SYS WriteAndX Invalid DataOffset
     Module: auxiliary/dos/windows/smb/ms09_001_write
    Version: 10394
    License: Metasploit Framework License (BSD)
       Rank: Normal

Provided by:
  j.v.vallejo 

Basic options:
  Name   Current Setting  Required  Description
  ----   ---------------  --------  -----------
  RHOST                   yes       The target address
  RPORT  445              yes       Set the SMB service port

Description:
  This module exploits a denial of service vulnerability in the 
  SRV.SYS driver of the Windows operating system. This module has been 
  tested successfully against Windows Vista.

References:
  http://www.microsoft.com/technet/security/bulletin/MS09-001.mspx
  http://www.osvdb.org/48153
  http://cve.mitre.org/cgi-bin/cvename.cgi?name=2008-4114
  http://www.securityfocus.com/bid/31179


set

'set' 명령어는 현재 사용중인 모듈에서 이용하는 프레임 워크 옵션과 파라미터를 수정할 때 사용합니다.
msf auxiliary(ms09_001_write) > set RHOST 192.168.1.1
RHOST => 192.168.1.1
msf auxiliary(ms09_001_write) > show options

Module options:

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   RHOST  192.168.1.1      yes       The target address
   RPORT  445              yes       Set the SMB service port

메타스플로잇은 또한 여러분에게 인코더를 제공합니다. 여러분이 어떤 페이로드 인코딩 방식을 사용해야 할지 확실하지 않을때 이 인코더는 여러분에게 유용한 도움을 줄 것입니다.

msf  exploit(ms08_067_netapi) > show encoders

Compatible Encoders
===================

   Name                    Disclosure Date  Rank       Description
   ----                    ---------------  ----       -----------
   cmd/generic_sh                           good       Generic Shell Variable Substitution Command Encoder
   cmd/ifs                                  low        Generic ${IFS} Substitution Command Encoder
   cmd/printf_php_mq                        manual     printf(1) via PHP magic_quotes Utility Command Encoder
   generic/none                             normal     The "none" Encoder
   mipsbe/longxor                           normal     XOR Encoder
   mipsle/longxor                           normal     XOR Encoder
   php/base64                               great      PHP Base64 encoder
   ppc/longxor                              normal     PPC LongXOR Encoder
   ppc/longxor_tag                          normal     PPC LongXOR Encoder
   sparc/longxor_tag                        normal     SPARC DWORD XOR Encoder
   x64/xor                                  normal     XOR Encoder
   x86/alpha_mixed                          low        Alpha2 Alphanumeric Mixedcase Encoder
   x86/alpha_upper                          low        Alpha2 Alphanumeric Uppercase Encoder
   x86/avoid_utf8_tolower                   manual     Avoid UTF8/tolower
   x86/call4_dword_xor                      normal     Call+4 Dword XOR Encoder
   x86/context_cpuid                        manual     CPUID-based Context Keyed Payload Encoder
   x86/context_stat                         manual     stat(2)-based Context Keyed Payload Encoder
   x86/context_time                         manual     time(2)-based Context Keyed Payload Encoder
   x86/countdown                            normal     Single-byte XOR Countdown Encoder
   x86/fnstenv_mov                          normal     Variable-length Fnstenv/mov Dword XOR Encoder
   x86/jmp_call_additive                    normal     Jump/Call XOR Additive Feedback Encoder
   x86/nonalpha                             low        Non-Alpha Encoder
   x86/nonupper                             low        Non-Upper Encoder
   x86/shikata_ga_nai                       excellent  Polymorphic XOR Additive Feedback Encoder
   x86/single_static_bit                    manual     Single Static Bit
   x86/unicode_mixed                        manual     Alpha2 Alphanumeric Unicode Mixedcase Encoder
   x86/unicode_upper                        manual     Alpha2 Alphanumeric Unicode Uppercase Encoder


unset


'unset' 명령어는 'set'명령어와 반대의 기능을 제공합니다. 'set'을 통해 수정했던 파라미터를 'unset'을 통해 제거하며, 'unset all' 명령어를 통해 수정된 모든 파라미터를 원래대로 바꿀 수 있습니다.

msf > set RHOSTS 192.168.1.0/24
RHOSTS => 192.168.1.0/24
msf > set THREADS 50
THREADS => 50
msf > set

Global
======

  Name     Value
  ----     -----
  RHOSTS   192.168.1.0/24
  THREADS  50

msf > unset THREADS
Unsetting THREADS...
msf > unset all
Flushing datastore...
msf > set

Global
======

No entries in data store.

msf > 


sessions

'sessions' 명령어는 스폰된 세션을 나열하고, 사용하고, 정지시킬 때 사용합니다. 이런 세션은 쉘, Meterpreter 세션, VNC 등이 될 수 있습니다.
msf > sessions -h
Usage: sessions [options]

Active session manipulation and interaction.

OPTIONS:

    -K        Terminate all sessions
    -c   Run a command on the session given with -i, or all
    -d   Detach an interactive session
    -h        Help banner
    -i   Interact with the supplied session ID
    -k   Terminate session
    -l        List all active sessions
    -q        Quiet mode
    -r        Reset the ring buffer for the session given with -i, or all
    -s   Run a script on the session given with -i, or all
    -u   Upgrade a win32 shell to a meterpreter session
    -v        List verbose fields
실행중인 세션을 활성화 하기 위해선 'sessions -l' 명령어를 입력합니다.
msf exploit(3proxy) > sessions -l

Active sessions
===============

  Id  Description    Tunnel
  --  -----------    ------
  1   Command shell  192.168.1.101:33191 -> 192.168.1.104:4444

주어진 세셜을 사용하기 위해선, 'session -i' 뒤에 사용하고자 하는 세션 아이디 넘버를 입력합니다.

msf exploit(3proxy) > sessions -i 1
[*] Starting interaction with 1...

C:\WINDOWS\system32>



참고 : http://www.offensive-security.com/metasploit-unleashed/Msfconsole