New json structure implemented #853

This commit is contained in:
ethicalhack3r
2015-09-03 22:04:44 +02:00
parent 57f6206aee
commit e6d29f6f18
9 changed files with 78 additions and 96 deletions

View File

@@ -172,19 +172,19 @@ class WpItems < Array
case type case type
when :vulnerable when :vulnerable
item_names = json.select { |item| !item['vulnerabilities'].empty? }.map {|item| item['name'] } items = json.select { |item| !json[item]['vulnerabilities'].empty? }
when :popular when :popular
item_names = json.select { |item| item['popular'] == true }.map {|item| item['name'] } items = json.select { |item| json[item]['popular'] == true }
when :all when :all
item_names = [*json].map { |item| item['name'] } items = [*json]
else else
raise "Unknown type #{type}" raise "Unknown type #{type}"
end end
item_names.each do |item_name| items.each do |item|
targets << create_item( targets << create_item(
item_class, item_class,
item_name, item[0],
wp_target, wp_target,
vulns_file vulns_file
) )

View File

@@ -12,19 +12,13 @@ class WpItem
json = json(vulns_file) json = json(vulns_file)
vulnerabilities = Vulnerabilities.new vulnerabilities = Vulnerabilities.new
json.each do |item| return vulnerabilities if json.empty?
asset = item['version'] || item['name']
next unless asset == identifier json[identifier]['vulnerabilities'].each do |vulnerability|
item['vulnerabilities'].each do |vulnerability|
vulnerability = Vulnerability.load_from_json_item(vulnerability) vulnerability = Vulnerability.load_from_json_item(vulnerability)
vulnerabilities << vulnerability if vulnerable_to?(vulnerability) vulnerabilities << vulnerability if vulnerable_to?(vulnerability)
end end
break # No need to iterate any further
end
vulnerabilities vulnerabilities
end end

View File

@@ -1,6 +1,5 @@
[
{ {
"name": "mr-smith", "mr-smith": {
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2989, "id":2989,
@@ -48,8 +47,7 @@
} }
] ]
}, },
{ "neo": {
"name": "neo",
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2993, "id":2993,
@@ -63,4 +61,4 @@
} }
] ]
} }
] }

View File

@@ -1,6 +1,5 @@
[
{ {
"name": "mr-smith", "mr-smith": {
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2989, "id":2989,
@@ -48,8 +47,7 @@
} }
] ]
}, },
{ "neo": {
"name":"neo",
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2993, "id":2993,
@@ -63,4 +61,4 @@
} }
] ]
} }
] }

View File

@@ -1,6 +1,5 @@
[
{ {
"name": "shopperpress", "shopperpress": {
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2989, "id":2989,
@@ -48,8 +47,7 @@
} }
] ]
}, },
{ "webfolio": {
"name": "webfolio",
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2993, "id":2993,
@@ -63,4 +61,5 @@
} }
] ]
} }
] }

View File

@@ -1,6 +1,5 @@
[
{ {
"name": "not-this-one", "not-this-one": {
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2989, "id":2989,
@@ -13,8 +12,7 @@
} }
] ]
}, },
{ "neo": {
"name": "neo",
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2993, "id":2993,
@@ -34,4 +32,4 @@
} }
] ]
} }
] }

View File

@@ -1,6 +1,5 @@
[
{ {
"name": "mr-smith", "mr-smith": {
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2993, "id":2993,
@@ -36,8 +35,7 @@
} }
] ]
}, },
{ "white-rabbit": {
"name": "white-rabbit",
"vulnerabilities": [ "vulnerabilities": [
{ {
"id":2993, "id":2993,
@@ -57,4 +55,4 @@
} }
] ]
} }
] }

View File

@@ -1,6 +1,5 @@
[
{ {
"name": "mr-smith", "mr-smith": {
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2989, "id":2989,
@@ -36,8 +35,7 @@
} }
] ]
}, },
{ "the-oracle": {
"name": "the-oracle",
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2993, "id":2993,
@@ -57,4 +55,5 @@
} }
] ]
} }
] }

View File

@@ -1,6 +1,5 @@
[
{ {
"version": "3.5", "3.5": {
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2989, "id":2989,
@@ -20,8 +19,7 @@
} }
] ]
}, },
{ "3.2": {
"version": "3.2",
"vulnerabilities":[ "vulnerabilities":[
{ {
"id":2993, "id":2993,
@@ -41,4 +39,4 @@
} }
] ]
} }
] }