Skip to content

Command Sequence API. Closes #471#478

Merged
regulartim merged 4 commits intointelowlproject:developfrom
regulartim:command_seq_api
Feb 24, 2025
Merged

Command Sequence API. Closes #471#478
regulartim merged 4 commits intointelowlproject:developfrom
regulartim:command_seq_api

Conversation

@regulartim
Copy link
Copy Markdown
Collaborator

@regulartim regulartim commented Feb 24, 2025

Description

New API that lets you (1) get all executed commands for a specific IP address or (2) get all IP addresses that executed a specific command. Also supports fuzzy matching of commands by including commands from the same cluster. Will update the docs later this week.

Related issues

Type of change

  • New feature (non-breaking change which adds functionality).

Checklist

  • I have read and understood the rules about how to Contribute to this project.
  • The pull request is for the branch develop.
  • I have added documentation of the new features.
  • 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. 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.

Important Rules

  • If you miss to compile the Checklist properly, your PR won't be reviewed by the maintainers.
  • If your changes decrease the overall tests coverage (you will know after the Codecov CI job is done), you should add the required tests to fix the problem
  • 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.

@regulartim regulartim requested a review from mlodic February 24, 2025 17:48
Comment on lines +59 to +60
"executed commands": seqs,
"executed by": sorted([ioc.name for ioc in related_iocs]),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you use underscore instead of spaces? just to avoid possible problems somewhere


Args:
request: The HTTP request object containing query parameters

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

observable and include_similar are missing in the docstring. I undestand that technically the only parameter is request but, based on how the documentation works, it makes sense to add them like you did for the advanced feeds

"""
observable = request.query_params.get("query")
include_similar = request.query_params.get("include_similar") is not None
logger.info(f"Command Sequence view requested for: {str(observable)}")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it would be great to log the request.user too here to track it

if is_ip_address(observable):
sessions = CowrieSession.objects.filter(source__name=observable, start_time__isnull=False, commands__isnull=False)
sequences = set(s.commands for s in sessions)
seqs = [{"time": s.start_time, "command sequence": "\n".join(s.commands.commands), "command sequence hash": s.commands.commands_hash} for s in sessions]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

_ here too if possible in the keys

@regulartim
Copy link
Copy Markdown
Collaborator Author

Thanks for the review! :) Will do all of that and merge afterwards.

@mlodic
Copy link
Copy Markdown
Member

mlodic commented Feb 24, 2025

I added a new issue to integrate these new endpoints to IntelOwl too intelowlproject/IntelOwl#2768

@regulartim regulartim merged commit b8062b8 into intelowlproject:develop Feb 24, 2025
5 checks passed
@regulartim regulartim deleted the command_seq_api branch February 24, 2025 20:10
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