#1 29. Mai 2008 Hilfe bei c++ scanner hey leute ^^ hab ein tutorial gelesen wie man ein chat programm in c++ schreibt und hab dann daraus ein kleinen portscanner gebastelt (oder besser versucht) auf 127.0.0.1 bezogen klappen die einzelnen portscans.. bei mir auf arbeit klappt es aber net mit der netzwerk-ip-adresse meine frage: hab ich da wirklich einen portscanner ?^^ probleme dich ich noch habe: 1. ich kann keine port-range abscannen .. weil er nach den ersten offenen port alle anderen ports als geschlossen erkennt xD (im quelltext ises deswegen auch nicht mehr drinne) 2. weiß ich nich wie ich ip-ranges scannen lassen kann, bzw. wie ich das programmieren kann vielleicht kennt sich ja jemand mit c++ bissel aus und kann mir helfen oder andere tuts für scanner mit c++ wären auch nett hier der quelltext: Spoiler Code: // doeners little portscanner #include <windows.h> //Dateien die eingebunden werden sollen.. #include <winsock.h> #include <stdio.h> #include <conio.h> #include <iostream.h> int startWinsock(void); //Prototyp einer Funktion int main() //Die Hauptfunktion. { //Variablen definition SOCKET so; SOCKADDR_IN addresse; int check; //für die fehlererkennung char remote_ip[15]; int start_port; int ende_port; check = startWinsock(); //winsocket starten if(check != 0) { cout<<"Error: startwinsock, Error: "<<check<<endl; return 1; } else { cout<<"doeners little portscanner v0.1 ultra alpha :) wird gestartet..."<<endl; } so = socket(AF_INET,SOCK_STREAM,0); if(so == INVALID_SOCKET) { cout<<"Error: Der socket wurde nicht erstellt, Error: "<<WSAGetLastError()<<endl; return 1; } else { cout<<"Socket erfolgreich generiert!\n"; cout<<"Portscan kann beginnen.\n"; } cout<<"IP: "; cin>>remote_ip; if(strlen(remote_ip) > 15) { cout<<"Fataler Fehler! IP ist falsch!"; getch(); return 1; } cout<<"Port: "; cin>>start_port; //cout<<"Ende : "; cin>>ende_port; ende_port = start_port; if(start_port > ende_port) { cout<<"Falsche Eingabe! Start und Ende wurden vertauscht...\n"; int korr; start_port = korr; start_port = ende_port; ende_port = korr; } if(ende_port > 65535) { cout<<"Fataler Fehler! EndPort ist größer als 65535!"<<endl; getch(); return 1; } for(int i=start_port; i <= ende_port;i++) { memset(&addresse,0,sizeof(SOCKADDR_IN)); addresse.sin_family=AF_INET; addresse.sin_port=htons(i); //<--Portnummer hier addresse.sin_addr.s_addr=inet_addr(remote_ip); //<-- IP hier check=connect(so,(SOCKADDR*)&addresse,sizeof(SOCKADDR)); //Verbindungsversuch if(check==SOCKET_ERROR) //Prüfen ob verbindung gescheitert ist oder erfolgreich war :) { cout<<"Port: "<<i<<" geschlossen!"<<endl; } else { cout<<"Port: "<<i<<" geöffnet!"<<endl; closesocket(so); } } //ENDE scan cout<<"Scan beendet!"; getchar(); return 0; } int startWinsock(void) //startWinsock - Funktion { WSADATA wsa; return WSAStartup(MAKEWORD(2,0),&wsa); } mfg doener + Multi-Zitat Zitieren
#2 30. Mai 2008 AW: Hilfe bei c++ scanner Werde die wohl nicht weiterhelfen können aber was ich nicht ganz verstehe ist: du deklarierst eine variable vom typ startWinsock(void): Code: int startWinsock(void); //Prototyp einer Funktion Und rufst due funktion dann auf obwohl ihr noch garkeine adresse zugeordnet wurde ? Code: check = startWinsock(); //winsocket starten Bin aber auch nicht der beste in c++ + Multi-Zitat Zitieren
#3 30. Mai 2008 AW: Hilfe bei c++ scanner Code: int startWinsock(void); //Prototyp einer Funktion Das is nur der Prototyp von ner Funktion. Damit weiß der Compiler, dass die Funktion existiert (wird ja weiter unten auch definiert) und wie er sie aufrufen muss. + Multi-Zitat Zitieren
#4 31. Mai 2008 AW: Hilfe bei c++ scanner ja genau mir wurde aber auch schon geholfen ^^ hab das programm nochmal komplett umgebaut, weil das ziemlich doof programmiert war ^^ hier der neue code ich mach den wieder als spoiler, weil der code so lang ist sind jetzt auch kleine spielereien drinne und man kann es mit parametern steuern, bzw. muss es so steuern^^ Spoiler Code: // DoeneR, 30.5.2008, all rights reserved #include <windows.h> //Dateien die eingebunden werden sollen.. #include <winsock.h> #include <stdio.h> #include <conio.h> #include <iostream.h> #include <string.h> int donscann(char *ip, int port); // Prototyp der Scannfunktion int startWinsock(void); int main(int argc, char *argv[]) { char *ip; int startport; int endport; int i; char *tmp; int tmp2; if (argc < 4) { printf ("Fehler : Parameter stimmen nicht!.\n"); printf ("Syntax : donscanner IP startport endport\n"); return 0; } if (strlen(argv[1]) > 15) { printf ("Fehler : Die IP-Adresse ist ungültig!\n"); return 0; } else { ip = argv[1]; }; tmp = argv[2]; tmp2 = atol (tmp); if (tmp2 < 65535 && tmp2 > 0) { startport = tmp2; } else { printf ("Startport muss zwischen 1 und 65535 liegen.\n"); return 0; } tmp = argv[3]; tmp2 = atol (tmp); if (tmp2 < 65535 && tmp2 > 0 && tmp2 > startport) { endport = tmp2; } else { printf ("Endport ist falsch! \n"); return 0; } system("color 0a"); system("cls"); cout<<"doener's kleiner port scanner v0.1\n"; cout<<"\nScanvorgang wird gestartet, dies kann einige Minuten dauern!\n"; cout<<"------------------------------------------------------------\n"; for (i = startport; i <= endport; i++) { donscann(ip,i); } cout<<"\n------------------------------------------------------------\n"; cout<<"Scanvorgang erfolgreich beendet!\n"; system("color 07"); return EXIT_SUCCESS; } int donscann(char *ip, int port) { SOCKET sockfd; SOCKADDR_IN addr; int check; check = startWinsock(); if(check != 0) { cout<<"Error: startwinsock, Error: "<<check<<endl; return 0; } sockfd = socket(AF_INET,SOCK_STREAM,0); if(sockfd == INVALID_SOCKET) { cout<<"Error: Der socket wurde nicht erstellt, Error: "<<WSAGetLastError()<<endl; return 1; } addr.sin_family=AF_INET; addr.sin_port=htons(port); //<--Portnummer hier addr.sin_addr.s_addr=inet_addr(ip); //<-- IP hier check=connect(sockfd,(SOCKADDR*)&addr,sizeof(SOCKADDR)); //Verbindungsversuch if(check==SOCKET_ERROR) //Prüfen ob verbindung gescheitert ist oder erfolgreich war :) { cout<<"### Port: "<<port<<" geschlossen ###"<<endl; } else { cout<<"### Port: "<<port<<" geöffnet ###"<<endl; } closesocket(sockfd); return 0; } int startWinsock(void) //startWinsock - Funktion { WSADATA wsa; return WSAStartup(MAKEWORD(2,0),&wsa); } wer mir noch ein heißen tipp geben kann, wie ich am besten eine ganze IP-RANGE abscannen kann, dem wär ich echt dankbar =) hab nämlich keine ahnung wie ich das machen soll wenn ich zb. als iprange: 192.168.1-3.1-254 oder eine startip und eine endip eingebe, da stören mich einfach diese punkte ^^ mfg doener + Multi-Zitat Zitieren
#5 31. Mai 2008 AW: Hilfe bei c++ scanner Hey! So hab ich das in KSnoop in C umgesetzt: range.c Spoiler Code: /* KSnoop - Snooping around on FTP Servers * Copyright (C) 2007 Kolazomai * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <stdlib.h> #include <string.h> #include <errno.h> /* inet_addr () && inet_ntoa () */ #ifdef _WIN32 #include <winsock2.h> #else #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #ifndef inet_aton extern int inet_aton (const char *cp, struct in_addr *inp); #endif #endif #include "range.h" static gchar** range_split (const gchar *range); static int range_validate (const gchar *ip); static gchar** range_ip_list (const gchar *begin, const gchar *end); static guint32 range_ntohl (const gchar *ip); static gchar* range_ntoa (guint32 hostlong); gchar** range_load_ips (const gchar *range) { gchar **parts = NULL, **ips = NULL; if ((parts = range_split (range)) == NULL) { g_print ("[-] range.c: range_load_ips (): \'%s\' is no valid range!\n", range); return NULL; } if (range_validate (parts[0]) == EXIT_FAILURE || range_validate (parts[1]) == EXIT_FAILURE) { g_print ("[-] range.c: range_load_ips (): \'%s\' is no valid range!\n", range); return NULL; } if ((ips = range_ip_list (parts[0], parts[1])) == NULL) { g_print ("[-] range.c: range_load_ips (): Couldn't create an IP-list...\n"); return NULL; } return ips; } static gchar** range_split (const gchar *range) { return g_strsplit (range, RANGE_SPLIT_DELIMITER, RANGE_RANGE_MAX_TOKENS); } static int range_validate (const gchar *ip) { #ifdef _WIN32 if (inet_addr (ip) == -1 && strcmp (ip, "255.255.255.255")) { #else struct in_addr in; if (inet_aton (ip, &in) == RANGE_ATON_FAILURE) { #endif g_print ("[-] range.c: range_validate (): \'%s\' is no valid IP-address!\n", ip); return EXIT_FAILURE; } return EXIT_SUCCESS; } static gchar** range_ip_list (const gchar *begin, const gchar *end) { gchar **ips = NULL; guint32 start = 0, stop = 0, current = 0, i = 0; start = range_ntohl (begin); stop = range_ntohl (end); if (start > stop) { start ^= stop; stop ^= start; start ^= stop; } /* It has to be NULL-terminated */ ips = g_malloc0 (((stop - start) + 1 + 1) * sizeof (gchar*)); if (!ips) { g_print ("[-] range.c: range_ip_list (): g_malloc0 (): %s!\n", g_strerror (errno)); return NULL; } for (current = start; current <= stop; current++) ips[i++] = range_ntoa (current); return ips; } static guint32 range_ntohl (const gchar *ip) { return g_ntohl (inet_addr (ip)); } static gchar* range_ntoa (guint32 hostlong) { struct in_addr in; in.s_addr = g_htonl (hostlong); return g_strdup (inet_ntoa (in)); } range.h Spoiler Code: /* KSnoop - Snooping around on FTP Servers * Copyright (C) 2007 Kolazomai * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef __RANGE_H__ #define __RANGE_H__ #include <glib.h> /* 0.0.0.0-255.255.255.255 */ #define RANGE_SPLIT_DELIMITER "-" #define RANGE_RANGE_MAX_TOKENS 2 #define RANGE_ATON_FAILURE 0 gchar** range_load_ips (const gchar *range); #endif /* __RANGE_H__ */ Sagt dir jetzt wahrscheinlich nicht viel, aber ich erklaers mal: Jede IP-Adresse ist im Prinzip eine Zahl. Du kannst jetzt mit der Funktion ntohl () in Kombination mit inet_addr () diese Zahl herausfinden. Danach musst kannst du einfach von der einen Zahl zur anderen Zahl hochzaehlen (deine Range), und das ganze zurueckwandeln, naemlich mit htonl () und inet_ntoa (). Ich benutze teilweise g_<funktion>, weil die GLib diese Funktionen aus Kompatibilitaetsgruenden und der Einfachheit halber anbietet. Edit: Zotteljedi - Port Scanner mal durchlesen! Mfg, Kolazomai + Multi-Zitat Zitieren