-
Notifications
You must be signed in to change notification settings - Fork 11
/
moulinette.php
53 lines (42 loc) · 1.58 KB
/
moulinette.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
$dir = "/bin/";
$files = scandir($dir);
$results = array();
echo "Processing $dir ";
foreach ($files as $file) {
if (is_file($dir . $file) && is_readable($dir . $file)) {
echo ".";
$fp = $dir . $file;
$random_key = substr(sha1(rand()), 0, 6);
$results[$fp] = array();
$results[$fp]['key'] = $random_key;
/* Encryption test */
file_put_contents('/tmp/moulinette_php', mcrypt_encrypt(MCRYPT_DES, $random_key, file_get_contents($fp), MCRYPT_MODE_ECB));
$hash_php_des = sha1(file_get_contents('/tmp/moulinette_php'));
exec("./des -e -i $fp -o /tmp/moulinette -k $random_key");
$hash_our_des = sha1(file_get_contents("/tmp/moulinette"));
$results[$fp]['php_encrypted_hash'] = $hash_php_des;
$results[$fp]['our_encrypted_hash'] = $hash_our_des;
$results[$fp]['success'] = $hash_our_des === $hash_php_des;
/* Decryption test */
$hash_php_des = sha1(mcrypt_decrypt(MCRYPT_DES, $random_key, file_get_contents('/tmp/moulinette_php'), MCRYPT_MODE_ECB));
exec("./des -d -i /tmp/moulinette -o /tmp/moulinette_decrypt -k $random_key");
$hash_our_des = sha1(file_get_contents("/tmp/moulinette_decrypt"));
$results[$fp]['php_decrypted_hash'] = $hash_php_des;
$results[$fp]['our_decrypted_hash'] = $hash_our_des;
$results[$fp]['success'] = $results[$fp]['success'] && $hash_our_des === $hash_php_des;
}
}
echo " done!\n";
$good = 0;
$bad = 0;
foreach ($results as $key => $arr) {
if ($arr['success'] !== true) {
echo $key . " failed\n";
$bad++;
} else {
$good++;
}
}
$total = $good + $bad;
echo "$good / $total pass\n";