1
2
3 """Scanning tasks.
4
5 @var default_scantime: Time to spend probing the target expressed in seconds.
6 @type default_scantime: C{int}
7
8 @var default_parallelism: Number of parallel threads to launch for the scan.
9 @type default_parallelism: C{int}
10
11 @var default_conf_dir: Path to the directory where the configuration file is
12 located.
13 @type default_conf_dir: C{str}
14
15 @var default_conf_file: Name of the default configuration file for halberd.
16 @type default_conf_file: C{str}
17
18 @var default_ratio_threshold: Minimum clues-to-realservers ratio to trigger a
19 clue reanalysis.
20 @type default_ratio_threshold: C{float}
21
22 @var default_out: Default place where to write reports (None means stdout).
23 @type default_out: C{str}
24 """
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 import os
44
45 import Halberd.conflib
46
47
48 default_scantime = 15
49
50 default_parallelism = 4
51
52 default_conf_dir = os.path.join(os.path.expanduser('~'), '.halberd')
53 default_conf_file = os.path.join(default_conf_dir,
54 'halberd' + os.extsep + 'cfg')
55
56 default_ratio_threshold = 0.6
57
58 default_out = None
59
60
62 """Error with configuration file(s)
63 """
66
69
70
72 """Describes the way a scan should be performed.
73
74 @ivar verbose: Display status information during the scan.
75 @type verbose: C{bool}
76
77 @ivar debug: Display debug information.
78 @type debug: C{bool}
79
80 @ivar urlfile: Root folder to use for storing results of MultiScans.
81 @type urlfile: C{str}
82
83 @ivar url: URL to scan.
84 @type url: C{str}
85
86 @ivar addr: Address of the target web server.
87 @type addr: C{str}
88
89 @ivar proxy_serv_addr: Address + port where to listen when operating as a
90 proxy.
91 @type proxy_serv_addr: C{tuple}
92
93 @ivar out: File where to write reports. If it's not set, stdout will be
94 used.
95 @type out: C{str}
96
97 @ivar save: File or directory name where the results will be written.
98 @type save: C{str}
99
100 @ivar keyfile: Key file for SSL connections.
101 @type keyfile: C{str}
102
103 @ivar certfile: Certificate to be used for SSL connections.
104 @type certfile: C{str}
105
106 @ivar clues: Sequence of clues obtained from the target.
107 @type clues: C{list}
108
109 @ivar analyzed: Sequence of clues after the analysis phase.
110 @type analyzed: C{list}
111 """
136
137
139 """Read configuration file.
140
141 This method tries to read the specified configuration file. If we try
142 to read it at the default path and it's not there we create a
143 bare-bones file and use that one.
144
145 @raise ConfError: If there's some problem creating or reading the
146 configuration file.
147 """
148
149
150 reader = Halberd.conflib.ConfReader()
151
152 try:
153 reader.open(self.conf_file)
154 except IOError:
155 if self.conf_file == default_conf_file:
156 try:
157 os.mkdir(default_conf_dir)
158 reader.writeDefault(default_conf_file)
159 reader.open(default_conf_file)
160 except (OSError, IOError):
161 raise ConfError, 'unable to create a default conf. file'
162 else:
163 raise ConfError, 'unable to open configuration file %s\n'
164 except conflib.InvalidConfFile:
165 raise ConfError, 'invalid configuration file %s\n' % self.conf_file
166
167 confvals = reader.parse()
168 self.proxy_serv_addr = confvals[0]
169 self.keyfile, self.certfile = confvals[1:]
170
171 reader.close()
172
173
174
175