Skip to content

Commit fe5f81b

Browse files
committed
[FEATURE] Added new argument: rebase to regulate if the dumped module should be rebased to its original base
1 parent 14aa1bb commit fe5f81b

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

include/pe_sieve_types.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ namespace pesieve {
5656
} t_obfusc_mode;
5757

5858
typedef enum {
59-
PE_IMPREC_NONE = 0, ///< do not try to recover imports
60-
PE_IMPREC_AUTO, ///< try to autodetect the most suitable mode
61-
PE_IMPREC_UNERASE, ///< recover erased parts of the partialy damaged import table
59+
PE_IMPREC_NONE = 0, ///< do not try to recover imports
60+
PE_IMPREC_AUTO, ///< try to autodetect the most suitable mode
61+
PE_IMPREC_UNERASE, ///< recover erased parts of the partialy damaged import table
6262
PE_IMPREC_REBUILD0, ///< build the import table from the scratch, basing on the found IAT(s): use only terminated blocks (restrictive mode)
6363
PE_IMPREC_REBUILD1, ///< build the import table from the scratch, basing on the found IAT(s): use terminated blocks, or blocks with more than 1 thunk
6464
PE_IMPREC_REBUILD2, ///< build the import table from the scratch, basing on the found IAT(s): use all found blocks (aggressive mode)
@@ -134,6 +134,7 @@ namespace pesieve {
134134
t_iat_scan_mode iat; ///< detect IAT hooking
135135
t_data_scan_mode data; ///< should scan non-executable pages?
136136
bool minidump; ///< make minidump of full process
137+
bool rebase; ///< rebase the module to its original base (if known)
137138
t_dump_mode dump_mode; ///< in which mode the detected PE implants should be dumped
138139
bool json_output; ///< display the final summary as the JSON report
139140
bool make_reflection; ///< operate on a process reflection rather than on the live process (this allows i.e. to force-read inaccessible pages)

params.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ using namespace pesieve;
2323
//dump options:
2424
#define PARAM_IMP_REC "imp"
2525
#define PARAM_DUMP_MODE "dmode"
26+
#define PARAM_REBASE "rebase"
2627
//output options:
2728
#define PARAM_OUT_FILTER "ofilter"
2829
#define PARAM_RESULTS_FILTER "report"
@@ -103,7 +104,10 @@ class PEsieveParams : public Params
103104
ss2 << INFO_SPACER << "Example: kernel32.dll" << PARAM_LIST_SEPARATOR << "user32.dll";
104105
this->setInfo(PARAM_MODULES_IGNORE, ss1.str(), ss2.str());
105106
}
106-
107+
108+
this->addParam(new BoolParam(PARAM_REBASE, false));
109+
this->setInfo(PARAM_REBASE, "Rebase the module to its original base (if known).");
110+
107111
this->addParam(new BoolParam(PARAM_QUIET, false));
108112
this->setInfo(PARAM_QUIET, "Print only the summary. Do not log on stdout during the scan.");
109113

@@ -236,6 +240,7 @@ class PEsieveParams : public Params
236240
this->addParamToGroup(PARAM_MINIDUMP, str_group);
237241
this->addParamToGroup(PARAM_IMP_REC, str_group);
238242
this->addParamToGroup(PARAM_DUMP_MODE, str_group);
243+
this->addParamToGroup(PARAM_REBASE, str_group);
239244

240245
str_group = "2. scan exclusions";
241246
this->addGroup(new ParamGroup(str_group));
@@ -270,7 +275,7 @@ class PEsieveParams : public Params
270275
copyVal<EnumParam>(PARAM_RESULTS_FILTER, ps.results_filter);
271276

272277
fillStringParam(PARAM_MODULES_IGNORE, ps.modules_ignored);
273-
278+
copyVal<BoolParam>(PARAM_REBASE, ps.rebase);
274279
copyVal<BoolParam>(PARAM_QUIET, ps.quiet);
275280
copyVal<BoolParam>(PARAM_JSON, ps.json_output);
276281

pe_sieve.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ namespace pesieve {
137137
dump_mode = pesieve::t_dump_mode(args.dump_mode);
138138
}
139139
size_t dumped_modules = 0;
140-
dumpReport = dumper.dumpDetectedModules(hProcess, isRefl, process_report, dump_mode, args.imprec_mode);
140+
dumpReport = dumper.dumpDetectedModules(hProcess, isRefl, process_report, dump_mode, args.imprec_mode, args.rebase);
141141
if (dumpReport && dumpReport->countDumped()) {
142142
dumped_modules = dumpReport->countDumped();
143143
}

postprocessors/results_dumper.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ pesieve::ProcessDumpReport* pesieve::ResultsDumper::dumpDetectedModules(
206206
bool isRefl,
207207
ProcessScanReport &process_report,
208208
const pesieve::t_dump_mode dump_mode,
209-
const t_imprec_mode imprec_mode)
209+
const t_imprec_mode imprec_mode,
210+
const bool rebase)
210211
{
211212
if (processHandle == nullptr) {
212213
return nullptr;
@@ -222,13 +223,15 @@ pesieve::ProcessDumpReport* pesieve::ResultsDumper::dumpDetectedModules(
222223
if (mod->status != SCAN_SUSPICIOUS) {
223224
continue;
224225
}
226+
ULONGLONG out_base = rebase ? mod->origBase : 0;
225227
dumpModule(processHandle,
226228
isRefl,
227229
process_report.modulesInfo,
228230
mod,
229231
process_report.exportsMap,
230232
dump_mode,
231233
imprec_mode,
234+
out_base,
232235
*dumpReport
233236
);
234237
}
@@ -260,6 +263,7 @@ bool pesieve::ResultsDumper::dumpModule(IN HANDLE processHandle,
260263
IN const peconv::ExportsMapper *exportsMap,
261264
IN const pesieve::t_dump_mode dump_mode,
262265
IN const t_imprec_mode imprec_mode,
266+
IN ULONGLONG out_base,
263267
OUT ProcessDumpReport &dumpReport
264268
)
265269
{
@@ -321,8 +325,8 @@ bool pesieve::ResultsDumper::dumpModule(IN HANDLE processHandle,
321325
modDumpReport->impRecMode = get_imprec_res_name(imprec_res);
322326

323327
module_buf.setRelocBase(mod->getRelocBase());
324-
if (mod->origBase) {
325-
module_buf.setRelocBase(mod->origBase);
328+
if (out_base) {
329+
module_buf.setRelocBase(out_base);
326330
}
327331
if (imprec_mode == pesieve::PE_IMPREC_NONE) {
328332
modDumpReport->isDumped = module_buf.dumpPeToFile(modDumpReport->dumpFileName, curr_dump_mode);

postprocessors/results_dumper.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ namespace pesieve {
1818
}
1919

2020
// dump all modules detected as suspicious during the process scan
21-
ProcessDumpReport* dumpDetectedModules(HANDLE hProcess, bool isRefl, ProcessScanReport &process_report, const pesieve::t_dump_mode dump_mode, const pesieve::t_imprec_mode imprec_mode);
21+
ProcessDumpReport* dumpDetectedModules(
22+
HANDLE hProcess,
23+
bool isRefl,
24+
ProcessScanReport &process_report,
25+
const pesieve::t_dump_mode dump_mode,
26+
const t_imprec_mode imprec_mode,
27+
const bool rebase
28+
);
2229

2330
// dump JSON report from the process scan
2431
bool dumpJsonReport(ProcessScanReport &process_report, const t_results_filter &filter, const pesieve::t_json_level &jdetails);
@@ -42,6 +49,7 @@ namespace pesieve {
4249
\param modReport : ModuleScanReport defining artefacts to be dumped
4350
\param exportsMap : mapping of all the exported APIs available within the process (for imports reconstruction)
4451
\param imprec_mode : mode in which imports reconstruction will be attempted
52+
\param out_base : the base to which the output module should be rebased, 0 if default
4553
\param dumpReport : ProcessDumpReport to which reports from the current dump will be appended
4654
*/
4755
bool dumpModule(
@@ -52,6 +60,7 @@ namespace pesieve {
5260
IN const peconv::ExportsMapper *exportsMap,
5361
IN const pesieve::t_dump_mode dump_mode,
5462
IN const pesieve::t_imprec_mode imprec_mode,
63+
IN ULONGLONG out_base,
5564
OUT ProcessDumpReport &dumpReport
5665
);
5766

0 commit comments

Comments
 (0)