2016-03-14 20:40:06 +01:00
import json
from url_archiver import url_archiver
misperrors = { ' error ' : ' Error ' }
2016-03-20 10:55:39 +01:00
mispattributes = { ' input ' : [ ' link ' , ' url ' ] , ' output ' : [ ' attachment ' , ' malware-sample ' ] }
2016-03-20 11:54:03 +01:00
moduleinfo = { ' version ' : ' 0.1 ' , ' author ' : ' Alexandre Dulaunoy ' , ' description ' : ' Module to cache web pages of analysis reports, OSINT sources. The module returns a link of the cached page. ' , ' module-type ' : [ ' expansion ' ] }
2016-03-16 20:02:03 +01:00
moduleconfig = [ ' archivepath ' ]
2016-03-14 20:40:06 +01:00
def handler ( q = False ) :
if q is False :
return False
request = json . loads ( q )
2016-03-16 20:02:03 +01:00
if ( request . get ( ' config ' ) ) :
archive_path = request [ ' config ' ] [ ' archivepath ' ]
else :
archive_path = ' /tmp/ '
2016-03-14 20:40:06 +01:00
if request . get ( ' link ' ) :
tocache = request [ ' link ' ]
2016-03-20 10:55:39 +01:00
data = __archiveLink ( archive_path , tocache )
mispattributes [ ' output ' ] = [ ' attachment ' ]
elif request . get ( ' url ' ) :
tocache = request [ ' url ' ]
data = __archiveLink ( archive_path , tocache )
mispattributes [ ' output ' ] = [ ' malware-sample ' ]
2016-03-14 20:40:06 +01:00
else :
misperrors [ ' error ' ] = " Link is missing "
return misperrors
2016-03-20 17:06:05 +01:00
enc_data = data . decode ( ' ascii ' )
2016-03-20 11:43:29 +01:00
r = { ' results ' : [ { ' types ' : mispattributes [ ' output ' ] , ' values ' : tocache , ' data ' : enc_data } ] }
2016-03-14 20:40:06 +01:00
return r
2016-03-20 10:55:39 +01:00
def __archiveLink ( archive_path , tocache ) :
archiver = url_archiver . Archive ( archive_path = archive_path )
2016-03-20 11:43:29 +01:00
return archiver . fetch ( url = tocache , armor = True )
2016-03-20 10:55:39 +01:00
2016-04-11 11:07:11 +02:00
2016-03-14 20:40:06 +01:00
def introspection ( ) :
return mispattributes
def version ( ) :
2016-03-16 20:02:03 +01:00
moduleinfo [ ' config ' ] = moduleconfig
2016-03-14 20:40:06 +01:00
return moduleinfo