Skip to content

Linux payload implementing HV exploits to run a custom bootloader

C

More cleanup.

Andy Nguyen50b28fb8c1f3
diff --git a/.gitignore b/.gitignore
index 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
*.o
diff --git a/Makefile b/Makefile
index a5e7676..bbd8cb9 100644
--- a/Makefile
+++ b/Makefile
@@ -10,16 +10,16 @@ BIN := bin/ps5-linux-loader.elf
SRC := $(wildcard source/*.c)
OBJS := $(SRC:.c=.o)
-CFLAGS := -std=c23 -Wall -Iinclude -Ishellcode_hypervisor -Ishellcode_kernel
+CFLAGS := -std=c23 -Wall -Iinclude -Ishellcode_hv -Ishellcode_kernel
LDFLAGS :=
-SC_HV_H := shellcode_hypervisor/shellcode_hypervisor.h
+SC_HV_H := shellcode_hv/shellcode_hv.h
SC_K_H := shellcode_kernel/shellcode_kernel.h
all: $(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 clean
diff --git a/shellcode_hypervisor/linux.h b/include/linux.h
similarity index 93%
rename from shellcode_hypervisor/linux.h
rename to include/linux.h
index 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];
+};
+
#endif
diff --git a/include/utils.h b/include/utils.h
index 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.c
extern uint64_t ktext; // Defined on utils.c
diff --git a/shellcode_hypervisor/Makefile b/shellcode_hv/Makefile
similarity index 88%
rename from shellcode_hypervisor/Makefile
rename to shellcode_hv/Makefile
index ae572e2..5aae236 100644
--- a/shellcode_hypervisor/Makefile
+++ b/shellcode_hv/Makefile
@@ -14,9 +14,9 @@ OBJCOPY = objcopy
endif
CFLAGS = -O2 -fno-stack-protector -ffreestanding -nostdlib -fcf-protection=none -m64 -I$(PS5_PAYLOAD_SDK)/target/include
LDFLAGS = -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.h
SRC = main.c utils.c boot_linux.c
OBJ = $(SRC:.c=.o)
diff --git a/shellcode_hypervisor/boot_linux.c b/shellcode_hv/boot_linux.c
similarity index 97%
rename from shellcode_hypervisor/boot_linux.c
rename to shellcode_hv/boot_linux.c
index 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.h
similarity index 100%
rename from shellcode_hypervisor/boot_linux.h
rename to shellcode_hv/boot_linux.h
diff --git a/shellcode_hypervisor/linker.ld b/shellcode_hv/linker.ld
similarity index 100%
rename from shellcode_hypervisor/linker.ld
rename to shellcode_hv/linker.ld
diff --git a/shellcode_hypervisor/main.c b/shellcode_hv/main.c
similarity index 100%
rename from shellcode_hypervisor/main.c
rename to shellcode_hv/main.c
diff --git a/shellcode_hypervisor/main.h b/shellcode_hv/main.h
similarity index 50%
rename from shellcode_hypervisor/main.h
rename to shellcode_hv/main.h
index 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.h
similarity index 91%
rename from shellcode_hypervisor/shellcode_hypervisor_args.h
rename to shellcode_hv/shellcode_hv_args.h
index 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 shellcode
uint64_t initrd_pa; // Already relocated by Kernel shellcode
uint64_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.c
similarity index 97%
rename from shellcode_hypervisor/utils.c
rename to shellcode_hv/utils.c
index 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.h
similarity index 100%
rename from shellcode_hypervisor/utils.h
rename to shellcode_hv/utils.h
diff --git a/shellcode_kernel/Makefile b/shellcode_kernel/Makefile
index 05a3cc4..042aab6 100644
--- a/shellcode_kernel/Makefile
+++ b/shellcode_kernel/Makefile
@@ -17,7 +17,7 @@ LDFLAGS = -T linker.ld
TARGET = shellcode_kernel.elf
TEXT_BIN = shellcode_kernel.bin
-SRC = main.c utils.c kernel_code.c
+SRC = main.c utils.c boot_linux.c
OBJ = $(SRC:.c=.o)
dump = shellcode_kernel.h
diff --git a/shellcode_kernel/kernel_code.c b/shellcode_kernel/boot_linux.c
similarity index 92%
rename from shellcode_kernel/kernel_code.c
rename to shellcode_kernel/boot_linux.c
index 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 mapping
uint8_t shellcode_jmp[] = {
diff --git a/shellcode_kernel/kernel_code.h b/shellcode_kernel/boot_linux.h
similarity index 90%
rename from shellcode_kernel/kernel_code.h
rename to shellcode_kernel/boot_linux.h
index 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.c
index 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.c
index 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.c
index 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.c
index 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>