Skip to content

Commit f5d2fac

Browse files
committed
elf的UPX检测
1 parent 66a3cf4 commit f5d2fac

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed
286 KB
Binary file not shown.

tests/test_packer.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@
77

88
cur_dir_path = Path(__file__).parent
99

10-
def test_upx_packer():
10+
11+
def test_exe_upx_packer():
1112
upxed_path = cur_dir_path / 'test_data' / 'Hello_upx.exe_'
1213
file_analyzer = FileAnalyzer(upxed_path)
1314
pe_analyzer = PeAnalyzer(file_analyzer)
1415
matches = pe_analyzer.get_packer_result()
1516
assert matches == ['UPX 2.90 [LZMA] -> Markus Oberhumer, Laszlo Molnar & John Reiser']
1617

1718

19+
def test_elf_upx_packer():
20+
upxed_path = cur_dir_path / 'test_data' / 'Hello64_elf_static_upx_'
21+
file_analyzer = FileAnalyzer(upxed_path)
22+
elf_analyzer = ElfAnalyzer(file_analyzer)
23+
matches = elf_analyzer.get_packer_result()
24+
assert matches == ['UPX 3.96']
25+
26+
1827
def test_pyinstaller_packer():
1928
pe_path = cur_dir_path / 'test_data' / 'pyinstaller_pack.exe_'
2029
file_analyzer = FileAnalyzer(pe_path)

xanalyzer/file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ def get_wide_strs(self):
184184
def get_tool_recommendations(self):
185185
recommended_tool_names = []
186186

187-
if 'UPX compressed' in self.file_type:
188-
recommended_tool_names.append('UPX')
189-
elif 'Mono/.Net assembly' in self.file_type:
187+
if 'Mono/.Net assembly' in self.file_type:
190188
recommended_tool_names.append('dnSpy')
191189
elif 'APK(Android application package)' in self.file_type:
192190
recommended_tool_names.append('JADX')
@@ -205,6 +203,8 @@ def get_tool_recommendations(self):
205203
recommended_tool_names.extend(['Wireshark', 'BruteShark'])
206204

207205
for packer in self.packer_list:
206+
if packer.startswith('UPX '):
207+
recommended_tool_names.append('UPX')
208208
if packer.startswith('PyInstaller,'):
209209
recommended_tool_names.append('PyInstaller Extractor')
210210

xanalyzer/file_process/elf.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# coding:utf8
22

3+
import re
34
from xanalyzer.utils import log
45

56

@@ -18,7 +19,16 @@ def get_packer_result(self):
1819
if b'E: neither argv[0] nor $_ works.' in file_content:
1920
matches = ['Shc, Shell script compiler, https://github.com/neurobin/shc']
2021
return matches
21-
22+
23+
# Check UPX
24+
if b'$Info: This file is packed with the UPX executable packer' in file_content:
25+
upx_ver_s = re.search(rb'\$Id: (UPX .+?) Copyright', file_content)
26+
if upx_ver_s:
27+
matches = [upx_ver_s.group(1).decode()]
28+
else:
29+
matches = ['UPX unknown version']
30+
return matches
31+
2232
return None
2333

2434
def packer_scan(self):

0 commit comments

Comments
 (0)