File: replay.py

package info (click to toggle)
aircrack-ng 1%3A1.6%2Bgit20210130.91820bc-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 19,056 kB
  • sloc: ansic: 67,045; cs: 5,392; sh: 3,773; python: 2,565; pascal: 1,074; asm: 570; makefile: 253; cpp: 46
file content (55 lines) | stat: -rwxr-xr-x 1,138 bytes parent folder | download | duplicates (3)
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