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

add a more flexible example for adding file type object #1313

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Delta-Sierra
Copy link
Collaborator

No description provided.

Copy link
Member

@Rafiot Rafiot left a comment

Choose a reason for hiding this comment

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

The script will do the trick, but why not using the CSV loader?
https://github.com/MISP/PyMISP/blob/main/pymisp/tools/csvloader.py

I think it does the same thing for most of the code here, and you just need to iterate over the list of objects it returns to submit it to MISP.

# -*- coding: utf-8 -*-

import csv
from pymisp import ExpandedPyMISP, MISPObject
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 (should) use PyMISP and not ExpandedPyMISP. They're the same and ExpandedPyMISP is deprecated.


pymisp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert)

f = open(args.attr_file, newline='', encoding="utf-8-sig")
Copy link
Member

Choose a reason for hiding this comment

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

Why -sig? utf-8 is default as far as I know.


for line, row in enumerate(csv_reader, start=2):
misp_object = MISPObject(name='file')
for idx, col in matching_columns.items():
Copy link
Member

Choose a reason for hiding this comment

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

Why not using csv.DictReader instead?

@Delta-Sierra
Copy link
Collaborator Author

Delta-Sierra commented Dec 10, 2024

The script will do the trick, but why not using the CSV loader? https://github.com/MISP/PyMISP/blob/main/pymisp/tools/csvloader.py

Cough Probably because I could not find it in the first place... 🤐 Didn't search enough apparently.

I think it does the same thing for most of the code here, and you just need to iterate over the list of objects it returns to submit it to MISP.

If you prefer me to remove it, that's fine by me, otherwise I'll go through the changes you requested :)

@Rafiot
Copy link
Member

Rafiot commented Dec 10, 2024

The script will do the trick, but why not using the CSV loader? https://github.com/MISP/PyMISP/blob/main/pymisp/tools/csvloader.py

Cough Probably because I could not find it in the first place... 🤐 Didn't search enough apparently.

I'm gong to blame the fact it is poorly documented ;)

I think it does the same thing for most of the code here, and you just need to iterate over the list of objects it returns to submit it to MISP.

If you prefer me to remove it, that's fine by me, otherwise I'll go through the changes you requested :)

You have a use case for a script that does what your script does, so I'll definitely merge it. I mostly wanted to make sure we don't duplicate for no reason :)

@Rafiot Rafiot self-assigned this Dec 12, 2024
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