Skip to content

Commit 189313a

Browse files
author
Ian Bouchard
committed
Starts working on cache file comparison
1 parent e99cb12 commit 189313a

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

analysis_tools/compile.php

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
if ($handle) {
55
while (($line = fgets($handle)) !== false) {
6+
$line = trim($line);
67
opcache_compile_file($line);
78
}
89
fclose($handle);

analysis_tools/opcache_malware_hunt.py

+35-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
# Copyright (c) 2016 GoSecure Inc.
44

55
from opcache_disassembler import OPcacheDisassembler
6+
from opcache_parser import OPcacheParser
67
import sys
78
import os
89
import subprocess
910
import shutil
1011

1112
hunt_source_files = "hunt_source_files.tmp"
12-
hunt_ini = "hunt.ini.tmp"
13+
hunt_ini = "hunt.ini"
1314
hunt_opcache = "hunt_opcache"
1415

1516
def list_opcache_files(path):
@@ -61,6 +62,9 @@ def setup_env(phpini_path):
6162
if "opcache.enable=" in line:
6263
line = "opcache.enable=1"
6364

65+
if "opcache.file_cache_only=" in line:
66+
line = "opcache.file_cache_only=0"
67+
6468
h.write(line)
6569

6670
# cache folder location
@@ -91,6 +95,15 @@ def compile_source_files():
9195
command = "php -c {0} compile.php {1}".format(hunt_ini, hunt_source_files)
9296
subprocess.call(command.split(), shell=False)
9397

98+
def parse_file(file):
99+
return OPcacheParser(file)
100+
101+
def compare_parsed_files(file1, file2):
102+
103+
# Compare opcodes
104+
print [f.opcode for f in file1['script']['main_op_array']['opcodes']]
105+
print [f.opcode for f in file2['script']['main_op_array']['opcodes']]
106+
94107
def show_help():
95108
""" Show the help menu"""
96109

@@ -121,13 +134,33 @@ def show_help():
121134
source_folder = prefix.split(system_id, 1)[1]
122135

123136
# Source files list
124-
source_files = [source_folder + file.split(source_folder, 1)[1][:-4] for file in opcache_files ]
137+
if len(opcache_files) > 1:
138+
source_files = [source_folder + file.split(source_folder, 1)[1][:-4] for file in opcache_files ]
139+
else:
140+
source_files = [source_folder[:-4]]
125141

126142
# Dump source files
127143
dump_source_file_list(source_files)
128144

129145
# Compile source files
130146
compile_source_files()
131147

148+
# Compare original cache files with new ones
149+
for idx, file in enumerate(opcache_files):
150+
new_cache_file = os.path.join(hunt_opcache, system_id)
151+
new_cache_file += os.path.join(new_cache_file, source_files[idx])
152+
new_cache_file += ".bin"
153+
154+
print "Checking " + file
155+
print "Checking " + new_cache_file
156+
157+
# Parse files
158+
original_file = parse_file(file)
159+
new_parsed = parse_file(new_cache_file)
160+
161+
# Compare files
162+
compare_parsed_files(original_file, new_parsed)
163+
break
164+
132165
# Remove temporary files and folders
133166
cleanup()

0 commit comments

Comments
 (0)