21 switch (shellc_mode) {
30 inline bool match_to_tag(std::ofstream& patch_report,
const char delimiter,
size_t start_offset,
const sig_finder::Match &match)
32 if (patch_report.is_open() && match.sign) {
33 patch_report << std::hex << match.offset + start_offset;
34 patch_report << delimiter;
35 patch_report << match.sign->name;
36 patch_report << delimiter;
37 patch_report << match.sign->size();
38 patch_report << std::endl;
51 std::ofstream patch_report;
52 patch_report.open(reportPath);
53 if (patch_report.is_open() ==
false) {
58 sig_finder::Match m = *itr;
61 if (patch_report.is_open()) {
71 if (!memPage.load()) {
75 const bool noPadding =
true;
82 bool obfuscated =
false;
84 size_t custom_matched_count = 0;
87 std::vector<sig_finder::Match> allMatched;
88 my_report->all_matched_count =
g_Matcher.
findAllPatterns(memPage.getLoadedData(noPadding), memPage.getLoadedSize(noPadding), allMatched);
90 if (my_report->all_matched_count) {
91 my_report->match_area_start = memPage.getStartOffset(noPadding);
104#ifdef CALC_PAGE_STATS
105 if (isByStats || this->args.obfuscated) {
112 if (calc.
fill(my_report->stats, &settings)) {
115 if (codeMatcher.
findMatches(my_report->stats, my_report->area_info)) {
120 if (!codeS && (this->args.obfuscated !=
OBFUSC_NONE)) {
126 if (obfMatcher.
findMatches(my_report->stats, my_report->area_info)) {
129 if (memPage.mapping_type == MEM_MAPPED
131 && memPage.loadMappedName())
142 code = (codeP && codeS);
145 code = (codeP || codeS);
148 my_report->has_shellcode = code;
150 if ( (obfuscated && this->args.obfuscated !=
OBFUSC_NONE)
151 || (code && (this->args.shellcode !=
SHELLC_NONE || custom_matched_count) ))
156 my_report->data_cache = memPage.loadedData;
166 return isPotentiallyExecutable(memPage, this->args.data);
171 if (mode == pesieve::PE_DATA_NO_SCAN) {
176 const bool is_managed = this->processReport.isManagedProcess();
177 if (mode == pesieve::PE_DATA_SCAN_NO_DEP
178 && this->pDetails.isDEP && !is_managed)
182 if (mode == pesieve::PE_DATA_SCAN_DOTNET
189 if (mode != pesieve::PE_DATA_SCAN_INACCESSIBLE_ONLY) {
190 if (is_page_readable) {
194 if ((mode >= pesieve::PE_DATA_SCAN_INACCESSIBLE) || (mode == pesieve::PE_DATA_SCAN_INACCESSIBLE_ONLY)) {
195 if (this->pDetails.isReflection && (memPage.
protection & PAGE_NOACCESS)) {
204 if (!_memPage.
load()) {
208 if (!isScannedAsModule(_memPage)) {
209 ArtefactScanner artefactScanner(this->processHandle, this->pDetails, _memPage, this->processReport);
225 const size_t region_size = size_t(_memPage.
region_end - region_start);
231 if (!checkAreaContent(_memPage, my_report)) {
239 my_report->
has_pe = isScannedAsModule(_memPage) && this->processReport.hasModule(_memPage.
region_start);
248 if (this->processReport.hasModule((ULONGLONG)memPage.
alloc_base)) {
261 const HMODULE module_start = (HMODULE)memPage.
alloc_base;
264 std::cout <<
"[!] Scanning detached: " << std::hex << module_start <<
" : " << memPage.
mapped_name << std::endl;
266 RemoteModuleData remoteModData(this->processHandle, this->pDetails.isReflection, module_start);
269 std::cout <<
"[-] Could not read the remote PE at: " << std::hex << module_start << std::endl;
278 std::cerr <<
"[-] [" << std::hex << modData.
moduleHandle <<
"] Could not read the module file" << std::endl;
285 std::cout <<
"[*] Scanned for hollows. Status: " << scan_status << std::endl;
295 if (!args.no_hooks) {
297 || (!this->pDetails.isDEP && (this->args.data == pesieve::PE_DATA_SCAN_NO_DEP));
298 const bool scan_inaccessible = (this->pDetails.isReflection && (this->args.data >= pesieve::PE_DATA_SCAN_INACCESSIBLE));
301 std::cout <<
"[*] Scanned for hooks. Status: " << scan_status << std::endl;
309 MemPageData memPage(this->processHandle, this->pDetails.isReflection, this->memRegion.base, 0);
310 memPage.
is_listed_module = this->processReport.hasModule(this->memRegion.base);
314 std::cout <<
"[!] Could not fill: " << std::hex << memPage.
start_va <<
" to: " << memPage.
region_end <<
"\n";
319 if (memPage.
alloc_base != this->memRegion.alloc_base) {
321 std::cerr <<
"WARNING: Alloc Base mismatch: " << std::hex << memPage.
alloc_base <<
" vs " << this->memRegion.alloc_base << std::endl;
327 std::cerr <<
"WARNING: Size mismatch: " << std::hex << (memPage.
region_end - memPage.
region_start) <<
" vs " << this->memRegion.size << std::endl;
333 const bool is_any_exec = isExecutable(memPage);
347 if (!isScannedAsModule(memPage)) {
351 if (this->processReport.hasModuleContaining(memPage.
region_start, region_size)) {
357 std::cout << std::hex << memPage.
start_va <<
": Scanning executable area" << std::endl;
A class responsible for filling in the statistics with the data from the particular buffer.
bool fill(AreaStats &stats, StatsSettings *settings)
A scanner for detection of artefacts related to PE implants in the process workingset.
virtual ArtefactScanReport * scanRemote()
DWORD protection
page protection
std::string mapped_name
if the region is mapped from a file, stores its file name
ULONGLONG start_va
VA that was requested. May not be beginning of the region.
Loads a module from the disk, corresponding to the module in the scanned process' memory.
size_t findAllPatterns(BYTE *loadedData, size_t loadedSize, ::std::vector< sig_finder::Match > &allMatches)
size_t filterCustom(::std::vector< sig_finder::Match > &allMatches, ::std::vector< sig_finder::Match > &customPatternMatches)
static t_scan_status scanForHooks(HANDLE hProcess, ModuleData &modData, RemoteModuleData &remoteModData, ProcessScanReport &process_report, bool scan_data, bool scan_inaccessible)
static t_scan_status scanForHollows(HANDLE hProcess, ModuleData &modData, RemoteModuleData &remoteModData, ProcessScanReport &process_report)
Buffers the data from the module loaded in the scanned process into the local memory.
A report from the working set scan, generated by WorkingSetScanner.
std::vector< sig_finder::Match > custom_matched
size_t generateTags(const std::string &reportPath)
WorkingSetScanReport * scanExecutableArea(MemPageData &memPageData)
bool isPotentiallyExecutable(MemPageData &memPageData, const t_data_scan_mode &mode)
bool checkAreaContent(IN MemPageData &_memPage, OUT WorkingSetScanReport *my_report)
bool isScannedAsModule(MemPageData &memPageData)
bool scanImg(MemPageData &memPage)
bool isExecutable(MemPageData &memPageData)
virtual WorkingSetScanReport * scanRemote()
size_t fillCodeStrings(OUT std::set< std::string > &codeStrings)
bool is_readable(DWORD mapping_type, DWORD protection)
bool is_executable(DWORD mapping_type, DWORD protection)
bool match_to_tag(std::ofstream &patch_report, const char delimiter, size_t start_offset, const sig_finder::Match &match)
enum pesieve::module_scan_status t_scan_status
bool is_by_stats(const t_shellc_mode &shellc_mode)
pesieve::PatternMatcher g_Matcher
@ SHELLC_STATS
detect shellcodes by stats
@ SHELLC_NONE
do not detect shellcode
@ SHELLC_PATTERNS_OR_STATS
detect shellcodes by patterns or stats (any match)
@ SHELLC_PATTERNS_AND_STATS
detect shellcodes by patterns and stats (both match)
@ PE_DATA_SCAN_INACCESSIBLE_ONLY
scan inaccessible pages (if running in reflection mode)
@ OBFUSC_ANY
detect both: possible strong or weak encryption
@ OBFUSC_WEAK_ENC
detect areas possibly encrypted with weak encryption (lower entropy, possible XOR patterns)
@ OBFUSC_STRONG_ENC
detect areas possibly encrypted with strong encryption
@ OBFUSC_NONE
do not detect obfuscated contents
Settings defining what type of stats should be collected.
std::set< std::string > watchedStrings
size_t findMatches(IN const AreaMultiStats &stats, OUT AreaInfo &info)
pesieve::PatternMatcher g_Matcher