from __future__ import absolute_import, print_function import json import sys import os import netlib.utils from . import flow, filt, utils from .protocol import http class DumpError(Exception): pass class Options(object): attributes = [ "app", "app_host", "app_port", "anticache", "anticomp", "client_replay", "filtstr", "flow_detail", "keepserving", "kill", "no_server", "nopop", "refresh_server_playback", "replacements", "rfile", "rheaders", "setheaders", "server_replay", "scripts", "showhost", "stickycookie", "stickyauth", "stream_large_bodies", "verbosity", "outfile", "replay_ignore_content", "replay_ignore_params", "replay_ignore_payload_params", "replay_ignore_host" ] def __init__(self, **kwargs): for k, v in kwargs.items(): setattr(self, k, v) for i in self.attributes: if not hasattr(self, i): setattr(self, i, None) def str_response(resp): r = "%s %s" % (resp.code, resp.msg) if resp.is_replay: r = "[replay] " + r return r def str_request(f, showhost): if f.client_conn: c = f.client_conn.address.host else: c = "[replay]" r = "%s %s %s" % (c, f.request.method, f.request.pretty_url(showhost)) if f.request.stickycookie: r = "[stickycookie] " + r return r class DumpMaster(flow.FlowMaster): def __init__(self, server, options, outfile=sys.stdout): flow.FlowMaster.__init__(self, server, flow.State()) self.outfile = outfile self.o = options self.anticache = options.anticache self.anticomp = options.anticomp self.showhost = options.showhost self.replay_ignore_params = options.replay_ignore_params self.replay_ignore_content = options.replay_ignore_content self.replay_ignore_host = options.replay_ignore_host self.refresh_server_playback = options.refresh_server_playback self.replay_ignore_payload_params = options.replay_ignore_payload_params self.set_stream_large_bodies(options.stream_large_bodies) if options.filtstr: self.filt = filt.parse(options.filtstr) else: self.filt = None if options.stickycookie: self.set_stickycookie(options.stickycookie) if options.stickyauth: self.set_stickyauth(options.stickyauth) if options.outfile: path = os.path.expanduser(options.outfile[0]) try: f = file(path, options.outfile[1]) self.start_stream(f, self.filt) except IOError as v: raise DumpError(v.strerror) if options.replacements: for i in options.replacements: self.replacehooks.add(*i) if options.setheaders: for i in options.setheaders: self.setheaders.add(*i) if options.server_replay: self.start_server_playback( self._readflow(options.server_replay), options.kill, options.rheaders, not options.keepserving, options.nopop, options.replay_ignore_params, options.replay_ignore_content, options.replay_ignore_payload_params, options.replay_ignore_host ) if options.client_replay: self.start_client_playback( self._readflow(options.client_replay), not options.keepserving ) scripts = options.scripts or [] for command in scripts: err = self.load_script(command) if err: raise DumpError(err) if options.rfile: try: self.load_flows_file(options.rfile) except flow.FlowReadError as v: self.add_event("Flow file corrupted.", "error") raise DumpError(v) if self.o.app: self.start_app(self.o.app_host, self.o.app_port) def _readflow(self, paths): """ Utitility function that reads a list of flows or raises a DumpError if that fails. """ try: return flow.read_flows_from_paths(paths) except flow.FlowReadError as e: raise DumpError(e.strerror) def add_event(self, e, level="info"): needed = dict(error=0, info=1, debug=2).get(level, 1) if self.o.verbosity >= needed: print(e, file=self.outfile) self.outfile.flush() @staticmethod def indent(n, t): l = str(t).strip().splitlines() pad = " " * n return "\n".join(pad + i for i in l) def _print_message(self, message): if self.o.flow_detail >= 2: print(self.indent(4, message.headers.format()), file=self.outfile) if self.o.flow_detail >= 3: if message.content == http.CONTENT_MISSING: print(self.indent(4, "(content missing)"), file=self.outfile) elif message.content: print("", file=self.outfile) content = message.get_decoded_content() if not utils.isBin(content): try: jsn = json.loads(content) print( self.indent( 4, json.dumps( jsn, indent=2)), file=self.outfil
package com.trilead.ssh2;
/**
* An <code>InteractiveCallback</code> is used to respond to challenges sent
* by the server if authentication mode "keyboard-interactive" is selected.
*
* @see Connection#authenticateWithKeyboardInteractive(String,
* String[], InteractiveCallback)
*
* @author Christian Plattner, plattner@trilead.com
* @version $Id: InteractiveCallback.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
*/
public interface InteractiveCallback
{
/**
* This callback interface is used during a "keyboard-interactive"
* authentication. Every time the server sends a set of challenges (however,
* most often just one challenge at a time), this callback function will be
* called to give your application a chance to talk to the user and to
* determine the response(s).
* <p>
* Some copy-paste information from the standard: a command line interface
* (CLI) client SHOULD print the name and instruction (if non-empty), adding
* newlines. Then for each prompt in turn, the client SHOULD display the
* prompt and read the user input. The name and instruction fields MAY be
* empty strings, the client MUST be prepared to handle this correctly. The
* prompt field(s) MUST NOT be empty strings.
* <p>
* Please refer to draft-ietf-secsh-auth-kbdinteract-XX.txt for the details.
* <p>
* Note: clients SHOULD use control character filtering as discussed in
* RFC4251 to avoid attacks by including
* terminal control characters in the fields to be displayed.
*
* @param name
* the name String sent by the server.
* @param instruction
* the instruction String sent by the server.
* @param numPrompts
* number of prompts - may be zero (in this case, you should just
* return a String array of length zero).
* @param prompt
* an array (length <code>numPrompts</code>) of Strings
* @param echo
* an array (length <code>numPrompts</code>) of booleans. For
* each prompt, the corresponding echo field indicates whether or
* not the user input should be echoed as characters are typed.
* @return an array of reponses - the array size must match the parameter
* <code>numPrompts</code>.
*/
public String[] replyToChallenge(String name, String instruction, int numPrompts, String[] prompt, boolean[] echo)
throws Exception;
}