Added Airmon-ng test.

This commit is contained in:
derv82
2018-04-15 23:10:47 -04:00
parent 64c0662d30
commit 42781dedcc
2 changed files with 39 additions and 10 deletions

24
tests/test_Airmon.py Normal file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import sys
sys.path.insert(0, '..')
from wifite.tools.airmon import Airmon
import unittest
class TestAirmon(unittest.TestCase):
def test_airmon_start(self):
# From https://github.com/derv82/wifite2/issues/67
stdout = '''
PHY Interface Driver Chipset
phy0 wlan0 iwlwifi Intel Corporation Centrino Ultimate-N 6300 (rev 3e)
(mac80211 monitor mode vif enabled for [phy0]wlan0 on [phy0]wlan0mon)
(mac80211 station mode vif disabled for [phy0]wlan0)
'''
mon_iface = Airmon._parse_airmon_start(stdout)
assert mon_iface == 'wlan0mon', 'Expected monitor-mode interface to be "wlan0mon" but got "{}"'.format(mon_iface)

View File

@@ -101,16 +101,7 @@ class Airmon(object):
Color.p("{+} enabling {G}monitor mode{W} on {C}%s{W}... " % iface) Color.p("{+} enabling {G}monitor mode{W} on {C}%s{W}... " % iface)
(out,err) = Process.call('airmon-ng start %s' % iface) (out,err) = Process.call('airmon-ng start %s' % iface)
# Find the interface put into monitor mode (if any) mon_iface = Airmon._parse_airmon_start(out)
mon_iface = None
for line in out.split('\n'):
if 'monitor mode' in line and 'enabled' in line and ' on ' in line:
mon_iface = line.split(' on ')[1]
if ']' in mon_iface:
mon_iface = mon_iface.split(']')[1]
if ')' in mon_iface:
mon_iface = mon_iface.split(')')[0]
break
if mon_iface is None: if mon_iface is None:
# Airmon did not enable monitor mode on an interface # Airmon did not enable monitor mode on an interface
@@ -138,6 +129,20 @@ class Airmon(object):
return mon_iface return mon_iface
@staticmethod
def _parse_airmon_start(stdout):
# Find the interface put into monitor mode (if any)
mon_iface = None
for line in stdout.split('\n'):
if 'monitor mode' in line and 'enabled' in line and ' on ' in line:
mon_iface = line.split(' on ')[1]
if ']' in mon_iface:
mon_iface = mon_iface.split(']')[1]
if ')' in mon_iface:
mon_iface = mon_iface.split(')')[0]
break
return mon_iface
@staticmethod @staticmethod
def stop(iface): def stop(iface):