Skip to content

Commit 476466c

Browse files
authored
Merge pull request #105 from tiagogalvao/tests
Tests
2 parents 29c4e91 + 8aaaf1f commit 476466c

File tree

14 files changed

+122
-86
lines changed

14 files changed

+122
-86
lines changed

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
chardet
12
pytest-flake8
3+
scapy
4+
argparse~=1.2.1

runtests.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#sleep 2
55
#sh tests/test_flake8.sh
66
#sleep 2
7+
clear
8+
79
echo "** Starting unittest/pytest .."
8-
sleep 5
10+
sleep 2
911
python3 -m unittest discover tests -v
1012
sleep 2
1113
echo "** runtests.sh test script at the end"

tests/files/airodump.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ F2:64:20:05:BF:90, 2015-05-30 11:28:43, 2015-05-30 11:28:50, 6, 54, WPA2, CCMP
2222
00:1D:D5:9B:11:00, 2015-05-30 11:28:43, 2015-05-30 11:28:50, 6, 54, WPA2, CCMP TKIP,PSK, -52, 32, 6, 0. 0. 0. 0, 9, HOME-1102,
2323
00:24:7B:AB:5C:EE, 2015-05-30 11:28:43, 2015-05-30 11:28:50, 6, 54, WPA2 WPA, CCMP TKIP,PSK, -55, 16, 25, 0. 0. 0. 0, 11, myqwest0445,
2424
02:1D:D5:9B:11:00, 2015-05-30 11:28:43, 2015-05-30 11:28:50, 6, 54, WPA2, CCMP,PSK, -53, 41, 0, 0. 0. 0. 0, 0, ,
25-
06:1D:D5:9B:11:00, 2015-05-30 11:28:43, 2015-05-30 11:28:50, 6, 54, OPN, , , -53, 56, 0, 0. 0. 0. 0, 11, xfinitywifi,
25+
06:1D:D5:9B:11:00, 2015-05-30 11:28:43, 2015-05-30 11:28:50, 6, 54, OPN, , , -53, 56, 0, 0. 0. 0. 0, 9, 这种情威灵顿酒店À,
2626
00:F7:6F:CD:B2:2A, 2015-05-30 11:28:43, 2015-05-30 11:28:50, 6, 54, WPA2, CCMP,PSK, -48, 44, 0, 0. 0. 0. 0, 13, im human 2015,
2727
30:85:A9:39:D2:18, 2015-05-30 11:28:43, 2015-05-30 11:28:50, 6, 54, WPA2, CCMP,PSK, -21, 44, 4, 0. 0. 0. 0, 32, Uncle Router's Gigabit LAN Party,
2828
00:0E:58:FA:7C:61, 2015-05-30 11:28:44, 2015-05-30 11:28:49, 6, -1, WPA, , , -1, 0, 57, 0. 0. 0. 0, 0, ,
2929
00:0E:58:F8:0B:B5, 2015-05-30 11:28:44, 2015-05-30 11:28:48, 6, -1, WPA, , , -1, 0, 59, 0. 0. 0. 0, 0, ,
3030
28:01:00:00:D0:00, 2015-05-30 11:28:44, 2015-05-30 11:28:44, 6, -1, , , , -1, 0, 0, 0. 0. 0. 0, 0, ,
3131
00:0E:58:E9:36:B3, 2015-05-30 11:28:44, 2015-05-30 11:28:48, 6, -1, WPA, , , -1, 0, 2, 0. 0. 0. 0, 0, ,
32-
05:00:40:00:BB:7C, 2015-05-30 11:28:50, 2015-05-30 11:28:50, -1, -1, , , , -1, 0, 0, 0. 0. 0. 0, 0, ,
32+
05:00:40:00:BB:7C, 2015-05-30 11:28:50, 2015-05-30 11:28:50, -1, -1, , , , -1, 0, 0, 0. 0. 0. 0, 0, ,
3333

3434
Station MAC, First time seen, Last time seen, Power, # packets, BSSID, Probed ESSIDs
3535
3A:01:44:32:C8:5C, 2015-05-30 11:28:44, 2015-05-30 11:28:44, -69, 3, 28:01:00:00:D0:00,

tests/test_Airmon.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
43
import sys
5-
6-
sys.path.insert(0, '..')
7-
4+
import unittest
85
from wifite.tools.airmon import Airmon
96

10-
import unittest
7+
sys.path.insert(0, '..')
118

129

1310
class TestAirmon(unittest.TestCase):

tests/test_Airodump.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@
22
# -*- coding: utf-8 -*-
33

44
import sys
5-
6-
sys.path.insert(0, '..')
7-
85
from wifite.tools.airodump import Airodump
9-
106
import unittest
117

8+
sys.path.insert(0, '..')
9+
1210

1311
class TestAirodump(unittest.TestCase):
1412
""" Test suite for Wifite's interaction with the Airodump tool """
1513

14+
def test_airodump(self):
15+
csv_filename = self.getFile('airodump.csv')
16+
targets = Airodump.get_targets_from_csv(csv_filename)
17+
18+
print('')
19+
for target in targets:
20+
print("Testing ESSID: ", target.essid)
21+
if target.essid is not None:
22+
assert target.essid_len == len(target.essid), \
23+
f'ESSID length is {target.essid_len} but ESSID is {len(target.essid)} - [{target.essid}]'
24+
1625
def test_airodump_weird_characters(self):
1726
csv_filename = self.getFile('airodump-weird-ssids.csv')
1827
targets = Airodump.get_targets_from_csv(csv_filename)
@@ -35,11 +44,10 @@ def test_airodump_weird_characters(self):
3544

3645
# Hidden access point
3746
target = targets[4]
38-
assert target.essid_known == False, 'ESSID full of null characters should not be known'
47+
assert target.essid_known is False, 'ESSID full of null characters should not be known'
3948
expected = None
4049
assert target.essid == expected, f'Expected ESSID ({expected}) but got ({target.essid})'
41-
42-
assert target.essid_len == 19, f'ESSID length shold be 19, but got {target.essid_len}'
50+
assert target.essid_len == 19, f'ESSID [unknow chars] length should be 19, but got {target.essid_len}'
4351

4452
def getFile(self, filename):
4553
""" Helper method to parse targets from filename """

tests/test_Handshake.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
# -*- coding: utf-8 -*-
33

44
import sys
5+
import unittest
56

67
from wifite.model.handshake import Handshake
78
from wifite.util.process import Process
89

910
sys.path.insert(0, '..')
1011

11-
import unittest
12-
1312

1413
class TestHandshake(unittest.TestCase):
1514
""" Test suite for Target parsing an generation """
1615

1716
def getFile(self, filename):
1817
""" Helper method to parse targets from filename """
19-
import os, inspect
18+
import os
19+
import inspect
2020
this_file = os.path.abspath(inspect.getsourcefile(self.getFile))
2121
this_dir = os.path.dirname(this_file)
2222
return os.path.join(this_dir, 'files', filename)
@@ -31,28 +31,32 @@ def testAnalyze(self):
3131

3232
@unittest.skipUnless(Process.exists("tshark"), 'tshark is missing')
3333
def testHandshakeTshark(self):
34+
print("\nTesting handshake with tshark...")
3435
hs_file = self.getFile("handshake_exists.cap")
3536
hs = Handshake(hs_file, bssid='A4:2B:8C:16:6B:3A')
36-
assert (len(hs.tshark_handshakes()) > 0)
37+
assert (len(hs.tshark_handshakes()) > 0), f'Expected len>0 but got len({len(hs.tshark_handshakes())})'
3738

39+
# TODO: Pyrit is broken
3840
@unittest.skipUnless(Process.exists("pyrit"), 'pyrit is missing')
3941
def testHandshakePyrit(self):
42+
print("\nTesting handshake with pyrit...")
4043
hs_file = self.getFile("handshake_exists.cap")
4144
hs = Handshake(hs_file, bssid='A4:2B:8C:16:6B:3A')
42-
assert (len(hs.pyrit_handshakes()) > 0)
45+
assert (len(hs.pyrit_handshakes()) > 0), f'Expected len>0 but got len({len(hs.pyrit_handshakes())})'
4346

4447
@unittest.skipUnless(Process.exists("cowpatty"), 'cowpatty is missing')
4548
def testHandshakeCowpatty(self):
49+
print("\nTesting handshake with cowpatty...")
4650
hs_file = self.getFile('handshake_exists.cap')
4751
hs = Handshake(hs_file, bssid='A4:2B:8C:16:6B:3A')
48-
hs.divine_bssid_and_essid()
49-
assert (len(hs.cowpatty_handshakes()) > 0)
52+
assert (len(hs.cowpatty_handshakes()) > 0), f'Expected len>0 but got len({len(hs.cowpatty_handshakes())})'
5053

5154
@unittest.skipUnless(Process.exists("aircrack-ng"), 'aircrack-ng is missing')
5255
def testHandshakeAircrack(self):
56+
print("\nTesting handshake with aircrack-ng...")
5357
hs_file = self.getFile('handshake_exists.cap')
5458
hs = Handshake(hs_file, bssid='A4:2B:8C:16:6B:3A')
55-
assert (len(hs.aircrack_handshakes()) > 0)
59+
assert (len(hs.aircrack_handshakes()) > 0), f'Expected len>0 but got len({len(hs.aircrack_handshakes())})'
5660

5761

5862
if __name__ == '__main__':

tests/test_Target.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
# -*- coding: utf-8 -*-
33

44
import unittest
5-
65
from wifite.tools.airodump import Airodump
76

87

98
class TestTarget(unittest.TestCase):
109
""" Test suite for Target parsing an generation """
11-
1210
airodump_csv = 'airodump.csv'
1311

1412
def getTargets(self, filename):
1513
""" Helper method to parse targets from filename """
16-
import os, inspect
14+
import os
15+
import inspect
1716
this_file = os.path.abspath(inspect.getsourcefile(TestTarget.getTargets))
1817
this_dir = os.path.dirname(this_file)
1918
csv_file = os.path.join(this_dir, 'files', filename)

tools/pyrit/cpyrit/pckttools.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,18 @@ def isFlagSet(self, name, value):
7777
"""
7878
field, val = self.getfield_and_val(name)
7979
if isEnumField(field):
80-
if val not in field.i2s:
81-
return False
82-
return field.i2s[val] == value
80+
if field.i2s is not None:
81+
if val not in field.i2s:
82+
return False
83+
return field.i2s[val] == value
84+
8385
else:
8486
try:
8587
return (1 << field.names.index(value)) & self.__getattr__(name) != 0
8688
except:
8789
return (1 << field.names.index([value])) & self.__getattr__(name) != 0
90+
91+
8892
scapy.packet.Packet.isFlagSet = isFlagSet
8993
del isFlagSet
9094

@@ -599,12 +603,15 @@ def open_offline(self, fname):
599603

600604
def read(self):
601605
"""Read one packet from the capture-source."""
602-
r = _cpyrit_cpu.PcapDevice.read(self)
603-
if r is not None:
604-
ts, pckt_string = r
605-
pckt = self.datalink_handler(pckt_string)
606-
return pckt
607-
else:
606+
try:
607+
r = _cpyrit_cpu.PcapDevice.read(self)
608+
if r is not None:
609+
ts, pckt_string = r
610+
pckt = self.datalink_handler(pckt_string)
611+
return pckt
612+
else:
613+
return None
614+
except:
608615
return None
609616

610617
def __iter__(self):

tools/pyrit/pyrit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ if __name__ == "__main__":
55
try:
66
pyrit_cli.Pyrit_CLI().initFromArgv()
77
except (KeyboardInterrupt, SystemExit):
8-
print( >> sys.stderr, "\nInterrupted..."
9-
except pyrit_cli.PyritRuntimeError, e:
8+
print("\nInterrupted...")
9+
except pyrit_cli.PyritRuntimeError as e:
1010
sys.exit(e)

0 commit comments

Comments
 (0)