30 HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processID);
32 std::cerr <<
"-> Access denied. Try to run the scanner as Administrator." << std::endl;
38 std::cerr <<
"-> Access denied. Could not query the process token." << std::endl;
41 std::cerr <<
"-> Access denied. Could not access the system process." << std::endl;
46 CloseHandle(hProcess);
52 BOOL isCurrWow64 = FALSE;
55 BOOL isRemoteWow64 = FALSE;
58 if (isCurrWow64 && !isRemoteWow64) {
67 const DWORD basic_access = SYNCHRONIZE | PROCESS_VM_READ | PROCESS_QUERY_INFORMATION;
68 DWORD access = basic_access;
73 HANDLE hProcess = OpenProcess(access, FALSE, processID);
81 if (!hProcess && access != basic_access) {
82 hProcess = OpenProcess( basic_access, FALSE, processID);
95 const DWORD last_err = GetLastError();
97 if (last_err == ERROR_ACCESS_DENIED) {
99 std::cerr <<
"[-][" << processID <<
"] Could not open the process Error: " << last_err << std::endl;
104 SetLastError(ERROR_ACCESS_DENIED);
105 throw std::runtime_error(
"Could not open the process: Access Denied");
108 if (last_err == ERROR_INVALID_PARAMETER) {
110 std::cerr <<
"-> Is this process still running?" << std::endl;
112 SetLastError(ERROR_INVALID_PARAMETER);
113 throw std::runtime_error(
"Could not open the process: Invalid Parameter");
130 if (dumper.
dumpJsonReport(process_report, args.results_filter, args.json_lvl) && !args.quiet) {
131 std::cout <<
"[+] Report dumped to: " << dumper.
getOutputDir() << std::endl;
136 if (args.dump_mode < peconv::PE_DUMP_MODES_COUNT) {
139 size_t dumped_modules = 0;
140 dumpReport = dumper.
dumpDetectedModules(hProcess, isRefl, process_report, dump_mode, args.imprec_mode, args.rebase);
144 if (!args.quiet && dumped_modules) {
145 std::cout <<
"[+] Dumped modified to: " << dumper.
getOutputDir() << std::endl;
152 std::cout <<
"[*] Creating minidump..." << std::endl;
154 std::string original_path = process_report.mainImagePath;
155 std::string file_name = peconv::get_file_name(original_path);
156 std::string dump_file = dumper.
makeOutPath(file_name +
".dmp");
163 std::cout <<
"[+] Minidump saved to: " << dumpReport->
minidumpPath << std::endl;
166 else if (!args.quiet) {
167 std::cout <<
"[-] Creating minidump failed! " << std::endl;
174 std::cout <<
"[+] Report dumped to: " << dumper.
getOutputDir() << std::endl;
187 switch (shellc_mode) {
205 HANDLE orig_proc =
nullptr;
206 HANDLE cloned_proc =
nullptr;
209 if (!args.quiet) std::cerr <<
"[-] Could not set debug privilege" << std::endl;
212 if (args.pattern_file.length) {
215 if (loaded) std::cout <<
"[+] Pattern file loaded: " << args.pattern_file.buffer <<
", Signs: " << loaded << std::endl;
216 else std::cerr <<
"[-] Failed to load pattern file: " << args.pattern_file.buffer << std::endl;
224 orig_proc =
open_process(args.pid, args.make_reflection, args.quiet);
225 HANDLE target_proc = orig_proc;
227 if (args.make_reflection) {
230 target_proc = cloned_proc;
233 if (!args.quiet) std::cerr <<
"[-] Failed to create the process reflection" << std::endl;
239 std::cout <<
"[*] Using process reflection!\n";
242 std::cout <<
"[*] Using raw process!\n";
243 if (args.data == pesieve::PE_DATA_SCAN_INACCESSIBLE || args.data == pesieve::PE_DATA_SCAN_INACCESSIBLE_ONLY) {
249 const bool is_reflection = (cloned_proc) ?
true :
false;
252 if (
report->scan_report) {
257 catch (std::exception &e) {
264 std::cout <<
"[+] Report dumped to: " << dumper.
getOutputDir() << std::endl;
270 CloseHandle(orig_proc);
276 std::stringstream stream;
279 stream <<
" (x64)" <<
"\n";
281 stream <<
" (x86)" <<
"\n";
283 stream <<
"Built on: " << __DATE__ <<
"\n\n";
284 stream <<
"~ from hasherezade with love ~\n";
285 stream <<
"Scans a given process, recognizes and dumps a variety of in-memory implants:\nreplaced/injected PEs, shellcodes, inline hooks, patches etc.\n";
size_t loadPatternFile(const char *filename)
bool initShellcodePatterns()
The report aggregating the results of the performed dumps.
size_t countDumped() const
The report aggregating the results of the performed scan.
The root scanner, responsible for enumerating all the elements to be scanned within a given process,...
ProcessScanReport * scanRemote()
The main function of ProcessScanner, deploying the scan. Throws exceptions in case of a failure.
The final report about the actions performed on the process: scanning and dumping.
std::string makeOutPath(const std::string &fname, const std::string &defaultExtension="")
ProcessDumpReport * dumpDetectedModules(HANDLE hProcess, bool isRefl, ProcessScanReport &process_report, const pesieve::t_dump_mode dump_mode, const t_imprec_mode imprec_mode, const bool rebase)
std::string getOutputDir()
bool dumpJsonReport(ProcessScanReport &process_report, const t_results_filter &filter, const pesieve::t_json_level &jdetails)
bool make_minidump(DWORD pid, const std::string &out_file)
process_integrity_t get_integrity_level(HANDLE hProcess)
std::string expand_path(const std::string &path)
bool set_debug_privilege()
BOOL is_process_wow64(IN HANDLE processHandle, OUT BOOL *isProcWow64)
const DWORD reflection_access1
void print_in_color(int color, const std::string &text, bool is_error=false)
BOOL(CALLBACK *_MiniDumpWriteDump)(HANDLE hProcess
const DWORD reflection_access
bool release_process_reflection(HANDLE *reflection_hndl)
DWORD(__stdcall *_PssCaptureSnapshot)(HANDLE ProcessHandle
HANDLE make_process_reflection(HANDLE orig_hndl)
void check_access_denied(DWORD processID)
bool is_by_patterns(const t_shellc_mode &shellc_mode)
HANDLE open_process(DWORD processID, bool reflection, bool quiet)
bool is_scanner_compatible(IN HANDLE hProcess)
pesieve::ProcessDumpReport * make_dump(IN HANDLE hProcess, IN bool isRefl, IN const pesieve::t_params &args, IN ProcessScanReport &process_report)
std::string info()
The string with the basic information about the scanner.
ReportEx * scan_and_dump(IN const pesieve::t_params args)
The main action performed by PE-sieve: scanning the process and dumping the detected material.
pesieve::PatternMatcher g_Matcher
pesieve::SyscallTable g_SyscallTable
The root of the PE-sieve scanner.
@ SHELLC_PATTERNS_OR_STATS
detect shellcodes by patterns or stats (any match)
@ SHELLC_PATTERNS_AND_STATS
detect shellcodes by patterns and stats (both match)
@ SHELLC_PATTERNS
detect shellcodes by patterns
@ OUT_NO_DUMPS
don't dump the modified PEs, but save the report
@ OUT_NO_DIR
don't dump any files
#define PESIEVE_VERSION_STR
Final summary about the scanned process.
DWORD suspicious
general summary of suspicious