Skip to content
This repository was archived by the owner on Nov 18, 2024. It is now read-only.

Commit 0e49eff

Browse files
committed
Dedup yara logic between windows/linux
1 parent 395e7d3 commit 0e49eff

File tree

3 files changed

+13
-38
lines changed

3 files changed

+13
-38
lines changed

Diff for: varc_core/systems/base_system.py

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import logging
1313
import os
1414
import os.path
15+
from pathlib import Path
1516
import socket
1617
import tarfile
1718
import time
@@ -113,6 +114,15 @@ def __init__(
113114
if self.yara_file and not self.include_memory and _YARA_AVAILABLE:
114115
logging.info("YARA hits will be recorded only since include_memory is not selected.")
115116

117+
if self.include_memory:
118+
if self.yara_file:
119+
self.yara_scan()
120+
self.dump_processes()
121+
122+
if self.extract_dumps:
123+
from varc_core.utils import dumpfile_extraction
124+
dumpfile_extraction.extract_dumps(Path(self.output_path))
125+
116126
def get_network(self) -> List[str]:
117127
"""Get active network connections
118128
@@ -381,3 +391,5 @@ def yara_hit_callback(hit: dict) -> Any:
381391
else:
382392
logging.info("No YARA rules were triggered. Nothing will be written to the output archive.")
383393

394+
def dump_processes(self) -> None:
395+
raise NotImplementedError()

Diff for: varc_core/systems/linux.py

-18
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,6 @@ class IOVec(ctypes.Structure):
3535

3636

3737
class LinuxSystem(BaseSystem):
38-
39-
def __init__(
40-
self,
41-
include_memory: bool,
42-
include_open: bool,
43-
extract_dumps: bool,
44-
yara_file: Optional[str],
45-
**kwargs: Any
46-
) -> None:
47-
super().__init__(include_memory=include_memory, include_open=include_open, extract_dumps=extract_dumps, yara_file=yara_file, **kwargs)
48-
if self.include_memory:
49-
if self.yara_file:
50-
self.yara_scan()
51-
self.dump_processes()
52-
53-
if self.extract_dumps:
54-
from varc_core.utils import dumpfile_extraction
55-
dumpfile_extraction.extract_dumps(Path(self.output_path))
5638

5739
def parse_mem_map(self, pid: int, p_name: str) -> List[Tuple[int, int]]:
5840
"""Returns a list of (start address, end address) tuples of the regions of process memory that are mapped

Diff for: varc_core/systems/windows.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,8 @@
1515

1616
import pymem
1717

18-
class WindowsSystem(BaseSystem):
19-
"""
20-
"""
21-
22-
def __init__(
23-
self,
24-
include_memory: bool,
25-
include_open: bool,
26-
extract_dumps: bool,
27-
yara_file: Optional[str],
28-
**kwargs: Any
29-
) -> None:
30-
super().__init__(include_memory=include_memory, include_open=include_open, extract_dumps=extract_dumps, yara_file=yara_file, **kwargs)
31-
if self.include_memory:
32-
if self.yara_file:
33-
self.yara_scan()
34-
self.dump_processes()
3518

36-
if self.extract_dumps:
37-
from varc_core.utils import dumpfile_extraction
38-
dumpfile_extraction.extract_dumps(Path(self.output_path))
19+
class WindowsSystem(BaseSystem):
3920

4021
def read_process(self, handle: int, address: int) -> Tuple[Optional[bytes], int]:
4122
""" Read a process. Based on pymems pattern module

0 commit comments

Comments
 (0)