Enumerating HTTP and SSH
Enumeration is the step after the scan: for each identified service, ask it everything it will tell an unauthenticated (or test-account) client, using the protocol as designed. For HTTP that means titles, methods, headers, default and forgotten paths. For SSH it means the server's algorithms and which authentication methods it accepts. Enumeration produces the concrete facts that findings are built from. It is also where a tester's tools generate the most traffic per minute, so the noise is part of the lesson.
Web application testing proper (authentication, injection, access control) is the subject of Web Application Security; this lesson covers the infrastructure view of a web server that a network test needs.
HTTP: what to ask
| Question | How | Why it matters |
|---|---|---|
| What is it? | title, Server/X-Powered-By, default pages |
product, admin consoles, default installs |
| Which methods? | OPTIONS, or trying PUT/DELETE/TRACE on a test path |
PUT on a static server can mean file upload; TRACE is a historic cross-site tracing issue |
| Which paths exist? | robots.txt, sitemap.xml, /.well-known/, a wordlist of common paths |
backups, admin pages, .git/, old API versions |
| Directory listings? | request directories without an index | exposed files |
| Virtual hosts? | the same address with different Host: headers |
internal applications on a shared server |
| TLS? | certificate names, protocol versions (see safe validation) | names, weak configurations |
HTTP enumeration in the sandbox
The session serves a small directory on 127.0.0.1:8080 with Python's web server, including a forgotten backup/ folder. Nmap's scripts http-title, http-methods and http-enum ask the first three questions; curl then confirms one result by hand, and the web server's own log shows what the scripts cost.
mkdir -p www/backup
printf '<!doctype html><title>Lab intranet</title><p>hello</p>\n' > www/index.html
printf 'db_host=db01.lab.test\ndb_pass=lab-only-example\n' > www/backup/config.old
(cd www && exec python3 -m http.server 8080 --bind 127.0.0.1 >../http.log 2>&1) &
for i in $(seq 50); do curl -s -o /dev/null http://127.0.0.1:8080/ && break; sleep 0.1; done
: > http.log
out=$(nmap -sT -p 8080 --script http-title,http-methods,http-enum 127.0.0.1)
for key in '/tcp' 'http-title' 'Supported Methods' 'Possible backup'; do grep -F -- "$key" <<< "$out"; done
echo "== confirm by hand: one request"
curl -s http://127.0.0.1:8080/backup/ | grep -E '<title>|<li>'
kill %1
echo "requests the web server logged during the scan: $(wc -l < http.log)"8080/tcp open http-proxy
|_http-title: Lab intranet
|_ Supported Methods: GET HEAD
|_ /backup/: Possible backup
== confirm by hand: one request
<title>Directory listing for /backup/</title>
<li><a href="config.old">config.old</a></li>
requests the web server logged during the scan: 4434
Three facts and a cost:
- the title names the application (
Lab intranet); onlyGETandHEADare supported, so there is nothing to report about methods; http-enumfound/backup/from its list of common paths, and one manual request confirms a directory listing exposingconfig.old, a file with a database host and password. In a real test the confirmation stops at the listing: the tester records the file name and size and that it was readable, and does not use the credential (unless the RoE explicitly allows it);- the server logged thousands of requests in a few seconds, almost all of them for paths that don't exist. That is what path enumeration looks like to the defender.
How HTTP enumeration is detected
A burst of 404 responses from one source, requests for well-known sensitive paths (/.git/HEAD, /backup/, /phpmyadmin/, /server-status), scanner user agents and NSE's own User-Agent: Mozilla/5.0 (compatible; Nmap Scripting Engine; …) are standard WAF and SIEM detections. Rate-based rules ("more than 100 distinct 404 paths per minute per client") catch tools that change their user agent.
How the weaknesses are fixed
Remove backups and old files from the web root (deploy from a build artefact, not by copying folders), turn off directory listing (autoindex off; in nginx, Options -Indexes in Apache), never keep secrets in files under the web root, and rotate the exposed credential: once readable, it must be treated as known. Add a deployment check that fails when the web root contains *.old, *.bak, .git/ or archives.
SSH: what to ask
An SSH server reveals, before any login: its version banner, its host key types, its key-exchange, cipher and MAC algorithms, and which authentication methods it offers for a user name. None of that needs a password. The sandbox has no SSH server, so here is the lab version.
Lab session, authorised internal test, scope 10.10.0.0/24, from 10.10.0.99, inside the window:
tester@lab:~$ nmap -v -sT -p 22 --script ssh2-enum-algos,ssh-auth-methods --script-args ssh.user=labtest 10.10.0.10,20
Nmap scan report for www.lab.test (10.10.0.10)
PORT STATE SERVICE
22/tcp open ssh
| ssh-auth-methods:
| Supported authentication methods:
|_ publickey
| ssh2-enum-algos:
| kex_algorithms: (4)
| sntrup761x25519-sha512@openssh.com
| curve25519-sha256
| curve25519-sha256@libssh.org
| diffie-hellman-group16-sha512
| server_host_key_algorithms: (2)
| rsa-sha2-512
| ssh-ed25519
| encryption_algorithms: (2)
| chacha20-poly1305@openssh.com
| aes256-gcm@openssh.com
| mac_algorithms: (1)
| hmac-sha2-256-etm@openssh.com
| compression_algorithms: (2)
| none
|_ zlib@openssh.com
Nmap scan report for legacy01.lab.test (10.10.0.20)
PORT STATE SERVICE
22/tcp open ssh
| ssh-auth-methods:
| Supported authentication methods:
| publickey
|_ password
| ssh2-enum-algos:
| kex_algorithms: (4)
| diffie-hellman-group-exchange-sha256
| diffie-hellman-group-exchange-sha1
| diffie-hellman-group14-sha1
| diffie-hellman-group1-sha1
| server_host_key_algorithms: (2)
| ssh-rsa
| ssh-dss
| encryption_algorithms: (13)
| aes128-cbc
| 3des-cbc
| blowfish-cbc
| cast128-cbc
| arcfour128
| arcfour256
| arcfour
| aes192-cbc
| aes256-cbc
| rijndael-cbc@lysator.liu.se
| aes128-ctr
| aes192-ctr
| aes256-ctr
| mac_algorithms: (7)
| hmac-md5
| hmac-sha1
| umac-64@openssh.com
| hmac-ripemd160
| hmac-ripemd160@openssh.com
| hmac-sha1-96
| hmac-md5-96
| compression_algorithms: (2)
| none
|_ zlib@openssh.com(Abridged: -v progress lines removed. Without -v, ssh2-enum-algos prints only the counts, such as kex_algorithms: (4), not the names.) www accepts only public keys and offers a short list of modern algorithms (an explicitly hardened configuration), including a post-quantum hybrid key exchange: a negative result worth recording. legacy01 offers OpenSSH 4.7's default lists. legacy01 accepts passwords, offers diffie-hellman-group1-sha1 (a 1024-bit group), DSA host keys, CBC-mode and RC4 (arcfour) ciphers and MD5 MACs. Each is a configuration finding of moderate severity. Password authentication on an SSH server reachable by many users is the one with the most practical impact, because it allows password guessing, which the RoE may allow only at a very low rate, if at all.
How SSH enumeration and guessing are detected
sshd logs every connection, including ones that end before authentication (Connection closed by … [preauth]) and every failed password (Failed password for invalid user admin from …). Many failures from one source, or one password tried against many user names (spraying), are standard detections; tools such as fail2ban block the source automatically.
How SSH is hardened
In /etc/ssh/sshd_config: PasswordAuthentication no and KbdInteractiveAuthentication no (keys or certificates only; KbdInteractiveAuthentication is the OpenSSH 8.7+ name of ChallengeResponseAuthentication), PermitRootLogin no, and explicit modern KexAlgorithms, Ciphers, MACs and HostKeyAlgorithms lists; or simply a current OpenSSH, whose defaults already drop the weak algorithms. Restrict who can reach port 22 at the firewall (a bastion or VPN group, see Network Security). Retest with the same script: the weak entries should be gone.
Pitfalls
- Wordlist size versus the window and the client's logs.
http-enumis thousands of requests; large wordlists are tens of thousands. Agree the rate. - Using found credentials. A password in an exposed file is a critical finding to report, not an invitation, unless the RoE says otherwise.
- Ignoring virtual hosts. One address can serve several sites; enumerate with each known name in
Host:. - Reporting each weak SSH algorithm as its own finding. Group them: one finding, "weak SSH configuration", with the list as evidence.
Practice
- Add
--script-args http-enum.basepath=/backup/to the scan. What would you expect, and why might a tester use a base path? - Write the remediation text for the
legacy01SSH finding in three sentences.
Answers
- The script appends its path list to
/backup/instead of/, which finds files inside an application that lives under a prefix (/app/,/shop/). Here/backup/is a listed directory, so the listing already shows everything; the base path matters when listing is off. - For example: "Disable password authentication (
PasswordAuthentication no, andChallengeResponseAuthentication noon this old version) and require key-based logins for the two administrator accounts. Remove the legacy algorithms by upgrading OpenSSH to a supported release: the host runs 4.7p1, which predates theKexAlgorithmsoption and every modern algorithm, so configuration alone can't fix it; until the upgrade, restrict it toCiphers aes128-ctr,aes192-ctr,aes256-ctrandMACs hmac-sha1, the least weak choices it supports. Restrict port 22 to the administration network."
Test yourself
http-enum reports /backup/ and a manual request shows a directory listing with config.old. What does a tester do next?
- Download and use the credentials in config.old
- Record the listing, file name and that it was readable, and report it; don't use the credential unless the RoE allows it
- Delete the file
- Ignore it, backups are normal
Which SSH server setting most reduces the risk of password guessing?
- Changing the port
- PasswordAuthentication no (keys only)
- Banner removal
- Allowing arcfour
What does a defender typically see during path enumeration?
- Nothing
- Thousands of 404 responses for well-known paths from one source in a short time
- A single request
- Encrypted traffic only
legacy01 offers diffie-hellman-group1-sha1, 3des-cbc and hmac-md5. How should this be reported?
- As three critical findings
- As one finding, weak SSH configuration, with the algorithms as evidence and an upgrade or explicit algorithm lists as the fix
- Not at all
- As a false positive