0

私はこのスクリプトを使用しましたが、もううまく機能していません。スクリプトを呼び出すには、mysite.com/serv.phpにアクセスする必要があります。したがって、最初にスクリプトを示します。

$ip = "ip";
$user = "user";
$pass = "password";

if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");

if(!($con = ssh2_connect($ip, 22))){
    echo "<font color='red'>fail: unable to establish connection</font>\n";
} else {   

    if(!ssh2_auth_password($con, $user, $pass)) {
        echo "fail: unable to authenticate";
    } else {
        echo "Sucessful";
        if (!($stream = ssh2_exec($con, "/home/boza/serv.sh" ))) {
            echo "fail: unable to execute command";
        } else {
            stream_set_blocking($stream, true);
            $data = "";
            while ($buf = fread($stream,4096)) {
                $data .= $buf;
            }
            fclose($stream);
        }
    }
}

スクリプトはうまく機能しますが、いくつか変更を加えたいと思います。1.安全性を高めるためにmd5ハッシュを追加したい2.serv.phpにアクセスするときにスクリプトを実行せず、ボタンを押してajax呼び出しを行うようにしたい。3.「成功」や「失敗」などのユーザーフィードバックを希望します...今と同じように、ライブajaxなどのサイトを更新せずに使用します。

私はグーグルでmd5('xxxx')をスクリプトに入れようとしましたが、奇妙なエラーが発生し、何か間違ったことをしていると確信しています。

誰かがこの事件で私を助けてくれませんか?

4

2 に答える 2

0

次のようなボタンを押した場合にのみ、フォームを使用してスクリプトを起動できます。

$ip = "ip";
$user = "user";
$pass = "password";

if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
echo '<form action="#" method="POST">';
echo '<input type="submit" name="launch" value="1" />'
echo '</form>';

if($_POST['launch']==1){
    if(!($con = ssh2_connect($ip, 22))){
        echo "<font color='red'>fail: unable to establish connection</font>\n";
    } else {   

        if(!ssh2_auth_password($con, $user, $pass)) {
            echo "fail: unable to authenticate";
        } else {
            echo "Sucessful";
            if (!($stream = ssh2_exec($con, "/home/boza/serv.sh" ))) {
                echo "fail: unable to execute command";
            } else {
                stream_set_blocking($stream, true);
                $data = "";
                while ($buf = fread($stream,4096)) {
                    $data .= $buf;
                }
                fclose($stream);
            }
        }
    }
}

パスワードには「baba」クラスを使用できます。ソースの読み取りのみの問題である場合は、XOR暗号化などの単純な可逆暗号化機能を使用できます。注意してください。パスワードをソースから直接赤字にできないようにするだけですが、そうではありません。完璧な暗号化

例 :

 function XORin($key='asimpletext', $text='pwd'){
     for($i=0;$i<strlen($text);$i++)
     {
         for($j=0;$j<strlen($key);$j++,$i++)
         {
             $outText .= $text{$i} ^ $key{$j};
         }
     }
     return $outText;
 }

 function XORout($key='asimpletext', $text='pwd'){(){
     for($i=0;$i<strlen($text);$i++)
     {
         for($j=0;$j<strlen($key);$j++,$i++)
         {
             $outText .= $key{$j} ^ $text{$i};
         }
     }
     return $outText;
 }
于 2012-09-25T16:18:51.863 に答える
0

MD5は一方向のハッシュであり、接続を保護することはできません。また、弱く、以前ほど強くはありません。どのレベルのセキュリティにもお勧めしません

あなたが見なければならないのは authenticating with public key authenticationこれを見ることです

ソースの例

class NiceSSH { 
    // SSH Host 
    private $ssh_host = 'myserver.example.com'; 
    // SSH Port 
    private $ssh_port = 22; 
    // SSH Server Fingerprint 
    private $ssh_server_fp = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; 
    // SSH Username 
    private $ssh_auth_user = 'username'; 
    // SSH Public Key File 
    private $ssh_auth_pub = '/home/username/.ssh/id_rsa.pub'; 
    // SSH Private Key File 
    private $ssh_auth_priv = '/home/username/.ssh/id_rsa'; 
    // SSH Private Key Passphrase (null == no passphrase) 
    private $ssh_auth_pass; 
    // SSH Connection 
    private $connection; 

    public function connect() { 
        if (!($this->connection = ssh2_connect($this->ssh_host, $this->ssh_port))) { 
            throw new Exception('Cannot connect to server'); 
        } 
        $fingerprint = ssh2_fingerprint($this->connection, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX); 
        if (strcmp($this->ssh_server_fp, $fingerprint) !== 0) { 
            throw new Exception('Unable to verify server identity!'); 
        } 
        if (!ssh2_auth_pubkey_file($this->connection, $this->ssh_auth_user, $this->ssh_auth_pub, $this->ssh_auth_priv, $this->ssh_auth_pass)) { 
            throw new Exception('Autentication rejected by server'); 
        } 
    } 
    public function exec($cmd) { 
        if (!($stream = ssh2_exec($this->connection, $cmd))) { 
            throw new Exception('SSH command failed'); 
        } 
        stream_set_blocking($stream, true); 
        $data = ""; 
        while ($buf = fread($stream, 4096)) { 
            $data .= $buf; 
        } 
        fclose($stream); 
        return $data; 
    } 
    public function disconnect() { 
        $this->exec('echo "EXITING" && exit;'); 
        $this->connection = null; 
    } 
    public function __destruct() { 
        $this->disconnect(); 
    } 
} 
于 2012-09-25T16:13:53.753 に答える