Blog

보안 코딩 기법: Zip 라이브러리의 기본 동작으로 인해 원격 코드 실행이 발생할 수 있습니다.

November 13, 2017
Pieter De Cremer

이번 주에는 Zip 라이브러리의 기본 동작에 대해 이야기하겠습니다.응용 프로그램 개발자라면 이전에 이 기능을 사용해 보셨을 가능성이 큽니다.인터넷을 통해 다운로드되는 대부분의 리소스는 zip 형식이므로 의미가 있습니다. 압축된 데이터는 크기가 작기 때문에 다운로드 속도가 빠르고 대역폭을 적게 소비합니다.

좀 더 구체적인 예를 원한다면 게임용 텍스처, 키보드 자동 완성을 위한 언어 팩,...많은 리소스가 애플리케이션과 함께 자동으로 번들로 제공되지 않고 나중에 다운로드됩니다.

그러나 이 기능을 사용할 때는 주의해야 합니다. zip 아카이브의 파일 이름에 경로 탐색 정보가 포함될 수 있습니다.압축을 풀면 의도한 디렉토리 외부에 파일이 생성될 수 있습니다.이는 주로 기존 파일을 덮어쓰기 위한 목적으로 수행됩니다.

Zip Archives

다음 두 파일이 들어 있는 zip 아카이브가 있다고 가정해 보겠습니다.

파일 1
../파일2

이 아카이브를 추출하면 unzip 디렉터리에서 우리가 예상한 위치인 file1이 추출됩니다.하지만 file2는 zip 라이브러리에 아카이브의 압축을 풀도록 요청한 위치보다 한 디렉토리 위에 기록되었습니다.

따라서 zip 라이브러리가 이 문제를 제대로 처리하지 못하면 공격자가 시스템에 임의의 파일을 쓸 수 있으므로 주의하십시오.라이브러리가 안전한지 항상 확인하십시오. 이 규칙은 모든 라이브러리에 적용되지만, 특히 이러한 유형의 파일에 대해서는 zip 라이브러리의 기본 동작을 확인하는 것이 좋습니다.

Android에서 이 케이스가 제대로 처리되지 않을 때 어떤 결과가 발생하는지 설명해 보겠습니다.Android에서는 자바 Zip 라이브러리 (java.util.zip) 가 사용되며, 라이브러리는 기본적으로 위에서 설명한 대로 경로 탐사를 허용합니다.

Android Dalvik 실행 가능 형식 (.dex) 에는 단일 파일에 포함할 수 있는 클래스 수에 제한이 있습니다.클래스가 더 필요한 앱은 API 레벨 21 (Android 5.0 Lollipop) 이후 추가된 MultiDex 지원 라이브러리를 사용할 수 있습니다.이 라이브러리는 애플리케이션의 데이터 디렉터리에 보조.dex 파일을 저장합니다. 이 디렉터리는 앱 사용자가 쓸 수 있으며.dex 파일이 필요할 때 이 코드가 로드되어 실행됩니다.

즉, 공격자는 악의적인 zip 아카이브를 사용하여.dex 파일을 덮어써서 수정할 수 있으며, 심지어 이 파일이 로드되고 실행되어 원격 코드 실행에 취약해질 수 있습니다.이는 단순한 이론적인 예가 아니라 앱 스토어에서 1억 건 이상의 다운로드를 기록한 My Talking Tom 앱에서도 입증되었습니다.다음은 Black Hat에서 선보인 익스플로잇의 동영상입니다.

Talking Tom

항상 zip 라이브러리의 동작을 확인하여 안전하지 않은지 확인하십시오.zip 라이브러리에서 경로 탐색을 비활성화할 수 없는 경우 추출하기 전에 각 항목의 이름을 확인해야 합니다.이름은 정규화해야 하며 결과 경로는 아카이브를 추출하려는 디렉터리에 있어야 합니다.이 작업을 진행하는 동안 압축 폭탄이 발생하지 않도록 압축을 푼 아카이브의 전체 크기도 확인해야 합니다. 하지만 이 글은 앞으로 일주일 동안 게시할 예정입니다.

원하신다면 패스 트래버설에서 몇 가지 챌린지를 플레이하세요 또는 보안 코딩 기술을 테스트하고 싶다면 당사 플랫폼을 확인하세요.

다음에 만나요. 보안 코드 또는 노 코드 기억하세요!

- 이름 앞에 임의의 숫자가 "../“인 파일을 삽입할 수 있습니다.
- zip 라이브러리가 이 경우를 제대로 처리하지 않으면 의도한 추출 디렉토리 외부에서 쓸 수 있습니다.
- zip 파일을 신뢰할 수 없는 경우 공격자에게 임의 쓰기 취약점이 생깁니다.

https://www.blackhat.com/docs/ldn-15/materials/london-15-Welton-Abusing-Android-Apps-And-Gaining-Remote-Code-Execution.pdf

태그라인

Govern AI-driven development before it ships

Measure AI-assisted risk, enforce secure coding policy at commit, and accelerate secure delivery across your SDLC.

book a demo
태그라인

Explore more blogs

우리는 이 방법을 잘 알고 있습니다. 우리는 이 두 가지 축복을 골고루 살기 위해 노력하고 있습니다.

browse all
Case Study
Filter Label
This is some text inside of a div block.

Supercharged Security Awareness: How Tournaments are Inspiring Developers at Erste Group

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Learn More
Case Study
Filter Label
This is some text inside of a div block.

Security as culture: How Blue Prism cultivates world-class secure developers

Learn how Blue Prism, the global leader in intelligent automation for the enterprise, used Secure Code Warrior's agile learning platform to create a security-first culture with their developers, achieve their business goals, and ship secure code at speed

Learn More
Case Study
Filter Label
This is some text inside of a div block.

One Culture of Security: How Sage built their security champions program with agile secure code learning

Discover how Sage enhanced security with a flexible, relationship-focused approach, creating 200+ security champions and achieving measurable risk reduction.

Learn More
Blog
Filter Label
This is some text inside of a div block.

Enabler 7: Developer Recognition

Recognition fuels participation. Enabler 7 celebrates developer achievement loudly, with rewards and exclusive swag that mark real, earned secure coding wins.

Learn More
Blog
Filter Label
This is some text inside of a div block.

Named in the Gartner® Hype Cycle™ for Application Security 2026

Secure Code Warrior is named in the Gartner® Hype Cycle™ for Application Security, 2026 for Agentic Coding Security and Secure Coding Training. Here's why.

Learn More
Blog
Filter Label
This is some text inside of a div block.

Are you a CISO or Engineering Leader worried about the Security and Cost of LLM code generation?

Review the SCW AI Trust Index, our proprietary LLM benchmarking data, before going all-in on an AI model.

Learn More

Secure AI-driven development before it ships

See developer risk, enforce policy, and prevent vulnerabilities across your software development lifecycle.

데모 예약하기
No items found.