[C/C#/C++] Small PMAFind

Dieses Thema im Forum "Projekte / Codes" wurde erstellt von Kolazomai, 4. August 2006 .

Schlagworte:
  1. 4. August 2006
    Small PMAFind

    Hi,

    hab letzdings mal ein kleines PMAFind-Programm in C geschrieben...
    Man koennte es natuerlich noch ein bisschen via select aufmotzen ( Threads, Timeout, etc. ).

    Der Source ist offen (GPL) und cross-platform ( fuer *nix und Windows ) und soll als Lernmaterial dienen.
    Wenn ihr paar mehr Infos wollt, einfach
    Code:
    #define DEBUG
    oben hinschreiben ^^.

    Unter Linux mit
    Code:
    gcc source.c -o out -Wall
    Unter Windows mit Bloodshed Dev C++ muesst ihr noch die Winsock2-Lib einbinden ( Ws2_32 )

    Ahja, das Programm ist ein ConsolenProgramm... also ohne Graphische Benutzeroberflaeche.

    Dann mal los:
    Code:
    /* Small PMAFind by Kolazomai */
    /* Usage: ./pmafind <pathes> <host-file> */
    /* Whereas <pathes> is a textfile with pathes inside */
    /* and <host-file> is a textfile with ips inside */
    
    /* Published under GPL - General Public License */
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #ifdef _WIN32
    #include <winsock.h>
    #include <windows.h>
    #include <io.h>
    
    #else
    #include <sys/socket.h>
    #include <sys/types.h>
    #include <netinet/in.h>
    #include <netdb.h>
    #include <arpa/inet.h>
    #include <sys/time.h>
    #include <sys/param.h>
    #include <unistd.h>
    #endif
    
    #include <errno.h>
    
    #define MAX_BUF 1024
    
    #define PORT 80
    #define WHAT_TO_FIND "200"
    
    
    #ifdef _WIN32
    SOCKET crea_sock() {
    #else
    int crea_sock() {
    #endif
    #ifdef _WIN32
    SOCKET s;
    #else
    int s;
    #endif
    s = socket(AF_INET,SOCK_STREAM,0);
    if (s < 0) {
     perror("[-] Socket");
     return (-1);
     }
    #ifdef DEBUG
    printf("[+] Socket initalisiert\n");
    #endif
    return s;
    }
    
    
    
    
    int main(int argc,char **argv) {
    printf("*******************\n");
    printf("** Small PMAFind **\n");
    printf("** by Kolazomai **\n");
    printf("*******************\n");
    
    char pathes_f_ch[MAX_BUF];
    char host_f_ch[MAX_BUF];
    
    if (argc < 3) {
     printf("[-] Usage: %s <pathes.file> <host.file>\n",argv[0]);
     exit(1);
     }
    else {
     strcpy(pathes_f_ch,argv[1]);
     strcpy(host_f_ch,argv[2]);
     printf("[+] Using Pathes located in \"%s\" !\n",pathes_f_ch);
     printf("[+] Using IPs located in \"%s\" !\n",host_f_ch);
     }
    
    #ifdef _WIN32
    WORD wVersionRequested;
    WSADATA wsaData;
    wVersionRequested = MAKEWORD (1, 1);
    if (WSAStartup (wVersionRequested, &wsaData) != 0) {
     printf("[-] Fehler beim Initialisieren von Winsock\n");
     return (-1);
     }
    else {
     #ifdef DEBUG
     printf("[+] Winsock initialisiert ...\n");
     #endif
     }
    #endif
    
    
    FILE *path_f;
    FILE *host_f;
    
    host_f = fopen(host_f_ch,"r");
    if (host_f == NULL) {
     perror("[-] Error while opening host-file\n");
     exit(-1);
     }
    
    char get_ch[MAX_BUF];
    char get_ch2[MAX_BUF];
    char buf[MAX_BUF];
    int tmp = 0;
    while (fgets(get_ch,sizeof(get_ch),host_f) != NULL) {
     printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
     path_f = fopen(pathes_f_ch,"r");
     if (path_f == NULL) {
     perror("[-] Error while opening path-file");
     exit(-1);
     }
    
     for (tmp = 0;tmp <= strlen(get_ch);tmp++) {
     if (get_ch[tmp] == '\n') {
     get_ch[tmp] = '\0';
     }
     }
    
     struct sockaddr_in addr;
     addr.sin_family = AF_INET;
     addr.sin_addr.s_addr = inet_addr(get_ch);
     addr.sin_port = htons(PORT);
    
     
     while (fgets(get_ch2,sizeof(get_ch2),path_f) != NULL) {
     #ifdef _WIN32
     SOCKET s;
     #else
     int s;
     #endif
    
     s = crea_sock();
    
     if (connect(s,(struct sockaddr*)&addr,sizeof(addr)) == -1) {
     sprintf(get_ch2,"[-] Could not connect to %s!",get_ch);
     perror(get_ch2);
     break;
     }
     for (tmp = 0;tmp <= strlen(get_ch2);tmp++) {
     if (get_ch[tmp] == '\n') {
     get_ch[tmp] = '\0';
     }
     }
     sprintf(buf,"GET %s HTTP/1.1\n\rHost: %s\n\r",get_ch2,get_ch);
     tmp = send(s,buf,strlen(buf),0);
     if (tmp == -1) {
     sprintf(buf,"[-] Could not send to %s via Port %i !",get_ch,PORT);
     perror(buf);
     close(s);
     break;
     }
     tmp = recv(s,buf,sizeof(buf) - 1,0);
     if (tmp == -1) {
     sprintf(buf,"[-] Could not receive any data from %s:%i !",get_ch,PORT);
     perror(buf);
     close(s);
     break;
     }
     buf[tmp] = '\0';
     if (strstr(buf,WHAT_TO_FIND) != NULL) {
     printf("[!] Found: http://%s%s",get_ch,get_ch2);
     }
     close(s);
     }
     printf("[+] Finished Host %s !\n",get_ch);
     fclose(path_f);
     }
    printf("***\nKolazomai out\n");
    return 0;
    }
    
    Mfg,

    Kolazomai
     
  2. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.