-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKernelBase_WriteFile.js
More file actions
55 lines (45 loc) · 2.04 KB
/
KernelBase_WriteFile.js
File metadata and controls
55 lines (45 loc) · 2.04 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
function getASCIIString(buffPtr, buffSize) {
let asciiString = "";
for (let i = 0; i < buffSize; i++) {
try {
let byte = buffPtr.add(i).readU8();
if (byte >= 32 && byte <= 126) { // Check if the byte is a printable ASCII character
asciiString += String.fromCharCode(byte);
}
} catch (error) {
send(`[!] Error reading memory at offset ${i}: ${error.message}`);
break;
}
}
return asciiString;
}
// Intercepting KernelBase.dll WriteFile function
Interceptor.attach(Module.findExportByName("KernelBase.dll", "WriteFile"), {
onEnter: function (args) {
// args[0]: hFile (HANDLE to the file)
// args[1]: lpBuffer (pointer to buffer containing data to be written)
// args[2]: nNumberOfBytesToWrite (number of bytes to write)
// args[3]: lpNumberOfBytesWritten (pointer to variable that receives number of bytes written)
this.hFile = args[0]; // Store the file handle for later
this.lpBuffer = args[1]; // Store the buffer pointer
this.nNumberOfBytesToWrite = args[2].toInt32(); // Store the number of bytes to write
// Send relevant information
send("WriteFile called: File Handle: " + this.hFile.toString() + ", Bytes to write: " + this.nNumberOfBytesToWrite);
// Read the full buffer content
var bufferContent = this.lpBuffer.readByteArray(this.nNumberOfBytesToWrite);
var hexContent = hexdump(bufferContent, {
offset: 0,
length: this.nNumberOfBytesToWrite, // Read the full length of the buffer
header: true,
ansi: false
});
// Send hex content as a string (full content)
send("Full Buffer content:\n" + hexContent);
let ascii_str = getASCIIString(this.lpBuffer, this.nNumberOfBytesToWrite);
send("ASCII: \n" + ascii_str);
},
onLeave: function (retval) {
// Send the result of the WriteFile call
send("WriteFile returned: " + retval.toString());
}
});