Skip to content

Phunter Analyzer #2841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open

Conversation

AnshSinghal
Copy link

@AnshSinghal AnshSinghal commented Apr 23, 2025

Closes #2286

Description

Please include a summary of the change and link to the related issue.

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. A link to the PR to the docs repo has been added as a comment here.
    • Advanced-Usage was updated (in case the plugin provides additional optional configuration). A link to the PR to the docs repo has been added as a comment here.
    • 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.
  • I have inserted the copyright banner at the start of the file: # This file is a part of IntelOwl https://github.com/intelowlproject/IntelOwl # See the file 'LICENSE' for copying permission.
  • 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 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 by using GitHub's reviewing system detailed here.
{
  "report": {
    "valid": "yes",
    "views": "1",
    "carrier": "reliance telecom pvt ltd",
    "location": "baghpat/baraut, uttar pradesh",
    "possible": "yes",
    "line_type": "fixed line",
    "local_time": "19:47:16",
    "spam_status": "Not spammer",
    "phone_number": "+911234567890",
    "national_format": "01234 567 890",
    "international_format": "+91 1234 567 890"
  },
  "data_model": null,
  "errors": [],
  "parameters": {}
}

image

@AnshSinghal
Copy link
Author

AnshSinghal commented Apr 24, 2025

@mlodic @fgibertoni Please review

Copy link
Contributor

@fgibertoni fgibertoni left a comment

Choose a reason for hiding this comment

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

Can you also provide an example of analyzer's output ?

# Modified to support synchronous analyzer BBOT that return results directly in the initial response, avoiding unnecessary polling.
if analyzer_name == "BBOT_Analyzer":
# Modified to support synchronous analyzers that return results directly in the initial response, avoiding unnecessary polling.
if analyzer_name in ["BBOT_Analyzer", "Phunter"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should refactor this.
Maybe adding an avoid_polling parameter to the _docker_run function which defaults to False to keep compatibility.

Copy link
Author

Choose a reason for hiding this comment

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

Sure

@@ -89,6 +89,7 @@ pylnk3==0.4.2
androguard==3.4.0a1 # version >=4.x of androguard raises a dependency conflict with quark-engine==25.1.1
wad==0.4.6
debloat==1.6.4
phonenumbers==9.0.3
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed if in docker analyzer

Copy link
Author

Choose a reason for hiding this comment

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

The phunter.py is also using this module so that would need to be installed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that performing the check twice is not necessary. I would keep it in docker analyzer only

Copy link
Author

@AnshSinghal AnshSinghal May 2, 2025

Choose a reason for hiding this comment

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

Sure. But I believe it would be better in phunter.py so that it would instantly returns if invalid phone number is passed.

container_name: phunter
restart: unless-stopped
expose:
- "5000"
Copy link
Contributor

Choose a reason for hiding this comment

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

intelowl_phoneinfoga container is already using this port. Please use a free one

@@ -0,0 +1,11 @@
services:
phunter:
image: intelowlproject/phunter:${REACT_APP_INTELOWL_VERSION}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
image: intelowlproject/phunter:${REACT_APP_INTELOWL_VERSION}
image: intelowlproject/intelowl_phunter:${REACT_APP_INTELOWL_VERSION}

services:
phunter:
image: intelowlproject/phunter:${REACT_APP_INTELOWL_VERSION}
container_name: phunter
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
container_name: phunter
container_name: intelowl_phunter

"spam_status": "Not spammer",
"phone_number": "+918929554991",
"national_format": "089295 54991",
"international_format": "+91 89295 54991",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this number real ? You should use a non existing number here

except ValueError as e:
logger.error(f"[{self.name}] Invalid response format: {e}", exc_info=True)
raise AnalyzerRunException(f"Invalid response format from Phunter API: {e}")

Copy link
Contributor

Choose a reason for hiding this comment

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

If no error is raised then nothing is returned. We should use a default

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a general Exception as fallback

Copy link
Author

Choose a reason for hiding this comment

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

😄 Didn't expect you to call for a general exception—tables have turned!


try:
logger.info("Executing Phunter CLI tool")
command = ["python3", "phunter.py", "-t", formatted_number]
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe consider using shlex for safer escaping before using subprocess.run

Copy link
Author

Choose a reason for hiding this comment

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

Umm but as we are already using a list which i believe is safer and preferred. What you say?

Copy link
Contributor

Choose a reason for hiding this comment

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

The list is not escaping possible injection in formatted_number, so it would be safer to use shlex

Copy link
Author

Choose a reason for hiding this comment

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

Sure


if __name__ == "__main__":
logger.info("Starting Phunter Flask API...")
app.run(host="0.0.0.0", port=5000)
Copy link
Contributor

Choose a reason for hiding this comment

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

port

)

except subprocess.CalledProcessError as e:
logger.error(f"Phunter CLI failed: {e.stderr}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this as said

@fgibertoni fgibertoni marked this pull request as ready for review April 28, 2025 09:53
@AnshSinghal AnshSinghal requested a review from fgibertoni April 29, 2025 14:42
Copy link
Contributor

@fgibertoni fgibertoni left a comment

Choose a reason for hiding this comment

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

Replied in thread

@AnshSinghal AnshSinghal requested a review from fgibertoni May 2, 2025 20:56
@AnshSinghal
Copy link
Author

@fgibertoni service_api_key needs to be added to the GitHub Actions secret.

Copy link

This pull request has been marked as stale because it has had no activity for 10 days. If you are still working on this, please provide some updates or it will be closed in 5 days.

@github-actions github-actions bot added the stale label May 13, 2025
@fgibertoni
Copy link
Contributor

This should not be the issue stated here I think

@AnshSinghal
Copy link
Author

AnshSinghal commented May 15, 2025 via email

@fgibertoni
Copy link
Contributor

I'm sorry you were right about the issue but the key had to be set in the test file.
You can pull the latest change from develop and should be fixed 😃

@AnshSinghal
Copy link
Author

AnshSinghal commented May 16, 2025 via email

@github-actions github-actions bot removed the stale label May 17, 2025
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