Hash MD5通过PHP显示不同于Unix终端的结果

时间:2016-10-06 18:33:46

标签: php linux unix hash terminal

目标

我尝试使用他们尝试访问的用户设备mac + URI 进行哈希

试过

我在 Mac OS 上尝试了终端

echo -n "00:00:11:22:33:44||http://www.bunlongheng.com" | openssl dgst -md5 -binary | base64 | tr -d "=" | tr "+/" "-_"

我得到了

QNyia8Q2VvKNJapAAVfXQw

我在php中试过它

$client_mac = Session::get('client_mac');
$original_uri = Session::get('original_uri');
$clean_uri = urldecode($original_uri);
$cmd = 'echo -n "'.$client_mac.'||'.$clean_uri.'" | openssl dgst -md5 -binary | base64 | tr -d "=" | tr "+/" "-_"';

//cmd = echo -n "00:00:11:22:33:44||http://www.bunlongheng.com" | openssl dgst -md5 -binary | base64 | tr -d "=" | tr "+/" "-_"

$clean_url_hash = exec($cmd);
//$clean_url_hash = t7Xnq9ClfRWciqFAYXbu7g

我尝试了exec()shell_exec() - 结果相同。

我得到了

t7Xnq9ClfRWciqFAYXbu7g

结果

终端

  

QNyia8Q2VvKNJapAAVfXQw

PHP

  

t7Xnq9ClfRWciqFAYXbu7g

为什么?任何想法,任何人?

更多细节

详细介绍PHP功能

public function forward(){

    $cp_host = env('CAPTIVE_PORTAL_HOST');
    $client_mac = Session::get('client_mac');
    $original_uri = Session::get('original_uri');
    $clean_uri = urldecode($original_uri);

    $cmd = 'echo -n "'.$client_mac.'||'.$clean_uri.'" | openssl dgst -md5 -binary | base64 | tr -d "=" | tr "+/" "-_"';

    $clean_url_hash = exec($cmd);

    //dd($clean_url_hash); <--- I got t7Xnq9ClfRWciqFAYXbu7g
    //dd(get_defined_vars());

    Session::put('c_'.$clean_url_hash,$original_uri);
    Session::put('clean_url_hash',$clean_url_hash);
    return Redirect::to($cp_host.'fbwifi/auth?c='.$clean_url_hash);

}

变量函数的值

dd(get_defined_vars()); will return 

array:6 [▼
  "cp_host" => "http://localhost:8888/"
  "client_mac" => "00:00:11:22:33:44"
  "original_uri" => "http%3A%2F%2Fwww.bunlongheng.com"
  "clean_uri" => "http://www.bunlongheng.com"
  "cmd" => "echo -n "00:00:11:22:33:44||http://www.bunlongheng.com" | openssl dgst -md5 -binary | base64 | tr -d "=" | tr "+/" "-_""
  "clean_url_hash" => "t7Xnq9ClfRWciqFAYXbu7g"
]

1 个答案:

答案 0 :(得分:2)

您可以使用PHP函数生成相同的哈希,无需shell调用。

像这样:

$hash = rtrim(base64_encode(md5("00:00:11:22:33:44||http://www.bunlongheng.com", true)),'=');
// QNyia8Q2VvKNJapAAVfXQw

工作示例:https://3v4l.org/KkR9v