Creating My Own Proxy

05/08/2007 21:05 KageKhan#1
Ok, so I'm posting this here because it's more of a question thread for any of the proxy developers out there. I am attempting to make my own proxy using auto it and have been successful in logging in, however, when I close the sockets the connection remains. I changed my Server.dat to send to 127.1.1.1 and my script takes the clients packets and sends them to the CO server and takes the CO servers responses and sends them to the client. I have ran my script and connected, I have ran the CO client and established that my script must be running to connect.. however once I'm connected and shut down my script, the connections remain relaying and I do not get disconnected from the server and vice versa. If anyone could help me with this I'd greatly appreciate it! My script is bellow and thanks!

*EDIT - It's DONE!!!! Although as explained in a post down bellow, it can't do anything except connect the game client to the server and pass traffic through. Thanks to bone-you and behelit ;)
05/09/2007 01:20 bone-you#2
uhh.. I can't help you with the sockets closing but might I recommend not doing it in that? The way it's setup is you only receive server data if the client sends any data since it has to wait to receive if there's nothing there.
05/09/2007 02:02 KageKhan#3
Thats not the problem, the client is sending and receiving data... The only problem is that after the login process my proxy is no longer needed. The data stream seems to be entirely between the client and the server instead of running through my proxy. I know it works at first because without my proxy running it can't login (the server.dat is set to my local host so it shouldn't be able to) but after it logs in... I can close my proxy and it still runs fine... To me, that just doesn't make any sense. As for your suggestion to not do this in autoit.. I may do it in java if I can't get this to work but for now I would like to see what I can do with what I have.
05/09/2007 04:37 bone-you#4
oh. You have to replace the ip in the initial authserver->client packet so that it reroutes the connection through your proxy.

in my proxy:

Code:
	switch (wMsgID)
	{
 case 0x041F:
 	char oldip[16];
 	memset(oldip, 0, 16);
 	memcpy(oldip, pData+12, 16);
 	memset(pData+12, 0, 16);
 	memcpy(pData+12, G_cLocalBindIP, strlen(G_cLocalBindIP));
 	wp = (WORD *)(pData+12+16);
 	G_iRemoteGamePort = *wp;
 	*wp = G_iLocalGamePort;
 	memcpy(G_cGameServerAddr, oldip, 16);
 	wsprintf(G_cTxt, "Remote game ip <%s> port <%d>", G_cGameServerAddr, G_iRemoteGamePort);
 	conadd(G_cTxt, DEF_VERBOSE_CRITICAL);
 	break;
	}
pData being the pointer to the packet in its entirety.


edit: btw.. you need to decrypt and encrypt the packet to modify it. You also need two more sockets open for the game server connection.
05/09/2007 04:59 KageKhan#5
lol awesome, thanks! I'm not sure how to go about this just yet but I'll get there. I'm assuming thats why all the other proxys have those keys right? to decrypt/encrypt data? I'm not just going to be able to edit some hex values in the packet as it's being sent huh?
05/09/2007 05:00 bone-you#6
Quote:
Originally posted by KageKhan@May 8 2007, 22:59
I'm not just going to be able to edit some hex values in the packet as it's being sent huh?
'fraid not. You have to do all the nasty stuff on it to be able to read/write it. :)
05/09/2007 15:46 KageKhan#7
Ok, so now the big question is how do I use the keys to decrypt and encrypt the data? I would guess that java and c# have that built in to a library, but on the off chance that you had to write your own crypto algorithm to translate the data I thought it might be wise to at least ask.

*EDIT - Ok so I should have looked at the keys before saying anything. By the looks of it, I would say that the keys are simple replacement values for ascii characters. My assumption is based on the fact that there are 256 hex values in the keys. I guess now my question would be, what does the corresponding hex value equal in terms of an ascii character? I could make many assumptions to the actual values and I know given time I could figure this out on my own but I was hoping someone might have a quick answer?
05/09/2007 19:15 bone-you#8
er.. libraries? No. All the encryption/decryption is coded by hand. You'd have to run it through a loop yourself too in order to process it. As for ascii values, just use the hex. You risk data corruption using ascii symbols since some editors take certain values and replace them with others. (die notepad)
05/09/2007 19:44 KageKhan#9
No what I mean is, what do I do with the key (whichever one it is) to decrypt the packets and what do I do with the other key to encrypt the packets.

*EDIT - guess I should have searched before asking something like that... Just so you know where I found the answer I was looking for and so you can possibly update me of any changes made to the process of decrypting/encrypting...

[Only registered and activated users can see links. Click Here To Register...]
05/10/2007 03:30 bone-you#10
The process is still the same. I don't know if you can do it in the program you're trying to make this in though. I'm quite amazed a macro program even supports socket connections. I suppose if you really wanted to you could even do this in mIRC. I'm almost tempted to try it.. lol. binary vars ftw.
05/10/2007 17:25 KageKhan#11
I believe that its very possible in autoit.. and autoit isn't just a macro program.. you can access system memory, write custom hooks, use dlls among other things. It's a very amazing language considering what it started out as. I also had my doubts at first but the more I work with it the more I realize how well rounded it is. You should check it out before you label it as "just another macro program". Although the bulk of the real features you would most likely want to use aren't included in the programs package, you have to find certain features within the autoit forums (such as the system memory functions) Anyways... Thank you for everything so far! I'll keep you updated on my progress ^.^
05/11/2007 21:01 KageKhan#12
Alright, so I've been able to get the 3rd and fourth key. My problem now is I have no idea how to decrypt the packets sent by the server and client... Lowfyr gives a great explaination of how to encrypt the decrypted packets but as far as decrypting the packets... well, the explaination doesn't seem to be there. It just says "Encrypt the received Packets", and "Encrypt the "Client sent" packets". He gives a small explaination about there being counters in the decryption process but I have no idea what to do... could you explain what I do with the 1st and 2nd key to decrypt the packets sent from the server and client?
05/12/2007 01:49 bone-you#13
Decryption is the exact opposite of encryption. The code is the same just reversed and opposite.
05/14/2007 15:27 KageKhan#14
ok so just wondering... do I use the same counter for encrypting/decrypting incoming packets and the same counters for encrypting/decrypting outgoing packets.. or do I actually end up with 8 counters, 2 for decrypting incoming packets, 2 for decrypting outgoing packets, 2 for encrypting incoming packets and 2 for encrypting outgoing packets?

*EDIT - I'm pretty sure it's just 4, 2 for incoming packets and 2 for outgoing and that the counters are used for both the encryption and decryption or thats what I think Lowfyr is saying anyway but I just thought I'd ask to make sure I'm understand it correctly.

<hr>Append on May 15 2007, 00:32<hr> Ok, I got past the decryption/encryption part of all of this.. I change the ip in the packet (216.93.174.172) to my localhost (127.0.0.1) I encrypt the packet and send it back to the client. The client sends me a packet which I pass on the the previous socket (69.59.142.13) and then try to start communication between my proxy and 216.93.174.172 For some reason I can't connect to that IP... can I not use port 9958 to connect to that ip? Or is there something else I'm missing?
05/18/2007 17:12 KageKhan#15
MY PROXY IS DONE!!!!!!!!!!!!! It can't really do much... but it can connect the client to the server and I made it using a stupid scripting language!!!!!! I love everything right now ^.^ My code is bellow, If you want to try it out you'll have to get auto-it and compile it yourself. The coding is sort of all over the place because I have been trying a whole bunch of different things to get it to connect.. until I stumbled across someone elses proxy that listened to port 5816.... That was what I was missing, so thanks to bone-you for all your help and thanks to behelit whose proxy says what ports it listens to lol I can't wait to start doing stuff with this!!!!! :D :D :D I love this community, thank you all!