int test_igd_desc_parse(char * buffer, int len, FILE * f)
{
	int n;
	struct IGDdatas igd;
	struct xmlparser parser;
	struct UPNPUrls urls;

	memset(&igd, 0, sizeof(struct IGDdatas));
	memset(&parser, 0, sizeof(struct xmlparser));
	parser.xmlstart = buffer;
	parser.xmlsize = len;
	parser.data = &igd;
	parser.starteltfunc = IGDstartelt;
	parser.endeltfunc = IGDendelt;
	parser.datafunc = IGDdata;
	parsexml(&parser);
#ifdef DEBUG
	printIGD(&igd);
#endif /* DEBUG */
	GetUPNPUrls(&urls, &igd, "http://fake/desc/url/file.xml", 0);
	printf("ipcondescURL='%s'\n", urls.ipcondescURL);
	printf("controlURL='%s'\n", urls.controlURL);
	printf("controlURL_CIF='%s'\n", urls.controlURL_CIF);
	n = f ? compare_igd(&igd, f) : 0;
	FreeUPNPUrls(&urls);
	return n;
}
static void upnpc_desc_received(struct evhttp_request * req, void * pvoid)
{
	size_t len;
	unsigned char * data;
	struct evbuffer * input_buffer;
	struct IGDdatas igd;
	struct xmlparser parser;
	upnpc_device_t * d = (upnpc_device_t *)pvoid;

	if(req == NULL) {
		debug_printf("%s(%p, %p) NULL argument !\n", __func__, req, pvoid);
		return;
	}
	input_buffer = evhttp_request_get_input_buffer(req);
	len = evbuffer_get_length(input_buffer);
	data = evbuffer_pullup(input_buffer, len);
	debug_printf("%s %d (%d bytes)\n", __func__, evhttp_request_get_response_code(req), (int)len);
	if(evhttp_request_get_response_code(req) != HTTP_OK) {
		d->parent->ready_cb(evhttp_request_get_response_code(req), d->parent, d, d->parent->cb_data);
		return;
	}
	if(data == NULL) {
		d->parent->ready_cb(UPNPC_ERR_ROOT_DESC_ERROR, d->parent, d, d->parent->cb_data);
		return;
	}
	debug_printf("%.*s\n", (int)len, (char *)data);

	memset(&igd, 0, sizeof(struct IGDdatas));
	memset(&parser, 0, sizeof(struct xmlparser));
	parser.xmlstart = (char *)data;
	parser.xmlsize = len;
	parser.data = &igd;
	parser.starteltfunc = IGDstartelt;
	parser.endeltfunc = IGDendelt;
	parser.datafunc = IGDdata;
	parsexml(&parser);
#ifdef DEBUG
	printIGD(&igd);
#endif /* DEBUG */
	d->control_conn_url = build_url_string(igd.urlbase, d->root_desc_location, igd.first.controlurl);
	d->event_conn_url = build_url_string(igd.urlbase, d->root_desc_location, igd.first.eventsuburl);
	d->conn_service_type = strdup(igd.first.servicetype);
	d->control_cif_url = build_url_string(igd.urlbase, d->root_desc_location, igd.CIF.controlurl);
	d->event_cif_url = build_url_string(igd.urlbase, d->root_desc_location, igd.CIF.eventsuburl);
	d->cif_service_type = strdup(igd.CIF.servicetype);
	debug_printf("control_conn_url='%s'\n  (service_type='%s')\n",
	             d->control_conn_url, d->conn_service_type);
	debug_printf("event_conn_url='%s'\n", d->event_conn_url);
	debug_printf("control_cif_url='%s'\n  (service_type='%s')\n",
	             d->control_cif_url, d->cif_service_type);

	if((d->cif_service_type == NULL)
	  || (strlen(d->cif_service_type) == 0)
	  || (!COMPARE(d->cif_service_type, "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:"))) {
		d->parent->ready_cb(UPNPC_ERR_NOT_IGD, d->parent, d, d->parent->cb_data);
	} else {
		d->state |= UPNPC_DEVICE_GETSTATUS;
		upnpc_get_status_info(d);
	}
}
Exemple #3
0
struct SVGPath* svgParse(char* input)
{
	struct SVGParser* p;
	struct SVGPath* ret = 0;

	p = svgCreateParser();
	if (!p)
		return 0;

	p->tol = 1.0f;

	parsexml(input, svgStartElement, svgEndElement, svgContent, p);

	if (p->buf)
	{
		free(p->buf);
		p->buf = NULL;
		p->nbuf = 0;
		p->cbuf = 0;
	}

	ret = p->plist;
	p->plist = 0;

	svgDeleteParser(p);

	return ret;
}
Exemple #4
0
/* destroy the session on the server side */
void destroysession()
{
	int sd;
	char *xml, query[256];

	sprintf(query, "/destroysession.php?sessionid=%s", xmlxml.sessionid);
	do
	{
		*xmlxml.error = 0;
		sd = getconnection(host_entry, gijohnport);
		getxml(sd, &xml, query, gijohnserver, gijohnport, 0);
		close(sd);
		parsexml(xml);
		free(xml);
		if (*xmlxml.error)
		{
			printf("[-] Error: destroying session: %s\n[+] Sleeping for %dsec... and resending\n", xmlxml.error, SLEEP_TIME);
			sleep(SLEEP_TIME);
		}
	}
	while (*xmlxml.error);

	if (options.flags & FLG_VERBOSE) printf("[+] Session destroyed\n[+] Thanks for using GI John!\n");

	return;
}
Exemple #5
0
/* root description parsing */
void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data)
{
	struct xmlparser parser;
	/* xmlparser object */
	parser.xmlstart = buffer;
	parser.xmlsize = bufsize;
	parser.data = data;
	parser.starteltfunc = IGDstartelt;
	parser.endeltfunc = IGDendelt;
	parser.datafunc = IGDdata;
	parser.attfunc = 0;
	parsexml(&parser);
}
Exemple #6
0
void
ParseNameValue(const char * buffer, int bufsize,
                    struct NameValueParserData * data)
{
    struct xmlparser parser;
    LIST_INIT(&(data->head));
    /* init xmlparser object */
    parser.xmlstart = buffer;
    parser.xmlsize = bufsize;
    parser.data = data;
    parser.starteltfunc = NameValueParserStartElt;
    parser.endeltfunc = 0;
    parser.datafunc = NameValueParserGetData;
    parser.attfunc = 0;
    parsexml(&parser);
}
Exemple #7
0
/* root description parsing */
MINIUPNP_LIBSPEC void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data)
{
	struct xmlparser parser;
	/* xmlparser object */
	parser.xmlstart = buffer;
	parser.xmlsize = bufsize;
	parser.data = data;
	parser.starteltfunc = IGDstartelt;
	parser.endeltfunc = IGDendelt;
	parser.datafunc = IGDdata;
	parser.attfunc = 0;
	parsexml(&parser);
#ifdef DEBUG
	printIGD(data);
#endif
}
/* Parse the PortMappingList XML document for IGD version 2
 */
void
ParsePortListing(const char * buffer, int bufsize,
                 struct PortMappingParserData * pdata)
{
	struct xmlparser parser;

	memset(pdata, 0, sizeof(struct PortMappingParserData));
	/* init xmlparser */
	parser.xmlstart     = buffer;
	parser.xmlsize      = bufsize;
	parser.data         = pdata;
	parser.starteltfunc = startelt;
	parser.endeltfunc   = endelt;
	parser.datafunc     = portlisting_data;
	parser.attfunc      = 0;
	parsexml(&parser);
}
void
ParseNameValue(const char * buffer, int bufsize,
               struct NameValueParserData * data)
{
	struct xmlparser parser;
	data->l_head = NULL;
	data->portListing = NULL;
	data->portListingLength = 0;
	/* init xmlparser object */
	parser.xmlstart = buffer;
	parser.xmlsize = bufsize;
	parser.data = data;
	parser.starteltfunc = NameValueParserStartElt;
	parser.endeltfunc = NameValueParserEndElt;
	parser.datafunc = NameValueParserGetData;
	parser.attfunc = 0;
	parsexml(&parser);
}
// bof !
void burptest(const char * buffer, int bufsize)
{
	struct IGDdatas data;
	struct xmlparser parser;
	// objet IGDdatas
	bzero(&data, sizeof(struct IGDdatas));
	// objet xmlparser
	parser.xmlstart = buffer;
	parser.xmlsize = bufsize;
	parser.data = &data;
	/*parser.starteltfunc = printeltname1;
	parser.endeltfunc = printeltname2;
	parser.datafunc = printdata; */
	parser.starteltfunc = IGDstartelt;
	parser.endeltfunc = IGDendelt;
	parser.datafunc = IGDdata; 
	parsexml(&parser);
	printIGD(&data);
}
Exemple #11
0
int test_igd_desc_parse(char * buffer, int len)
{
	struct IGDdatas igd;
	struct xmlparser parser;
	struct UPNPUrls urls;
	memset(&igd, 0, sizeof(struct IGDdatas));
	memset(&parser, 0, sizeof(struct xmlparser));
	parser.xmlstart = buffer;
	parser.xmlsize = len;
	parser.data = &igd;
	parser.starteltfunc = IGDstartelt;
	parser.endeltfunc = IGDendelt;
	parser.datafunc = IGDdata;
	parsexml(&parser);
	printIGD(&igd);
	GetUPNPUrls(&urls, &igd, "http://fake/desc/url/file.xml", 0);
	printf("ipcondescURL='%s'\n", urls.ipcondescURL);
	printf("controlURL='%s'\n", urls.controlURL);
	printf("controlURL_CIF='%s'\n", urls.controlURL_CIF);
	FreeUPNPUrls(&urls);
	return 0;
}
Exemple #12
0
/* sending the result */
void sendtheresults()
{
	char *post, *post2, *xml;
	int sd;

	makeitvalidxml(&post);
	if ((post2 = malloc(sizeof(char)*strlen(post)*3+1)) == NULL)
	{
		fprintf(stderr, "Malloc error...\n");
		exit(1);
	}
	urlencode(post, post2);
	free(post);
	post = post2;

	do
	{
		*xmlxml.error = 0;
		sd = getconnection(host_entry, gijohnport);
		postxml(sd, &xml, "/sendhashes.php", gijohnserver, gijohnport, post/*, 0*/);
		close(sd);
		parsexml(xml);
		free(xml);
		if (xmlxml.error[0])
		{
			printf("[-] Error (post): %s\n[+] Sleeping for %dsec... and resending\n", xmlxml.error, SLEEP_TIME);
			sleep(SLEEP_TIME);
		}
	}
	while (*xmlxml.error);

	free(post);
	if (options.flags & FLG_VERBOSE) printf("[+] %d cracked hash sent\n", crackedhashnum);
	free(crackedhash);
	crackedhashnum = 0;
	crackedhash = NULL;

	return;
}
Exemple #13
0
int testxmlparser(const char * xml, int size)
{
	int r;
	struct eventlist evtlist;
	struct eventlist evtlistref;
	struct xmlparser parser;
	evtlist.n = 0;
	evtlist.events = malloc(sizeof(struct event)*100);
	memset(&parser, 0, sizeof(parser));
	parser.xmlstart = xml;
	parser.xmlsize = size;
	parser.data = &evtlist;
	parser.starteltfunc = startelt;
	parser.endeltfunc = endelt;
	parser.datafunc = chardata;
	parsexml(&parser);
	printf("%d events\n", evtlist.n);
	/* compare */
	evtlistref.n = sizeof(evtref)/sizeof(struct event);
	evtlistref.events = (struct event *)evtref;
	r = evtlistcmp(&evtlistref, &evtlist);
	free(evtlist.events);
	return r;
}
Exemple #14
0
/* getting the new datas*/
int getthenewpiece()
{
	int sd, i;
	char *xml, query[256], *post, *post2;

	if (firstrun)
	{
		splitserver(gijohnserver, &gijohnport);
		if ((xmlxml.newhashes = malloc(sizeof(char))) == NULL)
		{
			fprintf(stderr, "Malloc error...\n");
			exit(1);
		}
		*xmlxml.newhashes = 0;
		if ((xmlxml.delhashes = malloc(sizeof(char))) == NULL)
		{
			fprintf(stderr, "Malloc error...\n");
			exit(1);
		}
		*xmlxml.newhashes = 0;
		memset(xmlxml.format, '\0', 64);
		memset(xmlxml.keymap.firstword, '\0', 64);
		memset(xmlxml.keymap.lastword, '\0', 64);
		memset(xmlxml.keymap.charset, '\0', 256);
		memset(xmlxml.error, '\0', 1024);
		memset(xmlxml.sessionid, '\0', 33);
	}

	if (getnewsid)
	{		
		getini(username, password);		
		makeformatandperformancexml(&post, username, password);
		if ((post2 = malloc(sizeof(char)*strlen(post)*3+1)) == NULL)
		{
			fprintf(stderr, "Malloc error...\n");
			exit(1);
		}
		urlencode(post, post2);
		free(post);
		post = post2;
		setbuf(stdout, NULL);
		if (options.flags & FLG_VERBOSE) printf("[+] Getting new session\n");

		if (gijohnsmp > 1) {
			for (i = 1; i < gijohnsmp; i++) {
				if (!fork()) {
					sessionname = malloc(sizeof(char)*30);
					memset(sessionname, 0, 30);
					sprintf(sessionname, "gijohnfork_%d", i);
					rec_name = sessionname;
					break;
				}
			}
		}

		sprintf(query, "/newsession.php");

		do
		{
			*xmlxml.error = 0;
			host_entry = getthehostname(gijohnserver);
			if ((sd = getconnection(host_entry, gijohnport)) < 0)
			{
				strncpy(xmlxml.error, "connection error",
				    strlen("connection error"));
				printf("[-] Connection error\n[+]"
				" Sleeping for %dsec... and reconnection\n", SLEEP_TIME);
				sleep(SLEEP_TIME);
			}
			else
			{
				postxml(sd, &xml, query, gijohnserver, gijohnport, post);
				close(sd);
				parsexml(xml);
				free(xml);
				if (*xmlxml.error)
				{
					printf("[-] Error (new sessionid): %s\n[+]"
					" Sleeping for %dsec... and resending\n", xmlxml.error, SLEEP_TIME);
					sleep(SLEEP_TIME);
				}
			}

		}
		while (*xmlxml.error);
		free(post);
		getnewsid = 0;
		if (options.flags & FLG_VERBOSE) printf("[+] New session is: %s\n", xmlxml.sessionid);
	}
	if (xmlxml.upgrade)
	{
		printf("[!] You have to upgrade your gijohn, because it's too old to use! Exiting...\n");
		destroysession();
		exit(1);
	}

	sprintf(query, "/getpieces.php?sessionid=%s", xmlxml.sessionid);
	do
	{
		*xmlxml.error = 0;
		if ((sd = getconnection(host_entry, gijohnport)) < 0)
		{
			strncpy(xmlxml.error, "connection error",
			    strlen("connection error"));
			printf("[-] Connection error\n[+]"
			" Sleeping for %dsec... and reconnection\n", SLEEP_TIME);
			sleep(SLEEP_TIME);
		}
		else
		{
			getxml(sd, &xml, query, gijohnserver, gijohnport, options.flags & FLG_VERBOSE);
			close(sd);
			parsexml(xml);
			free(xml);
			if (*xmlxml.error)
			{
				printf("[-] Error (new keyspace): %s\n[+] "
				"Sleeping for %dsec... and resending\n", xmlxml.error, SLEEP_TIME);
				sleep(SLEEP_TIME);
			}
		}
	}
	while (*xmlxml.error);

	if (firstrun)
	{
		ldr_init_database(&database, &options.loader);
	}

	if (xmlxml.clearhashes)
	{
		memset(&database, '\0', sizeof(struct db_main));
		ldr_init_database(&database, &options.loader);
	}

	if (*xmlxml.error == 0)
	{
		if (*xmlxml.newhashes) ldr_load_xml_array(&database, xmlxml.newhashes, xmlxml.format);
		if (*xmlxml.delhashes) ldr_load_xml_delarray(&database, xmlxml.delhashes);
		if (*xmlxml.newhashes || *xmlxml.delhashes) ldr_fix_xmldatabase(&database, xmlxml.clearhashes | firstrun);
	}
	else
	{
		printf("[-] Error: %s\n", xmlxml.error); exit(1);
	}

	if ((options.flags & FLG_VERBOSE) || firstrun)
	{
		log_event("Remaining %s", john_loaded_counts());
		printf("[+] Loaded %s (%s [%s])\n",	john_loaded_counts(),
		database.format->params.format_name,
		database.format->params.algorithm_name);
	}

	if (firstrun)
	{
		printf("[+] Server: %s\n[+] Charset: %s\n[+] Charset length: %d\n", gijohnserver, xmlxml.keymap.charset, (int)strlen(xmlxml.keymap.charset));
	}

	return 0;
}