0

我正在尽我最大的努力让这件事正常工作,但我不知道为什么我的世界服务器控制台给了我:05.04 01:40:29 [Server] INFO /212.1.212.1:58215 lost connection

我的代码php函数:

function Votifier($public_key, $server_ip, $server_port, $username)
{
//pharse the public key
$public_key2 = wordwrap($public_key, 65, "\n", true);
$public_key = <<<EOF
-----BEGIN PUBLIC KEY-----
$public_key2
-----END PUBLIC KEY-----
EOF;
//get user IP
$address = $_SERVER['REMOTE_ADDR'];
//set voting time
$timeStamp = time();

//create basic required string for Votifier
$string = "VOTE\nTest\n$username\n$address\n$timeStamp\n";

//fill blanks to make packet lenght 256
$leftover = (256 - strlen($string)) / 2;
while ($leftover > 0) {
$string.= "\x0";
$leftover--;
}

//encrypt string before send
openssl_public_encrypt($string,$crypted,$public_key);

//try to connect to server
$socket = fsockopen($server_ip, $server_port, $errno, $errstr, 3);
if ($socket)
{
var_dump(fwrite($socket, $crypted)); //on success send encrypted packet to server
}
else
return false; //on fail return false
}
4

1 回答 1

2

尝试使用 phpseclib ( http://phpseclib.sourceforge.net/ )。这里有一个关于如何使用私钥/公钥的示例:http: //phpseclib.sourceforge.net/ssh/examples.html#rsakey。然后,您可以像这样使用交互式 shell:

<?php
include('Net/SSH2.php');
include('Crypt/RSA.php');

$ssh = new Net_SSH2('www.domain.tld');
$key = new Crypt_RSA();
$key->loadKey(file_get_contents('privatekey'));
if (!$ssh->login('username', $key)) {
    exit('Login Failed');
}

echo $ssh->read('username@username:~$');
$ssh->write("ls -la\n");
echo $ssh->read('username@username:~$');
?>
于 2013-04-04T23:53:16.400 回答