def graphviz(): GV = """ digraph "PoshC2" { subgraph proxy { node [color=white, fontcolor=red, fontsize=15, shapefile="%s/firewall.png"]; "POSHSERVER"; } subgraph implant { node [color=white, fontcolor=white, fontsize=15, shapefile="%s/implant.png"]; IMPLANTHOSTS } subgraph daisy { node [color=white, fontcolor=white, fontsize=15, shapefile="%s/implant.png"]; DAISYHOSTS } } """ % (ImagesDirectory, ImagesDirectory, ImagesDirectory) ServerTAG = "\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPoshC2 Server\\n%s" % PayloadCommsHost.replace( "\"", "") GV = GV.replace("POSHSERVER", ServerTAG) implants = get_implants_all() hosts = "" daisyhosts = "" for implant in implants: if "Daisy" not in implant.Pivot: if implant.Hostname not in hosts: domain = implant.Domain.replace("\\", "\\\\") hosts += "\"%s\" -> \"%s \\n %s\\n\\n\\n\\n \"; \n" % ( ServerTAG, domain, implant.Hostname) else: domain = implant.Domain.replace("\\", "\\\\") if "\"%s\\n\\n\\n\\n \" -> \"%s \\n %s\\n\\n\\n\\n \"; \n" % ( implant.Pivot.replace('\x00', '').replace( "\\", "\\\\").replace('@', ' \\n '), domain, implant.Hostname) not in daisyhosts: daisyhosts += "\"%s\\n\\n\\n\\n \" -> \"%s \\n %s\\n\\n\\n\\n \"; \n" % ( implant.Pivot.replace( '\x00', '').replace("\\", "\\\\").replace( '@', ' \\n '), domain, implant.Hostname) GV = GV.replace("DAISYHOSTS", daisyhosts) GV = GV.replace("IMPLANTHOSTS", hosts) output_file = open("%sPoshC2.dot" % ReportsDirectory, 'w') output_file.write("%s" % GV) output_file.close() subprocess.check_output("dot -T png -o %sPoshC2.png %sPoshC2.dot" % (ReportsDirectory, ReportsDirectory), shell=True) print("") print("GraphViz Generated PoshC2.png") time.sleep(1)
def main(args): httpd = ThreadedHTTPServer((BindIP, BindPort), MyHandler) global new_implant_url, sharpurls, hosted_files, KEY, QuickCommandURI try: if os.name == 'nt': os.system('cls') else: os.system('clear') except Exception: print("cls") print(chr(27) + "[2J") print(Colours.GREEN + logopic) print(Colours.END + "") try: if db_exists(): if len(os.listdir(PoshProjectDirectory)) > 2: existingdb(DatabaseType) else: print(Colours.RED + "[-] Project directory does not exist or is empty \n") print(Colours.RED + "[>] Create new DB and remove dir (%s) \n" % PoshProjectDirectory) sys.exit(1) else: newdb(DatabaseType) except Exception as e: print(str(e)) traceback.print_exc() print(Colours.RED + "[>] Create new DB and remove dir (%s) \n" % PoshProjectDirectory) sys.exit(1) C2 = get_c2server_all() print("" + Colours.GREEN) print("CONNECT URL: " + get_newimplanturl() + Colours.GREEN) print("QUICKCOMMAND URL: " + select_item("QuickCommand", "C2Server") + Colours.GREEN) print("WEBSERVER Log: %swebserver.log" % PoshProjectDirectory) print("") print("PayloadCommsHost: " + select_item("PayloadCommsHost", "C2Server") + Colours.GREEN) print("DomainFrontHeader: " + str(select_item("DomainFrontHeader", "C2Server")) + Colours.GREEN) QuickCommandURI = select_item("QuickCommand", "C2Server") KEY = get_baseenckey() new_implant_url = get_newimplanturl() sharpurls = get_sharpurls().split(",") hosted_files = get_hosted_files() print("") print(time.asctime() + " PoshC2 Server Started - %s:%s" % (BindIP, BindPort)) killdate = datetime.strptime(C2.KillDate, '%Y-%m-%d').date() datedifference = number_of_days(date.today(), killdate) if datedifference < 8: print(Colours.RED + ("\nKill Date is - %s - expires in %s days" % (C2.KillDate, datedifference))) else: print(Colours.GREEN + ("\nKill Date is - %s - expires in %s days" % (C2.KillDate, datedifference))) print(Colours.END) if "https://" in PayloadCommsHost.strip(): if (os.path.isfile("%sposh.crt" % PoshProjectDirectory)) and (os.path.isfile("%sposh.key" % PoshProjectDirectory)): try: httpd.socket = ssl.wrap_socket(httpd.socket, keyfile="%sposh.key" % PoshProjectDirectory, certfile="%sposh.crt" % PoshProjectDirectory, server_side=True, ssl_version=ssl.PROTOCOL_TLS) except Exception: httpd.socket = ssl.wrap_socket(httpd.socket, keyfile="%sposh.key" % PoshProjectDirectory, certfile="%sposh.crt" % PoshProjectDirectory, server_side=True, ssl_version=ssl.PROTOCOL_TLSv1) else: raise ValueError("Cannot find the certificate files") c2_message_thread = threading.Thread(target=log_c2_messages, daemon=True) c2_message_thread.start() try: httpd.serve_forever() except (KeyboardInterrupt, EOFError): httpd.server_close() print(time.asctime() + " PoshC2 Server Stopped - %s:%s" % (BindIP, BindPort)) sys.exit(0)