#!/usr/bin/env ruby # frozen_string_literal: true require 'pwn' require 'json' require 'optparse' opts = {} OptionParser.new do |options| options.banner = "USAGE: #{File.basename($PROGRAM_NAME)} [opts] " options.on('-tIP_HOST', '--target=IP_HOST', '') do |t| opts[:target] = t end options.on('-PPORT', '--tls-port=PORT', '') do |p| opts[:tls_port] = p end options.on('-i', '--[no-]ipinfo', '') do |i| opts[:ipinfo] = i end options.on('-pPROXY', '--proxy=PROXY', '') do |p| opts[:proxy] = p end end.parse! target = opts[:target] tls_port = opts[:tls_port] ipinfo = opts[:ipinfo] proxy = opts[:proxy].to_s.scrub.strip.chomp unless opts[:proxy].nil? begin if proxy && opts[:target].nil? browser_obj = PWN::Plugins::TransparentBrowser.open( browser_type: :rest, proxy: proxy ) browser = browser_obj[:browser]::Request target = browser.execute( method: :get, url: 'https://checkip.amazonaws.com', verify_ssl: false ).to_s.chomp elsif opts[:target].nil? browser_obj = PWN::Plugins::TransparentBrowser.open(browser_type: :rest) browser = browser_obj[:browser]::Request target = browser.execute( method: :get, url: 'https://checkip.amazonaws.com' ).to_s.chomp end puts "[ { \"target\": \"#{target}\" } ]" if ipinfo.nil? && opts[:target].nil? ipinfo = true if ipinfo.nil? && opts[:target] if ipinfo ip_info_obj = PWN::Plugins::IPInfo.get( target: target, proxy: proxy, tls_port: tls_port ) puts JSON.pretty_generate(ip_info_obj) end rescue Interrupt puts "\n#{File.basename($PROGRAM_NAME)} => Goodbye." rescue StandardError => e raise e ensure if browser_obj browser_obj = PWN::Plugins::TransparentBrowser.close( browser_obj: browser_obj ) end end