[SOURCE] Hook Connection To Any Server

11/14/2016 19:34 atom0s#1
Here is how to connect to any server without altering the client exe at all. This can be done via DLL injection using the Detours library from Microsoft:

Code:
/**
 * Detour Prototypes
 */
extern "C"
{
    int         /**/(WINAPI *Real_connect)(SOCKET, const struct sockaddr*, int) = connect;
};


/**
 * winsock2!connect Detour Callback
 */
int  __stdcall Mine_connect(SOCKET s, const struct sockaddr* name, int namelen)
{
    auto saddr = (sockaddr_in*)name;


    // Check if this is a login attempt..
    if (saddr->sin_port >= htons(4000) && saddr->sin_port <= htons(4013))
    {
        auto naddr = HookCore::instance().m_ConfigurationManager->GetConfigString("noshook", "override_server_addr");
        auto nport = HookCore::instance().m_ConfigurationManager->GetConfigInt("noshook", "override_server_port", 4001);
        saddr->sin_addr.s_addr = inet_addr(naddr);
        saddr->sin_port = htons(nport);
    }


    return Real_connect(s, name, namelen);
}


// Apply the mutex detour:
::DetourTransactionBegin();
::DetourUpdateThread(::GetCurrentThread());
::DetourAttach(&(PVOID&)Real_connect, Mine_connect);
::DetourTransactionCommit();
11/14/2016 19:38 Cryless~#2
Useless, you can just run client using EntwellNostaleClientLoadFromIni
11/14/2016 20:31 Bejine#3
Quote:
Originally Posted by SystemX64™ View Post
Useless, you can just run client using EntwellNostaleClientLoadFromIni
Yup, it doesn't really bug, so it works perfectly with any IP/Port.
11/14/2016 20:48 FI0w#4
Quote:
Originally Posted by SystemX64™ View Post
Useless, you can just run client using EntwellNostaleClientLoadFromIni
As you know because i gave you it looooong time ago it works good and in this case your right :P the Argument is better as the Code of the Thread Creator

For People who want to use the Argument Create a file called Config.ini and inside the file you write:

[NosTale_Network]
IP=YOUR_IP
Port=YOUR_PORT
11/14/2016 21:02 Cryless~#5
Quote:
Originally Posted by xSensitivex View Post
As you know because i gave you it looooong time ago it works good and in this case your right :P the Argument is better as the Code of the Thread Creator

For People who want to use the Argument Create a file called Config.ini and inside the file you write:

[NosTale_Network]
IP=YOUR_IP
Port=YOUR_PORT
It is still too difficult to understand for some people on this forum.
Then I step to the bad guy because I know it better. Knowledge is a double-edged sword.
11/16/2016 12:17 ernilos#6
Actually the code snippet it's pretty usefull (talking beyond NosTale), I've used connect detour countless times to redirect client connections whenever I'm not able/or lazy to found out how IP is given or anything.
04/18/2021 04:05 vicy11#7
Bara 3asba