SQLI 복습

2021. 3. 23. 22:130x0B Web Hacking

728x90

나른한 화요일 퇴근 후, SQLI 복습을 위해 꺼내든 문제 

Portswigger (aka. burp suite) 

Lab Name
SQL Injection attack, listing the database contents on non-Oracle databases

아래의 테이블에서 주 키워드를 뽑아내면 다음과 같다.

1. product 카테고리에 UNION 어택을 사용하라.

2. 해당 서버에 특정 DB 테이블을 찾아서 administrator 정보를 얻어 로그인에 성공하라.

This lab contains as SQL injection vulnerability in the product category filter.
The results from the query are returned in the application's response so you can use a UNION attack to retrieve data from other tables.
The application has a login function, and the database contains a table that holds usernames and passwords.
You need to determine the name of this table and the columns it contains, then retrieve the contents of the table to obtain the username and password of all users.
To solve the lab, log in as the administrator user.

 

문제 파악 

여러 카테고리가 존재하며, 카테고리에 맞춰 검색하는 기능을 부여하고 있다. 하지만, product 카테고리는 식별되지 않고 있다. 

product 카테고리는 숨겨진 기능이라 유추 가능하다. 

union attack의 기본인 null 갯수를 늘려가며 주어진 테이블의 column을 파악하는 행위를 끝낸 후 서버에서 사용하는 모든 DB 테이블 명을 살펴보기 위해 information_scheme.tables를 사용하였다.
product '%20+union+select+NULL,table_name+from+information_schema.tables--

그 이후, information_schema.columns를 통해 의심되는 table명을 통해 결과 도출을 시도하였다.
product '%20+union+select+NULL,column_name+from+information_schema.columns+where+table_name=''

수많은 시행착오를 거치고 users_qnbmep 테이블이 username_katgvg와 password_xincgr를 소지하고 있음을 확인할 수 있었다.

약간의 게싱성이 있는 테이블명이었다고 생각된다.

 

두번째 문제 

Lab Name
SQL injection attack, listing the database contents on Oracle 

이번문제는 MS가 아닌 Oracle sql 구문에 대한 문제로 보여진다.

 

아래의 테이블에서 키워드를 뽑아내면, 다음과 같다.

1. 이전과 동일하게 product 카테고리에서 취약점이 발생한다.

2. UNION attack은 여전히 사용된다. 

3. username / password가 존재하는 테이블을 찾아서 administrator로 로그인하라.

This lab contains an SQL Injection vulnerability in the product category filter.
The results from the query are returned in the application's response so you can use a UNION attack to retrieve data from other tables.
The application has a login function, and the database contains a table that holds usernames and passwords.
You need to determine the name of this table and the columns it contains, then retrieve the contents of the table to obtain the username and password of all users.

To solve the lab, log in as the administrator user.

 

ORACLE SQLI는 information_schema.tables 대신 dba_tab_cols를 사용할 수 있다.

이전 문제처럼 users~~~로 찾으면 된다.

ref. docs.oracle.com/en/database/oracle/oracle-database/18/refrn/DBA_TAB_COLS.html#GUID-857C32FD-AE30-4AB9-811B-AC3A7B91A04D

product' union+select+table_name,column_name%20from+dba_tab_cols--

product' union+select+column_name,NULL%20from+dba_tab_cols+where+table_name='??'--

Intend를 참고해보니, all_tables라는 쉬운 키워드가 있었다.

 

Lab Name
Blind SQL Injection with conditional responses

다음 문제는 Blind SQL Injection이다.

 

이전 문제와 마찬가지로 키워드를 먼저 추려내보자.

1. Blind SQL Injection

2. Having a cookie 

3. 쿼리에 따라 메시지 유무가 다름 

4. users라는 테이블에 username, password 라는 컬럼을 소유하고 있다.

This lab contains a blind SQL injection vulnerability. 
The application uses a tracking cookie for analytics, and performs an SQL query containing the value of the submitted cookie.
The results of the SQL query are not returned, and no error messages are displayed. 
But, the application includes a "Welcome back" message in the page if the query returns any rows.

The database contains a different table called users, with columns called username and password.
You need to exploit the blind SQL injection vulnerability to find out the password of the administrator user.

To solve the lab, log in as the administrator user.

cookie가 존재한다기에 쿠키부터 확인해보았다.

2개의 쿠키 중 session은 볼 필요 없고 TrackingId가 의심된다.

Description에서 본 것과 같이, Welcome back! 문자열이 출력되는 것으로 보아 알 수 없는 암호화 데이터 TrackingId의 Value는 올바른 쿼리임을 알 수 있다.

Blind SQL Injection은 쿼리 결과 유무에 따라 참/거짓을 분별할 수 있는 어떠한 '키워드'를 통해 공격을 해나가는 방법이다. 

TrackingId를 아무렇게나 조작해보면 이런 화면이 뜨게된다.

 

 

constant는 해당 서버에 없는 쿼리이기에 이렇게 뜨게 된다. 2차 검증을 위해 실제 쿼리를 넣어본다.

1' or '1'='1

Blind SQL Injection은 코드를 작성해야한다.

현재 알고 있는 정보는 username, password라는 컬럼이 존재한다는 것이다. 그리고 administrator라는 아이디 정보는 가지고 있다.

 

administrator의 패스워드 길이를 살펴보고,  administrator의 패스워드 인덱스들을 살펴보아야한다. 

 

To be continue....