forked from CoolerVoid/Mosca
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmosca.c
166 lines (137 loc) · 3.24 KB
/
mosca.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
Date: 06/12/2014
Author: Cooler_
Contact: coolerlair@gmail.com
License: GPL3 read file LICENSE.txt
*/
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/resource.h>
#include "file_ops.h"
void init_banner_mosca()
{
puts(
CYAN
" _ \n"
" (^\\'='/^) \n"
" \\ \\=/ / . . __ ___ ___ __ \n"
" '--\\_Y_/--' |\\/| | | [__ | |__| \n"
" .'(_I_)`. | | |__| ___] |___ | | coded by Cooler_\n"
" \" \n"
YELLOW
" Static analysis tool to find bugs like a grep unix command v0.05 \n"
LAST
"+-----------------------------------------------------------------+\n"
"Options: \n"
"--egg = Load module to make analysis '--egg eggs/php_top_fails.php' don't use '../path' \n"
"--path = Path to open and make recursive search, use full path don't use ../path \n"
"--ext = File extension to search example; get only C files '\\.c$' \n"
"--log = File to save results \n"
YELLOW
"Example: \n"
LAST
"$ ./mosca --egg eggs/php_common_fail.egg --path /home/user/blog_php --ext \"\\\\.php$\" --log reports.txt \n"
);
puts(LAST);
}
static struct option long_options[] =
{
{"egg", required_argument, NULL, 'e'},
{"path", required_argument, NULL, 'p'},
{"ext", required_argument, NULL, 'x'},
{"log", required_argument, NULL, 'o'},
{NULL, 0, NULL, 0}
};
int main(int argc, char ** argv)
{
char c;
char *pack[5];
short y=4;
if(argc < 8)
{
init_banner_mosca();
DEBUG(" Need more arguments.\n");
exit(0);
}
while(y>-1)
{
pack[y]=NULL;
y--;
}
opterr = 0;
while((c = getopt_long(argc, argv, "e:p:x:o",long_options,NULL)) != -1)
switch(c)
{
case 'e':
if ( strnlen(optarg,256)<= 255 )
{
pack[0] = optarg;
printf("Egg: %s \n",pack[0]);
} else {
DEBUG("Error \nArgument egg is very large \n");
exit(1);
}
break;
case 'p':
if ( strnlen(optarg,256)<= 255 )
{
pack[1] = optarg;
printf("Path: %s \n",optarg);
} else {
DEBUG("Error \nArgument Path very large \n");
exit(1);
}
break;
case 'x':
if ( strnlen(optarg,8)<= 7 )
{
pack[2] = optarg;
printf("Extension: %s \n",optarg);
} else {
DEBUG("Error \nArgument extension is very large \n");
exit(1);
}
break;
case 'o':
if ( strnlen(optarg,256)<= 255 )
{
pack[3] = optarg;
printf("Log file: %s \n",optarg);
} else {
DEBUG("Error \nArgument Log is very large \n");
exit(1);
}
break;
case '?':
if(optopt == 'e' || optopt == 'p' || optopt == 'x' || optopt == 'o' )
{
init_banner_mosca();
puts(RED);
DEBUG("Option -%c requires an argument.\n", optopt);
puts(LAST);
exit(1);
}
break;
default:
init_banner_mosca();
DEBUG("Need more arguments.\n");
exit(1);
}
if(pack[3]==NULL)
{
DEBUG("error at log file");
exit(0);
}
if(pack[2]==NULL)
{
DEBUG("error at extension file");
exit(0);
}
memset(log_file,0,255);
strncpy(log_file,pack[3],255);
mosca_start(pack[1],pack[2],pack[0]);
exit(0);
}