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
main.cpp
Go to the documentation of this file.
1
6#include <windows.h>
7#include <psapi.h>
8#include <sstream>
9#include <fstream>
10
11#include "pe_sieve.h"
12#include "params.h"
13
17#include "utils/console_color.h"
18#include "color_scheme.h"
19
20
21using namespace pesieve;
22using namespace pesieve::util;
23
24
26{
27 if (!report.scan_report) return;
28
29 std::string report_str;
30 if (args.json_output) {
31 report_str = report_to_json(report, pesieve::REPORT_ALL, args.results_filter, args.json_lvl);
32 } else {
33 report_str = scan_report_to_string(*report.scan_report);
34 }
35 //summary:
36 std::cout << report_str;
37 if (!args.json_output) {
38 std::cout << "---" << std::endl;
39 }
40}
41
43{
44 free_strparam(args.modules_ignored);
45 free_strparam(args.pattern_file);
46}
47
48int main(int argc, char *argv[])
49{
50 t_params args = { 0 };
51 args.results_filter = SHOW_SUSPICIOUS;
52
54 if (argc < 2) {
55 uParams.printBanner();
56 uParams.printBriefInfo();
57 system("pause");
58 return PESIEVE_INFO;
59 }
60 if (!uParams.parse(argc, argv)) {
61 return PESIEVE_INFO;
62 }
63 uParams.fillStruct(args);
64 //---
65 // if scanning of inaccessible pages was requested, auto-enable reflection mode:
66 if (args.data == pesieve::PE_DATA_SCAN_INACCESSIBLE || args.data == pesieve::PE_DATA_SCAN_INACCESSIBLE_ONLY) {
67 if (!args.make_reflection) {
68 args.make_reflection = true;
69 if (!args.quiet) {
70 paramkit::print_in_color(paramkit::WARNING_COLOR, "[WARNING] Scanning of inaccessible pages requested: auto-enabled reflection mode!\n");
71 }
72 }
73 }
74 //print info about current settings:
75 if (!args.quiet) {
76 std::cout << "PID: " << args.pid << std::endl;
77 std::cout << "Output filter: " << translate_out_filter(args.out_filter) << std::endl;
78 std::cout << "Dump mode: " << translate_dump_mode(args.dump_mode) << std::endl;
79 }
80
83 if (report != nullptr) {
84 print_report(*report, args);
85 if (report->scan_report) {
86 pesieve::t_report summary = report->scan_report->generateSummary();
87 if (summary.scanned > 0) {
88 res = (summary.suspicious > 0) ? PESIEVE_DETECTED : PESIEVE_NOT_DETECTED;
89 }
90 }
91 delete report;
92 report = nullptr;
93 }
94
95 free_params(args);
96#ifdef _DEBUG
97 system("pause");
98#endif
99 return res;
100}
void printBanner()
Definition params.h:299
void fillStruct(t_params &ps)
Definition params.h:270
The final report about the actions performed on the process: scanning and dumping.
int main(int argc, char *argv[])
Definition main.cpp:48
void print_report(const pesieve::ReportEx &report, const t_params args)
Definition main.cpp:25
void free_params(t_params &args)
Definition main.cpp:42
std::string scan_report_to_string(const ProcessScanReport &report)
std::string translate_dump_mode(const DWORD dump_mode)
std::string report_to_json(const ReportEx &report, const t_report_type rtype, t_results_filter filter, const pesieve::t_json_level &jdetails, size_t start_level=0)
std::string translate_out_filter(const pesieve::t_output_filter o_filter)
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.
Definition pe_sieve.cpp:198
void free_strparam(PARAM_STRING &strparam)
Definition params.h:51
The root of the PE-sieve scanner.
@ PESIEVE_NOT_DETECTED
the process was scanned successfuly, and NO suspicious indicators are detected
@ PESIEVE_DETECTED
the process was scanned successfuly, and some suspicious indicators are detected
@ PESIEVE_ERROR
the scan has failed, PE-sieve returned an error
@ PESIEVE_INFO
PE-sieve was deployed in the info mode (i.e. displaying help)
@ SHOW_SUSPICIOUS
#define PESIEVE_VERSION_STR
Final summary about the scanned process.