WebHackersWeapons/scripts/migration.rb

83 lines
2.0 KiB
Ruby
Raw Normal View History

2022-08-15 07:15:42 -06:00
require 'json'
2022-08-15 07:59:41 -06:00
require 'yaml'
2022-08-15 08:04:15 -06:00
require "uri"
2022-08-15 07:59:41 -06:00
def get_os install
lst = []
if install['Linux'].length > 1
lst.push 'linux'
end
if install['MacOS'].length > 1
lst.push 'macos'
end
if install['Windows'].length > 1
lst.push 'windows'
end
return lst
end
2022-08-15 07:15:42 -06:00
2022-08-15 08:26:04 -06:00
def get_browser str
lst = []
if str.include? 'Chrome'
lst.push 'chrome'
end
if str.include? 'Firefox'
lst.push 'firefox'
end
if str.include? 'Safari'
lst.push 'safari'
end
if str.include? 'Burp'
lst.push 'burpsuite'
end
if str.include? 'ZAP'
lst.push 'zap'
end
if str.include? 'All'
lst.push 'burpsuite'
lst.push 'zap'
end
return lst
end
2022-08-15 08:04:15 -06:00
def get_urls str
return URI.extract(str).uniq
end
2022-08-15 08:19:18 -06:00
def migrate jsonfile, category
2022-08-15 08:18:05 -06:00
file = File.read(jsonfile)
data_hash = JSON.parse(file)
2022-08-15 07:15:42 -06:00
2022-08-15 08:18:05 -06:00
data_hash.each do | name, obj |
filename = name.gsub(' ','_')+".yaml"
# Make object
new_obj = {}
new_obj['name'] = name
new_obj['description'] = obj['Description']
new_obj['urls'] = get_urls obj['Data']
2022-08-15 08:19:18 -06:00
new_obj['category'] = category
2022-08-15 08:18:05 -06:00
new_obj['types'] = []
if obj['Install'] != nil
2022-08-15 08:26:04 -06:00
new_obj['platform'] = get_os(obj['Install'])
end
if category.include? 'addon'
if obj['Type'].length > 0
new_obj['platform'] = get_browser(obj['Type'])
end
2022-08-15 08:18:05 -06:00
end
new_obj['lang'] = [] # parse DATA
new_obj['tags'] = []
# Convert to YAML
yaml_data = YAML.dump(new_obj)
2022-08-15 07:59:41 -06:00
2022-08-15 08:18:05 -06:00
# Save yaml file
puts filename
#File.write("./weapons/#{filename}", yaml_data)
2022-08-15 08:18:05 -06:00
end
end
2022-08-15 07:59:41 -06:00
2022-08-15 08:19:18 -06:00
migrate './data.json', 'tool'
migrate './Bookmarklets/data.json', 'bookmarklet'
migrate './Browser Extensions/data.json', 'browser-addon'
migrate './Burp and ZAP Extensions/data.json', 'tool-addon'