/*-------------------------------------------------------------+ | Fritz anonymous mail client v 0.4 | | -------------------------------------------------------------| | | | Il codice e' scritto con in piedi, ma e' funzionale. | | Per ora non ho nessuna voglia di rivederlo, va bene cosi'. | | | | Per compilarlo: | | | | cc anon_mail-client.c -o fanon | | | | Per attivare l'opzione verbosity usare l'opzione -v: | | | | darkstar:~$ fanon -v | | | | Per contattare l'autore: | | | | mail fritz@spippolatori.com | | | +--------------------------------------------------------------*/ #define SMTP_PORT 25 #define MAX_MEX_NUMBER 10 //#define DEBUG #define VERB if(verbose==1) #include #include #include #include #include #include #include #include void scrivi(int n,char *str); void pulisci_buffer(); main(int argn,char **argv) { char linea[500]; char smtp_server[80]; //odio "segmentation fault" char from[100],to[100]; struct sockaddr_in smtp_server_address; struct hostent *server_info; int sockfd,z; int bl; int verbose=0; char c; if (argn>1) {if (argv[1][1]=='v') verbose=1;} printf("\n\n---------------------------" "\nFritz anonymous mail client" "\n v. 0.4 " "\n " "\n for info: " "\n fritz@spippolatori.com " "\n---------------------------"); printf("\n\nDigitare il server smtp anonimo da utilizzare:"); scanf("%s",smtp_server); c=getchar(); if ( inet_addr(smtp_server)==INADDR_NONE ) { if ( (server_info=gethostbyname(smtp_server))==NULL) {herror("Resolving host:"); exit(0);} else { smtp_server_address.sin_addr= *((struct in_addr *)server_info->h_addr); printf("\nHost rilevato:%s",inet_ntoa(smtp_server_address.sin_addr.s_addr)); } } else smtp_server_address.sin_addr.s_addr=inet_addr(smtp_server); smtp_server_address.sin_port=htons(SMTP_PORT); smtp_server_address.sin_family=AF_INET; sockfd=socket(AF_INET,SOCK_STREAM,0); z=connect(sockfd, (struct sockaddr *)&smtp_server_address, sizeof(struct sockaddr)); if (z==-1) printf("\nProblemi..." "\nil server e' irraggiungibile o non permette connessioni"); else { printf("\nConnessione effettuata"); bl=read(sockfd,linea,200); VERB scrivi(bl,linea); if ((char*)strstr(linea,"220")==NULL) {printf("\nl'smtp server non consente l'inoltro\n"); printf("\nMessaggio di errore:\n"); scrivi(bl,linea); exit(1); } //------------- HELO -------------- send(sockfd,"HELO 127.0.0.1\n",strlen("HELO 127.0.0.1\n"),0); bl=read(sockfd,linea,200); VERB scrivi(bl,linea); if ((char*)strstr(linea,"250")==(char*)NULL) {printf("\nErrore in fase HELO\n"); printf("\nMessaggio di errore:\n"); scrivi(bl,linea); exit(1); } //------------- MAIL FROM: -------------- printf("\nDigitare il mittente: "); scanf("%[!-~ ]",linea); c=getchar(); strcpy(from,linea); send(sockfd,"MAIL FROM: un@microsoft.com\n",strlen("MAIL FROM: un@microsoft.com\n"),0); bl=read(sockfd,linea,200); VERB scrivi(bl,linea); if ((char*)strstr(linea,"250")==(char*)NULL) {printf("\nIl mittente non viene accettato\n"); printf("\nMessaggio di errore:\n"); scrivi(bl,linea); exit(1); } //------------- RCPT TO: -------------- printf("Digitare il destinatario: "); scanf("%[!-~ ]",linea); c=getchar(); strcpy(to,linea); send(sockfd,"RCPT TO: ", strlen("RCPT TO: "),0); send(sockfd,linea,strlen(linea),0); send(sockfd,"\n",1,0); bl=read(sockfd,linea,400); VERB scrivi(bl,linea); if ((char*)strstr(linea,"250")==NULL) {printf("\nL'smtp server non consente il relay o user sconosciuto\n"); printf("\nMessaggio di errore:\n"); scrivi(bl,linea); exit(1); } //------------- DATA -------------- send(sockfd,"DATA\n",strlen("DATA\n"),0); bl=read(sockfd,linea,400); VERB scrivi(bl,linea); if ((char*)strstr(linea,"354")==NULL) {printf("\nSi e' verificato un errore in fase DATA\n"); printf("\nMessaggio di errore:\n"); scrivi(bl,linea); exit(1); } //------------- Received: -------------- printf("\nVuoi aggiungere un paio di \"Received: header\"? [s/n]"); c=getchar(); if (c=='s' || c=='S') { printf("\n\nn�1) \"Reveived:\"-->ip:"); scanf("%s",linea); c=getchar(); send(sockfd,"Received: from ", strlen("Received: from "),0); send(sockfd,linea,strlen(linea),0); printf("\n\nn�2) \"Reveived:\"-->ip:"); scanf("%s",linea); c=getchar(); send(sockfd,"\n\tby ",strlen("\n\tby "),0); send(sockfd,linea,strlen(linea),0); send(sockfd," with Express-mailer daemon 2.1\n", strlen(" with Express-mailer daemon 2.1\n"),0); send(sockfd,"Received: from ", strlen("Received: from "),0); send(sockfd,linea,strlen(linea),0); send(sockfd,"\tby localhost with SMTP daemon\n", strlen("\tby localhost with SMTP daemon\n"),0); } else getchar(); //------------- Message-ID -------------- bzero(linea,499); srand(((unsigned long)time(NULL))%99999); sprintf(linea,"Message-Id: <%d%d.",rand(),atoi(from)); srand((int)getpid()); sprintf(&linea[strlen(linea)],"%d@sales%d.microsoft.com>\n",rand(), (int)getpid()); send(sockfd,linea,strlen(linea),0); //------------- Date -------------- send(sockfd,"Date: unknown format\n",strlen("Date: unknown format\n"),0); //------------- From -------------- send(sockfd,"From: ",strlen("From: "),0); send(sockfd,from,strlen(from),0); send(sockfd,"\n",1,0); //------------- Organization -------------- send(sockfd,"Organization: www.microsoft.com\n", strlen("Organization: www.microsoft.com\n"),0); //------------- X-Mailer -------------- printf("\nVuoi aggiungere qualche \"X-Mailer header\" preconfezionato? [s/n]"); c=getchar(); if (c=='s' || c=='S') { printf("\nScegli il mailer che vuoi simulare:\n" "\na --> Mozilla 4.7 [en] (WinNT; I)" "\nb --> Mozilla 4.61 [en] (X11; I; Linux 2.2.13 i586" "\nc --> Mozilla 4.61 [en] (Win95; I)" "\nd --> Mozilla 4.5 [it] (Win98; I)" "\ne --> Microsoft Outlook Express 4.72.3110.5" "\nf --> Microsoft Outlook Express 5.00.2615.200" "\ng --> Microsoft Outlook 8.5, Build 4.71.2173.0" "\nh --> Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)" "\ni --> Mutt 1.0i" "\nl --> KMail [version 0.7.9]" "\nm --> Netscape Webmail" "\nn --> Calypso Version 3.10.03.02 (3)" "\no --> QUALCOMM Windows Eudora Pro Version 4.1" "\np --> XFMail 1.4.4 on Linux" "\nq --> The Bat! (v1.017) UNREG"); do { c=getchar();} while ( !(c>96 && c<114) && !(c>64&&c<83)); switch(c) { case 'a': send(sockfd,"X-Mailer: Mozilla 4.7 [en] (WinNT; I)\n", strlen("X-Mailer: Mozilla 4.7 [en] (WinNT; I)\n"),0);break; case 'b': send(sockfd,"X-Mailer: Mozilla 4.61 [en] (X11; I; Linux 2.2.13 i586\n", strlen("X-Mailer: Mozilla 4.61 [en] (X11; I; Linux 2.2.13 i586\n"),0);break; case 'c': send(sockfd,"X-Mailer: Mozilla 4.61 [en] (Win95; I)\n", strlen("X-Mailer: Mozilla 4.61 [en] (Win95; I)\n"),0);break; case 'd': send(sockfd,"X-Mailer: Mozilla 4.5 [it] (Win98; I)\n", strlen("X-Mailer: Mozilla 4.5 [it] (Win98; I)\n"),0);break; case 'e': send(sockfd,"X-Mailer: Microsoft Outlook Express 4.72.3110.5\n", strlen("X-Mailer: Microsoft Outlook Express 4.72.3110.5\n"),0);break; case 'f': send(sockfd,"X-Mailer: Microsoft Outlook Express 5.00.2615.200\n", strlen("X-Mailer: Microsoft Outlook Express 5.00.2615.200\n"),0);break; case 'g': send(sockfd,"X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0\n", strlen("X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0\n"),0);break; case 'h': send(sockfd,"X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)\n", strlen("X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)\n"),0);break; case 'i': send(sockfd,"X-Mailer: Mutt 1.0i\n", strlen("X-Mailer: Mutt 1.0i\n"),0);break; case 'l': send(sockfd,"X-Mailer: KMail [version 0.7.9]\n", strlen("X-Mailer: KMail [version 0.7.9]\n"),0);break; case 'm': send(sockfd,"X-Mailer: Netscape Webmail\n", strlen("X-Mailer: Netscape Webmail\n"),0);break; case 'n': send(sockfd,"X-Mailer: Calypso Version 3.10.03.02 (3)\n", strlen("X-Mailer: Calypso Version 3.10.03.02 (3)\n"),0);break; case 'o': send(sockfd,"X-Mailer: QUALCOMM Windows Eudora Pro Version 4.1\n", strlen("X-Mailer: QUALCOMM Windows Eudora Pro Version 4.1\n"),0);break; case 'p': send(sockfd,"X-Mailer: XFMail 1.4.4 on Linux\n", strlen("X-Mailer: XFMail 1.4.4 on Linux\n"),0);break; case 'q': send(sockfd,"X-Mailer: The Bat! (v1.017) UNREG\n", strlen("X-Mailer: The Bat! (v1.017) UNREG\n"),0);break; } } //------------- X-Accept-Language: -------------- send(sockfd,"X-Accept-Language: en\n", strlen("X-Accept-Language: en\n"),0); //------------- MIME-Version: -------------- send(sockfd,"MIME-Version: 1.0\n", strlen("MIME-Version: 1.0\n"),0); //------------- To: ------------- send(sockfd,"To: ",strlen("To: "),0); send(sockfd,to,strlen(to),0); send(sockfd,"\n",1,0); //------------- Subject: ------------- pulisci_buffer(); printf("\nSubject: "); scanf("%[!-~ ]",linea); getchar(); send(sockfd,"Subject: ",strlen("Subject: "),0); send(sockfd,linea,strlen(linea),0); send(sockfd,"\n",1,0); //------------- Content-Type: ------------- send(sockfd,"Content-Type: text/plain\n", strlen("Content-Type: text/plain\n"),0); //------------- X-Priority: ------------- send(sockfd,"X-Priority: 3\n",strlen("X-Priority: 3\n"),0); //------------- X-MIME-Autoconverted: ------------- send(sockfd,"X-MIME-Autoconverted: from quoted-printable to 8bit by mailerproc.microsoft.com id OAA00269\n", strlen("X-MIME-Autoconverted: from quoted-printable to 8bit by mailerproc.microsoft.com id OAA00269\n"),0); //------------- Content-Transfer-Encoding: ------------- send(sockfd,"Content-Transfer-Encoding: 8bit\n", strlen("Content-Transfer-Encoding: 8bit\n"),0); //------------- Body ------------- printf("\nDigitare il messaggio, finire con un punto in una linea vuota" "\n------------------------------------\n"); c=0; do { if (c!=0) pulisci_buffer(); scanf("%[!-~ ]",linea); send(sockfd,linea,strlen(linea),0); send(sockfd,"\n",1,0); c++; } while (!(linea[0]=='.' && strlen(linea)==1)); //------------- DISCONNECT -------------- bl=read(sockfd,linea,400); VERB scrivi(bl,linea); if ((char*)strstr(linea,"250")==NULL) {printf("\nATT -> La mail non e' stata accettata\n"); printf("\nMessaggio di errore:\n"); scrivi(bl,linea); exit(1); } else printf("------------------------------------\n" "La mail e' stata inoltrata correttamente"); send(sockfd,"quit\n",strlen("quit\n"),0); bl=read(sockfd,linea,400); VERB scrivi(bl,linea); printf("\n\n --[ fritz ]--" "\n Club SpiPPoLaTorI" "\n www.spippolatori.com\n\n"); } } void scrivi(int n,char *str) { int c; for (c=0;c