kevoreilly / CAPEv2

Malware Configuration And Payload Extraction
https://capesandbox.com/analysis/
Other
1.84k stars 398 forks source link

session.add(machine) in database.py unlock_machine function causes analysis to fail. #2225

Closed Cassandra-Fu closed 3 weeks ago

Cassandra-Fu commented 1 month ago

About accounts on capesandbox.com

This is open source and you are getting free support so be friendly!

Prerequisites

Please answer the following questions for yourself before submitting an issue.

Expected Behavior

Analysis is supposed to be completed.

Current Behavior

Analysis fails and then became inaccurate.

Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Pulled current repo
  2. submit sample analysis
  3. Analysis status is completed but the analysis report is not returned as the task is not released from machine.

Context

I tried to setup on a Ubuntu 22.04 machine and it worked but the when i tried to submit a sample for analysis, I received an error below which came from the unlock machine function. Apparently the session.add line is causing a race condition. As a result the analysis fails when the status is complete.: image

Once way I tried to fix the issue was by commenting out the session.add line in lock_machine and it worked but I had to restart my cape server everytime I start another analysis because the analysis machine was still locked to the previous task. image

I then reset up a cleaned version of cape but cloned from the flare_capa_7 branch so the error is fixed because of it was using the working version of the database.py file. But then the results for a bumblebee sample i used for testing the setup changed from this: image

to this (on the new setup): image

Is it possible to revert the database.py to before session.add was used to unlock the machine ?

Question Answer
Git commit Type $ git log \| head -n1 to find out
OS version Ubuntu 22.04, win10 21H2 (for analysis machine)

Failure Logs

Please include any relevant log snippets or files here.

Cassandra-Fu commented 1 month ago

Here is a clearer picture of the original error image

doomedraven commented 1 month ago

Hey what version of sqlachemy do you have?

Cassandra-Fu commented 1 month ago

sqlalchemy version 1.4.50 image

doomedraven commented 1 month ago

@tbeadle just for sync, do we miss with self.session.begin_nested(): here https://github.com/kevoreilly/CAPEv2/edit/master/lib/cuckoo/core/database.py#971? i don't think so, but just in case to sync

tbeadle commented 1 month ago

@Cassandra-Fu could you please enable the "log_statements" config item in the [database] section of cuckoo.conf, restart the cape-scheduler, and re-run the analysis? Then, attach the resulting logs from cape-scheduler.

Cassandra-Fu commented 1 month ago

image

These are the logs I received on my end.

tbeadle commented 1 month ago

That is only the query for getting a pending task. I'm going to need much more than that. In particular, I'll need to see from this point up until you get the error.

Cassandra-Fu commented 1 month ago

I managed to resolve the problem by reverting to commit e89be36522a21b184b69fb446ecd2ceb211f5a79.

ChrisThibodeaux commented 1 month ago

Thank you for the update. I've been trying to trace down odd sqalchemy issues for three days. I will give that commit a shot!

Edit: Oh boy, that is a bit farther back than I thought. Dang.

doomedraven commented 3 weeks ago

well i can't reproduce it and as the author of the issue didn't provide info to try to fix it and just reverted to some "random" commit, closing it