def edit_honeypots_submenu(ctx): try: subchoice = prompt( [ { "type": "list", "name": "subchoice", "message": "What do you need to do?", "choices": [ "Start Honeypot", "Stop Honeypot", "Configure Honeypot", ], "filter": lambda val: val.lower(), } ], style=style(), )["subchoice"] except EOFError: ctx.invoke(main_menu) if subchoice == "start honeypot": ctx.invoke(starthoneypot) elif subchoice == "stop honeypot": ctx.invoke(stophoneypot) elif subchoice == "configure honeypot": ctx.invoke(configurehoneypot)
def main_menu(ctx): # Main Loop to run the interactive menu while True: choice = prompt( [ { "type": "list", "name": "choice", "message": "What do you need to do?", "choices": ["Manage Hosts", "Install", "Edit Honeypots", "Exit"], "filter": lambda val: val.lower(), } ], style=style(), )["choice"] if choice == "manage hosts": ctx.invoke(manage_hosts_submenu) elif choice == "install": ctx.invoke(install_submenu) elif choice == "edit honeypots": ctx.invoke(edit_honeypots_submenu) elif choice == "exit": os.kill(os.getpid(), signal.SIGINT)
def install_submenu(ctx): try: subchoice = prompt( [ { "type": "list", "name": "subchoice", "message": "What do you need to do?", "choices": [ "Install Honeypot", "Uninstall Honeypot", "Reinstall Honeypot", ], "filter": lambda val: val.lower(), } ], style=style(), )["subchoice"] except EOFError: ctx.invoke(main_menu) if subchoice == "install honeypot": ctx.invoke(installhoneypot) elif subchoice == "uninstall honeypot": ctx.invoke(uninstallhoneypot) elif subchoice == "reinstall honeypot": ctx.invoke(reinstallhoneypot)
def manage_hosts_submenu(ctx): try: subchoice = prompt( [ { "type": "list", "name": "subchoice", "message": "What do you need to do?", "choices": ["Add Host", "Remove Host", "Check Status"], "filter": lambda val: val.lower(), } ], style=style(), )["subchoice"] except EOFError: ctx.invoke(main_menu) if subchoice == "add host": ctx.invoke(addhost) elif subchoice == "remove host": ctx.invoke(removehost) elif subchoice == "check status": ctx.invoke(checkstatus)
def addhost(ctx): """ Add a host """ new_host = None try: new_host = prompt( [ { "type": "input", "name": "hostname", "message": "Hostname:", "validate": HostnameValidator, }, { "type": "input", "name": "user", "message": "Username:"******"validate": EmptyValidator, }, { "type": "input", "name": "ip", "message": "IP Address:", "validate": DeviceIPValidator, }, { "type": "input", "name": "ssh_port", "message": "Port:", "validate": PortValidator, }, { "type": "input", "name": "ssh_key", "message": "SSH Key:", "validate": FilePathValidator, }, ], style=style(), ) except EOFError: log("Action cancelled by user", "red") return hostname = new_host.pop("hostname") new_host["status"] = "inactive" new_host["installed"] = "False" host_value = str(new_host) config.set("HOSTS", hostname, host_value) writeConfig("New host " + hostname + " saved!")
def uninstallhoneypot(ctx, selected_hosts=None): """ Stop and uninstall a honeypot """ if len(selected_hosts) == 0: selected_hosts = hostselector( "Which host(s) do you want to uninstall a honeypot on?") if len(selected_hosts) == 0: log("No host has been selected.", "red") return all_hosts = hosts() for host in selected_hosts: if host in all_hosts: host_data = hostdata(host) installed = host_data["installed"] if installed == "False": log(host + " did not have an installed honeypot.", "red") continue user = host_data["user"] ip = host_data["ip"] ssh_key = host_data["ssh_key"] status = host_data["status"] ssh_port = host_data["ssh_port"] password = None try: password = prompt( [{ "type": "password", "name": "password", "message": ("Password for " + user + "@" + ip + ":"), }], style=style(), )["password"] except EOFError: log("Action cancelled by user", "red") continue stdout, stderr = subprocess.Popen( [ "deployment/uninstall.sh", ssh_key, ip, user, password, status, ssh_port, ], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ).communicate() output = str(stdout.decode() + stderr.decode()) log(output, "yellow") if "Honeypot uninstalled successfully" in output: host_data["status"] = "inactive" host_data["installed"] = "False" host_value = str(host_data) config.set("HOSTS", host, host_value) writeConfig("The honeypot on " + host + " is now uninstalled.") else: log("The honeypot on " + host + " failed to uninstall.", "red") else: log("Host " + host + " could not be found.", "red")
def installhoneypot(ctx, selected_hosts=None): """ Install a honeypot """ if len(selected_hosts) == 0: selected_hosts = hostselector( "Which host(s) do you want to install a honeypot on?") if len(selected_hosts) == 0: log("No host has been selected.", "red") return tar_file = None try: tar_file = prompt( [{ "type": "input", "name": "tar_file", "message": "Tar File:", "validate": FilePathValidator, }], style=style(), )["tar_file"] except EOFError: log("Action cancelled by user", "red") return all_hosts = hosts() for host in selected_hosts: if host in all_hosts: host_data = hostdata(host) installed = host_data["installed"] if installed == "True": log(host + " already has an installed honeypot.", "red") continue user = host_data["user"] ip = host_data["ip"] ssh_key = host_data["ssh_key"] ssh_port = host_data["ssh_port"] stdout, stderr = subprocess.Popen( [ "deployment/install.sh", ssh_key, ip, user, tar_file, ssh_port ], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ).communicate() output = str(stdout.decode() + stderr.decode()) log(output, "yellow") if "Honeypot installed successfully" in output: host_data["installed"] = "True" host_value = str(host_data) config.set("HOSTS", host, host_value) writeConfig(host + " now has an installed honeypot.") else: log(host + " failed to install a honeypot.", "red") else: log("Host " + host + " could not be found.", "red")