#!/usr/bin/python ### doicmp client ### usage example: python client.py 10.0.0.1 10.0.0.5 "Hi there!" import time import sys from impacket import ImpactPacket from socket import * import os DLEN = 56 # specifies the DATA lenght of every packet. def send_pkt(x, y, a, seq_id): """send_pkt(tot num fragmented packets, last_packet, difference, ID""" str_send = '@'+string[DLEN*(i-a): DLEN*i] # Packet fragmentation icmp.contains(ImpactPacket.Data(str_send)) # fill DATA field ip.contains(icmp) # encapsulate ICMP packet in IP packet seq_id += 1 icmp.set_icmp_id(seq_id) # set ID field icmp.set_icmp_cksum(0) icmp.auto_checksum = 1 s.sendto(ip.get_packet(), (dst, 0)) # send packet time.sleep(0.05) # parser if len(sys.argv) < 3: print """"Usage: "data" """ sys.exit(1) src = sys.argv[1] dst = sys.argv[2] string = sys.argv[3]+'\n' # create RAW socket s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP) s.setsockopt(IPPROTO_IP, IP_HDRINCL, 1) # define IP packet ip = ImpactPacket.IP() ip.set_ip_src(src) ip.set_ip_dst(dst) # define ICMP packet icmp = ImpactPacket.ICMP() icmp.set_icmp_type(icmp.ICMP_ECHOREPLY) # define ICMP packet type # fragmentation for DATA fields > of 54 bytes seq_id = 0 x = len(string) / DLEN y = len(string) % DLEN for i in range(1,x+2): send_pkt(x,y,1,seq_id) while y > DLEN: #difference for packet len != DLEN send_pkt(x,y,0,seq_id)