15#define DIR_SEPARATOR "\\"
16#define DEFAULT_BASE 0x10000000
22 if (!artefactRepot.
has_pe) {
34 case peconv::PE_DUMP_VIRTUAL:
36 case peconv::PE_DUMP_UNMAP:
38 case peconv::PE_DUMP_REALIGN:
48 return "IMP_NOT_FOUND";
50 return "IMP_RECOVERY_ERROR";
52 return "IMP_RECOVERY_NOT_APPLICABLE";
56 return "IMP_ALREADY_OK";
58 return "IMP_DIR_FIXED";
62 return "IMP_RECREATED_FILTER0";
64 return "IMP_RECREATED_FILTER1";
66 return "IMP_RECREATED_FILTER2";
74 case pesieve::PE_DUMP_AUTO:
75 return peconv::PE_DUMP_AUTO;
77 case pesieve::PE_DUMP_VIRTUAL:
78 return peconv::PE_DUMP_VIRTUAL;
80 case pesieve::PE_DUMP_UNMAP:
81 return peconv::PE_DUMP_UNMAP;
83 case pesieve::PE_DUMP_REALIGN:
84 return peconv::PE_DUMP_REALIGN;
86 return peconv::PE_DUMP_AUTO;
91 if (directory.length() == 0) {
106 std::string modulePath =
"";
107 if (GetModuleFileNameExA(processHandle, (HMODULE)mod.
module, szModName,
MAX_PATH)) {
108 modulePath = peconv::get_file_name(szModName);
118 std::stringstream stream;
124 if (!process_report.
toJSON(stream, level, filter, jdetails)) {
127 std::string report_all = stream.str();
128 if (report_all.length() == 0) {
134 std::ofstream json_report;
135 std::string report_path =
makeOutPath(
"scan_report.json");
136 json_report.open(report_path);
137 if (json_report.is_open() ==
false) {
140 json_report << report_all << std::endl;
141 if (json_report.is_open()) {
153 std::stringstream stream;
155 process_report.
toJSON(stream, level);
156 std::string report_all = stream.str();
157 if (report_all.empty()) {
163 std::ofstream json_report;
164 std::string report_path = makeOutPath(
"dump_report.json");
165 json_report.open(report_path);
166 if (json_report.is_open() ==
false) {
169 json_report << report_all << std::endl;
170 if (json_report.is_open()) {
179 std::stringstream stream;
183 if (err_content.empty()) {
190 std::ofstream json_report;
191 std::string report_path = makeOutPath(
"error_report.json");
192 json_report.open(report_path);
193 if (json_report.is_open() ==
false) {
196 json_report << err_content << std::endl;
197 if (json_report.is_open()) {
205 HANDLE processHandle,
212 if (processHandle ==
nullptr) {
230 dumpModule(processHandle,
246 if (!mod)
return false;
253 filled = module_buf.fillFromBuffer((ULONGLONG)mod->module, wsReport->
data_cache);
257 filled = module_buf.readRemote((ULONGLONG)mod->module, mod->moduleSize);
266 IN
const peconv::ExportsMapper *exportsMap,
273 if (!mod)
return false;
275 const bool save_imp_report =
true;
276 bool is_dumped =
false;
280 bool dump_shellcode =
false;
281 std::string payload_ext =
"";
283 PeBuffer module_buf(processHandle, isRefl);
284 bool is_corrupt_pe =
false;
286 if (artefactReport) {
290 dump_shellcode =
true;
292 if (artefactReport->
has_pe) {
296 is_corrupt_pe =
true;
297 payload_ext =
"corrupt_" + payload_ext;
299 std::cout <<
"[-] Reconstructing PE at: " << std::hex << (ULONGLONG)found_pe_base <<
" failed." << std::endl;
305 if (!artefactReport || is_corrupt_pe) {
306 fillModuleCopy(mod, module_buf);
309 if (payload_ext.length() == 0) {
310 payload_ext = module_buf.
isValidPe() ?
"dll" :
"shc";
315 dumpReport.appendReport(modDumpReport);
321 peconv::ImpsNotCovered notCovered;
332 ULONGLONG out_base = 0;
334 out_base = mod->origBase;
340 if (imprec_mode == pesieve::PE_IMPREC_NONE) {
349 curr_dump_mode = peconv::PE_DUMP_VIRTUAL;
351 if (curr_dump_mode != peconv::PE_DUMP_VIRTUAL && out_base) {
356 if (iat_not_rebuilt || save_imp_report) {
357 std::string imports_file = modDumpReport->
dumpFileName +
".imports.txt";
362 std::string imports_not_rec_file = modDumpReport->
dumpFileName +
".not_fixed_imports.txt";
368 if (!modDumpReport->
isDumped || dump_shellcode)
370 if (dump_shellcode) {
374 fillModuleCopy(mod, module_buf);
377 dumpReport.appendReport(modDumpReport);
382 curr_dump_mode = peconv::PE_DUMP_VIRTUAL;
388 std::string mode_info = modDumpReport->
mode_info;
389 if (mode_info.length() > 0) mode_info =
" as " + mode_info;
390 std::cout <<
"[*] Dumped module to: " + modDumpReport->
dumpFileName + mode_info <<
"\n";
395 std::cerr <<
"[-] Failed dumping module!" << std::endl;
401 if (codeScanReport) {
402 std::string tags_file = modDumpReport->
dumpFileName +
".tag";
412 std::string tags_file = modDumpReport->
dumpFileName +
".pattern.tag";
422 if (iatHooksReport) {
423 std::string imports_not_rec_file = modDumpReport->
dumpFileName +
".iat_hooks.txt";
425 if (iatHooksReport->
generateList(imports_not_rec_file, processHandle, modulesInfo, exportsMap)) {
438 std::string inner_dir = this->dumpDir;
439 if (baseDir.length() > 0) {
445 if (baseDir.length() > 0) {
449 if (this->dumpDir.length() > 0) {
450 stream << this->dumpDir;
457 std::stringstream stream;
458 makeAndJoinDirectories(stream);
459 stream << std::hex << modBaseAddr;
460 if (fname.length() > 0) {
464 stream <<
"." << default_extension;
471 std::stringstream stream;
472 makeAndJoinDirectories(stream);
474 if (fname.length() > 0) {
478 stream << std::dec << time(
nullptr);
479 stream << default_extension;
486 std::stringstream stream;
487 stream <<
"process_";
488 stream << process_id;
A report from the artefacts scan, generated by ArtefactScanner.
A report from the code scan, generated by CodeScanner.
size_t generateTags(const std::string &reportPath)
A report from an IAT scan, generated by IATScanner.
bool generateList(IN const std::string &fileName, IN HANDLE hProcess, IN const ModulesInfo &modulesInfo, IN const peconv::ExportsMapper *exportsMap)
static bool saveNotRecovered(IN const std::string &fileName, IN HANDLE hProcess, IN peconv::ImportsCollection *storedFunc, IN peconv::ImpsNotCovered ¬Covered, IN const ModulesInfo &modulesInfo, IN const peconv::ExportsMapper *exportsMap)
t_imprec_res rebuildImportTable(const IN peconv::ExportsMapper *exportsMap, IN const pesieve::t_imprec_mode &imprec_mode)
bool printFoundIATs(const std::string &reportPath)
@ IMP_RECOVERY_NOT_APPLICABLE
enum pesieve::ImpReconstructor::imprec_res t_imprec_res
std::string notRecoveredFileName
std::string hooksTagFileName
std::string iatHooksFileName
std::string impListFileName
std::string patternsTagFileName
A base class of all the reports detailing on the output of the performed module's scan.
A container of all the process modules that were scanned.
void setRelocBase(ULONGLONG reloc_base)
size_t getBufferSize() const
bool dumpPeToFile(IN std::string dumpFileName, IN OUT peconv::t_pe_dump_mode &dumpMode, IN OPTIONAL const peconv::ExportsMapper *exportsMap=NULL, OUT OPTIONAL peconv::ImpsNotCovered *notCovered=NULL)
ULONGLONG getModuleBase() const
bool dumpToFile(IN std::string dumpFileName)
The report aggregating the results of the performed dumps.
virtual bool toJSON(std::stringstream &stream, size_t level) const
bool hasModule(const ULONGLONG modBase, const size_t modSize) const
The report aggregating the results of the performed scan.
virtual const bool toJSON(std::stringstream &stream, size_t level, const t_results_filter &filter, const pesieve::t_json_level &jdetails) const
peconv::ExportsMapper * exportsMap
std::vector< ModuleScanReport * > moduleReports
bool hasAnyShownType(const t_results_filter &filter)
std::string makeModuleDumpPath(ULONGLONG modBaseAddr, const std::string &fname, const std::string &defaultExtension)
std::string makeDirName(const DWORD process_id)
bool fillModuleCopy(IN ModuleScanReport *mod, IN OUT PeBuffer &module_buf)
void makeAndJoinDirectories(std::stringstream &name_stream)
std::string makeOutPath(const std::string &fname, const std::string &defaultExtension="")
bool dumpModule(IN HANDLE processHandle, IN bool isRefl, IN const ModulesInfo &modulesInfo, IN ModuleScanReport *modReport, IN const peconv::ExportsMapper *exportsMap, IN const pesieve::t_dump_mode dump_mode, IN const pesieve::t_imprec_mode imprec_mode, IN bool rebase, OUT ProcessDumpReport &dumpReport)
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)
bool dumpJsonReport(ProcessScanReport &process_report, const t_results_filter &filter, const pesieve::t_json_level &jdetails)
A report from the working set scan, generated by WorkingSetScanner.
util::ByteBuffer data_cache
size_t generateTags(const std::string &reportPath)
bool create_dir_recursively(const std::string &path)
std::string get_imprec_res_name(const ImpReconstructor::t_imprec_res &res)
std::string get_payload_ext(const ArtefactScanReport &artefactRepot)
std::string err_report_to_json(const ErrorReport &err_report, t_results_filter filter, size_t start_level=0)
peconv::t_pe_dump_mode convert_to_peconv_dump_mode(const pesieve::t_dump_mode dump_mode)
std::string get_module_file_name(HANDLE processHandle, const ModuleScanReport &mod)
bool make_dump_dir(const std::string &directory)
std::string get_dump_mode_name(peconv::t_pe_dump_mode dump_mode)