From a62016c5b45d44d86cdef3b2dc48f6d413f4e6c4 Mon Sep 17 00:00:00 2001 From: evilsocket <evilsocket@gmail.com> Date: Sat, 21 Sep 2019 18:52:00 +0200 Subject: [PATCH] added support for 5Ghz --- .../root/pwnagotchi/scripts/core/__init__.py | 11 +++++ .../pwnagotchi/scripts/pwnagotchi/agent.py | 5 +++ .../pwnagotchi/scripts/pwnagotchi/ai/gym.py | 41 +++++++++---------- .../scripts/pwnagotchi/mesh/wifi.py | 2 +- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/core/__init__.py b/sdcard/rootfs/root/pwnagotchi/scripts/core/__init__.py index ddb77cd..4321676 100644 --- a/sdcard/rootfs/root/pwnagotchi/scripts/core/__init__.py +++ b/sdcard/rootfs/root/pwnagotchi/scripts/core/__init__.py @@ -40,6 +40,17 @@ def iface_address(ifname): return line.split(' ')[1].strip() return None + +def iface_channels(ifname): + channels = [] + output = subprocess.getoutput("/sbin/iwlist %s freq" % ifname) + for line in output.split("\n"): + line = line.strip() + if line.startswith("Channel "): + channels.append(int(line.split()[1])) + return channels + + def led(on=True): with open('/sys/class/leds/led0/brightness', 'w+t') as fp: fp.write("%d" % (0 if on is True else 1)) diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/agent.py b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/agent.py index e0e7864..82ae1a0 100644 --- a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/agent.py +++ b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/agent.py @@ -28,6 +28,7 @@ class Agent(Client, AsyncAdvertiser, AsyncTrainer): self._started_at = time.time() self._filter = None if config['main']['filter'] is None else re.compile(config['main']['filter']) self._current_channel = 0 + self._supported_channels = core.iface_channels(config['main']['iface']) self._view = view self._access_points = [] self._last_pwnd = None @@ -43,6 +44,9 @@ class Agent(Client, AsyncAdvertiser, AsyncTrainer): pass return False + def supported_channels(self): + return self._supported_channels + def on_ai_ready(self): self._view.on_ai_ready() @@ -107,6 +111,7 @@ class Agent(Client, AsyncAdvertiser, AsyncTrainer): core.log("waiting for monitor interface %s ..." % mon_iface) time.sleep(1) + core.log("supported channels: %s" % self._supported_channels) core.log("handshakes will be collected inside %s" % self._config['bettercap']['handshakes']) self._reset_wifi_settings() diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ai/gym.py b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ai/gym.py index 82678c9..0e713a1 100644 --- a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ai/gym.py +++ b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ai/gym.py @@ -11,28 +11,21 @@ from pwnagotchi.ai.parameter import Parameter class Environment(gym.Env): metadata = {'render.modes': ['human']} params = [ - # Parameter('advertise', trainable=False), - # Parameter('deauth', trainable=False), - # Parameter('associate', trainable=False), + Parameter('min_rssi', min_value=-200, max_value=-50), + Parameter('ap_ttl', min_value=30, max_value=600), + Parameter('sta_ttl', min_value=60, max_value=300), - Parameter('min_rssi', min_value=-200, max_value=-50), - Parameter('ap_ttl', min_value=30, max_value=600), - Parameter('sta_ttl', min_value=60, max_value=300), - - Parameter('recon_time', min_value=5, max_value=60), - Parameter('max_inactive_scale', min_value=3, max_value=10), - Parameter('recon_inactive_multiplier', min_value=1, max_value=3), - Parameter('hop_recon_time', min_value=5, max_value=60), - Parameter('min_recon_time', min_value=1, max_value=30), - Parameter('max_interactions', min_value=1, max_value=25), - Parameter('max_misses_for_recon', min_value=3, max_value=10), - Parameter('excited_num_epochs', min_value=5, max_value=30), - Parameter('bored_num_epochs', min_value=5, max_value=30), - Parameter('sad_num_epochs', min_value=5, max_value=30), - ] + [ - Parameter('_channel_%d' % ch, min_value=0, max_value=1, meta=ch + 1) for ch in - range(featurizer.histogram_size) - ] + Parameter('recon_time', min_value=5, max_value=60), + Parameter('max_inactive_scale', min_value=3, max_value=10), + Parameter('recon_inactive_multiplier', min_value=1, max_value=3), + Parameter('hop_recon_time', min_value=5, max_value=60), + Parameter('min_recon_time', min_value=1, max_value=30), + Parameter('max_interactions', min_value=1, max_value=25), + Parameter('max_misses_for_recon', min_value=3, max_value=10), + Parameter('excited_num_epochs', min_value=5, max_value=30), + Parameter('bored_num_epochs', min_value=5, max_value=30), + Parameter('sad_num_epochs', min_value=5, max_value=30), + ] def __init__(self, agent, epoch): super(Environment, self).__init__() @@ -41,6 +34,12 @@ class Environment(gym.Env): self._epoch_num = 0 self._last_render = None + channels = agent.supported_channels() + Environment.params += [ + Parameter('_channel_%d' % ch, min_value=0, max_value=1, meta=ch + 1) for ch in + range(featurizer.histogram_size) if ch + 1 in channels + ] + self.last = { 'reward': 0.0, 'observation': None, diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/mesh/wifi.py b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/mesh/wifi.py index e94ffbc..6a9a00a 100644 --- a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/mesh/wifi.py +++ b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/mesh/wifi.py @@ -1,7 +1,7 @@ SignatureAddress = 'de:ad:be:ef:de:ad' BroadcastAddress = 'ff:ff:ff:ff:ff:ff' Dot11ElemID_Identity = 222 -NumChannels = 14 +NumChannels = 140 def freq_to_channel(freq): if freq <= 2472: