File: test_Handshake.py

package info (click to toggle)
wifite 2.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,196 kB
  • sloc: python: 6,457; sh: 10; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 2,737 bytes parent folder | download
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import unittest

from wifite.model.handshake import Handshake
from wifite.util.process import Process

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


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

    def getFile(self, filename):
        """ Helper method to parse targets from filename """
        import os
        import inspect
        this_file = os.path.abspath(inspect.getsourcefile(self.getFile))
        this_dir = os.path.dirname(this_file)
        return os.path.join(this_dir, 'files', filename)

    def testAnalyze(self):
        hs_file = self.getFile("handshake_exists.cap")
        hs = Handshake(hs_file, bssid='A4:2B:8C:16:6B:3A')
        try:
            hs.analyze()
        except Exception:
            exit()

    @unittest.skipUnless(Process.exists("tshark"), 'tshark is missing')
    def testHandshakeTshark(self):
        print("\nTesting handshake with tshark...")
        hs_file = self.getFile("handshake_exists.cap")
        print("Testing file:", hs_file)

        # Copy file to /tmp to work around tshark permission issues
        import tempfile
        import shutil
        import os

        with tempfile.NamedTemporaryFile(delete=False, suffix='.cap') as tmp:
            temp_file = tmp.name

        try:
            shutil.copy2(hs_file, temp_file)
            hs = Handshake(temp_file, bssid='A4:2B:8C:16:6B:3A')
            handshakes = hs.tshark_handshakes()
            print(f"Found {len(handshakes)} handshake(s): {handshakes}")
            assert len(handshakes) > 0, f'Expected len>0 but got len({len(handshakes)})'
        finally:
            if os.path.exists(temp_file):
                os.unlink(temp_file)

    @unittest.skipUnless(Process.exists("cowpatty"), 'cowpatty is missing')
    @unittest.skip('https://github.com/derv82/wifite2/issues/105')
    def testHandshakeCowpatty(self):
        print("\nTesting handshake with cowpatty...")
        hs_file = self.getFile('handshake_exists.cap')
        hs = Handshake(hs_file, bssid='A4:2B:8C:16:6B:3A')
        assert (len(hs.cowpatty_handshakes()) > 0), f'Expected len>0 but got len({len(hs.cowpatty_handshakes())})'

    @unittest.skipUnless(Process.exists("aircrack-ng"), 'aircrack-ng is missing')
    @unittest.skip('https://github.com/derv82/wifite2/issues/189')
    def testHandshakeAircrack(self):
        print("\nTesting handshake with aircrack-ng...")
        hs_file = self.getFile('handshake_exists.cap')
        hs = Handshake(hs_file, bssid='A4:2B:8C:16:6B:3A')
        assert (len(hs.aircrack_handshakes()) > 0), f'Expected len>0 but got len({len(hs.aircrack_handshakes())})'


if __name__ == '__main__':
    unittest.main()