LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-05-2012, 03:48 PM   #16
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600

Quote:
Originally Posted by AsadMoeen View Post
Well if you have Msn/ Skype or stuff, maybe I could show you.
My email address is available if you need to share nfo you rather not pass in public but other than that, thanks for the offer but I couldn't do that.


Quote:
Originally Posted by AsadMoeen View Post
V1.00 is a separate game and all other updates are separate so no problem with the game.
OK, if you say so...


Quote:
Originally Posted by AsadMoeen View Post
I also run a Cod4 server and on testing, it can also be flooded.
You talk about flooding but nothing can be inferred from the little traffic you've shown in this thread. Game servers use ports in the 20K range and AFAIK UDP/27015 or near are used for beacons like server game listings and game status updates. I need to see a lot more traffic, especially from before any (perceived) attack starts.



Quote:
Originally Posted by AsadMoeen View Post
When I restart my machine, it works for 2 hours.
Show us proof it does instead. Show us the iptables recent module is available ('cat /proc/net/ip_tables_matches'), loaded ('grep recent /proc/modules') and that your default bucket actually has items ('wc -l /proc/net/ipt_recent/DEFAULT').


Quote:
Originally Posted by AsadMoeen View Post
I can pay a bit to someone who can help out, he may access my machine.
Such work requires root privileges. You have absolutely no clue if somebody offering help is trustworthy, capable or able to fix the problem (post #6 again). And IMHO you shouldn't have to pay people to fix things.
 
Old 03-06-2012, 04:46 AM   #17
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
I guess I'll just make a video of the attack and how restart blocks it.

Please standby.
 
Old 03-06-2012, 06:52 AM   #18
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
And by the way here are the outputs of those commands from the XEN machine:

root@vps:~# cat /proc/net/ip_tables_matches
Code:
string
state
length
recent
udplite
udp
tcp
icmp

root@vps:~# grep recent /proc/modules
Code:
xt_recent 6627 0 - Live 0xffffffffa02e7000
x_tables 14047 10 xt_string,ipt_REJECT,xt_length,iptable_nat,xt_recent,xt_state,xt_tcpudp,iptable_filter,iptable_mangle,ip_tables, Live 0xffffffffa0296000
root@vps:~# wc -l /proc/net/xt_recent/UDP ( UDP was command name )
Code:
23 /proc/net/xt_recent/UDP
OpenVZ machine has similar output except that /proc/modules cant be seen since they are loaded from Host node

Video appears to be tough so after some time, I will just make a screenshot proof of how it works after restart.
 
Old 03-06-2012, 10:07 AM   #19
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
I have double checked the syntax and the working modules.

What was thought to be working with a restart temporarily was actually not the case but something similar.

It does work partially with a restart, here is more information:

The following commands do the job very well in blocking but there is a big issue.
Quote:
-A INPUT -p udp -m udp --dport 0:65535 -m state --state NEW -m recent --set --name UDP --rsource
-A INPUT -p udp -m udp --dport 0:65535 -m state --state NEW -m recent --update --seconds 1 --hitcount 10 --name UDP --rsource -j DROP
-A INPUT -p tcp -m tcp --dport 0:65535 -m state --state NEW -m recent --set --name TCP --rsource
-A INPUT -p tcp -m tcp --dport 0:65535 -m state --state NEW -m recent --update --seconds 1 --hitcount 10 --rttl --name TCP --rsource -j DROP

These would block automatically any IP on any port that makes more than 10 connections in a second. But the problem I am having here is that the rules do partial blocking. Lets say 5 different IP's are attacking me, no IP is getting blocked although iptables rules are intact. I restarted the machine with the same iptables rules that previously didn't block the attacker's IPs loaded on startup and suddenly they start blocking all the 5 attackers. But then lets say if attacker uses 2 more IPs to make a total of 7 IPs then the newer 2 do not get blocked while the previous 5 are blocked. This was the reason why I thought restart blocked the attacker for 2 hours but actually it just blocked the previous attackers.

So a restart once again would block all those 7 IPs and not the ones who attack after. I am not sure why this is happening.


And the attack is basically a UDP Flood, I've been under it before and the commands I mentioned are used to block it down. I have a tool myself for testing written for Debian, I've attached it in case if you wanna look at it. However, there are versions of this tool available for other Operating Systems too. You could just chmod +x Flood.sh and do "./Flood.sh IP port length time" for testing the attack on a UDP port. The attacker is using a lot of IPs ( surely botnets ) and the attack is being generated from http or some game-server ports.

Packet length is constant ( 14 ) so we could also use

-A INPUT -p udp -m udp --dport 0:65535 -m length --length 14 -j DROP

Which is a more simple but a wider command and the problem with this is the same as mentioned above.
 
Old 03-06-2012, 06:43 PM   #20
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
While I'm waiting for you to finally provide me with packet captures I asked for here's an idea: how about you shove a machine in front of those VPSes that actually has all the modules required (like a physical host or a XEN machine) and route traffic through that? That way you don't have to deal with uncooperative hosting companies or OpenVZ deficiencies.
 
Old 03-07-2012, 05:17 AM   #21
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by unSpawn View Post
While I'm waiting for you to finally provide me with packet captures I asked for here's an idea: how about you shove a machine in front of those VPSes that actually has all the modules required (like a physical host or a XEN machine) and route traffic through that? That way you don't have to deal with uncooperative hosting companies or OpenVZ deficiencies.

I am about to send those details with screenshots to your Email.

To your other concern: One of the machines I use is Xen HVM which already has everything installed but that is also a victim sadly.
 
Old 03-07-2012, 12:05 PM   #22
lisle2011
Member
 
Registered: Mar 2011
Location: Surrey B.C. Canada (Metro Vancouver)
Distribution: Slackware 2.6.33.4-smp
Posts: 183
Blog Entries: 1

Rep: Reputation: 25
DOS attacks

You have reverted to useless dialogue. You have been asked for specific information and consistently pay no attention and fail to respond with the requested information.

I think you don't have a clue, sorry to be so rude but that is the way you come across.

I for one will bail out from any further interaction with you.
 
Old 03-07-2012, 12:15 PM   #23
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Thanks for your email. However this is not what I asked for. In post #13 I supplied you with the command that will give me the output I can analyze:
Code:
tcpdump -C 50 -W 3 -p -n -nn -s 0 -i eth -w /path/to/eth.pcap
* where "eth" is your 'net-facing Ethernet device name (like "eth0") and "/path/to/eth.pcap" is the path and file name on a partition with enough space to support storing 3 packet captures of 50 megs each.

Once you have got these packet captures please send me an email to discuss where I can download the files for analysis.
** No other information or email is needed at this point.
 
Old 03-08-2012, 02:29 AM   #24
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
@Lisle:

What do you mean? I have provided everything that was asked in the topic while some private information about packet captures was mailed to unspawn with screenshots.

@Unspawn:

I'll email that to you shortly, thanks.
 
Old 03-08-2012, 04:12 AM   #25
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Pkt stats

Thanks for the captures. Finally. Three pcap files, avg size 50 MB.

Bandwidth statistics ('tcpstat -a -r filename'):
Code:
Bytes/sec       =    639.6 KB
Bytes/minute    =     37.5 MB
Bytes/hour      =      2.2 GB
Bytes/day       =     52.7 GB
Bytes/month     =   1580.9 GB
Traffic breakdown ('tcpstat -o "IPv4:%I\tTCP:%T\tUDP:%U\tICMP:%C\tpkg_avg_byte_sz:%a\tpkg_max_byte_sz:%M\tpkg_min_byte_sz:%m\tpkg_s ec:%p\tbytes_sec:%B\tload:%l\n" -r filename'):
Code:
IPv4:10822      TCP:35  UDP:10787       ICMP:0  pkg_avg_byte_sz:330.97  pkg_max_byte_sz:1440    pkg_min_byte_sz:40      pkg_sec:2170.00 bytes_sec:718206.40     load:1.00
IPv4:10947      TCP:12  UDP:10935       ICMP:0  pkg_avg_byte_sz:328.24  pkg_max_byte_sz:1440    pkg_min_byte_sz:40      pkg_sec:2193.60 bytes_sec:720020.60     load:1.00
IPv4:11067      TCP:10  UDP:11057       ICMP:0  pkg_avg_byte_sz:329.89  pkg_max_byte_sz:1440    pkg_min_byte_sz:40      pkg_sec:2217.80 bytes_sec:731622.20     load:0.98
IPv4:10935      TCP:1   UDP:10934       ICMP:0  pkg_avg_byte_sz:331.47  pkg_max_byte_sz:789     pkg_min_byte_sz:40      pkg_sec:2190.40 bytes_sec:726053.20     load:0.98
IPv4:10789      TCP:0   UDP:10789       ICMP:0  pkg_avg_byte_sz:337.21  pkg_max_byte_sz:1162    pkg_min_byte_sz:41      pkg_sec:2161.60 bytes_sec:728906.20     load:0.99
IPv4:11047      TCP:0   UDP:11047       ICMP:0  pkg_avg_byte_sz:332.30  pkg_max_byte_sz:739     pkg_min_byte_sz:41      pkg_sec:2213.60 bytes_sec:735571.80     load:0.98
IPv4:10901      TCP:0   UDP:10901       ICMP:0  pkg_avg_byte_sz:328.92  pkg_max_byte_sz:738     pkg_min_byte_sz:32      pkg_sec:2182.80 bytes_sec:717960.00     load:0.98
IPv4:10935      TCP:0   UDP:10935       ICMP:0  pkg_avg_byte_sz:330.07  pkg_max_byte_sz:824     pkg_min_byte_sz:41      pkg_sec:2190.20 bytes_sec:722921.40     load:0.98
IPv4:10898      TCP:0   UDP:10898       ICMP:0  pkg_avg_byte_sz:328.71  pkg_max_byte_sz:904     pkg_min_byte_sz:41      pkg_sec:2182.60 bytes_sec:717441.40     load:0.98
IPv4:10966      TCP:0   UDP:10966       ICMP:0  pkg_avg_byte_sz:326.69  pkg_max_byte_sz:793     pkg_min_byte_sz:41      pkg_sec:2196.40 bytes_sec:717532.40     load:0.98
IPv4:10935      TCP:0   UDP:10935       ICMP:0  pkg_avg_byte_sz:327.81  pkg_max_byte_sz:845     pkg_min_byte_sz:41      pkg_sec:2192.00 bytes_sec:718559.80     load:0.98
IPv4:10891      TCP:11  UDP:10880       ICMP:0  pkg_avg_byte_sz:333.51  pkg_max_byte_sz:1440    pkg_min_byte_sz:40      pkg_sec:2183.00 bytes_sec:728046.00     load:0.98
IPv4:7166       TCP:5   UDP:7161        ICMP:0  pkg_avg_byte_sz:338.37  pkg_max_byte_sz:1440    pkg_min_byte_sz:41      pkg_sec:1436.00 bytes_sec:485904.80     load:0.96
IPv4:10824      TCP:26  UDP:10798       ICMP:0  pkg_avg_byte_sz:328.99  pkg_max_byte_sz:1440    pkg_min_byte_sz:40      pkg_sec:2171.00 bytes_sec:714231.80     load:1.00
IPv4:10644      TCP:1   UDP:10643       ICMP:0  pkg_avg_byte_sz:340.11  pkg_max_byte_sz:1122    pkg_min_byte_sz:40      pkg_sec:2133.60 bytes_sec:725666.20     load:0.99
IPv4:10747      TCP:0   UDP:10747       ICMP:0  pkg_avg_byte_sz:340.18  pkg_max_byte_sz:960     pkg_min_byte_sz:41      pkg_sec:2154.40 bytes_sec:732884.20     load:0.98
IPv4:10736      TCP:9   UDP:10727       ICMP:0  pkg_avg_byte_sz:329.32  pkg_max_byte_sz:973     pkg_min_byte_sz:40      pkg_sec:2152.80 bytes_sec:708969.00     load:0.98
IPv4:10890      TCP:27  UDP:10863       ICMP:0  pkg_avg_byte_sz:330.63  pkg_max_byte_sz:847     pkg_min_byte_sz:40      pkg_sec:2183.00 bytes_sec:721760.20     load:0.98
IPv4:10823      TCP:3   UDP:10820       ICMP:0  pkg_avg_byte_sz:329.20  pkg_max_byte_sz:708     pkg_min_byte_sz:40      pkg_sec:2169.80 bytes_sec:714307.80     load:0.98
IPv4:10834      TCP:10  UDP:10824       ICMP:0  pkg_avg_byte_sz:331.29  pkg_max_byte_sz:845     pkg_min_byte_sz:40      pkg_sec:2171.80 bytes_sec:719493.80     load:0.98
IPv4:10906      TCP:33  UDP:10873       ICMP:0  pkg_avg_byte_sz:327.23  pkg_max_byte_sz:708     pkg_min_byte_sz:40      pkg_sec:2185.80 bytes_sec:715256.20     load:0.98
IPv4:10875      TCP:16  UDP:10859       ICMP:0  pkg_avg_byte_sz:334.15  pkg_max_byte_sz:708     pkg_min_byte_sz:40      pkg_sec:2179.00 bytes_sec:728102.00     load:0.98
IPv4:10664      TCP:13  UDP:10651       ICMP:0  pkg_avg_byte_sz:332.16  pkg_max_byte_sz:2840    pkg_min_byte_sz:40      pkg_sec:2139.00 bytes_sec:710495.80     load:0.98
IPv4:11137      TCP:13  UDP:11124       ICMP:0  pkg_avg_byte_sz:324.76  pkg_max_byte_sz:1336    pkg_min_byte_sz:39      pkg_sec:2255.60 bytes_sec:732537.80     load:0.98
IPv4:11108      TCP:21  UDP:11087       ICMP:0  pkg_avg_byte_sz:327.76  pkg_max_byte_sz:1336    pkg_min_byte_sz:28      pkg_sec:2250.40 bytes_sec:737585.40     load:0.98
IPv4:7707       TCP:17  UDP:7690        ICMP:0  pkg_avg_byte_sz:328.89  pkg_max_byte_sz:708     pkg_min_byte_sz:40      pkg_sec:1544.80 bytes_sec:508070.40     load:0.95
IPv4:10793      TCP:8   UDP:10785       ICMP:0  pkg_avg_byte_sz:335.65  pkg_max_byte_sz:909     pkg_min_byte_sz:40      pkg_sec:2162.60 bytes_sec:725873.80     load:1.00
IPv4:11033      TCP:6   UDP:11027       ICMP:0  pkg_avg_byte_sz:330.69  pkg_max_byte_sz:944     pkg_min_byte_sz:40      pkg_sec:2211.40 bytes_sec:731279.00     load:0.99
IPv4:11061      TCP:11  UDP:11050       ICMP:0  pkg_avg_byte_sz:332.85  pkg_max_byte_sz:2840    pkg_min_byte_sz:40      pkg_sec:2217.80 bytes_sec:738187.20     load:0.99
IPv4:11261      TCP:4   UDP:11257       ICMP:0  pkg_avg_byte_sz:324.56  pkg_max_byte_sz:708     pkg_min_byte_sz:40      pkg_sec:2259.20 bytes_sec:733255.00     load:0.99
IPv4:11246      TCP:18  UDP:11228       ICMP:0  pkg_avg_byte_sz:326.90  pkg_max_byte_sz:945     pkg_min_byte_sz:40      pkg_sec:2256.80 bytes_sec:737758.00     load:0.99
IPv4:10793      TCP:0   UDP:10793       ICMP:0  pkg_avg_byte_sz:333.31  pkg_max_byte_sz:1336    pkg_min_byte_sz:39      pkg_sec:2164.20 bytes_sec:721346.80     load:0.99
IPv4:10897      TCP:18  UDP:10877       ICMP:2  pkg_avg_byte_sz:331.29  pkg_max_byte_sz:1336    pkg_min_byte_sz:39      pkg_sec:2182.60 bytes_sec:723076.40     load:0.99
IPv4:11036      TCP:39  UDP:10997       ICMP:0  pkg_avg_byte_sz:330.83  pkg_max_byte_sz:1248    pkg_min_byte_sz:40      pkg_sec:2211.60 bytes_sec:731653.20     load:0.99
IPv4:11117      TCP:19  UDP:11098       ICMP:0  pkg_avg_byte_sz:325.99  pkg_max_byte_sz:990     pkg_min_byte_sz:40      pkg_sec:2227.20 bytes_sec:726039.80     load:0.99
IPv4:11315      TCP:51  UDP:11264       ICMP:0  pkg_avg_byte_sz:324.14  pkg_max_byte_sz:1274    pkg_min_byte_sz:40      pkg_sec:2268.00 bytes_sec:735150.20     load:0.99
IPv4:11216      TCP:110 UDP:11106       ICMP:0  pkg_avg_byte_sz:326.37  pkg_max_byte_sz:1336    pkg_min_byte_sz:40      pkg_sec:2260.80 bytes_sec:737852.60     load:0.99
IPv4:11215      TCP:47  UDP:11168       ICMP:0  pkg_avg_byte_sz:324.96  pkg_max_byte_sz:1336    pkg_min_byte_sz:40      pkg_sec:2273.60 bytes_sec:738827.60     load:0.99
IPv4:5686       TCP:0   UDP:5686        ICMP:0  pkg_avg_byte_sz:333.81  pkg_max_byte_sz:1336    pkg_min_byte_sz:41      pkg_sec:1151.60 bytes_sec:384412.00     load:0.95
Per pcap file there are roughly 140K packets. Of those 140K approximately 110K is UDP traffic, specifically game status messages (wireshark filter "data.data contains 74:61:74:75:73"), packet length divided equally between between 40-80 and 640-1280 or a 15 or 680 byte payload.
 
1 members found this post helpful.
Old 03-08-2012, 04:30 AM   #26
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
Thank you for posting this, here is some more information for the rest:

Quote:
I checked those packet capture files too and what it appears to be is that the "getstatus" string is flooding the game-servers. I'll give you my opinions on that one since its usually the case with game-servers because they start sending the output of the query ( the output that includes server information like name, slots and stuff ) and since they flood the query, the output reaches high file size. The attacker's IP is spoofed and they can use other game-server's ports to flood another server. A guy came to me that I was attacking his Cod4 server although he was attacking my SOF2 server and basically we were both attacking each other due to the real attacker's IP being spoofed on his machine. He gave this solution for firewall:

http://wiki.modsrepository.com/index...rs#DDos_Attack

You might like reading it and the ending solution too, so you can understand more about this attack.

The solution however didn't work for me although I did change the length to 15 using the same command.
 
Old 03-08-2012, 05:57 AM   #27
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
I have finally found the problem and an answer to all my questions, although still waiting to find a solution.

Here is the crack down:

After probably testing 7 days that included restarting, attacks from my own test machines and a large number of iptables rules I have finally reached the conclusion. The iptables rules are working and doing exactly what they should but they work only when the game-server is stopped which is why after a system restart the following things happened:
  • Attacker was sending "getstatus" requests to the game-server port.
  • The machine freshly restarted, so the game server wasn't running.
  • Tcpdump just sent "Port Unreaachable" to the attacker which hardly made 200kb/s output.
  • Output was "Zero" when rate-limit rules were applied so no output to the attacker.

As we all know that incoming packets can never be blocked by iptables, the output can be controlled but depending upon the application running at the port. So now when the Game-Server started, then because of the server itself; rate limit wasn't working. The game-server was replying to the attacker's "getstatus" requests which caused the large output to the attacker's IP. Please correct me if I am wrong with this conclusion.


Now some people have fixed this in the game server's executables already by manually applying some rate-limit in the patches like 1 request/sec while some are using their own scripts. Since I can't create any such patches or use newer version of the game, I'll have to use some scripts to do the job or some work-around the iptables.

For more information about the attack: http://wiki.modsrepository.com/index...rs#DDos_Attack

So most of you now will be fully aware of what I mean to say here, any suggestions to fix the issue or why the solution in the above link doesn't work for me would be greatly appreciated. Probably just the way the application works, not sure.

Code:
A INPUT -p UDP -m length --length 15 -m recent --set --name getstatus_cod
$IPT -A INPUT -p UDP -m string --algo bm --string "getstatus" -m recent --update --seconds 1 --hitcount 20 --name getstatus_cod -j DROP
 
Old 03-08-2012, 11:48 AM   #28
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
Thanks to this guy over here for making the exact script I needed.

http://wolffiles.de/index.php?forum-showposts-44-p1

His script I cronjob'd to run every 1 minute and automatically bans the address flooding "getstatus" requests. But I do also need to know a direct and instant solution, in case he floods harder; he would already have given my gameservers some piece of lag and it would take 1 minute to ban his IP.

iptables is the only instant solution so if anyone can come up with some direct commands or answer why the above ones don't work for me. I probably think that when the Game Server is running, it has some higher precedence than iptables rules so the iptables rules work only when the game-server is stopped.
 
Old 03-10-2012, 09:35 AM   #29
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by AsadMoeen View Post
The iptables rules are working and doing exactly what they should but they work only when the game-server is stopped
I do not believe this is a correct analysis.


Quote:
Originally Posted by AsadMoeen View Post
Tcpdump just sent "Port Unreaachable" to the attacker which hardly made 200kb/s output.
tcpdump doesn't send anything: it just captures traffic.


Quote:
Originally Posted by AsadMoeen View Post
As we all know that incoming packets can never be blocked by iptables,
Your analysis makes you believe that. However it was not correct and therefore your conclusions are not correct.


Quote:
Originally Posted by AsadMoeen View Post
I can't create any such patches or use newer version of the game
That's problem number #0: you are not willing to patch or use a patched version of the game. This basically means you yourself allow part of the problem to continue unnecessarily.


Quote:
Originally Posted by AsadMoeen View Post
Code:
A INPUT -p UDP -m length --length 15 -m recent --set --name getstatus_cod
$IPT -A INPUT -p UDP -m string --algo bm --string "getstatus" -m recent --update --seconds 1 --hitcount 20 --name getstatus_cod -j DROP
...and that's problem #1: because, for reasons unknown, your iptables modules don't work as advertised you won't be getting any use out of those rules until you fix the reason for the iptables modules not working. (Should you have been able to use ipset then you could try a suggestion as posted here but since you already have problems with iptables modules that's probably out of the question.)


Quote:
Originally Posted by AsadMoeen View Post
His script I cronjob'd to run every 1 minute and automatically bans the address flooding "getstatus" requests.
There's a few problems with the script. It is inefficient for 0) running tcpdump repeatedly, 1) disabling resolution only partially with "-f" (and not "-n -nn -N"), 2) running tcpdump without a BPF filter (like 'udp dst 20100'), 3) running "grep|awk|cut"-like chains where you could run awk with "-F" and a '/searchterm/' filter and 4) using the filter table INPUT chain for traffic that would be better dropped in the raw table PREROUTING chain. Most importantly though a server is required to send "getstatus" traffic to clients and other servers, so rate limiting at least allows for some functionality as opposed to the script which blocks IP addresses completely. Then again you're not the only one having OpenVZ-related trouble. So if blocking IP addresses based on packet payload is all that remains then at least run something more efficient like Snort:
- create a directory "/etc/snort" (if the Snort installation didn't do so already) and save this completely self-contained configuration file as "/etc/snort/snort_game.conf":
Code:
var HOME_NET nnn.nnn.nnn.nnn/32
var EXTERNAL_NET !$HOME_NET
preprocessor stream5_global: track_icmp no, track_tcp no, track_udp yes, max_udp 1052672
preprocessor stream5_udp: timeout 60
portvar GAME_PORTS [20100:29999]
alert udp $EXTERNAL_NET any -> $HOME_NET $GAME_PORTS (msg:"getstatus_thresh"; content:"getstatus"; flow:to_server, established; threshold: type both, track by_src, count 2, seconds 10; reference:url,www.linuxquestions.org/questions/linux-server-73/iptables-rate-limit-to-block-ddos-931931/; sid: 999999998; rev:1;)
- create a directory "/var/log/snort" (again, if the Snort installation didn't do so already) and ensure the user Snort runs as can write to it,
- run Snort as 'snort -A fast -q -c /etc/snort/snort_game.conf -k none -K none -l /var/log/snort'.
This will generate and update a plain text /var/log/snort/alert log file, without requiring a kludge like the "Q3-Engine-GetStatus-Flood-Fixer", which is only written to if the rule is triggered at least 2 times in 10 seconds (feel free to adjust) and which guardian, fail2ban or whatever continuously log-reading application you favor, can read and create 'iptables -t raw -A PREROUTING -s $IP -j DROP' rules for.


Quote:
Originally Posted by AsadMoeen View Post
if anyone can (..) answer why the above ones don't work for me.
That would minimally require IPTABLES_SAVE_COUNTER, IPTABLES_STATUS_NUMERIC, IPTABLES_STATUS_VERBOSE and IPTABLES_STATUS_LINENUMBERS to be set to "yes" in iptables-config,
running 'iptables-save > /path/to/iptables`date +%s`.log' at some interval and regularly checking /proc/net/ipt_recent/* lists so there's actually hard evidence of traffic. Your iptables rule set might need some adjusting beforehand. Here's a suggestion:
Code:
# Generated by iptables-save v1.4.2 on Wed Feb  1 17:28:45 2012
*nat
:PREROUTING ACCEPT [0:0]
# Block non-routable traffic: comment out any LAN ranges you use.
-A PREROUTING -i venet0 -s 0.0.0.0/8 -j DROP
-A PREROUTING -i venet0 -s 10.0.0.0/8 -j DROP
-A PREROUTING -i venet0 -s 127.0.0.0/8 -j DROP
-A PREROUTING -i venet0 -s 169.254.0.0/16 -j DROP
-A PREROUTING -i venet0 -s 172.16.0.0/12 -j DROP
-A PREROUTING -i venet0 -s 192.0.0.0/24 -j DROP
-A PREROUTING -i venet0 -s 192.0.2.0/24 -j DROP
-A PREROUTING -i venet0 -s 192.168.0.0/16 -j DROP
-A PREROUTING -i venet0 -s 198.18.0.0/15 -j DROP
-A PREROUTING -i venet0 -s 198.51.100.0/24 -j DROP
-A PREROUTING -i venet0 -s 203.0.113.0/24 -j DROP
:POSTROUTING DROP [0:0]
:OUTPUT ACCEPT [0:0]
# Block non-routable traffic: comment out any LAN ranges you use.
-A OUTPUT -o venet0 -s 0.0.0.0/8 -j DROP
-A OUTPUT -o venet0 -s 10.0.0.0/8 -j DROP
-A OUTPUT -o venet0 -s 127.0.0.0/8 -j DROP
-A OUTPUT -o venet0 -s 169.254.0.0/16 -j DROP
-A OUTPUT -o venet0 -s 172.16.0.0/12 -j DROP
-A OUTPUT -o venet0 -s 192.0.0.0/24 -j DROP
-A OUTPUT -o venet0 -s 192.0.2.0/24 -j DROP
-A OUTPUT -o venet0 -s 192.168.0.0/16 -j DROP
-A OUTPUT -o venet0 -s 198.18.0.0/15 -j DROP
-A OUTPUT -o venet0 -s 198.51.100.0/24 -j DROP
-A OUTPUT -o venet0 -s 203.0.113.0/24 -j DROP
-A OUTPUT -o venet0 -s 224.0.0.0/4 -j DROP
COMMIT
# Completed on Wed Feb  1 17:28:45 2012
# Generated by iptables-save v1.4.2 on Wed Feb  1 17:28:45 2012
*filter
:INPUT ACCEPT [0:0]
:IN_VENET ACCEPT [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
# Always allow localnet
-A INPUT -i lo -j ACCEPT
# Move everything that isn't localnet to another chain:
-A INPUT ! -i lo -j IN_VENET
# Allow traffic on connections already in use:
-A IN_VENET -m state --state ESTABLISHED -j ACCEPT
# Log and drop traffic that conntrack can't link to existing connections:
-A IN_VENET -m conntrack --ctstate INVALID -m limit --limit 1/minute --limit-burst 3 -j LOG --log-prefix "REJ_INV "
-A IN_VENET -m conntrack --ctstate INVALID -j REJECT --reject-with icmp-admin-prohibited
# This could limit UDP traffic in the 20100-29999 port range to 10 packets per second and burst up to 30 per IP address  + destination port (if you have "hashlimit"):
# -A IN_VENET -m udp -p udp -m multiport --dports 20100:29999 -m hashlimit --hashlimit 10/s --hashlimit-burst 30 --hashlimit-mode srcip,dstport --hashlimit-name SOF2 -m state --state NEW -j ACCEPT
# Use a 20100-29999 port range for your "recent" module traffic:
-A IN_VENET -p udp -m udp -m multiport --dports 20100:29999 -m state --state NEW -m recent --set --name SOF2 --rsource
-A IN_VENET -p udp -m udp -m multiport --dports 20100:29999 -m state --state NEW -m recent --update --seconds 1 --hitcount 10 --name SOF2 --rsource -j LOG --log-prefix "REJ_SOF2 "
-A IN_VENET -p udp -m udp -m multiport --dports 20100:29999 -m state --state NEW -m recent --update --seconds 1 --hitcount 10 --name SOF2 --rsource -j DROP 
-A OUTPUT -o lo -j ACCEPT
COMMIT
# Completed on Wed Feb  1 17:28:45 2012
 
1 members found this post helpful.
Old 03-12-2012, 03:29 AM   #30
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
I was busy last days so sorry about the late reply.

Thanks for the suggestion but I guess your thinking that I only have an OpenVZ machine that doesn't have the required iptables modules. As I posted above, I have a fully loaded Xen HVM machine with all required modules and even on the OpenVZ machine, required modules are loaded by the provider.

So what makes you think that the modules are not loaded because I posted a list of modules output in my previous post?


About the Patch:

The current version is the only patched version of the game by the provider and it does not follow any updates, for it being a very old game. All servers run this version but use a firewall solution to defend against the attack.

When I said tcpdump sending output, I actually meant the captured output.


About my Analysis:

Why do you think the iptables would work just after the restart? The only thing in common was the Game-Server not running. Just when the system restarted, game-server was definitely turned off because I have to start that manually ( no auto-startup ). All the attacks were blocked because at that time the server was just sending output of "port unreacheable" and when iptables rules were applied, I myself saw that no output was being made even for the newer IPs. Now as soon as the Game-Server started, people attacking before the game-server started were blocked but anyone attacking a running game-server port now was not being blocked but instead game-server was sending out "getstatus" replies. I tested this at least 10 times before coming to the conclusion so obviously this has something to do with it otherwise what else do you think caused it? because you also didn't explain this happening.


About Rate-Limit and the Script:

The script does block the attacker but has the functionality to unblock it as well. Rate-limit also does actually quite the same thing because when you go ahead of your limit, you are COMPLETELY BLOCKED so the only difference that makes is that when you fall below the limit, you are automatically unblocked. Although I understand your script or alternative to that is parallel but with the current script running, I am facing no issues and the clients are working good as well but your way being better so I would definitely try that if a direct iptables solution is not reached.




Your iptables Save File

I don't have the "hashlimit" module yet so I will be getting that loaded first onto the machine and then try your script considering that it will allow the traffic to pass through the iptables instead of allowing the attacker to bypass directly to the game-server port.

I am running a Custom Kernel so that I would have to repatch it and generate the config with the modules or is there any method to do so without it?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] IPTABLES Rate Limit AsadMoeen Linux - Security 4 03-16-2012 02:10 AM
Help with Iptables configuration protect from ddos tarciokk Linux - Server 5 11-19-2011 07:15 AM
Iptables rate limiting for Ddos AsadMoeen Linux - Server 5 03-07-2011 11:57 PM
tc - limit rate on VPN? qwertyjjj Linux - Server 1 11-08-2010 11:59 AM
I got DDOS: Need some help (esp with iptables) Swakoo Linux - Networking 3 01-16-2006 12:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration