loading

How to Block Malicious IPs Effectively

I blocked xmlrpc.php using .htaccess about a month ago. After about four and a half days, I noted that the attacks had lessened, but four and a half days is a short time. The bots might refresh their lists faster than that, or it could have just been a quiet week. So, this time, I pulled four weeks of Apache logs, divided the 28.7 days since the block into four chunks, and analyzed the data. To get straight to the point: the request volume dropped to about one-eighth of what it was before the block and the rejected IPs barely came back. However, there was one week where a single IP hit us 71 times within one minute, and this block successfully stopped one specific action on our end.

Breaking Down the 28.7 Days into Four Chunks

The time I implemented the block was 12:07:31 PM on October 11, 2026, when I modified the .htaccess file. Since the logs roll over at midnight every Saturday, I used that boundary as my window. The first window, starting from the block time, covers 6.49 days.

Week Period 403 Errors Avg. Daily Unique IPs IPs with Only One Hit Max Hits by One IP
Week 1 10/11 12:07 ~ 10/17 556 85.7 298 51.3% 10
Week 2 10/18 ~ 10/24 136 19.4 75 69.3% 11
Week 3 10/25 ~ 10/31 190 27.1 95 61.1% 16
Week 4 11/01 ~ 11/07 329 47.0 161 67.7% 71
Current 11/08 ~ 11/09 05:56 68 54.6 67 98.5% 2

Combining these four weeks, we see 1,211 instances of 403 errors, averaging 44.1 per day over 27.49 days. Before the block, our site was receiving 367 requests to xmlrpc.php daily during a 7-day period, so this is a drop of over 88%. That number has remained relatively stable, fluctuating between 19.4 and 85.7 over the month. It isn't a steady downward trend. It dipped to 19.4 in Week 2 but then climbed back up to 47.0 in Week 4.

The request methods changed across the weeks. In Week 1, we saw 490 POST requests compared to 66 GET requests, but in Weeks 2 and 3, GET requests made up over half. Then, in Week 4, it shifted back to POST with 237 requests versus 92 GET requests. It looks like they were alternating between POST requests—which send login credentials—and GET requests—which just check if a file exists.

Blocked IPs Aren't Coming Back

When you gather all the IPs that received a 403 error across five different windows, you get 662 unique addresses. I tracked how many of these IPs appeared in two or more windows.

Number of Windows Appeared In Number of IPs Percentage
1 632 95.5%
2 26 3.9%
3 4 0.6%
4 or More 0 0%

The overlap between adjacent windows was also small. For example, there were 6 IPs shared between Week 1 and Week 2, 8 between Week 2 and Week 3, and 14 between Week 3 and Week 4. Only 2 IPs spanned the gap between Week 1 and Week 4. This means that IPs that got a 403 error and then returned the following week made up only a single-digit percentage of the total.

However, that doesn't mean the bots gave up. New IPs show up every single week. A 403 error just teaches a specific IP address, "This address is useless," but the next IP comes along without knowing that.

Even when I tracked the IPs for four and a half days right after implementing the block, the number of IPs didn't decrease; it stayed the same over the course of a month.

The Day One IP Hit 71 Times in a Single Minute

There were five IPs that made more than 10 hits over the four weeks. The counts were ten, eleven, sixteen, ten, and seventy-one. I focused on the last one because it stood out and grouped the request times by minute.

All 71 requests landed within the same minute, and then they stopped coming. Even though I changed the browser name for every request, a human simply cannot send 71 POST requests to the same file in one minute, so those logs are all fake. For a 403 error to act as a signal to block the next request, the sender needs to read the response, but these 71 requests seem to have been dumped all at once without waiting for a reply. This is the kind of request that is difficult to stop with simple blocking.

Looking at the User Agent for the requests that got a 403, over 95% claimed to be browsers across all four weeks. This is the same kind of fabrication as the requests that claimed to be from Google (requests listed as coming from Google). There were eight external requests that claimed to be WordPress clients, and they all included a domain structure like followed by an eight-digit number. These are disposable addresses.

The Attacks Didn't Just Move to the Login Page

You often hear that when you block one attack vector, the attacks just switch to another door. In our initial five-and-a-half-day measurement, it looked like the POST requests to wp-login.php were increasing, but since the fluctuation was still within the normal range before the block, we didn't jump to conclusions. This time, we asked a different question: Are the increased login requests coming from those same IPs that were previously blocked by xmlrpc?

Week wp-login POST 200 Count Login IP Count Overlap with Blocked xmlrpc IPs Percentage of Login IPs
Week 1 1,515 767 72 9.4%
Week 2 2,270 391 4 1.0%
Week 3 2,746 584 17 2.9%
Week 4 4,116 311 28 9.0%

The number of login requests jumped from 1,515 to 4,116—a 2.7x increase. However, the percentage of those requests coming from IPs that had previously been blocked by xmlrpc was at most 9.4% in Week 1 and only 1.0% in Week 2. Over 90% of the IPs hitting the login page had never even touched xmlrpc.php. So, while the login traffic is definitely up, there's no proof that it migrated because we closed the other door. Bots that target both endpoints hit both, and bots that stick to one endpoint stick to it.

What This Block Actually Stopped

When I put the block in place, I noted that since Jetpack, the mobile app, and inbound pingbacks weren't being used, there was nothing to lose. After checking the logs for the past month for requests that our server itself was rejecting with a 403 error, I found exactly one type of activity.

54.116.4.12 "POST /xmlrpc.php" 403
  UA: The Incutio XML-RPC PHP Library -- WordPress/7.0.7

10/11 12:21:16 2 instances 10/28 20:22:03 5 instances
10/15 18:54:46 2 instances 11/03 15:55:54 2 instances
10/25 15:42:51 2 instances 11/03 16:07:14 2 instances <-- User Agent updated to 7.0.8

These requests were coming from the server's public IP address back to itself. All six timestamps perfectly matched the moments I was publishing or editing a post. WordPress tries to send a pingback to the link in the post body when saving, and since our posts only use internal links, the target is itself. It went out, came back to the public IP, and got caught by the rule we set up.

Over the course of a month, there were fifteen instances, and since I have no intention of adding pingbacks to my own posts, there's no loss. However, "nothing to lose" didn't mean "nothing happened." Every time I publish, two lines with my name show up in the logs as a 403 error. Plus, this line can also serve as a marker indicating when the WordPress version was updated.

The Loopholes That Open When You Block by Name

The rule targets a specific file name.

<Files "xmlrpc.php">
    Require all denied
</Files>

I tested whether there were any ways to bypass the name by creating variations and sending them directly to three different sites. I also tried sending requests to myself internally using the --resolve command.

Request Path Response Interpretation
/xmlrpc.php 403 Blocked
/xmlrpc.php?rsd 403 Blocked
/wp-includes/../xmlrpc.php 403 Blocked
/XMLRPC.php 404 File Not Found
/damyo.net/xmlrpc.php 500 Did Not Hit Rule

How a Single Dot Changes a 404 to a 500

The only difference is the path that returned a 500. To figure out why, I tried sending requests again, changing the first part and the file extension one by one.

Path Response
//ab/c.php 404
//a_b/c.php 404
//a.b/c.php 500
/a.b/c.php 500
//1.2/x.php 500
//a.b/c 301

There are two conditions at play. The first is that the path starts with a dot, and the file name ends in .php. It didn't matter if there were two slashes.

If you check the error logs, the reason is listed in a single line:

AH00124: Request exceeded the limit of 10 internal redirects
         due to probable configuration error.

# Rule automatically added by the subdirectory multisite
RewriteRule ^([ _0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

The part inside the parentheses at the beginning doesn't account for dots. Because of this, a.b/c.php fails to isolate the first segment, and the second parenthesis captures the entire path. The result is rewriting the request to itself. Since [L] tells Apache to restart the rules from the beginning, after ten loops, Apache gives up and returns a 500 error. This rule isn't something we wrote; it's something that comes along when you enable multisite.

Each request takes about 0.016 seconds. It's not slow. The issue is that something that should just result in a 404 error takes ten internal redirects and ends up as a 500 error, and it's incredibly easy to set up. In the four weeks of logs we've kept, there have been 19 requests starting with // that received a 500 error, 36, 0, and 25, and this week alone, we've already hit 27 in just two days.

How I Tracked It

The logs show that three domains write to a single file. Since there wasn't a vhost section, I separated the sites using response codes. A 403 means our rules blocked it; a 404 means the file belongs to another site; and a 301 means it's a redirect to another site. This count only includes the 403s.

# Step 1: Extract only the relevant lines from the 1.7GB of four files to create a smaller log file
grep -a 'xmlrpc' /var/log/httpd/access_log-20261108 > x.log

# Step 2: Aggregate by IP, keeping only 403 responses
awk 'BEGIN{FS="""}
     {split($3,s," "); if (s[1]!="403") next;
      split($1,a," "); IP[a[1]]++; tot++}
     END{for (i in IP) {n++; if (IP[i]==1) one++}
         printf "%d incidents %d IPs 1 time %.1f%%n", tot, n, 100*one/n}' x.log

Since the archived logs aren't growing anymore, running the script multiple times will give you the same result. Because I had issues with fluctuating numbers when tallying the current logs last time, I'm using only the most recent log from the five available windows, with all others being archives.

What I Can't Say

The average of 367 incidents over the seven days before the block came from archived logs. Since I only kept four log files, I can't recount them. I'm relying on notes I made back in October, and I have no way to verify that number right now.

Also, "fewer requests" doesn't mean "fewer attacks." What decreased was the number of times they reached our server; I have no idea how many they sent out there. For the numbers that stayed steady over the four weeks, it's more accurate to say the block has entered a "new equilibrium" rather than saying "the block maintained its effectiveness." The difference between 19.4 over two weeks and 47.0 over four weeks is likely due to external factors unrelated to the block.

Frequently Asked Questions

Since a month has passed, doesn't this mean the block was successful?

From a request volume standpoint, yes. The daily count dropped from 367 to 44, and it hasn't increased over the past month. However, the number of IPs hitting us hasn't decreased; new IPs show up every week. What has decreased is the frequency of requests coming from a single IP. So, it's more accurate to say that "the conversation is cut off at the first line and doesn't get longer," rather than "the attack has stopped."

What's the point of getting a 403 error when it's hitting us 71 times per minute?

Those 71 requests were mostly ineffective. The 403 error works by telling the recipient—the system that reads the response and decides on the next request—that "this is the end." It doesn't get delivered to the side that just blasts requests without reading the response. Those IPs were only hitting one spot across four weeks, making up 71 out of the total 1,211 requests. The remaining 1,140 requests got through.

Why is it a problem if a path with a dot returns a 500 error?

If you ask for a file that doesn't exist, you should get a 404. When you get a 500 error, it means we had to run internal rewriting ten times just to re-process the rules, effectively doing ten tasks for a single request. The cost to generate an error externally is just a few characters. What concerns us more is that the block we put in place by name didn't work on that specific path. Right now, it's only being stopped coincidentally because the file is missing from that location.