Government Security
Network Security Resources

Jump to content

Photo

Need To Make A Simple Ip Blocker

- - - - - linux network c++ tools firewall denial of service
  • Please log in to reply
3 replies to this topic

#1 prashantgadagi

prashantgadagi

    Private

  • Members
  • 1 posts

Posted 08 May 2010 - 06:39 AM


Well to start with, I'm developing a tool that prevents Denial of Service attacks. Considering the scope of the project, I'm just sticking to TCP SYN flood DoS attack. I've coded the flooding part in Linux. The prevention engine, which i call the DoS engine, is completely coded in Visual C++ 2005. The functionality of the DoS engine was to detect the attackers IP address and block it from sending more packets. But till now, I'm only able to detect the incoming packets.

So, I'm in need of guidance or source code (which will be a lot better) to block IP addresses. I came accross many tools that do this, but they are fully fledged firewalls. What I need is a simple tool, with one text box and one button, that accepts IP address or a range of IP addresses and blocks it from sending packets. I tried searching for help regarding terminating a logical connection with a computer in the network, but with no fruits.

Urgent help will be greatly appreciated..


#2 Craig Fox

Craig Fox

    Private

  • Members
  • 6 posts

Posted 18 May 2010 - 02:02 PM

I've been looking into this myself recently in C or more prefferbly C++ using WinSocks and so far I have had no luck, so what do you do if there is no soloution available? create one!
Oh I have done some tools on my site, many C++ and open source so take a look you may get some ideas.

These are the ways i've figured will work:

Blocking it by external application level (not a great idea but could work), meaning if for instance you're running a web-server creating an external process to the relevant application software to block the IP address(s) but this isn't great because it's relying upon other applications to be able to do this .

The better option would be to measure how many packets/sockets are being created by a specific host and if it's a threat, close the connection(s), possibly save IP to a blacklist file and check on certain intervals if it it's connected - if so, kill the connection to the IP address(s) in file... but it's only a temporary heres a pseudo example:


LISTEN FOR CONNECTION(S)
IS THREAT?
KILL CONNECTION<-YES--NO -> CONTINUE
GET IP AND SAVE TO BAN LIST
USE EXTERN OR SAME
PROG TO GET LIST, GO THROUGH
CHECK BELOW REGULARLY
IP FROM LIST CONNECTED? YES -> KILL CONNECTION NO -> CHECK NEXT IP


-Craig Fox

Security professional, Programmer

#3 Annexx

Annexx

    Private

  • Members
  • 2 posts

Posted 06 November 2010 - 04:18 PM

So you're basically writing a firewall, yes? Something to selectively and autonomously block incoming traffic from certain hosts.
Since you mentioned the Visual Studio IDE I'll assume you're using some version of Windows; you need to write a kernel driver (NDIS) to be able to just close off sockets like that for the entire system, so look into writing kernel modules and NDIS filter intermediate drivers. There really isn't any "EASY BLOCK ALL PACKETS" type deal in usermode, especially for Microsoft crap. Here's a little page I found that should give you some more insight on NDIS Filtering tactics in the NT Kernel (A little dated, but you'll still accumulate the necassary knowledge). http://www.ntkernel....m/w&p.php?id=14
Also if it helps, I have a little linux shellscript that works in conjunction with iptables to block malicious addresses.

#4 Takatori

Takatori

    Private

  • Members
  • 4 posts

Posted 10 March 2011 - 12:17 AM

The way I would go about it is...

Using Sockets to listen on the port of your choice, log all incoming connections. If one IP exceeds a certain number of HTTP Requests add the IP to a Blacklist.





Also tagged with one or more of these keywords: linux, network, c++, tools, firewall, denial of service