Example #1
0
def main(args):
    signal.signal(signal.SIGINT, catch_exit)
    user = None
    autohide = None
    if len(args) > 0:
        parser = argparse.ArgumentParser(
            description='The command line for handling implants in PoshC2')
        parser.add_argument('-u', '--user', help='the user for this session')
        parser.add_argument(
            '-a',
            '--autohide',
            help='to autohide implants after 30 inactive beacons',
            action='store_true')
        args = parser.parse_args(args)
        user = args.user
        autohide = args.autohide
    while not user:
        print(Colours.GREEN + "A username is required for logging")
        user = input("Enter your username: "******"sqlite" and not os.path.isfile(Database):
        print(Colours.RED + "The project database has not been created yet")
        sys.exit()
    database_connect()
    new_c2_message("%s logged on." % user)
    clear()
    implant_handler_command_loop(user, "", autohide)
Example #2
0
from poshc2.Colours import Colours
from poshc2.server.AutoLoads import check_module_loaded, run_autoloads_sharp
from poshc2.client.Help import sharp_help1
from poshc2.server.Config import PoshInstallDirectory, PoshProjectDirectory, SocksHost, PayloadsDirectory, ModulesDirectory, DatabaseType
from poshc2.server.Config import PayloadCommsHost, DomainFrontHeader, UserAgent
from poshc2.Utils import argp, load_file, gen_key
from poshc2.server.Core import print_bad, print_good
from poshc2.client.cli.CommandPromptCompleter import FilePathCompleter
from poshc2.server.Payloads import Payloads
from prompt_toolkit import PromptSession
from prompt_toolkit.history import FileHistory
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.styles import Style


if DatabaseType.lower() == "postgres":
    from poshc2.server.database.DBPostgres import new_task, kill_implant, get_implantdetails, get_sharpurls
    from poshc2.server.database.DBPostgres import select_item, update_label, get_allurls, get_c2server_all, get_newimplanturl, new_urldetails
else:
    from poshc2.server.database.DBSQLite import new_task, kill_implant, get_implantdetails, get_sharpurls
    from poshc2.server.database.DBSQLite import select_item, update_label, get_allurls, get_c2server_all, get_newimplanturl, new_urldetails


def handle_sharp_command(command, user, randomuri, implant_id):

    # alias mapping
    for alias in cs_alias:
        if alias[0] == command[:len(command.rstrip())]:
            command = alias[1]

    # alias replace
Example #3
0
def main(args):
    httpd = ThreadedHTTPServer((BindIP, BindPort), MyHandler)

    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 + "")

    if DatabaseType.lower() == "postgres":
        try:
            if get_db() > 0:
                if len(os.listdir(PoshProjectDirectory)) > 2:
                    existingdb("postgres")
                else:
                    print(
                        Colours.RED +
                        "[-] Project directory does not exist or is empty \n")
                    print(Colours.RED +
                          "[>] Create new postgres DB and remove dir (%s) \n" %
                          PoshProjectDirectory)
                    sys.exit(1)
            else:
                newdb("postgres")
        except Exception as e:
            print(e)
            traceback.print_exc()
            print(Colours.RED +
                  "[>] Create new postgres DB and remove dir (%s) \n" %
                  PoshProjectDirectory)
            sys.exit(1)
    elif os.path.isfile(Database):
        if len(os.listdir(PoshProjectDirectory)) > 2:
            existingdb("sqlite")
        else:
            print(Colours.RED +
                  "[-] Project directory does not exist (%s) \n" %
                  PoshProjectDirectory)
            sys.exit(1)
    else:
        newdb("sqlite")

    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)
    global KEY
    KEY = get_baseenckey()
    print("")
    print(time.asctime() + " PoshC2 Server Started - %s:%s" %
          (BindIP, BindPort))
    from datetime import date, datetime
    killdate = datetime.strptime(C2[5], '%d/%m/%Y').date()
    datedifference = number_of_days(date.today(), killdate)
    if datedifference < 8:
        print(Colours.RED + ("\nKill Date is - %s - expires in %s days" %
                             (C2[5], datedifference)))
    else:
        print(Colours.GREEN + ("\nKill Date is - %s - expires in %s days" %
                               (C2[5], 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)