|
4 | 4 | import shutil
|
5 | 5 | import tempfile
|
6 | 6 |
|
7 |
| -import numpy as np |
8 | 7 | import pyzipper
|
| 8 | +from Cryptodome.Util.strxor import strxor_c |
9 | 9 | from sqlalchemy import or_
|
10 | 10 | from sqlalchemy.dialects.postgresql.array import ARRAY
|
11 | 11 | from sqlalchemy.ext.mutable import MutableList
|
@@ -280,30 +280,25 @@ def iterate(self, chunk_size=1024 * 256):
|
280 | 280 | finally:
|
281 | 281 | File.close(fh)
|
282 | 282 |
|
283 |
| - def negate_bits(self, chunk): |
284 |
| - """ |
285 |
| - xor data with key equal 255 of length of chunk; using numpy |
286 |
| - https://stackoverflow.com/questions/23312571/fast-xoring-bytes-in-python-3 |
287 |
| - """ |
288 |
| - key = np.frombuffer(b"\xff" * len(chunk), dtype="uint8") |
289 |
| - chunk = np.frombuffer(chunk, dtype="uint8") |
290 |
| - return (key ^ chunk).tobytes() |
291 |
| - |
292 | 283 | def iterate_obfuscated(self, chunk_size=1024 * 256):
|
293 | 284 | r"""
|
294 | 285 | Iterates over bytes in the file contents with xor applied
|
295 | 286 | The idea behind xoring before send is to prevent browsers
|
296 | 287 | from caching original samples (malware). Unxoring is provided
|
297 | 288 | in mwdb\web\src\components\ShowSample.js in SamplePreview
|
298 | 289 | """
|
| 290 | + |
| 291 | + def negate_bits(chunk): |
| 292 | + return strxor_c(chunk, 255) |
| 293 | + |
299 | 294 | fh = self.open()
|
300 | 295 | try:
|
301 | 296 | if hasattr(fh, "stream"):
|
302 |
| - yield from map(self.negate_bits, fh.stream(chunk_size)) |
| 297 | + yield from map(negate_bits, fh.stream(chunk_size)) |
303 | 298 | else:
|
304 | 299 | while True:
|
305 | 300 | chunk = fh.read(chunk_size)
|
306 |
| - chunk = self.negate_bits(chunk) |
| 301 | + chunk = negate_bits(chunk) |
307 | 302 | if chunk:
|
308 | 303 | yield chunk
|
309 | 304 | else:
|
|
0 commit comments