secuinside ctfsecuinside.com/archive/2016/2016-2-7.pdf · 2016-07-13 · 취약점 •의도된...
TRANSCRIPT
SECUINSIDE CTFSolutions to Challenges
Challenges
• SBBS (Web 250pts)
• ByHuman (Pwnable 300pts)
• TrendyWeb (Web 100pts)
• CGC Challenges
SBBSWeb :: 250pts
Junsang Cheon [email protected]
SBBS - Overview
• Two Web Servers (Flask)
• Service Server (Challenges can access)
• Admin Server (Only administrator can access)
• Source code of admin server was provided
• XSS + Server Side Template Injection Vulnerabilities
SBBS - Structure
ServiceServer
AdminServer
Phantomjs
Database Fetch postWrite/Read post
Read post
Update post IF status is in 400 - 500
SBBS - VulnerabilityKey Variables
Vulnerable FUnction
SBBS - Vulnerability
• Make Phantomjs redirect to 404 page using below URLs
• location.href=“/{{ ‘’.__class__ }}”; —> <type ‘str’>
• /{{ ‘’.__class__.__mro__[-1].__subclasses__() }} —> a number of objects
• Challengers can see these responses
SBBS - Intended Solution
• Use ctypes methods of subclasses
• ctypes.CDLL._func_restype_.from_address(0x7effc7250370)
• 0x7effc7250370 is address of `title_404` variableit can be leaked by using `id` function
• `FLAG` is separated by about 26,000 bytes than `title_404`
SBBS - Intended Solution• Intended exploitation is similar with Blind SQL Injection
in memory using Server Side Template Injection
SBBS - Unintended Solution
• Use of specific object has `__builtins__` property
• __builtins__ has `__import__` function which can import any python packages
• ‘’.__class__.__mro__[-1].__subclasses__()[121]()._module.__builtins__[‘__import__’](‘admin.app’).FLAG
• I couldn’t filter challengers’ payloads well…
ByHumanPwnable :: 300pts
Yonghwi Jin [email protected]
Concept• 소스코드만 주었음
• 퍼징과 오디팅의 차이가 궁금했음
• 컴파일 환경이 달라도 동작하는 공격코드 요구
소스코드• 639 줄의 C++ 소스코드
• 바이너리 내의 함수 위치가 랜덤하게 바뀜
• 바이너리가 컴파일 할때마다 다름
프로그램 동작• 명령을 받아서 연산 수행 후 출력
• 자료형: Number/String/Storage(key-value)
• 명령: 숫자 지원, 변수 선언, 출력, 서브루틴, …
• 선언된 변수를 각각 고유번호로 참조할 수 있음
• 키-값 저장소의 키는 문자열이여야 함
취약점• typedef std::unique_ptr<Item> ItemPtr;
취약점• 키-값 저장소의 값 지정 시 (OP_SET)
key가 문자열(STRING)이 아니면 선언된 key, value 둘 다 free 됨
취약점 요약• C++11 스마트 포인터의 부적절한 사용으로 인한
Use-After-Free
Exploit• Use-After-Free 후에도 값 참조가 가능함
• 프로그램 흐름 조정
• C++이므로 vftable 조작을 통해 EIP 변경 가능
• 바이너리 및 임의 메모리 유출
• 여러 방법으로 쓸 수 있음
• (ex) String 클래스의 ptr, length 멤버 조작
TrendyWebWeb :: 100pts
Yonghwi Jin [email protected]
Concept• wget 1-day를 바로 찾아낼 수 있는가 (혹은 알고 있는가)
프로그램 동작• PHP로 된 소스코드를 줬음 (46줄)
• parse_url 리턴값의 path가 /avatar.png인 경우에만 파일을 /data/<랜덤id>/ 에 다운로드 가능함
프로그램 동작2• 다운로드는 wget 커맨드로 아래와 같이 함
• /usr/bin/wget <escaped URL>
• 이후 세션 정보를 /data/<랜덤id>/pickle에 저장 (serialize)
• 스크립트 시작 시 세션 파일이 있으면 로딩함 (unserialize)
취약점• 의도된 취약점
• wget은 원래 맨 마지막 / 뒤의 파일명으로 파일을 다운받게 되어있으며 HTTP 리다이렉트 후에도 첫번째 파일명으로 다운로드됨
• FTP는 안 그랬음 (CVE-2016-4971)
• 따라서 임의의 파일명으로 파일을 다운로드 할 수 있음
취약점• 의도된 풀이 (1-day + race condition)
• 이미지 다운로드 후 해당 폴더의 pickle에 현재 세션의 데이터를 저장함
• 이미지 다운로드 중 파일명을 조작하여 pickle로 해당 데이터를 조작한 후 세션 기록 전에 한번 더 같은 세션으로 요청을 보내서 임의의 데이터를 unserialize 하게 유도함
• unserialize 후 공격할 수 있는 클래스는 제공함
취약점• 의도치 않은 풀이 1 (1-day)
• pickle 파일 외에도 .php 확장자의 파일을 다운로드해서 풀 수 있었음 (php 실행 불가능하게 설정해야했음)
취약점• 의도치 않은 풀이 2 (parse_url bypass)
• path는 ? 뒤의 문자를 검사 안함
• wget은 ? 뒤의 문자까지 경로에 포함시켜서 파일을 다운받음
• /avatar.png?.php로 하면 path는 /avatar.png 이고 query가 .php가 됨
• php 파일 업로드 후 실행
CGC ChallengesCGC
Hwiwon Lee [email protected]
What is CGC?
• Fully automated computer security challenge by DARPA
• https://www.cybergrandchallenge.com/
• https://github.com/cybergrandchallenge
In DEFCON 2016 Quals
https://legitbs.net/statdump_2016/challenges.html
What is DECREE?
• DARPA’s Cyber Grand Challenge uses a new computing environment, the DARPA Experimental Cyber Research Evaluation Environment.
• It has some properties that make it excellent for binary reverse engineering, patching, and exploitation contests.
• http://repo.cybergrandchallenge.com/boxes/
How to make CGC Binary?
• In DECREE,
How to make CGC Binary?• And make,
http://cgc-docs.legitbs.net/cgc-release-documentation/walk-throughs/building-a-cb/
CGC CTF?
• Like DEFCON 2016 Quals, it needs the following.
• DECREE or Docker(with compiled cgc binaries and testing tools)
• Codes with some vulnerabilities
• Wrappers that recv&send PoV|CB&Result(or FLAG)
DECREE or Docker
• I decided to use DECREE as testing server
• Port forwarding rule must be set
• VBoxManage controlvm run_crs_##_## natpf1 cykor1,tcp,0.0.0.0,31338,,31338
• python wrapper.py 31338 (crs@virtualbox)
Codes with some vulns
• Patching point must be included
Codes with some vulns
• And make,
Wrappers
• 2 types
• For PoV (XML or CGC Binary)
• For Patched Binary
Wrappers
• For PoV
• Support 2 types (XML or CGC Binary)
• Get PoV and then TEST
• cb-test —negotiate —xml pov_filename —directory path —failure_ok —should_core —cb cb
Wrappers
• For Patched Binary
• Get patched binary
• Do some test (CGC type, Poller, …)
• cb-test —negotiate —xml pov_filename —directory path —cb cb
Wrappers
CYKOR_00001 & patch
• Stack based buffer overflow
• Type1 PoV (Control EIP and a general purpose register)
CYKOR_00001
CYKOR_00001
CYKOR_00001 PoV
CYKOR_00001 PoV
CYKOR_00001 Patch
CYKOR_00002 & patch
• Null pointer dereference
• Just crash (like CQE)
CYKOR_00002
CYKOR_00002
CYKOR_00002 PoV
CYKOR_00002 PoV
CYKOR_00002 Patch
Thank you