def run(self): if self.want_check_recommended: self.check_recommended() elif not self.prefs: out('No preferences found.') else: for pref in self.prefs: out(pref)
def dump_startup_json(self): data = self.load_json_mozlz4(STARTUP_FILE) num = sum(len(x.get('addons', {})) for x in data.values()) out('%d entries in "%s":\n' % (num, STARTUP_FILE)) for _, loc_data in data.items(): for addon in loc_data.get('addons', {}).values(): path = Path(loc_data['path']) / addon['path'] out('%s%s' % (path, ' (enabled)' if addon['enabled'] else ''))
def test_error(self, stdouterr): output.out('foo') out, err = stdouterr() assert out == 'foo\n' assert err == '' output.error('foo') out, err = stdouterr() assert out == '' assert 'foo' in err
def check(self, addon): checks = ( addon is not None, addon_id in self.startup_json.get(startup_key, {}).get('addons', {}), Path(self.ext_dir / ADDON_FILE).is_file(), ) if all(checks): out(good('Extension seems installed.')) else: out(bad('Extension doesn\'t seem (fully) installed.'))
def check_recommended(self): self.summarize() prefs_rec = list(self.parse_userjs(self.recommended_source)) out('%d recommendeded values read.\n' % len(prefs_rec)) bad_num = 0 for pref_rec in prefs_rec: try: pref = next(p for p in self.prefs if p.key == pref_rec.key) except StopIteration: if self.include_undefined: # Create a fake preference with an undefined value pref = Preference(pref_rec.key, None) else: continue if pref_rec.value == pref.value: if self.bad_only: continue markup = good else: markup = bad bad_num += 1 rec_text = markup(Preference.type_to_repr(pref_rec.value)) outitem(pref, [('Should', rec_text), ('Reason', pref_rec.info)]) if bad_num == 0: out(good('All preferences seem good.')) else: out('%d bad values found.' % bad_num)
def format_list(self): host_map = defaultdict(list) for cookie in self.cookies: host_map[cookie.host].append(cookie) for host, cookies in host_map.items(): out(host) for cookie in cookies: out(' %s = %s' % (cookie.name, cookie.value)) out()
def run(self): nss = self.nss if self.password is None: try: nss.check_password('') except NSSError as e: if e.name != 'SEC_ERROR_BAD_PASSWORD': fatal(e) # pragma: no cover self.password = getpass.getpass(prompt='Master password: '******'' try: nss.check_password(self.password) except NSSError as e: fatal(e) self.logins = [ Login( host=login['hostname'], username=nss.decrypt(login['encryptedUsername']), password=nss.decrypt(login['encryptedPassword']), ) for login in self.logins ] self.build_format()
def walk(node, depth=0): if node.type == DIRECTORY_TYPE: text = good('[%s]') % node.title out('%s%s' % (depth * 4 * ' ', text)) else: out('%s* %s' % (depth * 4 * ' ', node.title)) out('%s%s' % ((depth + 1) * 4 * ' ', node.url)) children = [n for n in bmarks if n.parent == node.id] for child in children: walk(child, depth + 1)
def show_profiles(): profiles = list(read_profiles()) if not profiles: out('No local profiles found. Set a profile path with -p/--profile.') return out('%d profiles found:' % len(profiles)) for profile in profiles: out('\n%s%s\n%s' % ( profile.name, good(' [default]') if profile.default else '', profile.path, ))
def install(self, addon): if not self.yes: out('Are you sure you want to infect profile "%s"? (y/N)' % self.session.profile) if input().lower() not in ['y', 'yes']: fatal('Cancelled.') out('Installing to "%s"...' % self.session.profile) if addon is not None: warn('Addon entry "%s" already exists.' % addon_id) else: addons = self.extensions_json['addons'] addons.append(self.make_addon_entry()) self.write_extensions_json() startup = self.startup_json if startup_key not in startup: startup[startup_key] = {} if 'addons' not in startup[startup_key]: startup[startup_key]['addons'] = {} if addon_id in startup[startup_key]['addons']: warn('Addon already registered in "%s".' % ADDON_STARTUP_FILE) else: startup[startup_key]['addons'][addon_id] = startup_entry startup[startup_key]['path'] = str(self.ext_dir) self.write_addon_startup_json() try: os.mkdir(self.ext_dir) except FileExistsError: pass xpi_source = ROOT_PATH / 'data/infect/' xpi_target = self.ext_dir / ADDON_FILE xpi_path_rel = (Path(self.ext_dir.name) / ADDON_FILE) if Path(xpi_target).exists(): warn('XPI already exists at "%s".' % xpi_path_rel) else: out('Writing XPI file to "%s".' % xpi_path_rel) with ZipFile(xpi_target, 'w') as f: for filename in os.listdir(xpi_source): path = xpi_source / filename print('Adding "%s".' % filename) f.write(path, filename) out('Done.')
def uninstall(self, addon): out('Uninstalling from "%s"...' % self.session.profile) addons = self.extensions_json['addons'] try: addons.remove(addon) except ValueError: warn('Can\'t remove addon from "%s". No entry found.' % EXT_DB) else: self.write_extensions_json() try: del self.startup_json[startup_key]['addons'][addon_id] except KeyError: warn('Can\'t remove addon entry from "%s". No entry found.' % ADDON_STARTUP_FILE) else: self.write_addon_startup_json() xpi_path = self.ext_dir / ADDON_FILE xpi_path_rel = (Path(self.ext_dir.name) / ADDON_FILE) if Path(xpi_path).exists(): out('Removing "%s".' % xpi_path_rel) os.remove(xpi_path) else: warn('Can\'t remove XPI from "%s". File not found.' % xpi_path_rel) out('Done.')
def summarize(self): out('%d logins found.' % len(self.logins))
def summarize(self): out('%d custom preferences found.' % len(self.prefs))
def dump_addons_json(self): data = self.load_json(ADDONS_FILE).get('addons', []) out('%d entries in "%s":\n' % (len(data), ADDONS_FILE)) for addon in data: out('%s (%s)' % (addon.get('name'), addon.get('id')))
def short(self): for addon in self.addons: out(addon.id, repr(addon.name))
def summarize(self): out('%d cookies found.' % len(list(self.cookies)))
def write_extensions_json(self): out('Updating "%s".' % EXT_DB) with open(self.profile_path(EXT_DB), 'w', encoding='utf-8') as f: json.dump(self.extensions_json, f)
def summarize(self): out('%d form entries found.' % len(list(self.entries)))
def run(self): for host in self.data: out('%s' % host.host)
def format_short(self): for entry in self.entries: out(entry.url)
def summarize(self): out('%d history entries found.' % len(self.entries))
def summarize(self): out('%d visits found.' % len(self.visits))
def format_setcookie(self): for cookie in self.cookies: out(cookie)
def run(self): for entry in self.data: out('%s' % entry.input)
def summarize(self): out('%d input history entries found.' % len(list(self.data)))
def run(self): for entry in self.entries: out('%s=%s' % (entry.fieldname, entry.value))
def summarize(self): out('%d permissions found.' % len(list(self.perms)))
def summarize(self): out('%d addons found. (%d enabled)' % (len(self.addons), sum(a.enabled for a in self.addons)))
def write_addon_startup_json(self): out('Updating "%s".' % ADDON_STARTUP_FILE) self.write_json_mozlz4(ADDON_STARTUP_FILE, self.startup_json)
def list(self): for visit in self.visits: out(datetime.fromtimestamp(visit.visit_date), visit.url)