PE-sieve
Scans all running processes. Recognizes and dumps a variety of potentially malicious implants (replaced/implanted PEs, shellcodes, hooks, in-memory patches).
Loading...
Searching...
No Matches
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
15namespace pesieve {
16
19 {
20 public:
33
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
47
49 {
50 if (report == nullptr) return;
51 moduleReports.push_back(report);
53 this->errorsCount++;
54 }
55 appendToType(report);
56 // if the scan was successful, append the module to the scanned modules:
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
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
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
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 {
119 }
120
121 size_t countHdrsReplaced() const;
122 bool hasAnyShownType(const t_results_filter &filter);
123
124 DWORD pid;
130
132 std::set<ModuleScanReport*> reportsByType[REPORT_TYPES_COUNT];
133
134 friend class ProcessScanner;
135 friend class ResultsDumper;
136 };
137
138}; //namespace pesieve
A base class of all the reports detailing on the output of the performed module's scan.
static t_scan_status get_scan_status(const ModuleScanReport *report)
A container of all the process modules that were scanned.
ScannedModule * findModuleContaining(ULONGLONG address, size_t size=0) const
size_t getScannedSize(ULONGLONG start_address) const
bool appendToModulesList(ModuleScanReport *report)
ScannedModule * getModuleAt(ULONGLONG address) const
The report aggregating the results of the performed scan.
Definition scan_report.h:19
size_t countResultsPerType(const t_report_type type, const t_scan_status result) const
virtual const bool toJSON(std::stringstream &stream, size_t level, const t_results_filter &filter, const pesieve::t_json_level &jdetails) const
ProcessScanReport(DWORD _pid, bool _is64bit, bool _isReflection, t_params *_usedParams)
Definition scan_report.h:36
void appendReport(ModuleScanReport *report)
Definition scan_report.h:48
bool isModuleReplaced(HMODULE module_base)
pesieve::t_report generateSummary() const
peconv::ExportsMapper * exportsMap
Definition scan_report.h:98
std::string listModules(size_t level, const t_results_filter &filter, const t_json_level &jdetails) const
std::set< ModuleScanReport * > reportsByType[REPORT_TYPES_COUNT]
std::vector< ModuleScanReport * > moduleReports
Definition scan_report.h:97
bool hasModule(ULONGLONG page_addr)
Definition scan_report.h:67
static t_report_type getReportType(ModuleScanReport *report)
bool hasModuleContaining(ULONGLONG page_addr, size_t size)
Definition scan_report.h:75
size_t countHdrsReplaced() const
ScannedModule * getModuleContaining(ULONGLONG field_addr, size_t field_size=0) const
Definition scan_report.h:85
size_t getScannedSize(ULONGLONG address) const
Definition scan_report.h:62
bool hasAnyShownType(const t_results_filter &filter)
void appendToType(ModuleScanReport *report)
size_t countSuspiciousPerType(const t_report_type type) const
The root scanner, responsible for enumerating all the elements to be scanned within a given process,...
Definition scanner.h:15
Represents a basic info about the scanned module, such as its base offset, size, and the status.
enum pesieve::module_scan_status t_scan_status
The types used by PE-sieve API.
t_results_filter
Final summary about the scanned process.