-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathclosemodule.cc
47 lines (38 loc) · 1.16 KB
/
closemodule.cc
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
// injcode/closemodule.cc
#include <stdlib.h>
#include "inject.h"
#include "ErrHandling.h"
#include "injcode.h"
extern options_t options;
extern "C" char* shellcodeClose();
extern "C" char* shellcodeCloseEnd();
/**
*
* Shellcode data:
* Size Value
* sizeof(int) fd to close
*
*/
CloseModule::CloseModule(Inject &injector)
:InjMod(injector)
{
char data[injector.pageSize()];
char code[injector.pageSize()];
// sanity check input
if (!options.parameters.count("fd")) {
throw ErrMalformed("CloseModule::CloseModule()",
"Close module requires option -ofd=<num>");
}
// init
memset(code, 0x90, injector.pageSize());
memset(data, 0, injector.pageSize());
code[injector.pageSize()-1] = 0xcc;
// data setup
*((int*)data) = strtoul(options.parameters["fd"].c_str(), NULL, 0);
// code setup
size_t s = (Inject::ptr_t)shellcodeCloseEnd
- (Inject::ptr_t)shellcodeClose;
memcpy(code, (char*)shellcodeClose, s);
// execute
injector.inject(code, data);
}