You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: macos-hardening/macos-auto-start-locations.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,12 @@ Here you can find start locations useful for **sandbox bypass** that allows you
46
46
***`~/Library/LaunchDemons`**
47
47
***Trigger**: Relog-in
48
48
49
+
{% hint style="success" %}
50
+
As interesting fact, **`launchd`** has an embedded property list in a the Mach-o section `__Text.__config` which contains other well known services launchd must start. Moreover, these services can contain the `RequireSuccess`, `RequireRun` and `RebootOnSuccess` that means that they must be run and complete successfully.
51
+
52
+
Ofc, It cannot be modified because of code signing.
53
+
{% endhint %}
54
+
49
55
#### Description & Exploitation
50
56
51
57
**`launchd`** is the **first****process** executed by OX S kernel at startup and the last one to finish at shut down. It should always have the **PID 1**. This process will **read and execute** the configurations indicated in the **ASEP****plists** in:
@@ -101,6 +107,28 @@ launchctl list
101
107
If a plist is owned by a user, even if it's in a daemon system wide folders, the **task will be executed as the user** and not as root. This can prevent some privilege escalation attacks.
102
108
{% endhint %}
103
109
110
+
#### More info about launchd
111
+
112
+
**`launchd`** is the **first** user mode process which is started from the **kernel**. The process start must be **successful** and it **cannot exit or crash**. It's even **protected** against some **killing signals**.
113
+
114
+
One of the first things `launchd` would do is to **start** all the **daemons** like:
115
+
116
+
***Timer daemons** based on time to be executed:
117
+
* atd (`com.apple.atrun.plist`): Has a `StartInterval` of 30min
118
+
* crond (`com.apple.systemstats.daily.plist`): Has `StartCalendarInterval` to start at 00:15
119
+
***Network daemons** like:
120
+
*`org.cups.cups-lpd`: Listens in TCP (`SockType: stream`) with `SockServiceName: printer`
121
+
* SockServiceName must be either a port or a service from `/etc/services`
122
+
*`com.apple.xscertd.plist`: Listens on TCP in port 1640
123
+
***Path daemons** that are executed when a specified path changes:
124
+
*`com.apple.postfix.master`: Checking the path `/etc/postfix/aliases`
*`com.apple.xscertd-helper.plist`: It's indicating in the `MachServices` entry the name `com.apple.xscertd.helper`
129
+
***UserEventAgent:**
130
+
* This is different from the previous one. It makes launchd spawn apps in response to specific event. However, in this case, the main binary involved isn't `launchd` but `/usr/libexec/UserEventAgent`. It loads plugins from the SIP restricted folder /System/Library/UserEventPlugins/ where each plugin indicates its initialiser in the `XPCEventModuleInitializer` key or. in the case of older plugins, in the `CFPluginFactories` dict under the key `FB86416D-6164-2070-726F-70735C216EC0` of its `Info.plist`.
Copy file name to clipboardExpand all lines: macos-hardening/macos-security-and-privilege-escalation/macos-proces-abuse/macos-ipc-inter-process-communication/macos-xpc/README.md
+79-2Lines changed: 79 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ Other ways to support HackTricks:
9
9
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
10
10
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
11
11
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
12
-
***Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
12
+
***Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
13
13
***Share your hacking tricks by submitting PRs to the**[**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
The ones in **`LaunchDameons`** are run by root. So if an unprivileged process can talk with one of these it could be able to escalate privileges.
80
80
81
+
## XPC Objects
82
+
83
+
***`xpc_object_t`**
84
+
85
+
Every XPC message is a dictionary object that simplifies the serialization and deserialization. Moreover, `libxpc.dylib` declares most of the data types so it's possible to make that the received data is of the expected type. In the C API every object is a `xpc_object_t` (and it's type can be checked using `xpc_get_type(object)`).\
86
+
Moreover, the function `xpc_copy_description(object)` can be used to get a string representation of the object that can be useful for debugging purposes.\
87
+
These objects also have some methods to call like `xpc_<object>_copy`, `xpc_<object>_equal`, `xpc_<object>_hash`, `xpc_<object>_serialize`, `xpc_<object>_deserialize`...
88
+
89
+
The `xpc_object_t` are created calling `xpc_<objetType>_create` function, which internally calls `_xpc_base_create(Class, Size)` where it's indicated the type of the class of the object (one of `XPC_TYPE_*`) and the size of it (some extra 40B will be added to the size for metadata). Which means that the data of the object will start at the offset 40B.\
90
+
Therefore, the `xpc_<objectType>_t` is kind of a subclass of the `xpc_object_t` which would be a subclass of `os_object_t*`.
91
+
92
+
{% hint style="warning" %}
93
+
Note that it should be the developer who uses `xpc_dictionary_[get/set]_<objectType>` to get or set the type and real value of a key.
94
+
{% endhint %}
95
+
96
+
***`xpc_pipe`**
97
+
98
+
A **`xpc_pipe`** is a FIFO pipe that processes can use to communicate (the communication use Mach messages).\
99
+
It's possible to create a XPC server calling `xpc_pipe_create()` or `xpc_pipe_create_from_port()` to create it using a specific Mach port. Then, to receive messages it's possible to call `xpc_pipe_receive` and `xpc_pipe_try_receive`.
100
+
101
+
Note that the **`xpc_pipe`** object is a **`xpc_object_t`** with information in its struct about the two Mach ports used and the name (if any). The name, for example, the daemon `secinitd` in its plist `/System/Library/LaunchDaemons/com.apple.secinitd.plist` configures the pipe called `com.apple.secinitd`.
102
+
103
+
An example of a **`xpc_pipe`** is the **bootstrap pip**e created by **`launchd`** making possible sharing Mach ports.
104
+
105
+
***`NSXPC*`**
106
+
107
+
These are Objective-C high level objects which allows the abstraction of XPC connections.\
108
+
Moreover, it's easier to debug these objects with DTrace than the previous ones.
109
+
110
+
***`GCD Queues`**
111
+
112
+
XPC uses GCD to pass messages, moreover it generates certain dispatch queues like `xpc.transactionq`, `xpc.io`, `xpc-events.add-listenerq`, `xpc.service-instance`...
113
+
114
+
## XPC Services
115
+
116
+
These are **bundles with `.xpc`** extension located inside the **`XPCServices`** folder of other projects and in the `Info.plist` they have the `CFBundlePackageType` set to **`XPC!`**.\
117
+
This file have other configuration keys like `ServiceType` which can be Application, User, System or `_SandboxProfile` which can define a sandbox or `_AllowedClients` which might indicate entitlements or ID required to contact the ser. these and other configuration options will be useful to configure the service when being launched.
118
+
119
+
### Starting a Service
120
+
121
+
The app attempts to **connect** to a XPC service using `xpc_connection_create_mach_service`, then launchd locates the daemon and starts **`xpcproxy`**. **`xpcproxy`** enforce configured restrictions and. spawns the service with the provided FDs and Mach ports.
122
+
123
+
In order to improve the speed of the search of the XPC service, a cache is used.
124
+
125
+
It's possible to trace the actions of `xpcproxy` using:
126
+
127
+
```bash
128
+
supraudit S -C -o /tmp/output /dev/auditpipe
129
+
```
130
+
131
+
The XPC library use `kdebug` to log actions calling `xpc_ktrace_pid0` and `xpc_ktrace_pid1`. The codes it uses are undocumented so it's needed to add the into `/usr/share/misc/trace.codes`. They have the prefix `0x29` and for example one is `0x29000004`: `XPC_serializer_pack`.\
132
+
The utility `xpcproxy` uses the prefix `0x22`, for example: `0x2200001c: xpcproxy:will_do_preexec`.
133
+
81
134
## XPC Event Messages
82
135
83
136
Applications can **subscribe** to different event **messages**, enabling them to be **initiated on-demand** when such events happen. The **setup** for these services is done in l**aunchd plist files**, located in the **same directories as the previous ones** and containing an extra **`LaunchEvent`** key.
This functionality provided by `RemoteXPC.framework` (from `libxpc`) allows to communicate via XPC through different hosts.\
468
+
The services that supports remote XPC will have in their plist the key UsesRemoteXPC like it's the case of `/System/Library/LaunchDaemons/com.apple.SubmitDiagInfo.plist`. However, although the service will be registered with `launchd`, it's `UserEventAgent` with the plugins `com.apple.remoted.plugin` and `com.apple.remoteservicediscovery.events.plugin` which provides the functionality.
469
+
470
+
Moreover, the `RemoteServiceDiscovery.framework` allows to get info from the `com.apple.remoted.plugin` exposing functions such as `get_device`, `get_unique_device`, `connect`...
471
+
472
+
Once connect is used and the socket `fd` of the service is gathered, it's possible to use `remote_xpc_connection_*` class.
473
+
474
+
It's possible to get information about remote services using the cli tool `/usr/libexec/remotectl` using parameters as:
475
+
476
+
```bash
477
+
/usr/libexec/remotectl list # Get bridge devices
478
+
/usr/libexec/remotectl show ...# Get device properties and services
479
+
/usr/libexec/remotectl dumpstate # Like dump withuot indicateing a servie
480
+
/usr/libexec/remotectl [netcat|relay] ... # Expose a service in a port
481
+
...
482
+
```
483
+
484
+
The communication between BridgeOS and the host occurs through a dedicated IPv6 interface. The `MultiverseSupport.framework` allows to establish sockets whose `fd` will be used for communicating.\
485
+
It's possible to find thee communications using `netstat`, `nettop` or the open source option, `netbottom`.
486
+
410
487
<details>
411
488
412
489
<summary><strong>Learn AWS hacking from zero to hero with</strong> <ahref="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
@@ -416,7 +493,7 @@ Other ways to support HackTricks:
416
493
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
417
494
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
418
495
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
419
-
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
496
+
***Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
420
497
***Share your hacking tricks by submitting PRs to the**[**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
0 commit comments