lib/threat_agent/tasks/pwnxy.rb in threat_agent-1.0.0.beta.1 vs lib/threat_agent/tasks/pwnxy.rb in threat_agent-1.0.0.beta.2
- old
+ new
@@ -1,5 +1,9 @@
+require 'base64'
+require 'cryptic'
+require 'colorize'
+require 'json'
require 'thor'
require 'threat_agent'
module ThreatAgent
module Tasks
@@ -13,17 +17,36 @@
# TODO: Add a UI class/method.
$stdout.puts info
end
desc 'pwnxy logs [INSTANCE] [OPTIONS]', 'Show logs for a Pwnxy instance'
- # TODO: Add logs(identifier = :last), add support in the TA API
- # Support last/first in the TA API. Currently 0 returns first. Use
- # -1 for last?
- # TODO: Add support for dropping all logs?
def logs(identifier = 0)
- log = $threat_agent_client.request(:pwnxy_logs, { p: identifier })
+ logs = $threat_agent_client.request(:pwnxy_logs, { p: identifier })
# TODO: Add a UI class/method.
- $stdout.puts log
+ # 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