NetExec/nxc/first_run.py

58 lines
2.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from os import mkdir
from os.path import exists
from os.path import join as path_join
import shutil
2023-09-20 04:09:25 +00:00
from nxc.paths import NXC_PATH, CONFIG_PATH, TMP_PATH, DATA_PATH
from nxc.nxcdb import initialize_db
from nxc.logger import nxc_logger
2018-03-01 19:36:17 +00:00
def first_run_setup(logger=nxc_logger):
if not exists(TMP_PATH):
mkdir(TMP_PATH)
2023-09-20 04:09:25 +00:00
if not exists(NXC_PATH):
2023-05-02 15:17:59 +00:00
logger.display("First time use detected")
logger.display("Creating home directory structure")
2023-09-20 04:09:25 +00:00
mkdir(NXC_PATH)
2017-03-27 21:09:36 +00:00
folders = (
2023-05-02 15:17:59 +00:00
"logs",
"modules",
"protocols",
"workspaces",
"obfuscated_scripts",
"screenshots",
)
2017-03-27 21:09:36 +00:00
for folder in folders:
2023-09-20 04:09:25 +00:00
if not exists(path_join(NXC_PATH, folder)):
logger.display(f"Creating missing folder {folder}")
2023-09-20 04:09:25 +00:00
mkdir(path_join(NXC_PATH, folder))
initialize_db(logger)
if not exists(CONFIG_PATH):
2023-05-02 15:17:59 +00:00
logger.display("Copying default configuration file")
default_path = path_join(DATA_PATH, "nxc.conf")
2023-09-20 04:09:25 +00:00
shutil.copy(default_path, NXC_PATH)
# if not exists(CERT_PATH):
# logger.display('Generating SSL certificate')
2023-01-02 11:55:03 +00:00
# try:
# check_output(['openssl', 'help'], stderr=PIPE)
# if os.name != 'nt':
# os.system('openssl req -new -x509 -keyout {path} -out {path} -days 365 -nodes -subj "/C=US" > /dev/null 2>&1'.format(path=CERT_PATH))
# else:
# os.system('openssl req -new -x509 -keyout {path} -out {path} -days 365 -nodes -subj "/C=US"'.format(path=CERT_PATH))
# except OSError as e:
# if e.errno == errno.ENOENT:
# logger.error('OpenSSL command line utility is not installed, could not generate certificate, using default certificate')
# default_path = path_join(DATA_PATH, 'default.pem')
2023-05-02 15:17:59 +00:00
# shutil.copy(default_path, CERT_PATH)
2023-01-02 11:55:03 +00:00
# else:
# logger.error('Error while generating SSL certificate: {}'.format(e))
# sys.exit(1)