-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
pombo.php
79 lines (76 loc) · 2.91 KB
/
pombo.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
error_reporting(0);
usleep(200000);
/* For multi hosts, you can define these 2 variables in
* the index.php and call pombo.php.
*
* Tree:
* /pombo.php
* /bob
* |--- index.php
* /alice
* |--- index.php
*
* Contents of index.php:
*
* <?php
* $PASSWORD = '<The same value as in pombo.conf.>';
* $CHECKFILE = '<The same value as in pombo.conf.>';
* require '../pombo.php';
* ?>
*/
if ( !isset($PASSWORD) )
$PASSWORD = '<The same value as in pombo.conf.>';
if ( !isset($CHECKFILE) )
$CHECKFILE = '<The same value as in pombo.conf.>';
if ( !function_exists('hash_hmac') ) {
//Calculate HMAC-SHA1 according to RFC2104
// http://www.ietf.org/rfc/rfc2104.txt
function hash_hmac($hashfunc, $data, $key) {
$blocksize = 64;
if ( strlen($key) > $blocksize )
$key = pack('H*', $hashfunc($key));
$key = str_pad($key, $blocksize, chr(0x00));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
$hmac = pack('H*', $hashfunc(($key ^ $opad).pack('H*', $hashfunc(($key ^ $ipad).$data))));
return bin2hex($hmac);
}
}
/* Stolen! */
if ( !empty($_GET) ) {
if ( isset($_GET['check']) && $_GET['check'] == $CHECKFILE ) {
if ( is_file($CHECKFILE) )
die('Computer already stolen!');
if ( ($fh = fopen($CHECKFILE, 'w')) === false )
die('Could not create file.');
fclose($fh);
die('File created, Pombo will see it and check every 5 minutes.');
}
if ( isset($_GET['myip']) )
die( !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
die('Nothing to do ...');
}
/* Routine */
else {
if ( empty($_POST) )
die('Nothing to do ...');
if ( isset($_POST['verify']) )
if ( $_POST['verify'] != hash_hmac('sha1', $_POST['filedata'].'***'.$_POST['filename'], $PASSWORD) )
die('Wrong password!');
else
die(is_file($CHECKFILE));
if ( $_POST['token'] != hash_hmac('sha1', $_POST['filedata'].'***'.$_POST['filename'], $PASSWORD) )
die('Wrong password!');
if ( pathinfo($_POST['filename'], 4) != 'gpg' && pathinfo($_POST['filename'], 4) != 'zip' )
die('Not a gpg file.');
if ( !preg_match('/^[\w\.\-]*$/', $_POST['filename']) )
die('Invalid characters in filename.');
if ( ($fh = fopen($_POST['filename'], 'xb')) === false )
die('Could not create file.');
if ( fwrite($fh, base64_decode($_POST['filedata'])) === false )
die('Could not write file.');
fclose($fh);
}
echo 'File stored.';
?>