diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2023-03-12 18:31:49 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2023-03-12 18:31:49 +0100 |
commit | cc3dbf16d29bf8f74c284d94a6da10ed004cf9d3 (patch) | |
tree | 5c235618261b1e07f6588d243f9cae70239d6434 /examples | |
parent | 683db70689b8e09fda983b254325fdc4b409ea14 (diff) |
AES256 support
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/driver-aes.bat | 27 | ||||
-rw-r--r-- | examples/driver-aes.cpp | 63 |
2 files changed, 90 insertions, 0 deletions
diff --git a/examples/driver-aes.bat b/examples/driver-aes.bat new file mode 100644 index 0000000..a8e5c7e --- /dev/null +++ b/examples/driver-aes.bat @@ -0,0 +1,27 @@ +@echo off +set SERVICE_NAME=ksocket +set DRIVER="%~dp0\driver-aes.sys" + +net session >nul 2>&1 +if NOT %ERRORLEVEL% EQU 0 ( + echo ERROR: This script requires Administrator privileges! + pause + exit /b 1 +) + +echo --------------------------------------- +echo -- Service Name: %SERVICE_NAME% +echo -- Driver......: %DRIVER% +echo --------------------------------------- + +sc create %SERVICE_NAME% binPath= %DRIVER% type= kernel +echo --------------------------------------- +sc start %SERVICE_NAME% +echo --------------------------------------- +sc query %SERVICE_NAME% +echo [PRESS A KEY TO STOP THE DRIVER] +pause +sc stop %SERVICE_NAME% +sc delete %SERVICE_NAME% +echo Done. +timeout /t 3 diff --git a/examples/driver-aes.cpp b/examples/driver-aes.cpp new file mode 100644 index 0000000..06b1dcd --- /dev/null +++ b/examples/driver-aes.cpp @@ -0,0 +1,63 @@ +#include <aes/aes256.hpp> + +extern "C" { +#include <ksocket/berkeley.h> +#include <ksocket/ksocket.h> +#include <ksocket/wsk.h> + +DRIVER_INITIALIZE DriverEntry; +DRIVER_UNLOAD DriverUnload; + +#define DebuggerPrint(...) \ + DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__); + +NTSTATUS +NTAPI +DriverEntry(_In_ PDRIVER_OBJECT DriverObject, + _In_ PUNICODE_STRING RegistryPath) { + UNREFERENCED_PARAMETER(DriverObject); + UNREFERENCED_PARAMETER(RegistryPath); + + { + ByteArray key = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}; + ByteArray enc, dec; + const char secret_message[] = "This is a top secret message."; + const size_t secret_message_len = strlen(secret_message); + + enc.clear(); + dec.clear(); + + { + Aes256 aes(key); + aes.encrypt_start(secret_message_len, enc); + aes.encrypt_continue((unsigned char *)secret_message, secret_message_len, + enc); + aes.encrypt_end(enc); + } + + { + Aes256 aes(key); + aes.decrypt_start(enc.size()); + aes.decrypt_continue(enc.data(), enc.size(), dec); + aes.decrypt_end(dec); + } + + if (memcmp(secret_message, dec.data(), secret_message_len) != 0) { + DebuggerPrint("%s\n", "AES secret message differs!"); + DebuggerPrint("Original.: %s\n", secret_message); + } + DebuggerPrint("Decrypted: %s\n", dec.data()); + } + + return STATUS_SUCCESS; +} + +VOID DriverUnload(_In_ struct _DRIVER_OBJECT *DriverObject) { + UNREFERENCED_PARAMETER(DriverObject); + + DebuggerPrint("Bye."); +} +} |