macOS XPC Connecting Process Check

Tip

AWS ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°:HackTricks Training AWS Red Team Expert (ARTE)
GCP ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training GCP Red Team Expert (GRTE) Azure ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks μ§€μ›ν•˜κΈ°

XPC Connecting Process Check

XPC μ„œλΉ„μŠ€μ— 연결이 μ„€μ •λ˜λ©΄, μ„œλ²„λŠ” 연결이 ν—ˆμš©λ˜λŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€. 일반적으둜 μˆ˜ν–‰ν•˜λŠ” μ²΄ν¬λŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€:

  1. μ—°κ²°ν•˜λŠ” ν”„λ‘œμ„ΈμŠ€κ°€ Apple μ„œλͺ… μΈμ¦μ„œλ‘œ μ„œλͺ…λ˜μ—ˆλŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€ (Appleμ—μ„œλ§Œ λ°œκΈ‰).
  • 이 확인이 이루어지지 μ•ŠμœΌλ©΄, κ³΅κ²©μžλŠ” κ°€μ§œ μΈμ¦μ„œλ₯Ό λ§Œλ“€μ–΄ λ‹€λ₯Έ 체크와 μΌμΉ˜μ‹œν‚¬ 수 μžˆμŠ΅λ‹ˆλ‹€.
  1. μ—°κ²°ν•˜λŠ” ν”„λ‘œμ„ΈμŠ€κ°€ 쑰직의 μΈμ¦μ„œλ‘œ μ„œλͺ…λ˜μ—ˆλŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€ (νŒ€ ID 확인).
  • 이 확인이 이루어지지 μ•ŠμœΌλ©΄, Apple의 λͺ¨λ“  개발자 μΈμ¦μ„œκ°€ μ„œλͺ…에 μ‚¬μš©λ  수 있으며, μ„œλΉ„μŠ€μ— μ—°κ²°ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
  1. μ—°κ²°ν•˜λŠ” ν”„λ‘œμ„ΈμŠ€κ°€ μ μ ˆν•œ λ²ˆλ“€ IDλ₯Ό ν¬ν•¨ν•˜κ³  μžˆλŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€.
  • 이 확인이 이루어지지 μ•ŠμœΌλ©΄, λ™μΌν•œ μ‘°μ§μ—μ„œ μ„œλͺ…λœ 도ꡬ가 XPC μ„œλΉ„μŠ€μ™€ μƒν˜Έμž‘μš©ν•˜λŠ” 데 μ‚¬μš©λ  수 μžˆμŠ΅λ‹ˆλ‹€.
  1. (4 λ˜λŠ” 5) μ—°κ²°ν•˜λŠ” ν”„λ‘œμ„ΈμŠ€κ°€ μ μ ˆν•œ μ†Œν”„νŠΈμ›¨μ–΄ 버전 번호λ₯Ό κ°€μ§€κ³  μžˆλŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€.
  • 이 확인이 이루어지지 μ•ŠμœΌλ©΄, 였래된, μ·¨μ•½ν•œ ν΄λΌμ΄μ–ΈνŠΈκ°€ ν”„λ‘œμ„ΈμŠ€ μ£Όμž…μ— μ·¨μ•½ν•˜μ—¬ λ‹€λ₯Έ 체크가 μžˆμ–΄λ„ XPC μ„œλΉ„μŠ€μ— 연결될 수 μžˆμŠ΅λ‹ˆλ‹€.
  1. (4 λ˜λŠ” 5) μ—°κ²°ν•˜λŠ” ν”„λ‘œμ„ΈμŠ€κ°€ μœ„ν—˜ν•œ κΆŒν•œμ΄ μ—†λŠ” κ°•ν™”λœ λŸ°νƒ€μž„μ„ κ°€μ§€κ³  μžˆλŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€ (μž„μ˜μ˜ 라이브러리λ₯Ό λ‘œλ“œν•˜κ±°λ‚˜ DYLD ν™˜κ²½ λ³€μˆ˜λ₯Ό μ‚¬μš©ν•  수 μžˆλŠ” κΆŒν•œκ³Ό 같은).
  2. 이 확인이 이루어지지 μ•ŠμœΌλ©΄, ν΄λΌμ΄μ–ΈνŠΈκ°€ μ½”λ“œ μ£Όμž…μ— μ·¨μ•½ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
  3. μ—°κ²°ν•˜λŠ” ν”„λ‘œμ„ΈμŠ€κ°€ μ„œλΉ„μŠ€μ— μ—°κ²°ν•  수 μžˆλŠ” κΆŒν•œμ„ κ°€μ§€κ³  μžˆλŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€. μ΄λŠ” Apple λ°”μ΄λ„ˆλ¦¬μ— μ μš©λ©λ‹ˆλ‹€.
  4. 검증은 μ—°κ²°ν•˜λŠ” ν΄λΌμ΄μ–ΈνŠΈμ˜ 감사 토큰을 기반으둜 ν•΄μ•Ό ν•˜λ©°, ν”„λ‘œμ„ΈμŠ€ ID (PID) λŒ€μ‹  μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€. μ΄λŠ” ν›„μžκ°€ PID μž¬μ‚¬μš© 곡격을 λ°©μ§€ν•˜κΈ° λ•Œλ¬Έμž…λ‹ˆλ‹€.
  • κ°œλ°œμžλ“€μ€ 감사 토큰 API ν˜ΈμΆœμ„ λ“œλ¬Όκ²Œ μ‚¬μš©ν•˜λ©°, μ΄λŠ” λΉ„κ³΅μ‹μ μ΄λ―€λ‘œ Apple이 μ–Έμ œλ“ μ§€ λ³€κ²½ν•  수 μžˆμŠ΅λ‹ˆλ‹€. λ˜ν•œ, 비곡식 API μ‚¬μš©μ€ Mac App Store μ•±μ—μ„œ ν—ˆμš©λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
  • processIdentifier λ©”μ„œλ“œκ°€ μ‚¬μš©λ˜λ©΄ μ·¨μ•½ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
  • **xpc_dictionary_get_audit_token**이 xpc_connection_get_audit_token λŒ€μ‹  μ‚¬μš©λ˜μ–΄μ•Ό ν•˜λ©°, ν›„μžλŠ” νŠΉμ • μƒν™©μ—μ„œ μ·¨μ•½ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Communication Attacks

PID μž¬μ‚¬μš© 곡격에 λŒ€ν•œ μžμ„Έν•œ μ •λ³΄λŠ” λ‹€μŒμ„ ν™•μΈν•˜μ‹­μ‹œμ˜€:

macOS PID Reuse

xpc_connection_get_audit_token 곡격에 λŒ€ν•œ μžμ„Έν•œ μ •λ³΄λŠ” λ‹€μŒμ„ ν™•μΈν•˜μ‹­μ‹œμ˜€:

macOS xpc_connection_get_audit_token Attack

Trustcache - Downgrade Attacks Prevention

TrustcacheλŠ” Apple Silicon κΈ°κ³„μ—μ„œ λ„μž…λœ λ°©μ–΄ λ°©λ²•μœΌλ‘œ, Apple λ°”μ΄λ„ˆμŠ€μ˜ CDHSAH λ°μ΄ν„°λ² μ΄μŠ€λ₯Ό μ €μž₯ν•˜μ—¬ ν—ˆμš©λœ λΉ„μˆ˜μ • λ°”μ΄λ„ˆμŠ€λ§Œ 싀행될 수 μžˆλ„λ‘ ν•©λ‹ˆλ‹€. μ΄λŠ” λ‹€μš΄κ·Έλ ˆμ΄λ“œ λ²„μ „μ˜ 싀행을 λ°©μ§€ν•©λ‹ˆλ‹€.

Code Examples

μ„œλ²„λŠ” **shouldAcceptNewConnection**μ΄λΌλŠ” ν•¨μˆ˜μ—μ„œ 이 검증을 κ΅¬ν˜„ν•©λ‹ˆλ‹€.

- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
//Check connection
return YES;
}

NSXPCConnection κ°μ²΄λŠ” private 속성 auditToken (μ‚¬μš©ν•΄μ•Ό ν•˜μ§€λ§Œ 변경될 수 μžˆλŠ” 것)κ³Ό public 속성 processIdentifier (μ‚¬μš©ν•΄μ„œλŠ” μ•ˆ λ˜λŠ” 것)을 κ°€μ§€κ³  μžˆμŠ΅λ‹ˆλ‹€.

μ—°κ²°λœ ν”„λ‘œμ„ΈμŠ€λŠ” λ‹€μŒκ³Ό 같은 λ°©λ²•μœΌλ‘œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€:

[...]
SecRequirementRef requirementRef = NULL;
NSString requirementString = @"anchor apple generic and identifier \"xyz.hacktricks.service\" and certificate leaf [subject.CN] = \"TEAMID\" and info [CFBundleShortVersionString] >= \"1.0\"";
/* Check:
- Signed by a cert signed by Apple
- Check the bundle ID
- Check the TEAMID of the signing cert
- Check the version used
*/

// Check the requirements with the PID (vulnerable)
SecRequirementCreateWithString(requirementString, kSecCSDefaultFlags, &requirementRef);
SecCodeCheckValidity(code, kSecCSDefaultFlags, requirementRef);

// Check the requirements wuing the auditToken (secure)
SecTaskRef taskRef = SecTaskCreateWithAuditToken(NULL, ((ExtendedNSXPCConnection*)newConnection).auditToken);
SecTaskValidateForRequirement(taskRef, (__bridge CFStringRef)(requirementString))

κ°œλ°œμžκ°€ ν΄λΌμ΄μ–ΈνŠΈμ˜ 버전을 ν™•μΈν•˜κ³  μ‹Άμ§€ μ•Šλ‹€λ©΄, 적어도 ν΄λΌμ΄μ–ΈνŠΈκ°€ ν”„λ‘œμ„ΈμŠ€ μ£Όμž…μ— μ·¨μ•½ν•˜μ§€ μ•Šμ€μ§€ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€:

[...]
CFDictionaryRef csInfo = NULL;
SecCodeCopySigningInformation(code, kSecCSDynamicInformation, &csInfo);
uint32_t csFlags = [((__bridge NSDictionary *)csInfo)[(__bridge NSString *)kSecCodeInfoStatus] intValue];
const uint32_t cs_hard = 0x100;        // don't load invalid page.
const uint32_t cs_kill = 0x200;        // Kill process if page is invalid
const uint32_t cs_restrict = 0x800;    // Prevent debugging
const uint32_t cs_require_lv = 0x2000; // Library Validation
const uint32_t cs_runtime = 0x10000;   // hardened runtime
if ((csFlags & (cs_hard | cs_require_lv)) {
return Yes; // Accept connection
}

Tip

AWS ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°:HackTricks Training AWS Red Team Expert (ARTE)
GCP ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training GCP Red Team Expert (GRTE) Azure ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks μ§€μ›ν•˜κΈ°