Skip to content

15. Port Scanning and the Hostile Internet

“Nothing on the internet is hidden. Most of it is just unannounced.”

You rent a fresh VPS on a quiet Tuesday. The control panel says running. You SSH in, feel the small pleasure of a clean machine with nothing on it, and do the habit you picked up from your last few deployments: you look at the auth log. Nothing has happened yet. You have not installed nginx. You have not even settled on a hostname you like.

Come back five minutes later and look again. The log has company.

Nov 20 09:14:02 lab sshd[1822]: Invalid user admin from 192.0.2.44 port 51422
Nov 20 09:14:03 lab sshd[1822]: Connection closed by invalid user admin 192.0.2.44 port 51422 [preauth]
Nov 20 09:14:31 lab sshd[1830]: Invalid user oracle from 198.51.100.91 port 40118
Nov 20 09:14:33 lab sshd[1831]: Failed password for root from 198.51.100.91 port 40118 ssh2
Nov 20 09:14:40 lab sshd[1840]: Invalid user ubuntu from 203.0.113.207 port 58812
Nov 20 09:15:12 lab sshd[1855]: Invalid user postgres from 192.0.2.160 port 33990

That is a composite, with documentation addresses standing in for the real ones. It is also a very ordinary morning for any public machine.

Read those lines the way a receptionist would. Someone tried admin. Someone tried oracle, the default account on some database installs. Someone tried ubuntu, the default user on many cloud images, and postgres, the default superuser of a database you have not installed yet. Someone tried root with a password. Four different addresses in under two minutes, and not one of them knew your name, your project, or that this box was new an hour ago. They went down a list, and your machine was on the list.

This is weather. Doorknob-rattlers are weather, not personal. They rattle your door because it sits on the row, not because they have a grudge against you. You cannot stop the weather. You can decide what it is worth to them.

Look closely at what they did not get. The lines say Failed password and Connection closed by invalid user. Nobody got a shell. Whether a knock turns into a shell depends on choices you can make in an afternoon, several of which Chapter 6 covered: keys instead of passwords, no direct root login, and a short list of who may log in at all. The knocking is weather. Getting in is a decision you make on purpose.

Now the city. Think of the internet as the street outside your building. Most people walking past are going somewhere else. Some are looking for one particular office. And a few, the ones this chapter is about, walk the whole row rattling every handle, because a handle costs nothing to rattle and sometimes a door is open. The habit of trying every door in a row has a name, and the name is scanning. By the end of this chapter you will be able to read every knock in your logs and tell the ones that are weather from the ones that deserve a second look.

Chapter 14 gave you the guard with the clipboard, and it left you with three answers a door can give: open, closed, and filtered. You met them as the difference between a refused connection and a timeout. A scanner is a patient client that asks that question on purpose, many times, for many doors. Everything else in this chapter is a longer version of that one sentence.

Before a scanner can tell you anything about a door, it has to knock on it. Every knock is a packet, and every answer is another packet. Chapter 2 gave you the packet and Chapter 3 gave you the numbered doors, so the only new idea here is the question a scanner asks: for this address and this port, what happens when I send a packet?

The answers are the three you met in Chapter 14. Something replies that it is listening, which means open. Something replies that nobody is listening, which means closed. Or nothing replies at all, because a firewall quietly dropped the packet, which means filtered. Everything a scanner does is a cleverer way of asking that one question: faster, more quietly, or with more detail about what sits behind the door.

The most honest way to ask is the connect scan. The scanner asks the operating system to do the ordinary thing and open a full TCP connection to the port. The kernel performs the three-way handshake, SYN and then SYN/ACK and then ACK. If that succeeds, the scanner closes the connection straight away. A connect scan needs no special privilege, so anyone can run one. It also leaves the clearest trace. A completed connection is exactly what a real client leaves behind, and any application that logs connections will log it.

The SYN scan is often called the half-open scan, because it never finishes the handshake. The scanner builds the first packet of the handshake itself, a bare SYN, and sends it to the port. Then it reads the reply.

If the reply is a SYN/ACK, the port is open. The scanner does not finish the handshake with an ACK. It sends a RST instead, which tears the half-built connection down before any application gets to accept it. If the reply is a RST, the port is closed. If there is no reply at all, the port is filtered. A live host that was not filtering should have answered, so silence is the firewall’s signature.

Figure 15.1 shows the open case, which is the one people remember.

A SYN scan against an open portTime runs down the page. The scanner sends a SYN to port 443. The open port replies with SYN/ACK. The scanner replies with RST instead of ACK, so the handshake never completes.ScannerTarget port 4431. SYN, port 4432. SYN/ACK: the door is open3. RST: hang up, no ACK sentThe handshake never completes, so the application never sees a connection.
Figure 15.1. A SYN scan asks with SYN, reads the answer, and hangs up before the handshake completes.

Crafting those packets by hand needs raw-packet access, which is why serious scanners want to run as root. The SYN scan is faster than a connect scan, and it used to be a favourite because most application logs never saw it. A firewall or an intrusion detector often does see it, which is a good reason to have one.

A port number tells you very little on its own. Port 8080 might be a web app, a debugging tool someone forgot to switch off, or a database speaking its own language. Service detection is the step where the scanner stops guessing from numbers and starts asking.

Many services talk first. An SSH server announces its version before you type a thing, and a mail server prints a greeting. For the quiet ones, the scanner sends a short probe, a few bytes shaped like an HTTP request or a Redis command, and watches what comes back. The returned text is the banner. The scanner matches the banner against a long list of signatures and reports its best guess, with a confidence level.

Service detection sends a probe and reads the bannerA scanner connects to port 22 and gets an SSH banner back, then sends an HTTP-style request to port 80 and gets a Server header back. Both answers are matched against known signatures.ScannerPort 22 SSHannounces itselfPort 80 webanswers a requestprobe: connectprobe: GET / HTTP/1.0Banner and Server header become matches, and each match is a guess.
Figure 15.2. A banner is what a service says when asked. The match against known patterns is only a guess.

Here is the shape of a result, annotated. The wording changes from version to version, so treat it as illustrative.

PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 9.6p1 Ubuntu <- the banner, read aloud
80/tcp open http nginx 1.24.0 (Ubuntu) <- from the Server header
443/tcp filtered https <- the probe was dropped
3306/tcp closed mysql <- a reset came back

Those three states are the Chapter 14 vocabulary. open means something accepted the connection. closed means a reset came back: the host is there and nothing listens. filtered means nothing came back at all, which usually means a firewall dropped the probe and the scanner gave up. Silence is the timeout. Once you read scan output that way, it looks like a list of doors and the guards in front of them.

TCP has a handshake, so a scanner gets a clear yes or no. UDP has no handshake and no promises. Send a packet to a closed UDP port and the host may answer with an ICMP “port unreachable” message. But hosts rate-limit those messages, and an open UDP service that does not understand your packet often stays quiet. Silence now means open|filtered, which is the scanner admitting it does not know. That is honest, and a little annoying.

The workaround is to ask the right question. A DNS query to port 53 gets a real answer from a DNS server, and an SNMP request to port 161 gets a reply from a device that speaks SNMP. Protocol-specific probes make UDP results useful, and they are also why UDP scans are slow. Most scans check the top UDP ports, not all 65,535 of them.

Every operating system’s network stack has small personal habits: the initial TTL on its packets, its TCP window sizes, which options it includes, and how it reacts to odd flag combinations. nmap sends a set of unusual probes and compares the pattern of replies against a database of known stacks. The result is a guess with a few candidates, not an ID card.

Why bother? An attacker wants to know whether to aim at Ubuntu or at a router with old firmware. You want to notice when a box you believe is an Ubuntu VPS answers like a NAS. If the answer surprises you, something is running that you did not install.

Your server is not the only thing knocking on doors. Some tools exist to sweep the whole internet, and some companies keep the answers so that anyone can search them.

Sweepers that cover the whole address space

Section titled “Sweepers that cover the whole address space”

nmap is a careful instrument. It scans a few targets well and explains itself as it goes. masscan and ZMap are built for the other job. They walk through IPv4, roughly 4.3 billion addresses, and send a small probe to each chosen port as fast as the network allows. The ZMap authors reported that one port across the whole space could be covered in under an hour from a well-connected machine, if memory serves. Treat that as the shape of the thing, not a stopwatch reading. The point is that scanning the entire internet stopped being a big-lab job a while ago.

Who uses them? Researchers measure how many hosts still speak a broken protocol. Security teams check their own address ranges. Attackers use the same tools to find the few boxes with a door left open. The tool does not care which one it is, and that is exactly why you should not assume nobody is looking.

Shodan and Censys do the sweep once, then keep what they found. They store banners, certificates and headers for every address that replied, and they let anyone search the result. In effect you can ask for every server answering on a given port in a given country. Their indexes have held billions of records for years. The exact numbers move faster than any book can track, so I will not quote them.

This changes how you think about a fresh VPS. You do not need to be found by a scanner. You only need to be listed. A test box that ran for a weekend with a port open can still show up in a search result months later, with its banner and its certificate, long after you turned it off.

Sweeps feed a public indexA sweeper probes every address on the open internet. Replies flow into a search index that strangers can query, and that index includes the banner of your server.Sweepermasscan or ZMapThe open internetevery address, every portSearch indexbanners and headersYour server is one of the addresses in that cloud. Its banner can end up in the index.
Figure 15.3. Sweepers write down what answers, and the index keeps it for anyone who asks.

Our lab VPS will be listed within days of getting a public address and an open port. That is fine, because it is a throwaway. It is also the reason the lab keeps its open ports to a minimum.

Here is the part that surprises people. The bots are not reading your site. They are asking your server a short list of questions, and most of the questions are the same for everyone. The list changes slowly, because it is built from old mistakes that never went away.

  • /.env is where many web frameworks keep their secrets: database passwords, API keys, the Razorpay secret you swore you would never commit. If that file sits in the web root and the server serves it as plain text, the bot walks away with all of it.
  • /.git/config catches people who deployed by copying a folder that still had a hidden .git directory inside. Anyone who can download that directory can often rebuild your source code, history and all.
  • /wp-login.php and /phpmyadmin are the doors to WordPress and a database admin tool. You may run neither. The bot does not check. It rattles the handle anyway.
  • /vendor/phpunit points at a testing library that, in one well-known old version, could be tricked into running commands. Test tools left on a production server are an open invitation.
  • /actuator/health belongs to Spring Boot. On its own it is harmless. Bots check it because some apps expose far more under the same path.

Then come the services that were never meant for the public internet. Redis on 6379, MongoDB on 27017, Elasticsearch on 9200, and the Docker API on 2375. Each was designed to live inside a building and trust whoever walks in. The bot does not know you meant “inside”. It only sees an open door.

Finally, some of what arrives is not a web request at all. A scanner guessing that your server speaks TLS may send TLS bytes to port 80, the plain HTTP port. Nginx logs those bytes as an ugly run of backslash escapes. That is a tell. Someone is probing with a tool, not a browser.

Nginx writes an access log, one line per request. Each line answers four questions: who asked, when, what they asked for, and what you answered. Here is a short excerpt from a lab box, with the addresses changed to documentation ranges.

192.0.2.44 - - [14/Nov/2026:03:12:08 +0000] "GET /.env HTTP/1.1" 404 153 "-" "Go-http-client/1.1"
192.0.2.44 - - [14/Nov/2026:03:12:08 +0000] "GET /.git/config HTTP/1.1" 404 153 "-" "Go-http-client/1.1"
198.51.100.7 - - [14/Nov/2026:03:12:19 +0000] "GET /wp-login.php HTTP/1.1" 404 153 "-" "Mozilla/5.0 zgrab/0.x"
198.51.100.7 - - [14/Nov/2026:03:12:21 +0000] "GET /actuator/health HTTP/1.1" 404 153 "-" "Mozilla/5.0 zgrab/0.x"
203.0.113.99 - - [14/Nov/2026:03:13:02 +0000] "\x16\x03\x01\x00\xF4\x01\x00\x00\xF0\x03\x03" 400 157 "-" "-"

Read the first line slowly. The address is who, the bracketed time is when, and the quoted request is what they wanted. The 404 is your answer: no such file. The last quoted field is the user agent, which is the client’s own claim about what it is. A Go client asking for /.env is a script, and a script can call itself anything.

The fifth line is the one to notice. Those bytes are the opening of a TLS handshake, sent to the plain HTTP port. No browser does that. Nginx gave up and returned a 400, and the dashes mean the client sent no user agent at all.

One bot visit as a sequenceTime runs from top to bottom. A scanner asks nginx for /.env and then for /.git/config. Nginx answers 404 both times. Nothing is forwarded to the app, which shows a dead end.ScannernginxYour appGET /.env404 Not FoundGET /.git/config404 Not Foundno request reaches the app
Figure 15.4. One bot visit: the scanner asks, nginx says no, and your app never wakes up.

The useful question is not “am I being attacked”. Everyone is. The useful question is which of your doors the world sees, and what each door says back. A stream of 404s means your server is saying no, correctly, every time. A single 200 on /.env would be the sentence you never want to read.

Your own VPS can tell you what is listening, but not what the world can reach. From inside the building you see the doors. You do not see the guard at the street, or the rule your provider put in front of the machine. The only honest test is to knock from outside.

A phone hotspot is the cheapest outside you own. Your phone joins a mobile carrier’s network, which in India very often puts you behind carrier-grade NAT, the gated township from Chapter 14. The address your probe leaves from is not yours, and it is not tied to your home. That is close to a stranger’s view. Point the probe at your lab’s public address and nothing else, and you are looking at what the street sees.

This is the part people skip, so let me be direct. Scanning is not hacking, but a scan is the first half of one, and the other side cannot tell which half they are getting.

Why so strict? Many countries treat unauthorised probing as an offence even when nothing breaks. In India, the Information Technology Act of 2000 covers unauthorised access to computer systems. The exact reach is a question for a lawyer, so take this as the gist, not as advice. Your hosting provider’s terms are a second rulebook, and many forbid outbound scanning outright. If your lab starts knocking on other people’s doors, expect an abuse complaint, and possibly a suspended VPS.

There is one place built for practice. The nmap project runs scanme.nmap.org so that people can learn on something that has agreed to be scanned. Keep it light: a few ports, a handful of runs. Do not sweep it.

Here is the rule of thumb I use. If you would have to explain the scan to the owner, you need the owner’s yes first. The bots do not ask, and that is exactly why you do not get to skip asking.

Each of these is a widely told story. Retelling polishes the details, so I have hedged the numbers wherever memory is fuzzy.

Around the turn of 2016 into 2017, a wave of attackers went looking for MongoDB servers on the default port with no password. Old releases often listened on every interface, so anyone on the internet could walk in. The attackers copied what they could, dropped the databases, and left a note asking for bitcoin. Tens of thousands of instances were hit.

Notice what was not clever about it. Nobody broke in with a trick. The database was open. The fixes that mattered were binding to localhost or a private address, and turning on authentication. Recent versions default more safely, but a safe default you switch back off is not safe.

This one is a composite of many incidents rather than a single event. Elasticsearch listens on port 9200, and in older setups authentication was not on by default. Researchers and attackers kept finding indexes full of logs, customer records and chat transcripts on the open internet. Some were abandoned test clusters. Others were production stores, and the owners often learned about it from a stranger.

The lesson is about forgotten things. Test data, logs and “temporary” clusters are the ones nobody remembers to close.

Redis, port 6379, often runs with no password. A widely told trick was to use Redis’s own configuration commands to change where it saves its data file, then write something that looks like an SSH key into a user’s authorised keys, or a cron entry that downloads a script. Plenty of these ended with a cryptocurrency miner quietly eating the CPU. The machine slows down, the bill climbs, and you wonder why.

The Docker daemon can listen on a TCP port, and the unencrypted choice is 2375. Without TLS and client certificates, anyone who can reach it can start containers. A container that mounts the host’s root filesystem is a root shell with extra steps. Attackers used this to start miners across many hosts.

In 2016, the Mirai botnet grew out of cameras, routers and recorders that shipped with a telnet service and well-known default passwords. Infected devices scanned for more devices with the same defaults, and the botnet was then turned on large targets with floods of traffic. One of those targets was a major DNS provider, and for hours a long list of popular sites was hard to reach. Here the scanner was also the weapon.

A default password is a scanner’s favourite word.

The lab: scan your own door from the outside

Section titled “The lab: scan your own door from the outside”

Goal: see your lab VPS the way a stranger sees it, then check that what the stranger sees matches what you think is running. The only target is your own lab address, and the probe leaves from your phone’s hotspot, not from your home or from the VPS itself.

Conceptual steps:

  1. Switch your laptop to the phone’s hotspot, so the probe leaves from a carrier network. Remember the gated township from Chapter 14: that address is not yours, which is what you want.
  2. Scan the most common ports first, for a quick picture. Then scan every TCP port once, slowly, because the surprises tend to hide up high. Ask for service detection only on the ports that came back open.
  3. On the VPS itself, list the sockets that are listening, with the program that owns each one. Lay the two lists side by side.
  4. Read the auth log and the nginx access log from the last day. Count unique source addresses per day, and list the five paths the bots asked for most often.

How you’ll know it worked:

  • You can name every port the outside saw open, and the process that owns it.
  • You can explain at least one port that is listening inside but invisible from outside. Was it bound to a private address, or stopped by a firewall rule? Chapter 14’s refused-versus-timeout vocabulary should tell you which.
  • You have two numbers you did not have before: unique attacker addresses per day, and the bot paths at the top of the list.
  • You scanned nothing except your own lab address, and you can say why that is the only one you were allowed to touch.

Do not spend the afternoon closing the bots’ doors. You cannot. Spend it on your own, and let the weather keep rattling the handles.

Open, closed and filtered ports seen from outsideA probe on the left sends one knock to three doors. The open door answers with SYN and ACK. The closed door answers with a refusal at once. The filtered door never answers, because a guard dropped the packet.your phonethe probe22openSYN/ACK answers. Your probe sends RST and leaves.80closedRST answers at once. Refused, and cheap for both.443filteredSilence until the probe gives up. A guard ate it.
Figure 15.5. Three answers a scanner can get from a port, and what each one tells the person asking.

Look at what you can do now that you could not at the start of this chapter. You can read an auth log and tell a doorknob rattler from a targeted attempt, and you know that the rattlers are weather, not a verdict on you. You know that a closed port answers quickly and a filtered port goes silent, and that the difference lives on the path between the probe and the door, not inside the program behind it. You know that the whole address space gets swept, and that anything you expose will be found, usually by someone who is not curious at all.

The one idea to carry out of here: exposure is a choice you make per port, and you can measure it from outside. Every door you open is a door the sweepers will try. Every door you close, or guard, is a door they cannot even see. Nothing in this chapter is a reason to panic. It is a reason to stop listening on public addresses by accident.

You started with a fresh VPS and a stranger knocking within minutes of boot. You now know who the knockers are, what they want, and how to look at your own door the way they do. That is real progress, and it is the kind that keeps a 2 a.m. call quiet. Next, Chapter 16 shows the other approach: private doors that the sweepers never see at all.

1. What does a SYN scan send first, and what does an open port answer with?

It sends a SYN packet, as if it were starting a normal handshake. An open port answers with SYN and ACK. The scanner then sends RST and leaves, so the full connection never forms.

2. A port answers RST straight away. Is that open, closed or filtered, and why does it matter?

Closed. Something is there and it refused, which is the same refused-versus-timeout vocabulary from Chapter 14. Filtered means silence, which usually means a firewall dropped the packet.

3. Why are UDP scans so much slower and less certain than TCP scans?

UDP has no handshake, so an open port often says nothing at all. A closed port may send back an ICMP unreachable message, but that reply is often rate-limited, so the scanner cannot tell silence from open from filtered without guessing and retrying.

4. What is the difference between a banner and a fingerprint?

A banner is what a service volunteers when asked, such as a version string. A fingerprint is a guess built from many small quirks of a network stack or a service’s replies, and it is a probability, not a fact.

5. A bot requests /.env on your server, and your app returns a 404. Did the bot learn anything useful?

Almost nothing. A 404 means the path is not there, and the bot will try the next name on its list. The worry is only when a real file comes back. Check your nginx logs, and make sure secrets are not sitting inside the web root in the first place.

6. Why is it not enough to say “I only scan my own servers” when you run a scan from home?

Because the scan still touches addresses, and the law and provider terms care about whose addresses they are, not your intentions. Scan only what you own or have written permission to scan. Practice on scanme.nmap.org, which exists for that purpose, and be careful with the rate and the scope.

Warm-up 1. Read one line of noise. Take this auth log line and say what it tells you and what it does not: Invalid user oracle from 198.51.100.44 port 51812. Then say what you would check next on your own server.

Answer

It tells you that someone tried a username, oracle, that does not exist on your system, from one source address. It does not tell you that the attacker is targeting you personally, because the same name is in every bot’s list. Next, check whether password logins are disabled and whether fail2ban or your firewall is counting these attempts. Chapter 6 covers the keys that make this noise harmless.

Warm-up 2. Closed or filtered? A scan of port 8080 comes back after about four seconds with no reply at all. A scan of port 8081 comes back at once with a refusal. Which port is filtered, which is closed, and what does each one suggest about the path?

Answer

Port 8080 is filtered: silence until the scanner gave up, which points at a firewall rule that drops packets. Port 8081 is closed: the refusal came back at once, so something is reachable and says no, which points at a host with nothing listening on that port. Both are “not open”, but they tell you different things about who is in the way.

Warm-up 3. Why the sweepers are fast. Explain in three sentences why a tool like masscan can cover a huge address range in a short time, and why you should not use one on someone else’s network.

Answer

It sends very small probes without waiting for each reply, so thousands of packets are in flight at once, and it records only what comes back. The same speed is what makes it rude: it hits many addresses in a short burst, which looks like an attack to the people who own them, and it can breach the law or provider terms even when nobody is harmed. Scan only what you own or have written permission to scan.

Lab 4. The outside picture. From your phone’s hotspot, scan your lab VPS (203.0.113.10) for the 100 most common TCP ports, then all TCP ports, then service detection on whatever came back open. Write down every open port and the service you think is behind it.

Hint

Run these from the laptop while it is on the hotspot. The connect scan needs no root.

Terminal window
nmap -sT --top-ports 100 203.0.113.10
nmap -sT -p- -T3 203.0.113.10
nmap -sV -p 22,80,443 203.0.113.10

Replace the port list with whatever the full scan found open. Stay on 203.0.113.10 and nothing else.

Model answer

Expect port 22 (SSH) and, if you set up Chapter 7’s app behind a proxy, 80 and 443. A surprise on a high port is the lesson: either something you forgot, or a service bound to all addresses when it should have been bound to localhost. Note the exact version strings nmap reports. They are guesses, so check them on the server before you believe them.

Lab 5. Inside versus outside. On the VPS, list every listening socket and the program that owns it. Put that list beside the outside scan from exercise 4. Explain each difference: a port listening inside but invisible outside, and any port seen outside that you did not expect.

Hint

On the VPS, as the ops user:

Terminal window
sudo ss -tlnp

Look at the local address column. A listener on 127.0.0.1 is reachable only from the machine itself. A listener on 0.0.0.0 or [::] is reachable from anywhere the firewall allows. Chapter 14’s refused-versus-timeout vocabulary explains what the outside saw.

Model answer

A service bound to 127.0.0.1 will be listening inside and invisible outside, which is the design you want for a database or an admin page. A port seen outside but absent from ss is a red flag that deserves an immediate look, because it may mean a container or a forwarding rule you did not expect. Write the difference in one sentence per port.

Lab 6. Count the knockers. Using the auth log and the nginx access log from the last day, count the unique attacker addresses per day, and list the five request paths the bots asked for most often. Compare the top paths with the hit list from this chapter.

Hint

The first command counts unique addresses per day in the auth log. The second lists the top paths in the nginx log.

Terminal window
sudo grep -E 'Failed password|Invalid user' /var/log/auth.log \
| awk '{d=$1" "$2; for(i=1;i<=NF;i++) if($i ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/){print d, $i; break}}' \
| sort -u | awk '{print $1, $2}' | uniq -c
sudo awk '{print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -5

If your auth log has been rotated, look in /var/log/auth.log.1 as well.

Model answer

Expect a few dozen unique addresses a day on a fresh box, and more on a box that has been up for weeks. The top paths should include /.env, /.git/config, /wp-login.php or /phpmyadmin, which your app does not serve. The point is not the exact count. It is that the count is never zero, and that your answers to these requests are 404s or 403s rather than files.

Staff 7. Design the outside view. Your manager asks whether it is safe to leave the Postgres port open to the internet so an analytics colleague in another city can connect. Write a short answer. Say what you would do instead, and what a scan from outside would show before and after your change.

Model answer

No. Close the database port to the internet and give the colleague a private route instead: a tailnet (Chapter 16) or an SSH tunnel through a bastion that already uses keys. Before the change, an outside scan shows the database port open, and every bot that scans it can try its password list. After the change, the same scan should show it filtered or closed, and ss -tlnp should show the database listening on 127.0.0.1 or a private address only. Check both views, because an unsaved firewall rule is the usual way this goes wrong. Write the decision down, so the next person knows why the port is closed.

Staff 8. The wave you cannot ignore. Your nginx access log shows tens of thousands of requests in an hour, from many addresses, all asking for /wp-login.php. Your app is not WordPress, and none of those requests reach it. Argue for or against a rate limit or a block at the edge, and say what you would measure first.

Model answer

Argue for a cheap block, not a clever one. A 404 on a path you never serve costs very little. The real risk is the traffic that gets past the proxy and reaches your app. So measure first: how many requests reach the app during the wave, how response times changed, and whether any of the addresses also appear in your auth log. If the app is healthy, a rate limit in nginx on the application routes, plus a fast refusal for the known bot paths, is enough. If the box is struggling, move the blocking out to the doorman (Chapter 17) so the noise never reaches the building. Note what you are not doing: you are not chasing each attacker. Doorknob-rattlers are weather. You are only keeping the lobby clear.

Book 2 of a series. Book 1: The Glue.