intrigue_api_client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/intrigue_api_client.rb +174 -0
  3. metadata +72 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4c28aff534d6ba8d84afd9b197d89bc8ad481d56
4
+ data.tar.gz: 80a7eec6c67da5892b9a52a652e0be2dcad465e5
5
+ SHA512:
6
+ metadata.gz: 3c26b74ad69289eaee25907c39dd354cb32a8c23d1cb6235712f1a97b314f094a5513067c0e2da0363f345df348225c6f28bc6c72675886b873d3d3867e83b17
7
+ data.tar.gz: aa30f1f67ba6a4340646325b846f6e011455672542706cb10c076c973ef6a0a4edf271051df4864b12ae182f544b75a3c0a6807886312cc6d23ac152634cbb1c
@@ -0,0 +1,174 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'rest_client'
4
+
5
+ class IntrigueApi
6
+
7
+ def initialize(uri="http://127.0.0.1:7777/v1",key="")
8
+ @intrigue_basedir = File.dirname(__FILE__)
9
+ @server_uri = ENV.fetch("INTRIGUE_API", uri)
10
+ @server_key = key
11
+ end
12
+
13
+ # List all tasks
14
+ def list
15
+ tasks_hash = JSON.parse(RestClient.get("#{@server_uri}/tasks.json"))
16
+ end
17
+
18
+ # Show detailed about a task
19
+ def info(task_name)
20
+
21
+ begin
22
+ task_info = JSON.parse(RestClient.get("#{@server_uri}/tasks/#{task_name}.json"))
23
+ rescue RestClient::InternalServerError => e
24
+ raise "Invalid Task Called"
25
+ end
26
+
27
+ end
28
+
29
+ # start_and_background - start and background a task
30
+ #
31
+ # entity_hash = {
32
+ # :type => "String"
33
+ # :attributes => { :name => "intrigue.io"}
34
+ # }
35
+ #
36
+ # options_list = [
37
+ # {:name => "resolver", :value => "8.8.8.8" }
38
+ # ]
39
+ def start_and_background(task_name,entity_hash,options_list=nil,handler_list=nil)
40
+
41
+ payload = {
42
+ "task" => task_name,
43
+ "options" => options_list,
44
+ "handlers" => handler_list,
45
+ "entity" => entity_hash
46
+ }
47
+
48
+ ### Send to the server
49
+ task_id = RestClient.post "#{@server_uri}/task_results",
50
+ payload.to_json, :content_type => "application/json"
51
+
52
+ if task_id == "" # technically a nil is returned , but becomes an empty string
53
+ #puts "[-] Task not started. Unknown Error. Exiting"
54
+ return nil
55
+ end
56
+
57
+ task_id
58
+ end
59
+
60
+ # start Start a task and wait for the result
61
+ def start(task_name,entity_hash,options_list=nil,handler_list=nil)
62
+
63
+ # Construct the request
64
+ task_id = start_and_background(task_name,entity_hash,options_list,handler_list)
65
+
66
+ if task_id == "" # technically a nil is returned , but becomes an empty string
67
+ #puts "[-] Task not started. Unknown Error. Exiting"
68
+ return nil
69
+ end
70
+
71
+ ### XXX - wait to collect the response
72
+ complete = false
73
+ until complete
74
+ sleep 3
75
+ begin
76
+ uri = "#{@server_uri}/task_results/#{task_id}/complete"
77
+ complete = true if(RestClient.get(uri) == "true")
78
+ rescue URI::InvalidURIError => e
79
+ puts "[-] Invalid URI: #{uri}"
80
+ return
81
+ end
82
+ end
83
+
84
+ ### Get the response
85
+ begin
86
+ response = JSON.parse(RestClient.get "#{@server_uri}/task_results/#{task_id}.json")
87
+ rescue JSON::ParserError => e
88
+ #puts "Error parsing JSON: #{e}"
89
+ #puts "response: #{response}"
90
+ response = nil
91
+ end
92
+
93
+ response
94
+ end
95
+
96
+ # start_scan_and_background - start and background a scan
97
+ #
98
+ # entity_hash = {
99
+ # :type => "String"
100
+ # :details => { :name => "intrigue.io"}
101
+ # }
102
+ #
103
+ # options_list = [
104
+ # {:name => "resolver", :value => "8.8.8.8" }
105
+ # ]
106
+ def start_scan_and_background(scan_type,entity_hash,options_list=nil,handler_list=nil)
107
+
108
+ payload = {
109
+ "scan_type" => scan_type,
110
+ "options" => options_list,
111
+ "entity" => entity_hash,
112
+ "handlers" => handler_list
113
+ }
114
+
115
+ ### Send to the server
116
+ scan_id = RestClient.post "#{@server_uri}/scan_results",
117
+ payload.to_json, :content_type => "application/json"
118
+
119
+
120
+ if scan_id == "" # technically a nil is returned , but becomes an empty string
121
+ #puts "[-] Task not started. Unknown Error. Exiting"
122
+ return nil
123
+ end
124
+
125
+ scan_id
126
+ end
127
+
128
+ def get_log(task_id)
129
+ log = RestClient.get "#{@server_uri}/task_results/#{task_id}/log"
130
+ end
131
+
132
+ def get_result(task_id)
133
+ begin
134
+ result = JSON.parse(RestClient.get "#{@server_uri}/task_results/#{task_id}.json")
135
+ rescue JSON::ParserError => e
136
+ response = nil
137
+ end
138
+ result
139
+ end
140
+
141
+
142
+ end
143
+
144
+
145
+ ###
146
+ ### SAMPLE USAGE
147
+ ###
148
+
149
+ =begin
150
+ x = Intrigue.new
151
+
152
+ #
153
+ # Create an entity hash, must have a :type key
154
+ # and (in the case of most tasks) a :attributes key
155
+ # with a hash containing a :name key (as shown below)
156
+ #
157
+ entity = {
158
+ :type => "String",
159
+ :attributes => { :name => "intrigue.io"}
160
+ }
161
+
162
+ #
163
+ # Create a list of options (this can be empty)
164
+ #
165
+ options_list = [
166
+ { :name => "resolver", :value => "8.8.8.8" }
167
+ ]
168
+
169
+ x.start "example", entity_hash, options_list
170
+ id = x.start "search_bing", entity_hash, options_list
171
+ puts x.get_log id
172
+ puts x.get_result id
173
+
174
+ =end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intrigue_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - jcran
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ description: API client for intrigue-core
42
+ email: jcran@intrigue.io
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/intrigue_api_client.rb
48
+ homepage: http://rubygems.org/gems/intrigue_api_client
49
+ licenses:
50
+ - BSD
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.4.6
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: API client for intrigue-core
72
+ test_files: []