Skip to content

Commit 8354589

Browse files
carlospolopgitbook-bot
authored andcommitted
GitBook: [master] 500 pages modified
1 parent 899a6ab commit 8354589

File tree

1 file changed

+51
-1
lines changed
  • macos/macos-security-and-privilege-escalation

1 file changed

+51
-1
lines changed

macos/macos-security-and-privilege-escalation/README.md

+51-1
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,26 @@ And find all the quarantined files with:
6161
find / -exec ls -ld {} \; 2>/dev/null | grep -E "[x\-]@ " | awk '{printf $9; printf "\n"}' | xargs -I {} xattr -lv {} | grep "com.apple.quarantine"
6262
```
6363

64-
### Sandbox
64+
## XProtect
65+
66+
**X-Protect is Apple’s built in malware scanner.** It keeps track of known malware hashes and patterns.
67+
68+
## Sandbox
6569

6670
MacOS Sandbox makes applications run inside the sandbox **need to request access to resources outside of the limited sandbox**. This helps to ensure that **the application will be accessing only expected resources** and if it wants to access anything else it will need to ask for permissions to the user.
6771

72+
You can get information about the latest XProtect update running:
73+
6874
Important **system services** also run inside their own custom **sandbox** such as the mdnsresponder service. You can view these custom **sandbox profiles** inside the **`/usr/share/sandbox`** directory.
6975

76+
```bash
77+
system_profiler SPInstallHistoryDataType 2>/dev/null | grep -A 4 "XProtectPlistConfigData" | tail -n 5
78+
```
79+
7080
Check some of the **already given permissions** to apps in `System Preferences --> Security & Privacy --> Privacy --> Files and Folders`.
7181

82+
## Common users
83+
7284
### SIP - System Integrity Protection
7385

7486
This protection was enabled to **help keep root level malware from taking over certain parts** of the operating system. Although this means **applying limitations to the root user** many find it to be worthwhile trade off.
@@ -611,6 +623,44 @@ The **kcpassword** file is a file that holds the **user’s login password**, bu
611623
The password is stored in the file **`/etc/kcpassword`** xored with the key **`0x7D 0x89 0x52 0x23 0xD2 0xBC 0xDD 0xEA 0xA3 0xB9 0x1F`**. If the users password is longer than the key, the key will be reused.
612624
This makes the password pretty easy to recover, for example using scripts like [**this one**](https://gist.github.com/opshope/32f65875d45215c3677d).
613625

626+
## **Library injection**
627+
628+
### Dylib Hijacking
629+
630+
As in Windows, in MacOS you can also **hijack dylibs** to make **applications** **execute** **arbitrary** **code**.
631+
However, the way **MacOS** applications **load** libraries is **more restricted** than in Windows. This implies that **malware** developers can still use this technique for **stealth**, but the probably to be able to **abuse this to escalate privileges is much lower**.
632+
633+
First of all, is **more common** to find that **MacOS binaries indicates the full path** to the libraries to load. And second, **MacOS never search** in the folders of the **$PATH** for libraries.
634+
635+
However, there are 2 types of dylib hijacking:
636+
637+
* **Missing weak linked libraries**: This means that the application will try to load a library that doesn't exist configured with **LC\_LOAD\_WEAK\_DYLIB**. Then, **if an attacker places a dylib where it's expected it will be loaded**.
638+
* The fact that the link is "weak" means that the application will continue running even if the library isn't found.
639+
* **Configured with @rpath**: The path to the library configured contains "**@rpath**" and it's configured with **multiple** **LC\_RPATH** containing **paths**. Therefore, **when loading** the dylib, the loader is going to **search** \(in order\) **through all the paths** specified in the **LC\_RPATH** **configurations**. If anyone is missing and **an attacker can place a dylib there** and it will be loaded.
640+
641+
The way to **escalate privileges** abusing this functionality would be in the rare case that an **application** being executed **by** **root** is **looking** for some **library in some folder where the attacker has write permissions.**
642+
643+
**A nice scanner to find missing libraries in applications is** [**Dylib Hijack Scanner**](https://objective-see.com/products/dhs.html)**.
644+
A nice report with technical details about this technique can be found** [**here**](https://www.virusbulletin.com/virusbulletin/2015/03/dylib-hijacking-os-x)**.**
645+
646+
### **DYLD\_INSERT\_LIBRARIES**
647+
648+
> This is a colon separated **list of dynamic libraries** to l**oad before the ones specified in the program**. This lets you test new modules of existing dynamic shared libraries that are used in flat-namespace images by loading a temporary dynamic shared library with just the new modules. Note that this has no effect on images built a two-level namespace images using a dynamic shared library unless DYLD\_FORCE\_FLAT\_NAMESPACE is also used.
649+
650+
This is like the [**LD\_PRELOAD on Linux**](../../linux-unix/privilege-escalation/#ld_preload).
651+
652+
This technique may be also **used as an ASEP technique** as every application installed has a plist called "Info.plist" that allows for the **assigning of environmental variables** using a key called `LSEnvironmental`.
653+
654+
## Crons
655+
656+
In MacOS several folders executing scripts with **certain frequency** can be found in:
657+
658+
```bash
659+
ls -lR /usr/lib/cron/tabs/ /private/var/at/jobs /etc/periodic/
660+
```
661+
662+
There you can find the regular **cron** **jobs**, the **at** **jobs** \(not very used\) and the **periodic** **jobs** \(mainly used for cleaning temporary files\). The daily periodic jobs can be executed for example with: `periodic daily`.
663+
614664
## Specific MacOS Enumeration
615665

616666
```bash

0 commit comments

Comments
 (0)