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
|
#!/usr/bin/env python
import sys
import pcapy
from scapy import *
from impacket.ImpactDecoder import *
try:
conf.verb=0
except NameError:
# Scapy v2
from scapy.all import *
conf.verb=0
if len(sys.argv) != 2:
print("Usage: ./replay.py <iface>")
sys.exit(1)
interface=sys.argv[1]
max_bytes = 2048
promiscuous = False
read_timeout = 100 # in milliseconds
packet_limit = -1 # infinite
pc = pcapy.open_live(interface, max_bytes, promiscuous, read_timeout)
def recv_pkts(hdr, data):
replay = True
if data[11] == "\xFF":
return
# separate ethernet header and ieee80211 packet
raw_header = data[:11] + "\xFF" + data[12:14]
header = Ether(raw_header)
try:
# end of separation
packet = Dot11(data[14:])
except struct.error:
# Ignore unpack errors on short packages
return
# manipulate/drop/insert dot11 packet
print(packet.summary())
# end of manipulation
# construct packet and replay
if replay == True:
data = header/packet
sendp(data, iface=interface)
pc.loop(packet_limit, recv_pkts) # capture packets
|