Class: IntrigueApi
- Inherits:
-
Object
- Object
- IntrigueApi
- Defined in:
- lib/intrigue_api_client.rb
Instance Method Summary collapse
- #get_log(task_id) ⇒ Object
- #get_result(task_id) ⇒ Object
-
#info(task_name) ⇒ Object
Show detailed about a task.
-
#initialize(uri, key = "") ⇒ IntrigueApi
constructor
A new instance of IntrigueApi.
-
#list ⇒ Object
List all tasks.
-
#start(project_name, task_name, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
start Start a task and wait for the result.
-
#start_and_background(project_name, task_name, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
start_and_background - start and background a task.
-
#start_scan_and_background(project_name, scan_type, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
start_scan_and_background - start and background a scan.
Constructor Details
#initialize(uri, key = "") ⇒ IntrigueApi
7 8 9 10 |
# File 'lib/intrigue_api_client.rb', line 7 def initialize(uri,key="") @intrigue_basedir = File.dirname(__FILE__) @server_uri = ENV.fetch("INTRIGUE_API", uri) end |
Instance Method Details
#get_log(task_id) ⇒ Object
129 130 131 |
# File 'lib/intrigue_api_client.rb', line 129 def get_log(task_id) log = RestClient.get "#{@server_uri}/task_results/#{task_id}/log" end |
#get_result(task_id) ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/intrigue_api_client.rb', line 133 def get_result(task_id) begin result = JSON.parse(RestClient.get "#{@server_uri}/task_results/#{task_id}.json") rescue JSON::ParserError => e response = nil end result end |
#info(task_name) ⇒ Object
Show detailed about a task
18 19 20 21 22 23 24 25 26 |
# File 'lib/intrigue_api_client.rb', line 18 def info(task_name) begin task_info = JSON.parse(RestClient.get("#{@server_uri}/tasks/#{task_name}.json")) rescue RestClient::InternalServerError => e raise "Invalid Task Called" end end |
#list ⇒ Object
List all tasks
13 14 15 |
# File 'lib/intrigue_api_client.rb', line 13 def list tasks_hash = JSON.parse(RestClient.get("#{@server_uri}/tasks.json")) end |
#start(project_name, task_name, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
start Start a task and wait for the result
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/intrigue_api_client.rb', line 61 def start(project_name,task_name,entity_hash,=nil,handler_list=nil) # Construct the request task_id = start_and_background(project_name,task_name,entity_hash,,handler_list) if task_id == "" # technically a nil is returned , but becomes an empty string #puts "[-] Task not started. Unknown Error. Exiting" return nil end ### XXX - wait to collect the response complete = false until complete sleep 3 begin uri = "#{@server_uri}/task_results/#{task_id}/complete" complete = true if(RestClient.get(uri) == "true") rescue URI::InvalidURIError => e puts "[-] Invalid URI: #{uri}" return end end ### Get the response begin response = JSON.parse(RestClient.get "#{@server_uri}/task_results/#{task_id}.json") rescue JSON::ParserError => e #puts "Error parsing JSON: #{e}" #puts "response: #{response}" response = nil end response end |
#start_and_background(project_name, task_name, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
start_and_background - start and background a task
entity_hash =
:type => "String"
:attributes => { :name => "intrigue.io"
}
options_list = [
{:name => "resolver", :value => "8.8.8.8" }
]
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/intrigue_api_client.rb', line 38 def start_and_background(project_name,task_name,entity_hash,=nil,handler_list=nil) payload = { "project_name" => project_name, "task" => task_name, "options" => , "handlers" => handler_list, "entity" => entity_hash } ### Send to the server task_id = RestClient.post "#{@server_uri}/task_results", payload.to_json, :content_type => "application/json" if task_id == "" # technically a nil is returned , but becomes an empty string #puts "[-] Task not started. Unknown Error. Exiting" return nil end task_id end |
#start_scan_and_background(project_name, scan_type, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
start_scan_and_background - start and background a scan
entity_hash =
:type => "String"
:details => { :name => "intrigue.io"
}
options_list = [
{:name => "resolver", :value => "8.8.8.8" }
]
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/intrigue_api_client.rb', line 106 def start_scan_and_background(project_name,scan_type,entity_hash,=nil,handler_list=nil) payload = { "project_name" => project_name, "scan_type" => scan_type, "options" => , "entity" => entity_hash, "handlers" => handler_list } ### Send to the server scan_id = RestClient.post "#{@server_uri}/scan_results", payload.to_json, :content_type => "application/json" if scan_id == "" # technically a nil is returned , but becomes an empty string #puts "[-] Task not started. Unknown Error. Exiting" return nil end scan_id end |