Mainly use Scapy to complete
Basic Environment
VM1 (192.168.1.226)
|
|
VM2 (192.168.1.125)
VM1 encapsulation ICMP packets sent to VM2
VM1 script:
#! /usr/bin/env pythonfrom scapy.all Import *target = "192.168.1.125" IP = IP () ICMP = ICMP () ip.dst = Targeticmp.type = 0icmp.c Ode = 0send (ip/icmp)
VM2 Script
From scapy.all import *packetcount = 0def customAction (packet): global packetcount Packetcount + = 1 If Len ( Packet) >0 and Len (Packet[0]) >1: if Hasattr (packet[0][1], ' src ') and packet[0][1].src = = ' 192.168.1.226 ' and packet[0][1].dst== ' 192.168.1.125 ': print packet.show () #return "packet #%s:%s ==>%s"% (Packetcount, PACKET[0][1].SRC, PACKET[0][1].DST) return Nonesniff (filter= "IP", prn=customaction)
This way we can use iptables to add rules that restrict ICMP to various types of code packages.
Reference
Http://www.nthelp.com/icmp.htmlhttps://www.oregontechsupport.com/articles/icmp.txt
Python mock ICMP Packet