require 'base64' require 'cryptic' require 'colorize' require 'json' require 'thor' require 'threat_agent' module ThreatAgent module Tasks # A namespace for Pwnxy Thor tasks # # @author Erran Carey class Pwnxy < Thor desc 'pwnxy info', 'List information on Pwnxy instances' def info info = $threat_agent_client.request(:pwnxy_info) # TODO: Add a UI class/method. $stdout.puts info end desc 'pwnxy logs [INSTANCE] [OPTIONS]', 'Show logs for a Pwnxy instance' def logs(identifier = 0) logs = $threat_agent_client.request(:pwnxy_logs, { p: identifier }) # TODO: Add a UI class/method. # TODO: Return the logs to the user if logs.is_a?(Hash) && logs['error'] $stderr.puts "Threat Agent API Error: #{logs['error']}".red exit 255 # This is an API error. Exit with an unspecific code. end $stdout.puts decrypt(logs) end no_commands do def decrypt(logs) keypair = Cryptic::Keypair.new(ThreatAgent::Config[:private_key]) private_key = keypair.private_key logs.map do |log| cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc') cipher.decrypt cipher.key = private_key.private_decrypt(Base64.decode64(log['encrypted_key'])) cipher.iv = private_key.private_decrypt(Base64.decode64(log['encrypted_iv'])) decrypted_data = cipher.update(Base64.decode64(log['encrypted_data'])) decrypted_data << cipher.final end.to_json end end end end end