WEB] Double encoding

노션으로 옮김·2020년 3월 6일
1

skills

목록 보기
7/37
post-thumbnail

개요

OWASP - double encoding 문서를 보며 정리하는 글이다.

정의

페이로드를 더블 인코딩하여 인젝션하는 기법이다.
LFI나 XSS 등의 공격을 할 때, 서버에서 필터링 루틴이 존재할 때 이를 우회하기 위해 사용한다.

This attack technique consists of encoding user request parameters twice in hexadecimal format in order to bypass security controls or cause unexpected behavior from the application. It’s possible because the webserver accepts and processes client requests in many encoded forms.

주의할 점은, 단순히 URL 인코딩을 두번 하는 것이 아니라

  1. hex로 변환 후
  2. url encoding
    의 순서로 진행해야 한다.

예를 들어, ../는 다음과 같이 인코딩 된다.

The hexadecimal encoding of “../” represents “%2E%2E%2f”
Then encoding the “%” represents “%25”
Double encoding of “../” represents “%252E%252E%252F”

원리

취약점이 발생하는 이유를 간단히 살펴보겠다.

Stackoverflow - When and why does bypassing XSS sanitizers with double encoding work?

예시코드이다.

$input = htmlentities($_GET["query"]);
echo urldecode($input);

htmlentities<, >같은 html 문법으로 인식될 수 있는 특수문자를 일반 문자열로 변환시키는 함수이다.
흔히 XSS 필터로 사용한다.

하지만, 그 후 URL 디코딩을 거치기 때문에 double encoding된 페이로드가 원상태로 복구되어 실행될 수 있는 것이다.

0개의 댓글