-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.py
64 lines (44 loc) · 1.58 KB
/
send.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
from time import sleep
from scapy.all import Dot11,RadioTap,sendp,hexdump
import os,binascii
import fcntl
import socket
import struct
def byte_xor(ba1, ba2):
la1, la2 = list(ba1), list(ba2)
for i, a in enumerate(la1):
la1[i] = a ^ la2[i % len(ba2)]
return bytes(la1)
def getHwAddr(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', bytes(ifname, 'utf-8')[:15]))
return ':'.join('%02x' % b for b in info[18:24])
def setMonitorMode(ifname):
os.system("ifconfig " + ifname + " down")
os.system("iwconfig " + ifname + " mode monitor")
os.system("ifconfig " + ifname + " up")
def unsetMonitorMode(ifname):
os.system("ifconfig " + ifname + " down")
os.system("iwconfig " + ifname + " mode managed")
os.system("ifconfig " + ifname + " up")
def getFrame(msg):
qos = ('\x00\x00') # QoS Control: 0x0000
iv = os.urandom(8) # CCMP IV: (randomized)
data = byte_xor(bytes(msg,'utf-8'), iv)
#data = bytes(msg,'utf-8')
frame = RadioTap()/Dot11(type=2, subtype=8, FCfield="protected")/qos/iv/data
return frame
#iface = 'wlx00198681c3d9' #Interface name here
#frame.show()
#print("\nHexdump of frame:")
#hexdump(frame)
device = input("Enter wireless interface name: ")
line = '1'
setMonitorMode(device)
print("Enter message below, or blank line to exit:")
while line != '':
line = input()
frame = getFrame(line)
sendp(frame, device)
sleep(.1)
unsetMonitorMode(device)