Linux payload implementing HV exploits to run a custom bootloader
C
More cleanup.
Andy Nguyen50b28fb8c1f3
diff --git a/.gitignore b/.gitignoreindex 0e4cabf..1a85b78 100644--- a/.gitignore+++ b/.gitignore@@ -1,6 +1,6 @@bin/shellcode_kernel/shellcode_kernel.h-shellcode_hypervisor/shellcode_hypervisor.h+shellcode_hv/shellcode_hv.h*.elf*.bin*.odiff --git a/Makefile b/Makefileindex a5e7676..bbd8cb9 100644--- a/Makefile+++ b/Makefile@@ -10,16 +10,16 @@ BIN := bin/ps5-linux-loader.elfSRC := $(wildcard source/*.c)OBJS := $(SRC:.c=.o)-CFLAGS := -std=c23 -Wall -Iinclude -Ishellcode_hypervisor -Ishellcode_kernel+CFLAGS := -std=c23 -Wall -Iinclude -Ishellcode_hv -Ishellcode_kernelLDFLAGS :=-SC_HV_H := shellcode_hypervisor/shellcode_hypervisor.h+SC_HV_H := shellcode_hv/shellcode_hv.hSC_K_H := shellcode_kernel/shellcode_kernel.hall: $(SC_HV_H) $(SC_K_H) $(BIN)$(SC_HV_H):- $(MAKE) -C shellcode_hypervisor+ $(MAKE) -C shellcode_hv$(SC_K_H):$(MAKE) -C shellcode_kernel@@ -33,5 +33,5 @@ $(BIN): $(OBJS)clean:rm -f $(BIN) $(OBJS)- $(MAKE) -C shellcode_hypervisor clean+ $(MAKE) -C shellcode_hv clean$(MAKE) -C shellcode_kernel cleandiff --git a/shellcode_hypervisor/linux.h b/include/linux.hsimilarity index 93%rename from shellcode_hypervisor/linux.hrename to include/linux.hindex d985f3c..8305187 100644--- a/shellcode_hypervisor/linux.h+++ b/include/linux.h@@ -1,7 +1,7 @@#ifndef __LINUX_H__#define __LINUX_H__-#include <stdint.h>+#include <unistd.h>#define X86_SUBARCH_PS5 5@@ -104,4 +104,15 @@ struct boot_params {uint8_t _pad9[276]; // 0xeec} __attribute__((packed));+struct linux_info {+ uintptr_t linux_info; // PA of linux_info+ uintptr_t bzimage;+ size_t bzimage_size;+ uintptr_t initrd;+ size_t initrd_size;+ size_t vram_size;+ int kit_type;+ char cmdline[2048];+};+#endifdiff --git a/include/utils.h b/include/utils.hindex 562e9b3..5086f9a 100644--- a/include/utils.h+++ b/include/utils.h@@ -35,17 +35,6 @@ typedef struct __flat_pmap {uint64_t pm_cr3;} flat_pmap;-struct linux_info {- uintptr_t bzimage;- size_t bzimage_size;- uintptr_t initrd;- size_t initrd_size;- size_t vram_size;- char cmdline[2048];- int kit_type;- uintptr_t linux_info; // PA of linux_info-};-/** These vars are global for the payload to simplify things */extern offset_list env_offset; // Defined on utils.cextern uint64_t ktext; // Defined on utils.cdiff --git a/shellcode_hypervisor/Makefile b/shellcode_hv/Makefilesimilarity index 88%rename from shellcode_hypervisor/Makefilerename to shellcode_hv/Makefileindex ae572e2..5aae236 100644--- a/shellcode_hypervisor/Makefile+++ b/shellcode_hv/Makefile@@ -14,9 +14,9 @@ OBJCOPY = objcopyendifCFLAGS = -O2 -fno-stack-protector -ffreestanding -nostdlib -fcf-protection=none -m64 -I$(PS5_PAYLOAD_SDK)/target/includeLDFLAGS = -T linker.ld-TARGET = shellcode_hypervisor.elf-TEXT_BIN = shellcode_hypervisor.bin-dump = shellcode_hypervisor.h+TARGET = shellcode_hv.elf+TEXT_BIN = shellcode_hv.bin+dump = shellcode_hv.hSRC = main.c utils.c boot_linux.cOBJ = $(SRC:.c=.o)diff --git a/shellcode_hypervisor/boot_linux.c b/shellcode_hv/boot_linux.csimilarity index 97%rename from shellcode_hypervisor/boot_linux.crename to shellcode_hv/boot_linux.cindex d1f49f2..76120d0 100644--- a/shellcode_hypervisor/boot_linux.c+++ b/shellcode_hv/boot_linux.c@@ -1,20 +1,10 @@#include "boot_linux.h"#include "../include/config.h"-#include "linux.h"+#include "../include/linux.h"#include "utils.h"#include <stddef.h>#include <stdint.h>-struct linux_info {- uintptr_t bzimage;- size_t bzimage_size;- uintptr_t initrd;- size_t initrd_size;- size_t vram_size;- char cmdline[2048];- int kit_type;-};-static struct linux_info info;static volatile int exited_cpus = 0;diff --git a/shellcode_hypervisor/boot_linux.h b/shellcode_hv/boot_linux.hsimilarity index 100%rename from shellcode_hypervisor/boot_linux.hrename to shellcode_hv/boot_linux.hdiff --git a/shellcode_hypervisor/linker.ld b/shellcode_hv/linker.ldsimilarity index 100%rename from shellcode_hypervisor/linker.ldrename to shellcode_hv/linker.lddiff --git a/shellcode_hypervisor/main.c b/shellcode_hv/main.csimilarity index 100%rename from shellcode_hypervisor/main.crename to shellcode_hv/main.cdiff --git a/shellcode_hypervisor/main.h b/shellcode_hv/main.hsimilarity index 50%rename from shellcode_hypervisor/main.hrename to shellcode_hv/main.hindex bfedeaa..b23b383 100644--- a/shellcode_hypervisor/main.h+++ b/shellcode_hv/main.h@@ -1,3 +1,3 @@-#include "shellcode_hypervisor_args.h"+#include "shellcode_hv_args.h"#include <stdarg.h>#include <stdint.h>diff --git a/shellcode_hypervisor/shellcode_hypervisor_args.h b/shellcode_hv/shellcode_hv_args.hsimilarity index 91%rename from shellcode_hypervisor/shellcode_hypervisor_args.hrename to shellcode_hv/shellcode_hv_args.hindex aac5ffa..92d7ff8 100644--- a/shellcode_hypervisor/shellcode_hypervisor_args.h+++ b/shellcode_hv/shellcode_hv_args.h@@ -6,4 +6,4 @@ typedef struct {uint64_t bzimage_pa; // Already relocated by Kernel shellcodeuint64_t initrd_pa; // Already relocated by Kernel shellcodeuint64_t linux_info_pa; // Already relocated by Kernel shellcode-} shellcode_hypervisor_args;+} shellcode_hv_args;diff --git a/shellcode_hypervisor/utils.c b/shellcode_hv/utils.csimilarity index 97%rename from shellcode_hypervisor/utils.crename to shellcode_hv/utils.cindex 44652a1..2a5c462 100644--- a/shellcode_hypervisor/utils.c+++ b/shellcode_hv/utils.c@@ -1,8 +1,8 @@#include "utils.h"-#include "shellcode_hypervisor_args.h"+#include "shellcode_hv_args.h"#include <cpuid.h>-extern shellcode_hypervisor_args args;+extern shellcode_hv_args args;__attribute__((noinline, optimize("O0"))) uint32_t putc_uart(uint8_t tx_byte) {volatile uint32_t *uart_tx = (volatile uint32_t *)0xc1010104ULL;diff --git a/shellcode_hypervisor/utils.h b/shellcode_hv/utils.hsimilarity index 100%rename from shellcode_hypervisor/utils.hrename to shellcode_hv/utils.hdiff --git a/shellcode_kernel/Makefile b/shellcode_kernel/Makefileindex 05a3cc4..042aab6 100644--- a/shellcode_kernel/Makefile+++ b/shellcode_kernel/Makefile@@ -17,7 +17,7 @@ LDFLAGS = -T linker.ldTARGET = shellcode_kernel.elfTEXT_BIN = shellcode_kernel.bin-SRC = main.c utils.c kernel_code.c+SRC = main.c utils.c boot_linux.cOBJ = $(SRC:.c=.o)dump = shellcode_kernel.hdiff --git a/shellcode_kernel/kernel_code.c b/shellcode_kernel/boot_linux.csimilarity index 92%rename from shellcode_kernel/kernel_code.crename to shellcode_kernel/boot_linux.cindex 96eedff..63430db 100644--- a/shellcode_kernel/kernel_code.c+++ b/shellcode_kernel/boot_linux.c@@ -1,7 +1,8 @@-#include "kernel_code.h"+#include "boot_linux.h"#include "../include/config.h"-#include "../shellcode_hypervisor/shellcode_hypervisor.h"-#include "../shellcode_hypervisor/shellcode_hypervisor_args.h"+#include "../include/linux.h"+#include "../shellcode_hv/shellcode_hv.h"+#include "../shellcode_hv/shellcode_hv_args.h"#include "shellcode_kernel_args.h"#include "utils.h"#include <unistd.h>@@ -41,16 +42,6 @@ struct dig_transmitter_control_parameters_v1_6 {uint32_t reserved1;};-struct linux_info {- uintptr_t bzimage;- size_t bzimage_size;- uintptr_t initrd;- size_t initrd_size;- size_t vram_size;- char cmdline[2048];- int kit_type;-};-static struct linux_info info;static int mp3_req[1281], mp3_rsp[1282];@@ -119,8 +110,8 @@ static void patch_hv(void) {}// Install hv_shellcode 2- memcpy((void *)PHYS_TO_DMAP(cave_hv_code), shellcode_hypervisor_bin,- shellcode_hypervisor_bin_len);+ memcpy((void *)PHYS_TO_DMAP(cave_hv_code), shellcode_hv_bin,+ shellcode_hv_bin_len);// Jump to shellcode final identity mappinguint8_t shellcode_jmp[] = {diff --git a/shellcode_kernel/kernel_code.h b/shellcode_kernel/boot_linux.hsimilarity index 90%rename from shellcode_kernel/kernel_code.hrename to shellcode_kernel/boot_linux.hindex ba0c49a..58a552d 100644--- a/shellcode_kernel/kernel_code.h+++ b/shellcode_kernel/boot_linux.h@@ -1,5 +1,5 @@-#ifndef KERNEL_CODE_H-#define KERNEL_CODE_H+#ifndef BOOT_LINUX_H+#define BOOT_LINUX_H#include <stdint.h>diff --git a/shellcode_kernel/main.c b/shellcode_kernel/main.cindex a8ecbc2..327e70e 100644--- a/shellcode_kernel/main.c+++ b/shellcode_kernel/main.c@@ -1,5 +1,5 @@#include "main.h"-#include "kernel_code.h"+#include "boot_linux.h"#include "utils.h"#include <stdint.h>diff --git a/source/loader.c b/source/loader.cindex ff93d91..eab9c35 100644--- a/source/loader.c+++ b/source/loader.c@@ -1,6 +1,7 @@#include "loader.h"#include "config.h"#include "firmware.h"+#include "linux.h"#include "utils.h"#include <errno.h>#include <fcntl.h>diff --git a/source/main.c b/source/main.cindex 8037a06..25e6559 100644--- a/source/main.c+++ b/source/main.c@@ -2,6 +2,7 @@#include "../shellcode_kernel/shellcode_kernel.h"#include "../shellcode_kernel/shellcode_kernel_args.h"#include "hv_defeat.h"+#include "linux.h"#include "loader.h"#include "offsets.h"#include "utils.h"diff --git a/source/utils.c b/source/utils.cindex 3bdf273..9e01863 100644--- a/source/utils.c+++ b/source/utils.c@@ -1,4 +1,5 @@#include "utils.h"+#include "linux.h"#include "offsets.h"#include <ps5/kernel.h>#include <stdio.h>