Ejemplo n.º 1
0
def main(args):
    # Parse options
    import optparse
    parser = optparse.OptionParser(
        usage="usage: %prog <connect-host> <connect-port> "
              "<username> <password>")
    (options, args) = parser.parse_args(args)

    if len(args) != 4:
        return parser.print_usage()

    host, port, username, password = args

    # Create profile
    profile = Profile()

    # Create factory
    factory = ChatLoggerFactory()
    factory.profile = profile

    # Log in and connect
    deferred = profile.login(username, password)
    deferred.addCallbacks(
        lambda data: factory.connect(host, int(port)),
        lambda err: print("login failed:", err.value))
    factory.run()
Ejemplo n.º 2
0
def main(args):
    # Parse options
    import optparse
    parser = optparse.OptionParser(
        usage="usage: %prog client_player_list "
              "<connect-host> <connect-port> <username> <password>")
    (options, args) = parser.parse_args(args)

    if len(args) != 4:
        return parser.print_usage()

    host, port, username, password = args

    # Create profile
    profile = Profile()

    # Create factory
    factory = PlayerListFactory()
    factory.profile = profile

    def login_ok(data):
        factory.connect(host, int(port))

    def login_failed(err):
        print "login failed:", err.value
        factory.stop()

    deferred = profile.login(username, password)
    deferred.addCallbacks(login_ok, login_failed)
    factory.run()
Ejemplo n.º 3
0
def main():
    # Parse options
    import optparse
    parser = optparse.OptionParser(
        usage="usage: %prog host port username password")
    (options, args) = parser.parse_args()

    if len(args) != 4:
        return parser.print_usage()

    host, port, username, password = args

    # Create profile
    profile = Profile()

    # Create factory
    factory = PlayerListFactory()
    factory.profile = profile

    def login_ok(data):
        factory.connect(host, int(port))

    def login_failed(err):
        print "login failed:", err.value
        factory.stop()

    deferred = profile.login(username, password)
    deferred.addCallbacks(login_ok, login_failed)
    factory.run()
def main():
    # Parse options
    import optparse
    parser = optparse.OptionParser(
        usage="usage: %prog host port username password")
    (options, args) = parser.parse_args()

    if len(args) != 4:
        return parser.print_usage()

    host, port, username, password = args

    # Create profile
    profile = Profile()

    # Create factory
    factory = ChatLoggerFactory()
    factory.profile = profile

    def login_ok(data):
        factory.connect(host, int(port))

    def login_failed(err):
        print "login failed:", err.value
        factory.stop()

    deferred = profile.login(username, password)
    deferred.addCallbacks(login_ok, login_failed)
    factory.run()
Ejemplo n.º 5
0
    def __init__(self, downstream_factory, downstream):
        self.downstream_factory = downstream_factory
        self.upstream_factory = downstream_factory.upstream_factory_class()
        self.downstream = downstream
        self.upstream = None

        self.buff_type = self.downstream_factory.buff_type

        self.logger = logging.getLogger(
            "%s{%s}" % (self.__class__.__name__, self.downstream.username))
        self.logger.setLevel(self.log_level)

        self.register_handlers()

        # Set up offline profile
        profile = Profile()
        profile.login_offline(self.downstream.username)

        # Set up client factory
        self.upstream_factory.bridge = self
        self.upstream_factory.buff_type = self.buff_type
        self.upstream_factory.profile = profile

        # Connect!
        self.upstream_factory.connect(self.downstream_factory.connect_host,
                                      self.downstream_factory.connect_port,
                                      "login",
                                      self.downstream.protocol_version)
Ejemplo n.º 6
0
def main(args):
    # Parse options
    import optparse
    parser = optparse.OptionParser(
        usage="usage: %prog <connect-host> <connect-port> "
        "<username> <password>")
    (options, args) = parser.parse_args(args)

    if len(args) != 4:
        return parser.print_usage()

    host, port, username, password = args

    # Create profile
    profile = Profile()

    # Create factory
    factory = PlayerListFactory()
    factory.profile = profile

    # Log in and connect
    deferred = profile.login(username, password)
    deferred.addCallbacks(lambda data: factory.connect(host, int(port)),
                          lambda err: print("login failed:", err.value))
    factory.run()
Ejemplo n.º 7
0
    def __init__(self, downstream_factory, downstream):
        self.downstream_factory  = downstream_factory
        self.upstream_factory    = downstream_factory.upstream_factory_class()
        self.downstream = downstream
        self.upstream   = None

        self.buff_type = self.downstream_factory.buff_type

        self.logger = logging.getLogger("%s{%s}" % (
            self.__class__.__name__,
            self.downstream.username))
        self.logger.setLevel(self.log_level)

        self.register_handlers()

        # Set up offline profile
        profile = Profile()
        profile.login_offline(self.downstream.username)

        # Set up client factory
        self.upstream_factory.bridge = self
        self.upstream_factory.buff_type = self.buff_type
        self.upstream_factory.profile = profile

        # Connect!
        self.upstream_factory.connect(
            self.downstream_factory.connect_host,
            self.downstream_factory.connect_port,
            "login",
            self.downstream.protocol_version)
Ejemplo n.º 8
0
    def __init__(self, downstream_factory, downstream):
        self.downstream_factory  = downstream_factory
        self.upstream_factory    = downstream_factory.upstream_factory_class()
        self.downstream = downstream
        self.upstream   = None

        self.buff_type = self.downstream_factory.buff_type

        self.logger = logging.getLogger("%s{%s}" % (
            self.__class__.__name__,
            self.downstream.username))
        self.logger.setLevel(self.log_level)

        # Set up client factory
        self.upstream_factory.bridge = self
        self.upstream_factory.buff_type = self.buff_type

        # If no upstream profile is set, generate an offline-mode profile
        if self.upstream_factory.profile is None:
            self.upstream_factory.profile = Profile()
            self.upstream_factory.profile.login_offline(
                self.downstream.username)

        # Connect to the server the client is requesting
        if self.downstream_factory.connect_host is None:
            self.connect_host = self.downstream.connect_host
            self.connect_port = self.downstream.connect_port
        else:
            self.connect_host = self.downstream_factory.connect_host
            self.connect_port = self.downstream_factory.connect_port

        self.setup()
Ejemplo n.º 9
0
def main():
    # Parse options
    import optparse
    parser = optparse.OptionParser(usage="usage: %prog host port")
    (options, args) = parser.parse_args()

    if len(args) != 2:
        return parser.print_usage()

    host, port = args

    # Create profile
    profile = Profile()
    profile.login_offline("quarry")

    # Create factory
    factory = PingFactory()
    factory.profile = profile

    factory.connect(host, int(port), "status")
    factory.run()
Ejemplo n.º 10
0
def main():
    if os.path.isfile(CONFIG_FILE):
        CONFIG.read(CONFIG_FILE)
    else:
        generate_config_file(CONFIG_FILE, CONFIG)

    profile = Profile()
    if not CONFIG['auth'].getboolean('auth'):
        profile.login_offline(CONFIG['auth']['username'])
        factory.profile = profile
    else:
        def login_ok(data):
            factory.connect(CONFIG['server']['ip'], int(CONFIG['server']['port']))

        def login_failed(err):
            print('login failed:', err.value)
            factory.stop()
            sys.exit(1)

        factory.profile = profile
        deferred = profile.login(CONFIG['auth']['username'], CONFIG['auth']['password'])
        deferred.addCallbacks(login_ok, login_failed)
        factory.run()
Ejemplo n.º 11
0
def main(args):
    # Parse options
    import argparse
    parser = argparse.ArgumentParser()

    group = parser.add_argument_group("upstream options")
    group.add_argument("-c", "--connect", dest="connect",
                       metavar="HOST[:PORT]",
                       help="Sets the address the proxy should connect to. "
                            "If not given, the proxy connects to the address "
                            "requested by the user. You probably want to set "
                            "this.")
    group.add_argument("-a", "--account", dest="account",
                       metavar=("EMAIL", "PASSWORD"), nargs=2,
                       help="Sets the minecraft account with which to log "
                            "in. Without setting this, the proxy will not be "
                            "capable of logging in to online-mode servers.")
    group = parser.add_argument_group("downstream options")
    group.add_argument("-l", "--listen", dest="listen",
                       metavar="HOST[:PORT]",
                       help="Sets the address the proxy should listen on. "
                            "If not given, the proxy listens on port 25565 on "
                            "all interfaces.")
    group.add_argument("-o", "--online-mode", dest="online_mode",
                       action="store_true",
                       help="If given, users connecting to the proxy are "
                            "authenticated by the Mojang session servers, "
                            "i.e. the server bit of the proxy is running in "
                            "online-mode.")
    group.add_argument("-v", "--protocol-version", dest="protocol_version",
                       type=int,
                       help="Sets the protocol version that the proxy "
                            "accepts from connecting users. If not set, the "
                            "proxy will attempt to use whichever the user "
                            "requests.")
    group = parser.add_argument_group("sniffer options")
    inner_group = group.add_mutually_exclusive_group()
    inner_group.add_argument("-p", "--packet", dest="packets",
                             action="append",
                             metavar=("DIRECTION", "NAME"),
                             nargs=2,
                             help="Adds a packet to be sniffed. "
                                  "DIRECTION should be one of: "
                                  "'up' (client --> server), "
                                  "'down' (server -> client).")
    inner_group.add_argument("-d", "--direction", dest="direction",
                             choices=("up", "down"),
                             help="Only sniff packets heading in a particular "
                                  "direction.")
    group.add_argument("-x", "--print-payload", dest="print_payload",
                       action="store_true",
                       help="Prints a hexdump with attempted ASCII "
                            "interpretation of the payload of sniffed "
                            "packets")
    group.add_argument("-y", "--dump-payload", dest="dump_payload",
                       metavar="DEST_PATH",
                       help="Dumps the payload of sniffed packets to the "
                            "specified directory")

    args = parser.parse_args(args)

    listen_host = ""
    listen_port = 25565

    factory = PacketSnifferDownstreamFactory()
    factory.online_mode = args.online_mode
    factory.force_protocol_version = args.protocol_version

    if args.direction is not None:
        factory.packet_direction = args.direction + "stream"
    if args.packets is not None:
        packets = set()
        for direction, name in args.packets:
            assert direction in ('up', 'down')
            direction += 'stream'
            packets.add((direction, name))
        factory.packet_whitelist = packets

    factory.print_payload = args.print_payload
    factory.dump_payload = args.dump_payload

    if args.listen:
        listen = split_host_port(args.listen)
        listen_host = listen[0]
        listen_port = int(listen[1])

    if args.connect:
        connect = split_host_port(args.connect)
        factory.connect_host = connect[0]
        factory.connect_port = int(connect[1])

    if args.account:
        def login_ok(data):
            factory.listen(listen_host, listen_port)

        def login_failed(err):
            print "login failed:", err.value
            factory.stop()

        username, password = args.account
        profile = Profile()

        factory.upstream_factory_class.profile = profile

        deferred = profile.login(username, password)
        deferred.addCallbacks(login_ok, login_failed)
    else:
        factory.listen(listen_host, listen_port)

    factory.run()
Ejemplo n.º 12
0
def main(args):
    # Parse options
    import argparse
    parser = argparse.ArgumentParser()

    group = parser.add_argument_group("upstream options")
    group.add_argument("-c",
                       "--connect",
                       dest="connect",
                       metavar="HOST[:PORT]",
                       help="Sets the address the proxy should connect to. "
                       "If not given, the proxy connects to the address "
                       "requested by the user. You probably want to set "
                       "this.")
    group.add_argument("-a",
                       "--account",
                       dest="account",
                       metavar=("EMAIL", "PASSWORD"),
                       nargs=2,
                       help="Sets the minecraft account with which to log "
                       "in. Without setting this, the proxy will not be "
                       "capable of logging in to online-mode servers.")
    group = parser.add_argument_group("downstream options")
    group.add_argument("-l",
                       "--listen",
                       dest="listen",
                       metavar="HOST[:PORT]",
                       help="Sets the address the proxy should listen on. "
                       "If not given, the proxy listens on port 25565 on "
                       "all interfaces.")
    group.add_argument("-o",
                       "--online-mode",
                       dest="online_mode",
                       action="store_true",
                       help="If given, users connecting to the proxy are "
                       "authenticated by the Mojang session servers, "
                       "i.e. the server bit of the proxy is running in "
                       "online-mode.")
    group.add_argument("-v",
                       "--protocol-version",
                       dest="protocol_version",
                       type=int,
                       help="Sets the protocol version that the proxy "
                       "accepts from connecting users. If not set, the "
                       "proxy will attempt to use whichever the user "
                       "requests.")
    group = parser.add_argument_group("sniffer options")
    inner_group = group.add_mutually_exclusive_group()
    inner_group.add_argument("-p",
                             "--packet",
                             dest="packets",
                             action="append",
                             metavar=("DIRECTION", "NAME"),
                             nargs=2,
                             help="Adds a packet to be sniffed. "
                             "DIRECTION should be one of: "
                             "'up' (client --> server), "
                             "'down' (server -> client).")
    inner_group.add_argument("-d",
                             "--direction",
                             dest="direction",
                             choices=("up", "down"),
                             help="Only sniff packets heading in a particular "
                             "direction.")
    group.add_argument("-x",
                       "--print-payload",
                       dest="print_payload",
                       action="store_true",
                       help="Prints a hexdump with attempted ASCII "
                       "interpretation of the payload of sniffed "
                       "packets")
    group.add_argument("-y",
                       "--dump-payload",
                       dest="dump_payload",
                       metavar="DEST_PATH",
                       help="Dumps the payload of sniffed packets to the "
                       "specified directory")

    args = parser.parse_args(args)

    listen_host = ""
    listen_port = 25565

    factory = PacketSnifferDownstreamFactory()
    factory.online_mode = args.online_mode
    factory.force_protocol_version = args.protocol_version

    if args.direction is not None:
        factory.packet_direction = args.direction + "stream"
    if args.packets is not None:
        packets = set()
        for direction, name in args.packets:
            assert direction in ('up', 'down')
            direction += 'stream'
            packets.add((direction, name))
        factory.packet_whitelist = packets

    factory.print_payload = args.print_payload
    factory.dump_payload = args.dump_payload

    if args.listen:
        listen = split_host_port(args.listen)
        listen_host = listen[0]
        listen_port = int(listen[1])

    if args.connect:
        connect = split_host_port(args.connect)
        factory.connect_host = connect[0]
        factory.connect_port = int(connect[1])

    if args.account:

        def login_ok(data):
            factory.listen(listen_host, listen_port)

        def login_failed(err):
            print "login failed:", err.value
            factory.stop()

        username, password = args.account
        profile = Profile()

        factory.upstream_factory_class.profile = profile

        deferred = profile.login(username, password)
        deferred.addCallbacks(login_ok, login_failed)
    else:
        factory.listen(listen_host, listen_port)

    factory.run()