threat_agent 1.0.0.beta.2 → 1.0.0.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/threatagent +4 -0
- data/lib/threat_agent/api_client.rb +6 -1
- data/lib/threat_agent/config.rb +1 -1
- data/lib/threat_agent/tasks/pwnxy.rb +56 -11
- data/lib/threat_agent/version.rb +1 -1
- data/threat_agent.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c559b1e76c0a281873bbe879d17806df5a5755f1
|
4
|
+
data.tar.gz: 38e547ecec2e570c1f5c491e895230e38f3f48cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ba0700266a222fd56c45c1f4bcf41d3e1c2ec8cb00c6e9083fa6bf7035d8f36c7bd9c2128d249c98cf434c6221bb7c8d4b036d5252f28647166434dec74a9ee
|
7
|
+
data.tar.gz: 89ef2559c5c1d8e23c5801cb92744a3c940aa2b492957ac3794d4f237f642def57f9046c893c55c366b60bdb6e1976aaef17d48b9700ddaaaf528bf4253a7c7c
|
data/bin/threatagent
CHANGED
@@ -35,7 +35,11 @@ class ThreatAgentCLI < Thor
|
|
35
35
|
subcommand :pwnxy, ThreatAgent::Tasks::Pwnxy
|
36
36
|
end
|
37
37
|
|
38
|
+
# TODO: Add a global configuration instead of independently loading it
|
39
|
+
# everytime?
|
38
40
|
config = ThreatAgent::Config
|
41
|
+
config.from_file("#{ENV['HOME']}/.threatagent")
|
42
|
+
|
39
43
|
$threat_agent_client = ThreatAgent::APIClient.new(config[:key], config[:sup])
|
40
44
|
|
41
45
|
ThreatAgentCLI.start(ARGV)
|
@@ -58,7 +58,12 @@ module ThreatAgent
|
|
58
58
|
|
59
59
|
resp = Net::HTTP.get_response(uri)
|
60
60
|
json = resp.body
|
61
|
-
|
61
|
+
|
62
|
+
if json =~ /^[{\[].*[\]}]$/
|
63
|
+
JSON.parse(json)
|
64
|
+
else
|
65
|
+
JSON.parse(json, { quirks_mode: true }) || { 'error' => 'An unknown error occurred' }
|
66
|
+
end
|
62
67
|
end
|
63
68
|
end
|
64
69
|
end
|
data/lib/threat_agent/config.rb
CHANGED
@@ -13,7 +13,7 @@ module ThreatAgent
|
|
13
13
|
|
14
14
|
# Sets the default configuration options
|
15
15
|
configure do |config|
|
16
|
-
config[:endpoint] =
|
16
|
+
config[:endpoint] = 'https://www.threatagent.com'
|
17
17
|
config[:key] = ENV['THREAT_AGENT_KEY']
|
18
18
|
config[:sup] = ENV['THREAT_AGENT_SUP']
|
19
19
|
config[:api_version] = 'v1'
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'cryptic'
|
3
3
|
require 'colorize'
|
4
|
+
require 'formatador'
|
4
5
|
require 'json'
|
5
6
|
require 'thor'
|
6
7
|
require 'threat_agent'
|
@@ -11,30 +12,72 @@ module ThreatAgent
|
|
11
12
|
#
|
12
13
|
# @author Erran Carey <me@errancarey.com>
|
13
14
|
class Pwnxy < Thor
|
15
|
+
class_option :format, aliases: %w[-f], default: :readable, desc: 'The format to display data in'
|
14
16
|
desc 'pwnxy info', 'List information on Pwnxy instances'
|
15
17
|
def info
|
16
18
|
info = $threat_agent_client.request(:pwnxy_info)
|
17
|
-
|
18
|
-
|
19
|
+
if options[:format].eql? 'json'
|
20
|
+
$stdout.puts info
|
21
|
+
else
|
22
|
+
[:encrypted, :encrypted_iv, :encrypted_key].each { |key| info.delete(key) }
|
23
|
+
Formatador.display_table(info)
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
|
-
desc 'pwnxy logs [INSTANCE] [OPTIONS]', 'Show logs for a Pwnxy instance'
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
desc 'pwnxy logs [INSTANCE] [ID] [OPTIONS]', 'Show logs for a Pwnxy instance'
|
28
|
+
method_option :encrypted, aliases: %w[-e], default: false, desc: 'Whether or not to decrypt the logs',type: :boolean
|
29
|
+
def logs(pwnxy_id = 0, id = nil)
|
30
|
+
id = id.to_i
|
31
|
+
|
32
|
+
logs = $threat_agent_client.request(:pwnxy_logs, { p: pwnxy_id })
|
26
33
|
if logs.is_a?(Hash) && logs['error']
|
27
34
|
$stderr.puts "Threat Agent API Error: #{logs['error']}".red
|
28
35
|
exit 255 # This is an API error. Exit with an unspecific code.
|
29
36
|
end
|
30
37
|
|
31
|
-
|
38
|
+
if options[:encrypted]
|
39
|
+
if options[:format].eql? 'json'
|
40
|
+
$stdout.puts (id ? logs[id] : logs).to_json
|
41
|
+
else
|
42
|
+
Formatador.display_table(id ? logs[id] : logs)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
decrypted_logs = decrypt(logs)
|
46
|
+
|
47
|
+
if options[:format].eql? 'json'
|
48
|
+
$stdout.puts (id ? decrypted_logs[id] : decrypted_logs).to_json
|
49
|
+
else
|
50
|
+
# # #
|
51
|
+
# Figure out how to use Formatador or an equiv to make a prettier
|
52
|
+
# table.
|
53
|
+
#
|
54
|
+
# Formatador.display_table(id ? decrypted_logs[id] : decrypted_logs)
|
55
|
+
# # #
|
56
|
+
printable = id ? decrypted_logs[id] : decrypted_logs
|
57
|
+
if printable.is_a? Hash
|
58
|
+
printable.each do |name, value|
|
59
|
+
if value
|
60
|
+
$stdout.puts "#{name}:", value, '---'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
elsif printable.is_a? Array
|
64
|
+
printable.each do |element|
|
65
|
+
printable.each do |name, value|
|
66
|
+
if value
|
67
|
+
$stdout.puts "#{name}:", value, '---'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
else
|
72
|
+
$stdout.puts printable.to_s
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
32
76
|
end
|
33
77
|
|
34
78
|
no_commands do
|
35
79
|
def decrypt(logs)
|
36
|
-
|
37
|
-
private_key = keypair.private_key
|
80
|
+
private_key = OpenSSL::PKey::RSA.new(ThreatAgent::Config[:private_key])
|
38
81
|
|
39
82
|
logs.map do |log|
|
40
83
|
cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
|
@@ -44,7 +87,9 @@ module ThreatAgent
|
|
44
87
|
|
45
88
|
decrypted_data = cipher.update(Base64.decode64(log['encrypted_data']))
|
46
89
|
decrypted_data << cipher.final
|
47
|
-
|
90
|
+
|
91
|
+
JSON.parse(decrypted_data) || {}
|
92
|
+
end
|
48
93
|
end
|
49
94
|
end
|
50
95
|
end
|
data/lib/threat_agent/version.rb
CHANGED
data/threat_agent.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: threat_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.beta.
|
4
|
+
version: 1.0.0.beta.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erran Carey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: formatador
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: json
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|