Skip to content

Commit c86f2b5

Browse files
committed
Ensure all paste_data is available to post processing
Previously things like hashes and triggered YaraRules were not available in the post processing steps. This change moves the setting of these values earlier so post processing actions can use them in their logic
1 parent ff2a2f4 commit c86f2b5

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

pastehunter.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ def paste_scanner():
237237
# Else use the rule name
238238
else:
239239
results.append(match.rule)
240+
241+
# Store additional fields for passing on to post processing
242+
encoded_paste_data = raw_paste_data.encode('utf-8')
243+
md5 = hashlib.md5(encoded_paste_data).hexdigest()
244+
sha256 = hashlib.sha256(encoded_paste_data).hexdigest()
245+
paste_data['MD5'] = md5
246+
paste_data['SHA256'] = sha256
247+
paste_data['raw_paste'] = raw_paste_data
248+
paste_data['YaraRule'] = results
249+
# Set the size for all pastes - This will override any size set by the source
250+
paste_data['size'] = len(raw_paste_data)
240251

241252
# Store all OverRides other options.
242253
paste_site = paste_data['confname']
@@ -282,21 +293,6 @@ def paste_scanner():
282293
results.append('no_match')
283294

284295
if len(results) > 0:
285-
286-
encoded_paste_data = raw_paste_data.encode('utf-8')
287-
md5 = hashlib.md5(encoded_paste_data).hexdigest()
288-
sha256 = hashlib.sha256(encoded_paste_data).hexdigest()
289-
paste_data['MD5'] = md5
290-
paste_data['SHA256'] = sha256
291-
# It is possible a post module modified or set this field.
292-
if not paste_data.get('raw_paste'):
293-
paste_data['raw_paste'] = raw_paste_data
294-
paste_data['size'] = len(raw_paste_data)
295-
else:
296-
# Set size based on modified value
297-
paste_data['size'] = len(paste_data['raw_paste'])
298-
299-
paste_data['YaraRule'] = results
300296
for output in outputs:
301297
try:
302298
output.store_paste(paste_data)

0 commit comments

Comments
 (0)