Code Monkey home page Code Monkey logo

Comments (28)

bldd14 avatar bldd14 commented on June 12, 2024

Here are the steps:

  1. The client sends the ID_OPEN_CONNECTION_REQUEST (24) packet with 2 empty bytes for alignment to the server.

  2. The server replies with ID_OPEN_CONNECTION_COOKIE (26) packet + the random cookie value which has a length of 2 bytes (its value is updated every (connseedtime) milliseconds, this interval can be specified in the server.cfg).

  3. The client sends ID_OPEN_CONNECTION_COOKIE (26) packet + the random cookie value the server sent but xored by 0x6969 (For SA-MP 0.3.7 R1 to R4, not sure if it's the same for SA-MP 0.3DL).

  4. After the server has received the response from the client, it xors the 2-byte length value the client sent with the ID_OPEN_CONNECTION_COOKIE (26) packet by 0x6969, if it's equal to the current server conncookie value (the 2 bytes random value I mentioned before) then it lets you join in, if it isn't, the process is repeated.

Keep in mind that every packet is encrypted by RakNet, that's the reason why the first packet, which only contains 3 bytes, ends as a 4 bytes value (which in addition to the 28 bytes of the header (iphdr + udphdr) gives you that 32 bytes packet).

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

ADRFranklin avatar ADRFranklin commented on June 12, 2024

Unfortunately there is nothing you can do at this stage to prevent udp flood, the only option you would have would be to either whitelist IP addresses, or setting up a load balancer and distributing the connections between multiple servers, however such a thing is extremely difficult to implement with something like sa-mp, because it was never designed to be used in such a way.

I mean you could potentially put a proxy in between it and drop bad packets that sent invalid response values, but this will only work so much, and you'd had to implement the proxy yourself in it's entirety. I actually started working on this exact idea a while ago, but didn't get around to finishing it.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

ADRFranklin avatar ADRFranklin commented on June 12, 2024

You can't fix this issue at all the way you are doing it, because the server itself needs to generate a cookie for the connection itself which it stores internally to validate the connection. If you are doing this yourself then the server will always drop any client packets you proxy to it. The server has to be able to validate the connection before it will continue processing it.

Also I also find that this route will not work out for you, because you might be able to check for them sending invalid responses, but what happens if they decide to keep sending valid responses? There would be no way to work out if the person sending it is an attacker or a legit user.

At the end of the day the server has to be the one in control of this process. The only way I could see this working, is if you wrote a plugin that hooks into sa-mp and removes the connection cookie check all together, and then you re-implement such a thing on your end. But that is something that would take time to do.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

ADRFranklin avatar ADRFranklin commented on June 12, 2024

They don't have it fixed, they have a temp solution to a specific request. As soon as that request is modified which is a single change in the source code, your entire protection becomes useless.

These methods require more then a little check and drop scripts.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

bldd14 avatar bldd14 commented on June 12, 2024

@AdrianBZG Sorry for the delayed response. Usually the conncookie flood overwhelms your server so even if you cache the connection cookie like some German folk did on his proxy thing, your server will use all of your CPU and you wouldn't even be able to play it.
You can actually do some hard-coded stuff and make a LKM, which listens to your server port and check whenever it receives a connection request. If the connection gets to step 4 successfully then you let the connection actually reach the SA-MP server.
That's how SYN proxy works, you can do the same thing for RakNet connections, even.
There's not much you can do, sadly. This is a design issue and should be fixed with a client-side part.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

bldd14 avatar bldd14 commented on June 12, 2024

@AdrianBZG LKM stands for Loadable Kernel Module.

Information I gave to you should be enough. iptables isn't needed in case you use LKMs, you must code it yourself.
You can look at RakSamps' code (https://github.com/6D6C666A/RakSAMP) to guide yourself.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

bldd14 avatar bldd14 commented on June 12, 2024

@AdrianBZG
https://github.com/LoleroChitero/RakSAMP/blob/master/raknet/RakPeer.cpp#L3986

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

bldd14 avatar bldd14 commented on June 12, 2024

Remember, all packets but those which are sent by the server are encrypted!
https://github.com/LoleroChitero/RakSAMP/blob/master/raknet/RakPeer.cpp#L3986
https://github.com/LoleroChitero/RakSAMP/blob/master/raknet/RakPeer.cpp#L3986

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

bldd14 avatar bldd14 commented on June 12, 2024

If the packets are coming from the client, yes. use unkyretardizeDatagram for that and the data will be allocated on decrBuffer.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

bldd14 avatar bldd14 commented on June 12, 2024

Spoof the connection packet from your LKM using the player's IP.
You can disable the connection cookies in your server, that way you will only need spoof the first packet (set conncookies to 0 in your server.cfg).
NOTE: This will only reduce the harm this attack does, but will not completely fix it.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

bldd14 avatar bldd14 commented on June 12, 2024

Yes, it's possible indeed.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

bldd14 avatar bldd14 commented on June 12, 2024

You can place a hook before the packet reaches the iptables NAT table (in the case you're using iptables to redirect the packets), in your hook check if the IP is associated with an existing samp connection, if it isn't then the first packet should be the connection cookie or a samp query.
If the packet comes from an existing connection you can simply let it pass in.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

bldd14 avatar bldd14 commented on June 12, 2024

Yes I implemented that system some time ago.
Public RakServer conncookie system is implemented but not used so you'll need to make it work on your own.
Since your first question is answered, I'm going to close this issue, hope your doubts are cleared.

from samp-packet-list.

AdrianBZG avatar AdrianBZG commented on June 12, 2024

.

from samp-packet-list.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.