首页 > Web开发 > 详细

PHP_Code_Challenge-5-sha1散列

时间:2020-03-23 15:21:19      阅读:74      评论:0      收藏:0      [点我收藏+]

题目

<?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‘])
技术分享图片

PHP_Code_Challenge-5-sha1散列

原文:https://www.cnblogs.com/Rain99-/p/12551895.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!