Nostale Packet Sniffer

03/18/2023 13:09 -Unknow#1
Hello :), i'm trying to create a proxy in C that stands between the client and the nostale server and shows me the packets exchanged with the game. I see that every time notale is started on a local port which is dynamic and changes every time the game is opened. Below is my C code used to create the TCP proxy.
Should I need to implement in this code something that allows me to preload the port on the nostal hooks? And if so, can anyone tell me which solutions I could adapt?

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>

#pragma comment(lib, "ws2_32.lib")

#define PORT LOCAL_PORT

int main() {
    WSADATA wsa;
    SOCKET s, new_socket;
    struct sockaddr_in server, client;
    int c;

    printf("\nInitializing Winsock...");
    if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) {
        printf("WSAStartup failed. Error Code : %d", WSAGetLastError());
        return 1;
    }


    if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
        printf("Could not create socket : %d", WSAGetLastError());
    }

    server.sin_family = AF_INET;
    server.sin_addr.s_addr = INADDR_ANY;
    server.sin_port = htons(PORT);

    if (bind(s, (struct sockaddr*)&server, sizeof(server)) == SOCKET_ERROR) {
        printf("Bind failed with error code : %d", WSAGetLastError());
    }


    listen(s, 3);

    puts("Waiting for incoming connections...");
    c = sizeof(struct sockaddr_in);
    while ((new_socket = accept(s, (struct sockaddr*)&client, &c)) != INVALID_SOCKET) {
        puts("Connection accepted");

        SOCKET server_socket = socket(AF_INET, SOCK_STREAM, 0);
        if (server_socket == INVALID_SOCKET) {
            printf("Could not create socket : %d", WSAGetLastError());
            return 1;
        }
        struct sockaddr_in server_address;
        server_address.sin_family = AF_INET;
        server_address.sin_addr.s_addr = inet_addr("NOSTALE_IP_SERVER");
        server_address.sin_port = htons(NOSTALE_PORT);
        if (connect(server_socket, (struct sockaddr*)&server_address, sizeof(server_address)) < 0) {
            printf("Connection error");
            return 1;
        }

        char buffer[1024];
        int bytes_received;
        while ((bytes_received = recv(new_socket, buffer, sizeof(buffer), 0)) > 0) {
            send(server_socket, buffer, bytes_received, 0);
            memset(buffer, 0, sizeof(buffer));

            bytes_received = recv(server_socket, buffer, sizeof(buffer), 0);
            send(new_socket, buffer, bytes_received, 0);
            memset(buffer, 0, sizeof(buffer));
        }

        closesocket(server_socket);
        puts("Remote server connection closed");

        closesocket(new_socket);
        puts("Client connection closed");
    }
    WSACleanup();

    return 0;
}
Sorry for my english and ty to all
03/18/2023 15:36 Apourtartt#2
Hello,

First of all I want to mention that I never did it, so it is only guesses + information that I found in the previous months/years.

Your "proxy" should be a server to your client and a client to Nostale server, therefore the local port from Nostale client should not really matter, as you are anyway only listening to it.

NostaleClientX.exe (client) <=> (server) Your proxy (client) <=> (server) GF's servers

That also means you will find a way to redirect NostaleClientX.exe's packets to your proxy (there are many ways to do it, just pick the most suitable for you)

TL;DR: You don't need to handle the client local port
03/18/2023 15:52 -Unknow#3
Hi :) , thank you for the answer,
It should be just like you said, only that by setting any free port, the software stays on "wainting connection", no connection is intercepted. Of course, all this by starting the Tcp proxy first and then the nostal client
03/18/2023 18:39 AfterLife-#4
I've created a Proxy via C# once a few years ago..
[Only registered and activated users can see links. Click Here To Register...]
03/18/2023 19:22 -Unknow#5
Quote:
Originally Posted by AfterLife- View Post
I've created a Proxy via C# once a few years ago..
[Only registered and activated users can see links. Click Here To Register...]
Hi, thanks for the reply. I will to know if it is possible to force nostal traffic on a specific port or if there is a way to understand on which port it will listen on to set it before the proxy
03/19/2023 20:11 AfterLife-#6
The port for the login server is set in the executable file and varies depending on the language of the client.

Here are the corresponding port values for each language:

Upon logging in, you will be provided with the IP address and port number of the world server that you are attempting to connect to. If nothing has been changed, you may refer to my previous response in the HandlePacket function.
04/12/2023 05:51 matuf98#7
It looks like you are trying to create a TCP proxy in C that stands between a client and a Nostale game server. Your code creates a socket and listens on a dynamic local port for incoming connections. When a connection is accepted, your code connects to the Nostale server, reads data from the client, forwards it to the Nostale server, and then reads data from the Nostale server and forwards it to the client.

To answer your question, it is possible to preload the port on the Nostale hooks, but it would require modifying the Nostale game client to use a fixed port instead of a dynamic one. This is not something you can do from the proxy server side.

However, you can modify your proxy server code to detect the local port that the Nostale game client is using and then use that same port to connect to the Nostale server. One way to do this is to use a packet sniffer library like WinPcap or Npcap to capture the packets exchanged between the Nostale game client and the server, and then parse the packets to extract the local port used by the client. You can then modify your code to use this port to connect to the server.

Another way to detect the local port used by the Nostale game client is to use the Windows API function GetExtendedTcpTable, which returns a table of all TCP endpoints on the local machine. You can search this table for an endpoint with a matching remote IP address and port number to the Nostale server, and then use the corresponding local port number to connect to the server.

Keep in mind that intercepting and manipulating network traffic can have legal and ethical implications, so make sure you have permission to do so before proceeding with your project.
04/12/2023 09:59 AfterLife-#8
Quote:
Originally Posted by matuf98 View Post
It looks like you are trying to create a TCP proxy in C that stands between a client and a Nostale game server. Your code creates a socket and listens on a dynamic local port for incoming connections. When a connection is accepted, your code connects to the Nostale server, reads data from the client, forwards it to the Nostale server, and then reads data from the Nostale server and forwards it to the client.

To answer your question, it is possible to preload the port on the Nostale hooks, but it would require modifying the Nostale game client to use a fixed port instead of a dynamic one. This is not something you can do from the proxy server side.

However, you can modify your proxy server code to detect the local port that the Nostale game client is using and then use that same port to connect to the Nostale server. One way to do this is to use a packet sniffer library like WinPcap or Npcap to capture the packets exchanged between the Nostale game client and the server, and then parse the packets to extract the local port used by the client. You can then modify your code to use this port to connect to the server.

Another way to detect the local port used by the Nostale game client is to use the Windows API function GetExtendedTcpTable, which returns a table of all TCP endpoints on the local machine. You can search this table for an endpoint with a matching remote IP address and port number to the Nostale server, and then use the corresponding local port number to connect to the server.

Keep in mind that intercepting and manipulating network traffic can have legal and ethical implications, so make sure you have permission to do so before proceeding with your project.
ChatGPT Copy & Paste on a few weeks inaktiv Thread.. Noice
05/01/2023 06:04 matuf98#9
Quote:
Originally Posted by AfterLife- View Post
ChatGPT Copy & Paste on a few weeks inaktiv Thread.. Noice
yeah, just lazy writing tbh
05/01/2023 11:48 Fizo55#10
Quote:
Originally Posted by matuf98 View Post
yeah, just lazy writing tbh
Just a lack of knowledge*