Skip to content

Commit dbe3fe3

Browse files
author
HD Moore
committed
Sanity check file: arguments for size and move into msfconsole
1 parent fe3f9c7 commit dbe3fe3

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

lib/msf/core/option_container.rb

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,6 @@ def type
191191
end
192192

193193
def normalize(value)
194-
if (value =~ /^file:(.*)/)
195-
path = $1
196-
begin
197-
value = File.read(path)
198-
rescue ::Errno::ENOENT, ::Errno::EISDIR
199-
value = nil
200-
end
201-
end
202194
value
203195
end
204196

@@ -220,14 +212,6 @@ def type
220212
end
221213

222214
def normalize(value)
223-
if (value =~ /^file:(.*)/)
224-
path = $1
225-
begin
226-
value = File.read(path)
227-
rescue ::Errno::ENOENT, ::Errno::EISDIR
228-
value = nil
229-
end
230-
end
231215
value
232216
end
233217

@@ -394,11 +378,7 @@ def type
394378

395379
def normalize(value)
396380
return nil unless value.kind_of?(String)
397-
if (value =~ /^file:(.*)/)
398-
path = $1
399-
return false if not File.exists?(path) or File.directory?(path)
400-
return File.readlines(path).map{ |s| s.strip}.join(" ")
401-
elsif (value =~ /^rand:(.*)/)
381+
if (value =~ /^rand:(.*)/)
402382
count = $1.to_i
403383
return false if count < 1
404384
ret = ''

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def cmd_rename_job(*args)
806806
end
807807

808808
# This is not respecting the Protected access control, but this seems to be the only way
809-
# to rename a job. If you know a more appropriate way, patches accepted.
809+
# to rename a job. If you know a more appropriate way, patches accepted.
810810
framework.jobs[job_id].send(:name=, job_name)
811811
print_status("Job #{job_id} updated")
812812

@@ -2068,6 +2068,16 @@ def cmd_set(*args)
20682068
return true
20692069
end
20702070

2071+
# If the value starts with file: and exists, load the file as the value
2072+
if value =~ /^file:(.*)/ && ::File.file?($1)
2073+
fname = $1
2074+
if ::File.size(fname) > (1024*1024)
2075+
print_error("The file name specified is too big (over 1Mb)")
2076+
else
2077+
::File.open(fname, "rb") {|fd| value = fd.read(fd.stat.size) }
2078+
end
2079+
end
2080+
20712081
if append
20722082
datastore[name] = datastore[name] + value
20732083
else

0 commit comments

Comments
 (0)