Skip to content

Commit d1f3e43

Browse files
authored
vmray: record command line info (mandiant#2515)
* vmray: record command line info
1 parent 83a4626 commit d1f3e43

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- allow call as valid subscope for call scoped rules @mr-tz
88
- support loading and analyzing a Binary Ninja database #2496 @xusheng6
9+
- vmray: record process command line details @mr-tz
910

1011
### Breaking Changes
1112

capa/features/extractors/vmray/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class VMRayMonitorProcess:
3535
ppid: int # parent process ID assigned by OS
3636
monitor_id: int # unique ID assigned to process by VMRay
3737
image_name: str
38+
filename: str
39+
cmd_line: str
3840

3941

4042
class VMRayAnalysis:
@@ -160,7 +162,12 @@ def _compute_monitor_processes(self):
160162
self.sv2.processes[process.ref_parent_process.path[1]].os_pid if process.ref_parent_process else 0
161163
)
162164
self.monitor_processes[process.monitor_id] = VMRayMonitorProcess(
163-
process.os_pid, ppid, process.monitor_id, process.image_name
165+
process.os_pid,
166+
ppid,
167+
process.monitor_id,
168+
process.image_name,
169+
process.filename,
170+
process.cmd_line,
164171
)
165172

166173
# not all processes are recorded in SummaryV2.json, get missing data from flog.xml, see #2394
@@ -170,6 +177,8 @@ def _compute_monitor_processes(self):
170177
monitor_process.os_parent_pid,
171178
monitor_process.process_id,
172179
monitor_process.image_name,
180+
monitor_process.filename,
181+
monitor_process.cmd_line,
173182
)
174183

175184
if monitor_process.process_id not in self.monitor_processes:

capa/features/extractors/vmray/extractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def extract_process_features(self, ph: ProcessHandle) -> Iterator[tuple[Feature,
8686

8787
def get_process_name(self, ph) -> str:
8888
monitor_process: VMRayMonitorProcess = ph.inner
89-
return monitor_process.image_name
89+
return f"{monitor_process.image_name} ({monitor_process.cmd_line})"
9090

9191
def get_threads(self, ph: ProcessHandle) -> Iterator[ThreadHandle]:
9292
for monitor_thread_id in self.analysis.monitor_threads_by_monitor_process[ph.inner.monitor_id]:

capa/features/extractors/vmray/models.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,28 @@ class FunctionReturn(BaseModel):
136136
from_addr: HexInt = Field(alias="from")
137137

138138

139+
def sanitize_string(value: str) -> str:
140+
# e.g. "cmd_line": "\"C:\\Users\\38lTTV5Kii\\Desktop\\filename.exe\" ",
141+
return value.replace("\\\\", "\\").strip(' "')
142+
143+
144+
# unify representation
145+
SanitizedString = Annotated[str, BeforeValidator(sanitize_string)]
146+
147+
139148
class MonitorProcess(BaseModel):
140149
ts: HexInt
141150
process_id: int
142151
image_name: str
143-
filename: str
152+
filename: SanitizedString
144153
# page_root: HexInt
145154
os_pid: HexInt
146155
# os_integrity_level: HexInt
147156
# os_privileges: HexInt
148157
monitor_reason: str
149158
parent_id: int
150159
os_parent_pid: HexInt
151-
# cmd_line: str
160+
cmd_line: SanitizedString
152161
# cur_dir: str
153162
# os_username: str
154163
# bitness: int
@@ -306,8 +315,9 @@ class Process(BaseModel):
306315
monitor_id: int
307316
# monitor_reason: str
308317
os_pid: int
309-
filename: str
318+
filename: SanitizedString
310319
image_name: str
320+
cmd_line: SanitizedString
311321
ref_parent_process: Optional[GenericReference] = None
312322

313323

0 commit comments

Comments
 (0)