| 1 |
|
| 2 |
""" pentest.py |
| 3 |
|
| 4 |
Copyright (C) 2016 Dale V. Patterson ([email protected]) |
| 5 |
|
| 6 |
This program is free software: you can redistribute it and/or modify it under |
| 7 |
the terms of the GNU General Public License as published by the Free Software |
| 8 |
Foundation, either version 3 of the License, or (at your option) any later |
| 9 |
version. |
| 10 |
|
| 11 |
Redistribution and use in source and binary forms, with or without |
| 12 |
modifications, are permitted provided that the following conditions are met: |
| 13 |
o Redistributions of source code must retain the above copyright notice, this |
| 14 |
list of conditions and the following disclaimer. |
| 15 |
o Redistributions in binary form must reproduce the above copyright notice, |
| 16 |
this list of conditions and the following disclaimer in the documentation |
| 17 |
and/or other materials provided with the distribution. |
| 18 |
o Neither the name of the orginal author Dale V. Patterson nor the names of |
| 19 |
any contributors may be used to endorse or promote products derived from |
| 20 |
this software without specific prior written permission. |
| 21 |
|
| 22 |
Example for setting up a wireless environment - must be done as root |
| 23 |
|
| 24 |
""" |
| 25 |
|
| 26 |
from __future__ import print_function |
| 27 |
import argparse as ap |
| 28 |
import time |
| 29 |
import sys |
| 30 |
import pyric |
| 31 |
import pyric.pyw as pyw |
| 32 |
import pyric.utils.hardware as hw |
| 33 |
from pyric.utils.channels import rf2ch |
| 34 |
|
| 35 |
def execute(dev): |
| 36 |
print('Setting up...') |
| 37 |
|
| 38 |
ifaces = pyw.interfaces() |
| 39 |
wifaces = pyw.winterfaces() |
| 40 |
if dev not in ifaces: |
| 41 |
print("Device {0} is not valid, use one of {1}".format(dev,ifaces)) |
| 42 |
return |
| 43 |
elif dev not in wifaces: |
| 44 |
print("Device {0} is not wireless, use one of {1}".format(dev,wifaces)) |
| 45 |
|
| 46 |
|
| 47 |
print("Regulatory Domain currently: ", pyw.regget()) |
| 48 |
dinfo = pyw.devinfo(dev) |
| 49 |
card = dinfo['card'] |
| 50 |
pinfo = pyw.phyinfo(card) |
| 51 |
driver = hw.ifdriver(card.dev) |
| 52 |
chipset = hw.ifchipset(driver) |
| 53 |
|
| 54 |
|
| 55 |
pyw.down(card) |
| 56 |
pyw.macset(card,'00:03:93:57:54:46') |
| 57 |
|
| 58 |
|
| 59 |
msg = "Using {0} currently in mode: {1}\n".format(card,dinfo['mode']) |
| 60 |
msg += "\tDriver: {0} Chipset: {1}\n".format(driver,chipset) |
| 61 |
if dinfo['mode'] == 'managed': |
| 62 |
msg += "\tcurrently on channel {0} width {1}\n".format(rf2ch(dinfo['RF']), |
| 63 |
dinfo['CHW']) |
| 64 |
msg += "\tSupports modes {0}\n".format(pinfo['modes']) |
| 65 |
msg += "\tSupports commands {0}".format(pinfo['commands']) |
| 66 |
msg += "\thw addr {0}".format(pyw.macget(card)) |
| 67 |
print(msg) |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
print('Preparing pent0 for monitor mode') |
| 73 |
pdev = 'pent0' |
| 74 |
pcard = pyw.devadd(card, pdev, 'monitor') |
| 75 |
for iface in pyw.ifaces(card): |
| 76 |
if iface[0].dev != pcard.dev: |
| 77 |
print("deleting {0} in mode {1}".format(iface[0],iface[1])) |
| 78 |
pyw.devdel(iface[0]) |
| 79 |
pyw.up(pcard) |
| 80 |
print("Using", pcard) |
| 81 |
|
| 82 |
print("Setting channel to 6 NOHT") |
| 83 |
pyw.chset(pcard,6,None) |
| 84 |
msg = "Virtual interface {0} in monitor mode on ch 6".format(pcard) |
| 85 |
print(msg + ", using hwaddr: {0}".format(pyw.macget(pcard))) |
| 86 |
|
| 87 |
|
| 88 |
try: |
| 89 |
print('Now ready to do stuff') |
| 90 |
print('For example, run wireshark to verify card is seeing all packets') |
| 91 |
print('Hit Ctrl-C to quit and restore') |
| 92 |
while True: time.sleep(1) |
| 93 |
except KeyboardInterrupt: |
| 94 |
pass |
| 95 |
|
| 96 |
|
| 97 |
print('Restoring', card, 'mode =', dinfo['mode'], 'mac =', dinfo['mac']) |
| 98 |
card = pyw.devadd(pcard,card.dev,dinfo['mode']) |
| 99 |
print('Deleting', pcard) |
| 100 |
pyw.devdel(pcard) |
| 101 |
pyw.macset(card,dinfo['mac']) |
| 102 |
pyw.up(card) |
| 103 |
print("card ", card, " restored") |
| 104 |
|
| 105 |
if __name__ == '__main__': |
| 106 |
|
| 107 |
print("Wireless Pentest Environment using PyRIC v{0}".format(pyric.version)) |
| 108 |
argp = ap.ArgumentParser(description="Wireless Pentest") |
| 109 |
argp.add_argument('-d','--dev',help="Pentesting Wireless Device") |
| 110 |
args = argp.parse_args() |
| 111 |
try: |
| 112 |
dname = args.dev |
| 113 |
if dname is None: |
| 114 |
print("usage: python pentest.py -d <dev>") |
| 115 |
sys.exit(0) |
| 116 |
else: |
| 117 |
execute(dname) |
| 118 |
except pyric.error as e: |
| 119 |
print(e) |