add extra check for fix_services

Signed-off-by: jayofelony <oudshoorn.jeroen@gmail.com>
This commit is contained in:
jayofelony
2024-03-26 12:15:00 +01:00
parent ac345c2ee7
commit ab541458fa

View File

@ -35,6 +35,7 @@ class FixServices(plugins.Plugin):
self.pattern4 = re.compile(r'error 400: could not find interface wlan0mon') self.pattern4 = re.compile(r'error 400: could not find interface wlan0mon')
self.pattern5 = re.compile(r'fatal error: concurrent map iteration and map write') self.pattern5 = re.compile(r'fatal error: concurrent map iteration and map write')
self.pattern6 = re.compile(r'panic: runtime error') self.pattern6 = re.compile(r'panic: runtime error')
self.pattern7 = re.compile(r'ieee80211 phy0: _brcmf_set_multicast_list: Setting allmulti failed, -110')
self.isReloadingMon = False self.isReloadingMon = False
self.connection = None self.connection = None
self.LASTTRY = 0 self.LASTTRY = 0
@ -111,7 +112,7 @@ class FixServices(plugins.Plugin):
logging.debug("[Fix_Services]**** epoch") logging.debug("[Fix_Services]**** epoch")
if time.time() - self.LASTTRY > 180: if time.time() - self.LASTTRY > 180:
# get last 10 lines # get last 10 lines
display = None display = agent.view()
logging.debug("[Fix_Services]**** checking") logging.debug("[Fix_Services]**** checking")
@ -119,7 +120,6 @@ class FixServices(plugins.Plugin):
if len(self.pattern.findall(last_lines)) >= 3: if len(self.pattern.findall(last_lines)) >= 3:
logging.debug("[Fix_Services]**** Should trigger a reload of the wlan0mon device:\n%s" % last_lines) logging.debug("[Fix_Services]**** Should trigger a reload of the wlan0mon device:\n%s" % last_lines)
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view()
display.set('status', 'Blind-Bug detected. Restarting.') display.set('status', 'Blind-Bug detected. Restarting.')
display.update(force=True) display.update(force=True)
logging.debug('[Fix_Services] Blind-Bug detected. Restarting.') logging.debug('[Fix_Services] Blind-Bug detected. Restarting.')
@ -132,7 +132,6 @@ class FixServices(plugins.Plugin):
elif len(self.pattern2.findall(other_last_lines)) >= 5: elif len(self.pattern2.findall(other_last_lines)) >= 5:
logging.debug("[Fix_Services]**** Should trigger a reload of the wlan0mon device:\n%s" % last_lines) logging.debug("[Fix_Services]**** Should trigger a reload of the wlan0mon device:\n%s" % last_lines)
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view()
display.set('status', 'Wifi channel stuck. Restarting recon.') display.set('status', 'Wifi channel stuck. Restarting recon.')
display.update(force=True) display.update(force=True)
logging.debug('[Fix_Services] Wifi channel stuck. Restarting recon.') logging.debug('[Fix_Services] Wifi channel stuck. Restarting recon.')
@ -156,7 +155,6 @@ class FixServices(plugins.Plugin):
elif len(self.pattern3.findall(other_last_lines)) >= 1: elif len(self.pattern3.findall(other_last_lines)) >= 1:
logging.debug("[Fix_Services] Firmware has halted or crashed. Restarting wlan0mon.") logging.debug("[Fix_Services] Firmware has halted or crashed. Restarting wlan0mon.")
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view()
display.set('status', 'Firmware has halted or crashed. Restarting wlan0mon.') display.set('status', 'Firmware has halted or crashed. Restarting wlan0mon.')
display.update(force=True) display.update(force=True)
try: try:
@ -170,7 +168,6 @@ class FixServices(plugins.Plugin):
elif len(self.pattern4.findall(other_other_last_lines)) >= 3: elif len(self.pattern4.findall(other_other_last_lines)) >= 3:
logging.debug("[Fix_Services] wlan0 is down!") logging.debug("[Fix_Services] wlan0 is down!")
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view()
display.set('status', 'Restarting wlan0 now!') display.set('status', 'Restarting wlan0 now!')
display.update(force=True) display.update(force=True)
try: try:
@ -184,7 +181,6 @@ class FixServices(plugins.Plugin):
elif len(self.pattern5.findall(other_other_last_lines)) >= 1: elif len(self.pattern5.findall(other_other_last_lines)) >= 1:
logging.debug("[Fix_Services] Bettercap has crashed!") logging.debug("[Fix_Services] Bettercap has crashed!")
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view()
display.set('status', 'Restarting pwnagotchi!') display.set('status', 'Restarting pwnagotchi!')
display.update(force=True) display.update(force=True)
os.system("systemctl restart bettercap") os.system("systemctl restart bettercap")
@ -194,11 +190,28 @@ class FixServices(plugins.Plugin):
elif len(self.pattern6.findall(other_other_last_lines)) >= 1: elif len(self.pattern6.findall(other_other_last_lines)) >= 1:
logging.debug("[Fix_Services] Bettercap has crashed!") logging.debug("[Fix_Services] Bettercap has crashed!")
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view()
display.set('status', 'Restarting pwnagotchi!') display.set('status', 'Restarting pwnagotchi!')
display.update(force=True) display.update(force=True)
os.system("systemctl restart bettercap") os.system("systemctl restart bettercap")
pwnagotchi.restart("AUTO") pwnagotchi.restart("AUTO")
# Look for pattern 7
elif len(self.pattern7.findall(other_other_last_lines)) >= 1:
logging.debug("[Fix_Services] Monitor mode failed!")
try:
result = agent.run("wifi.recon off; wifi.recon on")
if result["success"]:
logging.debug("[Fix_Services] wifi.recon flip: success!")
if display:
display.update(force=True, new_data={"status": "Wifi recon flipped!",
"face": faces.COOL})
else:
print("Wifi recon flipped\nthat was easy!")
else:
logging.warning("[Fix_Services] wifi.recon flip: FAILED: %s" % repr(result))
except Exception as err:
logging.error("[Fix_Services wifi.recon flip] %s" % repr(err))
else: else:
print("logs look good") print("logs look good")