Created
January 24, 2024 16:14
-
-
Save WKL-Sec/7a27c980e0b88539e9b8304c31aa594e to your computer and use it in GitHub Desktop.
Example of DLL code designed for protecting C2 payloads by disabling them after a predefined 'kill date', ensuring secure and time-controlled operations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <iostream> | |
#include <chrono> | |
#include <ctime> | |
#include <sstream> | |
// White Knight Labs - Offensive Development Course | |
// DLL Kill Date Example | |
bool parseDate(const std::string& dateStr, std::tm& date) { | |
std::istringstream iss(dateStr); | |
char delimiter; | |
int day, month, year; | |
if (iss >> day >> delimiter >> month >> delimiter >> year) { | |
if (delimiter == '-' && year > 1900) { | |
date.tm_year = year - 1900; | |
date.tm_mon = month - 1; | |
date.tm_mday = day; | |
return true; | |
} | |
} | |
return false; | |
} | |
bool isDateInThePast(const std::string& inputDate) { | |
// Get the current date | |
auto current_time = std::chrono::system_clock::now(); | |
std::time_t current_date = std::chrono::system_clock::to_time_t(current_time); | |
// Parse the input date | |
std::tm check_date = {}; | |
if (!parseDate(inputDate, check_date)) { | |
std::cerr << "Invalid date format. Please use DD-MM-YYYY." << std::endl; | |
return true; // Treating invalid date as past date | |
} | |
// Convert check_date to time_t for comparison | |
std::time_t check_time = std::mktime(&check_date); | |
// Compare the dates | |
return std::difftime(check_time, current_date) < 0; | |
} | |
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { | |
switch (fdwReason) { | |
case DLL_PROCESS_ATTACH: | |
// Check if a specific date is in the past | |
if (isDateInThePast("01-01-2024")) { | |
std::cout << "The date is in the past. DLL loading halted." << std::endl; | |
return FALSE; // Prevents the DLL from loading | |
} | |
std::cout << "The date is not in the past. Continuing DLL loading." << std::endl; | |
// ... [Rest of your code] | |
break; | |
case DLL_THREAD_ATTACH: | |
// Code for thread attach | |
break; | |
case DLL_THREAD_DETACH: | |
// Code for thread detach | |
break; | |
case DLL_PROCESS_DETACH: | |
// Code for process detach | |
break; | |
} | |
return TRUE; // Allow the DLL to load | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment