LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   Game server under attack (https://www.linuxquestions.org/questions/linux-security-4/game-server-under-attack-908100/)

smallgamer 10-14-2011 01:20 AM

Game server under attack
 
I run a gaming server on Centos. It's the most popular server in my game, and some people who don't like that have been attacking it daily. It's being done by spoofing or spamming some kind of packet to the server.

The game server process continues to run on the Centos server, but it no longer appears on the game list and players can not connect to it.

I have no idea where to begin figuring out how this is being done and how to stop it. Any ideas? [REMOVED]

Thanks for any guidance you can provide. I've been dealing with this for months and it's starting to drive me crazy (and ruin my server).

lithos 10-14-2011 02:41 AM

you should have iptables firewall up and running to allow only the ports the server needs for your 'game'
check your LOG files (/var/log/httpd etc.)
post the results

post your "iptables -L" or "cat /etc/sysconfig/iptables"

smallgamer 10-14-2011 10:57 AM

I'm curious why you wrote 'game' instead of game, lol. If you're actually interested I could PM you the server info and you can check it out. Anyway, thank you for your help so far.

I looked in the /var/log/httpd folder and there are a few files there. I'm not sure exactly what I'm looking for though. Sorry - could you be more specific please (I'm an admitted noob)?

This is what I get when I do "iptables -L" (I assume it's default since I've never touched it):

Code:

Chain INPUT (policy ACCEPT)
target    prot opt source              destination       

Chain FORWARD (policy ACCEPT)
target    prot opt source              destination       

Chain OUTPUT (policy ACCEPT)
target    prot opt source              destination       
[root@michigan2 ~]#

And here is "cat /etc/sysconfig/iptables" (again assuming this is default):

Code:

# Load additional iptables modules (nat helpers)
#  Default: -none-
# Space separated list of nat helpers (e.g. 'ip_nat_ftp ip_nat_irc'), which
# are loaded after the firewall rules are applied. Options for the helpers are
# stored in /etc/modprobe.conf.
IPTABLES_MODULES=""

# Unload modules on restart and stop
#  Value: yes|no,  default: yes
# This option has to be 'yes' to get to a sane state for a firewall
# restart or stop. Only set to 'no' if there are problems unloading netfilter
# modules.
IPTABLES_MODULES_UNLOAD="yes"

# Save current firewall rules on stop.
#  Value: yes|no,  default: no
# Saves all firewall rules to /etc/sysconfig/iptables if firewall gets stopped
# (e.g. on system shutdown).
IPTABLES_SAVE_ON_STOP="no"

# Save current firewall rules on restart.
#  Value: yes|no,  default: no
# Saves all firewall rules to /etc/sysconfig/iptables if firewall gets
# restarted.
IPTABLES_SAVE_ON_RESTART="no"

# Save (and restore) rule and chain counter.
#  Value: yes|no,  default: no
# Save counters for rules and chains to /etc/sysconfig/iptables if
# 'service iptables save' is called or on stop or restart if SAVE_ON_STOP or
# SAVE_ON_RESTART is enabled.
IPTABLES_SAVE_COUNTER="no"

# Numeric status output
#  Value: yes|no,  default: yes
# Print IP addresses and port numbers in numeric format in the status output.
IPTABLES_STATUS_NUMERIC="yes"

# Verbose status output
#  Value: yes|no,  default: yes
# Print info about the number of packets and bytes plus the "input-" and
# "outputdevice" in the status output.
IPTABLES_STATUS_VERBOSE="no"

# Status output with numbered lines
#  Value: yes|no,  default: yes
# Print a counter/number for every rule in the status output.
IPTABLES_STATUS_LINENUMBERS="yes"


Noway2 10-14-2011 12:40 PM

First off, welcome to LQ Security. The output of those two commands shows that you are not running any sort of firewall on your system. In terms of administering a public facing server, running a game or 'game' server is tantamount to putting a bulls-eye target on yourself as they are frequently targeted for all sort of ill activity, including DOS (Denial of Service) type attacks. As an admitted noob, you will face extra, but not insurmountable, challenges in dealing with it.

The first order of business will be to determine the type of attack you are being exposed to. You mentioned that some form of packet is being spammed or spoofed to your server. Could you please be more specific? How did you determine you were being attacked, what do these packets look like, what effect are they having, are they coming from one particular source or multiple sources, etc. Please be verbose in your description and provide as much detailed information as you possibly can. LQ Security has some extremely knowledgeable people and we can certainly help you with this problem, but we prefer and will need to deal with facts. To that end, as much specific information as you can provide will be helpful.

smallgamer 10-14-2011 01:41 PM

I'll try to answer all of your questions.

I know I'm under attack because these same people have been attacking my server for about a year now. Originally it was a chat flood, where they used a little script to spam in-game chat messages fast enough to make the game server crash (not the centos server, but the "game server" running on it... not sure if there is better terminology for that distinction). This is an independently developed game, so I have access to the developer and was able to get him to patch that.

Then they proceeded to start "spoofing" other players' in-game logins, and since those credentials are used to assign administrative rights to certain players, spoofing those players allowed them to do all sorts of things like mass banning players, changing server settings to the point of crippling the game and making it unplayable, etc. The developer was able to patch this also.

As far as the current attack, I'm less clear on exactly how they're doing it. The effect is that my server is unresponsive to the main-gameserver-tracking-server-the-developer-owns, so it disappears from the in-game server list, and it also becomes unresponsive to players who try to play on it or join it. However, the process continues running on centos. I do know that it's this same group with another attack, based on forum chatter and "the grapevine", and I say that they are doing it by sending packets for a few reasons. 1- I'm hearing that it's done via a winsock application. 2- I'm also hearing that these same people have been DOSing other servers (not sure whether that conflicts with #1). 3- The game logs (not the centos logs, which I'm pretty unfamiliar with, but the mediocre game server logs that document the in-game action and minor game server stuff) don't really show anything, unlike the previous chat spam attacks that were visible in the logs.

I don't know what the packets look like per se. I also don't know whether they're coming from one source or multiple sources.

Since I don't use this server for anything but gaming, what I'd really like to do is completely lock down everything else on the server... so that it basically ignores any packets that aren't sent to this specific application, but also logs any packets that are spammed at this application in case that's what is happening. I also want to make sure nobody can connect to the server in any way except for the game... meaning email services, http stuff, cron, anything that would allow my server to be controlled remotely (again, not that familiar with centos yet), and any possibility of other users or accounts existing on the system.

Of course, I don't know what I'm talking about in the slightest, but a complete lockdown sounds really good right now, and like I said, I'm not using any of that stuff.

EDIT: I should have also mentioned that I'm running centos on a VPS, since that might matter.

travisdh1 10-14-2011 03:34 PM

If you have a gui installed (something like a windows desktop) you should be able to use the system-config-firewall to get you started with locking down the system. Just remember to make sure you don't block the remote desktop port you're using! (Made that mistake a number of times myself.) If it's not installed just do a
Code:

yum -y install system-config-firewall
to download and install it. It's easy enough to use that as long as you know the port(s)/protocol(s) you need you should be good to go.

smallgamer 10-15-2011 05:41 AM

Quote:

as long as you know the port(s)/protocol(s) you need
I don't.

Anyway, I've received some more information indicating that this is being done with a UDP dos attack, presumably on the port from which the game is running on my server. Does anyone know how I can log and stop this type of attack?

unSpawn 10-15-2011 06:43 AM

Quote:

Originally Posted by smallgamer (Post 4499067)
I've received some more information indicating that this is being done with a UDP dos attack, presumably on the port from which the game is running on my server. Does anyone know how I can log and stop this type of attack?

First things first. Until we have a clear picture of what you need please stop and disable any publicly accessible services you don't need for server maintenance like web-based server management panels, FTP, VNC, SMTP, etc. You need SSH but ensure you use an unprivileged account with pubkey auth and not log in as root (more here: http://www.linuxquestions.org/questi...tempts-340366/). As you don't run a default firewall (the rules listing in chapter 2 http://wiki.centos.org/HowTos/Network/IPTables is) we need to set one up first and as quickly as possible. To help you set up /etc/sysconfig/iptables please post a list of ports in use
Code:

netstat -ntulpe
by services and obfuscate your IP address with something like "1.2.3.4". Also list enabled services
Code:

chkconfig --list | grep "$(runlevel|awk '{print $2}'):on";
and as much technical details about the game or games you're running. The more nfo the better and the quicker your reply the better.

salasi 10-15-2011 07:01 AM

Quote:

Originally Posted by smallgamer (Post 4498614)
...The developer was able to patch this also...

If you have that kind of access to the developer, you really ought to be able to find out what ports and protocols should normally be in use for the game.

I like wireshark for getting a screen dump of all traffic, but how useful this is will be a function of whether you can capture data when there isn't much 'good' traffic and a lot of 'bad' traffic.

It will be very helpful to know what the attack packets actually look like, because, for some cases there will be simple iptables blocks, and for others it would be more involved. Obviously. you should be trying to progress to a more secure situation, and a firewall will be an important part of that whatever the current attack looks like, but, if you are under attack currently, that must have a degree of priority.

Quote:

Originally Posted by smallgamer (Post 4498614)
..."spoofing" other players' in-game logins, and since those credentials are used to assign administrative rights to certain players, spoofing those players allowed them to do all sorts of things like mass banning players, changing server settings to the point of crippling the game and making it unplayable, etc.

You seem to be referring to attempts to crack passwords, by something like a brute-force or a dictionary attack. This is not the normal use of the word spoofing in connection with networking, so be careful with this. (And, if it is an attack from one, or a small number, of ip addresses, iptables can help here, too. Particularly important to look at the actual data, and see what it looks like, then.)

Quote:

Originally Posted by smallgamer (Post 4498614)
but also logs any packets that are spammed at this application in case that's what is happening. I also want to make sure nobody can connect to the server in any way except for the game... meaning email services, http stuff, cron, anything that would allow my server to be controlled remotely (again, not that familiar with centos yet), and any possibility of other users or accounts existing on the system.

Of course, I don't know what I'm talking about in the slightest, but a complete lockdown sounds really good right now, and like I said, I'm not using any of that stuff.

iptables also has some logging capabilities, so it could help there too. The trouble is defining what is a 'good' (ie, normal game packet) and what is a 'bad' packet. Again, looking at the actual data, it could jump off the page. Or, not. You won't know until you've actually looked at some data.

Quote:

I do know that it's this same group with another attack, based on forum chatter and "the grapevine", and I say that they are doing it by sending packets for a few reasons.
1- I'm hearing that it's done via a winsock application.
2- I'm also hearing that these same people have been DOSing other servers (not sure whether that conflicts with #1).
3- The game logs (not the centos logs, which I'm pretty unfamiliar with, but the mediocre game server logs that document the in-game action and minor game server stuff) don't really show anything, unlike the previous chat spam attacks that were visible in the logs.
Too much there that is hearsay, and which doesn't give actual details of the packets.

All that 1) means, if true, is that they using Windows. Not that helpful as a way of countering the threat.
2) means that there is a rumour that the same people have been using a denial of service attack of some sort. Even if it can be relied upon, that doesn't tell you very much (can you rely on the idea that it isn't a DDoS...I doubt it, unless you know more about the technical capability of the person who gave you the report, and whether it is a DoS or a DDoS does make a difference in how easy it is to take short-term measures against.)
3) isn't all that helpful, either, unless the implication is that game developer can again enhance the logs to help you.

smallgamer 10-15-2011 07:08 AM

netstat -ntulpe

Code:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address              Foreign Address            State      User      Inode      PID/Program name 
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                  LISTEN      0          1307246    1444/httpd         
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                  LISTEN      0          1075709    1390/sshd         
udp        0      0 0.0.0.0:36943              0.0.0.0:*                              0          571514324  16162/cs2d_dedicate
udp        0      0 0.0.0.0:36944              0.0.0.0:*                              500        571524858  16183/cs2d_dedicate

chkconfig --list | grep "$(runlevel|awk '{print $2}'):on";

Code:

crond          0:off  1:off  2:on    3:on    4:on    5:on    6:off
httpd          0:off  1:off  2:off  3:on    4:off  5:off  6:off
iptables        0:off  1:off  2:on    3:on    4:on    5:on    6:off
network        0:off  1:off  2:on    3:on    4:on    5:on    6:off
saslauthd      0:off  1:off  2:off  3:on    4:off  5:off  6:off
sendmail        0:off  1:off  2:on    3:on    4:on    5:on    6:off
sshd            0:off  1:off  2:on    3:on    4:on    5:on    6:off
syslog          0:off  1:off  2:on    3:on    4:on    5:on    6:off
vzquota        0:on    1:on    2:on    3:on    4:on    5:on    6:on
xinetd          0:off  1:off  2:off  3:on    4:on    5:on    6:off

Quote:

and as much technical details about the game or games you're running
The game is *edited to avoid attackers finding this in Google*. I'm not too aware of all of the technical details though. If there's anything specific you need to know, I can talk to the developer and get that information for you.

smallgamer 10-15-2011 07:15 AM

Quote:

If you have that kind of access to the developer, you really ought to be able to find out what ports and protocols should normally be in use for the game.
I am certain that you're right. But I wouldn't know how to go about locking down everything else that should not be in use. Also, my (limited) understanding of the current attack is that it's going to the port that has to be open in order for the game to run, and that it's sending a packet that the game accepts (but flooding the server with it).

If that is correct, then I will need to be able to log when packets are flooded that way, check what IP the packets came from, and then completely block any future packets from that IP so that they don't enter the server and reach the gaming software that is running on it.

Quote:

You seem to be referring to attempts to crack passwords, by something like a brute-force or a dictionary attack. This is not the normal use of the word spoofing in connection with networking, so be careful with this. (And, if it is an attack from one, or a small number, of ip addresses, iptables can help here, too. Particularly important to look at the actual data, and see what it looks like, then.)
Well, they were sending the server a packet that the game client normally sends the server, which tells the server what player it's dealing with. Player logins are done in the game client, and all of the servers simply listen to the login that the game client sends them. So they spoofed that and didn't need to use any kind of password cracking. Luckily, the developer patched that pretty quickly.

Quote:

I like wireshark for getting a screen dump of all traffic, but how useful this is will be a function of whether you can capture data when there isn't much 'good' traffic and a lot of 'bad' traffic.
I'm not really sure if that's the case or not. There are definitely a lot of packets flying around though, as this is a real-time shooting game.

Quote:

iptables also has some logging capabilities, so it could help there too. The trouble is defining what is a 'good' (ie, normal game packet) and what is a 'bad' packet. Again, looking at the actual data, it could jump off the page. Or, not.
I'm not entirely sure if the packet itself is any different from the packets that are normally sent to the server, or if it's the same kind of packet but just flooded to make the attack.

unSpawn 10-15-2011 07:56 AM

Quote:

Originally Posted by smallgamer (Post 4499104)
netstat -ntulpe
Code:

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                  LISTEN      0          1307246    1444/httpd         
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                  LISTEN      0          1075709    1390/sshd         
udp        0      0 0.0.0.0:36943              0.0.0.0:*                              0          571514324  16162/cs2d_dedicate
udp        0      0 0.0.0.0:36944              0.0.0.0:*                              500        571524858  16183/cs2d_dedicate


OK, so only TCP/22,80 and UDP/369... Lets see if we can build you an /etc/sysconfig/iptables replacement before moving on to packet inspection:
Code:

*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
# Accept localhost.
-A INPUT -i lo -j ACCEPT
# Accept established traffic.
-A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Log and deny invalid connections.
-A INPUT -m conntrack --ctstate INVALID -j LOG --log-prefix "IN_inv "
-A INPUT -m conntrack --ctstate INVALID -j REJECT
# Log and limit TCP SYN connections to 30 per /24 range.
-A INPUT -m tcp -p tcp --syn -m connlimit --connlimit-above 30 --connlimit-mask 24 -j LOG --log-prefix "IN_lim "
-A INPUT -m tcp -p tcp --syn -m connlimit --connlimit-above 30 --connlimit-mask 24 -j REJECT
# Log and limit new UDP connections to 100 per /24 range.
-A INPUT -m udp -p udp -m state --state NEW -m connlimit --connlimit-above 100 --connlimit-mask 24 -j LOG --log-prefix "IN_lim "
-A INPUT -m udp -p udp -m state --state NEW -m connlimit --connlimit-above 100 --connlimit-mask 24 -j REJECT
# Log and accept SSH and HTTP.
-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 22,80 -j LOG  --log-prefix "IN_tcpnew "
-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 22,80 -j ACCEPT
# Log and accept CS2D. It actually uses a range and I don't know how wide it is so from logging you'll know so
# you can tighten it.
-A INPUT -m state --state NEW -m udp -p udp -m multiport --dports 36900:36999 -j LOG  --log-prefix "IN_udpnew "
-A INPUT -m state --state NEW -m udp -p udp -m multiport --dports 36900:36999 -j ACCEPT
# This part of the INPUT chain should never be reached as long as the default policy is DROP. You'll appreciate
# this failsafe when your default policy changes and you forgot to adjust things.
-A INPUT -m limit --limit 1/minute --limit-burst 3 -j LOG --log-prefix "IN_rej "
-A INPUT -j REJECT --reject-with icmp-host-prohibited
# The OUTPUT chain doesn't need rules since your policy is ACCEPT but I like to have localhost in it anyway.
-A OUTPUT -i lo -j ACCEPT
COMMIT

Save this as /etc/sysconfig/iptables.new then activate like this (could use 'at' instead) since all your IPTABLES_SAVE.*= variables are set to "no":
Code:

#!/bin/sh --
/sbin/iptables-restore < /etc/sysconfig/iptables.new
sleep 5m
/etc/rc.d/init.d/iptables restart
exit 0

this allows you five minutes for testing / looking at logging after which the default script (having no rules :-( ) will be enabled. If you think this rule set works then
Code:

cp /etc/sysconfig/iptables /etc/sysconfig/iptables.bak && cat /etc/sysconfig/iptables.new > /etc/sysconfig/iptables && /etc/rc.d/init.d/iptables restart
- Note that SSH should really be confined to your management IP range or at least protected by 'fail2ban' or equivalent. The same would go for HTTP if you only use it for web-based service or server management. Also note the above rule set explicitly denies SMTP traffic (even though a standard sendmail.cf should have the MTA running on only loopback).
- Do adjust limits if you find a lot of logged "IN_lim " lines in /var/log/messages.
- Also see http://wiki.centos.org/HowTos/Network/IPTables, http://www.centos.org/docs/5/html/De...-US/ch-fw.html and http://www.frozentux.net/iptables-tu...-tutorial.html for a basic understanding of Netfilter / iptables.
- While you're at it run 'yum install logwatch' and run your logs through it. Not related to you getting DoSsed but it would be good to see if there's other things to address.

smallgamer 10-15-2011 11:02 AM

When I try to enter:

/sbin/iptables-restore < /etc/sysconfig/iptables.new

I get this message:

Code:

[root@michigan2 ~]# /sbin/iptables-restore < /etc/sysconfig/iptables.new
'ptables-restore v1.3.5: iptables-restore: unable to initializetable 'filter

Error occurred at line: 1
Try `iptables-restore -h' or 'iptables-restore --help' for more information.


smallgamer 10-15-2011 11:11 AM

I'm no longer getting that error now that I input the iptables text you gave me directly in centos using the vi tool, instead of saving it in a text editor. Now I am getting an error that -i can't be used with output. When I remove -i, I get another error saying "lo" is a bad argument.

unSpawn 10-15-2011 01:54 PM

Oops.

0) It's missing a "# Generated by iptables-save v1.3.5 on Sat Oct 15 00:00:01 2011" line before the "*filter" line,
1) Should be "-A OUTPUT -o lo -j ACCEPT".

If you change the loopback line then you should be able to execute the script like before. If that doesn't work try

Code:

#!/bin/sh --
/sbin/iptables -P INPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -P OUTPUT ACCEPT
awk '/^-A/ { print "/sbin/iptables -t filter "$ALL}' /etc/sysconfig/iptables.new && \
/sbin/iptables-save > /etc/sysconfig/iptables.new
sleep 5m
/etc/rc.d/init.d/iptables restart
exit 0


smallgamer 10-15-2011 02:13 PM

I'm getting the message "line 32 failed" after applying those last two changes. Does that indicate some problem with this iptables text, or is it fine and I should just use that other method of activating the iptables file from your last post?

unSpawn 10-15-2011 02:29 PM

The only thing missing are "-i eth0" items in lines below the ESTABLISHED,RELATED rule. Try adding it similar to that line.

smallgamer 10-15-2011 02:38 PM

Still "iptables-restore: line 32 failed."

And this is the FIRST step? I'm grateful that you're helping me, but YIKES.

unSpawn 10-15-2011 02:47 PM

OK, this is taking too long. Save as appropriate and run it like this standalone shell script:
Code:

#!/bin/sh --
/sbin/iptables -P INPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -t filter -A INPUT -i lo -j ACCEPT
/sbin/iptables -t filter -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -t filter -A INPUT -i eth0 -m conntrack --ctstate INVALID -j LOG --log-prefix "IN_inv "
/sbin/iptables -t filter -A INPUT -i eth0 -m conntrack --ctstate INVALID -j REJECT
/sbin/iptables -t filter -A INPUT -i eth0 -m tcp -p tcp --syn -m connlimit --connlimit-above 30 --connlimit-mask 24 -j LOG --log-prefix "IN_lim "
/sbin/iptables -t filter -A INPUT -i eth0 -m tcp -p tcp --syn -m connlimit --connlimit-above 30 --connlimit-mask 24 -j REJECT
/sbin/iptables -t filter -A INPUT -i eth0 -m udp -p udp -m state --state NEW -m connlimit --connlimit-above 100 --connlimit-mask 24 -j LOG --log-prefix "IN_lim "
/sbin/iptables -t filter -A INPUT -i eth0 -m udp -p udp -m state --state NEW -m connlimit --connlimit-above 100 --connlimit-mask 24 -j REJECT
/sbin/iptables -t filter -A INPUT -i eth0 -m state --state NEW -m tcp -p tcp -m multiport --dports 22,80 -j LOG  --log-prefix "IN_tcpnew "
/sbin/iptables -t filter -A INPUT -i eth0 -m state --state NEW -m tcp -p tcp -m multiport --dports 22,80 -j ACCEPT
/sbin/iptables -t filter -A INPUT -i eth0 -m state --state NEW -m udp -p udp -m multiport --dports 36900:36999 -j LOG  --log-prefix "IN_udpnew "
/sbin/iptables -t filter -A INPUT -i eth0 -m state --state NEW -m udp -p udp -m multiport --dports 36900:36999 -j ACCEPT
/sbin/iptables -t filter -A INPUT -i eth0 -m limit --limit 1/minute --limit-burst 3 -j LOG --log-prefix "IN_rej "
/sbin/iptables -t filter -A INPUT -i eth0 -j REJECT --reject-with icmp-host-prohibited
/sbin/iptables -t filter -A OUTPUT -o lo -j ACCEPT
sleep 5m
service iptables restart

exit 0


smallgamer 10-15-2011 02:55 PM

It froze on the fifth line and I can no longer log into my server via ssh.

unSpawn 10-15-2011 03:30 PM

Not back up yet? No access to port 80 (meaning it's inaccessible completely)?

smallgamer 10-15-2011 03:34 PM

How do I access port 80? Through my ssh client, just change port 22 to 80?

I need to stress that you're dealing with a noob here.

EDIT: That's not working.

unSpawn 10-15-2011 03:59 PM

OK, that plainly sucks. Just to be sure: the iptables rule set is really simple and unless your VPS doesn't come with the most basic of modules ('grep -i iptables /etc/vz/vz.conf'), or used an ethernet device other than eth0, I can't see why it wouldn't have worked. Anyway, since it remains inaccessible the only alternative is to ask your provider to either log in and fix things for you if they can or gracefully shut down and reboot it. After that you'll have to find out if iptables is enabled by your provider and if so which modules are offered.



Quote:

Originally Posted by smallgamer (Post 4499370)
How do I access port 80? Through my ssh client, just change port 22 to 80?
EDIT: That's not working.

No, use a browser for port 80.


Quote:

Originally Posted by smallgamer (Post 4499370)
I need to stress that you're dealing with a noob here.

Thanks, I sometimes tend to forget that.

smallgamer 10-21-2011 04:58 AM

Okay, apf firewall is set up and configured. I did have help with this (I'm sorry for not following your advice via email, but I'm also trying to maintain my job and it was either pay someone to set that up for me or shut down my gaming server.) My current iptables contents are below.

Unfortunately, the attack I described previously is still happening multiple times per day.

I have some more information about what is going on when the attack happens. The targeted application actually continues to run... it even continues producing log files. But it is dead to the outside world. Apparently this attack causes the application's socket to terminate.

I read that this is an exploit for attacking some other games as well. An oversized udp packet is sent, and it causes the application's socket to terminate. That seems to be what is happening here. So I had a rule added to the firewall:

-A INPUT -p udp -m length --length 2001:65535 -j DROP

(2000 is the number the game developer recommended, saying anything over that could be dropped.)

This rule is not stopping the attack. But wouldn't an oversized packet mean one which is larger than 65535 anyway? However, I can't enter any number higher than that, or I get an error when I restart iptables. So, can this be reversed and changed to ACCEPT with a criteria of 0-2000, so that ANY packet over 2000 (no matter HOW large) is automatically not accepted? If so, what is the syntax for that, and if not, do I have any other options?

I also noticed when I first looked at this configuration that there is no LIMIT rule for the rate of udp packets. What should I put for that kind of rule, so that if more than a certain number of udp packets come per second from the same IP address, they are automatically ignored and the DOS attack fails while the IP address is added to the deny hosts list?

Code:

# Generated by iptables-save v1.3.5 on Wed Oct 19 23:25:17 2011
*mangle
:PREROUTING ACCEPT [33166894:1191645360]
:INPUT ACCEPT [33166894:1191645360]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [72825690:3800736373]
:POSTROUTING ACCEPT [72825169:3800705902]
-A PREROUTING -p tcp -m tcp --sport 21 -j TOS --set-tos 0x08
-A PREROUTING -p tcp -m tcp --sport 20 -j TOS --set-tos 0x08
-A PREROUTING -p tcp -m tcp --sport 80 -j TOS --set-tos 0x08
-A PREROUTING -p tcp -m tcp --sport 25 -j TOS --set-tos 0x10
-A PREROUTING -p tcp -m tcp --sport 110 -j TOS --set-tos 0x10
-A PREROUTING -p tcp -m tcp --sport 143 -j TOS --set-tos 0x10
-A PREROUTING -p tcp -m tcp --sport 512:65535 -j TOS --set-tos 0x00
-A POSTROUTING -p tcp -m tcp --dport 21 -j TOS --set-tos 0x08
-A POSTROUTING -p tcp -m tcp --dport 20 -j TOS --set-tos 0x08
-A POSTROUTING -p tcp -m tcp --dport 80 -j TOS --set-tos 0x08
-A POSTROUTING -p tcp -m tcp --dport 25 -j TOS --set-tos 0x10
-A POSTROUTING -p tcp -m tcp --dport 110 -j TOS --set-tos 0x10
-A POSTROUTING -p tcp -m tcp --dport 143 -j TOS --set-tos 0x10
-A POSTROUTING -p tcp -m tcp --dport 512:65535 -j TOS --set-tos 0x00
COMMIT
# Completed on Wed Oct 19 23:25:17 2011
# Generated by iptables-save v1.3.5 on Wed Oct 19 23:25:17 2011
*filter
:INPUT ACCEPT [134:6112]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [327:18880]
:FRAG_UDP - [0:0]
:IN_SANITY - [0:0]
:OUT_SANITY - [0:0]
:P2P - [0:0]
:PROHIBIT - [0:0]
:PZERO - [0:0]
:RESET - [0:0]
:TALLOW - [0:0]
:TDENY - [0:0]
:TGALLOW - [0:0]
:TGDENY - [0:0]
:TMP_DROP - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -s 0.0.0.0/255.0.0.0 -j DROP
-A INPUT -s 127.0.0.0/255.0.0.0 -j DROP
-A INPUT -s 169.254.0.0/255.255.0.0 -j DROP
-A INPUT -s 192.0.0.0/255.255.255.0 -j DROP
-A INPUT -s 192.0.2.0/255.255.255.0 -j DROP
-A INPUT -s 198.18.0.0/255.254.0.0 -j DROP
-A INPUT -s 198.51.100.0/255.255.255.0 -j DROP
-A INPUT -s 203.0.113.0/255.255.255.0 -j DROP
-A INPUT -s 224.0.0.0/240.0.0.0 -j DROP
-A INPUT -s 240.0.0.0/240.0.0.0 -j DROP
-A INPUT -j TMP_DROP
-A INPUT -j TALLOW
-A INPUT -j TDENY
-A INPUT -j TGALLOW
-A INPUT -j TGDENY
-A INPUT -p tcp -m tcp --dport 135:139 -j DROP
-A INPUT -p udp -m udp --dport 135:139 -j DROP
-A INPUT -p tcp -m tcp --dport 111 -j DROP
-A INPUT -p udp -m udp --dport 111 -j DROP
-A INPUT -p tcp -m tcp --dport 513 -j DROP
-A INPUT -p udp -m udp --dport 513 -j DROP
-A INPUT -p tcp -m tcp --dport 520 -j DROP
-A INPUT -p udp -m udp --dport 520 -j DROP
-A INPUT -p tcp -m tcp --dport 445 -j DROP
-A INPUT -p udp -m udp --dport 445 -j DROP
-A INPUT -p tcp -m tcp --dport 1433 -j DROP
-A INPUT -p udp -m udp --dport 1433 -j DROP
-A INPUT -p tcp -m tcp --dport 1434 -j DROP
-A INPUT -p udp -m udp --dport 1434 -j DROP
-A INPUT -p tcp -m tcp --dport 1234 -j DROP
-A INPUT -p udp -m udp --dport 1234 -j DROP
-A INPUT -p tcp -m tcp --dport 1524 -j DROP
-A INPUT -p udp -m udp --dport 1524 -j DROP
-A INPUT -p tcp -m tcp --dport 3127 -j DROP
-A INPUT -p udp -m udp --dport 3127 -j DROP
-A INPUT -j IN_SANITY
-A INPUT -j FRAG_UDP
-A INPUT -j PZERO
-A INPUT -j P2P
-A INPUT -p tcp -m tcp --dport 36943 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 36944 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 55000 -j ACCEPT
-A INPUT -p udp -m udp --dport 36943 -j ACCEPT
-A INPUT -p udp -m udp --dport 36944 -j ACCEPT
-A INPUT -p udp -m udp --dport 22 -j ACCEPT
-A INPUT -p udp -m udp --dport 21 -j ACCEPT
-A INPUT -p udp -m udp --dport 22 -j ACCEPT
-A INPUT -p udp -m udp --dport 25 -j ACCEPT
-A INPUT -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -p udp -m udp --dport 80 -j ACCEPT
-A INPUT -p udp -m udp --dport 443 -j ACCEPT
-A INPUT -p udp -m udp --dport 3306 -j ACCEPT
-A INPUT -p udp -m udp --dport 55000 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 3 -m limit --limit 30/sec -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 5 -m limit --limit 30/sec -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 11 -m limit --limit 30/sec -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 0 -m limit --limit 30/sec -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 30 -m limit --limit 30/sec -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -m limit --limit 30/sec -j ACCEPT
-A INPUT -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j DROP
-A INPUT -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p udp -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -s xxx.xxx.xxx.222 -p udp -m udp --sport 53 --dport 1023:65535 -j ACCEPT
-A INPUT -s xxx.xxx.xxx.222 -p tcp -m tcp --sport 53 --dport 1023:65535 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 53 --dport 1023:65535 -j DROP
-A INPUT -p udp -m udp --sport 53 --dport 1023:65535 -j DROP
-A INPUT -s xxx.xxx.xxx.220 -p udp -m udp --sport 53 --dport 1023:65535 -j ACCEPT
-A INPUT -s xxx.xxx.xxx.220 -p tcp -m tcp --sport 53 --dport 1023:65535 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 53 --dport 1023:65535 -j DROP
-A INPUT -p udp -m udp --sport 53 --dport 1023:65535 -j DROP
-A INPUT -p tcp -m tcp --sport 1023:65535 --dport 21 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m multiport --dports 21,20 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p udp -m multiport --dports 21,20 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --sport 22 --dport 513:65535 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --sport 1024:65535 --dport 22 --tcp-flags FIN,SYN,RST,ACK SYN -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p udp -m udp --dport 22 -m state --state ESTABLISHED -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 33434:33534 -j ACCEPT
-A INPUT -p tcp -j DROP
-A INPUT -p udp -j DROP
-A INPUT -j DROP
-A INPUT -p udp -m length --length 2001:65535 -j DROP
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
-A OUTPUT -d 0.0.0.0/255.0.0.0 -j DROP
-A OUTPUT -d 127.0.0.0/255.0.0.0 -j DROP
-A OUTPUT -d 169.254.0.0/255.255.0.0 -j DROP
-A OUTPUT -d 192.0.0.0/255.255.255.0 -j DROP
-A OUTPUT -d 192.0.2.0/255.255.255.0 -j DROP
-A OUTPUT -d 198.18.0.0/255.254.0.0 -j DROP
-A OUTPUT -d 198.51.100.0/255.255.255.0 -j DROP
-A OUTPUT -d 203.0.113.0/255.255.255.0 -j DROP
-A OUTPUT -d 224.0.0.0/240.0.0.0 -j DROP
-A OUTPUT -d 240.0.0.0/240.0.0.0 -j DROP
-A OUTPUT -j TMP_DROP
-A OUTPUT -j TALLOW
-A OUTPUT -j TDENY
-A OUTPUT -j TGALLOW
-A OUTPUT -j TGDENY
-A OUTPUT -p tcp -m tcp --dport 135:139 -j DROP
-A OUTPUT -p udp -m udp --dport 135:139 -j DROP
-A OUTPUT -p tcp -m tcp --dport 111 -j DROP
-A OUTPUT -p udp -m udp --dport 111 -j DROP
-A OUTPUT -p tcp -m tcp --dport 513 -j DROP
-A OUTPUT -p udp -m udp --dport 513 -j DROP
-A OUTPUT -p tcp -m tcp --dport 520 -j DROP
-A OUTPUT -p udp -m udp --dport 520 -j DROP
-A OUTPUT -p tcp -m tcp --dport 445 -j DROP
-A OUTPUT -p udp -m udp --dport 445 -j DROP
-A OUTPUT -p tcp -m tcp --dport 1433 -j DROP
-A OUTPUT -p udp -m udp --dport 1433 -j DROP
-A OUTPUT -p tcp -m tcp --dport 1434 -j DROP
-A OUTPUT -p udp -m udp --dport 1434 -j DROP
-A OUTPUT -p tcp -m tcp --dport 1234 -j DROP
-A OUTPUT -p udp -m udp --dport 1234 -j DROP
-A OUTPUT -p tcp -m tcp --dport 1524 -j DROP
-A OUTPUT -p udp -m udp --dport 1524 -j DROP
-A OUTPUT -p tcp -m tcp --dport 3127 -j DROP
-A OUTPUT -p udp -m udp --dport 3127 -j DROP
-A OUTPUT -j OUT_SANITY
-A OUTPUT -j FRAG_UDP
-A OUTPUT -j PZERO
-A OUTPUT -j P2P
-A OUTPUT -p tcp -m tcp --dport 1024:65535 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p udp -m udp --dport 1024:65535 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -d xxx.xxx.xxx.222 -p udp -m udp --sport 1023:65535 --dport 53 -j ACCEPT
-A OUTPUT -d xxx.xxx.xxx.222 -p tcp -m tcp --sport 1023:65535 --dport 53 -j ACCEPT
-A OUTPUT -d xxx.xxx.xxx.222 -p udp -m udp --sport 1023:65535 --dport 53 -j ACCEPT
-A OUTPUT -d xxx.xxx.xxx.222 -p tcp -m tcp --sport 1023:65535 --dport 53 -j ACCEPT
-A OUTPUT -d xxx.xxx.xxx.220 -p udp -m udp --sport 1023:65535 --dport 53 -j ACCEPT
-A OUTPUT -d xxx.xxx.xxx.220 -p tcp -m tcp --sport 1023:65535 --dport 53 -j ACCEPT
-A OUTPUT -d xxx.xxx.xxx.220 -p udp -m udp --sport 1023:65535 --dport 53 -j ACCEPT
-A OUTPUT -d xxx.xxx.xxx.220 -p tcp -m tcp --sport 1023:65535 --dport 53 -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 21 --dport 1023:65535 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp -m multiport --dports 21,20 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p udp -m multiport --dports 21,20 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p udp -m state --state NEW -m udp --dport 33434:33534 -j ACCEPT
-A OUTPUT -j ACCEPT
-A FRAG_UDP -p udp -f -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags SYN,RST SYN,RST -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags FIN,RST FIN,RST -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags FIN,ACK FIN -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags ACK,URG URG -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags PSH,ACK PSH -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,PSH,URG -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,ACK,URG -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,PSH,ACK,URG -j DROP
-A IN_SANITY -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN -j DROP
-A OUT_SANITY -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
-A OUT_SANITY -p tcp -m tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
-A OUT_SANITY -p tcp -m tcp --tcp-flags SYN,RST SYN,RST -j DROP
-A OUT_SANITY -p tcp -m tcp --tcp-flags FIN,RST FIN,RST -j DROP
-A OUT_SANITY -p tcp -m tcp --tcp-flags FIN,ACK FIN -j DROP
-A OUT_SANITY -p tcp -m tcp --tcp-flags PSH,ACK PSH -j DROP
-A OUT_SANITY -p tcp -m tcp --tcp-flags ACK,URG URG -j DROP
-A P2P -p tcp -m tcp --dport 1214 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 1214 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1024:65534 --dport 1214 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1214 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --dport 2323 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 2323 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1024:65534 --dport 2323 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 2323 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 1024:65534 --dport 4660:4678 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 4660:4678 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1024:65534 --dport 4660:4678 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 4660:4678 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --dport 6257 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 6257 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1024:65534 --dport 6257 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 6257 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --dport 6699 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 6699 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1024:65534 --dport 6699 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 6699 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --dport 6346 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 6346 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1024:65534 --dport 6346 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 6346 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --dport 6347 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 6347 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1024:65534 --dport 6347 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 6347 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 1024:65534 --dport 6881:6889 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 6881:6889 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1024:65534 --dport 6881:6889 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 6881:6889 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --dport 6346 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 6346 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1024:65534 --dport 6346 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 6346 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --dport 7778 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p tcp -m tcp --sport 7778 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 1024:65534 --dport 7778 -j REJECT --reject-with icmp-port-unreachable
-A P2P -p udp -m udp --sport 7778 --dport 1024:65534 -j REJECT --reject-with icmp-port-unreachable
-A PROHIBIT -j REJECT --reject-with icmp-host-prohibited
-A PZERO -p tcp -m tcp --dport 0 -j DROP
-A PZERO -p udp -m udp --dport 0 -j DROP
-A PZERO -p tcp -m tcp --sport 0 -j DROP
-A PZERO -p udp -m udp --sport 0 -j DROP
-A RESET -p tcp -j REJECT --reject-with tcp-reset
-A TALLOW -s 68.61.150.115 -j ACCEPT
-A TALLOW -d 68.61.150.115 -j ACCEPT
COMMIT
# Completed on Wed Oct 19 23:25:17 2011
# Generated by iptables-save v1.3.5 on Wed Oct 19 23:25:17 2011
*nat
:PREROUTING ACCEPT [168650:6091718]
:POSTROUTING ACCEPT [778:41469]
:OUTPUT ACCEPT [778:41469]
COMMIT
# Completed on Wed Oct 19 23:25:17 2011


OlRoy 10-21-2011 07:02 AM

I'm not an iptables guy by any means. However, shouldn't the "-A INPUT -p udp -m length --length 2001:65535 -j DROP" go before the below rules that permit traffic to the port your game service listens on?
Code:

-A INPUT -p udp -m udp --dport 36943 -j ACCEPT
-A INPUT -p udp -m udp --dport 36944 -j ACCEPT


smallgamer 10-21-2011 07:22 AM

Thanks, I changed that. Hopefully it helps.

It's really hard to find qualified people to work on this stuff. The same person who did that also had logging set to 0 so that it was not logging dropped packets, even though I explicitly said I needed that. At least I'm starting to understand things in the process, but still, that's pretty annoying.

OlRoy 10-21-2011 07:32 AM

Quote:

Originally Posted by smallgamer (Post 4504270)
Thanks, I changed that. Hopefully it helps.

It's really hard to find qualified people to work on this stuff. The same person who did that also had logging set to 0 so that it was not logging dropped packets, even though I explicitly said I needed that. At least I'm starting to understand things in the process, but still, that's pretty annoying.

No problem, I hope it works out for you. But as I said, I'm by no means an iptables guy. My post was a question. I'm a bit rusty since I've been focusing on other areas of security so you may want to wait for verification or double check yourself.

Noway2 10-21-2011 08:24 AM

In general, there are two major philosophies with IP tables that are helpful to keep in mind when working with the rules. One, is that the rules are process in order from top to bottom and if a match is found, it stops comparing. As Ol'Roy pointed out, placing a drop rule based upon packet size beneath one that accepts traffic to that port won't work, because the length check won't even get analyzed. The second philosophy is to set your firewall so that traffic is dropped by default and only accepted when it meets certain parameters. The syntax for the rules is almost identical to your drop rules, but instead of -j DROP, use -j ACCEPT. This practice is commonly referred to as white-listing versus black-listing and it gives you a real leg up on the would be attacker, who can adapt to get around your reject lists. There are two ways to achieve this, one is to set the policy to DROP and then add the rules that you want to accept, the other is to set the policy to ACCEPT, add the rules you want to ACCEPT and then at the end put a catch all DROP rule. The primary difference is in how the filter will behave when the rules have been flushed, in which case it will act according to the policy. If you don't have physical access to the machine, setting the policy to accept is safer in that if the rules get cleared, you can still get at the machine via SSH.

So as an example of how this would impact your rules, instead of having 20+ rules to drop specified ports, you could have three or four rules to only accept the ports, or port ranges you wish to accept. You can also get creative to enhance your security on your SSH port or other management interface. Say for example, that you have either a static IP or you can identify the network+mask that identifies the range that YOU will be using, you can restrict access to only these source IP addresses, effectively cutting off traffic from everyone else. I also noticed that you have duplicate rules for TCP and UDP on the same port, you should be able to simplify your rules by just specifying the port without the protocol. For example, your three rules:
Code:

-A INPUT -p tcp -j DROP
-A INPUT -p udp -j DROP
-A INPUT -j DROP

The 3rd rule is really superfluous because traffic will be dropped by one of the two rules, but you could also eliminate the first two and just use the 3rd.

There are some really great tutorials on IPTables, that might help you with these rules. It looks like you have or are getting a grasp of the basic syntax and are starting to get into the art of rule writing. Once you get past the initial learning curve, writing iptables rules is actually enjoyable.

To address your other question about rate limiting: a quantitative suggestion is hard to provide. You might want to ask the developer for some guidance. Otherwise you will need to do some trial and error and expect to fine tune it for a while as a balance can be difficult to achieve.

You might find this link interesting: http://blog.bodhizazen.net/linux/pre...with-iptables/ It is an IPTables tutorial specifically geared towards preventing attacks and it discusses both length and limit functions. While somewhat cursory, it might at least be a good common reference point for refining the discussion.

smallgamer 10-21-2011 12:49 PM

Thanks for the help, Noway2. I'm looking through the information you linked to and trying to wrap my head around it.

I think unSpawn may have written me off due to the fact that I paid someone to do the initial configuration on my server.

UnSpawn, if that is the case, please understand where I'm coming from.

I realize that it's not apparent here, but I do have a love for knowledge, and I spend a lot of time each week learning how to do new things. I make my living on the internet, and I'm no stranger to spending days figuring out why X, Y, or Z isn't working.

Paying for someone to do the initial setup on my firewall, however, was logistically unavoidable. I did not have days to spend going through the entire process as a newb, and I also did not want to give up and shut down my gaming server. That only left me with one option. Please try not to think poorly of me. I'm still here trying to finish the job.

Noway2 10-21-2011 01:05 PM

I don't think anyone, unSpawn included, will look down upon you for paying to have someone perform a service for you. For that matter, we all have day jobs too. Sometimes expediency is the biggest priority and hired hands can bring that to the table. I do think that most here appreciate making an effort to learn, which you are doing, and I don't think that we could ask any more of you. Sometimes, especially for those who have been using Linux for a long time, we lose sight of the new user perspective. This causes us to forget to include things that have become obvious to us. Please have patience with us in this regard.

Once you have had a chance to read up on iptables and look over some of the tutorial pages, please ask questions and don't be afraid to ask.

unSpawn 10-21-2011 05:20 PM

Quote:

Originally Posted by smallgamer (Post 4504554)
Please try not to think poorly of me.

Be certain I do not.

And I do realize that you're trying to finish the job. I've been following the thread and thinking about things. What I'm missing here essentially is any "evidence" of an attack. Sure there's HL/CS exploits (mostly old) and even if there is no indication of everything having been fixed all we've got so far is hearsay type of information. Nothing tangible. Even though I'm hesitant about it due to expected size I think we should really start at the bottom, logging traffic and, basically what Noway2 hinted at in his first reply, combing over packet captures. If we can get a fix on things we could create one or more Snort rules and have Guardian or fail2ban tarpit the offenders. (While I don't like to get ahead of things, we shouldn't rule out the possibility that it may well be that raw data won't yield the evidence we seek, or something that can be dealt with effectively on the network layer, and what vulnerability exploits address needs to be dealt with at the Half-Life protocol level or inside cs2d_dedicated.)

smallgamer 10-21-2011 05:55 PM

It is an attack, for sure, this is a known thing among the community of server owners and the game developer has confirmed it. But I guess what you're referring to is evidence of what exactly is happening.

I'm firmly convinced that the socket is terminating, but I don't have any idea exactly what is causing it. And I could be wrong about the socket, of course, I would just be really surprised.

Is there a command that will let me check whether the socket has been terminated, and reopen it if necessary?

Regarding checking out the packets, I had Wireshark installed, but unfortunately the logs got massive within about 5 minutes (just due to regular game traffic) and the server started freezing up. After that there was trouble for about 30 minutes, and the datacenter supposedly even had to take the server off the rack and switch out the fans. WHOOPS!

I definitely want to get these packets logged during one of the attacks. How can we do that without a repeat of what happened with Wireshark?

unSpawn 10-21-2011 06:22 PM

Yeah, that's exactly why I said I was hesitant about this approach. The problem is we don't know what to look for. To tune down to "interesting" traffic as fast as possible we could initially define traffic as UDP and "-m state --state NEW". And I guess there's no other way than to run tcpdump with a BPF filter. We might need to make the firewall log too (like said earlier your firewall needs simplifying) and possibly a scoped strace ("-e") for correlation purposes too. If you happen to have another server we could use that as log host and send pcaps and logs there. If you don't then we need to think about how we're going to reduce it another way.

smallgamer 10-21-2011 06:51 PM

I do have another server, which I'm not currently using for anything. :)

If you can explain how to do the things you suggested in more detail, I will definitely try.

smallgamer 10-21-2011 08:45 PM

Hey, is it possible to move this thread to a private forum? It wouldn't be helpful if the attacker found this conversation. :eek:

OlRoy 10-21-2011 08:50 PM

Welp, the BPF below was working fine on one pcap I tested it with, and now I tested it on another and it doesn't seem to be as accurate as I thought. If anyone sees a problem with it please let me know.

So I take it the firewall rule for large UDP datagrams didn't help? If so it might not be the large UDP packets.

Wireshark is really bloated, so I'm not surprised it crashed the server. It was probably eating up your memory. If you want to test your theory it's large UDP traffic, you should be able to record just fragmented UDP traffic with the following tcpdump command... IP packets are 1500 bytes or less so to be over 2000 they are probably going to be fragmented.

Code:

sudo tcpdump -i eth0 -nns0 -w dos.pcap 'udp && ((ip[6] & 0x20 != 0) || (ip[6:2] & 0x1fff != 0))'
ip[6] & 0x20 != 0 will match if the More Fragment bit is not 0.
ip[6:2] & 0x1fff != 0 will match if the Fragment Offset field is not 0.

I don't know how much space you have, or how much traffic you'll record. To prevent from filling up your partition you can use the -C flag to specify the max file size, AND the -W flag to set a limit to how many files you want to keep.

-C 25M will keep creating 25MB files, where -W 20 will make it so after 20 files have been created, it will start to overwrite the first. By adding those two options you'll create 20 25MB files. You can change adjust the numbers to however you want.

Code:

sudo tcpdump -i eth0 -nns0 -C 25 -W 20 -w dos.pcap 'udp && ((ip[6] & 0x20 != 0) || (ip[6:2] & 0x1fff != 0))'
You can also add "dst host <your ip> &&" to the beginning of the BPF to make sure you only capture traffic being sent to your IP.

salasi 10-22-2011 06:53 AM

Quote:

Originally Posted by smallgamer (Post 4504788)
Regarding checking out the packets, I had Wireshark installed, but unfortunately the logs got massive within about 5 minutes (just due to regular game traffic) and the server started freezing up. After that there was trouble for about 30 minutes, and the datacenter supposedly even had to take the server off the rack and switch out the fans. WHOOPS!

I definitely want to get these packets logged during one of the attacks. How can we do that without a repeat of what happened with Wireshark?

OK, sorry about that, you clearly had a whole load more traffic than I was envisaging. The trouble is Wireshark, by default, tends to grab everything and then allows you to look at the data you have grabbed in different ways. The data display is easier for a newbie to get their heads around than some other apps, but that isn't a luxury that we have here.

On the iptables front, I would point you at a few links, and one warning:
  • First, the warning: this is an immediate problem, and the last thing that I want to do is to send you off for two weeks reading iptables documentation, with the result that you don't do anything about the immediate threat for that period of time. I have more in mind that you should have these things available, so that you have a quick reference, in case things do go wrong.
  • Extensive documentation on iptables is available here (don't bother with the 'online' version, just grab, eg, a .pdf so that you have it available and can look at it at your leisure); when I say extensive, I mean it. Pretty complete, but using it to look up a syntax is more useful than starting to read at the beginning and finishing at the end, at this point. (Actually, the iptables man page is better than some, too, so that is also an option.)
  • For a worked, explained, example of a firewall, I find that Linuxhomenetworking is the best (YMMV, etc...mind you, if I remember correctly, his examples are all for Red Hat/Fedora and so should be relevant for other distros of that family (eg, Centos)), but there is also Yolinux, which is less extensive, but also easier to get through.


(Passing note: the Linuxhomenetworking site is heavily based on the book by Harrison "The Linux Quick Fix Notebook" pub Prentice-Hall; that book, and some others in the series (the Bruce Perens open source series) have been made available by P-H as zero cost downloadable .pdfs; you could search for that, for example, but if you are interested, and you don't find anything, I can research that further for you. It may be that there is now a revised edition available as dead-tree-ware, I'm not sure, but i do get the impression that it is the older books in the series that have had this treatment.)

smallgamer 10-22-2011 11:06 PM

Thanks for your help guys!

What I'd really like to do at the moment is log all *incoming* udp traffic but with the logs being saved on a separate vps in manageable chunks, say 25mb each. Instructions on how to do this would be very helpful. Edit: I also need to log the IP addresses which the udp packets are coming from. Does Wireshark or tcpdump do that?

smallgamer 10-23-2011 06:28 AM

Right now I've got everything logging via tcpdump, and it seems to be working fine. After the next attack I'll let you guys know.

unSpawn 10-23-2011 06:46 AM

Quote:

Originally Posted by smallgamer (Post 4504867)
Hey, is it possible to move this thread to a private forum? It wouldn't be helpful if the attacker found this conversation. :eek:

Unfortunately, no.

Doing some research I see Counter Strike, like similar Quake-engine-like games, uses Valves Source engine Half-Life protocol [0|1] except it's not HLv1 but the HLv2 protocol so any dissectors ain't gong to work [2|3]. There's been HL / derivative vulns since 2000 (IIGC) 4|5|6] and exploits too (no links obviously). If we assert server-side, version-specific ones have been addressed by the developers then running the most recent version of CS2D (ensure you do) alleviate those. However to compound things there seems to be 0) different versions of Counter Strike out (dunno, haven't kept up, I dropped out after playing QWCL and UT1 basically), there seem to be problems with 1) enabling certain server-side cvars, game 2) mods, issues with 3) fake players, player names with 4) strange characters, 5) authorized players vs unauthorized users, enabling 6) remote admin console (RCON), (apparently large UDP packets?,) and 7) small UDP packets that seem to "freeze" the server application. And then I'm not talking about Steam itself [7].

- Items 1+6 mean you shouldn't allow any player to enter RCON commands. RCON should be disabled and if you need it access to the port should be confined to your management IP range and or trusted (really) admin-capable players. Maybe bind the port to localhost and only allow authenticated users to access it over SSH? And FWIW there seem to be mods out to lock the rcon users password.
- I don't know if item 3 is fixed but IIGC item 4 is.
- Item 5 means that if you have authorized players doing Bad Things you're in a whole different world of pain. (If you compare this to say SIP then there's a lot the firewall and SIP applications can do to protect the server from unauthorized users and restrict access for authorized ones, but once a user is in there isn't much you can defend yourself with from a user doing Bad Things except watch counters).
- As for item 7 this seems DoS-related. While there are fixes out ("DoS Attack Fixer") that claim to mitigate some of those (like "AntiCSDoS") contain only a (Windows) binary which you can't run on Linux and which I wouldn't run anyway as there's no clue as to what it contains or does. Some admins swear dropping short packets works
Code:

-A INPUT -p udp -m udp --dport $CS2D_SERVER_PORT} -m length --length $LENGTH} -j DROP
(where CS2D_SERVER_PORT obviously is the port cs2d_dedicated runs on and LENGTH seems to be 28 or 46) and some say it doesn't. The problem is no mailing list message, forum thread or web page shows any network data so in essence there's nothing to go on analysis-wise.


Down to the practical side of things. Given there's no network data whatsoever around for analysis and given your previous bad experiences with running tcpdump (though you don't show what command you actually did run) and OlRoy's latest post I think it would be wise to restrict pcap to only the necessary ports. IIGC the following ports may be in use:
UDP/1200 #friends service (whatever that may be)
UDP/27000-27015 # HL1
TCP/27020-27050 # HL2
UDP/27015 # HLDS, SRCDS and HLTV
UDP/27020 # HLDS, SRCDS and HLTV
TCP/27015 # RCON
UDP/28000 # unknown
UDP/29000 # unknown
Unless you check which server-side ports are in use on your server (which you should) I suggest using "port 1200 and portrange 27000-27050 and port 28000 and port 29000" as BPF filter.


Quote:

Originally Posted by smallgamer (Post 4504818)
I do have another server, which I'm not currently using for anything.

Excellent. As for actually running tcpdump logging to a remote server there's more than a few ways. Even though this isn't critical data I suggest not running the capture over Netcat but use encryption available. Let's assert for these examples the remote log server has IP address 10.1.1.2 and ports TCP/22 (SSH) and TCP/20000 are not blocked in the firewall.
* When I issue long-running commands on a server I usually do that inside a screen ('man screen') session as this ensures I can reconnect to the session if my SSH connection breaks. Obviously I don't log in as root over SSH (and neither should you) but a unprivileged user after which I use sudo or su to root when additional auditing is enabled.


I. Using OpenSSH
On the CS2D server become root and issue:
Code:

tcpdump -i eth0 -n -nn -v -f -s 0 -w - 'udp and port 1200 and portrange 27000-27050 and port 28000 and port 29000' \
| ssh remote_user@10.1.1.2 '(cat >/path/to/udp.pcap)'

* When using SSH this way you should use ssh-agent to load keys or set up an IP-restricted passwordless account.
** Ensure "/path/to/" is an existing path with ample space available, "udp.pcap" a non-existing file and "remote_user" may write the file there.
*** In this command tcpdump can not segment captures. Maybe adding "-W 1 -C 100" may limit it to sending 100MB once across the wire after which you restart the job. Alternatively you could log to local file as Olroy showed but limit the amount of files saved and send files across the wire separately once tcpdump starts writing a new one (inotify).


II. Using Socat
Code:

# On the log server become root and issue:
umask 0027
install -m 0700 -d /tmp/root
openssl genrsa -out /tmp/root/socat.key 1024
openssl req -new -key /tmp/root/socat.key -x509 -days 3653 -out /tmp/root/socat.crt
cat /tmp/root/socat.key /tmp/root/socat.crt >/tmp/root/socat.pem
chmod 0600 /tmp/root/socat.*
ssh user@server 'install -m 0700 -d /tmp/root'
scp /tmp/root/socat.* user@server:/tmp/root/
socat openssl-listen:20000,pf=ip4,reuseaddr,fork,cert=/tmp/root/socat.pem,cafile=/tmp/root/socat.crt OPEN:/tmp/root/udp.pcap,creat,append

# On the CS2D server become root and issue:
chmod 0700 /tmp/root && chown -R root.root /tmp/root
tcpdump -i eth0 -n -nn -v -f -s 0 -w - 'udp and port 1200 and portrange 27000-27050 and port 28000 and port 29000' \
| socat stdio openssl-connect:10.1.1.2:20000,pf=ip4,reuseaddr,fork,cert=/tmp/socat.pem,cafile=/tmp/socat.crt,verify=0

* Same comments as above apply here.
** For some reason on the server socat starts to spit out nfo to stdout. Dunno why. Maybe "${socat_cmd} >/dev/null".


III. Using fuse-sshfs
This requires FUSE to be installed and the fuse-sshfs package. On the CS2D server become root and issue:
Code:

sshfs user@10.1.1.2:/path /local/mountpoint -o compression=no -o reconnect
tcpdump -i eth0 -n -nn -v -f -s 0 -W 10 -C 100 -U -w /mnt/temp/udp.pcap 'udp and port 1200 and portrange 27000-27050 and port 28000 and port 29000'

* Same comments as above apply here except here tcpdump should be able to split captures.

HTH

OlRoy 10-23-2011 07:29 AM

@UnSpawn, I think you meant -W 10 -C 100 to create 10 100MB... -C is the file size, -W is the number of files to create. I found HLShield is supposed to help prevent attacks on Linux game servers, but as you mentioned I don't know what it contains. It's also an experimental version.

@smallgamer, you said the actual game server logs didn't show anything with this current attack, but do you know if there is a debug mode you can use for to get more verbose logging?

unSpawn 10-23-2011 08:36 AM

Quote:

Originally Posted by OlRoy (Post 4505780)
@UnSpawn, I think you meant -W 10 -C 100 to create 10 100MB... -C is the file size, -W is the number of files to create.

Thanks, changed it.

smallgamer 10-23-2011 08:42 AM

Thanks for the additional info. Although I think a lot of it is helpful either way, CS2D is not a version of Counter-Strike of Half-Life per se. It's a top-down 2D remake of Counter-Strike developed by Unreal Software. How much it shares with Counter-Strike in terms of exploits, I'm not exactly sure. We do have rcon though, so there appear to be some similarities.

unSpawn 10-23-2011 10:43 AM

Quote:

Originally Posted by smallgamer (Post 4504788)
I'm firmly convinced that the socket is terminating (..) Is there a command that will let me check whether the socket has been terminated, and reopen it if necessary?

That depends if it's only the connection to the Master List server (as it seems to be disappearing from the list), user-initiated connections or server replies. If its the Master List server then an iptables -j LOG rule for the remote servers address should show it doesn't download stats and update its own status anymore. Otherwise running stace on the server might show some oddness but you probably have to tweak the strace set, something like '-etrace=\!gettimeofday,sleep,ioctl', to cut out crud. BTW your latest reply is a bit short and doesn't address what Olroy asked earlier on about debug mode and if you really want to say "Thanks for the additional info" then you best do that by finding out and posting back if any of the items mentioned above are an issue with CS2D or not. While you're at it also report back what ports your CS2D uses and which tcpdump command you actually run: be complete and be verbose.

smallgamer 10-23-2011 04:47 PM

I'm sorry for not replying to it all. I'm trying to wrap my head around what for me is a boatload of new information, while maintaining focus on stopping this attack.

I don't think there is a debug mode, as the developer mentioned trying to put out a debug release soon to figure this out. I really don't know whether any of the items you mentioned are an issue with this game or not. I can certainly ask the developer.

As for this attack, the tcpdump worked and I've got a log file now of the latest attack. It is clearly visible when the attacker starts flooding the server with packets, and his IP address is from the same ISP as an attacker I had earlier this year when he was using a different kind of attack. I don't think I can post the pcap file here due to the fact that it contains a lot of players' IP addresses and I don't want that on a public forum. However I will upload it and PM it to you.

EDIT: Pcap file has been sent via the "send an email message" button, unSpawn.

unSpawn 10-23-2011 06:11 PM

Looking forward to seeing the pcap!

smallgamer 10-24-2011 04:49 AM

Thanks, I have sent it to the email you asked me to.

So based on the PCAP this guy is just flooding the server with thousands of packets per second. I'm trying to limit the rate of packets one IP address can send, but it's not as straightforward as I had hoped.

I just want to make it so that the same IP address can't send me more than 100 packets per second. I found this:

http://www.debian-administration.org/articles/187

But I've learned that the "hitcount" can not be set higher than 20 (which is much too low) without increasing the default value of ip_pkt_list_tot, which is located in /etc/modprobe.conf. And, OF COURSE, this file does not exist and can not be modified on an OpenVZ vps, which is what I have.

Wtf? Then how is limiting the rate of packets from a particular IP address done on OpenVZ servers? We're just a sitting duck for DOS attacks?

smallgamer 10-24-2011 05:07 AM

Will --seconds take a decimal? If I can set it to 20 hits within .2 seconds, that would be the equivalent of 100 hits within 1 second, which is what I'm aiming for.

unSpawn 10-24-2011 07:24 PM

Quote:

Originally Posted by smallgamer (Post 4506075)
As for this attack, the tcpdump worked and I've got a log file now of the latest attack.

You didn't post the command you ran. And the capture encompasses a very short time frame. Less than half an hour is not exactly a rich data set on a well-used game server.


Quote:

Originally Posted by smallgamer (Post 4506075)
EDIT: Pcap file has been sent

Next time please contact me first to make drop-off arrangements. I don't care much for file sharing sites.


On with the pcap:
Code:

]$ capinfos ServerDoS.pcap
File type: Wireshark/tcpdump/... - libpcap
File encapsulation: Linux cooked-mode capture
Number of packets: 79662
File size: 5170327 bytes
Data size: 3895711 bytes
Capture duration: 1404.329493 seconds
Start time:
End time:
Data rate: 2774.07 bytes/s
Data rate: 22192.58 bits/s
Average packet size: 48.90 bytes

]$ tcpstat -alr ServerDoS.pcap|head -3
Bytes/sec        =      2.7 KB
Bytes/minute        =    161.9 KB
Bytes/hour        =      9.5 MB

tcpstat -l -o "Since:%R\tPkt_tot=%n\tPkt_sec=%p\tPkt_avgsz=%a\tbitsec=%b\n" -r ServerDoS.pcap -1
Since:702      Pkt_tot=79662  Pkt_sec=56.73  Pkt_avgsz=48.90 bitsec=22192.58

]$ tcpstat -l -o "Since:%R\tPkt_tot=%n\tPkt_sec=%p\tPkt_avgsz=%a\tbitsec=%b\n" -r ServerDoS.pcap 60
Since:30        Pkt_tot=55237  Pkt_sec=920.62  Pkt_avgsz=47.48 bitsec=349700.27
Since:90        Pkt_tot=8073    Pkt_sec=134.55  Pkt_avgsz=51.66 bitsec=55603.07
Since:150      Pkt_tot=1458    Pkt_sec=24.30  Pkt_avgsz=52.19 bitsec=10144.80
Since:210      Pkt_tot=996    Pkt_sec=16.60  Pkt_avgsz=52.31 bitsec=6946.40
Since:270      Pkt_tot=866    Pkt_sec=14.43  Pkt_avgsz=52.34 bitsec=6044.00
Since:330      Pkt_tot=632    Pkt_sec=10.53  Pkt_avgsz=52.37 bitsec=4413.20
Since:390      Pkt_tot=662    Pkt_sec=11.03  Pkt_avgsz=52.39 bitsec=4624.40
Since:450      Pkt_tot=596    Pkt_sec=9.93    Pkt_avgsz=52.43 bitsec=4166.40
Since:510      Pkt_tot=740    Pkt_sec=12.33  Pkt_avgsz=52.37 bitsec=5167.33
Since:570      Pkt_tot=826    Pkt_sec=13.77  Pkt_avgsz=52.37 bitsec=5768.13
Since:630      Pkt_tot=912    Pkt_sec=15.20  Pkt_avgsz=52.33 bitsec=6363.73
Since:690      Pkt_tot=818    Pkt_sec=13.63  Pkt_avgsz=52.35 bitsec=5709.47
Since:750      Pkt_tot=815    Pkt_sec=13.58  Pkt_avgsz=52.33 bitsec=5686.13
Since:810      Pkt_tot=816    Pkt_sec=13.60  Pkt_avgsz=52.33 bitsec=5693.07
Since:870      Pkt_tot=769    Pkt_sec=12.82  Pkt_avgsz=52.34 bitsec=5366.93
Since:930      Pkt_tot=748    Pkt_sec=12.47  Pkt_avgsz=52.32 bitsec=5218.27
Since:990      Pkt_tot=632    Pkt_sec=10.53  Pkt_avgsz=52.44 bitsec=4418.93
Since:1050      Pkt_tot=631    Pkt_sec=10.52  Pkt_avgsz=52.41 bitsec=4409.33
Since:1110      Pkt_tot=856    Pkt_sec=14.27  Pkt_avgsz=52.32 bitsec=5971.87
Since:1170      Pkt_tot=717    Pkt_sec=11.95  Pkt_avgsz=52.39 bitsec=5008.13
Since:1230      Pkt_tot=657    Pkt_sec=10.95  Pkt_avgsz=52.37 bitsec=4587.73
Since:1290      Pkt_tot=593    Pkt_sec=9.88    Pkt_avgsz=52.40 bitsec=4143.47
Since:1350      Pkt_tot=452    Pkt_sec=7.53    Pkt_avgsz=52.15 bitsec=3142.80
Since:1410      Pkt_tot=160    Pkt_sec=2.67    Pkt_avgsz=52.98 bitsec=1130.27

]$ tcptrace -nru ServerDoS.pcap|sort -nrk 6|head -4|some sed|some awk
client.15:56765 server:36944 17744>
client.15:56765 server:36943 13000>
client.113:1053 server:36943 4155>
client.138:3033 server:36943 2730>

]$ tcpdump|count packets|grep -c|sort
2714  client.101
2789  client.138
4163  client.113
30890 client.15


Quote:

Originally Posted by smallgamer (Post 4506075)
It is clearly visible when the attacker starts flooding the server with packets

In the stats above "client.15" (last octet) has a significant larger packet count compared to the two following players. Generating statistics for the first 3 players (and unless you managed to start tcpdump at the end of an attack the first line definitely is a capture error) with
Code:

tcpstat -l -o "Pkt_tot=%n Pkt_ps=%p Pkt_avg_sz=%a bps=%b\n" -r ServerDoS.pcap 60 -f filtername
we get :

Code:

# client.15:
Pkt_tot=30748  Pkt_ps=512.47  Pkt_avg_sz=44.00  bps=180392.53
Pkt_tot=32    Pkt_ps=0.53    Pkt_avg_sz=52.38  bps=223.47
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=18    Pkt_ps=0.30    Pkt_avg_sz=52.22  bps=125.33
Pkt_tot=29    Pkt_ps=0.48    Pkt_avg_sz=52.17  bps=201.73
Pkt_tot=16    Pkt_ps=0.27    Pkt_avg_sz=52.25  bps=111.47
Pkt_tot=14    Pkt_ps=0.23    Pkt_avg_sz=52.71  bps=98.40
Pkt_tot=3      Pkt_ps=0.05    Pkt_avg_sz=51.67  bps=20.67
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=18    Pkt_ps=0.30    Pkt_avg_sz=52.22  bps=125.33
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0      Pkt_ps=0.00    Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=12    Pkt_ps=0.20    Pkt_avg_sz=52.67  bps=84.27

# client.113:
Pkt_tot=2698  Pkt_ps=44.97  Pkt_avg_sz=51.50  bps=18525.87
Pkt_tot=1465  Pkt_ps=24.42  Pkt_avg_sz=51.68  bps=10095.20

# client.138:
Pkt_tot=2504  Pkt_ps=41.73  Pkt_avg_sz=52.36  bps=17482.00
Pkt_tot=251  Pkt_ps=4.18  Pkt_avg_sz=52.92  bps=1771.20
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=15    Pkt_ps=0.25  Pkt_avg_sz=52.07  bps=104.13
Pkt_tot=9    Pkt_ps=0.15  Pkt_avg_sz=52.33  bps=62.80
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=0    Pkt_ps=0.00  Pkt_avg_sz=0.00  bps=0.00
Pkt_tot=10    Pkt_ps=0.17  Pkt_avg_sz=52.40  bps=69.87

Quote:

Originally Posted by smallgamer (Post 4506373)
So based on the PCAP this guy is just flooding the server with thousands of packets per second.

So discarding the first line it doesn't seem like client.15 exceeds any thresholds. Looking at data using Snort doesn't trigger anything. Wireshark doesn't show any interesting payload, except using a filter of
Code:

udp.length == 8
or in tcpdump
Code:

'udp && len<=46'
does show a sh*tload of payload-less packets. I wouldn't call it flooding, more like a set of bursts, as other players manage to get packets in as well. Now I haven't got any in-game experience wrt lag and players response times don't seem optimal anyway (we're talking the Unreliable Data Protocol) so I can't see how this would influence the game. And again, twenty minutes ain't exactly the amount of data to draw any conclusion from.


Quote:

Originally Posted by smallgamer (Post 4506373)
But I've learned that the "hitcount" can not be set higher than 20 (which is much too low) without increasing the default value of ip_pkt_list_tot, which is located in /etc/modprobe.conf. And, OF COURSE, this file does not exist and can not be modified on an OpenVZ vps, which is what I have. Wtf? Then how is limiting the rate of packets from a particular IP address done on OpenVZ servers?

modprobe.conf sets module loading parameters. If you can't load modules yourself then you can't change ip_pkt_list_tot yourself. Ask your provider. And please don't b*tch about OpenVZ here: nobody here forced you to rent one.


Quote:

Originally Posted by smallgamer (Post 4506373)
I'm trying to limit the rate of packets one IP address can send

Should you still want to block these packets, and given your past experiences with iptables modules, I suggest an alternative and that's using fail2ban plus Snort. You'll have to do the legwork yourself (install fail2ban and Snort, add your UDP ports to /etc/services, configure ports in /etc/fail2ban/jail.conf and an appropriate action in /etc/fail2ban/action.d/ for a rule searching for "CS_pkt_sz_lt_1", test the rule, set server IP address in snort_cs.conf) but as promised here's a Snort rule. You don't need any snort rule sets except this config and run snort with the (suboptimal: "-A fast") "-c /path/to/snort_cs.conf -A fast -q -K none -l /var/log" args:
Code:

var HOME_NET INSERTIPADDRESSHERE/32
var EXTERNAL_NET !$HOME_NET
preprocessor frag3_global: max_frags 65536
preprocessor frag3_engine: policy first detect_anomalies
preprocessor stream5_global: max_tcp 8192, track_tcp yes, track_udp no
preprocessor stream5_tcp: policy first, use_static_footprint_sizes
preprocessor sfportscan: proto  { all } memcap { 10000000 } sense_level { low }
portvar CS_PORTS [1200,27000:27050,28000,29000,36900:37000]
alert udp $EXTERNAL_NET any -> $HOME_NET $CS_PORTS (msg:"CS_pkt_sz_lt_1"; dsize: <1; reference:url,www.linuxquestions.org/questions/linux-security-4/game-server-under-attack-908100/; sid: 999999999; rev:1;)

[EDIT]
I. Alternatively you can also use a third party app like Guardian instead of fail2ban.
II. If you choose to block using Netfilter you could use a rule something like
Code:

-A INPUT -p udp -m length --length 0:8 -j DROP
though you've got to find out if --length needs the IP packet size (28) or the UDP size (8).
[/EDIT]

That's it for now.

smallgamer 10-25-2011 04:07 AM

Quote:

You didn't post the command you ran. And the capture encompasses a very short time frame. Less than half an hour is not exactly a rich data set on a well-used game server.
It appeared to be long enough to see the attack and plenty of standard game packets surrounding it. Perhaps you would like to tell me the minimum time you need, information I was not given before.

Quote:

Next time please contact me first to make drop-off arrangements. I don't care much for file sharing sites.
I already complied with your request and sent it to your email, so I'm not sure what your point is here.

Quote:

And please don't b*tch about OpenVZ here: nobody here forced you to rent one.
I apologize profusely - I didn't realize my logical questions regarding OpenVZ's apparent dead end in this area would be so offensive to you.

I didn't come here to be berated, and while I appreciate your help, I would also appreciate it if you would show me the same common courtesy that I show you. I assume that we're both adults here and that's not too much to ask.

Quote:

So discarding the first line it doesn't seem like client.15 exceeds any thresholds.
I'm not sure I understand. My attacker, Client.15, sends 512 packets per second, over ten times as many as the others. Is that not the threshold in question?

Quote:

does show a sh*tload of payload-less packets. I wouldn't call it flooding, more like a set of bursts, as other players manage to get packets in as well. Now I haven't got any in-game experience wrt lag and players response times don't seem optimal anyway (we're talking the Unreliable Data Protocol) so I can't see how this would influence the game. And again, twenty minutes ain't exactly the amount of data to draw any conclusion from.

...

Should you still want to block these packets
Do you mean blocking these packets from other players? No, I'm not concerned about that. I want to block the udp packets that exceed 100/second from any one IP address, i.e., the ones sent by Client.15. Do those instructions for snort and fail2ban refer to blocking the packets from other players, or the DOS attack from Client.15?


All times are GMT -5. The time now is 08:43 PM.