This week's book giveaway is in the Testing forum.
We're giving away four copies of Practical Unit Testing with TestNG and Mockito and have Tomek Kaczanowski on-line!
See this thread for details.
The moose likes General Computing and the fly likes Inner workings of firewall programs Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » General Computing
Reply Bookmark "Inner workings of firewall programs" Watch "Inner workings of firewall programs" New topic
Author

Inner workings of firewall programs

Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11945
I was wondering how are firewall programs such as BlackICE typically implemented? I know that they somehow intercept all traffic in and out of a network interface.
Is the firewall program relying on some "hooks" provided by the operating system? Something else?
I'd really appreciate any hints for where to look at...


Author of Test Driven (Manning Publications, 2007) [Blog] [HowToAskQuestionsOnJavaRanch]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 23395

I don't know much about Windows these days, but at one time the TCP stack was just a DLL -- it was replaceable and there multiple vendor-versions available. That's probably still true to some extent, and Windows firewalls probably work by hooking that DLL.
I know a little more about how this works on Linux. ipchains/iptables are kernel modules that work by hooking into the kernel's networking modules.


[Jess in Action][AskingGoodQuestions]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11945
Oooh. Can describe what these "hooks" look like in Linux?
girish rateshwar
Ranch Hand

Joined: Mar 04, 2001
Posts: 97
Hi,
Well every firewall defines the following:
Rule - a rule states whether packets(data) associated with a defined port is allowed or dis-allowed from passing a given point in the firewall.
Chain - a collection of rules. Associated with a Hook so that its rules become active.
Hooks - it is best to think of these as parts of the router that packets pass though.

[ October 07, 2003: Message edited by: girish rateshwar ]

Girish
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11945
Thanks Girish, for the info, but I know that conceptual stuff. What I'm interested in is how does a (C/C++) programmer code his program to use those hooks?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11945
Originally posted by Lasse Koskela:
Thanks Girish, for the info, but I know that conceptual stuff. What I'm interested in is how does a (C/C++) programmer code his program to use those hooks?
Just to clarify things a bit, I don't mean "how" as in "show me the code", but more like "tell me how one connects to these hooks using plain English instead of source code".
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
http://www.practicallynetworked.com/sharing/firewall.htm
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 23395

In Linux, it's something you can do only in kernel space -- i.e., you'd write a kernel module. The routines that provide the hooks are in the net/ipv4/netfilter directory in the kernel source distribution -- look, for example, at netfilter.c .
Now, ipfilter/iptables already offer a lot of configurable flexibility, so just using them might be all you need to do -- but I don't know why you're asking this, so I can't day.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11945
Eric, thanks for the link. You made me realize that I was still using the wrong terminology: I was particularly interested in "software personal firewall" internals...
Originally posted by Ernest Friedman-Hill:
In Linux, it's something you can do only in kernel space -- i.e., you'd write a kernel module. The routines that provide the hooks are in the net/ipv4/netfilter directory in the kernel source distribution -- look, for example, at netfilter.c .
Now, ipfilter/iptables already offer a lot of configurable flexibility, so just using them might be all you need to do -- but I don't know why you're asking this, so I can't day.

I kind of figured that you'd need to plug your piece of code into the operating system, which makes sense in Linux, but not so (for me) in Windows. I'm asking this because someone threw an idea in the air over lunch that we should write a personal firewall for Symbian devices. The natural progression was to ask how -- even though we're not really going to do it (I'm pretty much Java-only although I have a few .NET books on the shelf waiting for the rainy day, and my C++ skills are rusty to say the least). As I chewed on my pizza, I tried to visualize how one would go about writing the code that intercepts the incoming byte streams and somehow tells the operating system whether to let it pass or stop right there. Then I realized I was probably way wrong and decided to ask someone who might know...
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 23395

You probably wouldn't be intercepting streams, but raw IP packets. But basically, you'd be writing a DLL which did something like

inserting itself inside the OS.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11945
That's along the lines I figured it could be. Thanks.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

This might be a very cool place to start out (for Linux)

http://www.smoothwall.org/

open source, and free (as in beer)
 
IntelliJ Java IDE
 
subject: Inner workings of firewall programs
 
Threads others viewed
java.net.UnknownHostException when calling a web service from Java client
my PC suddenly turns to be extremely slow
firewall and javaw.exe and jvm
Datasource lookup on remote Websphere Application Server
simple socket programming
MyEclipse, The Clear Choice