fix: --clear does not start the agent anymore
This commit is contained in:
parent
a96dead519
commit
87e46610f9
175
bin/pwnagotchi
175
bin/pwnagotchi
@ -1,19 +1,91 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
import logging
|
||||||
|
import argparse
|
||||||
|
import time
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
import pwnagotchi
|
||||||
|
import pwnagotchi.grid as grid
|
||||||
|
import pwnagotchi.utils as utils
|
||||||
|
import pwnagotchi.plugins as plugins
|
||||||
|
|
||||||
|
from pwnagotchi.identity import KeyPair
|
||||||
|
from pwnagotchi.agent import Agent
|
||||||
|
from pwnagotchi.ui.display import Display
|
||||||
|
|
||||||
|
|
||||||
|
def do_clear(display):
|
||||||
|
logging.info("clearing the display ...")
|
||||||
|
display.clear()
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def do_manual_mode(agent):
|
||||||
|
logging.info("entering manual mode ...")
|
||||||
|
|
||||||
|
agent.mode = 'manual'
|
||||||
|
agent.last_session.parse(agent.view(), args.skip_session)
|
||||||
|
if not args.skip_session:
|
||||||
|
logging.info(
|
||||||
|
"the last session lasted %s (%d completed epochs, trained for %d), average reward:%s (min:%s max:%s)" % (
|
||||||
|
agent.last_session.duration_human,
|
||||||
|
agent.last_session.epochs,
|
||||||
|
agent.last_session.train_epochs,
|
||||||
|
agent.last_session.avg_reward,
|
||||||
|
agent.last_session.min_reward,
|
||||||
|
agent.last_session.max_reward))
|
||||||
|
|
||||||
|
while True:
|
||||||
|
display.on_manual_mode(agent.last_session)
|
||||||
|
time.sleep(5)
|
||||||
|
if grid.is_connected():
|
||||||
|
plugins.on('internet_available', agent)
|
||||||
|
|
||||||
|
|
||||||
|
def do_auto_mode(agent):
|
||||||
|
logging.info("entering auto mode ...")
|
||||||
|
|
||||||
|
agent.mode = 'auto'
|
||||||
|
agent.start()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
# recon on all channels
|
||||||
|
agent.recon()
|
||||||
|
# get nearby access points grouped by channel
|
||||||
|
channels = agent.get_access_points_by_channel()
|
||||||
|
# for each channel
|
||||||
|
for ch, aps in channels:
|
||||||
|
agent.set_channel(ch)
|
||||||
|
|
||||||
|
if not agent.is_stale() and agent.any_activity():
|
||||||
|
logging.info("%d access points on channel %d" % (len(aps), ch))
|
||||||
|
|
||||||
|
# for each ap on this channel
|
||||||
|
for ap in aps:
|
||||||
|
# send an association frame in order to get for a PMKID
|
||||||
|
agent.associate(ap)
|
||||||
|
# deauth all client stations in order to get a full handshake
|
||||||
|
for sta in ap['clients']:
|
||||||
|
agent.deauth(ap, sta)
|
||||||
|
|
||||||
|
# An interesting effect of this:
|
||||||
|
#
|
||||||
|
# From Pwnagotchi's perspective, the more new access points
|
||||||
|
# and / or client stations nearby, the longer one epoch of
|
||||||
|
# its relative time will take ... basically, in Pwnagotchi's universe,
|
||||||
|
# WiFi electromagnetic fields affect time like gravitational fields
|
||||||
|
# affect ours ... neat ^_^
|
||||||
|
agent.next_epoch()
|
||||||
|
|
||||||
|
if grid.is_connected():
|
||||||
|
plugins.on('internet_available', agent)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logging.exception("main loop exception")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import argparse
|
|
||||||
import time
|
|
||||||
import logging
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
import pwnagotchi
|
|
||||||
import pwnagotchi.grid as grid
|
|
||||||
import pwnagotchi.utils as utils
|
|
||||||
import pwnagotchi.plugins as plugins
|
|
||||||
|
|
||||||
from pwnagotchi.identity import KeyPair
|
|
||||||
from pwnagotchi.agent import Agent
|
|
||||||
from pwnagotchi.ui.display import Display
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.yml',
|
parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.yml',
|
||||||
@ -55,77 +127,14 @@ if __name__ == '__main__':
|
|||||||
plugins.load(config)
|
plugins.load(config)
|
||||||
|
|
||||||
display = Display(config=config, state={'name': '%s>' % pwnagotchi.name()})
|
display = Display(config=config, state={'name': '%s>' % pwnagotchi.name()})
|
||||||
keypair = KeyPair(view=display)
|
|
||||||
agent = Agent(view=display, config=config, keypair=keypair)
|
|
||||||
|
|
||||||
logging.info("%s@%s (v%s)" % (pwnagotchi.name(), agent.fingerprint(), pwnagotchi.version))
|
|
||||||
|
|
||||||
for _, plugin in plugins.loaded.items():
|
|
||||||
logging.debug("plugin '%s' v%s" % (plugin.__class__.__name__, plugin.__version__))
|
|
||||||
|
|
||||||
if args.do_clear:
|
if args.do_clear:
|
||||||
logging.info("clearing the display ...")
|
do_clear(display)
|
||||||
display.clear()
|
exit(0)
|
||||||
|
|
||||||
elif args.do_manual:
|
agent = Agent(view=display, config=config, keypair=KeyPair(view=display))
|
||||||
logging.info("entering manual mode ...")
|
|
||||||
|
|
||||||
agent.mode = 'manual'
|
|
||||||
agent.last_session.parse(agent.view(), args.skip_session)
|
|
||||||
if not args.skip_session:
|
|
||||||
logging.info(
|
|
||||||
"the last session lasted %s (%d completed epochs, trained for %d), average reward:%s (min:%s max:%s)" % (
|
|
||||||
agent.last_session.duration_human,
|
|
||||||
agent.last_session.epochs,
|
|
||||||
agent.last_session.train_epochs,
|
|
||||||
agent.last_session.avg_reward,
|
|
||||||
agent.last_session.min_reward,
|
|
||||||
agent.last_session.max_reward))
|
|
||||||
|
|
||||||
while True:
|
|
||||||
display.on_manual_mode(agent.last_session)
|
|
||||||
time.sleep(5)
|
|
||||||
if grid.is_connected():
|
|
||||||
plugins.on('internet_available', agent)
|
|
||||||
|
|
||||||
|
if args.do_manual:
|
||||||
|
do_manual_mode(agent)
|
||||||
else:
|
else:
|
||||||
logging.info("entering auto mode ...")
|
do_auto_mode(agent)
|
||||||
|
|
||||||
agent.mode = 'auto'
|
|
||||||
agent.start()
|
|
||||||
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
# recon on all channels
|
|
||||||
agent.recon()
|
|
||||||
# get nearby access points grouped by channel
|
|
||||||
channels = agent.get_access_points_by_channel()
|
|
||||||
# for each channel
|
|
||||||
for ch, aps in channels:
|
|
||||||
agent.set_channel(ch)
|
|
||||||
|
|
||||||
if not agent.is_stale() and agent.any_activity():
|
|
||||||
logging.info("%d access points on channel %d" % (len(aps), ch))
|
|
||||||
|
|
||||||
# for each ap on this channel
|
|
||||||
for ap in aps:
|
|
||||||
# send an association frame in order to get for a PMKID
|
|
||||||
agent.associate(ap)
|
|
||||||
# deauth all client stations in order to get a full handshake
|
|
||||||
for sta in ap['clients']:
|
|
||||||
agent.deauth(ap, sta)
|
|
||||||
|
|
||||||
# An interesting effect of this:
|
|
||||||
#
|
|
||||||
# From Pwnagotchi's perspective, the more new access points
|
|
||||||
# and / or client stations nearby, the longer one epoch of
|
|
||||||
# its relative time will take ... basically, in Pwnagotchi's universe,
|
|
||||||
# WiFi electromagnetic fields affect time like gravitational fields
|
|
||||||
# affect ours ... neat ^_^
|
|
||||||
agent.next_epoch()
|
|
||||||
|
|
||||||
if grid.is_connected():
|
|
||||||
plugins.on('internet_available', agent)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logging.exception("main loop exception")
|
|
||||||
|
@ -49,6 +49,10 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
|
|||||||
if not os.path.exists(config['bettercap']['handshakes']):
|
if not os.path.exists(config['bettercap']['handshakes']):
|
||||||
os.makedirs(config['bettercap']['handshakes'])
|
os.makedirs(config['bettercap']['handshakes'])
|
||||||
|
|
||||||
|
logging.info("%s@%s (v%s)" % (pwnagotchi.name(), self.fingerprint(), pwnagotchi.version))
|
||||||
|
for _, plugin in plugins.loaded.items():
|
||||||
|
logging.debug("plugin '%s' v%s" % (plugin.__class__.__name__, plugin.__version__))
|
||||||
|
|
||||||
def config(self):
|
def config(self):
|
||||||
return self._config
|
return self._config
|
||||||
|
|
||||||
@ -179,8 +183,8 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
|
|||||||
if ap['encryption'] == '' or ap['encryption'] == 'OPEN':
|
if ap['encryption'] == '' or ap['encryption'] == 'OPEN':
|
||||||
continue
|
continue
|
||||||
elif ap['hostname'] not in whitelist \
|
elif ap['hostname'] not in whitelist \
|
||||||
and ap['mac'].lower() not in whitelist \
|
and ap['mac'].lower() not in whitelist \
|
||||||
and ap['mac'][:8].lower() not in whitelist:
|
and ap['mac'][:8].lower() not in whitelist:
|
||||||
if self._filter_included(ap):
|
if self._filter_included(ap):
|
||||||
aps.append(ap)
|
aps.append(ap)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -337,11 +341,12 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
|
|||||||
(ap, sta) = ap_and_station
|
(ap, sta) = ap_and_station
|
||||||
self._last_pwnd = ap['hostname'] if ap['hostname'] != '' and ap[
|
self._last_pwnd = ap['hostname'] if ap['hostname'] != '' and ap[
|
||||||
'hostname'] != '<hidden>' else ap_mac
|
'hostname'] != '<hidden>' else ap_mac
|
||||||
logging.warning("!!! captured new handshake on channel %d, %d dBm: %s (%s) -> %s [%s (%s)] !!!" % ( \ ))
|
logging.warning(
|
||||||
ap['channel'],
|
"!!! captured new handshake on channel %d, %d dBm: %s (%s) -> %s [%s (%s)] !!!" % (
|
||||||
ap['rssi'],
|
ap['channel'],
|
||||||
sta['mac'], sta['vendor'],
|
ap['rssi'],
|
||||||
ap['hostname'], ap['mac'], ap['vendor']))
|
sta['mac'], sta['vendor'],
|
||||||
|
ap['hostname'], ap['mac'], ap['vendor']))
|
||||||
plugins.on('handshake', self, filename, ap, sta)
|
plugins.on('handshake', self, filename, ap, sta)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -394,7 +399,7 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
|
|||||||
self._view.on_assoc(ap)
|
self._view.on_assoc(ap)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logging.info("sending association frame to %s (%s %s) on channel %d [%d clients], %d dBm..." % ( \
|
logging.info("sending association frame to %s (%s %s) on channel %d [%d clients], %d dBm..." % ( \
|
||||||
ap['hostname'], ap['mac'], ap['vendor'], ap['channel'], len(ap['clients']), ap['rssi']))
|
ap['hostname'], ap['mac'], ap['vendor'], ap['channel'], len(ap['clients']), ap['rssi']))
|
||||||
self.run('wifi.assoc %s' % ap['mac'])
|
self.run('wifi.assoc %s' % ap['mac'])
|
||||||
self._epoch.track(assoc=True)
|
self._epoch.track(assoc=True)
|
||||||
@ -415,8 +420,8 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
|
|||||||
self._view.on_deauth(sta)
|
self._view.on_deauth(sta)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logging.info("deauthing %s (%s) from %s (%s %s) on channel %d, %d dBm ..." % (
|
logging.info("deauthing %s (%s) from %s (%s %s) on channel %d, %d dBm ..." % (
|
||||||
sta['mac'], sta['vendor'], ap['hostname'], ap['mac'], ap['vendor'], ap['channel'], ap['rssi']))
|
sta['mac'], sta['vendor'], ap['hostname'], ap['mac'], ap['vendor'], ap['channel'], ap['rssi']))
|
||||||
self.run('wifi.deauth %s' % sta['mac'])
|
self.run('wifi.deauth %s' % sta['mac'])
|
||||||
self._epoch.track(deauth=True)
|
self._epoch.track(deauth=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user