Last active
August 25, 2018 12:48
-
-
Save lojikil/21f2ac78cab2dc8966bffb3889ee5470 to your computer and use it in GitHub Desktop.
converts datasploit text dumps to CSV, consumable by other tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @(#) converts datasploit text dumps to CSV, consumable by other tools | |
* @(#) copyright 2018 Stefan Edwards, released under ISC license | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdint.h> | |
#include <regex.h> | |
int etlfile(FILE *, regex_t *, regex_t *); | |
int | |
main(int ac, char **al) { | |
FILE *fdin = NULL; | |
regex_t startre, endre; | |
if((regcomp(&startre, "List of Subdomains found", REG_EXTENDED|REG_NOSUB|REG_ICASE)) != 0) { | |
printf("starting regular expression compilation failure."); | |
return 2; | |
} | |
if((regcomp(&endre, "Searching in Shodan", REG_EXTENDED|REG_NOSUB|REG_ICASE)) != 0) { | |
printf("ending regular expression compilation failure."); | |
return 2; | |
} | |
if(ac < 2) { | |
etlfile(stdin, &startre, &endre); | |
return 0; | |
} | |
for(uint32_t idx = 1; idx < ac; idx++) { | |
fdin = fopen(al[idx], "r"); | |
if(!fdin) { | |
printf("an error occurred opening: %s\n", al[idx]); | |
return 2; | |
} | |
etlfile(fdin, &startre, &endre); | |
fclose(fdin); | |
} | |
regfree(&startre); | |
regfree(&endre); | |
return 0; | |
} | |
int | |
etlfile(FILE *fdin, regex_t *startre, regex_t *endre) { | |
char buf[4096] = {0}; | |
uint8_t printflag = 0; | |
int status = 0; | |
size_t len = 0; | |
while(1) { | |
if(feof(fdin)) { | |
break; | |
} | |
if(fgets(&buf[0], 4096, fdin) == NULL) { | |
break; | |
} | |
len = strnlen(buf, 4096); | |
// remove the trailing newline | |
buf[len - 1] = '\0'; | |
// replace escape sequences | |
for(size_t idx = 0; idx < len; idx++) { | |
if(buf[idx] == 0x1b) { | |
buf[idx] = 32; | |
} | |
} | |
if(!printflag) { | |
status = regexec(startre, &buf[0], (size_t) 0, NULL, 0); | |
if(!status) { | |
printflag = 1; | |
} | |
} else { | |
status = regexec(endre, &buf[0], (size_t) 0, NULL, 0); | |
if(!status) { | |
printflag = 0; | |
} else { | |
printf("%s,DATASPLOIT,\"no data\"\n", buf); | |
} | |
} | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment