Identifier / Programs / Linux and Unix
flock
Manage file locks from shell scripts. It can be used to ensure that only one instance of a command is running. tldr-pages
GTFOBins shell 1 Sigma rule name it 2 ATT&CK techniques 1 documented command
How flock is abused
shell T1059.004 Command and Scripting Interpreter: Unix Shell
-uUnlock toyboxEach abuse is GTFOBins's category and the options and words it uses; the full write-up is on GTFOBins's page for flock.
1 documented command
shell unprivileged, with sudo, as SUID
flock -u / /bin/shIdentifyAs SUID:
flock -u / /bin/sh -p
Trips 1 Sigma rule: highShell Execution via Flock - Linux by Li Ling, Andy Parkidomo, Robert Rakowski, Blake Hartstein (Bloomberg L.P.)
The command the identifier reads trips a Sigma process-creation rule. This command is from GTFOBins, at commit acd524623f9c of 2026-05-27, under the GPL-3.0, with no warranty. Changed: Markdown is shown formatted. The source is in lolbas-gtfobins-commands.json.gz, and the full entry is on GTFOBins’s page for flock. The identifier reads the line that runs flock.
What detects it
Everyday use
Run a command with a file lock as soon as the lock is available
flock path/to/lock.lock commandIdentifyRun a command with a file lock, or exit if the lock is currently being held (with exit code 1)
flock --nonblock path/to/lock.lock commandIdentifyRun a command with a file lock, or exit with a specific error code if the lock is currently being held
flock --nonblock --conflict-exit-code 123 path/to/lock.lock commandIdentifyNone of the 3 examples the identifier reads matches GTFOBins abuse or trips a Sigma process-creation rule.
Options
Show every option of flock
-sShared lock-xExclusive lock (default)-uUnlock-nNon-blocking: fail rather than wait for the lock