Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 16:41

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Question] Hooking send() & recv() works, but recv hiding data for co???

Discussion on [Question] Hooking send() & recv() works, but recv hiding data for co??? within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
clintonselke's Avatar
 
elite*gold: 0
Join Date: Feb 2007
Posts: 348
Received Thanks: 2,175
Question [Question] Hooking send() & recv() works, but recv hiding data for co???

Hey guys, I've been making a DLL to allow another program to intercept the packets of conquer using windows pipes. (Then its the job of the main program to decrypt the packets, the DLL only gives a communication channel for the main program)

(winsock functions btw)

- hooking send() works fine for my internet browser

- hooking recv() works fine for my internet browser

- hooking send() works fine for conquer online

- hooking recv() ??? only 1/2 working for conquer online. When i hook recieve for conquer online, the packets recieved always seem to have size zero and the data is empty... however when i try to comment out call to the original recv() inside my recv() conquer stops working (for checking conquer uses that function). So what i think is going on is conquer is doing some trick with winsock to make the result of a recv() get stored somewhere else.

Any ideas what is up w/ the conquer recv() ?

Thanks in advance , and my code listings are below.

DLL that gets injected...
PHP Code:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <windows.h>
#include "types.h"
#include "detours/patcher.h"

/*
int WSARecv(
  __in     SOCKET s,
  __inout  LPWSABUF lpBuffers,
  __in     DWORD dwBufferCount,
  __out    LPDWORD lpNumberOfBytesRecvd,
  __inout  LPDWORD lpFlags,
  __in     LPWSAOVERLAPPED lpOverlapped,
  __in     LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
*/

using namespace std;

typedef int (WINAPI *SendFunc)(SOCKET, const char*, intint);
typedef int (WINAPI *RecvFunc)(SOCKETchar*, intint);
typedef int (WINAPI *WSARecvFunc)(SOCKETLPWSABUFDWORDLPDWORDLPDWORDLPWSAOVERLAPPEDLPWSAOVERLAPPED_COMPLETION_ROUTINE);

SendFunc pSend NULL;
RecvFunc pRecv NULL;
WSARecvFunc pWSARecv NULL;

int WINAPI our_send(SOCKET s, const charbufint lenint flags);
int WINAPI our_recv(SOCKET scharbufint lenint flags);
int WINAPI our_wsa_recv(SOCKET sLPWSABUF lpBuffersDWORD dwBufferCountLPDWORD lpNumberOfBytesRecvdLPDWORD lpFlagsLPWSAOVERLAPPED lpOverlappedLPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);

HMODULE hWinsock GetModuleHandle("ws2_32.dll");

CPatch patchForSend((SendFunc)GetProcAddress(hWinsock"send"), our_sendpSend);
CPatch patchForRecv((RecvFunc)GetProcAddress(hWinsock"recv"), our_recvpRecv);
CPatch patchForWSARecv((WSARecvFunc)GetProcAddress(hWinsock"WSARecv"), our_wsa_recvpWSARecv);

fstream sendPipe;
fstream recvPipe;

SOCKET lastSocket INVALID_SOCKET;

int WINAPI our_send(SOCKET s, const charbufint lenint flags)
{
    
DWORD tmp;
    
lastSocket s;
    
sendPipe.write(buflen);
    
sendPipe.flush();
    
/*
    char buf2[len];
    sendPipe.read(buf2, len);
    pSend(s, buf2, sendPipe.gcount(), flags);
    */
    //return len;
    
return pSend(sbuflenflags);
}

int WINAPI our_recv(SOCKET scharbufint lenint flags)
{
    
DWORD tmp;
    
lastSocket s;
    
len pRecv(sbuflenflags);
    if (
len == 0) { return 0; }
    
recvPipe.write(buflen);
    
recvPipe.flush();
    
//recvPipe.read(buf, len);
    
return len;
}

int WINAPI our_wsa_recv(SOCKET sLPWSABUF lpBuffersDWORD dwBufferCountLPDWORD lpNumberOfBytesRecvdLPDWORD lpFlagsLPWSAOVERLAPPED lpOverlappedLPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
    
int x pWSARecv(slpBuffersdwBufferCountlpNumberOfBytesRecvdlpFlagslpOverlappedlpCompletionRoutine);
    for (
int i 0dwBufferCount; ++i) {
        
recvPipe.write(lpBuffers[i].buflpBuffers[i].len);
        
recvPipe.flush();
    }
    return 
x;
}

DWORD WINAPI transmitter(void*);

extern "C"
BOOL WINAPI DllMain(HINSTANCE hinstDLLDWORD fdwReasonLPVOID lpvReserved)
{
    switch (
fdwReason) {
        case 
DLL_PROCESS_ATTACH:
            
// attach to process
            
DisableThreadLibraryCalls((HMODULE)hinstDLL);
            
WaitNamedPipe("\\\\.\\pipe\\ConquerSendPipe"NMPWAIT_WAIT_FOREVER);
            
sendPipe.open("\\\\.\\pipe\\ConquerSendPipe");
            if (!
sendPipe) {
                
MessageBox(NULL"Failed to connect send pipe.""Error"MB_OK);
                return 
FALSE;
            }
            
WaitNamedPipe("\\\\.\\pipe\\ConquerRecvPipe"NMPWAIT_WAIT_FOREVER);
            
recvPipe.open("\\\\.\\pipe\\ConquerRecvPipe");
            if (!
recvPipe) {
                
MessageBox(NULL"Failed to connect recv pipe.""Error"MB_OK);
                return 
FALSE;
            }
            
//CreateThread(NULL, 0, transmitter, 0, 0, NULL);
            
break;
        case 
DLL_PROCESS_DETACH:
            
// detach from process

            
break;

        case 
DLL_THREAD_ATTACH:
            
// attach to thread
            
break;

        case 
DLL_THREAD_DETACH:
            
// detach from thread
            
break;
    }
    return 
TRUE// succesful
}

DWORD WINAPI transmitter(void*)
{
    
char buf[4096];
    
DWORD len;
    while (
1) {
        
sendPipe.read(buf4095);
        
len sendPipe.gcount();
        if (
len == 0) {
            
MessageBox(NULL"Connection to send pipe lost.""Error"MB_OK);
            return 
1;
        }
        
buf[len+1] = 0;
        if (
strcmp(buf"exit") == 0) { break; }
        
pSend(lastSocketbuflen0);
    }
    return 
0;

Test application...
PHP Code:
#include <iostream>
#include <iomanip>
#include <sstream>
#include <windows.h>
#include <conio.h>
#include "types.h"
#include "tools.h"

using namespace std;

static 
void output_packet(char packet[], int len)
{
    for (
int i 0len; ++i) {
        
cout << hex << setw(2) << right << setfill('0') << (int)(unsigned char)packet[i] << " ";
    }
}

DWORD WINAPI server_to_client(void*);
DWORD WINAPI client_to_server(void*);

HANDLE hSendPipe INVALID_HANDLE_VALUE;
HANDLE hRecvPipe INVALID_HANDLE_VALUE;

int main(int argccharargv[])
{

    if (
argc != 2) {
        
cout << "Usage: packetlogger <ProcessID>" << endl;
        return 
1;
    }
    
istringstream is(argv[1]);
    
uint32 processId;
    
is >> processId;

    
// create a named pipe for communicating with the remote process
    
string sendPipeNamerecvPipeName;
    {
        
ostringstream os;
        
os << "\\\\.\\pipe\\ConquerSendPipe";// << processId;
        
sendPipeName os.str();
        
os.str("");
        
os << "\\\\.\\pipe\\ConquerRecvPipe";// << processId;
        
recvPipeName os.str();
    }
    
cout << "send pipe name: " << sendPipeName << endl;
    
cout << "recv pipe name: " << recvPipeName << endl;
    
cout << "Creating & connecting send pipe... ";
    
hSendPipe CreateNamedPipe(sendPipeName.c_str(), PIPE_ACCESS_DUPLEX /*| FILE_FLAG_OVERLAPPED*/PIPE_TYPE_MESSAGE PIPE_READMODE_MESSAGE PIPE_WAIT/*PIPE_UNLIMITED_INSTANCES*/409640960NULL);
    if (
hSendPipe == INVALID_HANDLE_VALUE) {
        
cout << "failed to create send pipe." << endl;
        return 
1;
    }
    if (!
ConnectNamedPipe(hSendPipeNULL)) {
        
cout << "failed to connect client to send pipe." << endl;
        return 
1;
    }
    
cout << "done." << endl;
    
cout << "Creating & connecting recv pipe... ";
    
hRecvPipe CreateNamedPipe(recvPipeName.c_str(), PIPE_ACCESS_DUPLEX /*| FILE_FLAG_OVERLAPPED*/PIPE_TYPE_MESSAGE PIPE_READMODE_MESSAGE PIPE_WAIT/*PIPE_UNLIMITED_INSTANCES*/409640960NULL);
    if (
hRecvPipe == INVALID_HANDLE_VALUE) {
        
cout << "failed to create recv pipe." << endl;
        return 
1;
    }
    if (!
ConnectNamedPipe(hRecvPipeNULL)) {
        
cout << "failed to connect client to send pipe." << endl;
        return 
1;
    }
    
cout << "done." << endl;

    
cout << "ready for data." << endl;

    
HANDLE thread1 CreateThread(NULL0server_to_client00NULL);
    
HANDLE thread2 CreateThread(NULL0client_to_server00NULL);

    while (
WaitForSingleObject(thread11000) != WAIT_OBJECT_0) {}
    while (
WaitForSingleObject(thread21000) != WAIT_OBJECT_0) {}

    
DisconnectNamedPipe(hSendPipe);
    
DisconnectNamedPipe(hRecvPipe);

    
CloseHandle(hSendPipe);
    
CloseHandle(hRecvPipe);

    return 
0;
}

DWORD WINAPI server_to_client(void*)
{
    
char buf[4096];
    
DWORD lentmp;
    while (
1) {
        if (!
ReadFile(hRecvPipebuf4096, &lenNULL)) { break; }
        
cout << "Server --> Client" << endl;
        
output_packet(buflen);
        
cout << endl;
        
//WriteFile(hRecvPipe, buf, len, &tmp, NULL);
    
}
    return 
0;
}

DWORD WINAPI client_to_server(void*)
{
    
char buf[4096];
    
DWORD lentmp;
    while (
1) {
        if (!
ReadFile(hSendPipebuf4096, &lenNULL)) { break; }
        
cout << "Client --> Server" << endl;
        
output_packet(buflen);
        
cout << endl;
        
//WriteFile(hSendPipe, buf, len, &tmp, NULL);
    
}
    return 
0;

clintonselke is offline  
Old 05/06/2009, 12:09   #2
 
elite*gold: 0
Join Date: Jun 2006
Posts: 965
Received Thanks: 576
Try doing

Code:
int WINAPI our_recv(SOCKET s, char* buf, int len, int flags)
{
    DWORD tmp;
    lastSocket = s;
    len = pRecv(s, buf, len, flags);
    if (len > 0)
    {
        recvPipe.write(buf, len);
        recvPipe.flush();
    }
    //recvPipe.read(buf, len);
    return len;
}
Why? Because recv is called by conquer asynchronously. Meaning that if there is no data to receive, recv returns -1 right away.
high6 is offline  
Thanks
1 User
Old 05/06/2009, 12:58   #3
 
clintonselke's Avatar
 
elite*gold: 0
Join Date: Feb 2007
Posts: 348
Received Thanks: 2,175
Quote:
Originally Posted by high6 View Post
Try doing

Code:
int WINAPI our_recv(SOCKET s, char* buf, int len, int flags)
{
    DWORD tmp;
    lastSocket = s;
    len = pRecv(s, buf, len, flags);
    if (len > 0)
    {
        recvPipe.write(buf, len);
        recvPipe.flush();
    }
    //recvPipe.read(buf, len);
    return len;
}
Why? Because recv is called by conquer asynchronously. Meaning that if there is no data to receive, recv returns -1 right away.
high6 high6 high6 !!! UR a Genius!!! IT WORKS NOW... u rock

Thank you man!

Edit: I was about to give up and turn it into a proxy lol... then u fixed it
clintonselke is offline  
Reply


Similar Threads Similar Threads
[Help]HackShield detected send,recv hook c++
08/17/2010 - C/C++ - 6 Replies
Entschuldigung für noch einen Thread am selben Tag aber das passt glaub ich nicht wirklich in das andere deswegen eröffne ich einen neuen. Wenn ich die Winsock send recv hooke detected das Hackshield nach ca. 2 minuten einen hack kann man das Bypassen ? Und wenn ja,wie sollte ich anfangen. Würde mich freuen auf eine Antwort. Mit freundlichen Grüßen :)
[Question] Hp and Mana Pointer / Recv
10/22/2009 - Kal Online - 5 Replies
Hey could anyone tell me what's the hp pointer and mana pointer on private servers? If i search myself my PC crashes How can i see what's inside the Recv packets(what type/number) Thanks
Send Recv
08/18/2009 - Kal Online - 0 Replies
Hey;) I start checking this code http://www.elitepvpers.com/forum/kal-hacks-bots-che ats-exploits/189618-release-kalhackzz-v0-3-v0-4-so urces.html but i cant still send a packet of move just to see my player moving.Maybe this code is obsolete i dont know if there are better send and rev codes just tell me When dll process attach happens i call my function _beginthread(f,0,NULL); void f(void* start_parameter){ Console(); //Get the console printf("DLL loaded");
[help] recv
08/02/2009 - Kal Online - 3 Replies
Soo, man man behinderter tag. naja wayne. bin grad dabei mich etwas mehr mit den recv packets außeinander zu setzen. unter anderem mit den zahlen dahinter. Borsti sagte das ist die größe (size) naja also ich hab mir das mal als hex ausgeben lassen (das packet für empfangene nachrichten im chat ) ich hab mir das folgendermaßen "notiziert" 0c 00 3c //size 44 65 6e 4a 61 73//name
Problems while detouring send() and recv().
02/28/2009 - General Coding - 5 Replies
Hi there, i've a problem. I'm not sure if i've done some misstakes. But every time i inject my dll the game will crash while i get or send a packet. Maybe someone can help me? I'll post the source code. #include <windows.h> #include "detours.h" #pragma comment(lib, "detours.lib") DWORD RecvOffset = 0x00D95060;



All times are GMT +2. The time now is 16:41.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.