


	gooscan-1.c

this program is written to get the results for dorks in your dork file which has to be
supplied to the program as the first parameter. if you want to use a proxy you can give
the program a second parameter for example: proxy.anonymous.net:3334. 

     1	#include <stdio.h>
     2	#include <stdlib.h>
     3	#include <errno.h>
     4	#include <sys/time.h>
     5	
     6	#include "goo.h"
     7	

     8	int main(int argc, char **argv)
     9	{
    10		int i, max;
    11		FILE *fd;
    12		char buf[255];
    13		goo_t goo;
    14		cli_ans ans;
    15		time_t thetime;

    16	
    17		if(argc != 2) {
    18			printf("%s <dork-file> [proxy.domain.de:port]\n",argv[0]);
    19			return 0;
    20		}
    21		if( (fd = fopen(argv[1], "r")) == NULL) {
    22			perror("fopen");
    23			return 0;
    24		}

    25	
    26		goo = init_goo();
    27		if(goo.resultc != SUCCESS) {
    28			goo_prnt_er(&goo);
    29			return 0;
    30		}

    31		goo_cli(1,&goo);
    32		if(!goo_cli_cnt(&goo)) {
    33			goo_prnt_er(&goo);
    34			return 0;
    35		}

    36		goo_cli_set(1, GETRESLT, NULL, &goo);
    37		if(argc == 3) 
    38			goo_cli_set(1, SETPRXY, argv[2], &goo);
    39		

    40	
    41		while(!feof(fd)) {
    42			if(fgets(buf,255,fd) == NULL) break;
    43			buf[strlen(buf)-1] = '\0';
    44			goo_cli_req(1, buf, &goo,0);
    45	

    46			thetime = time(NULL);
    47			while(1) {
    48				if(thetime < (time(NULL)-10)) break;  //break after 10 seconds
    49				ans = goo_results(&goo);		//check for client answer
    50				if(goo.resultc != NOANSWER)   {  // we received an answer
    51					if(goo.resultc != SUCCESS) {  //some error occured
    52						goo_prnt_er(&goo);    //print the error and break
    53						break;			//the loop
    54					}
    55	                                printf("\t\t%s: %u results\n",ans.req,ans.goo_res);
							//print the results
    56					break;
    57				}
    58				usleep(100000);  //dont harm your cpu
    59			}
    60		}

    61		fclose(fd);
    62		delete_goo(&goo);
    63		return 1;
    64	}

line 1-7:
	include the needed headerfiles. the goo.c has to be in the working directory in 
	this case.
line 8-15:
	declarate the needed data types. "goo_t" is always needed if you are woring with gool
	and "cli_ans" is for receiving the clients answers.
line 16-24:
	everything should be clear...
line 25-30:
	initializies the goo with goo_init(). this fuction might fail in some special cases
	and will return a result-code which is not SUCCESS. then it might be helpful to print
	out the error message with the goo_print_er fuction.
line 31-35
	goo_cli with the parameter "1" will create one child. we dont check the return value
	of the function here cause we want to use the goo_cli_cnt function which returns the
	number of successfully created clients. if the return value is zero we print the 
	error message and exit with 0.
line 36-39
	now it is time to tell the client who he should work. with the GETRESLT option we
	will tell the client to give as the results of a serach as a long value. in line
	38 you can see how to set a proxy. you should note that there is no check implemented for
	the functionallity of the proxy! if you supplie a proxy which doesnt work as it should
	the program will show you nothing but connect error messages.
line 40-45:
	as usual the program reads a dork file. the dorks are sepperated by each other with a
	linebreak. in line 44 we are sending a single request which is stored in "buf" to the
	client with the id of 1. the fourth argument is zero - it is ignored in this case
	because we have set the GETRESLT option.
line 46-60
	we want to receive immediatly the answer to our single request in the upper code. 
	therefor we will wait maximal 10 seconds for the answer or we stop the loop if we
	receive a client answer for the request. see the comments for better understanding.
	line 55 will print the results as the resultvalue is stored in "ans.req" and the
	requested dork is kept in "ans.goo_res".
	line 58 makes sense as we dont want to eat all cpu power.
line 61-64
	with delete_goo we will free the mallocs and close opened message queues for the
	ipc. dont forget to clean up the gool stuff!


badass@badhost:~/goo/testlab> gcc -o prog  gooscan-1.c goo.c
badass@badhost:~/goo/testlab> time ./prog dork.dat
                inurl:admin ext:asp login.asp: 144000 results
                ext:pwd service.pwd: 86 results
                ext:cfg ks.cfg -example -test: 122 results
                johnny.long: 211000 results
                johnny.ihackstuff: 64600 results
                l0om: 9300 results
                ext:asp inurl:id shop: 2790000 results
                inurl:login login ext:php: 2900000 results
                immanuel.kant: 2090000 results
                john.locke: 1810000 results
                intitle:index.of private: 171000 results
                intitle:index.of asdf: 731 results
                david.hume: 1910000 results
                erasmus: 18300000 results
                intitle:index.of shop: 294000 results
                intitle:index.of backup: 201000 results
real    0m7.122s
user    0m0.001s
sys     0m0.001s

as you can see we got 17 results in about 7 seconds. 
we now change a few lines:
	
	gooscan-2.c

	[...]
	goo_cli(2,&goo);
	if(!goo_cli_cnt(&goo)) {
		goo_prnt_er(&goo);
		return 0;
	}
	goo_cli_set(1, GETRESLT, NULL, &goo);
	goo_cli_set(2, GETRESLT, NULL, &goo);

	while(!feof(fd)) {
		max = 0;
		for(i = 0; i < 8; i++) {
			if(fgets(buf,255,fd) == NULL) break;
			buf[strlen(buf)-1] = '\0';

			if(!i)
				max += goo_cli_req(1, buf, &goo,0);
			else max += goo_cli_req(2, buf, &goo,0);
			printf("have sent request: %s\n",buf);
		}
		thetime = time(NULL);
		while(max) {

			if(thetime < (time(NULL)-10)) break;
			ans = goo_results(&goo);
			if(goo.resultc != NOANSWER)   {  // read answers for 10 seconds
                                printf("\t\t%s: %u results\n",ans.req,ans.goo_res);
				max--;
			}
			usleep(100000);
		}
	}
	[...]

in this case we have created two clients and we will send the requests to both
clients. as goo_cli_req returns 1 on success the value max will keep the count of
the possible messages. for every read answer we will decrement max and the loop will
break if we received all answers we expected.

badass@badhost:~/goo/testlab> time ./prog dork.dat
have sent request: inurl:admin ext:asp login.asp
have sent request: ext:pwd service.pwd
have sent request: ext:cfg ks.cfg -example -test
have sent request: johnny.long
have sent request: johnny.ihackstuff
have sent request: l0om
have sent request: ext:asp inurl:id shop
have sent request: inurl:login login ext:php
                inurl:admin ext:asp login.asp: 144000 results
                ext:pwd service.pwd: 86 results
                ext:cfg ks.cfg -example -test: 122 results
                johnny.long: 211000 results
                johnny.ihackstuff: 64600 results
                l0om: 9300 results
                ext:asp inurl:id shop: 2790000 results
                inurl:login login ext:php: 2900000 results
have sent request: immanuel.kant
have sent request: john.locke
have sent request: intitle:index.of private
have sent request: intitle:index.of asdf
have sent request: david.hume
have sent request: erasmus
have sent request: intitle:index.of shop
have sent request: intitle:index.of backup
                john.locke: 1810000 results
                immanuel.kant: 2090000 results
                intitle:index.of private: 171000 results
                intitle:index.of asdf: 731 results
                david.hume: 1910000 results
                erasmus: 18300000 results
                intitle:index.of shop: 294000 results
                intitle:index.of backup: 201000 results
real    0m4.575s
user    0m0.000s
sys     0m0.003s

as you can see we tuned the code to work faster. the more dorks you have in the 
list the more you will notice the speed-up.
keep in mind the following: we are working with the internet and this means
		that the tcp connection might hang for a few seconds for some
		reasons. 

