Restructured configuration management such that configuration files are stored in the default user configuration directory for the OS they're using, utilising appdirs

This commit is contained in:
Samuel Dowling 2020-04-12 18:18:01 +09:30
parent c5fd182909
commit ef1b44ff4b
3 changed files with 161 additions and 6 deletions

138
.gitignore vendored Normal file
View File

@ -0,0 +1,138 @@
# Byte-compiled / optimized / DLL files
*__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/

View File

@ -23,6 +23,8 @@ import sys
import time
import toml
import termios
import appdirs
import shutil
def _quit():
termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, TERM_FLAGS)
@ -30,13 +32,30 @@ def _quit():
atexit.register(_quit)
TERM_FLAGS = termios.tcgetattr(sys.stdin.fileno())
appname = 'AutoRecon'
verbose = 0
nmap = '-vv --reason -Pn'
srvname = ''
heartbeat_interval = 60
port_scan_profile = None
rootdir = os.path.dirname(os.path.realpath(__file__))
default_config_dir = os.path.join(rootdir, 'config')
config_dir = appdirs.user_config_dir(appname)
port_scan_profiles_config_file = os.path.join(config_dir, 'port-scan-profiles.toml')
service_scans_config_file = os.path.join(config_dir, 'service-scans.toml')
global_patterns_config_file = os.path.join(config_dir, 'global-patterns.toml')
# Confirm this directory exists; if not, populate it with the default configurations
if not os.path.exists(config_dir):
os.makedirs(config_dir)
shutil.copy(os.path.join(default_config_dir,'port-scan-profiles-default.toml'), port_scan_profiles_config_file)
shutil.copy(os.path.join(default_config_dir,'service-scans-default.toml'), service_scans_config_file)
shutil.copy(os.path.join(default_config_dir,'global-patterns-default.toml'), global_patterns_config_file)
port_scan_profiles_config = None
service_scans_config = None
global_patterns = []
@ -44,7 +63,6 @@ global_patterns = []
username_wordlist = '/usr/share/seclists/Usernames/top-usernames-shortlist.txt'
password_wordlist = '/usr/share/seclists/Passwords/darkweb2017-top100.txt'
rootdir = os.path.dirname(os.path.realpath(__file__))
single_target = False
only_scans_dir = False
@ -146,8 +164,7 @@ def calculate_elapsed_time(start_time):
return ', '.join(elapsed_time)
port_scan_profiles_config_file = 'port-scan-profiles-default.toml'
with open(os.path.join(rootdir, 'config', port_scan_profiles_config_file), 'r') as p:
with open(port_scan_profiles_config_file, 'r') as p:
try:
port_scan_profiles_config = toml.load(p)
@ -157,13 +174,13 @@ with open(os.path.join(rootdir, 'config', port_scan_profiles_config_file), 'r')
except toml.decoder.TomlDecodeError as e:
fail('Error: Couldn\'t parse {port_scan_profiles_config_file} config file. Check syntax and duplicate tags.')
with open(os.path.join(rootdir, 'config', 'service-scans-default.toml'), 'r') as c:
with open(service_scans_config_file, 'r') as c:
try:
service_scans_config = toml.load(c)
except toml.decoder.TomlDecodeError as e:
fail('Error: Couldn\'t parse service-scans.toml config file. Check syntax and duplicate tags.')
with open(os.path.join(rootdir, 'config', 'global-patterns-default.toml'), 'r') as p:
with open(global_patterns_config_file, 'r') as p:
try:
global_patterns = toml.load(p)
if 'pattern' in global_patterns: