HelpPacket Injection

Posts 1–7 of 7 · Page 1 of 1
Packet Injection
I'm trying to make a bot to automatically feed my pet in Ragnarok Online. So far I've been quite successful in everything I've tried however I can't quite figure out how to send a packet using that games socket. Below is my code to read the food value of the pet. After much googleing I think what I'm trying to do can be done with raw sockets however I've found nothing about it. I'm not looking for someone to do this for me, simply a link to a msdn function that can do what I'm trying is more what I'm looking for.
Code:
#include <Windows.h>
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;
void error(int errorid){
	switch (errorid)
	{
	case 0:
		cout << "Couldn't find window." << endl;
		break;
	case 1:
		cout << "Couldn't open process." << endl;
	default:
		break;
	}
	exit(errorid);
}
int main(){
	const char* name = "Ragnarok Online"; //window name
	const DWORD address = 0x9B224C; //address food is stored in
	HWND hwnd; //window handle
	DWORD pid; //process id
	HANDLE handle; //program starting address(?)
	DWORD food; //used to store our pets current food value

	cout << name << endl;
	hwnd = FindWindow(NULL, name);
	if (!hwnd)
		error(0);
	GetWindowThreadProcessId(hwnd, &pid);
	handle = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
	if (!handle)
		error(1);
	while (true)
	{
		ReadProcessMemory(handle, (LPCVOID)address, &food, 4, NULL);
		if (cin.peek())
		{
			string input;
			cin >> input;
			if (input == "food")
			{
				cout << "Pet's current food is: " << food << endl;
			}
			else
			{
				cout << "Unknown Command!";
			}
		}
	}
	return 0;
}
Right, I totally suck at networking and everything related to it but wouldn't it be as easy as finding the Ragnarok socket in IDA and creating something like;

Socket foo = *(Socket *)RagSocketAddr;
Send(foo, "My pet is hungry!", 18, 0);
I've never done packet injection: If you want to read my 2 cents, keep reading.

Does the game use any type of encryption? Chances are it has an 'encryption key' which is updated/changed for every* packet that gets sent out. So you can't just send a packet w/o knowing the current key / if you do send a packet, you have to manually update the key. idk this game, maybe it uses no encryption.
If it doesn't.....what's to stop someone from creating a fake packet (forged source IP) and sending it to the server and making your pet eat

If the game uses encryption:
Somewhere in the game's code is a section responsible for sending packets --> find that game_code, and figure out a way to "call" that code, but passing in your own arguments. <--I've never done, but I think it's "an option."
I'm fairly sure there is no encryption. I've captured the packets sent multiple times when I feed it and the packets sent are exactly the same every time.
tcp/ip right?

I know tcp/ip packets have a 'sequence number' number in the header (?), so does that mean you can't copy the packet byte-for-byte because the sequence number will be incorrect? Or is it as easy as 'creating a second socket on the same port' and tcp/ip/ windows takes care of the rest? I don't think it's possible for you to send the packet from the 'same port' as the game is using, but I'm not sure. I guess it's possible, but not sure how to do it on windows (or anything else*). I'll read up soon.

I think forcing the game (codecave etc) to send the packet itself is maybe the best (?) way to do it.
Yeah, problem I'm having is figuring out how to do that, I though maybe I could just hijack the socket used by the program and use it externally. But so far that's been unsuccessful since I've been having problems finding the socket.
I'm not sure exactly what that means but..

I've seen people use..um..api hooking, to know whenever data is sent out --> I'm not sure which functions they're hooking exactly, or how, but maybe it's something worth looking into? If you can do that efficiently, you could know where in the game_code that it sends(). And go from there: figuring out how to call it yourself (another big subject).

Why not just move the mouse cursor over the 'food' button and Mouse.LeftClick() ? Depends on your needs, but if this is a personal project, maybe take the easy route for now, and learn about packet stuff later? I'm not sure either.
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us