Guest User

Untitled

a guest
Jan 20th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. $ip = "ip";
  2. $user = "user";
  3. $pass = "password";
  4.  
  5. if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
  6.  
  7. if(!($con = ssh2_connect($ip, 22))){
  8. echo "<font color='red'>fail: unable to establish connection</font>n";
  9. } else {
  10.  
  11. if(!ssh2_auth_password($con, $user, $pass)) {
  12. echo "fail: unable to authenticate";
  13. } else {
  14. echo "Sucessful";
  15. if (!($stream = ssh2_exec($con, "/home/boza/serv.sh" ))) {
  16. echo "fail: unable to execute command";
  17. } else {
  18. stream_set_blocking($stream, true);
  19. $data = "";
  20. while ($buf = fread($stream,4096)) {
  21. $data .= $buf;
  22. }
  23. fclose($stream);
  24. }
  25. }
  26. }
  27.  
  28. $ip = "ip";
  29. $user = "user";
  30. $pass = "password";
  31.  
  32. if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
  33. echo '<form action="#" method="POST">';
  34. echo '<input type="submit" name="launch" value="1" />'
  35. echo '</form>';
  36.  
  37. if($_POST['launch']==1){
  38. if(!($con = ssh2_connect($ip, 22))){
  39. echo "<font color='red'>fail: unable to establish connection</font>n";
  40. } else {
  41.  
  42. if(!ssh2_auth_password($con, $user, $pass)) {
  43. echo "fail: unable to authenticate";
  44. } else {
  45. echo "Sucessful";
  46. if (!($stream = ssh2_exec($con, "/home/boza/serv.sh" ))) {
  47. echo "fail: unable to execute command";
  48. } else {
  49. stream_set_blocking($stream, true);
  50. $data = "";
  51. while ($buf = fread($stream,4096)) {
  52. $data .= $buf;
  53. }
  54. fclose($stream);
  55. }
  56. }
  57. }
  58. }
  59.  
  60. function XORin($key='asimpletext', $text='pwd'){
  61. for($i=0;$i<strlen($text);$i++)
  62. {
  63. for($j=0;$j<strlen($key);$j++,$i++)
  64. {
  65. $outText .= $text{$i} ^ $key{$j};
  66. }
  67. }
  68. return $outText;
  69. }
  70.  
  71. function XORout($key='asimpletext', $text='pwd'){(){
  72. for($i=0;$i<strlen($text);$i++)
  73. {
  74. for($j=0;$j<strlen($key);$j++,$i++)
  75. {
  76. $outText .= $key{$j} ^ $text{$i};
  77. }
  78. }
  79. return $outText;
  80. }
  81.  
  82. class NiceSSH {
  83. // SSH Host
  84. private $ssh_host = 'myserver.example.com';
  85. // SSH Port
  86. private $ssh_port = 22;
  87. // SSH Server Fingerprint
  88. private $ssh_server_fp = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  89. // SSH Username
  90. private $ssh_auth_user = 'username';
  91. // SSH Public Key File
  92. private $ssh_auth_pub = '/home/username/.ssh/id_rsa.pub';
  93. // SSH Private Key File
  94. private $ssh_auth_priv = '/home/username/.ssh/id_rsa';
  95. // SSH Private Key Passphrase (null == no passphrase)
  96. private $ssh_auth_pass;
  97. // SSH Connection
  98. private $connection;
  99.  
  100. public function connect() {
  101. if (!($this->connection = ssh2_connect($this->ssh_host, $this->ssh_port))) {
  102. throw new Exception('Cannot connect to server');
  103. }
  104. $fingerprint = ssh2_fingerprint($this->connection, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX);
  105. if (strcmp($this->ssh_server_fp, $fingerprint) !== 0) {
  106. throw new Exception('Unable to verify server identity!');
  107. }
  108. if (!ssh2_auth_pubkey_file($this->connection, $this->ssh_auth_user, $this->ssh_auth_pub, $this->ssh_auth_priv, $this->ssh_auth_pass)) {
  109. throw new Exception('Autentication rejected by server');
  110. }
  111. }
  112. public function exec($cmd) {
  113. if (!($stream = ssh2_exec($this->connection, $cmd))) {
  114. throw new Exception('SSH command failed');
  115. }
  116. stream_set_blocking($stream, true);
  117. $data = "";
  118. while ($buf = fread($stream, 4096)) {
  119. $data .= $buf;
  120. }
  121. fclose($stream);
  122. return $data;
  123. }
  124. public function disconnect() {
  125. $this->exec('echo "EXITING" && exit;');
  126. $this->connection = null;
  127. }
  128. public function __destruct() {
  129. $this->disconnect();
  130. }
  131. }
Add Comment
Please, Sign In to add comment