def start(self): Log.loadSettings(self.cfg, self.section) self.loginProxyURI = None self.cfg.load(self, self.uriSettings) self.interceptURLs = False self.useSimProxy = False self.captureFile = '' self.captureCompression = 9 self.cfg.load(self, self.settings) if self.captureFile: Log(1, "Storing HTTP transactions in file %r" % self.captureFile) self.captureFile = open(self.captureFile, 'a+b') else: self.captureFile = None self.handler = CapProxyHandler(self) self.server = WebServer(self, self.section, self.handler) self.handler.sim = CapProxySimIntercept(self.simProxyURI) self.handler.mangler = CapProxyURIMangler(self.capProxyURI, self.simProxyURI, remote = True # XXX ## remote = False ) self.server.start() Log(1, "CapProxy loaded successfully")
def start(self): Log.loadSettings(self.cfg, self.section) self.simProxyURI = None self.capProxyURI = None self.loginProxyURI = None self.cfg.load(self, self.uriSettings) self.loginURI = 'https://login.agni.lindenlab.com/cgi-bin/login.cgi' self.logPasswords = False self.useSimProxy = False self.useCapProxy = False self.redirToSimHost = None self.redirToSimPort = None self.cfg.load(self, self.loginProxySettings) if self.capProxyURI: self.mangler = CapProxyURIMangler(self.capProxyURI, self.simProxyURI, remote=True) self.server = XMLRPCServer(self, self.section) self.server.register_function(self.login_to_simulator) ## self.server.register_instance(self) self.server.start() Log(1, "LoginProxy loaded successfully")
def start(self): Log.loadSettings(self.cfg, self.section) self.simProxyURI = None self.capProxyURI = None self.loginProxyURI = None self.cfg.load(self, self.uriSettings) self.loginURI = 'https://login.agni.lindenlab.com/cgi-bin/login.cgi' self.logPasswords = False self.useSimProxy = False self.useCapProxy = False self.redirToSimHost = None self.redirToSimPort = None self.cfg.load(self, self.loginProxySettings) if self.capProxyURI: self.mangler = CapProxyURIMangler( self.capProxyURI, self.simProxyURI, remote = True ) self.server = XMLRPCServer(self, self.section) self.server.register_function(self.login_to_simulator) ## self.server.register_instance(self) self.server.start() Log(1, "LoginProxy loaded successfully")
def newSim(self, simAddr): Log(1, "Requesting Sim proxy for %s:%d" % simAddr) simProxy = xmlrpclib.ServerProxy(self.__uri) simAddr = simProxy.newSim(simAddr) simAddr = tuple(simAddr) Log(1, "Granted Sim proxy as %s:%d" % simAddr) return simAddr
def filterPacket(self, rawPacket, fromViewer): isReply = False try: packet = SLPacket(rawPacket, self.main.pktCapture.slTemplate) result = self.main.msgFilter.run(fromViewer, packet) if result is not None: isReply, packet = result rawPacket = str(packet) except Exception, e: Log.logException()
def newSeed(self, uri): Log(1, "Discovered seed capabilities URI %s" % uri) if self.__remote: simProxy = xmlrpclib.ServerProxy(self.__sp_uri) hashed_uri = simProxy.newSeed(uri) else: hashed_uri = hash(uri) self.__seed[hashed_uri] = uri hashed_uri = str(hashed_uri) Log(2, "Remembered seed capabilities URI as hash %s" % hashed_uri) return hashed_uri
def getSeed(self, hashed_uri): Log(2, "Received hash %s" % hashed_uri) hashed_uri = long(hashed_uri) if self.__seed.has_key(hashed_uri): uri = self.__seed[hashed_uri] else: simProxy = xmlrpclib.ServerProxy(self.__sp_uri) uri = simProxy.getSeed(hashed_uri) Log(2, "Received capabilities URI: %s" % uri) if hash(uri) != hashed_uri: Log(1, "Bad hashed URI: (%d != %d) %s" % (hash(uri), hashed_uri, uri)) return uri
def start(self): if self.captureFile: Log(1, "Storing captured packets in %s" % self.captureFile) self.cap_file = open(self.captureFile, 'a+b') self.lock = threading.RLock() else: self.cap_file = None
def close(self): self.sock.close() del self.sock Log(1, self.die_message % \ (self.peerAddress, self.peerPort, self.bindPort) )
def change_xml(self, xml): try: ll = LLSD.fromstring(xml) if type(ll) == types.DictType and ll.has_key('events'): do_encode = False for msg in ll['events']: name = msg['message'] body = msg['body'] Log(4, name) if name == 'EstablishAgentCommunication': do_encode = True seed_cap = body['seed-capability'] ip_port = body['sim-ip-and-port'] sim_ip, sim_port = ip_port.split(':') sim_port = int(sim_port) sim_ip, sim_port = self.newSim((sim_ip, sim_port)) ip_port = '%s:%d' % (sim_ip, sim_port) body['sim-ip-and-port'] = ip_port elif name in ('CrossedRegion', 'TeleportFinish'): do_encode = True if name == 'CrossedRegion': info = body['RegionData'] elif name == 'TeleportFinish': info = body['Info'] sim_ip = info['SimIP'] sim_port = info['SimPort'] seed_cap = info['SeedCapability'] sim_ip = socket.inet_ntoa(str(sim_ip)) sim_ip, sim_port = self.newSim((sim_ip, sim_port)) sim_ip = LLSD.LLElement(socket.inet_aton(sim_ip)) sim_ip.set_llsd( info['SimIP'].get_llsd() ) info['SimIP'] = sim_ip info['SimPort'] = sim_port if do_encode: return LLSD.tostring(ll) return xml except Exception, e: Log.logException() return self.generic_change_xml(xml)
def select(self): socketList = self.bySock.keys() if socketList: socketList = select.select(socketList, [], [], 1)[0] for s in socketList: try: proxyTo = self.bySock[s] fromViewer = (proxyTo.__class__ == Sim) rawPacket, fromAddr = proxyTo.recvfrom() proxyFrom = self.connect(proxyTo, fromAddr) toAddr = (proxyTo.peerAddress, proxyTo.peerPort) isReply, newPacket = self.filterPacket(rawPacket, fromViewer) if newPacket: if isReply: proxyFrom.sendto(newPacket, fromAddr) self.capturePacket(rawPacket, fromAddr, toAddr) self.capturePacket(newPacket, toAddr, fromAddr) else: proxyFrom.sendto(newPacket, toAddr) self.capturePacket(newPacket, fromAddr, toAddr) except Exception, e: Log.logException()
def start(self): Log.loadSettings(self.cfg, self.section) self.loadSettings() self.pktCapture = PacketCapture(self.cfg) self.pktCapture.start() self.msgFilter = SLPacketFilter(self) self.lock = threading.RLock() self.active = True self.seed = {} self.worker = Selector(self) self.worker.start() self.server = XMLRPCServer(self, self.xmlrpc_section) self.server.register_function(self.newSim) self.server.register_function(self.newSeed) self.server.register_function(self.getSeed) self.server.start() Log(1, "SimProxy loaded successfully")
def __init__(self, peerAddress, peerPort, bindAddress = '0.0.0.0', bindPort = 0 ): self.peerAddress, self.peerPort = peerAddress, peerPort self.bindAddress, self.bindPort = bindAddress, bindPort self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sock.bind( (self.bindAddress, self.bindPort) ) self.bindAddress, self.bindPort = self.sock.getsockname() Log(1, self.new_message % \ (self.peerAddress, self.peerPort, self.bindPort) )
def do_POST(self, server, request, addr): try: print "\n\nURL: %r\n\n" % request.getpath() # XXX # Get the request data, if any if request.hasdata(): reqdata = request.getdata() else: reqdata = '' # If the request is not mangled, return a 404 error path = request.getpath() if not self.mangler.is_mangled(path): raise urllib2.HTTPError( self.mangler.absolute(path), 404, 'Not found', 'Content-length: 0\r\n\r\n', None) path = self.mangler.unmangle(path) # If we have request data... if reqdata: # Store the request data fd = self.main.captureFile if fd: cap_level = self.main.captureCompression cap_data = CapProxyCapture.packRequest(path, reqdata, cap_level) fd.write(cap_data) # Unmangle the request data Log(3, 'Mangled URI: %s' % path) path = self.mangler.unmangle(path) Log(2, "Requested URI: %s" % path) Log(3, "Request data: %r" % reqdata) unmangled_req = self.mangler.unmangle_xml(reqdata) if unmangled_req != reqdata: reqdata = unmangled_req Log(3, "Unmangled request data: %r" % reqdata) # Store the modified request data fd = self.main.captureFile if fd: cap_level = self.main.captureCompression cap_data = CapProxyCapture.packRequest(path, reqdata, cap_level) fd.write(cap_data) # Proxy the request new_req = HTTPRequest.fromurl(path, version=request.getversion()) new_req.setmethod(request.getmethod()) new_req.setdata(reqdata) if new_req.has_key('Host'): new_host = new_req['Host'] new_req.setallheaders(request.getallheaders()) new_req['Host'] = new_host else: new_req.setallheaders(request.getallheaders()) ## client = HTTPClient.fromurl(path) ## client.write(new_req) ## response = client.readresponse() ## if response.hasdata(): ## respdata = response.getdata() ## else: ## respdata = '' response = HTTPResponse.fromurl(path, reqdata) response.setversion(request.getversion()) # XXX this is a hack! ## print repr(response.getdata()) if response.hasdata(): respdata = response.getdata() else: respdata = '' if respdata: Log(3, "Response data: %r" % respdata) # Store the response data fd = self.main.captureFile if fd: cap_level = self.main.captureCompression cap_data = CapProxyCapture.packResponse(respdata, cap_level) fd.write(cap_data) # Mangle the response data if self.main.interceptURLs: try: respdata = self.mangler.mangle_xml(respdata) except Exception, e: Log.logException() if self.main.useSimProxy: try: respdata = self.sim.change_xml(respdata) except Exception, e: Log.logException() # Log the response data if self.main.interceptURLs or self.main.useSimProxy: Log(3, "Modified response data: %r" % respdata) # Store the response data fd = self.main.captureFile if fd: cap_level = self.main.captureCompression cap_data = CapProxyCapture.packResponse(respdata, cap_level) fd.write(cap_data)
def __run(self): try: self.run() except Exception, e: Log.logException() self.die()
def kill(self): Log(1, "LoginProxy shut down")
def login_to_simulator(self, *arg_list): try: login_req = arg_list[0] # should be a dictionary # Log entire request data Log(4, "XML-RPC Request: %s" % \ xmlrpclib.dumps(arg_list).replace('\n','') ) # Log login attempt first = login_req['first'] last = login_req['last'] if self.logPasswords: passwd = login_req['passwd'] if passwd.startswith('$1$'): passwd = passwd[3:] Log( 1, "User %s %s logging in\n" "\thash: %s" "" % (first, last, passwd)) else: Log(1, "User %s %s logging in" % (first, last)) # Send request to real login server server = xmlrpclib.ServerProxy(self.loginURI) login_resp = server.login_to_simulator(login_req) # Log entire response data Log(4, "XML-RPC Response: %s" % \ xmlrpclib.dumps((login_resp,), methodresponse = True).replace('\n','') ) # Parse response login = login_resp['login'] message = login_resp['message'] if login == 'false': reason = login_resp['reason'] elif login == 'true': sim_ip = login_resp['sim_ip'] sim_port = login_resp['sim_port'] seed_capability = login_resp['seed_capability'] # Log login success or failure if login == 'true': ## first_name = login_resp['first_name'] ## last_name = login_resp['last_name'] if self.logPasswords: session_id = login_resp['session_id'] secure_session_id = login_resp['secure_session_id'] Log(1, "User %s %s successfully logged in\n" "\tsid: %s\n" "\tssid: %s" % \ (first, last, session_id, secure_session_id) ) else: Log(1, "User %s %s logged in" % (first, last)) else: message = message.replace('\n', ' ') message = message.replace('\r', '') Log(1, "User %s %s failed to log in: %s" % (first, last, message)) # Modify the seed capabilities URI if login == 'true' and self.useCapProxy and self.capProxyURI: if seed_capability: Log(3, "Seed capability URI found: %s" % seed_capability) new_seed_capability = self.mangler.mangle(seed_capability) login_resp['seed_capability'] = new_seed_capability Log( 2, "Forcing seed capability URI: %s" % new_seed_capability) login_resp['message'] = 'All your base are belong to us' else: Log(3, "Seed capability URI not found") # Redirect to our Sim if login == 'true': Log(3, "Sim %s:%d discovered" % (sim_ip, sim_port)) orig_sim_ip, orig_sim_port = sim_ip, sim_port if self.redirToSimHost: sim_ip = self.redirToSimHost sim_port = self.redirToSimPort if self.useSimProxy and self.simProxyURI: Log( 3, "Requesting new Sim from SimProxy %s" % self.simProxyURI) try: simProxy = xmlrpclib.ServerProxy(self.simProxyURI) sim_ip, sim_port = simProxy.newSim( (orig_sim_ip, orig_sim_port)) except Exception, e: Log.logException() if (orig_sim_ip, orig_sim_port) != (sim_ip, sim_port): login_resp['sim_ip'] = sim_ip login_resp['sim_port'] = sim_port login_resp['message'] = 'All your base are belong to us' Log(2, "Forcing Sim redirection %s:%d -> %s:%d for %s %s" % \ ( orig_sim_ip, orig_sim_port, sim_ip, sim_port, first, last ) ) else: Log(2, "User %s %s connected to Sim %s:%d" % \ (first, last, sim_ip, sim_port) ) # Log entire mangled response data if self.useCapProxy or self.useSimProxy or self.redirToSimHost: Log(4, "XML-RPC Response (mangled): %s" % \ xmlrpclib.dumps((login_resp,), methodresponse = True).replace('\n','') ) # Send response back to the client return login_resp
def kill(self): Log(1, "CapProxy shut down")
def login_to_simulator(self, *arg_list): try: login_req = arg_list[0] # should be a dictionary # Log entire request data Log(4, "XML-RPC Request: %s" % \ xmlrpclib.dumps(arg_list).replace('\n','') ) # Log login attempt first = login_req['first'] last = login_req['last'] if self.logPasswords: passwd = login_req['passwd'] if passwd.startswith('$1$'): passwd = passwd[3:] Log(1, "User %s %s logging in\n" "\thash: %s" "" % (first, last, passwd) ) else: Log(1, "User %s %s logging in" % (first, last)) # Send request to real login server server = xmlrpclib.ServerProxy(self.loginURI) login_resp = server.login_to_simulator(login_req) # Log entire response data Log(4, "XML-RPC Response: %s" % \ xmlrpclib.dumps((login_resp,), methodresponse = True).replace('\n','') ) # Parse response login = login_resp['login'] message = login_resp['message'] if login == 'false': reason = login_resp['reason'] elif login == 'true': sim_ip = login_resp['sim_ip'] sim_port = login_resp['sim_port'] seed_capability = login_resp['seed_capability'] # Log login success or failure if login == 'true': ## first_name = login_resp['first_name'] ## last_name = login_resp['last_name'] if self.logPasswords: session_id = login_resp['session_id'] secure_session_id = login_resp['secure_session_id'] Log(1, "User %s %s successfully logged in\n" "\tsid: %s\n" "\tssid: %s" % \ (first, last, session_id, secure_session_id) ) else: Log(1, "User %s %s logged in" % (first, last)) else: message = message.replace('\n', ' ') message = message.replace('\r', '') Log(1, "User %s %s failed to log in: %s" % (first, last, message)) # Modify the seed capabilities URI if login == 'true' and self.useCapProxy and self.capProxyURI: if seed_capability: Log(3, "Seed capability URI found: %s" % seed_capability) new_seed_capability = self.mangler.mangle(seed_capability) login_resp['seed_capability'] = new_seed_capability Log(2, "Forcing seed capability URI: %s" % new_seed_capability) login_resp['message'] = 'All your base are belong to us' else: Log(3, "Seed capability URI not found") # Redirect to our Sim if login == 'true': Log(3, "Sim %s:%d discovered" % (sim_ip, sim_port)) orig_sim_ip, orig_sim_port = sim_ip, sim_port if self.redirToSimHost: sim_ip = self.redirToSimHost sim_port = self.redirToSimPort if self.useSimProxy and self.simProxyURI: Log(3, "Requesting new Sim from SimProxy %s" % self.simProxyURI) try: simProxy = xmlrpclib.ServerProxy(self.simProxyURI) sim_ip, sim_port = simProxy.newSim( (orig_sim_ip, orig_sim_port) ) except Exception, e: Log.logException() if (orig_sim_ip, orig_sim_port) != (sim_ip, sim_port): login_resp['sim_ip'] = sim_ip login_resp['sim_port'] = sim_port login_resp['message'] = 'All your base are belong to us' Log(2, "Forcing Sim redirection %s:%d -> %s:%d for %s %s" % \ ( orig_sim_ip, orig_sim_port, sim_ip, sim_port, first, last ) ) else: Log(2, "User %s %s connected to Sim %s:%d" % \ (first, last, sim_ip, sim_port) ) # Log entire mangled response data if self.useCapProxy or self.useSimProxy or self.redirToSimHost: Log(4, "XML-RPC Response (mangled): %s" % \ xmlrpclib.dumps((login_resp,), methodresponse = True).replace('\n','') ) # Send response back to the client return login_resp
# Log the response data if self.main.interceptURLs or self.main.useSimProxy: Log(3, "Modified response data: %r" % respdata) # Store the response data fd = self.main.captureFile if fd: cap_level = self.main.captureCompression cap_data = CapProxyCapture.packResponse(respdata, cap_level) fd.write(cap_data) # return the mangled response data response.setdata(respdata) except urllib2.HTTPError, e: Log.logException(2) ## Log.logException(2, print_tb = False) server.writeresponse( version = request.getversion(), code = e.code, desc = e.msg, hdr = str(e.hdrs) ) server.close() except Exception, e: # This should only happen if the module is buggy # internal error, report as HTTP server error Log.logException(2) server.writeresponse( version = request.getversion(),
def kill(self): Log(1, "Shutting down SimProxy...") self.active = False self.worker.kill() Log(1, "Shut down SimProxy")
class LoginProxy: section = 'LoginProxy' uriSettings = { 'URI': { 'loginProxyURI': 'string', 'capProxyURI': 'string', 'simProxyURI': 'string', }, } loginProxySettings = { 'LoginProxy': { 'loginURI': 'string', 'logPasswords': 'bool', 'useSimProxy': 'bool', 'useCapProxy': 'bool', 'redirToSimHost': 'ipaddr', 'redirToSimPort': 'int', }, } def __init__(self, configFilename): self.cfg = Config() self.cfg.read(filename) def start(self): Log.loadSettings(self.cfg, self.section) self.simProxyURI = None self.capProxyURI = None self.loginProxyURI = None self.cfg.load(self, self.uriSettings) self.loginURI = 'https://login.agni.lindenlab.com/cgi-bin/login.cgi' self.logPasswords = False self.useSimProxy = False self.useCapProxy = False self.redirToSimHost = None self.redirToSimPort = None self.cfg.load(self, self.loginProxySettings) if self.capProxyURI: self.mangler = CapProxyURIMangler(self.capProxyURI, self.simProxyURI, remote=True) self.server = XMLRPCServer(self, self.section) self.server.register_function(self.login_to_simulator) ## self.server.register_instance(self) self.server.start() Log(1, "LoginProxy loaded successfully") def kill(self): Log(1, "LoginProxy shut down") ## def _dispatch(self, method, params): ## print repr(method) ## print repr(params) ## if method == u'login_to_simulator': ## try: ## result = self.login_to_simulator(*params) ## print repr(result) ## return result ## except Exception, e: ## Log.logException() ## raise def login_to_simulator(self, *arg_list): try: login_req = arg_list[0] # should be a dictionary # Log entire request data Log(4, "XML-RPC Request: %s" % \ xmlrpclib.dumps(arg_list).replace('\n','') ) # Log login attempt first = login_req['first'] last = login_req['last'] if self.logPasswords: passwd = login_req['passwd'] if passwd.startswith('$1$'): passwd = passwd[3:] Log( 1, "User %s %s logging in\n" "\thash: %s" "" % (first, last, passwd)) else: Log(1, "User %s %s logging in" % (first, last)) # Send request to real login server server = xmlrpclib.ServerProxy(self.loginURI) login_resp = server.login_to_simulator(login_req) # Log entire response data Log(4, "XML-RPC Response: %s" % \ xmlrpclib.dumps((login_resp,), methodresponse = True).replace('\n','') ) # Parse response login = login_resp['login'] message = login_resp['message'] if login == 'false': reason = login_resp['reason'] elif login == 'true': sim_ip = login_resp['sim_ip'] sim_port = login_resp['sim_port'] seed_capability = login_resp['seed_capability'] # Log login success or failure if login == 'true': ## first_name = login_resp['first_name'] ## last_name = login_resp['last_name'] if self.logPasswords: session_id = login_resp['session_id'] secure_session_id = login_resp['secure_session_id'] Log(1, "User %s %s successfully logged in\n" "\tsid: %s\n" "\tssid: %s" % \ (first, last, session_id, secure_session_id) ) else: Log(1, "User %s %s logged in" % (first, last)) else: message = message.replace('\n', ' ') message = message.replace('\r', '') Log(1, "User %s %s failed to log in: %s" % (first, last, message)) # Modify the seed capabilities URI if login == 'true' and self.useCapProxy and self.capProxyURI: if seed_capability: Log(3, "Seed capability URI found: %s" % seed_capability) new_seed_capability = self.mangler.mangle(seed_capability) login_resp['seed_capability'] = new_seed_capability Log( 2, "Forcing seed capability URI: %s" % new_seed_capability) login_resp['message'] = 'All your base are belong to us' else: Log(3, "Seed capability URI not found") # Redirect to our Sim if login == 'true': Log(3, "Sim %s:%d discovered" % (sim_ip, sim_port)) orig_sim_ip, orig_sim_port = sim_ip, sim_port if self.redirToSimHost: sim_ip = self.redirToSimHost sim_port = self.redirToSimPort if self.useSimProxy and self.simProxyURI: Log( 3, "Requesting new Sim from SimProxy %s" % self.simProxyURI) try: simProxy = xmlrpclib.ServerProxy(self.simProxyURI) sim_ip, sim_port = simProxy.newSim( (orig_sim_ip, orig_sim_port)) except Exception, e: Log.logException() if (orig_sim_ip, orig_sim_port) != (sim_ip, sim_port): login_resp['sim_ip'] = sim_ip login_resp['sim_port'] = sim_port login_resp['message'] = 'All your base are belong to us' Log(2, "Forcing Sim redirection %s:%d -> %s:%d for %s %s" % \ ( orig_sim_ip, orig_sim_port, sim_ip, sim_port, first, last ) ) else: Log(2, "User %s %s connected to Sim %s:%d" % \ (first, last, sim_ip, sim_port) ) # Log entire mangled response data if self.useCapProxy or self.useSimProxy or self.redirToSimHost: Log(4, "XML-RPC Response (mangled): %s" % \ xmlrpclib.dumps((login_resp,), methodresponse = True).replace('\n','') ) # Send response back to the client return login_resp except Exception, e: Log.logException() raise