Last active
April 16, 2018 03:03
-
-
Save slayerlab/cacc2da309d516e0a2043c5faa7f947b to your computer and use it in GitHub Desktop.
Check the most recent post in exploit-db.com in just one click! :) see below about dependencies and compilation.
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
/*** | |
* toolname: check_exploit.c | |
* synopsis: Check the most recent post in Exploit-DB parsing an rss.xml | |
* using LibXML2 | |
* purpose: Demonstrate the use of xmlReaderForFile() to parse an XML file | |
* validating the content in the process and activating options | |
* like entities substitution, and DTD attributes defaulting. | |
* (Note that the XMLReader functions require libxml2 version later | |
* than 2.6.) -- just for education coding. | |
* usage: check_exploit.c <filename> | |
* compiling: gcc -o <output> <source.c> $(xml2-config --libs --cflags) | |
* author: sl4y3r_0wn3r | slayer owner | |
* copy: w8 dude, it is really necessary? | |
***/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <libxml/xmlreader.h> | |
#ifdef LIBXML_READER_ENABLED | |
static inline void /* if return error */ | |
print_usage(const char *argv0); | |
static void /* filename.xml handling */ | |
streamFile(const char *filename); /* filename to parse */ | |
static void | |
processNode(xmlTextReaderPtr reader); | |
int main(int argc, char *argv[]) | |
{ | |
int ReturnToExit = EXIT_SUCCESS; | |
if (argc != 2){ | |
print_usage(argv[0]); | |
goto b_ReturnToExit; | |
} | |
LIBXML_TEST_VERSION /* (Macro) for testing API */ | |
streamFile(argv[1]); | |
xmlCleanupParser(); | |
xmlMemoryDump(); | |
return ReturnToExit; /* EXIT_SUCCESS; */ | |
b_ReturnToExit: | |
ReturnToExit = EXIT_FAILURE; | |
return ReturnToExit; | |
} | |
#else | |
void main(void) | |
{ | |
fprintf(stderr, | |
"XInclude support not compiled in\n"); | |
exit(EXIT_FAILURE); | |
} | |
#endif | |
/** | |
* processNode: | |
* @reader: xmlReader | |
* | |
* Dump the current node information | |
**/ | |
static void | |
processNode(xmlTextReaderPtr reader) | |
{ | |
const xmlChar *name, *value; | |
name = xmlTextReaderConstName(reader); | |
if (name == NULL) | |
name=BAD_CAST "--"; | |
value = xmlTextReaderConstValue(reader); | |
if ((value == NULL)){ } | |
else{ | |
if (xmlStrlen(value) > 100) | |
printf(" %.100s...\n",value); | |
else | |
printf(" %s",value); | |
} | |
} | |
/** | |
* streamFile: | |
* @filename: *filname | |
* | |
* XML file is validate and print information inside. | |
**/ | |
static void | |
streamFile(const char *filename) | |
{ | |
xmlTextReaderPtr reader; | |
int ret; | |
reader = xmlReaderForFile(filename,NULL, /* filename,encoding,int option */ | |
// XML_PARSE_DTDATTR | /* DTD attr defaults */ | |
// XML_PARSE_DTDVALID | /* No Entities */ | |
XML_PARSE_NOENT);/* Valide with the DTD */ | |
if (reader != NULL){ | |
ret = xmlTextReaderRead(reader); | |
while (ret == 1){ | |
processNode(reader); | |
ret = xmlTextReaderRead(reader); | |
} | |
if (!!(xmlTextReaderIsValid(reader))){ /* edit !! for ! to enable xml validate */ | |
fprintf(stderr, | |
"Document %s does not validate\n", filename); | |
} | |
xmlFreeTextReader(reader); | |
if (ret != 0){ | |
fprintf(stderr, | |
"%s: failed to parse\n", filename); | |
} | |
}else{ | |
fprintf(stderr,"Unable to open %s\n",filename); | |
} | |
} | |
static inline void | |
print_usage(const char *argv0) | |
{ | |
fprintf(stderr, | |
"[!] Usage: %s <filename>\n",argv0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
installing LibXML2:
compiling:
execute:
Preview: http://i.imgur.com/EleRdUI.png