Skip to content

Commit e5fd9e7

Browse files
committed
clean plugin/nessus.rb implement additional APIs
1 parent c20a812 commit e5fd9e7

File tree

2 files changed

+978
-1090
lines changed

2 files changed

+978
-1090
lines changed

lib/nessus/nessus-xmlrpc.rb

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def authenticate(username, password)
2525
payload = {
2626
:username => username,
2727
:password => password,
28-
:json => 1,
28+
:json => 1
2929
}
30-
resp = http_post(:uri=>'/session', :data=>payload)
31-
@token = "token=#{resp['token']}"
30+
res = http_post(:uri=>"/session", :data=>payload)
31+
@token = "token=#{res['token']}"
3232
true
3333
end
3434

@@ -47,7 +47,7 @@ def authenticated
4747
end
4848

4949
def get_server_properties
50-
http_get(:uri=>'/server/properties', :fields=>x_cookie)
50+
http_get(:uri=>"/server/properties", :fields=>x_cookie)
5151
end
5252

5353
def user_add(username, password, permissions, type)
@@ -56,9 +56,9 @@ def user_add(username, password, permissions, type)
5656
:password => password,
5757
:permissions => permissions,
5858
:type => type,
59-
:json => 1,
59+
:json => 1
6060
}
61-
http_post(:uri=>'/users', :fields=>x_cookie, :data=>payload)
61+
http_post(:uri=>"/users", :fields=>x_cookie, :data=>payload)
6262
end
6363

6464
def user_delete(user_id)
@@ -69,47 +69,51 @@ def user_delete(user_id)
6969
def user_chpasswd(user_id, password)
7070
payload = {
7171
:password => password,
72-
:json => 1,
72+
:json => 1
7373
}
7474
res = http_put(:uri=>"/users/#{user_id}/chpasswd", :data=>payload, :fields=>x_cookie)
7575
return res.code
7676
end
7777

7878
def user_logout
79-
res = http_delete(:uri=>'/session', :fields=>x_cookie)
79+
res = http_delete(:uri=>"/session", :fields=>x_cookie)
8080
return res.code
8181
end
8282

8383
def list_policies
84-
http_get(:uri=>'/policies', :fields=>x_cookie)
84+
http_get(:uri=>"/policies", :fields=>x_cookie)
8585
end
8686

8787
def list_users
88-
http_get(:uri=>'/users', :fields=>x_cookie)
88+
http_get(:uri=>"/users", :fields=>x_cookie)
8989
end
9090

9191
def list_folders
92-
http_get(:uri=>'/folders', :fields=>x_cookie)
92+
http_get(:uri=>"/folders", :fields=>x_cookie)
9393
end
9494

9595
def list_scanners
96-
http_get(:uri=>'/scanners', :fields=>x_cookie)
96+
http_get(:uri=>"/scanners", :fields=>x_cookie)
9797
end
9898

9999
def list_families
100-
http_get(:uri=>'/plugins/families', :fields=>x_cookie)
100+
http_get(:uri=>"/plugins/families", :fields=>x_cookie)
101101
end
102102

103103
def list_plugins(family_id)
104104
http_get(:uri=>"/plugins/families/#{family_id}", :fields=>x_cookie)
105105
end
106106

107+
def list_template(type)
108+
res = http_get(:uri=>"/editor/#{type}/templates", :fields=>x_cookie)
109+
end
110+
107111
def plugin_details(plugin_id)
108112
http_get(:uri=>"/plugins/plugin/#{plugin_id}", :fields=>x_cookie)
109113
end
110114

111115
def is_admin
112-
res = http_get(:uri=>'/session', :fields=>x_cookie)
116+
res = http_get(:uri=>"/session", :fields=>x_cookie)
113117
if res['permissions'] == 128
114118
return true
115119
else
@@ -118,7 +122,7 @@ def is_admin
118122
end
119123

120124
def server_properties
121-
http_get(:uri=>'/server/properties', :fields=>x_cookie)
125+
http_get(:uri=>"/server/properties", :fields=>x_cookie)
122126
end
123127

124128
def scan_create(uuid, name, description, targets)
@@ -131,27 +135,27 @@ def scan_create(uuid, name, description, targets)
131135
},
132136
:json => 1
133137
}.to_json
134-
http_post(:uri=>'/scans', :body=>payload, :fields=>x_cookie, :ctype=>'application/json')
138+
http_post(:uri=>"/scans", :body=>payload, :fields=>x_cookie, :ctype=>'application/json')
135139
end
136140

137141
def scan_launch(scan_id)
138142
http_post(:uri=>"/scans/#{scan_id}/launch", :fields=>x_cookie)
139143
end
140144

141145
def server_status
142-
http_get(:uri=>'/server/status', :fields=>x_cookie)
146+
http_get(:uri=>"/server/status", :fields=>x_cookie)
143147
end
144148

145149
def scan_list
146-
http_get(:uri=>'/scans', :fields=>x_cookie)
150+
http_get(:uri=>"/scans", :fields=>x_cookie)
147151
end
148152

149153
def scan_details(scan_id)
150154
http_get(:uri=>"/scans/#{scan_id}", :fields=>x_cookie)
151155
end
152156

153157
def scan_pause(scan_id)
154-
http_get(:uri=>"/scans/#{scan_id}/pause", :fields=>x_cookie)
158+
http_post(:uri=>"/scans/#{scan_id}/pause", :fields=>x_cookie)
155159
end
156160

157161
def scan_resume(scan_id)
@@ -172,12 +176,12 @@ def scan_export(scan_id, format)
172176
def scan_export_status(scan_id, file_id)
173177
request = Net::HTTP::Get.new("/scans/#{scan_id}/export/#{file_id}/status")
174178
request.add_field("X-Cookie", @token)
175-
resp = @connection.request(request)
176-
if resp.code == "200"
179+
res = @connection.request(request)
180+
if res.code == "200"
177181
return "ready"
178182
else
179-
resp = JSON.parse(resp.body)
180-
return resp
183+
res = JSON.parse(resp.body)
184+
return res
181185
end
182186
end
183187

@@ -186,35 +190,23 @@ def policy_delete(policy_id)
186190
return res.code
187191
end
188192

189-
def report_list_hash
190-
raise NotImplementedError
191-
end
192-
193-
def scan_list_hash
194-
raise NotImplementedError
195-
end
196-
197-
def report_host_ports
198-
raise NotImplementedError
193+
def host_detail(scan_id, host_id)
194+
res = http_get(:uri=>"/scans/#{scan_id}/hosts/#{host_id}", :fields=>x_cookie)
199195
end
200196

201-
def scan_new
197+
def report_list
202198
raise NotImplementedError
203199
end
204200

205-
def report_file_download
201+
def report_del
206202
raise NotImplementedError
207203
end
208204

209-
def template_list_hash
210-
raise NotImplementedError
211-
end
212-
213-
def report_host
205+
def report_host_ports
214206
raise NotImplementedError
215207
end
216208

217-
def report_host_port_details
209+
def report_download
218210
raise NotImplementedError
219211
end
220212

0 commit comments

Comments
 (0)