Nmap – Techniques for Avoiding Firewalls (2024)

As a penetration tester you will come across with systems that are behind firewalls and they are blocking you from getting the information that you want.So you will need to know how to avoid the firewall rules that are in place and to discover information about a host.This step in a penetration testing called Firewall Evasion Rules.

Nmap is offering a lot of options about Firewall evasion so in this article we will explore these options.

Fragment Packets

This technique was very effective especially in the old days however you can still use it if you found a firewall that is not properly configured.The Nmap offers that ability to fragment the packets while scanning with the -f option so it can bypass the packet inspection of firewalls.

Nmap – Techniques for Avoiding Firewalls (1)

In the next image we can see that Nmap is sending packets 8-bytes size when we are doing a scan with the -f option.

Nmap – Techniques for Avoiding Firewalls (2)

Specify a specific MTU

Nmap is giving the option to the user to set a specific MTU (Maximum Transmission Unit) to the packet.This is similar to the packet fragmentation technique that we have explained above.During the scan that size of the nmap will create packets with size based on the number that we will give.In this example we gave the number 24 so the nmap will create 24-byte packets causing a confusion to the firewall.Have in mind that the MTU number must be a multiple of 8 (8,16,24,32 etc). You can specify the MTU of your choice with the command –mtu number target.

Nmap – Techniques for Avoiding Firewalls (3)

Use Decoy addresses

In this type of scan you can instruct Nmap to spoof packets from other hosts.In the firewall logs it will be not only our IP address but also and the IP addresses of the decoys so it will be much harder to determine from which system the scan started.There are two options that you can use in this type of scan:

  1. nmap -D RND:10 [target] (Generates a random number of decoys)
  2. nmap -D decoy1,decoy2,decoy3 etc. (Manually specify the IP addresses of the decoys)
Nmap – Techniques for Avoiding Firewalls (4)

In the next image we can see that in the firewall log files exist 3 different IP address.One is our real IP and the others are the decoys.

Nmap – Techniques for Avoiding Firewalls (5)

You need to have in mind that the host that you will use as decoys must be online in order this technique to work.Also using many decoys can cause network congestion so you may want to avoid that especially if you are scanning the network of your client.

Idle Zombie Scan

This technique allows you to use another host on the network that is idle in order to perform a port scan to another host.The main advantage of this method is that it very stealthy because the firewall log files will record the IP address of the Zombie and not our IP.However in order to have proper results we must found hosts that are idle on the network.

Metasploit framework has a scanner that can help us to discover hosts that are idle on the network and it can be used while implementing this type of scan.

Nmap – Techniques for Avoiding Firewalls (6)

As we can see from the above image the scanner has discovered that the IP addresses 192.168.1.67 and 192.168.1.69 are idle on the network and are potential candidates for use on an Idle Zombie Scan.In order to implement an Idle Zombie scan we need to use the command nmap -sI [Zombie IP] [Target IP]

Nmap – Techniques for Avoiding Firewalls (7)

We can see the effectiveness of this scan just by checking the firewall logs.As we can see the log files record the IP address of the Zombie host (SRC=192.168.1.69) and not our IP address so our scan was stealthy.

Nmap – Techniques for Avoiding Firewalls (8)

Source port number specification

A common error that many administrators are doing when configuring firewalls is to set up a rule to allow all incoming traffic that comes from a specific port number.The –source-port option of Nmap can be used to exploit this misconfiguration.Common ports that you can use for this type of scan are: 20,53 and 67.

Nmap – Techniques for Avoiding Firewalls (9)

Append Random Data

Many firewalls are inspecting packets by looking at their size in order to identify a potential port scan.This is because many scanners are sending packets that have specific size.In order to avoid that kind of detection you can use the command –data-length to add additional data and to send packets with different size than the default.In the image below we have changed the packet size by adding 25 more bytes.

Nmap – Techniques for Avoiding Firewalls (10)

The size of a typical packet that nmap sends to the target is 58 bytes as you can see in the image below.

Nmap – Techniques for Avoiding Firewalls (11)

With the command that we have used –data-length 25 we changed that value to 83 in order to avoid being discovered by firewalls that will check for the default packet size that nmap generates.

Nmap – Techniques for Avoiding Firewalls (12)

Scan with Random Order

In this technique you can scan a number of hosts in random order and not sequential.The command that you use to instruct Nmap to scan for host in random order is –randomize-hosts.This technique combined with slow timing options in nmap command can be very effective when you don’t want to alert firewalls.

Nmap – Techniques for Avoiding Firewalls (13)

MAC Address Spoofing

Another method for bypassing firewall restrictions while doing a port scan is by spoofing the MAC address of your host.This technique can be very effective especially if there is a MAC filtering rule to allow only traffic from certain MAC addresses so you will need to discover which MAC address you need to set in order to obtain results.

Specifically the –spoof-mac option gives you the ability to choose a MAC address from a specific vendor,to choose a random MAC address or to set a specific MAC address of your choice.Another advantage of MAC address spoofing is that you make your scan more stealthier because your real MAC address it will not appear on the firewall log files.

Specify MAC address from a Vendor —-> –spoof-mac Dell/Apple/3Com

Generate a random MAC address —-> spoof-mac 0

Specify your own MAC address —-> spoof-mac 00:01:02:25:56:AE

Nmap – Techniques for Avoiding Firewalls (14)

Send Bad Checksums

Checksums are used by the TCP/IP protocol to ensure the data integrity.However sending packets with incorrect checksums can help you to discover information from systems that is not properly configured or when you are trying to avoid a firewall.

You can use the command nmap –badsum IP in order to send packets with bad checksums to your targets.In the image below we didn’t get any results.This means that the system is suitable configured.

Nmap – Techniques for Avoiding Firewalls (15)

You can see below a sample of a packet with bad checksum that we have sent:

Nmap – Techniques for Avoiding Firewalls (16)

Conclusion

We have seen that Nmap offers a variety of methods that it can be used to avoid a firewall that exists on the network that we are scanning and to get proper results from the target host.The problem in many of the cases that we have seen is the bad configuration of Firewalls that allowed us to get results from the target.So in a network that have IDS and firewalls properly configured many of the techniques may not work.Every situation is different so you need to decide which one will work for you.

  1. I just wanted to thank you for writing this entry. I really enjoyed the information you posted. Isn’t nmap great? 🙂

    Reply

  2. great summary!

    Reply

  3. Interesting article, never knew that you could specify a static MTU using nmap 🙂

    Reply

  4. thanks a lot. your information help to me so many. especially in nmap the -f option is very good tip.

    Reply

  5. Reblogged this on Daniel Weis's I.T Security Blog and commented:
    Fantastic Post on Nmap Firewall evasion here, highly recommend the read, all of these and more I perform on most pentests however, the best protection against these is a good IPS.

    Reply

  6. Thank You 🙂

    nmap -f 192.168.1.64 did the trick for me

    Reply

  7. how to prevent from -f command so that it get detected by firewall

    Reply

Leave a comment

Nmap – Techniques for Avoiding Firewalls (2024)

FAQs

Nmap – Techniques for Avoiding Firewalls? ›

In Nmap, a stealth scan, also known as a half-open scan, is one of the scanning methods that an intruder can use to get beyond the firewall and authentication systems. Furthermore, by employing this strategy, the scan is disguised as typical network traffic, obscuring the scan.

How does Nmap evade firewall? ›

Exotic Scan Flags

Nmap offers several scan methods that are good at sneaking past firewalls while still providing the desired port state information. FIN scan is one such technique. In the section called “ACK Scan”, SYN and ACK scans were run against a machine named Para.

What techniques can be used to evade firewalls? ›

Encrypting data: By encrypting the data being transmitted, it becomes more difficult for the firewall or intrusion detection system to detect any malicious activity. VPN: A virtual private network (VPN) can help bypass firewalls and intrusion detection systems by routing traffic through a secure server.

Which Nmap option can be used to make it harder to detect packets when evading firewalls and IDS? ›

The -f option causes the requested scan (including host discovery scans) to use tiny fragmented IP packets. The idea is to split up the TCP header over several packets to make it harder for packet filters, intrusion detection systems, and other annoyances to detect what you are doing.

Can Nmap be blocked by firewall? ›

Now we look at the situation from the other side of the fence: How technology such as firewalls and IDSs can defend against Nmap. Possible defenses include blocking the probes, restricting information returned, slowing down the Nmap scan, and returning misleading information.

Can you go to jail for using Nmap? ›

When used properly, Nmap helps protect your network from invaders. But when used improperly, Nmap can (in rare cases) get you sued, fired, expelled, jailed, or banned by your ISP.

How to prevent port scanning attacks and ping scans using a firewall? ›

How to Prevent Port Scan Attacks
  1. Install a firewall. This will prevent unauthorized access to your network. ...
  2. TCP wrappers allow admins to accept or block access to servers based on IPs and domain names.
  3. Use a port scanner to check if there are unneeded open ports.
Mar 24, 2023

How does Nmap decoy scan work? ›

Decoying IP address

Nmap will send multiple packets with different IP addresses, along with your attacker's IP address. Again, the output is the same as previous outputs but on the target view is very different. Check the Logs on your Windows Server Firewall and analyze the last scan performed.

Can VPN bypass firewall? ›

Yes, it is possible for a VPN to bypass the rules set by a firewall. For instance, if your school Wi-Fi is set to block access to popular social media sites from within the network, turning on a VPN could allow you to regain access by hiding the fact that you are someone within the network.

How do hackers evade IDS? ›

Some common IDS evasion tactics include: Distributed denial-of-service (DDoS) attacks—taking IDSs offline by flooding them with obviously malicious traffic from multiple sources. When the IDS's resources are overwhelmed by the decoy threats, the hackers sneak in.

How to check firewall using Nmap? ›

To perform an Nmap firewall ACK scan, Nmap should be called with the IP address specification, the destination port, and the -sA option: root@KaliLinux:~# nmap -sA 172.16. 36.135 -p 22 Starting Nmap 6.25 ( http://nmap.org ) at 2014-01-24 11:21 EST Nmap scan report for 172...

Which Nmap scan is least detectable? ›

SYN scan is relatively unobtrusive and stealthy, since it never completes TCP connections.

Do real hackers use Nmap? ›

Inexperienced hackers will often use the default settings of Nmap and end up getting their IP blocked by the target IDS or their packets dropped by the network firewall. An experienced hacker will be patient and probe the target using different MAC/IP addresses to gain information about the targets system.

Why do hackers use Nmap? ›

Nmap is a powerful tool for ethical hackers who want to scan and analyze network traffic and logs. It can help you discover hosts, ports, services, vulnerabilities, and other information about your target network. But like any tool, it has its advantages and disadvantages.

How do I stop my firewall from blocking ports? ›

How to disable firewall on specific port?
  1. From the control panel choose Windows Firewall.
  2. Then go to advance setting from the menu on the left choose inbound rule.
  3. Select “New Rule” -> Port -> make sure that TCP is selected.
  4. Choose Specific local ports and fill the specific port that you want to allow.

What are the disadvantages of Nmap? ›

While Nmap is an excellent network mapping tool, its scanning techniques can be considered intrusive, especially on production networks. Certain scanning methods may trigger security alerts or cause disruptions on the network being scanned.

Is Nmap a firewall? ›

Nmap has a streamlined firewall filtering identification function that can be used to identify filtering on ports based on ACK probe responses. This function can be used to test a single port or multiple ports in sequence to determine filtering status.

How does Nmap work under the hood? ›

It probes open ports to gather information about the versions of services running on those ports. 5. OS Detection: Nmap can also perform operating system detection. It sends specific packets and analyzes the responses to determine the OS of the target host.

Is it illegal to scan a network with Nmap? ›

Fundamentally, it is not a crime to conduct a port scan in the United States or the European Union. This means that it isn't criminalized at the state, federal, or local levels. However, the issue of consent can still cause legal problems for unauthorized port scans and vulnerability scans.

Top Articles
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 5842

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.