From ccd465da54056af2f9903442f0be1e00b6590cbd Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 5 Aug 2016 20:30:44 +0200 Subject: [PATCH] Minidump upload --- src/Components/Modules/Exception.cpp | 53 +++++++++++++++++++--------- src/Components/Modules/Exception.hpp | 4 +-- src/Utils/Cryptography.cpp | 24 +++++++++++++ src/Utils/Cryptography.hpp | 7 ++++ src/Utils/WebIO.cpp | 13 +++---- 5 files changed, 77 insertions(+), 24 deletions(-) diff --git a/src/Components/Modules/Exception.cpp b/src/Components/Modules/Exception.cpp index 6f6f3a20..7f6a4957 100644 --- a/src/Components/Modules/Exception.cpp +++ b/src/Components/Modules/Exception.cpp @@ -9,24 +9,45 @@ namespace Components { - void Exception::UploadMinidump(std::string filename) + bool Exception::UploadMinidump(std::string filename) { -// Utils::WebIO webio("Firefucks", UPLOAD_URL); -// -// if (Utils::IO::FileExists(filename)) -// { -// std::string buffer = Utils::IO::ReadFile(filename); -// std::string result = webio.PostFile(buffer); -// -// MessageBoxA(0, result.data(), "Minidump", 0); -// } + Utils::WebIO webio("Firefucks", UPLOAD_URL); -// mg_mgr mgr; -// mg_mgr_init(&mgr, NULL); -// -// mg_connect_http -// -// mg_mgr_free(&mgr); + if (Utils::IO::FileExists(filename)) + { + std::string buffer = Utils::IO::ReadFile(filename); + std::string result = webio.PostFile(buffer); + + std::string errors; + json11::Json object = json11::Json::parse(result, errors); + + if (!object.is_object()) return false; + + json11::Json success = object["success"]; + + if (!success.is_bool() || !success.bool_value()) return false; + + json11::Json files = object["files"]; + + if (!files.is_array()) return false; + + for (auto file : files.array_items()) + { + json11::Json url = file["url"]; + json11::Json hash = file["hash"]; + + if (hash.is_string() && url.is_string()) + { + if (Utils::String::ToLower(Utils::Cryptography::SHA1::Compute(buffer, true)) == Utils::String::ToLower(hash.string_value())) + { + MessageBoxA(0, url.string_value().data(), 0, 0); + return true; + } + } + } + } + + return false; } LONG WINAPI Exception::ExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo) diff --git a/src/Components/Modules/Exception.hpp b/src/Components/Modules/Exception.hpp index c9f3c5d0..bb76e939 100644 --- a/src/Components/Modules/Exception.hpp +++ b/src/Components/Modules/Exception.hpp @@ -1,4 +1,4 @@ -#define UPLOAD_URL "https://momo5502.com/test/upload.php" +#define UPLOAD_URL "https://reich.io/upload.php" namespace Components { @@ -12,6 +12,6 @@ namespace Components static LONG WINAPI ExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo); static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilterStub(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter); - static void UploadMinidump(std::string filename); + static bool UploadMinidump(std::string filename); }; } diff --git a/src/Utils/Cryptography.cpp b/src/Utils/Cryptography.cpp index 68856132..91435c25 100644 --- a/src/Utils/Cryptography.cpp +++ b/src/Utils/Cryptography.cpp @@ -185,6 +185,30 @@ namespace Utils #pragma endregion +#pragma region SHA1 + + std::string SHA1::Compute(std::string data, bool hex) + { + return SHA1::Compute(reinterpret_cast(data.data()), data.size(), hex); + } + + std::string SHA1::Compute(const uint8_t* data, size_t length, bool hex) + { + uint8_t buffer[20] = { 0 }; + + hash_state state; + sha1_init(&state); + sha1_process(&state, data, length); + sha1_done(&state, buffer); + + std::string hash(reinterpret_cast(buffer), sizeof(buffer)); + if (!hex) return hash; + + return Utils::String::DumpHex(hash, ""); + } + +#pragma endregion + #pragma region SHA256 std::string SHA256::Compute(std::string data, bool hex) diff --git a/src/Utils/Cryptography.hpp b/src/Utils/Cryptography.hpp index ecae703f..66d58fe6 100644 --- a/src/Utils/Cryptography.hpp +++ b/src/Utils/Cryptography.hpp @@ -300,6 +300,13 @@ namespace Utils static std::string Compute(const uint8_t* data, size_t length, bool hex = false); }; + class SHA1 + { + public: + static std::string Compute(std::string data, bool hex = false); + static std::string Compute(const uint8_t* data, size_t length, bool hex = false); + }; + class SHA256 { public: diff --git a/src/Utils/WebIO.cpp b/src/Utils/WebIO.cpp index 5a6e01a7..78264bb0 100644 --- a/src/Utils/WebIO.cpp +++ b/src/Utils/WebIO.cpp @@ -144,15 +144,16 @@ namespace Utils { WebIO::Params headers; - std::string boundary = "xxxxxxxxx"; + std::string boundary = "----WebKitFormBoundaryHoLVocRsBxs71fU6"; headers["Content-Type"] = "multipart/form-data, boundary=" + boundary; - headers["Content-Length"] = fmt::sprintf("%u", data.size()); std::string body = "--" + boundary + "\r\n"; - body += "Content-Disposition: form-data; name=\"contents\"; filename=\"minidump.dmp\"\r\n"; + body += "Content-Disposition: form-data; name=\"files[]\"; filename=\"minidump.dmp\"\r\n"; body += "Content-Type: application/octet-stream\r\n\r\n"; body += data + "\r\n"; - body += "--" + boundary + "--"; + body += "--" + boundary + "--\r\n"; + + headers["Content-Length"] = fmt::sprintf("%u", body.size()); return WebIO::Execute("POST", body, headers); } @@ -248,9 +249,9 @@ namespace Utils return ""; } - if (headers.find("Content-type") == headers.end()) + if (headers.find("Content-Type") == headers.end()) { - headers["Content-type"] = "application/x-www-form-urlencoded"; + headers["Content-Type"] = "application/x-www-form-urlencoded"; } std::string finalHeaders;