Class: Nessus::Client
- Inherits:
-
Object
- Object
- Nessus::Client
- Defined in:
- lib/nessus/xmlrpc.rb
Instance Method Summary collapse
- #authenticate(username, password) ⇒ Object (also: #login)
- #authenticated ⇒ Object
- #get_server_properties ⇒ Object
- #host_detail(scan_id, host_id) ⇒ Object
-
#initialize(host, username = nil, password = nil, ssl_option = nil) {|@connection| ... } ⇒ Client
constructor
A new instance of Client.
- #is_admin ⇒ Object
- #list_families ⇒ Object
- #list_folders ⇒ Object
- #list_plugins(family_id) ⇒ Object
- #list_policies ⇒ Object
- #list_scanners ⇒ Object
- #list_template(type) ⇒ Object
- #list_users ⇒ Object
- #plugin_details(plugin_id) ⇒ Object
- #policy_delete(policy_id) ⇒ Object
- #report_download(scan_id, file_id) ⇒ Object
- #scan_create(uuid, name, description, targets) ⇒ Object
- #scan_details(scan_id) ⇒ Object
- #scan_export(scan_id, format) ⇒ Object
- #scan_export_status(scan_id, file_id) ⇒ Object
- #scan_launch(scan_id) ⇒ Object
- #scan_list ⇒ Object
- #scan_pause(scan_id) ⇒ Object
- #scan_resume(scan_id) ⇒ Object
- #scan_stop(scan_id) ⇒ Object
- #server_properties ⇒ Object
- #server_status ⇒ Object
- #user_add(username, password, permissions, type) ⇒ Object
- #user_chpasswd(user_id, password) ⇒ Object
- #user_delete(user_id) ⇒ Object
- #user_logout ⇒ Object
- #x_cookie ⇒ Object
Constructor Details
#initialize(host, username = nil, password = nil, ssl_option = nil) {|@connection| ... } ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nessus/xmlrpc.rb', line 17 def initialize(host, username = nil, password = nil, ssl_option = nil) uri = URI.parse(host) @connection = Net::HTTP.new(uri.host, uri.port) @connection.use_ssl = true if ssl_option == "ssl_verify" @connection.verify_mode = OpenSSL::SSL::VERIFY_PEER else @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE end yield @connection if block_given? authenticate(username, password) if username && password end |
Instance Method Details
#authenticate(username, password) ⇒ Object Also known as: login
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/nessus/xmlrpc.rb', line 31 def authenticate(username, password) payload = { :username => username, :password => password, :json => 1 } res = http_post(:uri=>"/session", :data=>payload) if res['token'] @token = "token=#{res['token']}" return true else false end end |
#authenticated ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/nessus/xmlrpc.rb', line 52 def authenticated if (@token && @token.include?('token=')) return true else return false end end |
#get_server_properties ⇒ Object
60 61 62 |
# File 'lib/nessus/xmlrpc.rb', line 60 def get_server_properties http_get(:uri=>"/server/properties", :fields=>) end |
#host_detail(scan_id, host_id) ⇒ Object
204 205 206 |
# File 'lib/nessus/xmlrpc.rb', line 204 def host_detail(scan_id, host_id) res = http_get(:uri=>"/scans/#{scan_id}/hosts/#{host_id}", :fields=>) end |
#is_admin ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/nessus/xmlrpc.rb', line 126 def is_admin res = http_get(:uri=>"/session", :fields=>) if res['permissions'] == 128 return true else return false end end |
#list_families ⇒ Object
110 111 112 |
# File 'lib/nessus/xmlrpc.rb', line 110 def list_families http_get(:uri=>"/plugins/families", :fields=>) end |
#list_folders ⇒ Object
102 103 104 |
# File 'lib/nessus/xmlrpc.rb', line 102 def list_folders http_get(:uri=>"/folders", :fields=>) end |
#list_plugins(family_id) ⇒ Object
114 115 116 |
# File 'lib/nessus/xmlrpc.rb', line 114 def list_plugins(family_id) http_get(:uri=>"/plugins/families/#{family_id}", :fields=>) end |
#list_policies ⇒ Object
94 95 96 |
# File 'lib/nessus/xmlrpc.rb', line 94 def list_policies http_get(:uri=>"/policies", :fields=>) end |
#list_scanners ⇒ Object
106 107 108 |
# File 'lib/nessus/xmlrpc.rb', line 106 def list_scanners http_get(:uri=>"/scanners", :fields=>) end |
#list_template(type) ⇒ Object
118 119 120 |
# File 'lib/nessus/xmlrpc.rb', line 118 def list_template(type) res = http_get(:uri=>"/editor/#{type}/templates", :fields=>) end |
#list_users ⇒ Object
98 99 100 |
# File 'lib/nessus/xmlrpc.rb', line 98 def list_users http_get(:uri=>"/users", :fields=>) end |
#plugin_details(plugin_id) ⇒ Object
122 123 124 |
# File 'lib/nessus/xmlrpc.rb', line 122 def plugin_details(plugin_id) http_get(:uri=>"/plugins/plugin/#{plugin_id}", :fields=>) end |
#policy_delete(policy_id) ⇒ Object
199 200 201 202 |
# File 'lib/nessus/xmlrpc.rb', line 199 def policy_delete(policy_id) res = http_delete(:uri=>"/policies/#{policy_id}", :fields=>) return res.code end |
#report_download(scan_id, file_id) ⇒ Object
208 209 210 |
# File 'lib/nessus/xmlrpc.rb', line 208 def report_download(scan_id, file_id) res = http_get(:uri=>"/scans/#{scan_id}/export/#{file_id}/download", :raw_content=> true, :fields=>) end |
#scan_create(uuid, name, description, targets) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/nessus/xmlrpc.rb', line 139 def scan_create(uuid, name, description, targets) payload = { :uuid => uuid, :settings => { :name => name, :description => description, :text_targets => targets }, :json => 1 }.to_json http_post(:uri=>"/scans", :body=>payload, :fields=>, :ctype=>'application/json') end |
#scan_details(scan_id) ⇒ Object
164 165 166 |
# File 'lib/nessus/xmlrpc.rb', line 164 def scan_details(scan_id) http_get(:uri=>"/scans/#{scan_id}", :fields=>) end |
#scan_export(scan_id, format) ⇒ Object
180 181 182 183 184 185 |
# File 'lib/nessus/xmlrpc.rb', line 180 def scan_export(scan_id, format) payload = { :format => format }.to_json http_post(:uri=>"/scans/#{scan_id}/export", :body=>payload, :ctype=>'application/json', :fields=>) end |
#scan_export_status(scan_id, file_id) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/nessus/xmlrpc.rb', line 187 def scan_export_status(scan_id, file_id) request = Net::HTTP::Get.new("/scans/#{scan_id}/export/#{file_id}/status") request.add_field("X-Cookie", @token) res = @connection.request(request) if res.code == "200" return "ready" else res = JSON.parse(res.body) return res end end |
#scan_launch(scan_id) ⇒ Object
152 153 154 |
# File 'lib/nessus/xmlrpc.rb', line 152 def scan_launch(scan_id) http_post(:uri=>"/scans/#{scan_id}/launch", :fields=>) end |
#scan_list ⇒ Object
160 161 162 |
# File 'lib/nessus/xmlrpc.rb', line 160 def scan_list http_get(:uri=>"/scans", :fields=>) end |
#scan_pause(scan_id) ⇒ Object
168 169 170 |
# File 'lib/nessus/xmlrpc.rb', line 168 def scan_pause(scan_id) http_post(:uri=>"/scans/#{scan_id}/pause", :fields=>) end |
#scan_resume(scan_id) ⇒ Object
172 173 174 |
# File 'lib/nessus/xmlrpc.rb', line 172 def scan_resume(scan_id) http_post(:uri=>"/scans/#{scan_id}/resume", :fields=>) end |
#scan_stop(scan_id) ⇒ Object
176 177 178 |
# File 'lib/nessus/xmlrpc.rb', line 176 def scan_stop(scan_id) http_post(:uri=>"/scans/#{scan_id}/stop", :fields=>) end |
#server_properties ⇒ Object
135 136 137 |
# File 'lib/nessus/xmlrpc.rb', line 135 def server_properties http_get(:uri=>"/server/properties", :fields=>) end |
#server_status ⇒ Object
156 157 158 |
# File 'lib/nessus/xmlrpc.rb', line 156 def server_status http_get(:uri=>"/server/status", :fields=>) end |
#user_add(username, password, permissions, type) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nessus/xmlrpc.rb', line 64 def user_add(username, password, , type) payload = { :username => username, :password => password, :permissions => , :type => type, :json => 1 } http_post(:uri=>"/users", :fields=>, :data=>payload) end |
#user_chpasswd(user_id, password) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/nessus/xmlrpc.rb', line 80 def user_chpasswd(user_id, password) payload = { :password => password, :json => 1 } res = http_put(:uri=>"/users/#{user_id}/chpasswd", :data=>payload, :fields=>) return res.code end |
#user_delete(user_id) ⇒ Object
75 76 77 78 |
# File 'lib/nessus/xmlrpc.rb', line 75 def user_delete(user_id) res = http_delete(:uri=>"/users/#{user_id}", :fields=>) return res.code end |
#user_logout ⇒ Object
89 90 91 92 |
# File 'lib/nessus/xmlrpc.rb', line 89 def user_logout res = http_delete(:uri=>"/session", :fields=>) return res.code end |
#x_cookie ⇒ Object
46 47 48 |
# File 'lib/nessus/xmlrpc.rb', line 46 def {'X-Cookie'=>@token} end |