WebHackersWeapons/scripts/migration.rb

95 lines
2.2 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-16 10:11:14 -06:00
def get_url str
urls = URI.extract(str).uniq
urls.each do |url|
if !url.include? "img.shields.io"
return url.gsub(")","")
end
end
return ""
2022-08-15 08:04:15 -06:00
end
2022-08-16 05:42:23 -06:00
def get_lang url
if url.include? "https://github.com"
end
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']
2022-08-16 10:11:14 -06:00
new_obj['url'] = get_url 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
2022-08-16 05:42:23 -06:00
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'