WebHackersWeapons/scripts/for_migration/migration.rb

95 lines
2.2 KiB
Ruby
Raw Normal View History

2022-08-15 09:15:42 -04:00
require 'json'
2022-08-15 09:59:41 -04:00
require 'yaml'
2022-08-15 10:04:15 -04:00
require "uri"
2022-08-15 09:59:41 -04: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 09:15:42 -04:00
2022-08-15 10:26:04 -04: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 12:11:14 -04: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 10:04:15 -04:00
end
2022-08-16 07:42:23 -04:00
def get_lang url
if url.include? "https://github.com"
end
end
2022-08-15 10:19:18 -04:00
def migrate jsonfile, category
2022-08-15 10:18:05 -04:00
file = File.read(jsonfile)
data_hash = JSON.parse(file)
2022-08-15 09:15:42 -04:00
2022-08-15 10:18:05 -04: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 12:11:14 -04:00
new_obj['url'] = get_url obj['Data']
2022-08-15 10:19:18 -04:00
new_obj['category'] = category
2022-08-15 10:18:05 -04:00
new_obj['types'] = []
if obj['Install'] != nil
2022-08-15 10:26:04 -04: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 10:18:05 -04:00
end
new_obj['lang'] = [] # parse DATA
new_obj['tags'] = []
# Convert to YAML
yaml_data = YAML.dump(new_obj)
2022-08-15 09:59:41 -04:00
2022-08-15 10:18:05 -04:00
# Save yaml file
puts filename
2022-08-16 07:42:23 -04:00
File.write("./weapons/#{filename}", yaml_data)
2022-08-15 10:18:05 -04:00
end
end
2022-08-15 09:59:41 -04:00
2022-08-15 10:19:18 -04: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'