首页 > 解决方案 > 两个字符串之间的 sha256 哈希冲突

问题描述

我必须找到两个作为参数'str1'和'str2'在URL中传递并满足这些条件的字符串?

if($_GET['str1'] !== $_GET['str2'] and $_GET['str1'] and $_GET['str2']) 
{
    $hash1 = hash('sha256', $salt . $_GET['str1']);
    $hash2 = hash('sha256', $salt . $_GET['str2']);

    if($hash1 === $hash2) {
       #print str1 and str2
    }

}

我将如何发现?

标签: phpencryptionhashsha256sha

解决方案


唯一可能的解决方案是使散列函数不起作用。
散列函数需要字符串输入(或类型转换为字符串),因此将输入作为数组将破坏散列并且两者都返回假/不工作。
这意味着两者是完全相同的。

这是一个作弊,但它满足当前代码的所有部分。

<?php
$_GET['str1'] = ["a"];
$_GET['str2'] = ["b"];
$salt = "aaabdnelnFnekknfn";

if($_GET['str1'] !== $_GET['str2'] and $_GET['str1'] and $_GET['str2']) 
{
    $hash1 = hash('sha256', $salt . $_GET['str1']);
    $hash2 = hash('sha256', $salt . $_GET['str2']);

    if($hash1 === $hash2) {
       var_dump($_GET['str1'],$_GET['str2']);
    }

}

https://3v4l.org/SPYKb


推荐阅读