📄 p3pmail.c
字号:
Modified this to check decoded quoted-printable. */ if (firstline) { firstline = 0; } else if (strlen(lastfew) > 0 && ( (config->image&&(strcasecmp(lastfew,"sr")==0&&strncasecmp(buffer,"c",4)==0))|| (config->image&&(strcasecmp(lastfew,"s")==0&&strncasecmp(buffer,"rc",5)==0))|| (config->link&&(strcasecmp(lastfew,"hre")==0&&strncasecmp(buffer,"f",4)==0))|| (config->link&&(strcasecmp(lastfew,"hr")==0&&strncasecmp(buffer,"ef",5)==0))|| (config->link&&(strcasecmp(lastfew,"h")==0&&strncasecmp(buffer,"ref",6)==0)))){ // Ok, we have a match buffer[0] = 'x'; // this is enough to scramble the attribute } /* If there is a blank reasonably near the end of the line then we save the last few characters of current line for further processing with next line else we save an empty string */ p = rindex(buffer, ' '); //if (p && (bufferlength - (p - buffer) - 1 <= FEWCHARACTERS) && (buffer[bufferlength - 1] == '=')) { if (p && (bufferlength - (p - buffer) - 1 <= FEWCHARACTERS)) { strcpy(lastfew, p + 1); } else { lastfew[0] = '\0'; }}void finib64(FILE *bin,FILE *bout,char *line2){ rewind(bin); decode64(bin,bout); rewind(bin); rewind(bout); while((fgets(line2,MAX_BUF_SIZE,bout))!=NULL){#ifdef DEBUG printf("debug-pre64: %i:%s",strlen(line2),line2);#endif parsehtml(line2,strlen(line2));#ifdef DEBUG printf("debug-post64: %i:%s",strlen(line2),line2);#endif fputs(line2,bin); } rewind(bin); rewind(bout); encode64(bin,bout); rewind(bout); while((fgets(line2,MAX_BUF_SIZE,bout))!=NULL){ printf("%s",line2); } /* Base64 bug - Treat the symptom */ printf("\n"); return;}void printversion(){ printf( "\n" PROGNAME " " VERSION "\n" "(C) 2004 by Jack S. Lai, <laitcg@cox.net>\n" " and Gabriele Carioli, <bilo@sslmit.unibo.it>\n" "\n" );}void usage(){ printversion(); printf( "Usage: %s [options]\n" "\n" "where options are:\n" " -h, --help Prints this text\n" " -i, --image Allow html image src tag\n" " (default obfuscate)\n" " -l, --link Allow html link tag\n" " (default obfuscate)\n" " -v, --version Prints version information\n" ,PROGNAME);}int main(int argc, char **argv){ char line[MAX_BUF_SIZE],line2[MAX_BUF_SIZE]; int pasthdr=0,html=0,b64=0,toggle=0,skip=0,qp=0,bdone=0,eom=0; int newlen=0; FILE *qin=NULL; FILE *qout=NULL; FILE *bin=NULL; FILE *bout=NULL; //parse options: struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"image", no_argument, NULL, 'i'}, {"link", no_argument, NULL, 'l'}, {"version", no_argument, NULL, 'v'}, {NULL, no_argument, NULL, 0 } }; char getoptparam[] = "hilv"; void switchoption(char opt, char * arg, char * optstr, char * where, int state){ switch (opt){ case 'h': usage(); exit(0); break; case 'i': config->image=0; break; case 'l': config->link=0; break; case 'v': printversion(); exit(0); break; default: fprintf(stderr, "p3scan: %s Option '%s' isn't known\n", where, optstr); exit(1); } } void parseargs(int c, char **v, char * where, int state){ int option, option_index = 0; opterr=0; optind=1; while (1){ option = getopt_long(c, v, getoptparam, long_options, &option_index); if (option == EOF) break; switchoption(option, optarg, v[optind-1], where, state); } if (state != 1 && optind < c){ while (optind < c) fprintf(stderr, "%s Unknown option '%s'\n", where, v[optind++]); } } if ((config=malloc(sizeof(struct configuration_t)))==NULL){ fprintf(stderr, "malloc error\n"); exit(1); } /* set defaults */ config->image=1; config->link=1; parseargs(argc, argv, "\t[cmdlineparm]", 1); //start processing input: while ((fgets(line,MAX_BUF_SIZE,stdin))!=NULL){ if (strncasecmp(line,"Content-Type: text/html",23)==0) html=1; if (strncasecmp(line,"Content-Type: text/plain",23)==0) html=0; if (strncasecmp(line,"Content-Type: image",19)==0) skip=1; if (strncasecmp(line,"Content-Type: audio",19)==0) skip=1; if (strncasecmp(line,"Content-Type: video",19)==0) skip=1; if (strncasecmp(line,"Content-Type: application",25)==0) skip=1; if (strncasecmp(line,"Content-Disposition: attachment",31)==0) skip=1; if (strncasecmp(line,"Content-Transfer-Encoding: base64",33)==0 && !skip){ b64=1; bin=tmpfile(); bout=tmpfile();#ifdef DEBUG if (html) printf("\nFound HTML, Base64 only\n");#endif } //if ((strncasecmp(line,"Content-Transfer-Encoding: quoted-printable",43)==0) && html){ if ((strcasecmp(line,"Content-Transfer-Encoding: quoted-printable\n")==0) && html){ qp=1; qin=tmpfile(); qout=tmpfile();#ifdef DEBUG printf("\nFound HTML, quoted-printable\n");#endif } // at end of message? if ((strncmp(line,".\n",2)==0) || (strncmp(line,".\r",2)==0)) eom=1; /* Look for end of header*/ if (!pasthdr){ if ((*line == '\n') || (*line == '\r')){ pasthdr=1; printf("X-HTML-Parser: %s %s by %s\n",PROGNAME,VERSION,AUTHOR); toggle++; } printf("%s",line); } else { if (html){ // Quoted Printable if (qp > 1){ // Done? if((strncmp(line,"--",2)==0) || eom){#ifdef DEBUG printf("\nfound end of qp\n");#endif qp=0; rewind(qin);#ifdef DEBUG while((fgets(line2,MAX_BUF_SIZE,qin))!=NULL) printf("pre-decode: %s",line2); rewind(qin); printf("\ngoing to decode...\n");#endif qdecode(qin,qout);#ifdef DEBUG printf("\ndecode complete.\n");#endif rewind(qin); rewind(qout); while((fgets(line2,MAX_BUF_SIZE,qout))!=NULL){#ifdef DEBUG printf("debug-qp: %s",line2);#endif parsehtml(line2,strlen(line2)); fputs(line2,qin); } rewind(qin); rewind(qout); qencode(qin,qout); fclose(qin); // don't need it anymore rewind(qout); while((fgets(line2,MAX_BUF_SIZE,qout))!=NULL){ printf("%s",line2); } fclose(qout); // don't need it anymore } // No, not done, continue... // writing eom, reset eom variable so it is not written again //if ((strncmp(line,".\n",2)==0) || (strncmp(line,".\r",2)==0)) eom=0; if (qp) fputs(line,qin); } // Base64 if (b64){ if(skip){ printf("%s",line); }else{ if (strncasecmp(line,"Content-Transfer-Encoding: base64",33)==0) printf("%s",line); // Done? if (eom) bdone=1; if (bdone){ b64=0; finib64(bin,bout,line2); fclose(bin); // don't need it anymore fclose(bout); // don't need it anymore } // No, continue... // do we have a base64 encoded line? if (newlen==0 && strlen(line) > 40) newlen = strlen(line) -1; // 40 is an arbitrary number if (newlen > 0){ fputs(line,bin); if(strlen(line)==1) bdone=1; // wrote eom, reset eom variable so it is not written again //if((strncmp(line,".\n",2)) || (strncmp(line,".\r",2))) eom=0; }#ifdef DEBUG printf("len:%i-bdone-%i:%s",strlen(line),bdone,line);#endif } } if (!qp && !b64){#ifdef DEBUG printf("debug: %s",line);#endif parsehtml(line,strlen(line)); // writing eom, reset eom variable so it is not written again //if ((strncmp(line,".\n",2)==0) || (strncmp(line,".\r",2)==0)) eom=0; printf("%s",line); } if ((*line == '\n') || (*line =='\r')) toggle++; if (qp==1){ printf("%s",line); qp++; } } else { /* dont parse non-html*/ // writing eom, reset eom variable so it is not written again //if ((strncmp(line,".\n",2)==0) || (strncmp(line,".\r",2)==0)) eom=0; if (!bdone) printf("%s",line); } /* Keep skipping until past the header */ } } /* All done, clean up */ if(b64){ // we are not done! b64=0;#ifdef DEBUG printf("\nBase64 incomplete, finishing...\n" );#endif finib64(bin,bout,line2); }/* if (eom){ // eom was not written.#ifdef DEBUG printf("\nGenerating eom\n");#endif printf("\n."); }*/#ifdef DEBUG2 fprintf(stderr,"%i",b64eom);#endif return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -