Saturday 6 April 2019

PHP Hash MD5 SHA256 File Recursive

Gambar mungkin berisi: teks

Karena Big Data itu besar, maka dibuatkan saja secara recursive untuk mensensus hash setiap file yang diupload user untuk kedepannya diolah menjadi pengetahuan tentang database virus baru oleh Bot Machine Learning.

#php #recursive #hash #md5 #sha256 #bigdata#MySQL #iamroot #iamMalwareHunter

Partial code in Gist GitHub: https://gist.github.com/ryanbekabe/5b13eaed7e9ca33af5f9e32ba853301f

----
//bekabeipa@gmail.com
if(isset($_GET['recursivehash']) AND isset($_GET['rest']))
{
//https://stackoverflow.com/questions/34190464/php-scandir-recursively
//https://stackoverflow.com/questions/15687363/php-access-global-variable-in-function
//global $varrest;
date_default_timezone_set('Asia/Jakarta');
$waktupengiriman=date("YmdHi");
$varpathtorecursive = ($_GET['recursivehash']);
$varrest = $_GET['rest']."-".$waktupengiriman;
function scandir_rec($root)
{
global $varrest;
// if root is a file
if (is_file($root)) {
echo '
  • '
  • . basename($root) . '
    ';
    return;
    }
    if (!is_dir($root)) {
    return;
    }
    $dirs = scandir($root);
    foreach ($dirs as $dir) {
    if ($dir == '.' || $dir == '..') {
    continue;
    }
    $path = $root . '/' . $dir;
    if (is_file($path)) {
    // if file, create list item tag, and done.
    $varmd5=hash_file('md5',$path);
    $varsha256=hash_file('sha256',$path);
    $varsize=filesize($path);
    $vartipe=filetype($path);
    echo '
  • file MD5 : '
  • .$varmd5.' - SHA256 : '.$varsha256.' - path - '.$path.' :' . $dir . '
    ';
    //mysql_query("INSERT INTO ryanfilelog(id, filename, md5, sha256, filesize, filetype, rest) VALUES(NULL,'$dir','$varmd5','$varsha256','$varsize','$vartipe','$varrest')");
    } else if (is_dir($path)) {
    // if dir, create list item with sub ul tag
    echo '
  • '
  • ;
    echo ' . $dir . '
    ';
    echo '
      '
    ;
    scandir_rec($path); // <--- recursion="" span="" then="">
    echo '
    ';
    echo '
    ';
    }
    }
    }
    // init call
    $rootDir = $varpathtorecursive;
    echo '
      '
    ;
    scandir_rec($rootDir);
    echo '
    ';
    die;
    }
    ?>

    No comments: