-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicmp.py
80 lines (53 loc) · 1.45 KB
/
icmp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/bash
import sys
import os
import datetime
import socket
import struct
overflow_len =
ip_src = "192.168.1.1."
ip_dst = "192.168.1.110"
def build_eth_header():
eth_src = "\x00\x00\x00\x00\x00\x00"
eth_dst = "\x00\x00\x00\x00\x00\x00"
eth_type = 0x800
eth_len = 14
eth_header = struct.pack('', )
def build_ip_header():
#ip header
ip_ver = 4
ip_ihl = 6
ip_tos = 0
ip_total_len =
ip_id = 0
ip_frag_offset = 0
ip_ttl = 255
ip_protocol = socket.IPPROTO_ICMP
ip_checksum = 0
ip_src_addr = socket.inet_pton(socket.AF_INET, ip_src)
ip_dst_addr = socket.inet_pton(socket.AF_INET, ip_dst)
ip_options = "\x00\x83\x94\x04"
ip_header = struct.pack('!BBHHHBBH4s4s4s' , ip_ver_ihl, ip_tos, ip_total_len, ip_id, ip_frag_offset, ip_ttl, \
ip_protocol, ip_checksum, ip_src_addr, ip_dst_addr, ip_options)
return ip_header
def build_icmp():
def checksum(packet):
if (len(packet) & 1):
packet += b'\x00';
i = 0;
nSum = 0;
while i < len(packet):
nSum += (packet[i] << 8) + packet[i+1];
i += 2;
nCarry = nSum >> 16;
while nCarry:
nSum = (nSum & 0xffff) + nCarry;
nCarry = (nSum >> 16);
nSum = (~nSum & 0xffff);
return nSum;
def build_payload():
def build_packet():
def send_packet():
def main():
if __name__ == "__main__":
main()