|
3 | 3 | # Copyright (c) 2016 GoSecure Inc.
|
4 | 4 |
|
5 | 5 | from opcache_disassembler import OPcacheDisassembler
|
| 6 | +from opcache_parser import OPcacheParser |
6 | 7 | import sys
|
7 | 8 | import os
|
8 | 9 | import subprocess
|
9 | 10 | import shutil
|
10 | 11 |
|
11 | 12 | hunt_source_files = "hunt_source_files.tmp"
|
12 |
| -hunt_ini = "hunt.ini.tmp" |
| 13 | +hunt_ini = "hunt.ini" |
13 | 14 | hunt_opcache = "hunt_opcache"
|
14 | 15 |
|
15 | 16 | def list_opcache_files(path):
|
@@ -61,6 +62,9 @@ def setup_env(phpini_path):
|
61 | 62 | if "opcache.enable=" in line:
|
62 | 63 | line = "opcache.enable=1"
|
63 | 64 |
|
| 65 | + if "opcache.file_cache_only=" in line: |
| 66 | + line = "opcache.file_cache_only=0" |
| 67 | + |
64 | 68 | h.write(line)
|
65 | 69 |
|
66 | 70 | # cache folder location
|
@@ -91,6 +95,15 @@ def compile_source_files():
|
91 | 95 | command = "php -c {0} compile.php {1}".format(hunt_ini, hunt_source_files)
|
92 | 96 | subprocess.call(command.split(), shell=False)
|
93 | 97 |
|
| 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 | + |
94 | 107 | def show_help():
|
95 | 108 | """ Show the help menu"""
|
96 | 109 |
|
@@ -121,13 +134,33 @@ def show_help():
|
121 | 134 | source_folder = prefix.split(system_id, 1)[1]
|
122 | 135 |
|
123 | 136 | # 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]] |
125 | 141 |
|
126 | 142 | # Dump source files
|
127 | 143 | dump_source_file_list(source_files)
|
128 | 144 |
|
129 | 145 | # Compile source files
|
130 | 146 | compile_source_files()
|
131 | 147 |
|
| 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 | + |
132 | 165 | # Remove temporary files and folders
|
133 | 166 | cleanup()
|
0 commit comments