From 2411c920d5be92105bc88ee7f3d9d13da590ec6e Mon Sep 17 00:00:00 2001 From: Awayume Date: Thu, 28 Mar 2024 14:14:32 +0900 Subject: [PATCH] add: Add crdreader --- Makefile | 9 +++++++++ src/crdreader.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Makefile create mode 100644 src/crdreader.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..91d3de7 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +.PHONY: build + +CC := x86_64-w64-mingw32-gcc-win32 +CFLAGS := -static -Wall -Wextra +TARGET := crdreader.exe +SRCS := src/crdreader.c + +build: + $(CC) -o $(TARGET) $(SRCS) diff --git a/src/crdreader.c b/src/crdreader.c new file mode 100644 index 0000000..3b1b200 --- /dev/null +++ b/src/crdreader.c @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: 2024 Awayume +// SPDX-License-Identifier: MIT + +#include + +#include +#include + + +int main() { + DWORD count; + PCREDENTIAL* credentials; + + if (!CredEnumerate(NULL, 0, &count, &credentials)) { + char message[] = "[ERROR] Failed to enumerate credentials:"; + switch (GetLastError()) { + case 1168: + printf("%s ERROR_NOT_FOUND (0x490)\n", message); + case 1312: + printf("%s ERROR_NO_SUCH_LOGON_SESSION (0x520)\n", message); + case 1004: + printf("%s ERROR_INVALID_FLAGS (0x3EC)\n", message); + defaut: + printf("%sUnknown error\n", message); + } + return 255; + } + + if (count == 0) { + printf("No credentials found!\n"); + return 0; + } + + printf("Credentials (total %d):\n", count); + for (DWORD i = 0; i < count; i++) { + LPSTR key = credentials[i]->TargetName; + LPBYTE value = credentials[i]->CredentialBlob; + printf(" %s: %s\n", key, value); + } +}