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
thread_scanner.h
Go to the documentation of this file.
1#pragma once
2
3#include <windows.h>
4
5#include "module_scanner.h"
7#include "../stats/stats.h"
9
10namespace pesieve {
11
14 {
15 public:
16 static const DWORD THREAD_STATE_UNKNOWN = (-1);
17 static const DWORD THREAD_STATE_WAITING = 5;
18
25
26 const virtual void fieldsToJSON(std::stringstream &outs, size_t level, const pesieve::t_json_level &jdetails)
27 {
29 outs << ",\n";
30
31 OUT_PADDED(outs, level, "\"thread_id\" : ");
32 outs << std::dec << tid;
33 outs << ",\n";
34 OUT_PADDED(outs, level, "\"thread_ip\" : ");
35 outs << "\"" << std::hex << thread_ip << "\"";
36 outs << ",\n";
38 OUT_PADDED(outs, level, "\"thread_state\" : ");
39 outs << "\"" << translate_thread_state(thread_state) << "\"";
40 outs << ",\n";
41
43 OUT_PADDED(outs, level, "\"thread_wait_reason\" : ");
45 outs << ",\n";
46 }
47 }
48 OUT_PADDED(outs, level, "\"protection\" : ");
49 outs << "\"" << std::hex << protection << "\"";
50 if (stats.isFilled()) {
51 outs << ",\n";
53 }
54 }
55
56 const virtual bool toJSON(std::stringstream& outs, size_t level, const pesieve::t_json_level &jdetails)
57 {
58 OUT_PADDED(outs, level, "\"thread_scan\" : {\n");
60 outs << "\n";
61 OUT_PADDED(outs, level, "}");
62 return true;
63 }
64
66 DWORD tid;
71
72 protected:
73 static std::string translate_thread_state(DWORD thread_state);
74 static std::string translate_wait_reason(DWORD thread_wait_reason);
75 };
76
78 typedef struct _thread_ctx {
79 bool is64b;
83 ULONGLONG ret_addr; // the last return address on the stack (or the address of the first shellcode)
84 bool is_managed; // does it contain .NET modules
86
90 public:
91 // neccessery to validly recognize stack frame
92 static bool InitSymbols(HANDLE hProc);
93 static bool FreeSymbols(HANDLE hProc);
94
100
101 virtual ThreadScanReport* scanRemote();
102
103 protected:
104
107 bool fetchThreadCtx(IN HANDLE hProcess, IN HANDLE hThread, OUT thread_ctx& c);
108 size_t enumStackFrames(IN HANDLE hProcess, IN HANDLE hThread, IN LPVOID ctx, IN OUT thread_ctx& c);
111
115 peconv::ExportsMapper* exportsMap;
116 };
117
118}; //namespace pesieve
bool isFilled() const
Definition stats.h:40
virtual const bool toJSON(std::stringstream &outs, size_t level)
Definition stats.h:49
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 container of all the process modules that were scanned.
A base class for all the scanners checking appropriate process' features.
A report from the thread scan, generated by ThreadScanner.
virtual const void fieldsToJSON(std::stringstream &outs, size_t level, const pesieve::t_json_level &jdetails)
static std::string translate_wait_reason(DWORD thread_wait_reason)
static const DWORD THREAD_STATE_UNKNOWN
static const DWORD THREAD_STATE_WAITING
virtual const bool toJSON(std::stringstream &outs, size_t level, const pesieve::t_json_level &jdetails)
static std::string translate_thread_state(DWORD thread_state)
ThreadScanner(HANDLE hProc, bool _isReflection, const util::thread_info &_info, ModulesInfo &_modulesInfo, peconv::ExportsMapper *_exportsMap)
virtual ThreadScanReport * scanRemote()
bool reportSuspiciousAddr(ThreadScanReport *my_report, ULONGLONG susp_addr, thread_ctx &c)
size_t enumStackFrames(IN HANDLE hProcess, IN HANDLE hThread, IN LPVOID ctx, IN OUT thread_ctx &c)
bool resolveAddr(ULONGLONG addr)
static bool FreeSymbols(HANDLE hProc)
bool fillAreaStats(ThreadScanReport *my_report)
bool isAddrInShellcode(ULONGLONG addr)
peconv::ExportsMapper * exportsMap
const util::thread_info & info
static bool InitSymbols(HANDLE hProc)
bool fetchThreadCtx(IN HANDLE hProcess, IN HANDLE hThread, OUT thread_ctx &c)
#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
struct pesieve::_thread_ctx thread_ctx
A custom structure keeping a fragment of a thread context.
A custom structure keeping a fragment of a thread context.