Commit Graph

4061 Commits

Author SHA1 Message Date
CoderFX
3962c75730 fix(fix_services): merge duplicate pattern handlers 5 and 6
Patterns 5 (concurrent map iteration) and 6 (panic: runtime error) had
identical handlers — both log "Bettercap has crashed!", restart bettercap,
and restart pwnagotchi. Merge into a single elif with an or condition.

Closes #539

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 17:12:37 +02:00
Jayofelony
3d9280a61a Merge pull request #533 from CoderFX/fix/fix-services-print-to-logging
fix(fix_services): replace print() calls with logging
2026-03-11 07:29:37 +01:00
Jayofelony
012efdbaf4 Merge pull request #535 from CoderFX/fix/fix-services-lasttry-update
fix(fix_services): update LASTTRY cooldown after pattern matches
2026-03-11 07:21:06 +01:00
Jayofelony
635f00f4e7 Merge pull request #531 from CoderFX/fix/fix-services-unused-imports
fix(fix_services): remove unused imports Text, BLACK, fonts
2026-03-11 07:20:46 +01:00
Jayofelony
50719285a7 Merge pull request #529 from CoderFX/fix/fix-services-os-system
fix(fix_services): replace os.system with subprocess.run
2026-03-11 07:20:30 +01:00
Jayofelony
bade01f515 Merge pull request #527 from CoderFX/fix/fix-services-success-check
fix(fix_services): fix bettercap result success checks
2026-03-11 07:20:15 +01:00
Jayofelony
cb5366a211 Merge pull request #523 from CoderFX/fix/fix-services-display-null-ref
fix(fix_services): fix display null reference in on_epoch
2026-03-11 07:19:59 +01:00
Jayofelony
c672430e2c Merge pull request #521 from CoderFX/fix/fix-services-dead-code-ui-setup
fix(fix_services): remove dead code in on_ui_setup
2026-03-11 07:19:45 +01:00
Jayofelony
1fe97e8680 Merge pull request #519 from CoderFX/fix/fix-services-dead-code-on-ready
fix(fix_services): remove unused Popen in on_ready
2026-03-11 07:19:30 +01:00
Jayofelony
3d7894cb4c Merge pull request #517 from CoderFX/fix/fix-services-typo
fix(fix_services): fix "interfaceface" typo in log message
2026-03-11 07:19:15 +01:00
Jayofelony
f10c01f2ab Merge pull request #513 from CoderFX/feature/pisugarx-implement-stubs
feat(pisugarx): implement all 17 stub methods for PiSugar3
2026-03-11 07:19:01 +01:00
Jayofelony
1b676ef707 Merge pull request #512 from CoderFX/fix/pisugarx-i2c-robustness
fix(pisugarx): improve I2C thread safety, error recovery, and write protection
2026-03-11 07:18:42 +01:00
Jayofelony
92c5526cca Merge pull request #510 from CoderFX/fix/pisugarx-double-voltage
fix(pisugarx): prevent double voltage append with charge protection
2026-03-11 07:18:25 +01:00
Jayofelony
5367acecad Merge pull request #508 from CoderFX/fix/pisugarx-null-safety
fix(pisugarx): guard against None self.ps in on_loaded and on_ui_update
2026-03-11 07:17:38 +01:00
Jayofelony
10216f854b Merge pull request #506 from CoderFX/fix/pisugarx-model-name-mismatch
fix(pisugarx): correct model name mismatch in web UI
2026-03-11 07:16:18 +01:00
CoderFX
c2e61a1517 fix(fix_services): update LASTTRY in all on_epoch pattern handlers
Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 03:15:28 +02:00
CoderFX
310a7d3930 fix(fix_services): replace print() calls with proper logging
Plugin code uses print() in several places instead of the logging
module. On a headless Pi Zero, print() output goes nowhere useful
while logging integrates with pwnagotchi's log system.

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 03:15:26 +02:00
CoderFX
d85fd18932 fix(fix_services): replace os.system with subprocess.run
Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 03:12:59 +02:00
CoderFX
36647cb367 fix(fix_services): remove unused imports Text, BLACK, fonts
Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 03:10:56 +02:00
CoderFX
74e4743042 fix(fix_services): fix bettercap result success checks
'"success" in result' checks if the key exists in the dict (always
True for valid responses), not whether the operation succeeded.
result["success"] can KeyError if the key is missing.

Change all checks to result.get("success") which correctly returns
the boolean value or None if the key is absent.

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 03:00:35 +02:00
CoderFX
0fd715b554 fix(fix_services): fix display null reference crash in on_epoch
on_epoch calls agent.view() directly without checking hasattr first,
unlike every other method in the plugin. This crashes if the agent
has no view attribute (e.g., during early startup or in headless mode).

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 02:54:39 +02:00
CoderFX
bbf1d95bfc fix(fix_services): remove dead code in on_ui_setup
on_ui_setup computes a pos variable from options or defaults but
never uses it. The ui._lock context and logging.debug("Got here")
are leftover scaffolding with no effect.

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 02:44:49 +02:00
CoderFX
283be16549 fix(fix_services): remove unused Popen in on_ready (resource leak)
on_ready opens a subprocess.Popen to read journalctl but never uses
the result. The Popen object is never closed, leaking a file descriptor
and zombie process on every startup.

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 02:43:06 +02:00
CoderFX
7fc4bef0ab fix(fix_services): fix interfaceface typo in log message
Typo "wifi.interfaceface" should be "wifi.interface" in the debug
log for the bettercap set wifi.interface command result.

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 02:42:04 +02:00
CoderFX
73f8524af4 feat(pisugarx): implement all stub methods for PiSugar3
All 17 stub methods now return real data by reading PiSugar3 I2C
registers directly or from pisugar-power-manager config.

Register reads (from cached i2creg, address 0x57):
- get_battery_current: registers 0x26-0x27
- get_anti_mistouch: CTR1 (0x02) bit 3
- get_battery_auto_power_on: CTR1 (0x02) bit 4
- get_battery_soft_poweroff: CTR2 (0x03) bit 4
- get_battery_charging: derived from power_plugged + allow_charging
- get_system_time: RTC registers 0x31-0x37 (BCD decoded)
- get_rtc_adjust_ppm: registers 0x3A-0x3B (frequency compensation)
- get_rtc_alarm_repeat: registers 0x40, 0x44-0x47

I2C writes:
- set_battery_allow_charging (PiSugar3): CTR1 bit 6 set
- set_battery_notallow_charging (PiSugar3): CTR1 bit 6 clear
- rtc_web: write system time as BCD to RTC registers 0x31-0x37

Config-derived:
- get_battery_safe_shutdown_level: from plugin config
- get_battery_safe_shutdown_delay: 10s (PiSugar3 hardware)
- get_battery_charging_range: from max_charge_voltage_protection
- get_battery_full_charge_duration: N/A (no hardware support)

Pisugar-power-manager config reads:
- get_tap_enable: reads {tap}_tap_enable from config.json
- get_tap_shell: reads {tap}_tap_shell from config.json

Also fixes model name mismatch in web UI ('Pisugar 3' -> 'PiSugar3')
so PiSugar3-specific fields display correctly.

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 01:37:00 +02:00
CoderFX
380d05cca9 fix(pisugarx): improve I2C thread safety, error recovery, and write protection
Four robustness improvements to PiSugarServer I2C communication:

1. Race condition: build i2creg into temp list, swap atomically with
   threading lock so UI thread never reads partial register data.

2. Bus recovery: add error counter with exponential backoff (3s-30s),
   log suppression after 3 errors, and SMBus reconnect after 5
   consecutive failures to recover from MCU deep sleep.

3. Write protection: restructure as try/finally so register 0x0B is
   always re-enabled even if the middle write fails.

4. Shutdown safety: wrap I2C writes in try/except/finally so failures
   are logged but never prevent pwnagotchi.shutdown() from executing.

Fixes #511

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 01:07:27 +02:00
CoderFX
1fbfe4bc86 fix(pisugarx): prevent double voltage append with charge protection
For PiSugar2/2Plus with max_charge_voltage_protection enabled,
battery_voltage was appended to voltage_history twice per cycle:
once inside the charge protection block and once unconditionally
at the end. This skews the trimmed-mean battery level calculation.

Make the final append conditional so each model appends exactly
once per cycle regardless of charge protection setting.

Fixes #509

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 01:04:19 +02:00
CoderFX
2246a91590 fix(pisugarx): guard against None self.ps in on_loaded and on_ui_update
on_loaded crashes with AttributeError when PiSugar is not connected
because it accesses self.ps without a None check. Also uses direct
dict access on self.options which crashes if keys are missing.

on_ui_update crashes when checking battery_plugged outside the
self.ready guard, hitting self.ps.get_battery_power_plugged on None.

Changes:
- Wrap self.ps access in on_loaded with None guard
- Use self.options.get() with safe defaults
- Move battery_plugged inside self.ready + self.ps check
- Downgrade "PiSugar is not ready" from info to debug

Fixes #507

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 01:02:07 +02:00
CoderFX
55f294ec77 fix(pisugarx): correct model name mismatch in web UI
The web UI checks for 'Pisugar 3' (with space, lowercase 's') but
the model detection sets self.model = 'PiSugar3' (no space, uppercase 'S').
This causes 5 PiSugar3-specific fields to never display their actual values.

Replace all occurrences to match the value set during initialization.

Fixes #505

Signed-off-by: PwnPacker <4704376+CoderFX@users.noreply.github.com>
2026-03-11 00:57:54 +02:00
Jayofelony
8b1297d836 Merge pull request #497 from CoderFX/fix/handshake-capture-optimizations
Optimize handshake capture: fix bugs and improve attack efficiency
2026-03-10 22:43:05 +01:00
Jayofelony
241513c2f8 Merge pull request #504 from CoderFX/feature/pisugar3-scripts
Add PiSugar 3 shutdown/startup scripts and watchdog
2026-03-10 22:42:12 +01:00
Jayofelony
0df8d4b2ec Merge pull request #501 from CoderFX/fix/fix-services-syslog-spam
Fix Fix_Services syslog handler spamming errors when bettercap is unstable
2026-03-10 22:41:34 +01:00
Jayofelony
1793a76d12 Merge pull request #498 from CoderFX/fix/whitelist-handshake-filter
Fix whitelist not filtering passively captured handshakes
2026-03-10 22:40:35 +01:00
CoderFX
dff77e105d Add PiSugar 3 shutdown/startup scripts and watchdog
PiSugar 3 users need graceful shutdown with e-ink feedback, boot-loop
prevention when charging from dead battery, and automatic recovery
when pisugar-server loses I2C connection after MCU wake.

- safe-shutdown.sh: stops pwnagotchi, draws sleeping face on e-ink,
  powers off. Boot-loop guard skips shutdown when battery <10% and
  charging.
- pisugar-watchdog.sh + systemd timer: detects MCU wake from deep
  sleep and restarts pisugar-server when I2C is present but daemon
  reports disconnected.
- epd-shutdown.py / epd-startup.py: e-ink display faces for
  Waveshare V4. Exit silently on non-V4 displays.

Signed-off-by: CoderFX <4704376+CoderFX@users.noreply.github.com>
2026-03-10 23:33:51 +02:00
CoderFX
3162fdf2aa Fix Fix_Services syslog handler spamming errors when bettercap is unstable
on_bcap_sys_log fires on every bettercap syslog event matching "wifi
error while hopping to channel". When bettercap is in a bad state, it
sends many such events per second. Each one triggers agent.run() to
flip wifi.recon, which also fails because bettercap is unstable. This
creates a cascade of TypeError errors filling the log — 61 errors in
a few minutes in observed logs.

Two fixes:

1. Safe Message access: use event.get() with isinstance check instead
   of direct dict access into re.search(). Prevents TypeError when
   Message is None or non-string, and KeyError if event structure is
   unexpected.

2. Add 30-second cooldown: check self.LASTTRY before attempting a
   recon flip, matching the debounce pattern already used in on_epoch
   and _tryTurningItOffAndOnAgain. Update LASTTRY on all outcomes
   (success, failure, exception) to prevent cascading retries.

Signed-off-by: CoderFX <4704376+CoderFX@users.noreply.github.com>
2026-03-10 23:12:42 +02:00
CoderFX
f2c73f5bbe Fix whitelist not filtering passively captured handshakes
The whitelist in config.toml is checked in get_access_points() to
filter APs from active attacks, but bettercap still passively captures
handshakes from all networks including whitelisted ones. The
_on_event() handler processes wifi.client.handshake events without
any whitelist check, so handshakes from the user's own networks are
saved and reported as new captures.

Add whitelist filtering to _on_event() with two checks:
- By MAC address immediately after extracting ap_mac (catches
  MAC-based whitelist entries before any processing)
- By hostname after _find_ap_sta_in() resolves the AP (catches
  name-based whitelist entries)

When a whitelisted handshake is detected, the pcap file that
bettercap already wrote to disk is removed to prevent accumulation.

Signed-off-by: CoderFX <4704376+CoderFX@users.noreply.github.com>
2026-03-10 22:52:01 +02:00
CoderFX
3c8aa55a57 Fix auto-tune plugin: history compat, XSS, channel dedup, defaults
- Fix interaction display to handle new history dict format
  ({count, first_seen} from handshake capture optimization PR)
- Escape preset names in HTML output to prevent XSS
- Deduplicate channel list to avoid scanning same channel twice
- Replace deprecated logging.warn() with logging.warning()
- Reduce default extra_channels from 15 to 5 (15 scans nearly all
  2.4GHz channels every epoch, defeating focused scanning)

Signed-off-by: CoderFX <153912+CoderFX@users.noreply.github.com>
Signed-off-by: CoderFX <4704376+CoderFX@users.noreply.github.com>
2026-03-10 20:11:50 +02:00
CoderFX
8c1c51f158 Optimize handshake capture: fix bugs and improve attack efficiency
agent.py:
- Fix _has_handshake() substring match bug: was matching partial MACs
  (e.g. "AA:BB:CC" matching "AA:BB:CC:DD:EE:FF"), causing APs to be
  skipped. Now splits key on ' -> ' and checks exact MAC match.
- Add time-based decay to interaction history: previously once an AP/STA
  hit max_interactions it was permanently skipped for the session. Now
  resets count after 5 minutes, allowing retry of stubborn targets.
- Cap recon time increase when inactive: was doubling (30s->60s), now
  adds at most 15s to avoid long idle periods with fewer channel hops.
- Interleave populated and sparse channels instead of always hitting
  most-populated first, giving sparse channels fair coverage.
- Use set for whitelist lookup (O(1) instead of O(n) per AP).
- Remove fragile mac[:13] prefix whitelist match, use full MAC only.
- Add backward compat for recovery data format change.

cli.py:
- Reduce inter-deauth sleep from 1.0s to 0.3s. The 1s delay was overly
  conservative for nexmon firmware; 0.3s is sufficient and processes
  multi-client APs 3x faster.

Signed-off-by: CoderFX <153912+CoderFX@users.noreply.github.com>
Signed-off-by: CoderFX <4704376+CoderFX@users.noreply.github.com>
2026-03-10 19:57:26 +02:00
Jeroen Oudshoorn
6808063e9b Update file paths to use /etc/pwnagotchi for configuration and data storage 2026-02-27 17:21:47 +01:00
Jayofelony
ee44500c1d Merge pull request #487 from wsvdmeer/noai
Update Bluetooth Tether Plugin to Latest Version
2026-02-26 22:27:53 +01:00
wsvdmeer
00c3c84c17 update bt-tether plugin to newest version 2026-02-26 21:56:58 +01:00
Jayofelony
b1abe80340 Delete README-google.md 2026-02-24 18:37:23 +01:00
Jayofelony
e5a53975b4 Merge pull request #480 from wsvdmeer/bugfix/plugins-page
bugfix tooltip plugins
2026-02-22 15:22:06 +01:00
Jayofelony
7842b40f91 Merge pull request #479 from wsvdmeer/bugfix/bt-tether-helper
Bugfix BT-Tether
2026-02-22 15:21:52 +01:00
wsvdmeer
ecb831f806 bugfix tooltip plugins 2026-02-22 15:14:52 +01:00
wsvdmeer
91444ff1ba updated toml + bt-tether.py 2026-02-22 12:32:40 +01:00
Jeroen Oudshoorn
a0f29a5a71 Update bt-tether plugin settings
Remove gdrivesync settings, as plugin is removed
2026-02-21 20:36:04 +01:00
Jeroen Oudshoorn
62e115ce57 Remove unused regex import from cli.py 2026-02-21 20:12:04 +01:00
Jeroen Oudshoorn
71389426ba Remove connection scripts 2026-02-21 20:11:54 +01:00
Jeroen Oudshoorn
a2634ab5cd Remove unused google_cmd parser and wizard installation logic from cli.py 2026-02-21 20:11:32 +01:00