From c279365ccc0ad86b3250f4cf6a20bf31c3b8c606 Mon Sep 17 00:00:00 2001 From: Conor Horan-Kates Date: Mon, 28 Nov 2016 19:17:47 -0800 Subject: [PATCH] useful tools, probably should be part of ctf --- lib/util.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/util.rb diff --git a/lib/util.rb b/lib/util.rb new file mode 100644 index 0000000..7d0024b --- /dev/null +++ b/lib/util.rb @@ -0,0 +1,52 @@ +#!/usr/bin/ruby + +require 'base64' +require 'net/http' +require 'uri' + +class Utility + + # TODO add a logger here + + def self.get_url(url) + uri = URI.parse(url) + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = false + request = Net::HTTP::Get.new(uri.request_uri) + response = http.request(request) + + if response.code.eql?('301') + return self.get_url(response.header['location']) + end + + response + end + + def self.base64_decode(string) + Base64.strict_decode64(string) + end + + def self.base64_encode(string) + Base64.strict_decode64(string) + end + + def self.uri_encode(string) + URI.encode(string) + end + + def self.uri_decode(string) + URI.decode(string) + end + + def self.uri_form_decode(string) + h = Hash.new + + URI.decode_www_form(string).each do |array| + h[array.first.to_sym] = array.last + end + + h + end + + +end \ No newline at end of file