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

Implemented logic for preventing self-extracting payloads #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stoq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,12 @@ async def scan_request(
else:
payload_idx = hashes_seen[payload_hash]
for idx in payload_idx:
if request.payloads[idx].results.payload_id in extracted_payload.results.extracted_from:
# Handle self extracting payload
dup_idx = extracted_payload.results.extracted_from.index(request.payloads[idx].results.payload_id)
del extracted_payload.results.extracted_by[dup_idx]
del extracted_payload.results.extracted_from[dup_idx]
self.log.debug(f'Self extracting payload detected for {request.payloads[idx].results.payload_id}')
request.payloads[idx].results.extracted_by.extend(
extracted_payload.results.extracted_by
)
Expand Down
6 changes: 5 additions & 1 deletion stoq/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ async def test_scan_with_duplicate_extracted_payloads(self):
'extract_payload', response.results[1].plugins_run['workers'][0]
)
self.assertEqual('simple_worker', response.results[1].extracted_by[0])
self.assertEqual('extract_payload', response.results[1].extracted_by[1])
self.assertEqual(1, len(response.results[1].extracted_by))

async def test_scan_with_nested_required_plugin(self):
s = Stoq(base_dir=utils.get_data_dir())
Expand Down Expand Up @@ -507,6 +507,10 @@ async def test_dedup(self):
response = await s.scan(self.generic_content)
self.assertEqual(len(response.results), 2)

# Make sure extracted_from does not include the result payload_id
for result in response.results:
self.assertNotIn(result.payload_id, result.extracted_from)

@asynctest.skipIf(
sys.version_info >= (3, 8), 'skipping because python >= 3.8 breaks test'
)
Expand Down