def dataReceived(self, data): try: data = json.loads(data) except ValueError: self.factory.msg("Cannot decode WebSocket request.") return if not "action" in data: return #Handle Authentication if data.get("action") == "auth" and data.get( "key") == HoneyProxy.getAuthKey() and not self.authenticated: self.authenticated = True self.factory.clients.add(self) self.factory.msg("Authenticated.") return #Forbid unauthenticated requests if not self.authenticated: self.factory.msg("Unauthorized request to WebSocket API.") return def notImplemented(): self.factory.msg("Unimplemented function call") raise NotImplementedError() def read(data): f = HoneyProxy.getProxyMaster().getFlowCollection() if "id" in data and data["id"] != "all": self.factory.msg("read", { "id": data.get("id"), "data": f.getFlowsSerialized()[data.get("id")] }, client=self) else: flows = f.getFlowsSerialized() self.factory.msg("read", { "id": "all", "data": flows }, client=self) try: { #'create': notImplemented, 'read': read, #'update': notImplemented, #'delete': notImplemented, }[data.get("action")](data) except KeyError: notImplemented()
def onMessage(self, data, binary): try: data = json.loads(data) except ValueError: self.factory.msg("Cannot decode WebSocket request.") return if not "action" in data: return #Handle Authentication if data.get("action") == "auth" and data.get("key") == HoneyProxy.getAuthKey() and not self.authenticated: self.authenticated = True self.factory.clients.add(self) self.factory.msg("Authenticated.") return #Forbid unauthenticated requests if not self.authenticated: self.factory.msg("Unauthorized request to WebSocket API.") return def notImplemented(): self.factory.msg("Unimplemented function call") raise NotImplementedError() def read(data): f = HoneyProxy.getProxyMaster().getFlowCollection() if "id" in data and data["id"] != "all": self.factory.msg("read",{"id":data.get("id"), "data": f.getFlowsSerialized()[data.get("id")]},client=self) else: flows = f.getFlowsSerialized() self.factory.msg("read",{"id":"all","data": flows},client=self) try: { #'create': notImplemented, 'read' : read, #'update': notImplemented, #'delete': notImplemented, }[data.get("action")](data) except KeyError: notImplemented()
sys.exit(1) HoneyProxy.setAuthKey(options.apiauth) if options.readonly: HoneyProxy.apiAuthToken = None #set up HoneyProxy GUI guiSessionFactory = session.GuiSessionFactory("ws://*****:*****@localhost:"+str(options.guiport)+"/" guiURL = httpGui +"app/" HoneyProxy.setConfig({ "proxy-addr":options.addr, "proxy-port":options.port, "ws-port": wsPort, "auth": HoneyProxy.getAuthKey(), "dumpdir": True if options.dumpdir else False }) root = Resource() root.putChild("app",File(os.path.join(honeyproxy_dir,"gui"))) root.putChild("api",api.HoneyProxyApi(honeyproxy_dir)) root.putChild("files", content.ContentAPIResource()) if(options.dumpdir): root.putChild("dump", File(options.dumpdir))
print >> sys.stderr, "%(name)s: %(args)s" % {"name": version.NAME, "args": v.args[0]} sys.exit(1) HoneyProxy.setAuthKey(options.apiauth) if options.readonly: HoneyProxy.apiAuthToken = None #set up HoneyProxy GUI guiSessionFactory = session.GuiSessionFactory() #WebSocket websocketRes = WebSocketsResource(guiSessionFactory) reactor.listenTCP(options.apiport, Site(websocketRes)) #Config wsPort = str(options.apiport) urlauth = "honey:"+HoneyProxy.getAuthKey()+"@" if HoneyProxy.getAuthKey() != "NO_AUTH" else "" httpGui = "http://"+urlauth+"localhost:"+str(options.guiport)+"/" guiURL = httpGui +"app/" HoneyProxy.setConfig({ "proxy-addr":options.addr, "proxy-port":options.port, "ws-port": wsPort, "auth": HoneyProxy.getAuthKey(), "dumpdir": True if options.dumpdir else False }) root = Resource() root.putChild("app",File(os.path.join(dirutils.honeyproxy_dir,"gui"))) root.putChild("api",api.HoneyProxyApi()) root.putChild("files", content.ContentAPIResource()) if(options.dumpdir):