'file download'에 해당되는 글 2건

반응형

파일 다운로드 취약점이 발생되었을 때 DB에 접근할 수 있는 정보 혹은 업로드하는 파일의 소스코드를 봐서 FU 취약점이 발생될 수 있는지를 확인한다. 이 때 Spring Framework에서 Controller의 위치를 한번에 알 수 있는 방법이 있는지에 대해 공부한 일련의 과정을 정리해둔다.


※ View 위치 찾기

1. /WEB-INF/web.xml

 (1) Spring에서 MVC를 구현하기 위한 Dispatcher Servlet을 찾는다.

 (2) Dispatcher Servlet에 포함되어 URL Mapping을 담당하고 있는 servlet-context.xml의 경로를 찾는다.


그림1. /WEB-INF/web.xml (출처 : https://all-record.tistory.com/165?category=733072)


◎ 만약 위와 같이 servlet-context.xml이 존재하지 않은 경우

contextConfigLocation 초기화 파라미터를 설정하지 않은 경우, DispatcherServlet은 WEB-INF/[서블릿이름]-servlet.ml 파일을 설정파일로 사용한다.


2. servlet-context.xml 경로

 (1) Controller에 의해 리턴된 View를 찾아주는 ViewResolver를 찾는다.

 (2) 해당 ViewResolver의 속성인 prefix와 suffix를 통해 내가 요청한 URL의 view page가 어디인지 찾는다.


그림2. servlet-context.xml (출처 : https://all-record.tistory.com/165?category=733072)



※ Controller 위치 찾기

view는 찾기 쉽지만 우리가 원하는 실제 코드는 controller에 있다. 이를 찾기 위해서는 우리가 URL에 입력한 것이 각 controller의 @RequestMapping Annotation에 있는지를 찾아야 한다.


그렇다면 각 controller의 파일명을 알 수 있는 방법이 있을까?

정확하지는 않지만 일단 지금까지의 결론은 다음과 같다.


1. web-xml에 dispatcherServlet을 등록함

2. dispatcherSerlvet 안에 <annotation-driven />과 함께 component-scan을 통해 패키지 안에 @controller라고 적어둔 annotation을 기준으로 컨트롤러를 스캔한다.

3. 이후 요청은 스캔한 컨트롤러들을 기준으로 동작한다.


결론 : 모든 컨트롤러가 적혀있는 특정 파일은 존재하지 않다.


추가적으로 더 알게된 내용이 있으면 추가하겠음.


참고 ) 

이론 : https://all-record.tistory.com/165?category=733072

실제 파일 위치들 예제 : http://pgm-progger.blogspot.com/2014/01/spring-base-setting.html

반응형

'Hacking > Web' 카테고리의 다른 글

tar 명령어 이용 시 주의사항  (0) 2019.08.11
Indirect SQL Injection  (0) 2019.08.11
MYSQL load_file & into outfile  (0) 2019.06.28
[JAVA] AES256 decrypt Code  (0) 2019.04.25
[Websec.fr] level 8 Writeup  (0) 2019.04.11
블로그 이미지

rootable

,
반응형

mysql에서는 SQL Injection을 통해 파일 다운로드 취약점, 파일 업로드 취약점으로 나아갈 수 있는 방법이 있다. 이는 바로 load_file 구문과 into outfile 구문을 이용하는 것이다.

해당 구문을 이용한 취약점에 대해서는 구글링할 것을 추천하고 해당 포스팅에서는 SQL Injection 이후 해당 구문들을 사용할 수 있는지 확인하는 것에 포커스를 두었다.


1. SQL Injection을 통해 DB 정보 획득

 - user명 : select user();

 - version 정보 : select @@version;


만약 버전 5.1.17 이상이라면 file-priv 옵션이 존재하므로 load_file과 into outfile을 진행하기 위해서는 해당 옵션이 현재 user에 Y로 설정되어있는지 확인이 필요함.


- file-priv 옵션 : select user, file_priv from mysql.user;

만약 file_priv 값이 N으로 설정되어 있다면 load_file과 into outfile은 불가하다.



2. secure-file-priv

 - 현재 user에게 file-priv 옵션이 Y로 지정되어있다라도 secure-file-priv 옵션이 지정되어있으면 해당 디렉토리 이외에는 읽기/쓰기가 불가능하다.


ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement


만약 위와 같은 에러가 떴다면, 이는 secure-file-priv로 지정한 디렉토리 이외의 디렉토리에 존재하는 파일을 읽거나 쓰려고 했기 때문이다.


 - MYSQL 5.6.34 이후의 버전에서는 보안 문제로 인해 secure-file-priv 옵션이 지정되어 있지 않을 경우에도 위와 같은 에러문이 출력되며 load_file과 into outfile 구문을 사용할 수 없다.


 secure-file-priv 확인 방법

 * 명령어 :  SHOW VARIABLES LIKE 'secure_file%';

 * 옵션 설정 파일 예시

   - 리눅스 :  /etc/my.cnf  or /etc/mysql/my.cnf

   - 윈도우 : C:\ProgramData\MySQL\MySQL Server 5.6\my.ini


반응형

'Hacking > Web' 카테고리의 다른 글

Indirect SQL Injection  (0) 2019.08.11
Controller Location In Spring Framework  (0) 2019.07.29
[JAVA] AES256 decrypt Code  (0) 2019.04.25
[Websec.fr] level 8 Writeup  (0) 2019.04.11
[websec.fr] level 25 writeup with parse_url bug  (0) 2019.04.07
블로그 이미지

rootable

,