-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcmdparser.py
More file actions
199 lines (180 loc) · 5.56 KB
/
cmdparser.py
File metadata and controls
199 lines (180 loc) · 5.56 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
from optparse import OptionParser
from optparse import OptionGroup
from optparse import OptionValueError
from regex import regex
from os.path import exists
def buildArgvSys():
Regex = regex()
parser = OptionParser()
# GROUPS
Proxy = OptionGroup(parser,
"Proxy Options")
Encryptation = OptionGroup(parser,
"Hash's Encrypt And Decrypt")
External_command = OptionGroup(parser,
"External Command",
"Use an external tool with the scan")
# SET OPTIONS TO GROUPS
Proxy.add_option("-p","--proxy",
dest="proxy",
help="Use proxy with scan",
metavar="PROXY")
External_command.add_option("--command",
dest="external-command",
help="call command at evrey host scan",
metavar="COMMAND",
type="str")
External_command.add_option("--HOST",
help="Constant in command option for replace it with url",
metavar=None)
External_command.add_option("--IP",
help="Constant in command option for replace it with the ip of host ",
metavar=None)
Encryptation.add_option("--md5Encr",
dest="md5Enc",
help="Encrypte a string to md5 hash",
metavar="STRING")
Encryptation.add_option("--base64Encr",
dest="base64Encr",
help="Encrypte a string to base64",
metavar="STRING")
Encryptation.add_option("--base64Decr",
dest="base64Decr",
help="Decrypte a base64 to string",
metavar="STRING")
# ADD GROUPS
parser.add_option_group(Proxy)
parser.add_option_group(Encryptation)
parser.add_option_group(External_command)
# GENERAL OPTIONS
parser.add_option("-u","--url",
dest="url",
help="Scan a particular URL",
type="str",
metavar="URL|LIST",
callback=listExist,
callback_args=tuple([Regex]),
action="callback")
parser.add_option("-d","--dork",
dest="dork",
help="Look for dork",
metavar="DORK|LIST",
type="str",
callback=listExist,
callback_args=tuple([Regex]),
action="callback")
parser.add_option("--pages",
help="Set number of pages to get from the engine",
dest="pages",
type="int",
default=1)
parser.add_option("-e","--engine",
dest="engin",
help="Set engine to search for dork",
metavar="ENGINE",
default="google")
parser.add_option("--time-out",
dest="timeout",
help="Set time out of the connecton default time out = 30s",
metavar="SECONDS",
default=30,
type="int",
callback=timeout,
action="callback")
parser.add_option("--tcp-ports",
dest="tcp-ports",
help="Scan tcp ports in the server",
default=False,
action="store_true")
parser.add_option("--ports",
dest="ports",
help="set your ports to scan you can set set a single port or multiple ports separated by ','\
or an intervale of ports with using range(min,max) function ",
callback=portsChecker,
action="callback",
type="string",
callback_args=tuple([Regex])
)
parser.add_option("--portsTCP",
dest="portsTCP",
help="Scan tcp ports in the server",
default=False,
action="store_true")
parser.add_option("--validation",
dest="validation",
help="Look for a string in response of site's",
metavar="STRING",
default=False)
parser.add_option("--regex",
dest="regex",
help="Look for a regex in response",
metavar="REGEX")
parser.add_option("--sql-injection",
dest="sql",
help="scan for sql injection error",
default=False,
action="store_true")
parser.add_option("--noInfo",
dest="info",
help="Disable displaying informations about target" ,
action="store_true",
default=False)
parser.add_option("--update",
dest="update",
help="Check if a new update available",
action="store_true",
default=False)
parser.add_option("-s","--save",
dest="save",
help="save scan results in file",
metavar="FILE")
(options, args) = parser.parse_args()
return vars(options)
# CALLBACKS FOR HANDLING OPTIONS
def timeout(option,opt_str,value,parser):
"""
param option optparse.Option
param opt_str str passed option
param value str the value of option
param parser OptionParser object
"""
if value >= 5 :
parser.values.timeout = value
else :
raise OptionValueError("{} value must be more than 10 seconds".format(opt_str))
pass
"""
@func to check if a passed file exist or not and raise an error if doesn't exist
"""
def listExist(option,opt_str,value,parser,Regex):
if Regex.isPath(value):
if exists(value):
if option.dest == "dork" :
parser.values.dork = {"List":value}
elif option.dest == "url" :
parser.values.url = {"List":value}
else :
raise OptionValueError("file passed in {} doesn't exist".format(opt_str))
else :
if option.dest == "dork":
parser.values.dork = value
if option.dest == "url":
parser.values.url = value
pass
def portsChecker(option,opt_str,value,parser,Regex):
result = Regex.getfullMatch(Regex.PortsChecker,value)
if result.string != None:
if "range" not in result.string :
result = result.string.split(",")
else :
result = Regex.findRegex(r'range\((\d+),(\d+)\)',result.string)
fromPort = int( result[0][0] )
toPort = int( result[0][1] )
if fromPort < toPort :
result = range(fromPort,toPort)
else :
result = range(toPort,fromPort)
parser.values.ports = result
else :
raise OptionValueError("no ports match set a single port or port1,port2,... or range(fromPort,toPort)")
pass