-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwifitap.py
executable file
·139 lines (117 loc) · 4.3 KB
/
wifitap.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#! /usr/bin/env python
########################################
#
# wifitap.py --- WiFi injection tool through tun/tap device
#
# Copyright (C) 2011 Daniel Smith <viscous.liquid@gmail.com>
# Copyright (C) 2005 Cedric Blancher <sid@rstack.org>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation; version 2.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
#########################################
import os,sys,getopt,struct,re,string,logging,asyncore
# Import Psyco if available to speed up execution
try:
import psyco
psyco.full()
except ImportError:
print "Psyco optimizer not installed, running anyway..."
from scapy.all import Ether,SNAP,conf
from wifitap_device import WifiTapDevice
from readers import WifiTapReader, InterfaceReader
def usage(status=0):
print "Usage: wifitap -b <BSSID> [-o <iface>] [-i <iface>] [-s <SMAC>]"
print " [-w <WEP key> [-k <key id>]] [-d [-v]] [-h]"
print " -b <BSSID> specify BSSID for injection"
print " -o <iface> specify interface for injection (default: ath0)"
print " -i <iface> specify interface for listening (default: ath0)"
print " -s <SMAC> specify source MAC address for injected frames"
print " -w <key> WEP mode and key"
print " -k <key id> WEP key id (default: 0)"
print " -r <b/g rate> B/G transmit rate"
print " -m <mcs rate> N transmit rate"
print " -t <retries> Number of retries"
print " -g Enable short guard interval"
print " -d activate debug"
print " -v verbose debugging"
print " -h this so helpful output"
sys.exit(status)
def parse_opts(wifitap):
opts = getopt.getopt(sys.argv[1:],"b:o:i:s:w:k:r:m:t:gdvh")
for opt,optarg in opts[0]:
if opt == "-b":
wifitap.bssid = optarg
elif opt == "-o":
wifitap.outface = optarg
elif opt == "-i":
wifitap.inface = optarg
elif opt == "-s":
wifitap.smac = optarg
elif opt == "-w":
wifitap.wepkey = optarg
elif opt == "-k":
wifitap.keyid = int(optarg)
elif opt == "-r":
wifitap.rate = int(optarg)
elif opt == "-m":
wifitap.mcs = int(optarg)
elif opt == "-t":
wifitap.retries = int(optarg)
elif opt == "-g":
wifitap.hgi = True
elif opt == "-d":
wifitap.debug = True
elif opt == "-v":
wifitap.verb = True
elif opt == "-h":
usage()
if not wifitap.bssid:
print "\nError: BSSID not defined\n"
usage()
# Match and parse BSSID
if re.match('^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$', wifitap.bssid):
wifitap.bssid = wifitap.bssid.lower()
else:
print "\nError: Wrong format for BSSID\n"
usage ()
if wifitap.smac != '':
# Match and parse SMAC
if re.match('^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$', wifitap.smac):
wifitap.smac = wifitap.smac.lower()
else:
print "\nError: Wrong format for SMAC\n"
usage()
print "IN_IFACE: %s" % wifitap.inface
print "OUT_IFACE: %s" % wifitap.outface
print "BSSID: %s" % wifitap.bssid
if wifitap.smac != '':
print "SMAC: %s" % wifitap.smac
def setup_scapy(wifitap):
logging.getLogger("scapy").setLevel(1)
conf.iface = wifitap.outface
# Speed optimization si Scapy does not have to parse payloads
Ether.payload_guess=[]
SNAP.payload_guess=[]
if __name__ == "__main__":
wifitap = WifiTapDevice()
parse_opts(wifitap)
setup_scapy(wifitap)
try:
wifitap.open()
wt_reader = WifiTapReader(wifitap)
intf_reader = InterfaceReader(wifitap)
asyncore.loop()
# Program killed
except KeyboardInterrupt:
print "Stopped by user."
#s.close()
#os.close(f)
sys.exit()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 autoindent