Source code for pytx.malware
import base64
import cStringIO
import zipfile
from common import Common
from vocabulary import Malware as m
from vocabulary import ThreatExchange as t
[docs]class Malware(Common):
_URL = t.URL + t.VERSION + t.MALWARE_ANALYSES
_DETAILS = t.URL
_RELATED = t.URL
_fields = [
m.ADDED_ON,
m.CRX,
m.ID,
m.IMPHASH,
m.METADATA,
m.MD5,
m.PASSWORD,
m.PE_RICH_HEADER,
m.SAMPLE,
m.SHA1,
m.SHA256,
m.SHARE_LEVEL,
m.SSDEEP,
m.STATUS,
m.SUBMITTER_COUNT,
m.VICTIM_COUNT,
m.XPI
]
_unique = [
'zfh',
'zf',
'rfh',
'rf',
]
@property
[docs] def zfh(self):
"""
Return a file handle of the base64-decoded sample in a zip file.
"""
if self.get(m.SAMPLE) is None:
self.details()
zfh = cStringIO.StringIO()
zfh.write(base64.b64decode(self.get(m.SAMPLE)))
zfh.seek(0)
return zfh
@property
[docs] def zf(self):
"""
Return the base64-decoded sample in a zip file.
"""
return self.zfh.read()
@property
[docs] def rfh(self):
"""
Return a file handle of the base64-decoded and unzipped sample.
"""
zfh = self.zfh
rfh = cStringIO.StringIO()
with zipfile.ZipFile(zfh, 'r') as zf:
for entry in zf.infolist():
rfh.write(zf.read(entry.filename,
self.get(m.PASSWORD)))
rfh.seek(0)
return rfh
@property
[docs] def rf(self):
"""
Return the base64-decoded and unzipped sample.
"""
return self.rfh.read()