forked from SeeFlowerX/stackplz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frida_hw_brk.js
72 lines (61 loc) · 1.95 KB
/
frida_hw_brk.js
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
function log(msg) {
console.log(`${msg}`);
}
async function SetHWBrk(brk_addr, brk_type) {
try {
let size_len = 4;
let brk_options = {
// brk_pid: Process.id,
brk_pid: -1,
brk_len: 4,
brk_type: brk_type,
brk_addr: brk_addr,
};
// open conn
log(`[SetHWBrk] open conn`);
// stackplz --rpc-path
let conn = await Socket.connect({
family: "ipv4",
host: "localhost",
port: 41718,
});
let payload = JSON.stringify(brk_options);
log(`brk_options -> ${payload}`);
let msg_len = payload.length;
// send payload size
let size_buffer = Memory.alloc(size_len);
size_buffer.writeU32(msg_len);
await conn.output.writeAll(size_buffer.readByteArray(size_len));
// send payload
let payload_buffer = Memory.alloc(payload.length);
payload_buffer.writeUtf8String(payload);
await conn.output.writeAll(payload_buffer.readByteArray(payload.length));
// try read resp size
let resp_size_buffer = await conn.input.readAll(size_len);
let resp_size = resp_size_buffer.unwrap().readU32();
let resp = await conn.input.readAll(resp_size);
log(`resp -> ${hexdump(resp)}`);
// close conn
await conn.close();
} catch (error) {
log(`[SetHWBrk] error ${error}`);
}
}
function do_hw_brk() {
// modify here
try {
let lib = Process.getModuleByName("libnative-lib.so");
SetHWBrk(lib.base.add(0xaaaa), "rw");
SetHWBrk(lib.base.add(0x1111), "x");
} catch (error) {
log(`error ${error}`);
}
}
rpc.exports = {
do_hw_brk: do_hw_brk
}
// ./stackplz --rpc --stack
// ./stackplz --rpc --stack --mstack
// ./stackplz --rpc --stack --mstack --regs
// ./stackplz --rpc --rpc-path 127.0.0.1:12345 --stack
// repl call rpc.exports.do_hw_brk()