MacOS에서 터미널앱이 차단된 경우 (Gatekeeper disable 하기)

간만에 Arachni 소스를 좀 고쳐볼까 하고 보던 중 난감한 상황이 있었습니다. 언젠가부터 MacOS에서 앱스토어 출처가 아닌 어플리케이션 경우 기본적으로 실행을 차단하고 별도의 과정을 통해 실행할 수 있게 하고 있습니다.

이게 바로 MacOS의 보안 어플리케이션 중 하나인 Gatekeeper인데요. 보통은 Finder에서 우클릭 후 실행을 하면 열기 라는 버튼을 통해 활성화 시킬 수 있었습니다. 다만 저에겐 좀 애매한 경우가 있었는데, 앱은 승인을 해도 앱 내 포함된 dylib로 인해 차단되는거였죠..

./arachni
dyld: Library not loaded: /Users/zapotek/arachni-build-dir/arachni/system/usr/lib/libruby.2.2.0.dylib
  Referenced from: /Users/hahwul/HAHWUL/tool/arachni/bin/../system/usr/bin/ruby
  Reason: no suitable image found.  Did find:
 /Users/hahwul/HAHWUL/tool/arachni/bin/../system/usr/lib/libruby.2.2.0.dylib: code signature in (/Users/hahwul/HAHWUL/tool/arachni/bin/../system/usr/lib/libruby.2.2.0.dylib) not valid for use in process using Library Validation: library load disallowed by system policy
[1]    84989 abort      ./arachni

Why?

애플 개발자 문서에서 정책을 찾아보니 dyld는 기본적으로 차단한다고 합니다.

Typically, the Hardened Runtime’s library validation prevents an app from loading frameworks, plug-ins, or libraries unless they’re either signed by Apple or signed with the same team ID as the app. The macOS dynamic linker (dyld) provides a detailed error message when this happens. Use the Disable Library Validation Entitlement to circumvent this restriction. To add this entitlement to your app, first enable the Hardened Runtime capability in Xcode, and then under Runtime Exceptions, select Disable Library Validation.

해결방안

로드되는 Dyld 모두 허용처리하기

실행 시 차단된 Dyld들은 시스템 환경설정 > 보안 및 개인정보 보호 > 일반에서 별도로 내용이 나타나고, 예외 처리를 할 수 있습니다.

저도 처음엔 그렇게 하려고 했으나 처리해야할 파일이 너무 많아서 이 방법은 제외하고 사용할만한 방법을 찾아보았습니다.

Gatekeeper 비 활성화 후 실행하여 신뢰처리

가장 위험하지만, 가장 깔끔한 방법입니다. 일정 시간동안 게이트키퍼를 비활성화 시켜 모든 앱을 허용시킨 후 앱의 기능을 수행합니다. 그럼 신뢰받는 dyld로 보고 다시 활성화 되여도 재확인을 하지 않습니다. 아래와 같이 spctl 로 비활성화 시킵니다.

sudo spctl --master-disable

이후 앱을 실행하면 잘 실행됩니다. 여기서 하나 중요한점은, 실행 과정에서 필요한 dyld가 모두 로드되어야한다는건데, 즉 아래처럼 ./arachni 만 실행한 경우 실제로 스캔을 돌릴 때 또 에러가 나게 됩니다. (스캔에서 다시 필요한 dyld를 불러와서)

./arachni
Arachni - Web Application Security Scanner Framework v1.5.1
   Author: Tasos "Zapotek" Laskos <tasos.laskos@arachni-scanner.com>

           (With the support of the community and the Arachni Team.)

   Website:       http://arachni-scanner.com
   Documentation: http://arachni-scanner.com/wiki

 [-] Missing URL argument.

그래서 되도록이면 여러가지 루트로 어플리케이션에서 사용하는 dyld를 최대한 사용해주고, 다시 기능을 활성화합니다.

sudo spctl --master-enable