Lesson 8.1: Thinking like an attacker
Almost every attack on a content management system is automated: scanners probe for known files, bots try leaked passwords, scrapers count through every address. Exponential 6 is secure by default against most of it, and the administrator's job is to keep those defaults in force and close what is left. This lesson opens the security module with the attacker's view and a check every administrator can run in two minutes.
Warning
.htaccess slows down every request. When .htaccess files are enabled (AllowOverride anything but None), let alone
used, Apache looks for them and reads and evaluates them on every request, in every directory of the path, and
page loading times go up drastically (measured). The only real fix is to switch the feature off for
the virtual host: AllowOverride None in the HTTPS virtual host, and the rules in the virtual host's own
configuration as mod_rewrite rules. That is far faster in production speed tests and well worth the time it takes
to optimize a production configuration. Switch over right away: copy the rules of the
example HTTPS virtual host into your virtual host (with the static cache, also
staticcache_offload.conf), set AllowOverride None, run apachectl configtest, reload Apache and
test the site. The same rules for other servers: nginx, LiteSpeed,
Caddy, IIS, Velocity (built in); where virtual host rules go in a control
panel: Plesk, cPanel, DirectAdmin, ISPConfig.
On LiteSpeed or OpenLiteSpeed, the server's own page cache can also answer anonymous visitors and crawlers without PHP: Page caching with LiteSpeed and OpenLiteSpeed.
Note
Run the outside check only against your own training installation. Probing a site you do not run is an attack.
At a glance
| Course | Site administration |
| Module | Module 8: Security |
| Duration | 40 minutes (20 presenting, 20 exercise) |
| Level | Intermediate |
| Audience | Site administrators, security officers |
| Prerequisites | Module 7; a training installation served over HTTP and a terminal |
Learning objectives
After this lesson, learners can:
- name four kinds of automated attack on a CMS and one built-in defense against each;
- explain the principles secure by default, least privilege and privilege separation with an example each;
- check from outside that dot files, settings and logs are never handed out;
- find the request classifier's verdicts in
security.log; - use the hardening checklist to find what is still open on an installation.
Trainer's notes
How to present it
Sources: Security hardening and Chapter 13: Security hardening for production, section 13.2.
- Who attacks (5 minutes). Botnets and scanners (
/wp-login.php,/.env,/.git/config), credential attackers (leaked pairs, default passwords), access brokers who sell one working sign-in, scrapers and AI crawlers, and supply-chain attackers. None of it is personal. - The principles (5 minutes). Show the principles table of the hardening page: secure by default, least privilege, privilege separation, minimal attack surface, audit, fix forward. For each, one thing built in and one thing that is the administrator's part.
- What the web server must never hand out (5 minutes). Only a fixed list of asset paths is served as files;
everything else goes to
index.php. Dot files and scripts below the root answer 404. Never serve the installation with a generic "serve the file if it exists" configuration. - Watching (3 minutes).
security.logholds the classifier's verdicts; it classifies, it does not block. Blocking is the job of a shield in front, the web server, or request rules, which can allow, deny, redirect, rewrite or log a request after its URL alias is translated. - Reporting (2 minutes). Vulnerabilities are reported privately, as the hardening page says, never in a public issue.
Common questions
Is a 200 answer for /settings/site.ini a leak? Not if the body is an HTML page of Exponential. It is a leak only
if the INI text comes back. Look at the body once.
Can we hide /content/view/full/123 addresses? Yes, with a request rule that redirects system URLs to their alias;
see Request rules. Try it on a training site first; it has an audit-only
rule to see who would be affected.
Does Exponential block attackers? The classifier does not; the hardening page describes the shield and the web server as the places that block.
Pitfalls
- Deleting rules to make something work. A missing image is never a reason to remove a rule from
.htaccess. Find the cause. - Testing the wrong host. The outside check must use the address visitors use, through the same web server and proxy.
- Scaring learners. Keep the tone factual: the point is that most defenses are already on.
Hands-on exercise
Use your own training installation, served for example with exp:velocity start (see
Serving the site). Replace http://127.0.0.1:8087 with its address.
In a terminal, run the outside check:
for p in /.git/config /.env /settings/site.ini /composer.json /kernel/classes/ezini.php /var/log/error.log; do printf '%-32s %s\n' "$p" "$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8087$p)" doneFor
/settings/site.ini, look at the body once:curl -s http://127.0.0.1:8087/settings/site.ini | head -5. It must be HTML, not INI text.Request a typical probe address:
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8087/wp-login.php.In the administration, open Setup > Log files and open
security.log. Find your probe and read its category and rule.Read the checklist at the end of Security hardening. For each line, mark done, open or not applicable for your training installation.
Check two of the lines yourself: is debug output off (Setup > Ini settings or
php bin/php/console exp:ini get site.ini/DebugSettings/DebugOutput), and doesvar/log/initial-admin-passwordstill exist?Preview what the request rules would decide for a system URL, changing nothing:
php bin/php/ezrequestrules.php -s <site> --uri=content/view/full/2Share your three most important open lines with the group.
Expected result
- Step 1 shows
404for every path, or200only where the body is an Exponential page (step 2). - Step 4 shows a line with a category such as
probe/...for the/wp-login.phprequest. - Step 5 gives each learner a marked checklist; on a fresh training installation the password and file lines are usually open.
- The trainer collects the open lines on a flip chart; they are the agenda of the rest of the module.
Quiz
- Which of these is not served as a file by the shipped rules?
A. An image below
storage/original/imageB./.envC. A stylesheet of a design D./.well-known/files - What does the request classifier do with a request it names an attack?
- Name the principle behind "CLI scripts refuse to run as root without
--allow-root-user". - A colleague wants to use nginx's "serve the file if it exists, else
index.php". What do you answer? - Where do you report a vulnerability you found in Exponential?
Answers
- B. Dot files answer 404;
/.well-known/is the one exception (Chapter 13, 13.2). - It writes it to
security.logwith its category and rule; it blocks nothing. - Least privilege.
- No: such a configuration hands out every file that exists, including
settings/*.iniand the SQLite database. Use the server block of chapter 8. - Privately, as Reporting a vulnerability says; never in a public issue.
Further reading
- Security hardening: every threat with its defense.
- Chapter 13: Security hardening for production: the setting-by-setting reference and go-live checklist.
- Request rules: allow, deny, redirect or rewrite requests.
- Hardening for hosts and Request shield and request rules.
Related pages
- Module 8: Security
- Site administration: course overview
- Trainers: start here
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.