[ privscope: Finding the Shortcuts to Admin and Root ]
[ Overview |
How it works |
What it checks |
The reports |
Keeping it honest |
Testing your detections |
What it won't do |
FAQ ]
[ Overview ]
Most machines I've looked at closely had a way for an ordinary account to become admin or root that nobody meant to leave there. A service whose program anyone can overwrite. A scheduled task that runs a file out of a folder users can write to. A root cron job pointing at a script someone else owns. A sudo rule that's a lot broader than it looks. privscope is the tool I built to find those, on my own machines and on the ones I'm asked to assess. There are plenty of tools for this already. winPEAS, linPEAS and PrivescCheck are good at what they do, but they're written for the person doing the escalating: a wall of colored output, nothing about how to fix it, and no memory of last month. I wanted the defender's version. Every finding comes with the evidence, why it matters and the fix, and the next run gets compared with this one, so I can see what I actually fixed. It comes in two halves. A collector runs on the machine: a PowerShell script on Windows, a plain sh script on Linux. Neither needs anything installed, and both only read. The analyzer runs anywhere with Python 3.9 or newer, standard library only, and does all the judging offline. It's free software, GPL-3.0-or-later. # on Windows: no install, no admin needed powershell -ExecutionPolicy Bypass -File .\Invoke-PrivscopeCollector.ps1 # on Linux: no install; run it as root to see the most sh privscope-collect.sh # anywhere with Python pip install git+https://github.com/magikh0e/privscope privscope analyze collection.json --format html -o report.html privscope diff last-month.json today.json GitHub source, README and both collectors RULES.md exactly how every rule is evaluated
[ How it works ]
The collector and the analyzer are split on purpose, and the line between
them is strict. The collector records facts: how every service, task, cron
job and systemd unit is set up, who owns each file they run and what its
permissions are, which groups and privileges the account has, and the policy
settings that matter. It writes all that to one JSON file and decides
nothing. It doesn't test whether it can write somewhere, doesn't try
anything, and doesn't open files that hold secrets.
I like it that way for two reasons. The part that runs on somebody's
production box stays small and boring, with nothing in it that looks like an
attack. And because the judging happens offline, when I fix a rule or add
one I can re-run it against last month's collection without going back to
the machine.
The analyzer reads permissions the way the operating system does. On Windows
that's real ACL evaluation: inherited and inherit-only entries, deny beating
allow, the owner's implicit right to change permissions. On Linux it's owner,
group and other bits with the kernel's precedence, plus a check that every
folder above a file actually lets you get to it. A world-writable script
inside a folder nobody else can enter isn't a finding, and it shouldn't be.
Then every rule asks the same question: could someone who isn't admin use
this to become admin? Who that someone is depends on how the collector ran.
as a normal account what that account can reach. On Windows, if it's an
admin running without elevation, that's what code in
its session can do without a UAC prompt.
as admin or root what any ordinary account could reach. On Linux that
includes the non-root owner of a script root runs,
since whoever owns a file can change it.
[ What it checks ]
69 rules so far. They're JSON data rather than code, and each has a stable ID
so a finding in one run lines up with the same finding in the next.
Windows (32 rules)
services a program anyone can overwrite, a folder that takes new
files (DLL planting), an unquoted path with a writable
gap in it, a missing program someone could create
scheduled tasks SYSTEM and highest-privilege tasks whose program is
writable, missing, or sitting in a writable folder
logon programs machine-wide Run entries with the same problems
system PATH writable folders, and missing ones a user could create
policy AlwaysInstallElevated, UAC switched off or silent,
WDigest, LSA protection, Point and Print, WSUS over plain
HTTP, NTLMv1
the account privileges like SeImpersonate and SeBackup, and groups
that amount to admin
credentials a readable setup answer file, an autologon password in
the registry, PowerShell history
Linux (37 rules)
setuid writable setuid programs, setuid-root programs that can
start a shell, setuid files outside the system folders,
file capabilities that lead to root
cron, systemd root jobs and services whose program is writable,
swappable through its folder, or missing; writable unit
files and init scripts
root's PATH writable, missing, relative or empty entries in sudo's
secure_path, /etc/environment, login.defs and cron
key files writable passwd, shadow, sudoers or PAM config; readable
password hashes; writable cron, systemd, loader and shell
startup files
sudo passwordless rules for anything, or for a program that
can start a shell; rules that run a writable program;
wildcards; LD_PRELOAD kept through env_keep
the rest docker, lxd and disk groups, writable container sockets,
NFS exports without root squashing, other accounts'
readable SSH keys and credential files
The Linux collector sticks to POSIX sh, awk, find and stat, so it runs the
same on a full Ubuntu server, an Alpine container and a BusyBox appliance.
[ The reports ]
privscope writes plain text for the terminal, Markdown, JSON, or a single HTML file. Each finding shows the exact permission that makes it a problem, something like "/opt/app/bin/backup.sh is writable by everyone (mode 0777)", then why it matters and how to fix it. The HTML report is one file with no JavaScript and nothing loaded from anywhere else, and it carries a Content-Security-Policy that forbids both. That's on purpose. Every path and name in a report comes from the machine that was scanned, and on an engagement I can't assume that machine is friendly. After fixing things I run the collector again, and privscope diff tells me what's new, what's resolved and what hasn't moved. --fail-on high makes it exit with an error when anything high or worse turns up, which is handy in a scheduled job.
[ Keeping it honest ]
A tool like this is only useful if I can trust it not to cry wolf, so it gets checked three ways. Every rule has at least one hand-built test case that has to trigger it, and the test suite fails if a rule has none. The same cases pin down the fiddly parts: inherit-only entries, deny entries, a user who's in a file's group and so gets the group bits even when "other" would allow more, a writable file behind a folder nobody can enter. The repo also has a Debian container that's broken on purpose, with fifteen weaknesses planted in it. One command builds it, runs the collector inside as a normal user and as root, and checks that privscope finds exactly what was planted. Not one more, not one less. Clean systems have to come back clean, too. A stock Debian container and Alpine, where everything is BusyBox, both report nothing.
[ Testing your detections ]
Finding a weakness is one half of the job. The other half, on a purple-team
engagement, is knowing whether anything would have noticed it being used. So
privscope has an opt-in third piece, separate from the read-only collector and
analyzer: privscope attack reads a collection and writes a self-contained
detection-test script for that host — bash for Linux, PowerShell for Windows —
that runs the real technique behind each finding, so I can see whether the box's
IDS, IPS, EDR or audit rules catch it.
privscope attack collection.json -o pack.sh
Because it runs real local-privesc techniques, it's wrapped in rails. It's a
dry run by default — it lists the tests and changes nothing. It only detonates
when three things are true: I pass --execute, an authorization marker file I
placed on the host is present, and the hostname matches the collection. Each
test backs up what it touches and restores it afterwards, proves the result
with id or whoami, and logs a line per step with a correlation id and the
MITRE ATT&CK technique, so I can line each action up against the alert it did
or didn't raise. No persistence, no exfiltration, and no evasion — the whole
point is to be seen. It's for hosts I own or am authorized to test, and the
REDTEAM.md in the repo spells out every technique.
[ What it won't do ]
The collector and analyzer detect and report, nothing more. They run no
technique, change nothing on the machine, and the collector doesn't even read
secret files. The only part that acts is privscope attack above, and only when
I explicitly point it at a host I'm cleared to test. Run any of it on systems
you own or are allowed to assess.
The collectors don't open secret files either. For shadow, unattend files,
SSH keys, credential files and shell history they note that the file exists
and who can read it. Never what's inside.
A collection is still a map of what's weak on that machine, so I treat it
like one. Mine stay on my own machines, and the repo's .gitignore keeps
collections out of commits.
One side effect on Linux: the collector runs sudo -n -l to list the account's
sudo rules. It never prompts for a password, but sudo logs the request, and
for an account that isn't in sudoers it can mail the admin. --no-sudo skips
it.
[ FAQ ]
Does privscope exploit anything?
The collector and analyzer don't — they read configuration and permissions and
report. The repo also ships an opt-in subcommand, privscope attack, that turns
findings into a detection-test script which runs the real techniques, so you
can check whether your host-based IDS/IPS catches them. It's a dry run by
default, and only runs with an explicit flag plus an authorization marker you
put on the host. For authorized testing only; see the Testing your detections
section above.
Do I need admin or root to run it?
No. Run as an ordinary account, the collector shows what that account can
reach, which is the realistic view. Run as admin or root, it sees more of the
machine, and the analyzer then judges everything from the point of view of an
ordinary account.
Does it send my data anywhere?
No. The collector writes one JSON file on the machine, and the analyzer reads
it wherever you run it. Nothing is uploaded, and the HTML report doesn't load
anything from the internet either.
How is it different from winPEAS or linPEAS?
Those are built for the person doing the escalating and do their analysis on
the target. privscope only collects facts on the target and does the analysis
offline. It tells you how to fix each finding, keeps stable rule IDs so you
can compare one run with the next, and never reads secret files.
What doesn't it check yet?
On Windows, the permissions on services themselves and on their registry
keys. On Linux, ACLs set with setfacl. And missing patches: the collectors
record the OS and kernel versions, and matching those against known local
privilege-escalation CVEs is a job I have planned for cvescope.
Is privscope free?
Yes. It's free software under the GPL-3.0-or-later, and the source is on
GitHub. The analyzer is Python 3.9 or newer with no third-party dependencies,
and the collectors need nothing installed.
[ See Also ]
privscope on GitHub # source, both collectors and the rules
RULES.md # exactly how every rule is evaluated
REDTEAM.md # the opt-in detection-test packs, technique by technique
cvescope # its sibling: the CVEs that hit the gear you run
fwscope # firewall, WAF and IDS logs in the browser
Code & Tools (parent) # the rest of the code
