class Object

Public Instance Methods

process_dir(dir) click to toggle source

Iterate a Directory

# File bin/access_key_scan, line 28
def process_dir(dir)
    Dir.foreach(dir) do |item|
      next if item == '.' or item == '..'
      file_item = File.join(dir,item)
      begin
        process_dir(file_item) if File.directory?(file_item) and not FileTest.symlink?(file_item)
      rescue StandardError => e
        #ignore
      end
      begin
        process_file(file_item) if File.file?(file_item)
      rescue StandardError => e
        #ignore
      end
    end
end
process_file(file) click to toggle source

Peer inside of a file for AWS Creds

# File bin/access_key_scan, line 46
def process_file(file)
  contents = File.read(file,$str.length)
  if contents == $str
    test_creds(file)
  end
  $files_processed += 1
end
show_process() click to toggle source

Simple way for us to see that this thing is doing something

# File bin/access_key_scan, line 80
def show_process
  while true
    before_sleep = $files_processed
    sleep(5)
    after_sleep = $files_processed
    puts "Processed #{after_sleep} Files - #{(after_sleep-before_sleep)/5} per second"
  end
end
test_creds(file) click to toggle source

Test the Creds to see if they work

# File bin/access_key_scan, line 55
def test_creds(file)
  usable = false
  begin
    lines = File.readlines(file)
    items = lines[1].split(',')
    #puts "|#{items[1]}| : |#{items[2]}|"
    ec2 = AWS::EC2.new(
      :access_key_id =>items[1],
      :secret_access_key => items[2])
    begin
      ec2.regions.each do |region| 
      end
      usable = true
    rescue AWS::Errors::ClientError => ce
      # ignore, usable is already false
    end
  rescue StandardError => e
    puts "An Unknown Error #{e.to_s}"
    usable = nil
  end
  puts "Found file #{file}, usable: #{usable}"
  $results << { :filename => file, :usable => usable }
end