public function Exec($command) { $engine = $this->session->getSpooler(); if (!isset($engine[0]['shell'])) { print "?!"; exit; } $shell = $engine[0]['shell']; $host = $shell['host']; $user = $shell['user']; $password = $shell['password']; $method = 'CURL'; set_include_path(get_include_path() . PATH_SEPARATOR . '../vendor/phpseclib'); include 'Net/SSH2.php'; include 'Crypt/RSA.php'; $ssh = new \Net_SSH2($host); if (1) { $key = new \Crypt_RSA(); $ret = $key->loadKey("-----BEGIN RSA PRIVATE KEY-----\nMIICWgIBAAKBgQCzRy01HoHIzBJJb/D8A/eTV3qiZxy0NIR97NE14rJblnJZT5Kg\noP2DvIRzlB0msL5cHQJ/qXYAoemHRDKqNZuj89+MYsBeZqNu3/DXdZLq9XJ8e2rb\nsGrDjHvCHEDWL0JIRFnRacem55+XsUsKTIs4tbcD6adMPIYJSQQ7oB/8AQIBIwKB\ngB67vptkUMNWLwVGY9NuZPSv6SMnnoVK1OJjHIzlCKH8iKGYnMsUSLd/ZynBnpjr\nGVGekrbMl+LZ7YTnHqDV/WxGoWEc3xiHE8/HwZwQZxP92K70inz8+6dGEagsrSqO\nQkdAPR/+qen7uQ9yXqj7WAoNFicPJ2cpo8kuEW33KywzAkEA4yH4jf0uNBFDUkR6\ni9DQC5bsgEloVezWnCsm6eIm5o5SGKPZ6Rpro/h3pq5qvPmCtjrZFnK0Dab9xkFr\n/F9lkwJBAMoQMqxYdnPz74Bto99o0PZrk2ikROwXR9eURi3B4bWGq9+mvN3OEQdE\n8JofGyq60LMlnFAkE7v49fYHziyaFJsCQHTPpGZHsVybKe/LcjlG0WULyhYXH7cp\nWG2SiQqRkFlQgf4LH5xz/Nf8IEcX3x9bv5DrEI8zrQ5V4Zko9bT93HcCQQCEyNDX\np9jP2tCWOWuwEa3jwwkY4PoXfQNTJuxJ9G/AbnDyDnwcup15zje1vKtz2dmaS+pg\njLyC1s2Ea4d8ZUC9AkAeUr/N+011K2zGTjxZnAFY/Ow348bomzddiJYAYA+76exV\n3wUYsjeDxqq8Km93+iMQ8DDNZIvoVcfYQW9BfDlf\n-----END RSA PRIVATE KEY----- "); if (!$ret) { echo "loadKey failed\n"; print "<pre>" . $ssh->getLog() . '</pre>'; exit; } } elseif (isset($shell['password'])) { $key = $shell['password']; } else { $key = ''; // ?! possible ? } if (!$ssh->login($user, $key)) { exit("Login Failed ({$user})"); } return $ssh->exec("system '{$command}'"); }
public function Exec($command, $stdin = '') { $database = $this->session->getDatabase(); $name = $database['name']; $engine = $this->session->getSpoolerByName($name, 'waae'); if (!isset($engine[0]['shell'])) { print "?!"; exit; } set_include_path('../vendor/phpseclib' . PATH_SEPARATOR . get_include_path()); include 'Net/SSH2.php'; include 'Crypt/RSA.php'; $shell = $engine[0]['shell']; $host = $shell['host']; $user = $shell['user']; $ssh = new \Net_SSH2($host); if (isset($shell['key'])) { $key = new \Crypt_RSA(); $ret = $key->loadKey($shell['key']); if (!$ret) { echo "loadKey failed\n"; print "<pre>" . $ssh->getLog() . '</pre>'; exit; } } elseif (isset($shell['password'])) { $key = $shell['password']; } else { $key = ''; // ?! possible ? } if (!$ssh->login('autosys', $key)) { print 'Login Failed'; print "<pre>" . $ssh->getLog() . '</pre>'; exit; } if ($stdin == '') { return $ssh->exec(". ~/.bash_profile;{$command}"); } // Test STDIN $ssh->enablePTY(); print "profile" . $ssh->exec(". ~/.bash_profile"); print "sort" . ($exec = $ssh->exec('sort')); $ssh->write(<<<EOF echo "update_job: SE.ERIC.JOB.JobType_UNIX" echo "description: 'ok!!' EOF ); $ssh->reset(true); $ssh->setTimeout(2); print $ssh->read(); return; return $ssh->read(); // outputs the echo above }
public function Exec($shell, $command, $stdin = '') { $host = $shell['host']; $user = $shell['user']; $ssh = new \Net_SSH2($host); if (isset($shell['key'])) { $key = new \Crypt_RSA(); $ret = $key->loadKey($shell['key']); if (!$ret) { $this->status = '!KEY'; echo "loadKey failed\n"; print "<pre>" . $ssh->getLog() . '</pre>'; return; } } elseif (isset($shell['password'])) { $key = $shell['password']; } else { $key = ''; // ?! possible ? } if (!@$ssh->login($shell['user'], $key)) { $this->status = '!LOGIN'; print 'Login Failed: ' . $shell['user']; print "<pre>" . $ssh->getLog() . '</pre>'; return; } $this->status = 'RUNNING'; if ($stdin == '') { return $ssh->exec("{$command}"); } return; }
$dh_pid = trim(preg_replace('/\\s+/', ' ', $dh_pid)); echo "Start.{$dh_pid}.END<br />"; //$dh_pid = "11192"; //$dh_pid_result = $ssh->exec("pgrep -fl ".$dh_pid.""); //echo "<hr>"; //echo $ssh->exec("ls"); //echo "<hr>"; $dh_pid_result = $ssh->exec("ps aux | grep {$dh_pid} | grep -v grep"); $ssh->setTimeout(10); //$dh_pid_result = $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); echo "<pre>{$dh_pid_result}</pre>"; echo str_repeat(' ', 1024 * 64); //need SECOND occurance of $needle since the result will include the actual command //$dh_after_first_result = stristr($dh_pid_result, $dh_pid); if (stristr($dh_pid_result, $dh_pid) === TRUE) { echo "DH not completed.... waiting..."; sleep(15); echo str_repeat(' ', 1024 * 64); if (stristr($dh_pid_result, $dh_pid) === TRUE) { echo "DH STILL not completed.... waiting..."; sleep(15); if (stristr($dh_pid_result, $dh_pid) === TRUE) { echo "<hr>DH STILL NOT COMPLETED.... manually run <br />source ./vars and ./build-dh in {$var_dir} then <br />copy dh1024.pem from {$key_dir} to config directory (usually /etc/openvpn)<hr>"; echo $ssh->getLog(); exit; } } } echo str_repeat(' ', 1024 * 64); echo $ssh->getLog(); exit;