Pwnagotchi stopped reporting pwned networks, pwngrid error

After updating to 1.3.0 I’ve noticed that my pwnagotchi stopped reporting pwned networks in the same time the number of epochs is properly posted.
I don’t see anything strange using pwnagotchi --debug except:

[2019-11-22 08:08:12,364] [INFO] entering auto mode …
[2019-11-22 08:08:12,393] [INFO] [ai] bootstrapping dependencies …
[2019-11-22 08:08:12,940] [INFO] web ui available at http://0.0.0.0:8080/
Unhandled exception in thread started by <bound method Server._http_serve of <pwnagotchi.ui.web.server.Server object at 0xb4d48410>>
Traceback (most recent call last):
File “/usr/local/lib/python3.7/dist-packages/pwnagotchi/ui/web/server.py”, line 49, in _http_serve
app.run(host=self._address, port=self._port, debug=False)
File “/usr/local/lib/python3.7/dist-packages/flask/app.py”, line 943, in run
[2019-11-22 08:08:13,074] [INFO] connecting to http://localhost:8081/api
run_simple(host, port, self, **options)
File “/usr/local/lib/python3.7/dist-packages/werkzeug/serving.py”, line 1010, in run_simple
inner()
File “/usr/local/lib/python3.7/dist-packages/werkzeug/serving.py”, line 963, in inner
fd=fd,
File “/usr/local/lib/python3.7/dist-packages/werkzeug/serving.py”, line 806, in make_server
host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
File “/usr/local/lib/python3.7/dist-packages/werkzeug/serving.py”, line 699, in init
HTTPServer.init(self, server_address, handler)
File “/usr/lib/python3.7/socketserver.py”, line 452, in init
self.server_bind()
File “/usr/lib/python3.7/http/server.py”, line 137, in server_bind
socketserver.TCPServer.server_bind(self)
File “/usr/lib/python3.7/socketserver.py”, line 466, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use
[2019-11-22 08:08:15,044] [INFO] found monitor interface: mon0

Unfortunately with pwngrid -debug i’m geting:

2019-11-22 08:16:39 inf pwngrid v1.10.3 starting in server mode …
2019-11-22 08:16:39 !!! open .env: no such file or directory

Pwned networks counter shows 548 but the number reported to grid stopped at 497:
b4b7b9d2f84fd95bf3eebba6378f14c19a075d5b2356c62a210cd75b93557d13
I checked /root/handshakes directory and there are 548 files.

Can you post your config.yml redacting where needed? There’s a few changes from previous releases to the current. You might want to read through the default.yml and compare for hints.

1 Like

I’m facing the exact same problem. I flashed the v1.3.0 image yesterday and set it up (didn’t restore any backup; new unit). The number of pwned networks were initially being correctly reported but stopped soon after that, while the number of epochs are still being successfully reported.

main:
  custom_plugins: "/root/pwnagotchi-plugins-contrib"
  name: 'oriko'
  whitelist:
    - '****'
    - '****'
  plugins:
    screen_refresh:
      enabled: true
      refresh_interval: 20
    grid:
      enabled: true
      report: true
      exclude:
        - '****'
        - '****'
    bt-tether:
      enabled: true
      devices:
        poco-f1:                    # you can choose your phones name here
          enabled: true             # enables the device
          search_order: 1           # in which order the devices should be searched. E.g. this is #1.
          mac: '**:**:**:**:**:**'  # you need to put your phones bt-mac here (the same as above,
                                    ## or goto your phones   settings > status)
          ip: '192.168.44.44'       # this is the static ip of your pwnagotchi
                                    ## adjust this to your phones pan-network (run "ifconfig bt-pan" on your phone)
                                    ## if you feel lucky, try: 192.168.44.44 (Android) or 172.20.10.6 (iOS)
                                    ## 44 is just an example, you can choose between 2-254 (if netmask is 24)
          netmask: 24               # netmask of the PAN
          interval: 1               # in minutes, how often should the device be searched
          scantime: 15              # in seconds, how long should be searched on each interval
          share_internet: true      # this will change the routing and nameserver on your pi
          priority: 99              # if you have multiple devices which can share internet; the highest priority wins
          max_tries: 5              # how often should be tried to find the device until it is disabled (to save power)
                                    ## 0 means infinity

ui:
    web:
      username: ***
      password: ***
    display:
      enabled: true
      type: 'waveshare_2'
      color: 'black'

@LittleSlip Thank you for an answer, I checked config multiple times and I’m pretty sure that it’s fine.
Like @sayak-brm I even flashed fresh 1.3.0 image and restored the backup - it, unfortunately, didn’t help.
But after hours of debugging and digging through the code, I believe, I found the root cause.

So @sayak-brm first thing is to check is json file with already reported networks: /root/.api-report.json,
If there are duplicated entries it will prevent grid.py plugin from reporting pwned networks because it checks number of files in /root/handshakes and compare it with the number of reported networks:

pcap_files = glob.glob(os.path.join(agent.config()[‘bettercap’][‘handshakes’], “*.pcap”))
num_networks = len(pcap_files)
reported = self.report.data_field_or(‘reported’, default=[])
num_reported = len(reported)
num_new = num_networks - num_reported

if num_new > 0:

with duplitcates in /root/.api-report.json the variable num_new will be most likely < 0.
You can use following script to find and remove duplicates:

import json

with open(’.api-report.json’) as json_file:
data = json.load(json_file)

print( "Entries before: " + str(len(data[‘reported’])))
data = list(dict.fromkeys(data[‘reported’]))
print( "Entries with no duplicates: " + str(len(data)))

output = {}
output[‘reported’] = data

with open(‘fixed.json’, ‘w’) as outfile:
json.dump(output, outfile)

To prevent adding more duplicates to .api-report.json I’ve added if condition to set_reported method in /usr/local/lib/python3.7/dist-packages/pwnagotchi/plugins/default/grid.py:

def set_reported(self, reported, net_id):
if net_id not in reported:
reported.append(net_id)
self.report.update(data={‘reported’: reported})

If the number of reported networks and number of files in /root/handshakes is equal newly pwned networks should be reported properly.
The next thing I did was cleaning /root/.api-report.json and running sudo pwnagotchi --debug.
It started reporting all pwned networks, of course, api is not counting previously reported networks so there is no harm.
After a while, I saw that for some specific .pcap files it ends up in kind of infinite loop trying to parse/report them again and again (so without editing the grid.py it could create duplicated entries).
So for each of those, I was stopping pwnagotchi service, manually adding names of flawed pcaps to /root/.api-report.json and starting pwnagotchi service again.

To summarize:
I don’t know yet why some caps could not be parsed (debug mode didn’t throw any exceptions).
Maybe the grid.py plugin is runing in more than one thread and there is no locking mechanism?
It would be great if someone more experienced like @dadav, @chip could investigate it?

1 Like

Since this commit, all plugins event handlers run asynchronously, including but not limited to on_internet_available() in pwnagotchi/plugins/default/grid.py. If this event is triggered twice in quick succession, this would result in the duplicates.

I’ve also checked again, v1.3.0 is the first release that ships with this commit in it’s code, and hence multiple (yet vague) reports of this issue has been cropping up in different places.

1 Like

I have been experiencing an issue where .api-report.json will reset to zero entries while parsing pcaps. I have nearly ~700 pcaps that vary in size.

Is anybody else experiencing this issue?

Edit: this is version 1.4.1.
Edit 2: I’ve figured out that the json file becomes corrupted, almost repeatedly. I haven’t figured out a way forward with this without taking constant backups and restoring to a known good version.

@Scherbatsky i am currently in the process of attempting to make a backup of my unit and then i will attempt to reflash it because i am having the same issue but im having some troubles with the backup command itself

i have the same problem… grid setting is true on reporting.
I connect with iphone bt-tether. All works fine, just no report of pwned networks!
my first try was with version1.3, it automaticly updated to 1.4.1. Later i setuped, completle new (flashed sdcard) - directly to version 1.4.1 but still no reporting!?

could you guys please try the latest code? (update maually)

how should i update manually?

I’ve done “apt update”, and “apt upgrade”.
I’ve used bettercap Update, from “advanced” - “update” - “update.check on”

all is fine.

Dec 18 18:23:54 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:54,554] [INFO] Session-stats plugin loaded.
Dec 18 18:23:54 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:54,556] [INFO] [update] plugin loaded.
Dec 18 18:23:54 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:54,563] [INFO] grid plugin loaded.
Dec 18 18:23:54 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:54,572] [WARNING] ui.fps is 0, the display will only update for major changes
Dec 18 18:23:54 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:54,561] [INFO] [led] plugin loaded for /sys/class/leds/led0/brightness
Dec 18 18:23:54 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:54,610] [INFO] initializing waveshare v2 display
Dec 18 18:23:54 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:54,701] [INFO] BT-TETHER: Successfully loaded …
Dec 18 18:23:58 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:58,594] [INFO] [ai] loading /root/brain.json
Dec 18 18:23:58 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:58,663] [INFO] [email protected] (v1.4.1)
Dec 18 18:23:58 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:58,672] [INFO] entering manual mode …
Dec 18 18:23:58 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:23:58,815] [INFO] web ui available at http://0.0.0.0:8080/

Dec 18 18:24:00 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:24:00,525] [ERROR] error parsing line ‘]’: time data ‘{{node RMSProp/update_model/vf/w/Cast}}’ does not match format ‘%Y-%m-%d %H:%M:%S’
Dec 18 18:24:00 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:24:00,539] [ERROR] error parsing line ‘, td_map)’: time data ‘self’ does not match format ‘%Y-%m-%d %H:%M:%S’
Dec 18 18:24:00 xyz pwnagotchi-launcher[14507]: [2019-12-18 18:24:00,543] [ERROR] error parsing line ‘]’: time data ‘node RMSProp/update_model/vf/w/Cast (defined at /lib/python3/dist-packages/tensorflow_core/python/framework/ops’ does not match format ‘%Y-%m-%d %H:%M:%S’

Dec 18 19:24:26 xyz pwnagotchi-launcher[372]: [2019-12-18 19:24:26,144] [INFO] entering manual mode …
Dec 18 19:24:26 xyz pwnagotchi-launcher[372]: [2019-12-18 19:24:26,252] [INFO] web ui available at http://0.0.0.0:8080/
Dec 18 19:24:28 xyz pwnagotchi-launcher[372]: [2019-12-18 19:24:28,218] [ERROR] error parsing line ‘]’: time data ‘{{node RMSProp/update_model/vf/w/Cast}}’ does not match format ‘%Y-%m-%d %H:%M:%S’
Dec 18 19:24:28 xyz pwnagotchi-launcher[372]: [2019-12-18 19:24:28,225] [ERROR] error parsing line ‘, td_map)’: time data ‘self’ does not match format ‘%Y-%m-%d %H:%M:%S’
Dec 18 19:24:28 xyz pwnagotchi-launcher[372]: [2019-12-18 19:24:28,237] [ERROR] error parsing line ‘]’: time data ‘node RMSProp/update_model/vf/w/Cast (defined at /lib/python3/dist-packages/tensorflow_core/python/framework/ops’ does not match format ‘%Y-%m-%d %H:%M:%S’
Dec 18 19:24:28 xyz pwnagotchi-launcher[372]: [2019-12-18 19:24:28,356] [INFO] the last session lasted 47 minutes, 58 seconds (46 completed epochs, trained for 1), average reward:-0.0810170289289406 (min:-0.2 max:1.008695652173913)

im currently on the latest update and it seems to be working very for reporting to the grid now as long as all then network settings are correct on the host pc but i have noticed that when i do have it sharing an internet connection with my host pc the web ui seems to load slightly slower? it could just be me but im also thinking its because its now using resources to constantly report the new networks etc