Unconfigured Ad Widget

Collapse

Anúncio

Collapse
No announcement yet.

file4 tool - gathering system information

Collapse
X
 
  • Filter
  • Tempo
  • Show
Clear All
new posts

  • Font Size
    #1

    Tools file4 tool - gathering system information

    E aii pessoal, beleza?

    Venho escrevendo muito sockets em C que chega a doer os dedos, em meio uma dessas madrugadas de desenvolvimento eu pensei: "porque não desenvolver uma tool para auxiliar novatos dentro de uma shell?" e bum! nessa manhã surgiram dezenas de ideias e decidi por a mão na massa, ou melhor... no code!

    Introdução:
    É um code simples, a maioria das funções desse code usa a primitiva system() pra gerar alguns outputs e dar continuidade ao "gathering information", ou seja... esse programinha tem como base outputs gerado por comandos executados por system().

    Funções:
    Imprime informações básicas do sistema.
    Imprime informações do Apache (por enquanto só Apache)
    Imprime informações do PHP.
    Busca por arquivos conf com permissão de leitura.
    Busca por arquivos/diretórios com permissão de escrita no diretório atual.
    Busca por arquivos/diretórios com permissão de escrita.

    Proposta:
    Facilitar a vida do script kiddie que não sabe o que fazer ao cair em uma shell.

    Conclusão:
    Este code é para estudos, a probabilidade de gerar erros do que informações úteis é alta.
    Este code usa "whereis" para localizar os binários e imprimir as informações, ou seja... foi feito baseado na estrutura de arquivos do meu sistema, pode não funcionar em um outros sistemas. Espero que alguém teste, e me informe (aqui no fórum mesmo) os erros gerados, pra eu poder deixa-lo um pouco mais portável e flexível.
    Código:
    #include <stdlib.h>
    #include <stdio.h>
    #include <errno.h>
    #define MIN 100
    #define MAX 256
    int issue(){
    	FILE *issue;
    	char issuef[MIN] = "/etc/issue";
    	char issuestr[MIN];
    	
    	if ((issue = fopen(issuef,"r")) == NULL)
    	{
    		fprintf(stderr,"ERROR %s: %s\n",issuef,strerror(errno));
    	}
    	else
    	{
    		fscanf(issue,"%[^\n]",issuestr);
    		printf("%s\n",issuestr);
    	}
    }fclose(issue);
    int kernel(){
    	FILE *uname;
    	FILE *bash;
    	char unamef[MIN] = "/usr/bin/uname";
    	char bashf[MIN] = "/usr/bin/bash";
    	
        if ((uname = fopen(unamef,"rb")) == NULL)
        {
    		fprintf(stderr,"ERROR %s: %s\n",unamef,strerror(errno));	
    	}
    	else
    	{
    		system("/bin/uname -a");
    	}
    	if ((bash = fopen(bashf,"rb")) == NULL)
    	{
    		fprintf(stderr,"ERROR %s: %s\n",bashf,strerror(errno));
    		
    	}
    	else
    	{
    		system("file /bin/bash | awk {'print $3'}");
    	}
    	
    }fclose(uname,bash);
    int lsb(){
    	FILE *lsb;
    	char lsbf[MIN] = "/usr/bin/lsb_release";
    	
    	if ((lsb = fopen(lsbf,"rb")) == NULL)
    	{
    		fprintf(stderr,"ERROR %s: %s\n",lsbf,strerror(errno));
    		
    	}
    	else
    	{
    		system("/usr/bin/lsb_release -a");
    		
    	}
    }fclose(lsb);
    int httpd(){
    	FILE *httpd_file;
    	char httpd_out[MIN];
    	char httpd_versao[MIN];
    	
    	system("whereis httpd |awk {'print $4'} > /var/tmp/httpd");	
    	if ((httpd_file = fopen("/var/tmp/httpd","r")) == NULL)
    	{
    		fprintf(stderr,"ERROR %s: %s\n",httpd_file,strerror(errno));
    	}
    	else
    	{
    		fscanf(httpd_file,"%[^\n]",httpd_out);
    		printf ("%s\n\n",httpd_out);
    		sprintf(httpd_versao,"%s -V",httpd_out);
    		system(httpd_versao);
        }
    	return 0;
    }fclose(httpd_file);
    int phpversion(){
    	FILE *php_file;
    	char php_out[MIN];
    	char php_version[MIN];
    	
    	system("whereis php |awk {'print $3'} > /var/tmp/php");	
    	__fpurge(stdout);
    	if ((php_file = fopen("/var/tmp/php","r")) == NULL)
    	{
    		fprintf(stderr,"ERROR %s: %s\n",php_file,strerror(errno));
    	}
    	else
    	{
    		fscanf(php_file,"%[^\n]",php_out);
    		printf ("%s\n\n",php_out);
    		sprintf(php_version,"%s -i |grep Version",php_out);
    		system(php_version);
        }
    }fclose(php_file);
    int phpini(){
    	FILE *php_file;
    	char php_out[MIN];
    	char php_ini[MIN];
    	
    	system("whereis php |awk {'print $3'} > /var/tmp/php");	
    	if ((php_file = fopen("/var/tmp/php","r")) == NULL)
    	{
    		fprintf(stderr,"ERROR %s: %s\n",php_file,strerror(errno));
    	}
    	else
    	{
    		fscanf(php_file,"%[^\n]",php_out);
    		sprintf(php_ini,"%s --ini",php_out);
    		system(php_ini);
        }
    }fclose(php_file);
    int conf(){
    	FILE *find;
    	char findf[MIN] = "/usr/bin/find";
    	char path[MAX];
    	char cmd[MAX];
    	
    	if((find = fopen(findf,"rb")) == NULL)
    	{
    		fprintf(stderr,"ERROR %s: %s",findf,strerror(errno));
    	}
    	else
    	{
    		printf("Especify a path to search readable conf files (e.g /etc/).\n");
    		printf("[file4]$ ");
    		scanf("%s",path);
    		sprintf(cmd,"%s %s -type f -name *conf -readable",findf,path);
    		system(cmd);
    		fclose(find);
    	}
    }fclose(find);
    int pwd(){
    	FILE *pwdb;
    	FILE *pwd_out;
    	char findb[MIN] = "/usr/bin/find";
    	char pwd_binfile[MIN] = "/usr/bin/pwd";
    	char pwd_var[MIN];
    	char cmd[MAX];
    	int c;
    	
    	if((pwdb = fopen(pwd_binfile,"rb")) == NULL)
    	{
    		fprintf(stderr,"ERROR %s: %s",pwd_binfile,strerror(errno));
    	}
    	else
    	{
    		system("/usr/bin/pwd > /var/tmp/pwd");
    		pwd_out = fopen("/var/tmp/pwd","r");
    		fscanf(pwd_out,"%s",pwd_var);	
    		printf("1 Writable dir\n2 Writable file\n");
    		printf("[file4@%s]$ ",pwd_var);
    		scanf("%d",&c);
    		if (c == 1)
    		{
    			sprintf(cmd,"%s %s -type f -writable",findb,pwd_var);
    			system(cmd);
    	    }
    	    if (c == 2)
    	    {
    			sprintf(cmd,"%s %s -type d -writable",findb,pwd_var);
    			system(cmd);
    	    }
    	}
    }fclose(pwdb,pwd_out);
    int writable(){
    	FILE *find;
    	char findf[MIN] = "/usr/bin/find";
    	char path[MAX];
    	char cmd[MAX];
    	int c;
    	
    	if((find = fopen(findf,"rb")) == NULL)
    	{
    		fprintf(stderr,"ERROR %s: %s",findf,strerror(errno));
    	}
    	else
    	{
    		printf("1 Writable dir\n2 Writable file\n");
    		printf("[file4]$ ");
    		scanf("%d",&c);
    		if(c == 1)
    		{
    			printf("Especify a path to search writable directories (e.g /var/www).\n");
    			printf("[file4]$ ");
    			scanf("%s",path);
    		    sprintf(cmd,"%s %s -type d -writable",findf,path);
    		    system(cmd);
    		}
    		
    		if(c == 2)
    		{
    			printf("Especify a path to search writable files (e.g /var/www).\n");
    			printf("[file4]$ ");
    			scanf("%s",path);
    			sprintf(cmd,"%s %s -type f -writable",findf,path);
    		    system(cmd);
    		}
    	}
    }fclose(find);
    
    int main(void){
    	int go = 0;
    	
    	printf("\n0 (About)\n1 (System Info)\n2 (Apache Info)\n3 (PHP Info)\n");
    	printf("4 (Find Conf)\n5 (Current dir)\n6 (Writable dir/file)\n7 (Menu)\n99 (Back to shell)\n");
    	while (go >= 0)
    	{
    	printf("\n[file4]# ");
    	scanf("%d",&go);
    	switch(go)
    	{
    		case 0:
    		printf("\nfile4 0.1 developed by Spy_Unkn0wn - spy_unkn0wn@mail.org\n");
    		printf("A pretty small software that use system() ");
    		printf("to automate command's system and find some useful information, nothing extraordinary.\n");
    		break;
    		case 1:
    		issue();
    		kernel(); printf("\n");
    		lsb();
    		break;
    		case 2:
    		httpd();
    		break;
    		case 3:
    		phpversion(); printf("\n");
    		phpini();
     		break;
     		case 4:
     		conf();
     		break;
     		case 5:
     		pwd();
     		break;
     		case 6:
     		writable();
     		break;
     		case 7:
     		printf("\n0 (About)\n1 (System Info)\n2 (Apache Info)\n3 (PHP Info)\n");
     		printf("4 (Find Conf)\n5 (Current dir)\n6 (Writable dir/file)\n99 (Back to shell)\n");
     		break;
     		case 99:
     		printf("Removing output files and exiting... bye :)\n\n");
    		system("rm /var/tmp/find /var/tmp/httpd /var/tmp/php /var/tmp/pwd");
    		exit(1);
    		break;
    		default:
    		continue;
    	}
    }
    return 0;
    }
    []'s
    Similar Threads
X
Working...
X