Skip to content
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

dev: Added package management with Poetry, Ruff for code static analysis #567

Merged
merged 8 commits into from
Jan 18, 2024

Conversation

fukusuket
Copy link
Collaborator

@fukusuket fukusuket commented Jan 16, 2024

What Changed

Ruff (made with Rust), a Python code static analysis tool, looked good, so I decided to try it out :)

Add the following tools for the development environment.

  • Python package version management
  • Python code static analysis

This PR does not affect script logic. (This is a PR for improving the development environment)

Evidence

Test Environment

  • OS: macOS Sonoma version 14.0
  • Hard: MacBook Air(M1, 2020) , Memory 8GB, Core 8
  • Poetry: version 1.7.1

Test(README)

Complete the script as follows according to the steps in the README.

sigmac % poetry install --no-root
Creating virtualenv hayabusa_rule_converter-6ygZgvup-py3.12 in /Users/fukusuke/Library/Caches/pypoetry/virtualenvs
Installing dependencies from lock file

Package operations: 3 installs, 0 updates, 0 removals

  • Installing pyyaml (6.0.1)
  • Installing oyaml (1.0)
  • Installing ruff (0.1.13)
sigmac % poetry run python logsource_mapping.py -r ../../../sigma -o ./converted_sigma_rules
[INFO:logsource_mapping.py:462] Start to logsource mapping sigma rules.
[INFO:logsource_mapping.py:499] Loading logsource mapping yaml(sysmon/windows-audit/windows-services) done.
[INFO:logsource_mapping.py:440] Start to collect target yml files path.
...
[INFO:logsource_mapping.py:520] [4111] files created successfully. Created files were saved under [./converted_sigma_rules].
[INFO:logsource_mapping.py:521] Script took [11.11] seconds.
sigmac % 

Test(Code static analysis)

I was able to execute the Ruff command and check the code static analysis results.

sigmac % poetry run ruff logsource_mapping.py                                               
logsource_mapping.py:432:18: F541 [*] f-string without any placeholders
logsource_mapping.py:440:17: F541 [*] f-string without any placeholders
logsource_mapping.py:499:17: F541 [*] f-string without any placeholders
Found 3 errors.
[*] 3 fixable with the `--fix` option.
sigmac % 

I would appreciate it if you could review when you have time🙏

@fukusuket fukusuket self-assigned this Jan 16, 2024
@fukusuket fukusuket added the enhancement New feature or request label Jan 16, 2024
@fukusuket fukusuket changed the title dev: Added library management with Poetry dev: Added package management with Poetry Jan 16, 2024
@fukusuket fukusuket changed the title dev: Added package management with Poetry dev: Added package management with Poetry, Ruff for code static analysis Jan 17, 2024
@fukusuket fukusuket marked this pull request as ready for review January 17, 2024 00:13
@YamatoSecurity
Copy link
Collaborator

@fukusuket Thanks for this!
This is not a problem with this particular PR but I noticed that when a rule is not able to be converted it sometimes does not print the file name:

[ERROR:logsource_mapping.py:299] This rule has incompatible field.{'process_creation': {'EventID': 4688, 'Channel': 'Security'}, 'selection': {'OriginalFileName': 'RUNDLL32.EXE'}, 'filter': {'NewProcessName|endswith': '\\rundll32.exe'}, 'condition': 'selection and not filter'}. skip conversion.
[ERROR:logsource_mapping.py:299] This rule has incompatible field.{'process_creation': {'EventID': 4688, 'Channel': 'Security'}, 'selection': {'Description': 'Execute processes remotely', 'Product': 'Sysinternals PsExec'}, 'filter': {'NewProcessName|endswith': ['\\PsExec.exe', '\\PsExec64.exe']}, 'condition': 'selection and not filter'}. skip conversion.
[ERROR:logsource_mapping.py:299] This rule has incompatible field.{'process_creation': {'EventID': 4688, 'Channel': 'Security'}, 'exec_selection': {'NewProcessName|endswith': '\\rclone.exe', 'ParentProcessName|endswith': ['\\PowerShell.exe', '\\cmd.exe']}, 'command_selection': {'CommandLine|contains': [' pass ', ' user ', ' copy ', ' mega ', ' sync ', ' config ', ' lsd ', ' remote ', ' ls ']}, 'description_selection': {'Description': 'Rsync for cloud storage'}, 'condition': 'command_selection and ( description_selection or exec_selection )'}. skip conversion.

It would be nice to figure out what rules are not being able to get converted. Can you add the filename to the error output?

Copy link
Collaborator

@hitenkoku hitenkoku left a comment

Choose a reason for hiding this comment

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

LGTM

@fukusuket
Copy link
Collaborator Author

@YamatoSecurity @hitenkoku
Thank you so much for checking :)
I added the path of the yml file to the ERROR log as shown below!

[ERROR:logsource_mapping.py:299] Error while converting rule [../../../sigma/deprecated/windows/proc_creation_win_renamed_rundll32.yml]: This rule has incompatible field.{'process_creation': {'EventID': 4688, 'Channel': 'Security'}, 'selection': {'OriginalFileName': 'RUNDLL32.EXE'}, 'filter': {'NewProcessName|endswith': '\\rundll32.exe'}, 'condition': 'selection and not filter'}. skip conversion.
[ERROR:logsource_mapping.py:299] Error while converting rule [../../../sigma/deprecated/windows/proc_creation_win_renamed_psexec.yml]: This rule has incompatible field.{'process_creation': {'EventID': 4688, 'Channel': 'Security'}, 'selection': {'Description': 'Execute processes remotely', 'Product': 'Sysinternals PsExec'}, 'filter': {'NewProcessName|endswith': ['\\PsExec.exe', '\\PsExec64.exe']}, 'condition': 'selection and not filter'}. skip conversion.
[ERROR:logsource_mapping.py:299] Error while converting rule [../../../sigma/deprecated/windows/win_susp_rclone_exec.yml]: This rule has incompatible field.{'process_creation': {'EventID': 4688, 'Channel': 'Security'}, 'exec_selection': {'NewProcessName|endswith': '\\rclone.exe', 'ParentProcessName|endswith': ['\\PowerShell.exe', '\\cmd.exe']}, 'command_selection': {'CommandLine|contains': [' pass ', ' user ', ' copy ', ' mega ', ' sync ', ' config ', ' lsd ', ' remote ', ' ls ']}, 'description_selection': {'Description': 'Rsync for cloud storage'}, 'condition': 'command_selection and ( description_selection or exec_selection )'}. skip conversion.
[INFO:logsource_mapping.py:520] [4111] files created successfully. Created files were saved under [./converted_sigma_rules].
[INFO:logsource_mapping.py:521] Script took [11.03] seconds.

@YamatoSecurity
Copy link
Collaborator

@fukusuket Thanks! Looks good now. I updated the English changelog. Could you update the Japanese one for me?

@fukusuket
Copy link
Collaborator Author

@YamatoSecurity
Thank you so much for updating change log :) I updated the Japanese change log!

Copy link
Collaborator

@YamatoSecurity YamatoSecurity left a comment

Choose a reason for hiding this comment

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

@fukusuket Thank you so much! All looks good, so I will merge this then.

@YamatoSecurity YamatoSecurity merged commit ef3b570 into main Jan 18, 2024
2 checks passed
@YamatoSecurity YamatoSecurity deleted the add-poetry branch January 18, 2024 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants