Class: Ronin::Wordlists::WordlistRepo

Inherits:
Object
  • Object
show all
Includes:
WordlistMetadata
Defined in:
lib/ronin/wordlists/wordlist_repo.rb

Overview

Represents a git repository of wordlists.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, **kwargs) ⇒ WordlistRepo

Initializes the wordlist repository.

Parameters:

Options Hash (**kwargs):

  • :url (String, nil)

    The optional URL of the wordlist repository. If no URL is given, #url will infer it from the git repository.



60
61
62
63
64
65
# File 'lib/ronin/wordlists/wordlist_repo.rb', line 60

def initialize(path,**kwargs)
  super(**kwargs)

  @path = path
  @name = File.basename(@path)
end

Instance Attribute Details

#nameString (readonly)

The name of the wordlist repository.

Returns:

  • (String)


44
45
46
# File 'lib/ronin/wordlists/wordlist_repo.rb', line 44

def name
  @name
end

#pathString (readonly)

The path to the wordlist repository.

Returns:

  • (String)


39
40
41
# File 'lib/ronin/wordlists/wordlist_repo.rb', line 39

def path
  @path
end

Class Method Details

.download(url, dest_dir = Dir.pwd) ⇒ WordlistRepo

Clones a wordlist repository from the given git URL.

Parameters:

  • url (String, URI::HTTP)

    The git URL for the wordlist repository.

  • dest_dir (String) (defaults to: Dir.pwd)

    The directory to clone the wordlist repository into.

Returns:

Raises:

  • (DownloadFailed)

    The git clone --depth 1 command failed or git was not installed on the system.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ronin/wordlists/wordlist_repo.rb', line 83

def self.download(url,dest_dir=Dir.pwd)
  uri       = URI(url)
  url       = url.to_s
  repo_name = File.basename(uri.path,'.git')
  repo_path = File.join(dest_dir,repo_name)

  case system('git','clone','--depth','1','--',url,repo_path)
  when true
    new(repo_path, url: url)
  when false
    raise(DownloadFailed,"git command failed: git clone --depth 1 -- #{url} #{repo_path}")
  when nil
    raise(DownloadFailed,"git is not installed on the system")
  end
end

Instance Method Details

#deleteObject

Deletes the wordlist repository.



161
162
163
# File 'lib/ronin/wordlists/wordlist_repo.rb', line 161

def delete
  FileUtils.rm_rf(@path)
end

#filenameString

The name of the wordlist repository directory.

Returns:

  • (String)


122
123
124
# File 'lib/ronin/wordlists/wordlist_repo.rb', line 122

def filename
  File.basename(@path)
end

#git?Boolean

Determines if the wordlist repository uses Git.

Returns:

  • (Boolean)


113
114
115
# File 'lib/ronin/wordlists/wordlist_repo.rb', line 113

def git?
  File.directory?(File.join(@path,'.git'))
end

#type:git

The wordlist type.

Returns:

  • (:git)


104
105
106
# File 'lib/ronin/wordlists/wordlist_repo.rb', line 104

def type
  :git
end

#updateObject

Updates the wordlist repository.

Raises:

  • (DownloadFailed)

    The git pull -C command failed or git was not installed on the system.



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ronin/wordlists/wordlist_repo.rb', line 146

def update
  if git?
    case system('git','pull','-C',@path)
    when true then true
    when false
      raise(DownloadFailed,"git command failed: git pull -C #{@path}")
    when nil
      raise(DownloadFailed,"git is not installed on the system")
    end
  end
end

#urlString?

The URL of the wordlist repository.

Returns:

  • (String, nil)


131
132
133
134
135
136
137
# File 'lib/ronin/wordlists/wordlist_repo.rb', line 131

def url
  @url ||= if git?
             Dir.chdir(@path) do
               `git config --get remote.origin.url`.chomp
             end
           end
end