Question**: How can I block traffic coming from specific operating system in Linux? In other words, how can I block traffic from Windows users on my firewall and allows other people?
Answer: There is an iptables module named OSF **(passive OS Fingerprinting) **that was written by Evgeniy Polyakov. This module allows passively detect OS packet was sent from and perform various netfilter actions based on this match. Packets with SYN bit set are analyzed.
In order to install OSF module, do the following:
- Download latest release from here, for example as follows:
Edit Makefile from unpacked archive in order to set proper path to iptables headers (iptables.h and libiptc/ dir).
If your kernel sources can not be accessed via /lib/modules/$(shell uname -r)/build, you have to replace KDIR variable with the correct path to kernel sources.
makethat should build ipt_osf.ko kernel module.
make libthat will build libipt_osf.so shared library (copy it to where all other iptables shared libs are placed in your distro e.g. /lib/iptables or /lib64/iptables in Fedora).
make binthat will build userspace applications which allows to load fingerprints and obtain information about matched packets (load, osfd, ucon_osf).
Download signatures list:
- Install kernel module:
- Load signatures:
./load ./pf.os /proc/sys/net/ipv4/osf
- Set up iptables rules allowing/disallowing packets generated by certain OS:
iptables -I INPUT -j ACCEPT -p tcp -m osf --genre Linux --log 0 --ttl 2
This example allows traffic from Linux systems and logs packets from other ones:
ipt_osf: Windows [2000:SP3:Windows XP Pro SP1, 2000 SP3]: 22.214.171.124:4024 -> 126.96.36.199:139
BTW, OSF has following options:
If present, OSF will log determined genres even if they donâ€™t match desired one.
0 â€“ log all matched and unknown entries.
1 â€“ only first one.
2 â€“ log all matched entries.
0 â€“ true ip and fingerprint TTL comparison. Works for LAN.
1 â€“ check if ip TTL is less than fingerprint one. Works for global addresses.
2 â€“ do not compare TTL at all. Allows to detect NMAP, but can produce false results.
If present, OSF will log all events also through netlink connector(1.0 id).
More about connector can be found in
Documentation/connector in kernel source tree.