Folgende Warnungen sind aufgetreten:
Warning [2] preg_match_all(): The /e modifier is no longer supported, use preg_replace_callback instead - Line: 1007 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/highlighter.php 1007 preg_match_all
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] Invalid argument supplied for foreach() - Line: 1008 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
/inc/highlighter.php 1008 errorHandler->error
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] preg_match_all(): The /e modifier is no longer supported, use preg_replace_callback instead - Line: 1007 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/highlighter.php 1007 preg_match_all
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] Invalid argument supplied for foreach() - Line: 1008 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
/inc/highlighter.php 1008 errorHandler->error
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] preg_match_all(): The /e modifier is no longer supported, use preg_replace_callback instead - Line: 1007 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/highlighter.php 1007 preg_match_all
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] Invalid argument supplied for foreach() - Line: 1008 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
/inc/highlighter.php 1008 errorHandler->error
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] preg_match_all(): The /e modifier is no longer supported, use preg_replace_callback instead - Line: 1007 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/highlighter.php 1007 preg_match_all
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] Invalid argument supplied for foreach() - Line: 1008 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
/inc/highlighter.php 1008 errorHandler->error
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] preg_match_all(): The /e modifier is no longer supported, use preg_replace_callback instead - Line: 1007 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/highlighter.php 1007 preg_match_all
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] Invalid argument supplied for foreach() - Line: 1008 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
/inc/highlighter.php 1008 errorHandler->error
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] preg_match_all(): The /e modifier is no longer supported, use preg_replace_callback instead - Line: 1007 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/highlighter.php 1007 preg_match_all
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] Invalid argument supplied for foreach() - Line: 1008 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
/inc/highlighter.php 1008 errorHandler->error
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] preg_match_all(): The /e modifier is no longer supported, use preg_replace_callback instead - Line: 1007 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/highlighter.php 1007 preg_match_all
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] Invalid argument supplied for foreach() - Line: 1008 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
/inc/highlighter.php 1008 errorHandler->error
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] preg_match_all(): The /e modifier is no longer supported, use preg_replace_callback instead - Line: 1007 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/highlighter.php 1007 preg_match_all
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message
Warning [2] Invalid argument supplied for foreach() - Line: 1008 - File: inc/highlighter.php PHP 7.4.33 (Linux)
File Line Function
/inc/highlighter.php 1008 errorHandler->error
/inc/highlighter.php 353 generic_highlight
/inc/plugins/coolcode.php 133 php_highlight
/inc/plugins/coolcode.php 61 coolcode_run
/inc/class_plugins.php 139 coolcode_end
/inc/class_parser.php 232 pluginSystem->run_hooks
/printthread.php 184 postParser->parse_message



Home of Gamehacking - Archiv
C++ Code Injection(ohne DLL) - Druckversion

+- Home of Gamehacking - Archiv (http://archiv-homeofgamehacking.de)
+-- Forum: Coding (http://archiv-homeofgamehacking.de/forumdisplay.php?fid=15)
+--- Forum: C, C#, C++, Visual C++ (http://archiv-homeofgamehacking.de/forumdisplay.php?fid=18)
+--- Thema: C++ Code Injection(ohne DLL) (/showthread.php?tid=1059)

Seiten: 1 2


RE: C++ Code Injection(ohne DLL) - Acubra - 13.07.2012

Hey,
also der ASM Code bewirkt folgendes:

Sorry, aber hab grad keine Zeit mehr um ausführlicher auf dein Problem einzugehen.

//EDiT: Hab grad noch nen sehr interessanten Artikel gefunden: http://www.codeguru.com/cpp/w-p/system/processesmodules/article.php/c5767/Three-Ways-To-Inject-Your-Code-Into-Another-Process.htm
Vor allem der dritte Unterpunkt (III. The CreateRemoteThread & WriteProcessMemory Technique) sollte dich interessieren.


RE: C++ Code Injection(ohne DLL) - Colix - 17.07.2012

nach einigen tagen meld ich mich jetzt auch mal wieder! Happy

Erstmal danke für die Erklärung und den weiteren Link, hat mir eigentlich gut geholfen, sodass ich folgendes zusammengeschrieben hab.

Code:
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
struct SGame
{
	HWND hWnd;
	HANDLE hProcess;	
	LPVOID pAllocMemory;
	DWORD dwProcessID;
};
SGame Game;

LPCTSTR lpCaption = "Message";
LPCTSTR lpText = "Hello";

void InjectThread()
{
	FARPROC Message = GetProcAddress(GetModuleHandle( TEXT("user32.dll")), "MessageBox");
	_asm
	{
		push 0
		push lpCaption
		push lpText
		push 0
		call dword ptr [Message]
	}
}
static void after_InjectThread()
{

}
int main()
{
	if(!(Game.hWnd = FindWindow(NULL, "iTunes")))
		printf("[-] FindWindow failed! Error: %d\n", GetLastError());
	else 
		printf("[+] FindWindow succesfully\n");

	GetWindowThreadProcessId(Game.hWnd,&Game.dwProcessID);
	if(!(Game.hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, Game.dwProcessID)))
		printf("[-] OpenProcess failed! Error: %d\n", GetLastError());
	else 
        printf("[+] OpenProcess succesfully\n");

	DWORD sizeOfFunc = (PBYTE)&after_InjectThread - (PBYTE)&InjectThread;
	printf("[+] Size of Function: %d\n", sizeOfFunc);
	
	if(!(Game.pAllocMemory = VirtualAllocEx(Game.hProcess, 0, sizeOfFunc, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE)))
		printf("[-] VirtualAllocEx failed! Error: %d\n", GetLastError());
	else 
	{
		printf("[+] VirtualAllocEx succesfully\n!");
		if(!WriteProcessMemory(Game.hProcess, Game.pAllocMemory, &InjectThread,  sizeOfFunc, 0))
			printf("[-] WriteProcessMemory failed! Error: %d\n", GetLastError());
		else
		{
			printf("[+] WriteProcessMemory succesfully\n");
			if(!CreateRemoteThread(Game.hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)Game.pAllocMemory, NULL, NULL, NULL))
				printf("[-] CreateRemoteThread failed! Error: %d\n", GetLastError());
			else printf("[+] CreateRemoteThread succesfully\n");
		}
	}
	CloseHandle(Game.hProcess);

	while(true)
	{

		Sleep(100);
	}
	return 0;
}


Schön und gut, dacht ich zumindest, doch der Prozess, egal ob iTunes oder irgendein Game, crasht einfach. In meiner Konsole wird kein Fehler ausgegeben, die Funktionen werden alle ordnungsgemäß ausgeführt, laut meinen logs.
Könnte jemand von euch drüber schauen und es vielleicht selber mal ausprobieren? Hab ich was komplett falsch verstanden oder fehlt irgendwas? :P

Danke für jede Hilfe! Smiling

Gruß
Colix




RE: C++ Code Injection(ohne DLL) - Acubra - 19.07.2012

Hey,
ich hab deinen Code mal bei mir ausgeführt und im Debugger geguckt was passiert.
Also, nach dem WriteProcessMemory Call, findest du folgendes im "Mutter" Prozess:
[attachment=969]
Wie du siehst, eine Reihe von Jumps. Jedoch führt nur der erste zu einer validen Adresse (dieser wird auch nur "gecalled", weil -->). Der erste Jump springt zu folgendem Code:
[attachment=970]

Das Programm crasht dann bei folgendem Befehl:
CALL DWORD PTR DS:[258208]

Da ich nicht wirklich Ahnung von der Theorie hinter dem Ganzen hab und auch sonst nicht weiss wie es aussehen soll, bin ich ab hier mit meinem Latein am Ende. Sorry.


RE: C++ Code Injection(ohne DLL) - sungwoo - 14.10.2012

Hallo, ich weiss zwar nicht ob das hier noch Interesse an dem Thema besteht aber ich schreib mal was dazu:

1. Mit VirtualAllocEx Speicher im Zielprozess reservieren.
VirtualAllocEx(handle, NULL, SizeOfBytesToReserve, MEM_COMMIT , PAGE_EXECUTE_READWRITE );


2. Mit ReadProcessMemory die Daten sichern welche überschrieben werden.
3. Mit WriteProcessMemory folgendes schreiben:
JMP AdresseVoMReserviertenSpeicherBereich

Hier schreibst du zuerst den Opcode 0xe9
Die Adresse wo hingesprungen werden soll wird wohl kleiner sein als

die Adresse VON der du springst, also rechnest du folgendes:
ZielAdressOpcodes = ZielSprungAdresse - StartSprungAdresse - 5

Ach ich geb mal ein genaueres Beispiel^^:

PHP-Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0040ff90 mov eax,1234

Kurzer Peseudcode(naja eigentlich ist der gar nicht so Pseudo^^):
unsigend LongJmpOpcode = 0xe9;
unsigned JumpFromThisAddr = 0040ff90;

WriteProcessMemory(handle, (void*)JumpFromThisAddr, &LongJmpOpcode, 1, 0 );
        
unsigned TargerAddrOpcodes = BerechneSprungAdresse(  AdressOfReserveMemoryArea, JumpFromThisAddr);

JumpFromThisAddr++;  // Du willst ja nicht deinen JMP Long Opcode überschreiben

WriteProcessMemory(handle, (void*)JumpFromThisAddr, &LongJmpOpcode, OpcodeLength, 0 );  // OpcodeLength = 4

Hier noch:

JumpFromThisAddr+=4;
unsigned nop = 0x90;  // NOP operation
WriteProcessMemory(handle,(void*)CallFromThisAddr, &nop, 1, 0 );

Damit dein JMP die richtige Opcode Länge bekommt.

Ich hoffe man kann meine Erklärung verstehen.


So würde dann BerechneSprungAdresse intern aussehen:

PHP-Code:
unsigned BerechneSprungAdresse( unsigned AdressOfReserveMemoryArea, unsigned JumpFromThisAddr)
{
return ZielAdressOpcodes = (AdressOfReserveMemoryArea - JumpFromThisAddr)  - 5;
}