intrigue_api_client 1.0.1 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/intrigue_api_client.rb +26 -37
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7584cd1b0f64137d233048a2417c114608108778
|
4
|
+
data.tar.gz: 5120734394133b63b0d78993c124aadac04677ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 258cae10730ec552a67c32960bcf9bcd25eb783ec6d758e3fb66b448a50d895b5f96ef34d341376639841a4a7e45a9f04c1232620070a8f78cd261bb7a37169a
|
7
|
+
data.tar.gz: c6914d3271b78359b6bb4ecb873e37dcbce30cf99a201fccffdba5e79592d1d31c8fe365af7f0d4c138c2a933a7acafd4c419601609a382579b1efe35e5e8be9
|
data/lib/intrigue_api_client.rb
CHANGED
@@ -6,33 +6,28 @@ class IntrigueApi
|
|
6
6
|
|
7
7
|
def initialize(uri,key="")
|
8
8
|
@intrigue_basedir = File.dirname(__FILE__)
|
9
|
-
@server_uri =
|
9
|
+
@server_uri = uri
|
10
10
|
end
|
11
11
|
|
12
12
|
# List all tasks
|
13
13
|
def list
|
14
|
-
|
14
|
+
_get_json_result "tasks.json"
|
15
15
|
end
|
16
16
|
|
17
17
|
# Show detailed about a task
|
18
18
|
def info(task_name)
|
19
|
-
|
20
|
-
begin
|
21
|
-
task_info = JSON.parse(RestClient.get("#{@server_uri}/tasks/#{task_name}.json"))
|
22
|
-
rescue RestClient::InternalServerError => e
|
23
|
-
raise "Invalid Task Called"
|
24
|
-
end
|
25
|
-
|
19
|
+
_get_json_result "#{@server_uri}/tasks/#{task_name}.json"
|
26
20
|
end
|
27
21
|
|
28
22
|
# start_and_background - start and background a task
|
29
23
|
#
|
30
|
-
#
|
24
|
+
# project_name - must exist as a valid project_name
|
25
|
+
# task_name - must exist as a valid task name
|
26
|
+
# entity_hash - symbol-based hash representing an entity: {
|
31
27
|
# :type => "String"
|
32
28
|
# :attributes => { :name => "intrigue.io"}
|
33
29
|
# }
|
34
|
-
#
|
35
|
-
# options_list = [
|
30
|
+
# options_list - list of options: [
|
36
31
|
# {:name => "resolver", :value => "8.8.8.8" }
|
37
32
|
# ]
|
38
33
|
def start_and_background(project_name,task_name,entity_hash,options_list=nil,handler_list=nil)
|
@@ -46,7 +41,7 @@ class IntrigueApi
|
|
46
41
|
}
|
47
42
|
|
48
43
|
### Send to the server
|
49
|
-
task_id = RestClient.post "#{@server_uri}/task_results",
|
44
|
+
task_id = RestClient.post "#{@server_uri}/#{project_name}/task_results",
|
50
45
|
payload.to_json, :content_type => "application/json"
|
51
46
|
|
52
47
|
if task_id == "" # technically a nil is returned , but becomes an empty string
|
@@ -57,7 +52,7 @@ class IntrigueApi
|
|
57
52
|
task_id
|
58
53
|
end
|
59
54
|
|
60
|
-
#
|
55
|
+
# Start a task and wait for the result
|
61
56
|
def start(project_name,task_name,entity_hash,options_list=nil,handler_list=nil)
|
62
57
|
|
63
58
|
# Construct the request
|
@@ -71,10 +66,10 @@ class IntrigueApi
|
|
71
66
|
### XXX - wait to collect the response
|
72
67
|
complete = false
|
73
68
|
until complete
|
74
|
-
sleep
|
69
|
+
sleep 1
|
75
70
|
begin
|
76
|
-
|
77
|
-
complete = true if
|
71
|
+
response = RestClient.get "#{@server_uri}/#{project_name}/task_results/#{task_id}/complete"
|
72
|
+
complete = true if response == "true"
|
78
73
|
rescue URI::InvalidURIError => e
|
79
74
|
puts "[-] Invalid URI: #{uri}"
|
80
75
|
return
|
@@ -82,27 +77,12 @@ class IntrigueApi
|
|
82
77
|
end
|
83
78
|
|
84
79
|
### Get the response
|
85
|
-
|
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
|
80
|
+
response = _get_json_result "#{project_name}/task_results/#{task_id}.json"
|
92
81
|
|
93
82
|
response
|
94
83
|
end
|
95
84
|
|
96
85
|
# 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
86
|
def start_scan_and_background(project_name,scan_type,entity_hash,options_list=nil,handler_list=nil)
|
107
87
|
|
108
88
|
payload = {
|
@@ -114,12 +94,11 @@ class IntrigueApi
|
|
114
94
|
}
|
115
95
|
|
116
96
|
### Send to the server
|
117
|
-
scan_id = RestClient.post "#{@server_uri}/scan_results",
|
97
|
+
scan_id = RestClient.post "#{@server_uri}/#{project_name}/scan_results",
|
118
98
|
payload.to_json, :content_type => "application/json"
|
119
99
|
|
120
100
|
|
121
101
|
if scan_id == "" # technically a nil is returned , but becomes an empty string
|
122
|
-
#puts "[-] Task not started. Unknown Error. Exiting"
|
123
102
|
return nil
|
124
103
|
end
|
125
104
|
|
@@ -127,18 +106,28 @@ class IntrigueApi
|
|
127
106
|
end
|
128
107
|
|
129
108
|
def get_log(task_id)
|
130
|
-
log =
|
109
|
+
log = _get_json_result "#{project_name}/task_results/#{task_id}/log"
|
131
110
|
end
|
132
111
|
|
133
112
|
def get_result(task_id)
|
134
113
|
begin
|
135
|
-
result =
|
114
|
+
result = _get_json_result "#{project_name}/task_results/#{task_id}.json"
|
136
115
|
rescue JSON::ParserError => e
|
137
116
|
response = nil
|
138
117
|
end
|
139
118
|
result
|
140
119
|
end
|
141
120
|
|
121
|
+
def _get_json_result(path)
|
122
|
+
begin
|
123
|
+
JSON.parse(RestClient.get "#{@server_uri}/#{path}")
|
124
|
+
rescue JSON::ParserError => e
|
125
|
+
puts "Error: #{e}"
|
126
|
+
rescue RestClient::InternalServerError => e
|
127
|
+
puts "Error: #{e}"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
142
131
|
|
143
132
|
end
|
144
133
|
|