Repository navigation
Expand file tree
/
Copy pathhook_writemem.js
More file actions
100 lines (89 loc) · 2.55 KB
/
Copy pathhook_writemem.js
File metadata and controls
100 lines (89 loc) · 2.55 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
// Utils
function log(message){
send({log:'['+new Date().toISOString()+'] '+message});
}
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
};
function read_string_param(fname, arg, length){
if (parseInt(args[i])===0){ return null; }
length = typeof length === 'undefined' ? 50 : length;
try {
if (endsWith(fname,'W')){ return Memory.readUtf16String(ptr(args[i]),50); }
else { return Memory.readANSIString(ptr(args[i]),50); }
}
catch (e){
return e;
}
};
//Function interceptor
/*
BOOL WINAPI WriteProcessMemory(
_In_ HANDLE hProcess,
_In_ LPVOID lpBaseAddress,
_In_ LPCVOID lpBuffer,
_In_ SIZE_T nSize,
_Out_ SIZE_T *lpNumberOfBytesWritten
);
* */
function i_WriteProcessMemory(fname, msg, args){
var handle=ptr(args[0]),addr=args[1],buff=ptr(args[2]), buflen=args[3];
msg['writemem'] = {
time : new Date().toISOString(),
buff : Memory.readByteArray(buff, buflen)
};
}
function o_WriteProcessMemory(fname, msg, retfal){
}
/*
BOOL WINAPI CreateProcess(
_In_opt_ LPCTSTR lpApplicationName,
_Inout_opt_ LPTSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCTSTR lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
*/
function i_CreateProcess(fname, msg, args){
var process_info = ptr(args[9]);
this.proc_pid=0;//buff;
}
function o_CreateProcess(fname, msg, retfal){
}
// Code
var exportcallbacks = {};
exportcallbacks.onMatch = function (mod){
var fname = mod.name;
if (/^WriteProcessMemory/.test(mod.name) ){
log('hooking '+fname);
Interceptor.attach(ptr(mod.address), {
onEnter: function(args) {
i_WriteProcessMemory(fname, c, args);
},
onLeave: function(retval){
var c = {t:new Date().toISOString(), f:fname};
o_WriteProcessMemory(fname, c, retval);
send(c);
return retval;
}
});
return;
}
};
exportcallbacks.onComplete = function (){};
var modulecallbacks={};
modulecallbacks.onMatch = function (module){
Module.enumerateExports( module.name, exportcallbacks );
return;
};
modulecallbacks.onComplete = function (){
log('module enumeration done');
return;
};
// Main
Process.enumerateModules( modulecallbacks );