-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_gtp.py
executable file
·66 lines (56 loc) · 2.61 KB
/
send_gtp.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
#!/usr/bin/env python
import argparse
import sys
import socket
import random
import struct
import argparse
import gpt2
from scapy.all import sendp, send, get_if_list, get_if_hwaddr, hexdump
from scapy.all import Packet
from scapy.all import Ether, IPv6, UDP, TCP
from gpt2 import *
def get_if():
ifs=get_if_list()
iface=None # "h1-eth0"
for i in get_if_list():
if "eth0" in i:
iface=i
break;
if not iface:
print "Cannot find eth0 interface"
exit(1)
return iface
def main():
if len(sys.argv)<2:
print 'pass 2 arguments: <destination> "<message>"'
exit(1)
#addr = socket.gethostbyname(sys.argv[1])
addr = "2001:0DB8:AC10:FE01:0000:0000:0000:0002"#socket.gethostbyname(sys.argv[1])
iface = get_if()
print "sending on interface %s to %s" % (iface, str(addr))
pkt = Ether(src=get_if_hwaddr(iface), dst='ff:ff:ff:ff:ff:ff')
#pkt = pkt / IPv6(dst=addr) / UDP(dport=1234 ,sport=random.randint(49152,65535)) / sys.argv[1]
#pkt = pkt /IPv6(dst=addr) / TCP(dport=1234, sport=random.randint(49152,65535), flags=None) / sys.argv[1]
#pkt = pkt / IPv6(dst="2001:0DB8:AC10:FE01:0000:0000:0000:0002" , src="2001:0DB8:AC10:FE01:0000:0000:0002:0002") / UDP (sport=64515, dport=2152 ) / GTP_U_Header(TEID=31)/ IPv6() / TCP(dport=random.randint(29152,65535), sport=random.randint(49152,65535)), / sys.argv[1]
pkt = pkt / IPv6(dst="2001:0DB8:AC10:FE01:0000:0000:0000:000A" , src="2001:0DB8:AC10:FE01:0000:0000:0000:000B") / UDP (sport=64515, dport=2152 ) / GTP_U_Header(TEID=32, Reserved=0)/ IPv6(dst="2001:0DB8:AC10:FE01:0000:0000:0000:0003" , src="2001:0DB8:AC10:FE01:0000:0000:0002:0002") / TCP(dport=80) / sys.argv[1]
pkt.show2()
sendp(pkt, iface=iface, verbose=False)
'''
if (0 < 1):
print "sending on interface {}".format(iface)
pkt = Ether(src=get_if_hwaddr(iface), dst='ff:ff:ff:ff:ff:ff')
pkt = pkt / IPv6(dst="2001:0DB8:AC10:FE01:0000:0000:0000:0002", src="2001:0DB8:AC10:FE01:0000:0000:0002:0002") / UDP (sport=64515, dport=2152) / GTP_U_Header() / IPv6(dst=addr) / TCP(dport=random.randint(29152,65535), sport=random.randint(49152,65535)) / args.message
else:
print "deu erro~"
print "sending on interface {} to IP addr {}".format(iface, str(addr))
pkt = Ether(src=get_if_hwaddr(iface), dst='ff:ff:ff:ff:ff:ff')
pkt = pkt / IP(dst=addr) / TCP(dport=2152, sport=random.randint(49152,65535)) / args.message
pkt.show2()
pkt.summary()
# hexdump(pkt)
# print "len(pkt) = ", len(pkt)
sendp(pkt, iface=iface, verbose=False)
'''
if __name__ == '__main__':
main()