forked from CoolerVoid/C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopen_example.c
More file actions
66 lines (52 loc) · 1.08 KB
/
popen_example.c
File metadata and controls
66 lines (52 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Exemplo simples de popen()
*
* Este programa abstrai informações de uma varredura do nmap,
* e salva servidores com uma característica determinada na constante
* "DORK", e então salva em um determinado log.
*
* */
#include <stdio.h>
#include <string.h>
#define PATH_MAX 500
#define LOG "log_nmap.txt"
#define DORK "open ssh"
int
Write_File(char *file,char *str)
{
FILE *arq;
arq=fopen(file,"a");
if(!arq)
{
fprintf(stdout,"error in Write_File() %s",file);
return 0;
}
fprintf(arq,"%s\n",str);
fclose(arq);
return 1;
}
int
main()
{
FILE *fp;
char buffer[PATH_MAX+1],tmp[(PATH_MAX<<1)+3];
puts("Simple nmap Bot :: by Cooler_");
fp = popen("/usr/bin/nmap 192.168.0.1/24", "r");
while(fgets(buffer,PATH_MAX,fp) != NULL)
{
if(strstr(buffer,"report"))
{
fprintf(stdout,"%s",buffer);
bzero(tmp,(PATH_MAX<<1)+2);
strncpy(tmp,buffer,PATH_MAX);
}
if(strstr(buffer,DORK))
{
fprintf(stdout,"DORK HERE hohoho \n %s\n", buffer);
strncat(tmp,buffer,PATH_MAX);
Write_File(LOG,tmp);
}
}
pclose(fp);
return 0;
}