GoAdmio

posttop

Report IPs sending the most POST requests and block POST floods

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/posttop finds the IP addresses that sent the most POST requests to the server. Login forms, contact forms, and APIs receive POST requests, so a flood of them is a common sign of brute-force, spam, or application-layer attacks. The command:

No setup is needed. GoAdmio's default cron jobs already run posttop block every hour.


Quick start

# Top POST senders in the last 24 hours. Nothing is blocked.
/go/posttop

# Show the last hour and block offenders (what cron runs)
/go/posttop block

Syntax

/go/posttop [block | <seconds>]
Form Behavior
/go/posttop Report for the last 24 hours. Nothing is blocked.
/go/posttop <seconds> Report for that many seconds. Nothing is blocked.
/go/posttop block Report for the last hour, then block offenders and send notifications. This is what cron runs.

The command has no -- options. Only the first argument is read.

An unrecognized argument is treated like no argument. There is no "unknown parameter" error. A typo such as /go/posttop blok runs the 24-hour report and blocks nothing. Words such as hour, day, and week are not recognized here (unlike iptop), so each of them also gives the 24-hour report.


Options

Item Required Default Notes
block (argument) No Report only Turns on blocking and notifications. Uses a one-hour window.
<seconds> (argument) No 86400 Length of the report window in seconds. Digits only. Never blocks.
/var/go/etc/posttop (file) No 300 A whole number: the number of POST requests at which an IP is blocked. See Threshold.

Output

Outcome What you get
Report A table of up to 20 IPs with visits, country, city, and company.
block mode, IPs blocked The same table, then an email and a WhatsApp message listing the blocked IPs.
block mode, nothing over the threshold The table only. No message is sent.
block mode, another instance running Instance (<name>) already running. and exit code 1.

Report

The columns are aligned with column. This sample is illustrative.

IP            VISITS  COUNTRY  CITY     COMPANY
--            ------  -------  ----     -------
203.0.113.7   1840    US       Chicago  Example Hosting LLC
198.51.100.22 95      DE       Berlin   Example Telecom

The server's own IPv4 address, its IPv6 address, and 127.0.0.1 are never listed.

Notification

Sent only in block mode, and only if at least one IP was blocked in that run.

Channel Subject or title
Email, through sendmail Automated Block: Excessive POST Requests Detected (<N> IPs)
WhatsApp, through sendwhatsapp *Automated Block: Excessive POST Requests Detected (<N> IPs)*

The body explains what happened, then lists one line per blocked IP:

- POST Traffic 203.0.113.7 (1840 Visits / Hour) - Country: US, Company: Example Hosting LLC.

The email ends by saying that legitimate API clients may need whitelisting. See Whitelist before relying on that.

[!WARNING] Blocking is automatic and unattended. Busy sites, APIs, webhooks, and payment or chat integrations can send hundreds of legitimate POST requests per hour from one IP. Check whether your own services reach the threshold before relying on the default of 300, and read the notification emails after any change.


Examples

# Who sent the most POST requests in the last 5 minutes?
/go/posttop 300
# Last 7 days (604800 seconds)
/go/posttop 604800
# Report and block, as cron does every hour
/go/posttop block
# Block at 1000 POST requests per hour instead of 300
echo 1000 | sudo tee /var/go/etc/posttop
# Go back to the default threshold
sudo rm /var/go/etc/posttop
# Read the history of runs and their arguments
sudo tail /var/log/go/posttop.log

Troubleshooting

Symptom Likely cause Fix
Instance (<name>) already running. A block run started less than 60 seconds ago. The lock is shared with other commands. Wait, then run again. A lock older than 60 seconds is ignored.
[: : integer expression expected appears after the table The script never sets its blocked-IP counter, so the final check fails when nothing was blocked. Harmless. The table was still printed.
Nothing was blocked Ran without block, no IP reached the threshold, or the IP was exempt. Run /go/posttop block and check the Threshold and exemptions.
/go/posttop hour shows 24 hours hour, day, and week aren't recognized. Pass seconds instead, for example /go/posttop 3600.
An IP over the threshold wasn't blocked A file /var/log/go/block/<IP>.* already exists, or the company is exempt. See Already-blocked IPs and exempt visitors.
A legitimate client was blocked It sent many POST requests, such as an API or webhook caller. Run unblock for that IP and raise the threshold.
A whitelisted IP was blocked This command doesn't read the whitelist. See Whitelist.
No notification arrived No IP was blocked in that run, or email and WhatsApp aren't configured. Check the table for blocks, then test sendmail and sendwhatsapp.
Country or city is blank in cron output Cron runs use the whois record, which may lack those fields. Run the command in a terminal for fuller lookups.
The threshold change had no effect The file contains something other than digits. Put only a whole number in /var/go/etc/posttop. Anything else falls back to 300.
The server's own IP shows in the table The lookup of the server's public IP failed. Check that the server can reach checkip.amazonaws.com and icanhazip.com.

Details

Threshold

Condition Limit used
/var/go/etc/posttop doesn't exist 300
It exists and contains only digits That number
It exists but isn't a whole number 300

An IP is blocked when its POST count is greater than or equal to the limit. In block mode the count covers the last hour.

What counts as a visit

Check Rule
Time window Judged by the timestamp in each log line.
Matching Log lines containing the text |POST, whatever the response code.
Visitor IP The forwarded client IP if the log has one. Otherwise the connecting IP.
Counting Case-insensitive per IP, highest first.
Rows kept The top 20.

Whitelist

This command does not read /etc/white. Whitelisted IPs are counted and shown like any other. Whether block skips them isn't visible in this script, so check that before relying on the email's advice to whitelist legitimate clients. iptop does filter /etc/white before counting.

Exempt visitors

An IP is never blocked if the company name found for it contains:

Text Case-sensitive
google No
bing Yes (lowercase)
cloudflare Yes (lowercase)

Exempt visitors still appear in the table. Because the bing and cloudflare checks are case-sensitive, a name written as Cloudflare, Inc. would not match them.

Already-blocked IPs

An IP is skipped if any file named /var/log/go/block/<IP>.* exists. Such a file is the record left by block. An IP that already has one is not blocked again and is not included in the notification. New blocks are recorded with the reason post.

Lookups

Data Terminal run Cron or other non-terminal run
Company whois record whois record
Country Geo lookup country: field of the whois record
City Geo lookup city: field of the whois record

Locking

Only block mode takes a lock, so report-only runs can overlap freely.

Item Value
Lock file /usr/local/goadmio/lock/block.lock
Contents The name of the command holding the lock
Considered stale after 60 seconds without an update
Refreshed Once per IP processed, so a long run stays locked
Released On exit, including Ctrl+C

404top and iptop use the same lock file. If one of their block runs overlaps with posttop block, the second command exits with Instance (<name>) already running.

What it does

In short: take the lock if blocking, read the log, rank the visitors, look each one up, block those over the limit, print the table, then notify.

flowchart TD
    A["posttop [block]"] --> B{"First argument is block?"}
    B -- "Yes" --> L{"Lock under 60 s old?"}
    L -- "Yes" --> X["Instance already running, exit 1"]
    L -- "No" --> C["Take the lock"]
    B -- "No" --> D
    C --> D["Pick window and read threshold, default 300"]
    D --> E["Find top 20 IPs by POST requests in the window"]
    E --> F["For each IP: skip own and local IPs, look up whois"]
    F --> G{"block mode, over limit, not exempt, not already blocked?"}
    G -- "Yes" --> H["/go/block IP post country company"]
    G -- "No" --> I["Add row to the table"]
    H --> I
    I --> J["Print table"]
    J --> K{"Any IPs blocked?"}
    K -- "Yes" --> M["Send email and WhatsApp"]
    K -- "No" --> N["Release the lock"]
    M --> N
  1. Appends the date and arguments to /var/log/go/posttop.log.
  2. Loads shared functions from /go/function and the access log path.
  3. In block mode, exits with an error if block.lock is under 60 seconds old. Otherwise writes the lock.
  4. Picks the time window: the given number of seconds, one hour for block, otherwise 24 hours.
  5. Reads the threshold from /var/go/etc/posttop, falling back to 300.
  6. Finds the server's public IPv4 and IPv6 addresses.
  7. Counts POST log lines per visitor IP within the window and keeps the top 20.
  8. Skips the server's own IPs and 127.0.0.1, then looks up whois, company, country, and city for each remaining IP.
  9. In block mode, for each IP at or above the limit that isn't exempt and has no record in /var/log/go/block/, runs /go/block <IP> post <country> <company> and adds it to the notification list.
  10. Adds each IP to the output table.
  11. Prints the table.
  12. If any IP was blocked, sends the email and the WhatsApp message.
  13. Removes the lock file.

See also

Command Description
iptop Report the busiest IPs by request count and block floods and bot networks
404top Report IPs causing the most 404 errors and block scanners and probes
block Block an IP address on a GoAdmio server
unblock Unblock an IP address on a GoAdmio server
white Add an IP to the whitelist
sasltop Report SASL LOGIN authentication failures and block persistent sources
sshtop Report top SSH brute-force sources and optionally block them
ddos Track and block DDoS attack IPs in GoAdmio
usertop Check recent visitors per domain
cron Set up main cron jobs in GoAdmio