Module: Reaver

Defined in:
lib/reaver.rb,
lib/reaver/git.rb,
lib/reaver/walk.rb,
lib/reaver/banner.rb,
lib/reaver/version.rb,
lib/reaver/download.rb,
lib/reaver/metadata.rb,
lib/reaver/collection.rb

Overview

Download link

Defined Under Namespace

Classes: Collection, Git, MetaData, Walk

Constant Summary collapse

CACHE_DIR =

Where downloads things

"#{ENV['HOME']}/.cache/reaver"
WORKDIR =

Search collection paths

ENV['XDG_CONFIG_HOME'] ? "#{ENV['XDG_CONFIG_HOME']}/reaver" : "#{ENV['HOME']}/.config/reaver"
VERSION =
'0.20.1'

Class Method Summary collapse

Class Method Details

.agent_listObject

List from www.useragents.me/ return a random user-agent with sample



60
61
62
63
64
65
66
67
# File 'lib/reaver/download.rb', line 60

def agent_list
  ag = ['Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.10 Safari/605.1.1',
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.3',
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.3',
        'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.3',
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Trailer/93.3.8652.5']
  ag.sample
end

.analyze_collection(info_next, forced = nil) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/reaver.rb', line 66

def analyze_collection(info_next, forced = nil)
  next_download = info_next
  force_download = forced || false
  return true if next_download < Time.new || force_download

  puts " > Next download > #{next_download}"
  false
end


5
6
7
8
9
10
11
12
13
14
15
# File 'lib/reaver/banner.rb', line 5

def self.banner
  # Generated on https://www.coolgenerator.com/ascii-text-generator
  # font > ASCII New Roman
  <<~BANNER
     ____, ____, ____,__  _,____,____,
    (-|__)(-|_, (-/_|(-\\  /(-|_,(-|__)
     _|  \\,_|__,_/  |, _\\/  _|__,_|  \\,
    (     (    (      (    (    (

  BANNER
end

.collection_name(filename) ⇒ Object



60
61
62
63
64
# File 'lib/reaver.rb', line 60

def collection_name(filename)
  name = filename.split('/').last
  name = name.split('.').first
  "#{CACHE_DIR}/#{name}"
end

.download(url, name, limit = 5) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/reaver/download.rb', line 12

def download(url, name, limit = 5)
  dest = name
  url = URI.parse(url)
  raise ArgumentError, 'url was invalid' unless url.respond_to?(:open)
  raise ArgumentError, 'too many HTTP redirects' if limit.zero?

  http_object = Net::HTTP.new(url.host, url.port)
  just_add_ssl(http_object) # if url.scheme == 'https'
  http_object.start do |http|
    request = Net::HTTP::Get.new(url.request_uri, { 'user-agent' => agent_list })
    response_stuff(http, request, dest, limit)
  end
end

.get_the_file(res, dest) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/reaver/download.rb', line 46

def get_the_file(res, dest)
  Whirly.start do
    Whirly.status = "Downloading #{dest}"
    File.binwrite(dest, res.read_body)
    # open(dest, 'wb') do |io|
    # res.read_body do |chunk|
    #   io.write chunk
    # end
    # end
  end
end

.just_add_ssl(http_object) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/reaver/download.rb', line 38

def just_add_ssl(http_object)
  store = OpenSSL::X509::Store.new
  store.set_default_paths
  http_object.use_ssl = true
  http_object.verify_mode = OpenSSL::SSL::VERIFY_PEER
  http_object.cert_store = store
end

.load_collection(pathname) ⇒ Object



47
48
49
50
51
# File 'lib/reaver.rb', line 47

def load_collection(pathname)
  collection = Collection.new(pathname)
  collection.load_yaml
  collection
end

.load_metadata(workdir, collection) ⇒ Object



53
54
55
56
57
58
# File 'lib/reaver.rb', line 53

def (workdir, collection)
  FileUtils.mkdir_p(workdir)
  md = MetaData.new(workdir, collection)
  md.load_yaml
  md
end

.mainObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/reaver.rb', line 31

def main
  Dir.glob("#{WORKDIR}/*.yml").each do |f|
    workdir = collection_name(f)
    collection = load_collection(f)

    next unless collection.tasks

     = (workdir, collection)
    if analyze_collection(.info['next'], collection.tasks['force_download'])
      time_to_download(workdir, collection, )
    end

    .save_yaml
  end
end

.response_stuff(http, request, dest, limit) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/reaver/download.rb', line 26

def response_stuff(http, request, dest, limit)
  http.read_timeout = 500
  http.request request do |response|
    case response
    when Net::HTTPSuccess then get_the_file(response, dest)
    when Net::HTTPRedirection then download(response['location'], dest, limit - 1)
    else
      raise response.value
    end
  end
end

.time_to_download(workdir, collection, metadata) ⇒ Object



75
76
77
78
79
# File 'lib/reaver.rb', line 75

def time_to_download(workdir, collection, )
  FileUtils.chdir(workdir)
  collection.launch()
  # collection.save_yaml if force_download
end