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
iat_scanner.h
Go to the documentation of this file.
1#pragma once
2
3#include <windows.h>
4
5#include "module_scanner.h"
6#include "scanned_modules.h"
7
8namespace pesieve {
9
12 {
13 public:
14
15 static bool saveNotRecovered(IN std::string fileName,
16 IN HANDLE hProcess,
17 IN peconv::ImportsCollection *storedFunc,
18 IN peconv::ImpsNotCovered &notCovered,
19 IN const ModulesInfo &modulesInfo,
20 IN const peconv::ExportsMapper *exportsMap);
21
27
28 const virtual bool toJSON(std::stringstream &outs, size_t level, const pesieve::t_json_level &jdetails)
29 {
30 size_t hooks = countHooked();
31 OUT_PADDED(outs, level, "\"iat_scan\" : ");
32 outs << "{\n";
34 outs << ",\n";
35 OUT_PADDED(outs, level + 1, "\"hooks\" : ");
36 outs << std::dec << hooks;
37 if (jdetails >= JSON_DETAILS && hooks) {
38 outs << ",\n";
39 this->hooksToJSON(outs, level + 1);
40 }
41 outs << "\n";
42 OUT_PADDED(outs, level, "}");
43 return true;
44 }
45
46 bool generateList(IN const std::string &fileName, IN HANDLE hProcess, IN const ModulesInfo &modulesInfo, IN const peconv::ExportsMapper *exportsMap);
47
48 const bool hooksToJSON(std::stringstream &outs, size_t level);
49 size_t countHooked() { return notCovered.count(); }
50
51 peconv::ImportsCollection storedFunc;
52 peconv::ImpsNotCovered notCovered;
53
54 protected:
55 static std::string formatHookedFuncName(IN peconv::ImportsCollection* storedFunc, DWORD thunk_rva);
56 static std::string formatTargetName(IN const peconv::ExportsMapper* exportsMap, IN const ModulesInfo& modulesInfo, IN const ULONGLONG module_start, IN ULONGLONG addr);
57 };
58
59 //---
60
62 class IATScanner : public ModuleScanner {
63 public:
64
69 const peconv::ExportsMapper &_exportsMap,
72 )
74 exportsMap(_exportsMap), modulesInfo(_modulesInfo),
75 hooksFilter(_hooksFilter)
76 {
77 initExcludedPaths();
78 }
79
80 virtual IATScanReport* scanRemote();
81
82 private:
83 bool scanByOriginalTable(peconv::ImpsNotCovered &not_covered);
84 bool isValidFuncFilled(ULONGLONG filled_val, const peconv::ExportedFunc &definedFunc, const peconv::ExportedFunc& possibleFunc);
85
86 void initExcludedPaths();
87 bool isInSystemDir(const std::string &moduleName);
88
89 bool filterResults(peconv::ImpsNotCovered &not_covered, IATScanReport &report);
90
92 bool listAllImports(peconv::ImportsCollection &collection);
93
94 const peconv::ExportsMapper &exportsMap;
95 const ModulesInfo &modulesInfo;
96
97 t_iat_scan_mode hooksFilter;
98
99 //excluded paths:
100 std::string m_sysWow64Path_str;
101 std::string m_system32Path_str;
102 };
103
104}; //namespace pesieve
105
A report from an IAT scan, generated by IATScanner.
Definition iat_scanner.h:12
IATScanReport(HMODULE _module, size_t _moduleSize, std::string _moduleFile)
Definition iat_scanner.h:22
const bool hooksToJSON(std::stringstream &outs, size_t level)
static std::string formatHookedFuncName(IN peconv::ImportsCollection *storedFunc, DWORD thunk_rva)
static bool saveNotRecovered(IN std::string fileName, IN HANDLE hProcess, IN peconv::ImportsCollection *storedFunc, IN peconv::ImpsNotCovered &notCovered, IN const ModulesInfo &modulesInfo, IN const peconv::ExportsMapper *exportsMap)
bool generateList(IN const std::string &fileName, IN HANDLE hProcess, IN const ModulesInfo &modulesInfo, IN const peconv::ExportsMapper *exportsMap)
peconv::ImportsCollection storedFunc
Definition iat_scanner.h:51
static std::string formatTargetName(IN const peconv::ExportsMapper *exportsMap, IN const ModulesInfo &modulesInfo, IN const ULONGLONG module_start, IN ULONGLONG addr)
peconv::ImpsNotCovered notCovered
Definition iat_scanner.h:52
virtual const bool toJSON(std::stringstream &outs, size_t level, const pesieve::t_json_level &jdetails)
Definition iat_scanner.h:28
A scanner for detection of IAT hooking.
Definition iat_scanner.h:62
IATScanner(HANDLE hProc, ModuleData &moduleData, RemoteModuleData &remoteModData, const peconv::ExportsMapper &_exportsMap, IN const ModulesInfo &_modulesInfo, t_iat_scan_mode _hooksFilter)
Definition iat_scanner.h:65
virtual IATScanReport * scanRemote()
Loads a module from the disk, corresponding to the module in the scanned process' memory.
Definition module_data.h:15
A base class of all the reports detailing on the output of the performed module's scan.
virtual const bool _toJSON(std::stringstream &outs, size_t level=JSON_LEVEL, const pesieve::t_json_level &jdetails=JSON_BASIC)
A base class for all the scanners operating on module data.
RemoteModuleData & remoteModData
A container of all the process modules that were scanned.
Buffers the data from the module loaded in the scanned process into the local memory.
#define OUT_PADDED(stream, field_size, str)
Definition format_util.h:12
size_t fill_iat(BYTE *vBuf, size_t vBufSize, IN const peconv::ExportsMapper *exportsMap, IN OUT IATBlock &iat, IN ThunkFoundCallback *callback)
Definition iat_finder.h:31
@ JSON_DETAILS
include the basic list patches in the main JSON report
Final summary about the scanned process.