macOS Perl security testing and hardening. Use this skill whenever the user needs to test for Perl-based privilege escalation on macOS, analyze PERL5OPT/PERL5LIB environment variable abuse, check for @INC path vulnerabilities, or assess CVE-2023-32369 (Migraine) SIP bypass risks. Also use for hardening recommendations and security audits of Perl applications on macOS systems.
Instrucciones de origen · Vista previa de solo lectura
name
macos-perl-injection
description
macOS Perl security testing and hardening. Use this skill whenever the user needs to test for Perl-based privilege escalation on macOS, analyze PERL5OPT/PERL5LIB environment variable abuse, check for @INC path vulnerabilities, or assess CVE-2023-32369 (Migraine) SIP bypass risks. Also use for hardening recommendations and security audits of Perl applications on macOS systems.
macOS Perl Injection & Hardening
A skill for security professionals to test, analyze, and harden Perl applications on macOS against environment variable injection and privilege escalation attacks.
When to Use This Skill
Use this skill when:
Testing macOS systems for Perl-based privilege escalation vectors
Auditing Perl applications for environment variable injection risks
Investigating CVE-2023-32369 (Migraine) vulnerability status
Hardening macOS systems against Perl injection attacks
Vulnerability:/Library/Perl/5.30 exists, is NOT SIP-protected, and appears BEFORE protected /System/Library paths.
Attack scenario:
Gain root access
Write malicious module to /Library/Perl/5.30/File/Basename.pm
Any script using use File::Basename; loads attacker code first
Warning: macOS shows TCC prompt for Full Disk Access when writing to /Library/Perl.
4. CVE-2023-32369 "Migraine" SIP Bypass
Vulnerability:systemmigrationd daemon has com.apple.rootless.install.heritable entitlement. Child processes inherit this and run outside SIP restrictions.
Affected versions: macOS before Ventura 13.4, Monterey 12.6.6, Big Sur 11.7.7
Exploitation flow:
# As root, poison environment
launchctl setenv PERL5OPT '-Mwarnings;system("/private/tmp/migraine.sh")'# Trigger systemmigrationd to spawn Perl
open -a "Migration Assistant.app"# Or programmatically:# /System/Library/PrivateFrameworks/SystemMigration.framework/Resources/MigrationUtility
Result:/usr/bin/perl executes with malicious PERL5OPT in SIP-less context, allowing:
Writing to /System/Library/LaunchDaemons
Setting com.apple.rootless extended attributes
Any other SIP-restricted operations
Testing Procedures
Quick Environment Check
Run the helper script to assess current Perl environment:
./scripts/check-perl-env.sh
This checks:
Current PERL5OPT, PERL5LIB, PERL5DB values
@INC paths and their writability
Perl version and taint mode status
System version for CVE-2023-32369 applicability
Module Hijacking Test
./scripts/test-inc-paths.sh
This identifies writable paths in @INC that could be exploited.
CVE-2023-32369 Status Check
./scripts/check-migraine-vuln.sh
Determines if the system is vulnerable to the Migraine SIP bypass.
Hardening Recommendations
1. Clear Dangerous Environment Variables
Privileged processes should start with pristine environments:
# For launchd jobs, add to plist:
<key>EnvironmentVariables</key>
<dict>
<key>PERL5OPT</key>
<string></string>
<key>PERL5LIB</key>
<string></string>
<key>PERL5DB</key>
<string></string>
</dict>
# Or explicitly unset:
launchctl unsetenv PERL5OPT
launchctl unsetenv PERL5LIB
launchctl unsetenv PERL5DB
# For cron jobs, use env -i:env -i /usr/bin/perl /path/to/script.pl
2. Use Taint Mode for Privileged Scripts
Add -T flag to force taint checking, which ignores unsafe switches:
#!/usr/bin/perl -T
use strict;
use warnings;
# ... rest of script
Or in shebang:
#!/usr/bin/perl -T -w
3. Avoid Running Interpreters as Root
Use compiled binaries when possible
Drop privileges early in scripts
Run interpreters as unprivileged users with minimal permissions
4. Keep macOS Updated
CVE-2023-32369 is patched in:
macOS Ventura 13.4+
macOS Monterey 12.6.6+
macOS Big Sur 11.7.7+
5. Monitor @INC Paths
Regularly audit @INC paths for writable directories: