Skip to content

Conversation

@spoiicy
Copy link
Member

@spoiicy spoiicy commented Nov 29, 2024

Closes #2496

Description

Added MobSF_Service analyzer

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist

  • I have read and understood the rules about how to Contribute to this project
  • The pull request is for the branch develop
  • A new plugin (analyzer, connector, visualizer, playbook, pivot or ingestor) was added or changed, in which case:
    • I strictly followed the documentation "How to create a Plugin"
    • Usage file was updated.
    • Advanced-Usage was updated (in case the plugin provides additional optional configuration).
    • I have dumped the configuration from Django Admin using the dumpplugin command and added it in the project as a data migration. ("How to share a plugin with the community")
    • If a File analyzer was added and it supports a mimetype which is not already supported, you added a sample of that type inside the archive test_files.zip and you added the default tests for that mimetype in test_classes.py.
    • If you created a new analyzer and it is free (does not require any API key), please add it in the FREE_TO_USE_ANALYZERS playbook by following this guide.
    • Check if it could make sense to add that analyzer/connector to other freely available playbooks.
    • I have provided the resulting raw JSON of a finished analysis and a screenshot of the results.
    • If the plugin interacts with an external service, I have created an attribute called precisely url that contains this information. This is required for Health Checks.
    • If the plugin requires mocked testing, _monkeypatch() was used in its class to apply the necessary decorators.
    • I have added that raw JSON sample to the MockUpResponse of the _monkeypatch() method. This serves us to provide a valid sample for testing.
  • If external libraries/packages with restrictive licenses were used, they were added in the Legal Notice section.
  • Linters (Black, Flake, Isort) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.
  • I have added tests for the feature/bug I solved (see tests folder). All the tests (new and old ones) gave 0 errors.
  • If changes were made to an existing model/serializer/view, the docs were updated and regenerated (check CONTRIBUTE.md).
  • If the GUI has been modified:
    • I have a provided a screenshot of the result in the PR.
    • I have created new frontend tests for the new component or updated existing ones.
  • After you had submitted the PR, if DeepSource, Django Doctors or other third-party linters have triggered any alerts during the CI checks, I have solved those alerts.

Important Rules

  • If you miss to compile the Checklist properly, your PR won't be reviewed by the maintainers.
  • Everytime you make changes to the PR and you think the work is done, you should explicitly ask for a review. After being reviewed and received a "change request", you should explicitly ask for a review again once you have made the requested changes.

@spoiicy spoiicy marked this pull request as ready for review November 29, 2024 10:11
@spoiicy
Copy link
Member Author

spoiicy commented Nov 29, 2024

Screenshot 2024-11-29 at 3 41 34 PM Attached is the screenshot for the MobSF_Service report and below is the full JSON report containing results for static & dynamic analysis. [job#38_report.json](https://github.com/user-attachments/files/17957663/job.38_report.json)

@spoiicy
Copy link
Member Author

spoiicy commented Nov 29, 2024

@mlodic Could you please re-run the workflow since the backend-test CI has failed for some reason. It was passing in the previous commit 574808c

Copy link
Member

@mlodic mlodic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR!

Comment on lines 27 to 30
"supported_filetypes": [
"application/vnd.android.package-archive",
"application/zip",
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use this list for android:

application/java-archive
application/vnd.android.package-archive
application/x-dex
application/zip

"health_check_status": True,
"type": "file",
"docker_based": False,
"maximum_tlp": "RED",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if you should have control of the MOBSF Instance, it is still an external service so by definition this should be AMBER

get_runtime_dependency_response.raise_for_status()

stop_dynamic_analysis = requests.post(
url=self.mobsf_host + "/api/v1/dynamic/stop_analysis",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you suggested, dynamic analysis time is debatable. This is the reason why I think we should add here a sleep and that this should be a parameter of the analyzer. Which default? 20-30 seconds? What do you think about?

Copy link
Member Author

@spoiicy spoiicy Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I commented here, wouldn't just configuring the soft-time limit do the trick. Because if I keep it at default value 60, "SoftTimeLimitExceeded" error is thrown and my job fails. I had to set it to 400 in order for my job to be successful. Let me know what you think!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that no sleep was added so basically the analysis has a really brief duration time, just the time needed to execute all the steps between the calls "start" and "stop". As mentioned, I would add a sleep between the "start" and the later calls, to allow time for the stuff to start properly and the code loaded and maybe to allow the malware to do some nasty things too.

Comment on lines 58 to 60
"default_hooks": "api_monitor,ssl_pinning_bypass,root_bypass,debugger_check_bypass",
"auxiliary_hooks": "",
"frida_code": "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 3 values should be parameters of the analyzer. In that way the users can choose how to leverage dynamic analysis as they wish

@spoiicy spoiicy marked this pull request as draft December 14, 2024 22:46
@spoiicy spoiicy marked this pull request as ready for review December 14, 2024 22:58
@spoiicy
Copy link
Member Author

spoiicy commented Dec 14, 2024

Hi @mlodic I've made the changes as per your comments. I hope we are good to go, let me know otherwise. :)

url=scan_url, data=data, headers=headers, timeout=self.timeout
)
scan_response.raise_for_status()
logger.info("Static analysis completed successfully")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am bothering about logs because they are really critical in terms of maintenance and debugging so I have other tweaks to ask you :). Here, there is a log without any dynamic variable. It would be very difficult to use in practice because you cannot distinguish it between other logs from other runs. Always add a reference to the file hash.

scan_response.raise_for_status()
logger.info("Static analysis completed successfully")

logger.info("Generating JSON Report for static analysis")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can merge this log with the previous one because they are one next to other so they make sense to be the same log

@spoiicy
Copy link
Member Author

spoiicy commented Dec 17, 2024

@mlodic The PR is ready for review :)

Copy link
Member

@mlodic mlodic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to ask you other stuff to have this PR accepted. Some standards needs to be followed:

  • a PR against the documentation repository has been added? Please do that following the checklist and add a link to that PR here.
  • the static_analysis and dynamic_analysis functions are really difficult to read and they contain a lot or redundant code. I ask you to refactor that code in a way that there is an helper method that executes all of the requests stuff

"name": "MobSF_Service",
"description": "[MobSF_service](https://github.com/MobSF/Mobile-Security-Framework-MobSF) can be used for a variety of use cases such as mobile application security, penetration testing, malware analysis, and privacy analysis.",
"disabled": False,
"soft_time_limit": 400,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned in a previous comment, you can extend it to 1000 to allow for broader use cases

get_runtime_dependency_response.raise_for_status()

stop_dynamic_analysis = requests.post(
url=self.mobsf_host + "/api/v1/dynamic/stop_analysis",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that no sleep was added so basically the analysis has a really brief duration time, just the time needed to execute all the steps between the calls "start" and "stop". As mentioned, I would add a sleep between the "start" and the later calls, to allow time for the stuff to start properly and the code loaded and maybe to allow the malware to do some nasty things too.

@spoiicy
Copy link
Member Author

spoiicy commented Dec 18, 2024

@mlodic I've added the usage for MobSF_Service. Here is the pull request.
I've improved the readability of the code by adding helper method to handle request-response and refactored some of the code.

The PR is ready to be reviewed.

@mlodic
Copy link
Member

mlodic commented Dec 19, 2024

thank you, we are ready to merge it!

@mlodic mlodic merged commit cb6b3e2 into intelowlproject:develop Dec 19, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants