def do_stream(self, args): """Usage: stream [-f=<fmt> | --format=<fmt>] [-p=<pkt> | --packet=<pkt>] Print session data (TCP/UDP). -f <fmt>, --format <fmt> output format, default is "hex": str, urldecode, hex, hexarray, json, base64 (decode) -p <pkt>, --packet <pkt> only print the packet data instead of session data. Default is -1 (all packets). """ if self.current_session: pkt = args['--packet'] if args['--packet'] else -1 fmt = args['--format'] if args['--format'] else 'hex' pkt = int(pkt) formatter = SessionFormatter(self.analyzer.sessions[self.current_session]) results = formatter.format(fmt, pkt) self.print_stream(results, pkt) if pkt >= 0 else map(lambda tpl : self.print_stream(tpl[1], tpl[0]), enumerate(results))
def do_extract(self, args): """Usage: extract [options] (-p=<pkt>|--packet=<pkt>) -p=<pkt>, --packet=<pkt> packet number (mandatory). -u, --unquote urldecode the data. """ if self.current_session: formatter = SessionFormatter(self.analyzer.sessions[self.current_session]) pkt = int(args['--packet']) if args['--unquote']: kv_data = formatter.unquote_pkt(pkt).split('&') else: kv_data = formatter.strings_pkt(pkt).split('&') for kv in kv_data: try: params = kv.split('=') self.print_default('Key : %s' % params[0]) json_data = format_json(params[1]) self.print_default('Value : ') print json_data except Exception: self.print_default('Value : %s' % params[1])