From 981e1fc1293a9e73dcf7681d4b26f3b8eb0043df Mon Sep 17 00:00:00 2001 From: ufrisk Date: Mon, 5 Sep 2016 19:33:27 +0200 Subject: [PATCH] Version 1.1 --- pcileech/device.c | 5 +- pcileech/device.h | 2 +- pcileech/help.c | 332 ++++++++++++++++++ pcileech/help.h | 14 + pcileech/kmd.c | 145 +++++++- pcileech/memdump.c | 58 +-- pcileech/mempatch.c | 166 ++++++--- pcileech/mempatch.h | 6 +- pcileech/pcileech.c | 153 ++------ pcileech/pcileech.h | 9 + pcileech/pcileech.vcxproj | 2 + pcileech/pcileech.vcxproj.filters | 6 + pcileech/shellcode.h | 46 +++ pcileech/util.c | 84 ++++- pcileech/util.h | 37 +- pcileech_files/pcileech.exe | Bin 167424 -> 184320 bytes pcileech_files/signature_info.txt | 34 +- pcileech_shellcode/pcileech_shellcode.vcxproj | 1 + .../pcileech_shellcode.vcxproj.filters | 3 + pcileech_shellcode/wx64_stage2_hal.asm | 244 +++++++++++++ readme.md | 52 ++- 21 files changed, 1122 insertions(+), 277 deletions(-) create mode 100644 pcileech/help.c create mode 100644 pcileech/help.h create mode 100644 pcileech_shellcode/wx64_stage2_hal.asm diff --git a/pcileech/device.c b/pcileech/device.c index 7e941db..e4ebdae 100644 --- a/pcileech/device.c +++ b/pcileech/device.c @@ -105,7 +105,7 @@ BOOL DeviceReadDMA(_In_ PDEVICE_DATA pDeviceData, _In_ DWORD dwAddrPci32, _Out_ DWORD i, dwChunk; if(cb % 0x1000) { return FALSE; } if(cb > 0x01000000) { return FALSE; } - if(_DeviceIsInReservedMemoryRange(dwAddrPci32, cb)) { return FALSE; } + if(_DeviceIsInReservedMemoryRange(dwAddrPci32, cb) && !pDeviceData->IsAllowedAccessReservedAddress) { return FALSE; } ZeroMemory(td, sizeof(THREAD_DATA_READ_EP) * 3); if(cb < 0x00300000 || !pDeviceData->IsAllowedMultiThreadDMA) { if(cb > 0x00800000) { // read max 8MB at a time. @@ -291,7 +291,7 @@ VOID DeviceOpen_SetPipePolicy(_In_ PDEVICE_DATA pDeviceData) WinUsb_SetPipePolicy(pDeviceData->WinusbHandle, pDeviceData->PipeDmaIn3, PIPE_TRANSFER_TIMEOUT, (ULONG)sizeof(BOOL), &ulTIMEOUT); } -BOOL DeviceOpen(_Out_ PDEVICE_DATA pDeviceData) +BOOL DeviceOpen(_In_ PCONFIG pCfg, _Out_ PDEVICE_DATA pDeviceData) { BOOL result; pDeviceData->HandlesOpen = FALSE; @@ -326,6 +326,7 @@ BOOL DeviceOpen(_Out_ PDEVICE_DATA pDeviceData) DeviceOpen_SetPipePolicy(pDeviceData); pDeviceData->HandlesOpen = TRUE; pDeviceData->IsAllowedMultiThreadDMA = IsWindows8OrGreater(); // multi threaded DMA read fails on WIN7. + pDeviceData->IsAllowedAccessReservedAddress = pCfg->fForceRW; return TRUE; } diff --git a/pcileech/device.h b/pcileech/device.h index 787c283..3ec1d4b 100644 --- a/pcileech/device.h +++ b/pcileech/device.h @@ -40,7 +40,7 @@ * -- pDeviceData = ptr to DeviceData to receive values on success. * -- result */ -BOOL DeviceOpen(_Out_ PDEVICE_DATA pDeviceData); +BOOL DeviceOpen(_In_ PCONFIG pCfg, _Out_ PDEVICE_DATA pDeviceData); /* * Clean up various device related stuff and deallocate some meoory buffers. diff --git a/pcileech/help.c b/pcileech/help.c new file mode 100644 index 0000000..3047e5d --- /dev/null +++ b/pcileech/help.c @@ -0,0 +1,332 @@ +// help.c : implementation related to displaying help texts. +// +// (c) Ulf Frisk, 2016 +// Author: Ulf Frisk, pcileech@frizk.net +// +#include "help.h" +#include "util.h" + +VOID ShowListFiles(_In_ LPSTR szSearchPattern) +{ + WIN32_FIND_DATAA data; + HANDLE h; + CHAR szSearch[MAX_PATH]; + Util_GetFileInDirectory(szSearch, szSearchPattern); + h = FindFirstFileA(szSearch, &data); + while(h != INVALID_HANDLE_VALUE) { + data.cFileName[strlen(data.cFileName) - 4] = 0; + printf(" %s\n", data.cFileName); + if(!FindNextFileA(h, &data)) { + return; + } + } +} + +VOID Help_ShowGeneral() +{ + printf( + " PCILEECH COMMAND LINE REFERENCE \n" \ + " PCILeech can run in two modes - DMA (default) and Kernel Module Assisted (KMD)\n" \ + " KMD mode may be triggered by supplying the option kmd and optionally cr3 / pt.\n" \ + " If an address is supplied in the kmd option pcileech will use the already ins-\n" \ + " erted KMD. The already inserted KMD will be left intact upon exit. If the KMD\n" \ + " contains a kernel mode signature the kernel module will be loaded and then un-\n" \ + " loaded on program exit ( except for the kmdload command ). \n" \ + " KMD mode may access all memory. DMA mode may only access memory below 4GB. \n" \ + " For more detailed help about a specific command type: pcileech -help\n" \ + " General syntax: pcileech.exe [- ] ... \n" \ + " Valid commands and valid MODEs [ and options ]: \n" \ + " info DMA,KMD \n" \ + " dump DMA,KMD [ min, max, out ] \n" \ + " patch DMA,KMD [ min, max, sig, all ] \n" \ + " write DMA,KMD [ min, in ] \n" \ + " search DMA,KMD [ min, max, sig, in, all ] \n" \ + " [implant] KMD [ in, out, s, 0..9 ] \n" \ + " kmdload DMA [ pt, cr3 ] \n" \ + " kmdexit KMD \n" \ + " 8051start DMA,KMD [ in ] \n" \ + " 8051stop DMA,KMD \n" \ + " flash DMA,KMD [ in ] \n" \ + " pagedisplay DMA,KMD [ min ] \n" \ + " testmemread DMA [ min ] \n" \ + " testmemreadwrite DMA [ min ] \n" \ + " Valid options: \n" \ + " -min : memory min address, valid range: 0x0..0xffffffffffffffff \n" \ + " default: 0x0 \n" \ + " For memory accesses over 0xffffffff KMD must be loaded. \n" \ + " note that the address must be given in hexadecimal format. \n" \ + " -max : memory max address, valid range: 0x0..0xffffffffffffffff \n" \ + " default: 0xffffffff (4GB) in standard mode \n" \ + " default: actual memory size in KMD mode \n" \ + " For memory accesses over 0xffffffff KMD must be loaded. \n" \ + " note that the address must be given in hexadecimal format. \n" \ + " -out : name of output file. \n" \ + " default: pcileech----