Skip to content

Commit

Permalink
File.exists? must die
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Cook committed Apr 21, 2016
1 parent 6b3326e commit 57ab974
Show file tree
Hide file tree
Showing 59 changed files with 101 additions and 101 deletions.
2 changes: 1 addition & 1 deletion data/exploits/capture/http/forms/grabforms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def usage
next if site =~ /^#/

out = File.join(output, site + ".txt")
File.unlink(out) if File.exists?(out)
File.unlink(out) if File.exist?(out)

fd = File.open(out, "a")

Expand Down
2 changes: 1 addition & 1 deletion lib/anemone/storage/pstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PStore
def_delegators :@keys, :has_key?, :keys, :size

def initialize(file)
File.delete(file) if File.exists?(file)
File.delete(file) if File.exist?(file)
@store = ::PStore.new(file)
@keys = {}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/base/sessions/scriptable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def find_script_path(script)

# Scan all of the path combinations
check_paths.each { |path|
if ::File.exists?(path)
if ::File.exist?(path)
full_path = path
break
end
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/base/simple/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module PluginManager
def load(path, opts = {})
def_path = Msf::Config.plugin_directory + File::SEPARATOR + path

if (File.exists?(def_path) or File.exists?(def_path + ".rb"))
if (File.exist?(def_path) or File.exist?(def_path + ".rb"))
super(def_path, opts)
else
super
Expand Down
18 changes: 9 additions & 9 deletions lib/msf/core/db_manager/import/metasploit_framework/zip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def import_msf_collateral(args={}, &block)

# Only report loot if we actually have it.
# TODO: Copypasta. Separate this out.
if ::File.exists? loot_info[:orig_path]
if ::File.exist? loot_info[:orig_path]
loot_dir = ::File.join(basedir,"loot")
loot_file = ::File.split(loot_info[:orig_path]).last
if ::File.exists? loot_dir
if ::File.exist? loot_dir
unless (::File.directory?(loot_dir) && ::File.writable?(loot_dir))
raise Msf::DBImportError.new("Could not move files to #{loot_dir}")
end
Expand All @@ -77,7 +77,7 @@ def import_msf_collateral(args={}, &block)
end
new_loot = ::File.join(loot_dir,loot_file)
loot_info[:path] = new_loot
if ::File.exists?(new_loot)
if ::File.exist?(new_loot)
::File.unlink new_loot # Delete it, and don't report it.
else
report_loot(loot_info) # It's new, so report it.
Expand Down Expand Up @@ -115,10 +115,10 @@ def import_msf_collateral(args={}, &block)

# Only report a task if we actually have it.
# TODO: Copypasta. Separate this out.
if ::File.exists? task_info[:orig_path]
if ::File.exist? task_info[:orig_path]
tasks_dir = ::File.join(basedir,"tasks")
task_file = ::File.split(task_info[:orig_path]).last
if ::File.exists? tasks_dir
if ::File.exist? tasks_dir
unless (::File.directory?(tasks_dir) && ::File.writable?(tasks_dir))
raise Msf::DBImportError.new("Could not move files to #{tasks_dir}")
end
Expand All @@ -127,7 +127,7 @@ def import_msf_collateral(args={}, &block)
end
new_task = ::File.join(tasks_dir,task_file)
task_info[:path] = new_task
if ::File.exists?(new_task)
if ::File.exist?(new_task)
::File.unlink new_task # Delete it, and don't report it.
else
report_task(task_info) # It's new, so report it.
Expand Down Expand Up @@ -156,7 +156,7 @@ def import_msf_zip(args={}, &block)
bl = validate_ips(args[:blacklist]) ? args[:blacklist].split : []

new_tmp = ::File.join(Dir::tmpdir,"msf","imp_#{Rex::Text::rand_text_alphanumeric(4)}",@import_filedata[:zip_basename])
if ::File.exists? new_tmp
if ::File.exist? new_tmp
unless (::File.directory?(new_tmp) && ::File.writable?(new_tmp))
raise Msf::DBImportError.new("Could not extract zip file to #{new_tmp}")
end
Expand All @@ -172,7 +172,7 @@ def import_msf_zip(args={}, &block)
# already exist
@import_filedata[:zip_tmp_subdirs].each {|sub|
tmp_subdirs = ::File.join(@import_filedata[:zip_tmp],sub)
if File.exists? tmp_subdirs
if File.exist? tmp_subdirs
unless (::File.directory?(tmp_subdirs) && File.writable?(tmp_subdirs))
# if it exists but we can't write to it, give up
raise Msf::DBImportError.new("Could not extract zip file to #{tmp_subdirs}")
Expand All @@ -198,7 +198,7 @@ def import_msf_zip(args={}, &block)
Dir.entries(@import_filedata[:zip_tmp]).each do |entry|
if entry =~ /^.*#{Regexp.quote(Metasploit::Credential::Exporter::Core::CREDS_DUMP_FILE_IDENTIFIER)}.*/
manifest_file_path = File.join(@import_filedata[:zip_tmp], entry, Metasploit::Credential::Importer::Zip::MANIFEST_FILE_NAME)
if File.exists? manifest_file_path
if File.exist? manifest_file_path
import_msf_cred_dump(manifest_file_path, wspace)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/core/db_manager/module_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def update_all_module_details
next
end

unless md.file and ::File.exists?(md.file)
unless md.file and ::File.exist?(md.file)
refresh << md
next
end
Expand Down
4 changes: 2 additions & 2 deletions lib/msf/core/db_manager/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def report_artifact(opts)
created = opts.delete(:created_at)
updated = opts.delete(:updated_at)

unless File.exists? tmp_path
unless File.exist? tmp_path
raise Msf::DBImportError 'Report artifact file to be imported does not exist.'
end

unless (File.directory?(artifacts_dir) && File.writable?(artifacts_dir))
raise Msf::DBImportError "Could not move report artifact file to #{artifacts_dir}."
end

if File.exists? new_path
if File.exist? new_path
unique_basename = "#{(Time.now.to_f*1000).to_i}_#{artifact_name}"
new_path = File.join(artifacts_dir, unique_basename)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/core/encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def find_key(buf, badchars, state)
#
def find_context_key(buf, badchars, state)
# Make sure our context information file is sane
if !File.exists?(datastore['ContextInformationFile'])
if !File.exist?(datastore['ContextInformationFile'])
raise NoKeyError, "A context information file must specified when using context encoding", caller
end

Expand Down
4 changes: 2 additions & 2 deletions lib/msf/core/exploit/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def open_pcap(opts={})
cap = datastore['PCAPFILE'] || ''

if (not cap.empty?)
if (not File.exists?(cap))
if (not File.exist?(cap))
raise RuntimeError, "The PCAP file #{cap} could not be found"
end
self.capture = ::Pcap.open_offline(cap)
Expand Down Expand Up @@ -216,7 +216,7 @@ def inject_pcap(pcap_file, filter=nil, delay = 0, pcap=self.capture)
raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)"
end

if (not File.exists?(pcap_file))
if (not File.exist?(pcap_file))
raise RuntimeError, "The PCAP file #{pcap_file} could not be found"
end

Expand Down
8 changes: 4 additions & 4 deletions lib/msf/core/exploit/java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def init_jvm(jvmoptions = nil)
end

toolsjar = File.join(ENV['JAVA_HOME'], "lib", "tools.jar")
if (not File.exists? toolsjar)
if (not File.exist? toolsjar)
raise RuntimeError, 'JAVA_HOME does not point to a valid JDK installation.'
end

Expand All @@ -69,7 +69,7 @@ def query_jvm
def save_to_file(classnames, codez, location)
path = File.join( Msf::Config.install_root, "external", "source", location )

if not File.exists? path
if not File.exist? path
Dir.mkdir(path)
end

Expand All @@ -96,7 +96,7 @@ def compile(classnames, codez, compile_options=nil)
compile_options = [] if compile_options.nil?

# Create the directory if it doesn't exist
Dir.mkdir(datastore['JavaCache']) if !File.exists? datastore['JavaCache']
Dir.mkdir(datastore['JavaCache']) if !File.exist? datastore['JavaCache']

# For compatibility, some exploits need to have the target and source version
# set to a previous JRE version.
Expand Down Expand Up @@ -157,7 +157,7 @@ def sign_jar(cert_cn, unsiged_jar, signed_jar, cert_alias="signFiles", msf_keyst

# Check if the keystore exists from previous run. If it does, delete it.
msf_keystore = File.join(datastore['JavaCache'], msf_keystore)
File.delete msf_keystore if File.exists? msf_keystore
File.delete msf_keystore if File.exist? msf_keystore

# Rjb pukes on a CN with a comma in it so bad that it crashes to shell
# and turns input echoing off. Simple fix for this ugly bug is
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/core/opt_address_range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def normalize(value)
return nil unless value.kind_of?(String)
if (value =~ /^file:(.*)/)
path = $1
return false if not File.exists?(path) or File.directory?(path)
return false if not File.exist?(path) or File.directory?(path)
return File.readlines(path).map{ |s| s.strip}.join(" ")
elsif (value =~ /^rand:(.*)/)
count = $1.to_i
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/core/opt_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def valid?(value)
if value =~ /^memory:\s*([0-9]+)/i
return false unless check_memory_location($1)
else
unless File.exists?(value)
unless File.exist?(value)
return false
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/msf/core/post/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def exist?(path)
# @param data [String]
# @return [void]
def file_local_write(local_file_name, data)
unless ::File.exists?(local_file_name)
unless ::File.exist?(local_file_name)
::FileUtils.touch(local_file_name)
end

Expand All @@ -160,7 +160,7 @@ def file_local_write(local_file_name, data)
# @param local_file_name [String] Local file name
# @return [String] Hex digest of file contents
def file_local_digestmd5(local_file_name)
if ::File.exists?(local_file_name)
if ::File.exist?(local_file_name)
require 'digest/md5'
chksum = nil
chksum = Digest::MD5.hexdigest(::File.open(local_file_name, "rb") { |f| f.read})
Expand Down Expand Up @@ -191,7 +191,7 @@ def file_remote_digestmd5(file_name)
# @param local_file_name [String] Local file name
# @return [String] Hex digest of file contents
def file_local_digestsha1(local_file_name)
if ::File.exists?(local_file_name)
if ::File.exist?(local_file_name)
require 'digest/sha1'
chksum = nil
chksum = Digest::SHA1.hexdigest(::File.open(local_file_name, "rb") { |f| f.read})
Expand Down Expand Up @@ -222,7 +222,7 @@ def file_remote_digestsha1(file_name)
# @param local_file_name [String] Local file name
# @return [String] Hex digest of file contents
def file_local_digestsha2(local_file_name)
if ::File.exists?(local_file_name)
if ::File.exist?(local_file_name)
require 'digest/sha2'
chksum = nil
chksum = Digest::SHA256.hexdigest(::File.open(local_file_name, "rb") { |f| f.read})
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/core/rpc/v10/rpc_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def rpc_load(path, xopts = {})

# If the plugin isn't in the user direcotry (~/.msf3/plugins/), use the base
path = Msf::Config.user_plugin_directory + File::SEPARATOR + plugin_file_name
if not File.exists?( path + ".rb" )
if not File.exist?( path + ".rb" )
# If the following "path" doesn't exist it will be caught when we attempt to load
path = Msf::Config.plugin_directory + File::SEPARATOR + plugin_file_name
end
Expand Down
8 changes: 4 additions & 4 deletions lib/msf/ui/console/command_dispatcher/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def cmd_resource(*args)

args.each do |res|
good_res = nil
if ::File.exists?(res)
if ::File.exist?(res)
good_res = res
elsif
# let's check to see if it's in the scripts/resource dir (like when tab completed)
Expand All @@ -258,7 +258,7 @@ def cmd_resource(*args)
::Msf::Config.user_script_directory + ::File::SEPARATOR + "resource"
].each do |dir|
res_path = dir + ::File::SEPARATOR + res
if ::File.exists?(res_path)
if ::File.exist?(res_path)
good_res = res_path
break
end
Expand Down Expand Up @@ -1254,7 +1254,7 @@ def cmd_load(*args)

# If the plugin isn't in the user directory (~/.msf3/plugins/), use the base
path = Msf::Config.user_plugin_directory + File::SEPARATOR + plugin_file_name
if not File.exists?( path + ".rb" )
if not File.exist?( path + ".rb" )
# If the following "path" doesn't exist it will be caught when we attempt to load
path = Msf::Config.plugin_directory + File::SEPARATOR + plugin_file_name
end
Expand Down Expand Up @@ -3291,7 +3291,7 @@ def verify_session(session_id, quiet = false)

# Determines if this is an apt-based install
def is_apt
File.exists?(File.expand_path(File.join(Msf::Config.install_root, '.apt')))
File.exist?(File.expand_path(File.join(Msf::Config.install_root, '.apt')))
end

# Determines if we're a Metasploit Pro/Community/Express
Expand Down
6 changes: 3 additions & 3 deletions lib/msf/ui/console/command_dispatcher/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ def cmd_loot(*args)
print_error("Can't make loot with no filename")
return
end
if (!File.exists?(filename) or !File.readable?(filename))
if (!File.exist?(filename) or !File.readable?(filename))
print_error("Can't read file")
return
end
Expand Down Expand Up @@ -1979,13 +1979,13 @@ def cmd_db_connect(*args)
return
end
if (args[0] == "-y")
if (args[1] and not ::File.exists? ::File.expand_path(args[1]))
if (args[1] and not ::File.exist? ::File.expand_path(args[1]))
print_error("File not found")
return
end
file = args[1] || ::File.join(Msf::Config.get_config_root, "database.yml")
file = ::File.expand_path(file)
if (::File.exists? file)
if (::File.exist? file)
db = YAML.load(::File.read(file))['production']
framework.db.connect(db)

Expand Down
8 changes: 4 additions & 4 deletions lib/msf/ui/console/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
if opts['Resource'].blank?
# None given, load the default
default_resource = ::File.join(Msf::Config.config_directory, 'msfconsole.rc')
load_resource(default_resource) if ::File.exists?(default_resource)
load_resource(default_resource) if ::File.exist?(default_resource)
else
opts['Resource'].each { |r|
load_resource(r)
Expand Down Expand Up @@ -279,7 +279,7 @@ def junit_error(tname, ftype, data = nil)

fname = ::File.join(@junit_output_path, "#{bname}.xml")
cnt = 0
while ::File.exists?( fname )
while ::File.exist?( fname )
cnt += 1
fname = ::File.join(@junit_output_path, "#{bname}_#{cnt}.xml")
end
Expand Down Expand Up @@ -314,7 +314,7 @@ def junit_pass(tname)
# Generate the output path, allow multiple test with the same name
fname = ::File.join(@junit_output_path, "#{bname}.xml")
cnt = 0
while ::File.exists?( fname )
while ::File.exist?( fname )
cnt += 1
fname = ::File.join(@junit_output_path, "#{bname}_#{cnt}.xml")
end
Expand Down Expand Up @@ -416,7 +416,7 @@ def load_resource(path)
if path == '-'
resource_file = $stdin.read
path = 'stdin'
elsif ::File.exists?(path)
elsif ::File.exist?(path)
resource_file = ::File.read(path)
else
print_error("Cannot find resource script: #{path}")
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/util/document_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def self.get_module_document(mod)
kb_path = File.join(PullRequestFinder::MANUAL_BASE_PATH, "#{mod.fullname}.md")
kb = ''

if File.exists?(kb_path)
if File.exist?(kb_path)
File.open(kb_path, 'rb') { |f| kb = f.read }
end

Expand Down
4 changes: 2 additions & 2 deletions lib/msf/util/exe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2253,9 +2253,9 @@ def self.is_eicar_corrupted?
path = ::File.expand_path(::File.join(
::File.dirname(__FILE__),"..", "..", "..", "data", "eicar.com")
)
return true unless ::File.exists?(path)
return true unless ::File.exist?(path)
ret = false
if ::File.exists?(path)
if ::File.exist?(path)
begin
data = ::File.read(path)
unless Digest::SHA1.hexdigest(data) == "3395856ce81f2b7382dee72602f798b642f14140"
Expand Down
Loading

0 comments on commit 57ab974

Please sign in to comment.