diff --git a/lib/cuckoo/core/data/tasking.py b/lib/cuckoo/core/data/tasking.py index 5e827c21542..d40990a64ce 100644 --- a/lib/cuckoo/core/data/tasking.py +++ b/lib/cuckoo/core/data/tasking.py @@ -215,14 +215,17 @@ def add( task.route = route task.cape = cape task.tags_tasks = tags_tasks + + # Use a nested transaction so that we can return an ID. + with self.session.begin_nested(): + self.session.add(task) + self.session.flush() + # Deal with tags format (i.e., foo,bar,baz) if tags: for tag in tags.split(","): tag_name = tag.strip() if tag_name and tag_name not in [tag.name for tag in task.tags]: - # "Task" object is being merged into a Session along the backref cascade path for relationship "Tag.tasks"; in SQLAlchemy 2.0, this reverse cascade will not take place. - # Set cascade_backrefs to False in either the relationship() or backref() function for the 2.0 behavior; or to set globally for the whole Session, set the future=True flag - # (Background on this error at: https://sqlalche.me/e/14/s9r1) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9) task.tags.append(self._get_or_create(Tag, name=tag_name)) if clock: @@ -248,10 +251,6 @@ def add( ) self.session.add(association) - # Use a nested transaction so that we can return an ID. - with self.session.begin_nested(): - self.session.add(task) - return task.id def add_path( diff --git a/utils/gcp_pubsub_service.py b/utils/gcp_pubsub_service.py index 440f7c1b1db..8fcb555ef82 100644 --- a/utils/gcp_pubsub_service.py +++ b/utils/gcp_pubsub_service.py @@ -112,6 +112,7 @@ def process_message(self, message): options=sandbox_options, custom=custom, category=category, + filename=sample_name, ) if task_ids: log.info("Successfully submitted task(s): %s", task_ids) diff --git a/utils/submit.py b/utils/submit.py index d8bae23ab1b..5388ffb217c 100644 --- a/utils/submit.py +++ b/utils/submit.py @@ -47,6 +47,7 @@ def submit_file( unique=False, quiet=False, category = None, + filename = None, ): if not File(file_path).get_size(): if not quiet: @@ -64,7 +65,9 @@ def submit_file( try: with open(file_path, "rb") as f: - tmp_path = store_temp_file(f.read(), sanitize_filename(os.path.basename(file_path))) + if not filename: + filename = os.path.basename(file_path) + tmp_path = store_temp_file(f.read(), sanitize_filename(filename)) with db.session.begin(): # ToDo expose extra_details["errors"] task_ids, extra_details = db.demux_sample_and_add_to_db( @@ -167,10 +170,9 @@ def main(): parser.add_argument( "--shuffle", action="store_true", default=False, help="Shuffle samples before submitting them", required=False ) - parser.add_argument( - "--unique", action="store_true", default=False, help="Only submit new samples, ignore duplicates", required=False - ) + parser.add_argument("--unique", action="store_true", default=False, help="Only submit new samples, ignore duplicates", required=False) parser.add_argument("--quiet", action="store_true", default=False, help="Only print text on failure", required=False) + parser.add_argument("--name", type=str, action="store", default=None, help="Desired sample name", required=False) parser.add_argument("--procdump", action="store_true", default=False, help="Disable process dumps", required=False) try: @@ -339,7 +341,8 @@ def main(): url = "http://{0}/apiv2/tasks/create/file/".format(args.remote) with open(file_path, "rb") as f: - files = dict(file=f, filename=os.path.basename(file_path)) + filename = args.name or os.path.basename(file_path) + files = dict(file=f, filename=filename) data = dict( package=args.package, @@ -411,6 +414,7 @@ def main(): route=args.route, unique=args.unique, quiet=args.quiet, + filename=args.name, ) tasks_count = len(task_ids) diff --git a/web/templates/submission/index.html b/web/templates/submission/index.html index e8499ec20f1..93d451b45f7 100644 --- a/web/templates/submission/index.html +++ b/web/templates/submission/index.html @@ -922,9 +922,9 @@
Advance {% if config.tlp %} @@ -932,10 +932,10 @@
Advance {% endif %} @@ -1177,6 +1177,24 @@
Advance }; interactive.addEventListener("change", syncManualCheckbox); } + + // Color sync for Priority and TLP + function updateSelectColor(selectId) { + const select = $(selectId); + const selectedOption = select.find('option:selected'); + const color = selectedOption.data('color'); + if (color) { + select.css('color', color); + } + } + + $('#form_priority, #form_tlp').on('change', function() { + updateSelectColor('#' + $(this).attr('id')); + }); + + // Initialize colors + updateSelectColor('#form_priority'); + updateSelectColor('#form_tlp'); }); {% endblock %}