-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateProcessW_Intercept.js
More file actions
55 lines (42 loc) · 1.98 KB
/
CreateProcessW_Intercept.js
File metadata and controls
55 lines (42 loc) · 1.98 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
var ptrCreateProcessW = Module.findExportByName("Kernel32.dll", "CreateProcessW");
// Global storage for the new command line buffer
var newCmdPtr = null;
let execCount = 0;
Interceptor.attach(ptrCreateProcessW, {
onEnter: function (args) {
var lpCommandLine = args[1].readUtf16String();
send("\n[#] CreateProcessW");
send("[#] Original command: " + lpCommandLine);
// Correctly formatted new command line
let new_lpCommandLine = "C:\\Windows\\System32\\cmd.exe /C C:\\Windows\\System32\\calc.exe";
if (execCount != 1) {
// Allocate buffer large enough for the string plus a null-terminator (UTF-16, 2 bytes per char)
var bufferSize = (new_lpCommandLine.length + 1) * 2; // +1 for the null terminator, *2 for UTF-16
newCmdPtr = Memory.alloc(bufferSize);
// Write the new command line string into the allocated memory
newCmdPtr.writeUtf16String(new_lpCommandLine);
// Replace the old command line argument with the new one
args[1] = newCmdPtr;
send("[#] Modified Command Line: " + new_lpCommandLine);
execCount += 1;
// Confirm that the command line has been correctly set
var conf_lpCommandLine = args[1].readUtf16String();
send("[##] Confirming Command Line: " + conf_lpCommandLine);
}
},
onLeave: function (retval) {
send("Process created (CreateProcessW).");
}
});
var ptrCreateProcessInternalW = Module.findExportByName("kernelbase.dll", "CreateProcessInternalW");
Interceptor.attach(ptrCreateProcessInternalW, {
onEnter: function (args) {
// `args[2]` corresponds to `lpCommandLine`
var lpCommandLine = args[2].readUtf16String();
send("\n[#] CreateProcessInternalW called.");
send("[#] Original command: " + lpCommandLine);
},
onLeave: function (retval) {
send("Process created (CreateProcessInternalW).");
}
});