Get a Pentest and security assessment of your IT network.

Cyber Security

Block MAC Addresses on Your Website

TL;DR

Blocking a MAC address directly from your website is generally not possible using standard web technologies (like JavaScript or PHP). MAC addresses are network layer details, and websites operate at the application layer. However, you can use server-side techniques to identify repeat visitors based on IP address and potentially block them if they consistently attempt to spoof a MAC address. This isn’t foolproof but offers some protection.

Understanding Why It’s Difficult

MAC addresses are used for communication within a local network. A website only sees the visitor’s IP address, not their MAC address. The browser hides this information for privacy and security reasons.

Steps to Identify & Block Repeat Visitors (Based on IP Address)

  1. Access Your Server Configuration: You’ll need access to your web server’s configuration files (e.g., Apache’s .htaccess file, Nginx’s main configuration file). How you do this depends on your hosting provider.
  2. Identify Repeat Visitors via Logs:
    • Most servers log IP addresses of visitors. Use these logs to identify suspicious patterns – many requests from the same IP address in a short period.
    • You can use tools like awk or grep on Linux/Unix systems to analyze log files.
      grep 'your_website_pattern' /var/log/apache2/access.log | awk '{print $1}' | sort | uniq -c | sort -nr
  3. Implement IP Blocking: Once you’ve identified a problematic IP address, block it using your server configuration.
    • Apache (.htaccess): Add the following line to your .htaccess file (replace 192.168.1.100 with the actual IP address):
      Deny from 192.168.1.100
    • Nginx: Add a block to your Nginx configuration file (usually in nginx.conf or a site-specific config file):
      location / {
        deny 192.168.1.100;
        allow all;
      }
  4. Consider Using a Web Application Firewall (WAF): A WAF can provide more sophisticated protection against malicious activity, including IP blocking and rate limiting.
    • Popular options include Cloudflare, Sucuri, and ModSecurity. These often have features to automatically detect and block suspicious IPs.
  5. Rate Limiting: Implement rate limiting to restrict the number of requests from a single IP address within a given timeframe.
    • This can help prevent brute-force attacks or automated scraping, even if you can’t block specific MAC addresses. The implementation varies depending on your server and WAF.

Important Considerations

  • IP Address Spoofing: IP addresses can be spoofed, so blocking an IP address isn’t a guaranteed solution.
  • Shared IPs: Blocking an IP address might block legitimate users if they share the same IP address (e.g., on a shared hosting plan).
  • Dynamic IPs: Dynamic IP addresses change over time, making blocking less effective in the long run.

Alternative Approaches

  • Client Certificates: For highly secure applications, consider using client certificates for authentication instead of relying on IP address or MAC address-based identification. This requires users to install a certificate on their device.
  • CAPTCHAs and other challenges: Implement CAPTCHAs or other challenge-response systems to verify that visitors are human.
Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation