Repository navigation
Find URL-decoded hosts for every URL in IoCExtract, not only the first - #957
Open
Dennys Kaluzny Pereira (protonnegativo) wants to merge 1 commit into
Open
Dennys Kaluzny Pereira (protonnegativo) wants to merge 1 commit into
Dennys Kaluzny Pereira (protonnegativo) wants to merge 1 commit into
Conversation
_scan_for_iocs passed the end offset of the previous match in the source string to _check_decode_url, which used it as the start position when scanning the decoded URL. For the first URL the offset is 0, but for later URLs it points into (or past) a different, shorter string, so the decoded URL and its host were not extracted. For example, "http://%65vil.com/x" yields evil.com when it is the first URL in the input, but not when it follows another URL. Scan the decoded URL from the start, and drop match_pos, which is no longer used.
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IoCExtractURL-decodes each URL it finds and adds the decoded URL and its host to the results (_check_decode_url). That only works for the first URL in the input.Reproducing
http://evil.com/xis also missing from theurlresults in the second case.Cause
_scan_for_iocspassedmatch_pos, the end offset of the previous match in the source string, to_check_decode_url, which used it as the start position forfinditeron the decoded URL. For the first URL the offset is 0. For later ones it points into, or past the end of, a different and shorter string, so nothing is found.The change
_check_decode_urlscans the decoded URL from the start. With that,match_poswas no longer read anywhere (finditer(src, match_pos)only ever saw 0), so I removed it.Testing
test_url_encoded_hostintests/transform/test_ioc_extractor.py, with the encoded URL first and second. The second case fails onmainand passes with the change.pytest tests/transform/test_ioc_extractor.py tests/context/test_lookup.py tests/context/test_vtlookup.py: same results asmainapart from the new test (the remaining errors are the optionalpassivetotalimport).ruff checkandruff format --checkpass oniocextract.py.