@@ -11,14 +11,15 @@ def initialize(info = {})
11
11
super ( update_info ( info ,
12
12
'Name' => 'Gather PDF Authors' ,
13
13
'Description' => %q{
14
- This module takes a list of PDF URLs, downloads the PDFs,
15
- and extracts the author's name from the document metadata.
14
+ This module downloads PDF files and extracts the author's
15
+ name from the document metadata.
16
16
} ,
17
17
'License' => MSF_LICENSE ,
18
18
'Author' => 'Brendan Coles <bcoles[at]gmail.com>' ) )
19
19
register_options (
20
20
[
21
- OptPath . new ( 'URL_LIST' , [ true , 'File containing a list of PDF URLs to analyze' , '' ] ) ,
21
+ OptString . new ( 'URL' , [ false , 'The URL of a PDF to analyse' , '' ] ) ,
22
+ OptString . new ( 'URL_LIST' , [ false , 'File containing a list of PDF URLs to analyze' , '' ] ) ,
22
23
OptString . new ( 'OUTFILE' , [ false , 'File to store output' , '' ] )
23
24
] )
24
25
register_advanced_options (
@@ -37,6 +38,16 @@ def progress(current, total)
37
38
end
38
39
39
40
def load_urls
41
+ return [ datastore [ 'URL' ] ] unless datastore [ 'URL' ] . to_s . eql? ''
42
+
43
+ if datastore [ 'URL_LIST' ] . to_s . eql? ''
44
+ fail_with Failure ::BadConfig , 'No URL(s) specified'
45
+ end
46
+
47
+ unless File . file? datastore [ 'URL_LIST' ] . to_s
48
+ fail_with Failure ::BadConfig , "File '#{ datastore [ 'URL_LIST' ] } ' does not exit"
49
+ end
50
+
40
51
File . open ( datastore [ 'URL_LIST' ] , 'rb' ) { |f | f . read } . split ( /\r ?\n / )
41
52
end
42
53
@@ -77,6 +88,8 @@ def download(url)
77
88
78
89
begin
79
90
target = URI . parse url
91
+ raise 'Invalid URL' unless target . scheme =~ %r{https?}
92
+ raise 'Invalid URL' if target . host . to_s . eql? ''
80
93
rescue => e
81
94
print_error "Could not parse URL: #{ e } "
82
95
return
@@ -128,10 +141,6 @@ def write_output(data)
128
141
end
129
142
130
143
def run
131
- unless File . file? datastore [ 'URL_LIST' ]
132
- fail_with Failure ::BadConfig , "File '#{ datastore [ 'URL_LIST' ] } ' does not exit"
133
- end
134
-
135
144
if datastore [ 'PROXY' ]
136
145
@proxysrv , @proxyport = datastore [ 'PROXY' ] . split ( ':' )
137
146
@proxyuser = datastore [ 'PROXY_USER' ]
0 commit comments