Home Nginx off by slash
Post
Cancel

Nginx off by slash

Nginx의 off by slash로 인한 보안설정으로 발생할 수 있는 취약점에 대해 알아봅시다.

off by slash

off by slash는 /로 닫지 않는 것을 의미합니다.
nginx의 설정 파일에 /를 닫지 않았을 때 어떤 취약점이 발생할 수 있는지 예제를 통해 알아봅시다.

Alias LFI Misconfiguration

nginx 설정 시 location 경로를 지정할 때 root 나 alias 를 설정할 수 있습니다.
둘다 nginx에서 특정 파일을 찾을 때 사용이 가능하며 이중 alias는 파일 경로를 변경하여 serving을 할 수 있는 기능입니다.

만약 위의 예시와 같이 off by slash가 되어 있다면 LFI가 가능합니다.
단 1단계 위로만 가능합니다.

예시 : /imgs../flag.txt

1
2
3
location /imgs { 
    alias /path/images/;
}
1
2
3
location /imgs/ { 
    alias /path/images/;
}

Bypass Nginx ACL Rules with Pathname Manipulation

Nginx는 우회를 방지하기 위해 경로 정규화를 수행한 후에 확인합니다.
그러나 백엔드 서버가 다른 정규화를 수행하는 경우(nginx가 제거하지 않는 문자를 제거하는 경우), 이 방어를 우회할 수 있습니다. 자세한 공격은 Hacktrick에서 확인 가능합니다.

1
2
3
4
5
6
7
location = /admin {
    deny all;
}

location = /admin/ {
    deny all;
}

Reference

  • https://domdom.tistory.com/346
  • https://book.hacktricks.xyz/pentesting-web/proxy-waf-protections-bypass