2022-07-18 23:59:14 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2016-12-15 07:28:00 +00:00
import argparse
import sys
from argparse import RawTextHelpFormatter
2023-09-14 21:07:15 +00:00
from nxc . loaders . protocolloader import ProtocolLoader
from nxc . helpers . logger import highlight
2020-11-16 20:21:41 +00:00
from termcolor import colored
2023-09-14 21:07:15 +00:00
from nxc . logger import nxc_logger
2023-07-13 23:29:30 +00:00
import importlib . metadata
2016-12-15 07:28:00 +00:00
2023-03-27 04:48:45 +00:00
2016-12-15 07:28:00 +00:00
def gen_cli_args ( ) :
2023-09-14 21:07:15 +00:00
VERSION = importlib . metadata . version ( " netexec " )
CODENAME = " A New Beginning "
2016-12-15 07:28:00 +00:00
2020-11-16 20:21:41 +00:00
parser = argparse . ArgumentParser ( description = f """
2023-09-14 21:07:15 +00:00
_ _ _ _____
| \ | | ___ | | _ | ____ | __ __ ___ ___
| \| | / _ \ | __ | | _ | \ \/ / / _ \ / __ |
| | \ | | __ / | | _ | | ___ > < | __ / | ( __
| _ | \_ | \___ | \__ | | _____ | / _ / \_ \ \___ | \___ |
The network execution tool
Maintained as an open source project by @NeffIsBack , @MJHallenbeck , @_zblurx
For documentation and usage examples , visit : https : / / www . netexec . wiki /
{ highlight ( ' Version ' , ' red ' ) } : { highlight ( VERSION ) }
{ highlight ( ' Codename ' , ' red ' ) } : { highlight ( CODENAME ) }
""" ,
2023-05-02 15:17:59 +00:00
formatter_class = RawTextHelpFormatter ,
)
parser . add_argument (
" -t " ,
type = int ,
dest = " threads " ,
default = 100 ,
help = " set how many concurrent threads to use (default: 100) " ,
)
parser . add_argument (
" --timeout " ,
default = None ,
type = int ,
help = " max timeout in seconds of each thread (default: None) " ,
)
parser . add_argument (
" --jitter " ,
metavar = " INTERVAL " ,
type = str ,
help = " sets a random delay between each connection (default: None) " ,
)
parser . add_argument (
" --no-progress " ,
action = " store_true " ,
help = " Not displaying progress bar during scan " ,
)
2023-05-01 01:00:55 +00:00
parser . add_argument ( " --verbose " , action = " store_true " , help = " enable verbose output " )
2023-05-08 18:39:36 +00:00
parser . add_argument ( " --debug " , action = " store_true " , help = " enable debug level information " )
2023-09-14 21:07:15 +00:00
parser . add_argument ( " --version " , action = " store_true " , help = " Display nxc version " )
2016-12-15 07:28:00 +00:00
2023-05-31 13:55:09 +00:00
# we do module arg parsing here so we can reference the module_list attribute below
module_parser = argparse . ArgumentParser ( add_help = False )
mgroup = module_parser . add_mutually_exclusive_group ( )
mgroup . add_argument ( " -M " , " --module " , action = " append " , metavar = " MODULE " , help = " module to use " )
module_parser . add_argument (
" -o " ,
metavar = " MODULE_OPTION " ,
nargs = " + " ,
default = [ ] ,
dest = " module_options " ,
help = " module options " ,
)
module_parser . add_argument ( " -L " , " --list-modules " , action = " store_true " , help = " list available modules " )
module_parser . add_argument (
" --options " ,
dest = " show_module_options " ,
action = " store_true " ,
help = " display module options " ,
)
module_parser . add_argument (
" --server " ,
choices = { " http " , " https " } ,
default = " https " ,
help = " use the selected server (default: https) " ,
)
module_parser . add_argument (
" --server-host " ,
type = str ,
default = " 0.0.0.0 " ,
metavar = " HOST " ,
help = " IP to bind the server to (default: 0.0.0.0) " ,
)
module_parser . add_argument (
" --server-port " ,
metavar = " PORT " ,
type = int ,
help = " start the server on the specified port " ,
)
module_parser . add_argument (
" --connectback-host " ,
type = str ,
metavar = " CHOST " ,
help = " IP for the remote system to connect back to (default: same as server-host) " ,
)
2023-05-08 18:39:36 +00:00
subparsers = parser . add_subparsers ( title = " protocols " , dest = " protocol " , description = " available protocols " )
2016-12-15 07:28:00 +00:00
std_parser = argparse . ArgumentParser ( add_help = False )
2023-05-02 15:17:59 +00:00
std_parser . add_argument (
" target " ,
2023-07-14 11:12:20 +00:00
nargs = " + " if not ( module_parser . parse_known_args ( ) [ 0 ] . list_modules or module_parser . parse_known_args ( ) [ 0 ] . show_module_options ) else " * " ,
2023-05-02 15:17:59 +00:00
type = str ,
help = " the target IP(s), range(s), CIDR(s), hostname(s), FQDN(s), file(s) containing a list of targets, NMap XML or .Nessus file(s) " ,
)
std_parser . add_argument (
" -id " ,
metavar = " CRED_ID " ,
nargs = " + " ,
default = [ ] ,
type = str ,
dest = " cred_id " ,
help = " database credential ID(s) to use for authentication " ,
)
std_parser . add_argument (
" -u " ,
metavar = " USERNAME " ,
dest = " username " ,
nargs = " + " ,
default = [ ] ,
help = " username(s) or file(s) containing usernames " ,
)
std_parser . add_argument (
" -p " ,
metavar = " PASSWORD " ,
dest = " password " ,
nargs = " + " ,
default = [ ] ,
help = " password(s) or file(s) containing passwords " ,
)
2023-09-21 10:36:04 +00:00
std_parser . add_argument ( " --ignore-pw-decoding " , action = " store_true " , help = " Ignore non UTF-8 characters when decoding the password file " )
2023-05-08 18:39:36 +00:00
std_parser . add_argument ( " -k " , " --kerberos " , action = " store_true " , help = " Use Kerberos authentication " )
2023-05-02 11:30:32 +00:00
std_parser . add_argument ( " --no-bruteforce " , action = " store_true " , help = " No spray when using file for username and password (user1 => password1, user2 => password2 " )
std_parser . add_argument ( " --continue-on-success " , action = " store_true " , help = " continues authentication attempts even after successes " )
2023-05-02 15:17:59 +00:00
std_parser . add_argument (
" --use-kcache " ,
action = " store_true " ,
help = " Use Kerberos authentication from ccache file (KRB5CCNAME) " ,
)
2023-05-08 18:39:36 +00:00
std_parser . add_argument ( " --log " , metavar = " LOG " , help = " Export result into a custom file " )
2023-05-02 15:17:59 +00:00
std_parser . add_argument (
" --aesKey " ,
metavar = " AESKEY " ,
nargs = " + " ,
help = " AES key to use for Kerberos Authentication (128 or 256 bits) " ,
)
std_parser . add_argument (
" --kdcHost " ,
metavar = " KDCHOST " ,
help = " FQDN of the domain controller. If omitted it will use the domain part (FQDN) specified in the target parameter " ,
)
2020-05-04 17:22:10 +00:00
2016-12-15 07:28:00 +00:00
fail_group = std_parser . add_mutually_exclusive_group ( )
2023-05-02 15:17:59 +00:00
fail_group . add_argument (
" --gfail-limit " ,
metavar = " LIMIT " ,
type = int ,
help = " max number of global failed login attempts " ,
)
fail_group . add_argument (
" --ufail-limit " ,
metavar = " LIMIT " ,
type = int ,
help = " max number of failed login attempts per username " ,
)
fail_group . add_argument (
" --fail-limit " ,
metavar = " LIMIT " ,
type = int ,
help = " max number of failed login attempts per host " ,
)
2016-12-15 07:28:00 +00:00
2023-05-27 18:52:28 +00:00
p_loader = ProtocolLoader ( )
protocols = p_loader . get_protocols ( )
2016-12-15 07:28:00 +00:00
for protocol in protocols . keys ( ) :
2023-05-27 18:52:28 +00:00
try :
protocol_object = p_loader . load_protocol ( protocols [ protocol ] [ " argspath " ] )
subparsers = protocol_object . proto_args ( subparsers , std_parser , module_parser )
except :
2023-09-14 21:07:15 +00:00
nxc_logger . exception ( f " Error loading proto_args from proto_args.py file in protocol folder: { protocol } " )
2016-12-15 07:28:00 +00:00
if len ( sys . argv ) == 1 :
parser . print_help ( )
sys . exit ( 1 )
args = parser . parse_args ( )
2023-05-31 14:16:35 +00:00
if args . version :
2023-05-31 14:18:18 +00:00
print ( f " { VERSION } - { CODENAME } " )
2023-05-31 14:16:35 +00:00
sys . exit ( 1 )
2016-12-15 07:28:00 +00:00
return args