PHP_Code_Challenge-5-sha1散列

题目

<?php
if (isset($_GET['name']) and isset($_GET['password'])) {
    if ($_GET['name'] == $_GET['password'])
        echo '<p>Your password can not be your name!</p>';
    else if (sha1($_GET['name']) === sha1($_GET['password']))
      die('Flag: '.$flag);
    else
        echo '<p>Invalid password.</p>';
}
else{
    echo '<p>Login first!</p>';
}
?>

分析

需要满足

  1. $_GET['name'] !== $_GET['password']
  2. sha1($_GET['name']) === sha1($_GET['password'])

知识点

sha1()

sha1 — 计算字符串的 sha1 散列值
sha1( string $str[, bool $raw_output = false] ) : string
str    输入字符串。 
raw_output    如果可选的 raw_output 参数被设置为 TRUE,那么 sha1 摘要将以 20 字符长度的原始格式返回,否则返回值是一个 40 字符长度的十六进制数字。 

emmm理解为与md5()作用类似吧

当有数组传入sha1()时,返回值为null

sha1()无法处理数组,返回null

解法

利用sha1()无法处理数组,返回null
name和password输入不同数组=>满足$_GET['name'] !== $_GET['password']
使sha1($_GET['name'])=NULLsha1($_GET['password'])=NULL=>满足sha1($_GET['name']) === sha1($_GET['password'])

posted @ 2020-03-23 14:09  雨九九  阅读(288)  评论(0编辑  收藏  举报