elitepvpers

elitepvpers (https://www.elitepvpers.com/forum/)
-   Kal Online (https://www.elitepvpers.com/forum/kal-online/)
-   -   [Question] Sending data (https://www.elitepvpers.com/forum/kal-online/2444829-question-sending-data.html)

iszoPL 02/25/2013 15:42

[Question] Sending data
 
I have 2 questions.

I know that packets are encrypted. I found address of send in engine, not ws2 send but engineSend func that takes data before it's encrypted.

I am able to use it but i can't hook it because of memory manipulation detection. Mid function hook doesn't work also, so i guess there has to be somekind of checksum of memory part.

I hooked IAT send function, but sniffed sent data is encrypted. I know that I am sending packets to server because when I use engineSend then I see sniffed packets client->server, but they are always different so they has to be encrypted.

Code:

typedef int (__stdcall *Send_org)(DWORD type,LPCSTR szFormat,...);

DWORD dwEngineSendA = CMemory::dwFindPattern(0x401000,0x2bc000,(BYTE*)"\x55\x8B\xEC\x83\xEC\x18\x83\x3D\x00\x00\x00\x00\x00\x00\x00\x33\xC0","xxxxxxxx???????xx");
        sendAdd = CMemory::dwFindPattern(dwEngineSendA+1,0x2bc000,(BYTE*)"\x55\x8B\xEC\x83\xEC\x18\x83\x3D\x00\x00\x00\x00\x00\x00\x00\x33\xC0","xxxxxxxx???????xx");
        LogTextBox("[Send Address]: 0x%x",sendAdd);

void KalTools::SendEngine(DWORD Header,LPCSTR szFormat,...)
{
        ((Send_org)sendAdd)(Header,szFormat);
}

This is how I'm finding the address and SendEngine is just using their function.

When i for example write

Code:

KalTools::SendEngine(0x3d,"db",pid,14);
I see in sniffer that it was sent but nothing happens in game. Am i doing something wrong?

bloodx 02/25/2013 15:59

u need to decrypt the packets also.
upload unpacked engine for me and I give u encrypt + decrypt call + table

the key u get from 0x2a packet also.

position 7 or smth

and Send is no __stdcall its __cdecl

+ u also dont pass the last " ... " parameter to the send function, so what he should do ?

meak1 02/25/2013 16:13

the Whole engine.exe is checked by HS

Decrypt packets or just use the Send function, u didnt need any hook there... Just use the func for sending them ;d

iszoPL 02/25/2013 16:21

1 Attachment(s)
I changed calling convention to cdecl already. I've noticed it after posting ;p.

@meak
I am using their send function. I just got address and sendEngine is executing it as u can see. I can't hook it because of hs. I only hooked send function at IAT but it's send from ws2_32 so packets intercepted in there are encrypted already.

What about last parameter? I think I am blind cuz i don't see any error ;p

I attached my dumped engine.exe. Tell me if it's ok ;)

meak1 02/25/2013 16:23

AS I SAID, NOT HOOK IT, ONLY USE IT........................................

GET RECV PACKET, ANSWER WITH CALL SEND, NOT HOOK IT... -.-#

Edit: or for what u wanna hook Send?

iszoPL 02/25/2013 16:27

I can hook IAT send. How can i answer to that if it needs socket,buf,len,flags.
It's easier to use engineSend than ws2 send. I'd have to crypt packet first in order to use IAT hooked send.

I didn't hook send in engine. I just have address and i'm trying to use it.

Btw. If i try to call

Code:

((Send_org)sendAdd)(Header,szFormat,...);
It gives me an error and I don't really know why because typedef is ok.

meak1 02/25/2013 16:30

i didnt said any other method, its puplic how to send over engineFunc

PHP Code:

DWORD SendPacketMain_ SearchPattern("55 8B EC 83 EC 18 83 3D x x x x 00 74 07 33 C0 E9 x x x x 8A 45 08",0x00400000,0x007FFFFF);
DWORD SendPacketMain  SearchPattern("55 8B EC 83 EC 18 83 3D x x x x 00 74 07 33 C0 E9 x x x x 8A 45 08",SendPacketMain_+1,0x007FFFFF);
DWORD SendPacketBack  SendPacketMain 0x06;

int Naked PacketSend(DWORD type,LPCSTR format,...)
{

    
__asm
    
{
        
push ebp
        mov ebp
esp
        sub esp
,18h
        jmp SendPacketBack
    
}
}

PacketSend(0x0D,"bbd",1,1,TargetID); <- behead 


iszoPL 02/25/2013 16:37

Yes i know this example. But in order for this to work you need to place JMP over first 5 bytes of this func to ur function right? And if I try that hs detects memory corruption.

Edit.

@blood

I've changed it so it's passing va_list args but it is still not working ;)

Code:

void KalTools::SendEngine(DWORD Header,LPCSTR szFormat,...)
{
    va_list args;
    va_start(args, szFormat);
    ((Send_org)sendAdd)(Header,szFormat,args);
    va_end(args);
}

What's the easiest way of checking it. I mean what packet can I use to check. Maybe my problem is with trying to use it ;p

meak1 02/25/2013 16:50

U DONT UNDERSTAND?
NOT HOOK IT JUST USE IT, THIS IS UR FUNCTION AND THIS JUMP BACK TO ENGINE, ENGINE DIDNT NEED TO JUMP TO UR FUNCTION -.-.................................................. .................................................

Said it now 5 times, if u dont get it, its ur problem.

U Just call the function, engine didnt need to jmp to ur function...

iszoPL 02/25/2013 16:59

oh... i get it know. This kind of programming is new for me so don't be angry if i don't undestand how sometimes some things works.

meak1 02/25/2013 17:01

np, i like to rage ;D

U use the function from Engine, u call ur function with ur Paramaters and then the Function jumps to the Engine Send, the engine Send crypt ur Packet and send it..

iszoPL 02/25/2013 17:10

Ye so pretty much my engineSend did the same thing but it was calling directly their function and passing parameters. Anyway is this sit packet ok? I want to check if it works

send(0x1F,"b",1);

bloodx 02/25/2013 17:26

static int (__cdecl* SendPacket)(DWORD,LPCSTR,...) = (int (__cdecl*)(DWORD,LPCSTR,...))0x005A0100;

u can do this ,too and than just use SendPacket(......);

if u want to sniff packets hook send from ws2 and decrypt packets there.

005A01F3 there should be the Encrypt call and @0073AEE0 should be Encrypt Table

RunzelEier 02/25/2013 18:11

Quote:

Originally Posted by meak1 (Post 21407884)
PHP Code:

DWORD SendPacketMain_ SearchPattern("55 8B EC 83 EC 18 83 3D x x x x 00 74 07 33 C0 E9 x x x x 8A 45 08",0x00400000,0x007FFFFF);
DWORD SendPacketMain  SearchPattern("55 8B EC 83 EC 18 83 3D x x x x 00 74 07 33 C0 E9 x x x x 8A 45 08",SendPacketMain_+1,0x007FFFFF);
DWORD SendPacketBack  SendPacketMain 0x06;

int Naked PacketSend(DWORD type,LPCSTR format,...)
{

    
__asm
    
{
        
push ebp
        mov ebp
esp
        sub esp
,18h
        jmp SendPacketBack
    
}



so you add 6 Bytes to SendPacketMain
so you can reconstruct those 6 Bytes and jump to SendPacketBack.
This is one big NOP :D
why dont you call SendPacketMain directly?

iszoPL 02/25/2013 20:17

Thanks blood ;)

I changed my send to

Code:

void KalTools::SendEngine(DWORD Header,LPCSTR szFormat,...)
{
    va_list args;
    va_start(args, szFormat);
    ((Send_org)sendAdd)(Header,szFormat,args);
    va_end(args);
}

so it should now pass all data to func ;) But ur way is also great. Good trick xD
Ye i found this encrypt func and ida pseudocode looks like bakabug's one so i guess it is it ;p Encrypt table is pretty big oO. Well i guess i can use pointer to it and use the one from engine directly.

And about that packet sending. I am hooked already to IAT send so i can sniff sent data. Now i have to decrypt them in order to learn more. Are some packets changed now because this sit packet

0x1f,"b",1 is not working I can see that it was sent, because sniffed functions shows it but nothing happens.

bloodx 02/25/2013 20:22

Code:

//Account
Type: 0x00 Format: Ud - Restore Char
Type: 0x01 Format: ? - HS
Type: 0x02 Format: Uss - Login
Type: 0x03 Format: ? - HS
Type: 0x04 Format: Usbwwwwwbb - CharGen
Type: 0x05 Format: Ud - Ping
Type: 0x07 Format: Ud - Delete Char
Type: 0x08 Format: dddddbb - Connect
Type: 0x09 Format: Ubd - Check Version
Type: 0x0a Format: Uddd - LoadPlayer
Type: 0x75 Format: Ubs - 2nd Pass

//Char
Type: 0x0a Format: Uddd - GameStart
Type: 0x0c Format: Ubdd - Attack
Type: 0x0d Format: Ubbd - Attack with Skill
Type: 0x0e Format: Us - Chat

Type: 0x10 Format: Ub - Relog
Type: 0x11 Format: Ubbb - Move
Type: 0x12 Format: Ubbb - MoveStop
Type: 0x13 Format: Ud - Talk To NPC
Type: 0x14 Format: Ud - Merchant Get Tax
Type: 0x15 Format: Um - Merchant Buy
Type: 0x16 Format: Um - Merchant Sell
Type: 0x17 Format: Udd - DropItem
Type: 0x18 Format: U - Quit Game
Type: 0x19 Format: Um - Trade insert item

Type: 0x1b Format: Ub - Stat Up
Type: 0x1c Format: Ub - Rest
Type: 0x1d Format: Uddd - Pick Item
Type: 0x1e Format: Ud - Use Item
Type: 0x1f Format: Ud - Request Trade

Type: 0x20 Format: Ubd - OnAskTrade
Type: 0x21 Format: U - Cancel Trade
Type: 0x22 Format: U - Revive

Type: 0x27 Format: Ub - SkillUp
Type: 0x28 Format: Ubd - Skill (Prep Ani)
Type: 0x29 Format: Ud - Request Party
Type: 0x2a Format: Ubd - Party Onask
Type: 0x2b Format: ... - guild {...}
Type: 0x2c Format: U - Party Leave
Type: 0x2d Format: d - Party kick
Type: 0x2e Format: Um - StorageKeeper CheckIn
Type: 0x2f Format: Um - StorageKeeper CheckOut

Type: 0x30 Format: Ud - NPC-Reply
Type: 0x31 Format: U - Storage Keeper Show Invent

Type: 0x33 Format: Ubd - Statue Save
Type: 0x34 Format: Udd - Pimp
Type: 0x35 Format: bddd - Player Shop AddItem

Type: 0x38 Format: Udb - Ani (Dance)
Type: 0x39 Format: U - Trade confirm

Type: 0x3a Format: Ud - Destroy Item
Type: 0x3b Format: Ub - Friendlist
Type: 0x3c Format: Ud - PutOn Item
Type: 0x3d Format: Ud - PutOff Item
Type: 0x3e Format: Ub - Cancel PlayerShop
Type: 0x3f Format: U - CancelFishing



Type: 0x40 Format: bd - Check Playershop Shop
Type: 0x41 Format: Um - Buy Playershop

Type: 0x47 Format: U - Request AssaList
Type: 0x48 Format: Ud - Request Duel
Type: 0x49 Format: Ubd - Duel OnAsk

Type: 0x4d Format: Ub - Student (open Window)

Type: 0x4f Format: Ub - ? beim login

Type: 0x51 Format: Ubd - Blacksmith
Type: 0x52 Format: Um - FL Parcel

Type: 0x54 Format: Ud - Treasure Box

Type: 0x57 Format: Udbb - Teleport (fisher?)

Type: 0x9d Format: Ub - Triangular Battle


iszoPL 02/25/2013 20:39

Thanks. I love you xDD I'd try to check it myself after decrypting send packets but it's huge help for me ;) I guess encrypt table can be also used to decrypt packets. I know it's a stupid question but it's better to ask if i'm not sure xD heh I just started cryptography at this semester so i will know more when it ends ^^

bloodx 02/25/2013 20:48

DecryptTable != EncryptTable :P

in some Games / Applications sure, but here are 2 different used.

iszoPL 02/25/2013 20:51

hmm so i have to find decrypt table in order to decrypt packets right and decrypt function. Or just use encrypt function in reversed order?

bloodx 02/25/2013 21:02

u also can use the engine crypt function like I did with SendPacket ;) hehe

or u just use BakaBugs released stuff hehe I think his Decrypt and Encrypt Table is still the same like now.

iszoPL 02/25/2013 21:08

But this function u gave is encrypt. I didn't yet tried to reverse it. I guess it takes buffer and some other stuff to do it. I guess it would be easier to find their decrypt function and just use it. hmm but when it will be used ;p Somewhere before receiving? or in send also?

bloodx 02/25/2013 21:21

u can see Decrypt Function @ recv :P

iszoPL 02/25/2013 21:52

I'm guessing that

00484E80 is Decrypt func and at 007412E0 is DecryptTable right? ;) Now i have to guess what parameters they are taking ^^

bloodx 02/25/2013 21:56

same like bakabugs function I think :p

meak1 02/25/2013 23:17

use bakabugs source, update crypt/decrypt table(changed 1 time long time ago), use pointer for AESkey or dumb it.

iszoPL 02/25/2013 23:36

There is alot to reverse ;p I guess it's not a job for today. It seems like alot of work for me since I am new at reversing ^^ and baka source's are complicated for me. Specially that I've never had to deal with cryptography ;) I don't even really know what for is this DecryptTable function xD I'm guessing it decrypts header and size seperately and rest of packet is decrypted by AESPacketDecrypt but who knows xD

meak1 02/25/2013 23:47

u didnt need to know, just copy it ;d

thought sooner too, dat bakabug is a boss on coding but later i found all in IDA, he just copied all out from IDA ;\

Edit: Gogo, if ur fast enough we can handle the HS d;
i just look sometimes into it, got the first HS packet i guess

iszoPL 02/25/2013 23:50

heh most of his stuff is generated by IDA as i see ;) Now i'm tracing call of decrypt func so i can find this stupid eas key xD I already have decrypttable. xor key also changed? Oh, and HS is too difficult for me xDD Maybe someday. For now it is not a problem since i'm able to work even with hs on.

meak1 02/26/2013 00:27

y u have time E;
Xor not changed.

iszoPL 02/26/2013 14:37

I'm trying to reverse this shit and it's so annoying ;p I can't find anywhere in near calls any trace of AES key. I thought that recv packet are not crypted and as it turns out they are ;p

There are some func i was able to find. Any hints where to look next?

[Only registered and activated users can see links. Click Here To Register...]

Encrypt is used both by send and recvEngine but there is this this func that is using it and i have no idea what is it for. 5A0000

RunzelEier 02/26/2013 16:49

but bakabug's source only decrypts the first 16 bytes (?)

meak1 02/26/2013 16:57

@Runzel cause first 16 bytes are not used for AES crypt.
Bakabug added the AESkey pointer wrong or idk, if u add it manually it works well.

Just use the AESkey pointer from bakabug and make a Dumb every week.

PHP Code:

char *TEST = (char*)*((DWORD*)(SendPacketMain+0xA5)); 

if u get the 0x2A packet, dumb it.

0x01 is Encrypt
0x02 is Decrypt, at the End. its the AESKey expanded into 2 parts 0x01 and 0x02 at the End.

iszoPL 02/26/2013 18:02

I have to get straight some info because it's chaos in my head right now xDD

This is captured packet 0x2a

Code:

57 0 2A [U][COLOR="Red"]73 2B DD 9 3E[/COLOR][/U] 32 6D 25 51 36 8A 25 51 61 F6 F7 27 0 4 0 0 0
 22 0 0 2 12 2 18 3C A 1E 18 96 B9 80 AB AC B6 B4 A6 96 8A A2 8A B5
 9D 9F 8A A7 A9 94 A2 86 F8 D7 EA EE C2 D8 FC DA F8 E4 E6 CC DB F3 D7 F1
 C9 C7 CA FA E8 A8 8C BA F4 F2 D3 E8 8 0

This part is changing. I got the pointer to decryption table and i swapped it with baka's table.

Now what for is DecryptTable function of his because is says that is takes index buf and len. Ok buf and len i get but u are passing RecvKey as index. WTF xD Is it just for decrypting type of packet/first 3 bytes? And when u do it u just use decryptPacketAES? I don't get this cryptography stuff right now so a bit explanation would be great ;)

Ps. And this pointer u gave SendEngine + 0xA5 it's pointing to some table(unknown) full of 0 bytes. Actually start of this table is at SendEngine + 0xA4 according to my dump and ida ;) Well not start but push ;p

Code:

.text:005A01A4                push    offset unk_8B6300

meak1 02/26/2013 18:38

if 0x2A comes in, u can dumb at the address SendEngine + 0xA5. The AESkey is created in runtime, expanded into 2 parts 0x01 0x02

i got RecvKey cause clientless u need to decrypt Recv...
in Engine.exe the Recv is called twice. first for encrypt and secound is the Real Recv
but it goes over the same function, its to hard to explain, if u hook recv at engine u get the Real recv data.

Index is the Tablekey i guess, KalOnline routine ->

under 16 bytes u didnt need the 2 AESKey's, it gets only crypted by Tablekey(Xoring with the Tablekey) and XorKey at the End.

For what u need now the Decrypt part? i would say its to difficult to explain
U see at the SendFunc how its decrypted, there are 2 calls, one for Tablkey Xoring and one for AES crypt

And bakabug just copied those functions with IDA.

EDIT: Someone know about VEH hooking? its hooking over exceptions, its still undetected hook in all Games, cause it cant get detected i guess, its smth new

iszoPL 02/26/2013 18:58

Well i want to have a look at encrypted send packets so i can learn more about them.

So AES key is this 540 bytes long unknown table in baka code?

Basically i have to dump this table, swap it with original. Swap decrypt/encryp tables. And everytime at the start when 0x2a comes i have to save sendKey so i can later use it to decrypt header + data of send packets? (Edit. Scratch that ;p As this table is static i can save the key and dump table at first use then at the start of app just compare first key and if it differs then make new dump and replace with old).

so I did this

Code:

sendKey = (BYTE*)*((DWORD*)(sendAdd+0xA5));
LogTextBox("Send key captured: 0x%X ",*sendKey);
for(int i=0;i<540;i++)
{
        dumptable byte by byte
}

I got updated decryptTable.

so can I now do this?

Code:

if(KalTools::getSendKey() != 0)
{
DecryptTable(*KalTools::getSendKey(),(unsigned char*)packet+2,len-2);
DecryptPacket((char*)packet);
}

sendKey is BYTE* so it's first cell of aes table 0x3A i guess.

meak1 02/26/2013 21:05

AESkey != Tablekey....

the aeskey is for AES cryption(UNKNOWN), and TableKey is just an Xor cryption
and bakabug have a pointer to the Tablekey... u just can use it.

Tablekey is 0x1-0x3F - Tablekey+an hex 0x25, then it using the Tablekey from encrypttable to encrypt it with Xor.. idk how to explain <,<

iszoPL 02/26/2013 21:19

You mean that there are 2 seperate pointers for aes key and table key?

The one u gave is to table with aes data and

BYTE *TKey = (BYTE*)*((DWORD*)(PacketSendMain+0xCA));

this is for table key?

then i should do this

TableKey = ((*TKey)-1) & 0x3F;

and then i can use it?

meak1 02/26/2013 21:31

y

iszoPL 02/26/2013 21:38

Ok then what's this for in ur code? Because i'm now a little confused xD

Code:

if(buf[2] == 0x2A){
SendKey=*(BYTE*)&buf[7];

is this pointer the same data?

meak1 02/26/2013 21:43

isnt a pointer, u dont have a client on clientless, u cant doing a pointer on memory, cause the game isnt opened. 0x2A is welcome packet, and buf[7] is the first sendkey.

so with Client u just use the Pointer from tablekey. *Tkey

best way to learn, is by doing. Now watching a movie and going to sleep after ;E


All times are GMT +2. The time now is 07:06.

Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.