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
report_formatter.cpp
Go to the documentation of this file.
1#include "report_formatter.h"
2#include <string>
3#include <sstream>
4
5using namespace pesieve;
6
7std::string pesieve::scan_report_to_string(const ProcessScanReport &process_report)
8{
9 const t_report report = process_report.generateSummary();
10 std::stringstream stream;
11 //summary:
12 size_t other = report.other;
13 stream << "---" << std::endl;
14 stream << "PID: " << std::dec << report.pid << "\n";
15 stream << "---" << std::endl;
16 stream << "SUMMARY: \n" << std::endl;
17 stream << "Total scanned: " << std::dec << report.scanned << "\n";
18 stream << "Skipped: " << std::dec << report.skipped << "\n";
19 stream << "-\n";
20 stream << "Hooked: " << std::dec << report.patched << "\n";
21 stream << "Replaced: " << std::dec << report.replaced << "\n";
22 stream << "Hdrs Modified: " << std::dec << report.hdr_mod << "\n";
23 stream << "IAT Hooks: " << std::dec << report.iat_hooked << "\n";
24 stream << "Implanted: " << std::dec << report.implanted << "\n";
25 if (report.implanted) {
26 stream << "Implanted PE: " << std::dec << report.implanted_pe << "\n";
27 stream << "Implanted shc: " << std::dec << report.implanted_shc << "\n";
28 }
29 stream << "Unreachable files: " << std::dec << report.unreachable_file << "\n";
30 stream << "Other: " << std::dec << other << "\n";
31 stream << "-\n";
32 stream << "Total suspicious: " << std::dec << report.suspicious << "\n";
33 if (report.errors) {
34 stream << "[!] Errors: " << std::dec << report.errors << "\n";
35 }
36 return stream.str();
37}
38
40 t_results_filter filter,
41 size_t start_level
42)
43{
44 if ((filter & SHOW_ERRORS) == 0) {
45 return "";
46 }
47 //summary:
48 std::stringstream stream;
49
50 size_t level = start_level + 1;
51 OUT_PADDED(stream, start_level, "{\n"); // beginning of the report
52
53 OUT_PADDED(stream, level, "\"pid\" : ");
54 stream << std::dec << err_report.pid << ",\n";
55 OUT_PADDED(stream, level, "\"err_message\" : ");
56 stream << "\"" << err_report.message << "\"\n";
57 OUT_PADDED(stream, start_level, "}\n"); // end of the report
58
59 std::string report_all = stream.str();
60 if (report_all.length() == 0) {
61 return "";
62 }
63 return report_all;
64}
65
66
68 const ProcessScanReport &process_report,
69 t_results_filter filter,
70 const pesieve::t_json_level &jdetails,
71 size_t start_level
72)
73{
74 //summary:
75 std::stringstream stream;
76
77 if (!process_report.toJSON(stream, start_level, filter, jdetails)) {
78 return "";
79 }
80 std::string report_all = stream.str();
81 if (report_all.length() == 0) {
82 return "";
83 }
84 return report_all;
85}
86
88 const ProcessDumpReport& process_report,
89 const pesieve::t_json_level& jdetails,
90 size_t start_level
91)
92{
93 //summary:
94 std::stringstream stream;
95
96 if (!process_report.toJSON(stream, start_level)) {
97 return "";
98 }
99 std::string report_all = stream.str();
100 if (report_all.length() == 0) {
101 return "";
102 }
103 return report_all;
104}
105
106std::string pesieve::report_to_json(const pesieve::ReportEx& report, const t_report_type rtype, t_results_filter filter, const pesieve::t_json_level& jdetails, size_t start_level)
107{
108 if (rtype == REPORT_NONE) return 0;
109
110 size_t level = 1;
111 std::stringstream stream;
112
113 if (report.error_report && (filter & SHOW_ERRORS)) {
114 stream << "{\n";
115 OUT_PADDED(stream, level, "\"error_report\" :\n");
116 stream << err_report_to_json(*report.error_report, filter, level);
117 stream << "}\n";
118 return stream.str();
119 }
120 const bool has_dumps = (report.dump_report && report.dump_report->countDumped() > 0) ? true : false;
121 stream << "{\n";
122 if (report.scan_report && (rtype == REPORT_ALL || rtype == REPORT_SCANNED)) {
123 OUT_PADDED(stream, level, "\"scan_report\" :\n");
124 stream << scan_report_to_json(*report.scan_report, filter, jdetails, level);
125 if (rtype == REPORT_ALL && has_dumps) {
126 stream << ",";
127 }
128 stream << "\n";
129 }
130 if (rtype == REPORT_ALL || rtype == REPORT_DUMPED) {
131 if (has_dumps || rtype == REPORT_DUMPED) { // do not output an empty report, unless requested specifically
132 OUT_PADDED(stream, level, "\"dump_report\" :\n");
133 stream << dump_report_to_json(*report.dump_report, jdetails, level);
134 stream << "\n";
135 }
136 }
137 stream << "}\n";
138 return stream.str();
139}
const std::string message
The report aggregating the results of the performed dumps.
Definition dump_report.h:49
virtual bool toJSON(std::stringstream &stream, size_t level) const
The report aggregating the results of the performed scan.
Definition scan_report.h:19
virtual const bool toJSON(std::stringstream &stream, size_t level, const t_results_filter &filter, const pesieve::t_json_level &jdetails) const
pesieve::t_report generateSummary() const
The final report about the actions performed on the process: scanning and dumping.
#define OUT_PADDED(stream, field_size, str)
Definition format_util.h:12
std::string scan_report_to_string(const ProcessScanReport &report)
std::string dump_report_to_json(const ProcessDumpReport &process_report, const pesieve::t_json_level &jdetails, size_t start_level=0)
std::string err_report_to_json(const ErrorReport &err_report, t_results_filter filter, size_t start_level=0)
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 scan_report_to_json(const ProcessScanReport &process_report, t_results_filter filter, const pesieve::t_json_level &jdetails, size_t start_level=0)
t_results_filter
@ SHOW_ERRORS
@ REPORT_ALL
output all available reports
@ REPORT_DUMPED
output the dumps report
@ REPORT_NONE
do not output a report
@ REPORT_SCANNED
output the scan report
Final summary about the scanned process.
DWORD implanted
all implants: shellcodes + PEs
DWORD errors
the number of elements that could not be scanned because of errors. If errors == ERROR_SCAN_FAILURE,...
DWORD implanted_shc
implanted shellcodes
DWORD scanned
number of all scanned modules
DWORD patched
detected modifications in the code
DWORD suspicious
general summary of suspicious
DWORD iat_hooked
detected IAT hooks
DWORD hdr_mod
PE header is modified (but not replaced)
DWORD unreachable_file
cannot read the file corresponding to the module in memory
DWORD implanted_pe
the full PE was probably loaded manually
DWORD skipped
some of the modules must be skipped (i.e. dotNET managed code have different characteristics and this...
DWORD replaced
PE file replaced in memory (probably hollowed)
DWORD other
other indicators
DWORD pid
pid of the process that was scanned