Skip to content

Commit 2edcf72

Browse files
committed
Removed Pyrcrack class
With the new airmon-ng and airodump-ng APIs with async context managers, proper properties for results and interfaces and callable objects, the "simplified" interface that exposed the Pyrcrack class is no longer needed. Usage is more comprehensive now, and cleanup afterwards should work. Altough examples seem to not wait for __aexit__ to cleanup (thus airmon-ng's created interface would prevail) upon KeyboardInterrupt. Might be caused by https://bugs.python.org/issue29988 wich relates to bpo-29988 ( python/cpython#18334 )
1 parent 6276907 commit 2edcf72

File tree

5 files changed

+28
-102
lines changed

5 files changed

+28
-102
lines changed

docs/examples/scan_for_targets.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
"""Scan for targets and and pretty print some data."""
22
import asyncio
3-
import sys
43

54
import pyrcrack
65

76
from rich.console import Console
7+
from rich.prompt import Prompt
88

99

1010
async def scan_for_targets():
1111
"""Scan for targets, return json."""
1212
console = Console()
1313
console.clear()
1414
console.show_cursor(False)
15-
async with pyrcrack.AirodumpNg() as pdump:
16-
async for result in pdump(sys.argv[1]):
17-
# Current running process will be stored in self.proc
18-
# Be careful, the process will only start when you iter trough
19-
# results. A simple await anext(pdump(...)) would do if you don't
20-
# reallywant to gather results.
21-
console.clear()
22-
console.print(result.table)
23-
await asyncio.sleep(2)
15+
airmon = pyrcrack.AirmonNg()
16+
17+
interface = Prompt.ask(
18+
'Select an interface',
19+
choices=[a['interface'] for a in await airmon.interfaces])
20+
async with airmon(interface) as mon:
21+
async with pyrcrack.AirodumpNg() as pdump:
22+
async for result in pdump(mon.monitor_interface):
23+
console.clear()
24+
console.print(result.table)
25+
await asyncio.sleep(2)
2426

2527

2628
asyncio.run(scan_for_targets())

docs/examples/scan_for_targets_simplified.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

pyrcrack/__init__.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
Aircrack-NG python bindings
44
"""
5-
import asyncio
65
import subprocess
76

87
from .aircrack import AircrackNg # noqa
@@ -17,53 +16,3 @@
1716
def check():
1817
"""Check if aircrack-ng is compatible."""
1918
assert '1.6' in subprocess.check_output(['aircrack-ng', '-v'])
20-
21-
22-
class Pyrcrack:
23-
"""High level aircrack-ng interface.
24-
25-
Arguments:
26-
27-
list_waiting_time: Time (in seconds) to wait for a network scan
28-
"""
29-
def __init__(self):
30-
"""Set up pyrcrack instance."""
31-
self.iface = None
32-
33-
@property
34-
async def interfaces(self):
35-
"""List of currently available interfaces as reported by airmon-ng
36-
37-
This is an awaitable property, use it as in::
38-
39-
await Pyrcrack().interfaces
40-
41-
Returns: None
42-
"""
43-
return [a['interface'] for a in await AirmonNg().list_wifis()]
44-
45-
async def set_interface(self, interface):
46-
"""Select an interface, set it on monitor mode
47-
48-
Will set `iface` property.
49-
"""
50-
assert interface in await self.interfaces
51-
async with AirmonNg() as airmon:
52-
interface = await airmon.set_monitor(interface)
53-
self.iface = interface[0]['monitor']['interface']
54-
55-
@property
56-
async def access_points(self) -> list:
57-
"""Return a list of access points by scanning with airodump-ng
58-
59-
This is a basic, hihg-level scan, for 10 seconds, on all channels
60-
without extra options, for more custom searches uses directly the
61-
AirodumpNg async context manager.
62-
63-
Returns: List `AccessPoint` instances
64-
"""
65-
async with AirodumpNg() as pdump:
66-
async for res in pdump(self.iface):
67-
if res:
68-
return res
69-
asyncio.sleep(10)

pyrcrack/airmon.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class AirmonNg(ExecutorHelper):
2020
def __init__(self, *args, **kwargs):
2121
super().__init__(*args, **kwargs)
2222
self.monitor_enabled = []
23+
self.interface = None
2324

2425
async def run(self, *args, **kwargs):
2526
"""Check argument position. Forced for this one."""

tests/unit/test_airmon.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,20 @@ async def test_run_airmon():
77
import asynctest
88
from pyrcrack import AirmonNg
99

10-
async with AirmonNg() as airmong:
11-
with asynctest.mock.patch("asyncio.create_subprocess_exec") as runmock:
12-
with pytest.raises(AssertionError):
13-
await airmong.run('foo')
14-
await airmong.run('start')
10+
with asynctest.mock.patch("asyncio.create_subprocess_exec") as runmock:
11+
with pytest.raises(AssertionError):
12+
await AirmonNg().run('foo')
13+
await AirmonNg().run('start')
1514

16-
runmock.assert_called_with('airmon-ng',
17-
'start',
18-
stderr=-1,
19-
stdout=-1,
20-
stdin=-1)
15+
runmock.assert_called_with('airmon-ng',
16+
'start',
17+
stderr=-1,
18+
stdout=-1,
19+
stdin=-1)
2120

22-
async with AirmonNg() as airmong:
23-
with asynctest.mock.patch("asyncio.create_subprocess_exec") as runmock:
24-
await airmong.run()
25-
runmock.assert_called_with('airmon-ng',
26-
stderr=-1,
27-
stdout=-1,
28-
stdin=-1)
21+
with asynctest.mock.patch("asyncio.create_subprocess_exec") as runmock:
22+
await AirmonNg().run()
23+
runmock.assert_called_with('airmon-ng',
24+
stderr=-1,
25+
stdout=-1,
26+
stdin=-1)

0 commit comments

Comments
 (0)