Class: Dradis::Plugins::Wpscan::Importer

Inherits:
Upload::Importer
  • Object
show all
Defined in:
lib/dradis/plugins/wpscan/importer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.templatesObject



3
4
5
# File 'lib/dradis/plugins/wpscan/importer.rb', line 3

def self.templates
  { evidence: 'evidence', issue: 'vulnerability' }
end

Instance Method Details

#create_node(data) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dradis/plugins/wpscan/importer.rb', line 59

def create_node(data)
  node = content_service.create_node(label: data['target_url'], type: :host)

  # Define Node properties
  if node.respond_to?(:properties)
    node.set_property(:start_url, data['target_url'])
    #node.set_property(:start_time, data['start_time'])
    node.set_property(:scan_time, data['elapsed'])
  end

  scan_info = mapping_service.apply_mapping(source: 'scan_info', data: data)
  content_service.create_note text: scan_info, node: node

  node
end

#import(params = {}) ⇒ Object

The framework will call this function if the user selects this plugin from the dropdown list and uploads a file.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dradis/plugins/wpscan/importer.rb', line 10

def import(params = {})
  file_content = File.read(params[:file])

  # Parse the uploaded file into a Ruby Hash
  logger.info { "Parsing WPScan output from #{ params[:file] }..." }
  data = MultiJson.decode(file_content)
  logger.info { 'Done.' }

  # Do a sanity check to confirm the user uploaded the right file
  # format.
  if data['target_url'].nil?
    error = "ERROR: No 'target_url' field present in the provided " \
            'JSON data. Are you sure you uploaded a WPScan JSON output file?'
    logger.fatal { error }
    content_service.create_note text: error
    return false
  end

  # Initial data normalisation
  data = parse_json(data)

  # Create a node based on the target_url
  node = create_node(data)

  # Parse vulnerability data and make more human readable.
  # NOTE: You need an API token for the WPVulnDB vulnerability data.
  parse_known_vulnerabilities(data, node)

  # Add bespoke/config vulnerabilities to Dradis
  #
  # TODO: Can we add severity to issues?
  #
  # Note: No API key needed.
  parse_config_vulnerabilities(data, node)
end

#parse_config_vulnerabilities(data, node) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/dradis/plugins/wpscan/importer.rb', line 121

def parse_config_vulnerabilities(data, node)
  vulnerabilities = []

  if data['config_backups']
    data['config_backups'].each do |url, value|
      vulnerability = {}
      vulnerability['title']    = 'WordPress Configuration Backup Found'
      vulnerability['evidence'] = url

      vulnerabilities << vulnerability
    end
  end

  if data['db_exports']
    data['db_exports'].each do |url, value|
      vulnerability = {}
      vulnerability['title']    = 'Database Backup File Found'
      vulnerability['evidence'] = url

      vulnerabilities << vulnerability
    end
  end

  if data['timthumbs']
    data['timthumbs'].each do |url, value|
      unless value['vulnerabilities'].empty?
        vulnerability = {}
        vulnerability['title']    = 'Timthumb RCE File Found'
        vulnerability['evidence'] = url

        vulnerabilities << vulnerability
      end
    end
  end

  if data['password_attack']
    data['password_attack'].each do |user|
      vulnerability = {}
      vulnerability['title'] = 'WordPres Weak User Password Found'
      vulnerability['evidence'] = "#{user[0]}:#{user[1]['password']}"

      vulnerabilities << vulnerability
    end
  end

  # Add WordPress configuration vulnerabilities to Dradis
  vulnerabilities.each do |vulnerability|
    logger.info { "Adding vulnerability: #{vulnerability['title']}" }

    vulnerability_template = mapping_service.apply_mapping(source: 'vulnerability', data: vulnerability)
    issue = content_service.create_issue(text: vulnerability_template, id: "wpscan_#{rand(999999)}")

    if vulnerability['evidence']
      evidence_content = mapping_service.apply_mapping(source: 'evidence', data: vulnerability)
      content_service.create_evidence(issue: issue, node: node, content: vulnerability['evidence'])
    end
  end
end

#parse_json(data) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dradis/plugins/wpscan/importer.rb', line 46

def parse_json(data)
  # Parse scan info data and make more human readable.
  data['wpscan_version']    = data.dig('banner', 'version')
  data['start_time']        = DateTime.strptime(data['start_time'].to_s, '%s')
  data['elapsed']           = "#{data["elapsed"]} seconds"
  data['wordpress_version'] = data.dig('version', 'number')   if data['version']
  data['plugins_string']    = data['plugins'].keys.join("\n") if data['plugins']
  data['themes_string']     = data['themes'].keys.join("\n")  if data['themes']
  data['users']             = data['users'].keys.join("\n")   if data['users']

  data
end

#parse_known_vulnerabilities(data, node) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/dradis/plugins/wpscan/importer.rb', line 75

def parse_known_vulnerabilities(data, node)
  vulnerabilities = []

  # WordPress Vulnerabilities
  if data['version'] && ['insecure', 'outdated'].include?(data['version']['status'])
    data['version']['vulnerabilities'].each do |vulnerability_data|
      vulnerabilities << parse_vulnerability(vulnerability_data)
    end
  end

  # Plugin Vulnerabilities
  if data['plugins']
    data['plugins'].each do |key, plugin|
      if plugin['vulnerabilities']
        plugin['vulnerabilities'].each do |vulnerability_data|
          vulnerabilities << parse_vulnerability(vulnerability_data)
        end
      end
    end
  end

  # Theme Vulnerabilities
  if data['themes']
    data['themes'].each do |key, theme|
      if theme['vulnerabilities']
        theme['vulnerabilities'].each do |vulnerability_data|
          vulnerabilities << parse_vulnerability(vulnerability_data)
        end
      end
    end
  end

  # Add vulnerabilities from WPVulnDB to Dradis
  vulnerabilities.each do |vulnerability|
    logger.info { "Adding vulnerability: #{vulnerability['title']}" }

    vulnerability_template = mapping_service.apply_mapping(source: 'vulnerability', data: vulnerability)
    issue = content_service.create_issue(text: vulnerability_template, id: vulnerability['wpvulndb_id'], node: node)

    if vulnerability['evidence']
      evidence_content = mapping_service.apply_mapping(source: 'evidence', data: vulnerability)
      content_service.create_evidence(issue: issue, node: node, content: vulnerability['evidence'])
    end
  end
end

#parse_vulnerability(vulnerability_data) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/dradis/plugins/wpscan/importer.rb', line 180

def parse_vulnerability(vulnerability_data)
  wpvulndb_url = 'https://wpvulndb.com/vulnerabilities/'

  vulnerability = {}
  vulnerability['title']        = vulnerability_data['title']
  vulnerability['fixed_in']     = vulnerability_data['fixed_in'] if vulnerability_data['fixed_in']
  vulnerability['cve']          = 'CVE-' + vulnerability_data['references']['cve'][0] if vulnerability_data['references']['cve']
  vulnerability['url']          = vulnerability_data['references']['url'].join("\n") if vulnerability_data['references']['url']
  vulnerability['wpvulndb_url'] = wpvulndb_url + vulnerability_data['references']['wpvulndb'][0]
  vulnerability['wpvulndb_id']  = vulnerability_data['references']['wpvulndb'][0]

  vulnerability
end