
오픈 소스 도구와 약간의 코드만으로 유용하고 가벼운 정적 분석을 만드세요.
이 저장소는 ShellCon 2019 발표인 "직접 만들기: 커스텀 경량 정적 분석 도구 작성 방법"(슬라이드)의 PoC 코드를 포함합니다.
간단히 말해, 이 저장소는 오픈 소스 도구와 약간의 커스텀 코드를 사용하여 흥미로운 정적 분석을 구축하는 방법에 대한 몇 가지 구체적인 예를 보여줍니다.
이 저장소의 코드 예제:
before_action들을 파악합니다.예제 동작 방식
높은 수준에서 예제 구현은 다음과 같이 동작합니다:
이 프로젝트는 Docker를 사용하여 실행하도록 만들어졌습니다.
그렇게 하려면 먼저 몇 가지를 설정해야 합니다.
우리의 Dockerfile은 GitHub 패키지 레지스트리에 호스팅된 semantic Docker 이미지를 기반으로 하므로, GitHub Package Registry와 함께 Docker를 사용하도록 구성해야 합니다.
$ docker login docker.pkg.github.com -u USERNAME -p TOKENdocker build -t lightweight_static_analysis .bash 셸을 실행한 다음 스크립트를 실행합니다.# Run this
# (Make sure to run this from a terminal in this repo's project root)
$ docker run -it --rm --entrypoint /bin/bash -v $PWD:/lightweight_static_analysis lightweight_static_analysis
# cd into this project's source code within the
# running container
$ cd /lightweight_static_analysis
# Run main.py with different config options, described further below
Docker 컨테이너에서 bash 셸을 사용할 수 있게 되면(위의 docker run 명령 참조), 몇 가지 모드 중 하나로 main.py를 실행할 수 있습니다.
/lightweight_static_analysis> $ python3 src/main.py <options>
옵션 없이 src/main.py를 실행하거나 main.py의 parser.add_argument 부분을 보면 사용 가능한 모든 옵션을 확인할 수 있습니다.
Rails 코드베이스를 대화형으로 탐색하는 데 도움이 되는 몇 가지 명령이 있습니다.
먼저 하나 이상의 Rails 저장소를 클론하여 examples/에 넣으세요. 예제 저장소가 필요하다면 rubygems.org의 소스 코드나 Open Source Rails에 등록된 저장소 중 하나를 사용할 수 있습니다.
# Print out the class, super class, defined methods, and before actions
# for all controllers
$ python3 src/main.py --rails-summarize-controllers examples/<repo_name>
# Print out every controller name, grouped by super class
#
# This can find examples where security protections defined in a parent class
# (e.g. ApplicationController or Api::BaseController) aren't applied because
# the vulnerable controller didn't subclass the appropriate class.
$ python3 src/main.py --rails-controllers-by-superclass examples/<repo_name>
# For every before_action used by any controller, list the controllers that
# use that before_action and the routes that it is and isn't applied to
# (e.g. handle the 'except' and 'only" keywords)
#
# This can:
# * Give you quick insight the various before_actions the application defines,
# yielding some intuition as to the code's flow and organization.
# * `verify_with_otp` - Hm, that sounds interesting, I probably want to
# review how that filter is implemented.
# * Show you where a given before_action is and isn't applied across an entire
# code base, potentially leading to bugs where it is inconsistently used
#
# For example
# * Is there a before_action that's used to protect all state0-changing API
# routes except for 1 model? That's strange.
# * Is there an authentication or authorization before_action applied to every
# action in a controller except one? Why?
$ python3 src/main.py --rails-controllers-by-before_action examples/<repo_name>
파싱이 완료된 후 ipdb REPL로 빠져나와 파싱된 Ruby 코드를 대화형으로 검사하고 싶다면, 위 명령어에 --repl 플래그를 함께 전달하면 됩니다.
이 예제들은 ast_node.py에 정의된 다양한 AstNode 클래스에 의존하며, Rails 관련 코드는 모두 ruby.py에 있습니다.
exec()를 통한 명령 주입 찾기이 구현은 아직 정리되고 문서화되지 않았습니다. main.py의 batch_parse_json()과 visitor.py의 visit() 및 그것이 호출하는 다른 메서드를 참조하세요.
이 작업에 대해 더 자세히 이야기하고 싶다면 언제든지 이슈를 열거나 Twitter로 연락주세요: @clintgibler, @defreez.
이 프로젝트와 우리가 작업하는 다른 프로젝트에 대한 소식을 받아보고 싶다면 tl;dr sec 뉴스레터를 확인하세요. 주요 보안 발표의 상세 요약과 최고의 보안 도구 및 리소스 링크를 보내드립니다.
낮은 빈도로 발행되는 고신호 뉴스레터로, 최신 보안 동향을 놓치지 않도록 도와드리며, 업무를 더 효율적이고 효과적으로 수행할 수 있게 하고 정보 보안 동료들과 나눌 유용한 이야깃거리도 제공합니다.