Class: Ronin::PHP::LFI::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/php/lfi/target.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Target

Creates a new Path object with the specified path and pattern.



41
42
43
44
45
46
47
48
# File 'lib/ronin/php/lfi/target.rb', line 41

def initialize(&block)
  @paths = Hash.new { |hash,key| hash[key] = [] }

  @recognizor = nil
  @extractors = {}

  block.call(self) if block
end

Instance Attribute Details

#extractorsObject (readonly)

Hash of extractor rules



36
37
38
# File 'lib/ronin/php/lfi/target.rb', line 36

def extractors
  @extractors
end

#pathsObject (readonly)

Hash of OS specific paths for the target



30
31
32
# File 'lib/ronin/php/lfi/target.rb', line 30

def paths
  @paths
end

#recognizorObject

Hash of patterns to recognize the target by



33
34
35
# File 'lib/ronin/php/lfi/target.rb', line 33

def recognizor
  @recognizor
end

Class Method Details

.allObject



128
129
130
# File 'lib/ronin/php/lfi/target.rb', line 128

def Target.all
  Target.categories.values.flatten
end

.categoriesObject



120
121
122
# File 'lib/ronin/php/lfi/target.rb', line 120

def Target.categories
  @@categories ||= Hash.new { |hash,key| hash[key] = [] }
end

.category(name) ⇒ Object



124
125
126
# File 'lib/ronin/php/lfi/target.rb', line 124

def Target.category(name)
  Target.categories[name]
end

.config(&block) ⇒ Object



146
147
148
# File 'lib/ronin/php/lfi/target.rb', line 146

def Target.config(&block)
  Target.define(:config,&block)
end

.configsObject



150
151
152
# File 'lib/ronin/php/lfi/target.rb', line 150

def Target.configs
  Target.category(:config)
end

.each(&block) ⇒ Object



132
133
134
135
136
# File 'lib/ronin/php/lfi/target.rb', line 132

def Target.each(&block)
  Target.categories.each_value do |targets|
    targets.each(&block)
  end
end

.log(&block) ⇒ Object



154
155
156
# File 'lib/ronin/php/lfi/target.rb', line 154

def Target.log(&block)
  Target.define(:log,&block)
end

.logsObject



158
159
160
# File 'lib/ronin/php/lfi/target.rb', line 158

def Target.logs
  Target.category(:logs)
end

.targets_for(os) ⇒ Object



162
163
164
165
166
167
168
# File 'lib/ronin/php/lfi/target.rb', line 162

def Target.targets_for(os)
  Target.each do |target|
    if target.oses.include?(os)
      return target
    end
  end
end

.test(&block) ⇒ Object



138
139
140
# File 'lib/ronin/php/lfi/target.rb', line 138

def Target.test(&block)
  Target.define(:test,&block)
end

.testsObject



142
143
144
# File 'lib/ronin/php/lfi/target.rb', line 142

def Target.tests
  Target.category(:test)
end

.with_extractorsObject



170
171
172
173
174
175
176
177
178
179
180
# File 'lib/ronin/php/lfi/target.rb', line 170

def Target.with_extractors
  targets = []

  Target.each do |target|
    unless target.extractors.empty?
      targets << target
    end
  end

  return targets
end

.with_file(name) ⇒ Object



182
183
184
185
186
187
188
189
190
# File 'lib/ronin/php/lfi/target.rb', line 182

def Target.with_file(name)
  Target.each do |target|
    target.each_path do |path|
      if path =~ /#{name}$/
        return target
      end
    end
  end
end

Instance Method Details

#all_pathsObject

Returns all the paths of the target.



60
61
62
# File 'lib/ronin/php/lfi/target.rb', line 60

def all_paths
  @paths.values.flatten.uniq
end

#each_path(&block) ⇒ Object

Iterates over each path passing each one to the specified block.



74
75
76
77
78
# File 'lib/ronin/php/lfi/target.rb', line 74

def each_path(&block)
  @paths.each_value do |os_paths|
    os_paths.each(&block)
  end
end

#extract(name, pattern) ⇒ Object

Add an extraction rule with the specified name and the specified pattern.



96
97
98
# File 'lib/ronin/php/lfi/target.rb', line 96

def extract(name,pattern)
  @extractors[name] = pattern
end

#extract_from(body) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ronin/php/lfi/target.rb', line 100

def extract_from(body)
  data = {}

  @extractors.each do |name,pattern|
    match = pattern.match(body)

    if match
      if match.length > 2
        data[name] = match[1..-1]
      elsif match.length == 2
        data[name] = match[1]
      else
        data[name] = match[0]
      end
    end
  end

  return data
end

#included_in?(body) ⇒ Boolean

Returns true if the specified body has the path included in it, returns false otherwise.

Returns:

  • (Boolean)


84
85
86
87
88
89
90
# File 'lib/ronin/php/lfi/target.rb', line 84

def included_in?(body)
  if @recognizor
    return !((body =~ @recognizor).nil?)
  else
    return false
  end
end

#osesObject

Returns the supported OSes.



53
54
55
# File 'lib/ronin/php/lfi/target.rb', line 53

def oses
  @paths.keys
end

#paths_for(os) ⇒ Object

Returns the paths for the target commonly found on the specified os.



67
68
69
# File 'lib/ronin/php/lfi/target.rb', line 67

def paths_for(os)
  @paths[os]
end