PE-sieve
Scans all running processes. Recognizes and dumps a variety of potentially malicious implants (replaced/implanted PEs, shellcodes, hooks, in-memory patches).
Toggle main menu visibility
Loading...
Searching...
No Matches
scanners
scan_report.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <windows.h>
4
5
#include <iostream>
6
#include <sstream>
7
#include <string>
8
#include <vector>
9
10
#include <peconv.h>
11
#include "
pe_sieve_types.h
"
12
#include "
module_scan_report.h
"
13
#include "
scanned_modules.h
"
14
15
namespace
pesieve
{
16
18
class
ProcessScanReport
19
{
20
public
:
21
typedef
enum
{
22
REPORT_MAPPING_SCAN
,
23
REPORT_HEADERS_SCAN
,
24
REPORT_CODE_SCAN
,
25
REPORT_MEMPAGE_SCAN
,
26
REPORT_ARTEFACT_SCAN
,
27
REPORT_UNREACHABLE_SCAN
,
28
REPORT_SKIPPED_SCAN
,
29
REPORT_IAT_SCAN
,
30
REPORT_THREADS_SCAN
,
31
REPORT_TYPES_COUNT
32
}
t_report_type
;
33
34
static
t_report_type
getReportType
(
ModuleScanReport
*
report
);
35
36
ProcessScanReport
(DWORD _pid,
bool
_is64bit,
bool
_isReflection,
t_params
* _usedParams)
37
:
pid
(_pid),
exportsMap
(nullptr),
errorsCount
(0),
modulesInfo
(
pid
),
isManaged
(false),
is64bit
(_is64bit),
38
isReflection
(_isReflection),
usedParams
(_usedParams)
39
{
40
}
41
42
~ProcessScanReport
()
43
{
44
deleteModuleReports
();
45
delete
exportsMap
;
46
}
47
48
void
appendReport
(
ModuleScanReport
*
report
)
49
{
50
if
(
report
==
nullptr
)
return
;
51
moduleReports
.push_back(
report
);
52
if
(
ModuleScanReport::get_scan_status
(
report
) ==
SCAN_ERROR
) {
53
this->
errorsCount
++;
54
}
55
appendToType
(
report
);
56
// if the scan was successful, append the module to the scanned modules:
57
if
(
ModuleScanReport::get_scan_status
(
report
) !=
SCAN_ERROR
) {
58
modulesInfo
.appendToModulesList(
report
);
59
}
60
}
61
62
size_t
getScannedSize
(ULONGLONG address)
const
63
{
64
return
modulesInfo
.getScannedSize(address);
65
}
66
67
bool
hasModule
(ULONGLONG page_addr)
68
{
69
if
(!
modulesInfo
.getModuleAt(page_addr)) {
70
return
false
;
71
}
72
return
true
;
73
}
74
75
bool
hasModuleContaining
(ULONGLONG page_addr,
size_t
size)
76
{
77
if
(!
modulesInfo
.findModuleContaining(page_addr, size)) {
78
return
false
;
79
}
80
return
true
;
81
}
82
83
bool
isModuleReplaced
(HMODULE module_base);
84
85
ScannedModule
*
getModuleContaining
(ULONGLONG field_addr,
size_t
field_size = 0)
const
86
{
87
return
modulesInfo
.findModuleContaining(field_addr, field_size);
88
}
89
90
const
virtual
bool
toJSON
(std::stringstream &stream,
size_t
level,
const
t_results_filter
&filter,
const
pesieve::t_json_level
&jdetails)
const
;
91
92
pesieve::t_report
generateSummary
()
const
;
93
DWORD
getPid
() {
return
pid
; }
94
bool
isManagedProcess
() {
return
this->
isManaged
; }
95
96
std::string
mainImagePath
;
97
std::vector<ModuleScanReport*>
moduleReports
;
//TODO: make it protected
98
peconv::ExportsMapper *
exportsMap
;
99
100
protected
:
101
std::string
listModules
(
size_t
level,
const
t_results_filter
&filter,
const
t_json_level
&jdetails)
const
;
102
103
void
deleteModuleReports
()
104
{
105
std::vector<ModuleScanReport*>::iterator itr =
moduleReports
.begin();
106
for
(; itr !=
moduleReports
.end(); ++itr) {
107
ModuleScanReport
* module = *itr;
108
delete
module
;
109
}
110
moduleReports
.clear();
111
}
112
113
void
appendToType
(
ModuleScanReport
*
report
);
114
size_t
countResultsPerType
(
const
t_report_type
type,
const
t_scan_status
result)
const
;
115
116
size_t
countSuspiciousPerType
(
const
t_report_type
type)
const
117
{
118
return
countResultsPerType
(type,
SCAN_SUSPICIOUS
);
119
}
120
121
size_t
countHdrsReplaced
()
const
;
122
bool
hasAnyShownType
(
const
t_results_filter
&filter);
123
124
DWORD
pid
;
125
bool
is64bit
;
126
bool
isManaged
;
127
bool
isReflection
;
128
t_params
*
usedParams
;
129
size_t
errorsCount
;
130
131
ModulesInfo
modulesInfo
;
132
std::set<ModuleScanReport*>
reportsByType
[
REPORT_TYPES_COUNT
];
133
134
friend
class
ProcessScanner
;
135
friend
class
ResultsDumper
;
136
};
137
138
};
//namespace pesieve
pesieve::ElementScanReport::get_scan_status
static t_scan_status get_scan_status(const ElementScanReport *report)
Definition
module_scan_report.h:35
pesieve::ModuleScanReport
A base class of all the reports detailing on the output of the performed module's scan.
Definition
module_scan_report.h:56
pesieve::ModulesInfo
A container of all the process modules that were scanned.
Definition
scanned_modules.h:84
pesieve::ProcessScanReport::~ProcessScanReport
~ProcessScanReport()
Definition
scan_report.h:42
pesieve::ProcessScanReport::countResultsPerType
size_t countResultsPerType(const t_report_type type, const t_scan_status result) const
Definition
scan_report.cpp:88
pesieve::ProcessScanReport::toJSON
virtual const bool toJSON(std::stringstream &stream, size_t level, const t_results_filter &filter, const pesieve::t_json_level &jdetails) const
Definition
scan_report.cpp:209
pesieve::ProcessScanReport::ResultsDumper
friend class ResultsDumper
Definition
scan_report.h:135
pesieve::ProcessScanReport::isReflection
bool isReflection
Definition
scan_report.h:127
pesieve::ProcessScanReport::isManagedProcess
bool isManagedProcess()
Definition
scan_report.h:94
pesieve::ProcessScanReport::mainImagePath
std::string mainImagePath
Definition
scan_report.h:96
pesieve::ProcessScanReport::ProcessScanReport
ProcessScanReport(DWORD _pid, bool _is64bit, bool _isReflection, t_params *_usedParams)
Definition
scan_report.h:36
pesieve::ProcessScanReport::appendReport
void appendReport(ModuleScanReport *report)
Definition
scan_report.h:48
pesieve::ProcessScanReport::isModuleReplaced
bool isModuleReplaced(HMODULE module_base)
Definition
scan_report.cpp:115
pesieve::ProcessScanReport::generateSummary
pesieve::t_report generateSummary() const
Definition
scan_report.cpp:152
pesieve::ProcessScanReport::exportsMap
peconv::ExportsMapper * exportsMap
Definition
scan_report.h:98
pesieve::ProcessScanReport::usedParams
t_params * usedParams
Definition
scan_report.h:128
pesieve::ProcessScanReport::pid
DWORD pid
Definition
scan_report.h:124
pesieve::ProcessScanReport::listModules
std::string listModules(size_t level, const t_results_filter &filter, const t_json_level &jdetails) const
Definition
scan_report.cpp:182
pesieve::ProcessScanReport::isManaged
bool isManaged
Definition
scan_report.h:126
pesieve::ProcessScanReport::getPid
DWORD getPid()
Definition
scan_report.h:93
pesieve::ProcessScanReport::errorsCount
size_t errorsCount
Definition
scan_report.h:129
pesieve::ProcessScanReport::reportsByType
std::set< ModuleScanReport * > reportsByType[REPORT_TYPES_COUNT]
Definition
scan_report.h:132
pesieve::ProcessScanReport::modulesInfo
ModulesInfo modulesInfo
Definition
scan_report.h:131
pesieve::ProcessScanReport::moduleReports
std::vector< ModuleScanReport * > moduleReports
Definition
scan_report.h:97
pesieve::ProcessScanReport::t_report_type
t_report_type
Definition
scan_report.h:21
pesieve::ProcessScanReport::REPORT_ARTEFACT_SCAN
@ REPORT_ARTEFACT_SCAN
Definition
scan_report.h:26
pesieve::ProcessScanReport::REPORT_SKIPPED_SCAN
@ REPORT_SKIPPED_SCAN
Definition
scan_report.h:28
pesieve::ProcessScanReport::REPORT_UNREACHABLE_SCAN
@ REPORT_UNREACHABLE_SCAN
Definition
scan_report.h:27
pesieve::ProcessScanReport::REPORT_MEMPAGE_SCAN
@ REPORT_MEMPAGE_SCAN
Definition
scan_report.h:25
pesieve::ProcessScanReport::REPORT_THREADS_SCAN
@ REPORT_THREADS_SCAN
Definition
scan_report.h:30
pesieve::ProcessScanReport::REPORT_TYPES_COUNT
@ REPORT_TYPES_COUNT
Definition
scan_report.h:31
pesieve::ProcessScanReport::REPORT_MAPPING_SCAN
@ REPORT_MAPPING_SCAN
Definition
scan_report.h:22
pesieve::ProcessScanReport::REPORT_HEADERS_SCAN
@ REPORT_HEADERS_SCAN
Definition
scan_report.h:23
pesieve::ProcessScanReport::REPORT_IAT_SCAN
@ REPORT_IAT_SCAN
Definition
scan_report.h:29
pesieve::ProcessScanReport::REPORT_CODE_SCAN
@ REPORT_CODE_SCAN
Definition
scan_report.h:24
pesieve::ProcessScanReport::deleteModuleReports
void deleteModuleReports()
Definition
scan_report.h:103
pesieve::ProcessScanReport::hasModule
bool hasModule(ULONGLONG page_addr)
Definition
scan_report.h:67
pesieve::ProcessScanReport::getReportType
static t_report_type getReportType(ModuleScanReport *report)
Definition
scan_report.cpp:53
pesieve::ProcessScanReport::hasModuleContaining
bool hasModuleContaining(ULONGLONG page_addr, size_t size)
Definition
scan_report.h:75
pesieve::ProcessScanReport::countHdrsReplaced
size_t countHdrsReplaced() const
Definition
scan_report.cpp:132
pesieve::ProcessScanReport::getModuleContaining
ScannedModule * getModuleContaining(ULONGLONG field_addr, size_t field_size=0) const
Definition
scan_report.h:85
pesieve::ProcessScanReport::getScannedSize
size_t getScannedSize(ULONGLONG address) const
Definition
scan_report.h:62
pesieve::ProcessScanReport::hasAnyShownType
bool hasAnyShownType(const t_results_filter &filter)
Definition
scan_report.cpp:38
pesieve::ProcessScanReport::appendToType
void appendToType(ModuleScanReport *report)
Definition
scan_report.cpp:104
pesieve::ProcessScanReport::countSuspiciousPerType
size_t countSuspiciousPerType(const t_report_type type) const
Definition
scan_report.h:116
pesieve::ProcessScanReport::ProcessScanner
friend class ProcessScanner
Definition
scan_report.h:134
pesieve::ProcessScanReport::is64bit
bool is64bit
Definition
scan_report.h:125
pesieve::ScannedModule
Represents a basic info about the scanned module, such as its base offset, size, and the status.
Definition
scanned_modules.h:14
pesieve.t_json_level
Definition
pesieve.py:83
pesieve.t_params
Definition
pesieve.py:110
pesieve.t_report_type
Definition
pesieve.py:98
pesieve.t_report
Definition
pesieve.py:136
pesieve.t_results_filter
Definition
pesieve.py:89
module_scan_report.h
pesieve
Definition
pesieve.py:1
pesieve::SCAN_SUSPICIOUS
@ SCAN_SUSPICIOUS
Definition
module_scan_report.h:21
pesieve::SCAN_ERROR
@ SCAN_ERROR
Definition
module_scan_report.h:19
pesieve::t_scan_status
enum pesieve::module_scan_status t_scan_status
pe_sieve_types.h
The types used by PE-sieve API.
scanned_modules.h
report
Final summary about the scanned process.
Definition
pe_sieve_types.h:151
Generated by
1.17.0