-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #82 Adds -d and -V flags, Add unsupported RFG notice #83
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#include <ostream> | ||
#include <vector> | ||
#include <optional> | ||
#include <string> | ||
|
||
#include "vendor/json.hpp" | ||
using json = nlohmann::json; | ||
|
@@ -161,6 +162,65 @@ Checksec::operator json() const { | |
}; | ||
} | ||
|
||
const std::string Checksec::detailedReport() const { | ||
json j = toJson(); | ||
std::string s = ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you mentioned not being experienced with C++: the idiomatic way to do this kind of function is with a |
||
std::string sep = ""; | ||
std::vector<std::vector<std::string>> name_keys{ | ||
{"Dynamic Base", "dynamicBase"}, | ||
{"ASLR", "aslr"}, | ||
{"High Entropy VA", "highEntropyVA"}, | ||
{"Force Integrity", "forceIntegrity"}, | ||
{"Isolation", "isolation"}, | ||
{"NX", "nx"}, | ||
{"SEH", "seh"}, | ||
{"CFG", "cfg"}, | ||
{"RFG", "rfg"}, | ||
{"SafeSEH", "safeSEH"}, | ||
{"GS", "gs"}, | ||
{"Authenticode", "authenticode"}, | ||
{".NET", "dotNET"}, | ||
}; | ||
|
||
for (std::vector<std::string> name_key : name_keys) { | ||
std::string name = name_key[0]; | ||
std::string key = name_key[1]; | ||
|
||
s += sep; | ||
sep = "\n"; | ||
s += "Mitigation: " + name + "\n"; | ||
s += "Presence: " + std::string(j["mitigations"][key]["presence"]) + "\n"; | ||
|
||
std::string word = ""; | ||
size_t col = 0; | ||
size_t max = 54; | ||
s += "Description: "; | ||
|
||
for (char c : std::string(j["mitigations"][key]["description"])) { | ||
if (c == ' ') { | ||
if (word.length() + col > max) { | ||
s += "\n "; | ||
col = word.length(); | ||
} else if (col == 0) { | ||
col = word.length(); | ||
} else { | ||
s += " "; | ||
col += word.length(); | ||
} | ||
s += word; | ||
word = std::string(""); | ||
} else { | ||
word += c; | ||
} | ||
} | ||
s += ' ' + word + "\n"; | ||
if (!j["mitigations"][key]["explanation"].is_null()) { | ||
s += "Explanation: " + std::string(j["mitigations"][key]["explanation"]) + "\n"; | ||
} | ||
} | ||
return s; | ||
} | ||
|
||
const MitigationReport Checksec::isDynamicBase() const { | ||
if (dllCharacteristics_ & peparse::IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) { | ||
return REPORT(Present, kDynamicBaseDescription); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,8 +60,9 @@ constexpr const char kAuthenticodeDescription[] = | |
"Binaries with Authenticode signatures are verified at load time."; | ||
|
||
constexpr const char kRFGDescription[] = | ||
"Binaries with RFG enabled have additional return-oriented-programming " | ||
"protections."; | ||
// https://www.techrepublic.com/article/windows-10-security-how-the-shadow-stack-will-help-to-keep-the-hackers-at-bay/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This link is pretty light on details, consider replacing it with this one: https://xlab.tencent.com/en/2016/11/02/return-flow-guard/ Also, please put it above the variable declaration 🙂 |
||
"(This was never released by Microsoft). Binaries with RFG enabled have " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIt: Remove the parens and put this sentence at the end of the description. |
||
"additional return-oriented-programming protections."; | ||
|
||
constexpr const char kSafeSEHDescription[] = | ||
"Binaries with SafeSEH enabled have additional protections for stack-based " | ||
|
@@ -143,6 +144,8 @@ class Checksec { | |
|
||
json toJson() const; | ||
|
||
const std::string detailedReport() const; | ||
|
||
/** | ||
* @return a MitigationReport indicating whether the program can be loaded from a dynamic base | ||
* address (i.e. `/DYNAMICBASE`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we currently want this functionality: it'll be a little unwieldy to maintain (since we don't currently have a nice way to just enumerate all of our checks), and its existence on the main
Checksec
class is another place where we fail to isolate with CLI from the C++ public API.I'm happy to merge the rest of this PR, though.