def is_vulnerable(ctx): """ Attempt to check if target is vulnerable to i2c-based unlock bypass, based upon the Sonos-provided (i.e. not the U-Boot) version number. """ ver_regex = re.compile( r'U-Boot \d{4}\.\d{2}-Royale(-Strict)?-Rev(?P<rev>\d{1,}\.\d{1,})\s') for info in ctx.version(): log.debug('Checking version string: ' + info) m = ver_regex.match(info) if m is not None: ver = float(m.group('rev')) if ver == 0.2: log.info('Vulnerable version detected: ' + info) return True if ver <= 0.3: msg = 'Version may be vulnerable, but our memory patches are specific to v0.2' log.error(msg) else: log.error('Patched or unknown version detected: ' + info) return False log.error('Did not detect "U-Boot Royale" version string.') return False
#!/usr/bin/env python3 import traceback from depthcharge import Console, Depthcharge, log ctx = None try: console = Console('/dev/ttyUSB0', baudrate=115200) ctx = Depthcharge.load('my_device.cfg', console) # Comment out the above ctx creation and uncomment the following one in # order to possibly make more operations available to Depthcharge by allowing # it to deploy executable payloads to RAM and reboot/crash the platform. #ctx = Depthcharge(console, allow_deploy=True, allow_reboot=True) # Perform actions here except Exception as error: log.error(str(error)) # Shown if DEPTHCHARGE_LOG_LEVEL=debug in environment log.debug(traceback.format_exc()) finally: # Save any updates or new information to the device config if ctx: ctx.save('my_device.cfg')