3
3
# Copyright (c) 2016 GoSecure Inc.
4
4
5
5
from opcache_disassembler import OPcacheDisassembler
6
- from opcache_parser import OPcacheParser
6
+ import hashlib
7
+ import opcache_parser
8
+ import opcache_parser_64
7
9
import sys
8
10
import os
9
11
import subprocess
@@ -232,7 +234,7 @@ def compare_parsed_files(file1, file2):
232
234
233
235
return True
234
236
235
- def create_diff_report (file1 , file2 , report_name , from_desc , to_desc , is_64_bit ):
237
+ def create_diff_report (file1 , file2 , file_name , from_desc , to_desc , is_64_bit ):
236
238
237
239
""" Create a report showing the differences between two files
238
240
@@ -252,14 +254,16 @@ def create_diff_report(file1, file2, report_name, from_desc, to_desc, is_64_bit)
252
254
html_differ = difflib .HtmlDiff ()
253
255
254
256
# Generate the report and write into a file
255
- report_name = report_name .replace ("/" , "%2f" ) + '.html'
256
- with open (hunt_report + "/" + report_name , "w" ) as f :
257
- f .write (html_differ .make_file (disassembled_1 , disassembled_2 , from_desc , to_desc ))
257
+ file_name = file_name .replace ("/" , "%2f" ) + '.html'
258
+ hash_name = hashlib .sha1 (file_name ).hexdigest ()
259
+ with open (hunt_report + "/" + hash_name + ".html" , "w" ) as f :
260
+ content = html_differ .make_file (disassembled_1 , disassembled_2 , from_desc , to_desc )
261
+ f .write (content )
258
262
259
263
# Return the name of the report
260
- return report_name
264
+ return ( file_name , hash_name + ".html" )
261
265
262
- def create_index (report_names ):
266
+ def create_index (file_names , report_names ):
263
267
264
268
""" Create an index file containing the list of all the reports generated by create_diff_report
265
269
@@ -279,9 +283,9 @@ def create_index(report_names):
279
283
280
284
# The list of links towards each report
281
285
body = "<ul>"
282
- for report_name in report_names :
286
+ for index , report_name in enumerate ( report_names ) :
283
287
link = report_name .replace ("%2f" , "%252f" )
284
- link_name = report_name .replace ("%2f" , "/" )[:- 5 ]
288
+ link_name = file_names [ index ] .replace ("%2f" , "/" )[:- 5 ]
285
289
body += "<li><a href='{0}'>{1}</a></li>" .format (link , link_name )
286
290
body += "</ul>"
287
291
@@ -317,8 +321,10 @@ def show_help():
317
321
is_64_bit = False
318
322
if architecture == "-a64" :
319
323
is_64_bit = True
324
+ OPcacheParser = opcache_parser_64 .OPcacheParser
320
325
elif architecture == "-a32" :
321
326
is_64_bit = False
327
+ OPcacheParser = opcache_parser .OPcacheParser
322
328
323
329
324
330
# Setup a new phpini for compilation
@@ -365,13 +371,15 @@ def show_help():
365
371
print ""
366
372
print "Potentially infected files : "
367
373
reports = []
374
+ file_names = []
368
375
for idx , file , new_cache_file in flagged_files :
369
376
print " - " + file
370
377
371
- report = create_diff_report (new_cache_file , file , opcache_files [idx ], "Source Code" , "Cache" , is_64_bit )
378
+ ( file_name , report ) = create_diff_report (new_cache_file , file , opcache_files [idx ], "Source Code" , "Cache" , is_64_bit )
372
379
reports += [report ]
380
+ file_names += [file_name ]
373
381
374
- create_index (reports )
382
+ create_index (file_names , reports )
375
383
else :
376
384
print "No infected files found."
377
385
0 commit comments