Exemplo n.º 1
0
int run(LOGGER log, struct config config) {
	sqlite3* db = sqlite_service_connect(log, config.dbpath);

	curl_global_init(CURL_GLOBAL_SSL);

	if (!db) {
		return 1;
	}

	if (config.single) {
		QUIT = 1;
	}
	if (prepare_statements(log, db)) {
		return 2;
	}
	spider(log, db, config.hash, config.tree);
	while(!QUIT) {
		begin_transaction(log, db);
		spider(log, db, config.hash, config.tree);
		commit_transaction(log, db);
		sleep(config.sleep);
	}
	finalize_statements(log);
	sqlite_service_close(log, db);

	curl_global_cleanup();
	return 0;
}
Exemplo n.º 2
0
SpiderBuilder::SpiderBuilder(){
	Spider spider();
	this->spider.frame = 0;
	Leg l = Leg(-10, 50, 0.55, 0.5);
	this->spider.legs.push_back(l);
	l = Leg(5, 40, 0.52, 0.4);
	this->spider.legs.push_back(l);
	l = Leg(-10, 50, 0.52, 0.4);
	this->spider.legs.push_back(l);
	l = Leg(10, 45, 0.6, 0.5);
	this->spider.legs.push_back(l);
	this->spider.isRedirecting = false;
	this->spider.redirectFinish = false;
	this->spider.aliveFlag = true;
	this->done = false;
}
Exemplo n.º 3
0
void scan(void *arguments)
{
	FILE *fp=NULL;
        int num1=0,num2=0;

	char **arg = (char **)arguments;
	char *pathtable=NULL,*pathhammer=NULL,*view=NULL,*template2=NULL,*template3=NULL;
	char line[2048]; 

	pid_t pid;

	if(arg[11]!=NULL)
		threadss=atoi(arg[11]);

	int old_thread=threadss;
	int status=-1;

 	int timeout=3;

	if(arg[8]!=NULL)
		timeout=atoi(arg[8]);
 
	pathtable=xmalloc(sizeof(char)*64);
	memset(pathtable,0, sizeof(char)*63);
	strncat(pathtable,"tables/",8);
	strncat(pathtable,arg[5],16);
	strncat(pathtable,".txt",5);
	fp = fopen(arg[1], "r");

 	if ( !fp )
	{ 
		DEBUG("error to open Payload list"); 
		exit(1);
	}

        num1=FileSize(TEMPLATE2);
        num2=FileSize(TEMPLATE3); 

	view=xmalloc(sizeof(char)*(num1+num2+42));
	memset(view,0,sizeof(char)*(num1+num2+1));

      //  template2=xmalloc(sizeof(char)*num1+1);
        template2=readLine(TEMPLATE2);
	strncat(view,template2,num1+1);
	strncat(view,"\"sAjaxSource\": \"",23);
	strncat(view,arg[5],16);
	strncat(view,".txt\" \n",9);

      //  template3=xmalloc(sizeof(char)*num2+1);
        template3=readLine(TEMPLATE3);

	strncat(view,template3,num2);

	pathhammer=xmalloc(sizeof(char)*64);
	memset(pathhammer,0,sizeof(char)*63);
	strncat(pathhammer,"tables/hammer_",15);
	strncat(pathhammer,arg[5],16);
	strncat(pathhammer,".html",6);
	WriteFile(pathhammer,view);
	WriteFile(pathtable,"{ \"aaData\": [ \n");

	puts("start...");

// TODO add my thread pool library
	while ( fgets(line,2047,fp) != NULL ) 
	{
		curl_global_cleanup();
		pid=fork();
		curl_global_init(CURL_GLOBAL_ALL);

 
		if(pid==-1)
		{
			DEBUG("error in fork()");
			exit(1);
		}

		if(!pid)
		{

//			curl_global_init(CURL_GLOBAL_ALL);
			threadss--;
			spider(arguments,line,pathtable);
//			curl_global_cleanup();
			exit(0);
		}
		
		if(threadss<=0)
		{
				while(1)
				{
					pid=wait(&status);	

						if (errno == ECHILD)
						{
							break;
						}
						
				}

				threadss=old_thread;							
		}

  	}

	threadss=0;


	while(1)
	{
		pid=wait(&status);	

		if (errno == ECHILD)
		{
			break;
		}
	}				

	sleep(timeout);

	WriteFile(pathtable," [\"\",\"\",\"\",\"\",\"\"] \n ] }");

	puts(RED);
	fprintf(stdout,"end scan \n look the file %s\n \n",pathhammer);
	puts(LAST);

	memset(pathtable,0,sizeof(char)*strlen(pathtable)-1);
	xfree((void **)&pathtable);
	memset(pathhammer,0,sizeof(char)*strlen(pathhammer)-1);
	xfree((void **)&pathhammer);
	memset(view,0,sizeof(char)*strlen(view)-1);
	xfree((void **)&view);


	xfree((void **)&template2);
	xfree((void **)&template3);



	if( fclose(fp) == EOF )
	{
		DEBUG("Error in close()");
		exit(1);
	}

	fp=NULL;

	exit(0);
}