def run(payload, socket): global vnc_running host = payload["args"]["host"] port = payload["args"]["port"] key = payload["args"]["key"] response = { 'cmd_id': payload['cmd_id'], 'session_id': payload["args"]["session_id"], 'key': key, 'error': "" } if vnc_running == True: response['error'] = "VNC is already running" socket.response(response) else: socket.response(response) try: vnc_running = True r = RFBServer(host, port, key) r.HandShake() r.Initialisation() r.VNCServerLoopStart() except Exception as e: vnc_running = False Klogger().error("VNC handshake %s" % (str(e), ))
def run(payload, socket): session_id = payload["args"]["session_id"] response = { "cmd_id": payload["cmd_id"], "session_id": session_id, "network": [], "error": "" } get_gateway(response) network_connections(response) get_arp_caches(response) check_arp_monitor_tool(response) check_ipv4_configuration(response) check_ipv6_configuration(response) check_dns_server(response) check_ssh_configuration(response) Kharden().sync_process( socket, session_id, Kharden().NETWORK, 2, [0, 0.4, 0.6, 0.8, 1], [ "netstat -anp", "ifconfig -a", "cat /proc/net/arp", "cat /etc/ssh/sshd_config", "Finished" ]) socket.response(response)
def download(self, payload, socket): identity = payload["args"]["identity"] if not identity or identity in self.download_cache: return path = payload["args"]["path"] items = payload["args"]["items"] session_id = payload["args"]["session_id"] error = self.download_check(path, items) if error: socket.response({ "cmd_id": payload["cmd_id"], "session_id": session_id, "error": error }) return self.download_prepare(identity, path, items) socket.response({ "cmd_id": payload["cmd_id"], "session_id": session_id, "identity": identity, "error": "" })
def run(payload, socket): response = { "cmd_id": payload["cmd_id"], "session_id": payload["args"]["session_id"], "nic": {}, "error": "" } network_status(response) socket.response(response)
def sync_upload_progress(self, socket, session_id, identity, received, total, filename, error): socket.response({ "cmd_id": "1081", "session_id": session_id, "percent": round(received / total, 4), "received": received, "total": total, "filename": filename, "identity": identity, "error": error })
def sync_download_progress(self, socket, session_id, identity, received, total, filename, data): socket.response({ "cmd_id": "1082", "session_id": session_id, "percent": round(received / total, 4), "received": received, "total": total, "filename": filename, "identity": identity, "data": data })
def uploading(self, args, socket): datalen = args["data_len"] filename = args["filename"] identity = args["identity"] error = "" if identity not in self.upload_cache: self.upload_cache[identity] = { "begin_time": time_op.now(), "last_time": time_op.now(), "path": args["path"], "filename": filename, "total": datalen, "received": 0, "content": bytearray() } cache = self.upload_cache[identity] cache["content"].extend(bytearray(args["data"])) cache["received"] += len(args["data"]) if cache["received"] == cache["total"]: item_new_path = os.path.join(cache["path"], cache["filename"]) if os.path.exists(item_new_path): item_new_path = "{}-{}".format(item_new_path, time_op.localtime2string()) try: with open(item_new_path, "ab") as f: f.write(cache["content"]) except Exception as e: error = str(e) print(error) finally: del self.upload_cache[identity] socket.response({ "cmd_id": "1068", "session_id": args["session_id"], "identity": identity, "error": "" }) self.sync_upload_progress(socket, args["session_id"], identity, cache["received"], datalen, filename, error)
def run(payload, socket): response = { "cmd_id": payload["cmd_id"], "session_id": payload["args"]["session_id"], "pair_id": payload["args"]["pair_id"], "error": "" } response_2 = { "cmd_id": "1063", "pair_id": payload["args"]["pair_id"], "error": "data error" } # Create a UDP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Bind the socket to the port sock.bind(('', 0)) sock.settimeout(5) random_code = Krandom().purely(32) response["random_code"] = random_code response["port"] = sock.getsockname()[1] response["ip"] = common.get_ip_gateway() socket.response(response) try: data, client = sock.recvfrom(1024) if data != random_code: socket.response(response_2) return sock.sendto(payload["args"]["server2client_key"], client) except socket.timeout as e: socket.response(response_2) sock.close()
def run(payload, socket): response = { "cmd_id": payload["cmd_id"], "session_id": payload["args"]["session_id"], "pair_id": payload["args"]["pair_id"], "error": "" } # Create a UDP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.settimeout(5) # Bind the socket to the port server_address = (payload["args"]["ip"], payload["args"]["port"]) message = payload["args"]["random_code"] sock.sendto(message, server_address) try: data, server = sock.recvfrom(1024) if data != payload["args"]["server2client_key"]: response["error"] = "data error" socket.response(response) return #UDP connection established socket.response(response) path = payload["args"]["path"] except socket.timeout as e: response["error"] = "data error" socket.response(response) sock.close()