From 7071d44d874c44bf3796ec75d3b646857444ec1f Mon Sep 17 00:00:00 2001 From: pUrGe12 Date: Sat, 14 Mar 2026 02:33:55 +0530 Subject: [PATCH 1/5] forced file uploads instead of referencing on the server side --- nettacker/api/engine.py | 41 +++++++++++++++++++++++++++++++++ nettacker/config.py | 1 + nettacker/locale/en.yaml | 6 ++++- nettacker/web/static/index.html | 24 ++++++++++++++++++- nettacker/web/static/js/main.js | 27 ++++++++++++++++++++++ 5 files changed, 97 insertions(+), 2 deletions(-) diff --git a/nettacker/api/engine.py b/nettacker/api/engine.py index 817673f61..e4f0f253d 100644 --- a/nettacker/api/engine.py +++ b/nettacker/api/engine.py @@ -5,6 +5,7 @@ import random import string import time +import uuid from threading import Thread from types import SimpleNamespace @@ -50,6 +51,11 @@ app = Flask(__name__, template_folder=str(Config.path.web_static_dir)) app.config.from_object(__name__) +app.config["MAX_CONTENT_LENGTH"] = ( + 10 * 1024 * 1024 +) # https://flask.palletsprojects.com/en/stable/patterns/fileuploads/ +FILE_UPLOAD_PARAMS = ("targets_list", "passwords_list", "usernames_list", "read_from_file") +uploaded_files = {} nettacker_path_config = Config.path nettacker_application_config = Config.settings.as_dict() @@ -236,6 +242,35 @@ def sanitize_report_path_filename(report_path_filename): return safe_report_path +def allowed_file(filename): + return ( + "." in filename + and filename.rsplit(".", 1)[1].lower() in Config.settings.allowed_upload_extensions + ) + + +@app.route("/upload/file", methods=["POST"]) +def upload_file(): + api_key_is_valid(app, flask_request) + param_name = get_value(flask_request, "param_name") + if "file" not in flask_request.files: + return jsonify(structure(status="error", msg=_("upload_no_file"))), 400 + uploaded = flask_request.files["file"] + if uploaded.filename == "": + return jsonify(structure(status="error", msg=_("upload_no_file_selected"))), 400 + if not allowed_file(uploaded.filename): + return jsonify(structure(status="error", msg=_("upload_file_type_not_allowed"))), 400 + filename = secure_filename(uploaded.filename) + if not filename: + return jsonify(structure(status="error", msg=_("upload_invalid_filename"))), 400 + unique_name = f"{uuid.uuid4().hex}_{filename}" + tmp_dir = nettacker_path_config.tmp_dir + tmp_dir.mkdir(parents=True, exist_ok=True) + uploaded.save(str(tmp_dir / unique_name)) + uploaded_files[param_name] = str(tmp_dir / unique_name) + return jsonify(structure(status="ok", msg=unique_name)), 200 + + @app.route("/new/scan", methods=["GET", "POST"]) def new_scan(): """ @@ -253,6 +288,12 @@ def new_scan(): if not report_path_filename: return jsonify(structure(status="error", msg="Invalid report filename")), 400 form_values["report_path_filename"] = str(report_path_filename) + + # Ensuring that these parameters cannot be set by the user without a file upload + for key in FILE_UPLOAD_PARAMS: + form_values.pop(key, None) + form_values.update(uploaded_files) + for key in nettacker_application_config: if key not in form_values: form_values[key] = nettacker_application_config[key] diff --git a/nettacker/config.py b/nettacker/config.py index f05730213..f5bf061f0 100644 --- a/nettacker/config.py +++ b/nettacker/config.py @@ -190,6 +190,7 @@ class DefaultSettings(ConfigBase): verbose_mode = False scan_compare_id = None compare_report_path_filename = "" + allowed_upload_extensions = ("txt", "csv", "lst", "list") class Config: diff --git a/nettacker/locale/en.yaml b/nettacker/locale/en.yaml index 5b60b92d1..a9d7b661b 100644 --- a/nettacker/locale/en.yaml +++ b/nettacker/locale/en.yaml @@ -140,4 +140,8 @@ report_retrieval_fail: Could not retrieve the report read_report_fail: Failed to read report file {0} search_results_end: No more search results database_error: Database error! -error_exclude_all: "Cannot exclude all modules. Please specify individual module names to exclude using -x." \ No newline at end of file +error_exclude_all: "Cannot exclude all modules. Please specify individual module names to exclude using -x." +upload_no_file: no file provided +upload_no_file_selected: no file selected +upload_invalid_filename: invalid filename +upload_file_type_not_allowed: file type not allowed \ No newline at end of file diff --git a/nettacker/web/static/index.html b/nettacker/web/static/index.html index 7205802fd..d1ac453cc 100644 --- a/nettacker/web/static/index.html +++ b/nettacker/web/static/index.html @@ -162,6 +162,10 @@

Targets

+ +

+

Usernames

+ +

Passwords

+ + +
+
+
+

Wordlist

+ +

+

-