erran/nessus.rb — pull request #1 by mwulftange (2014-06-14 19:19:56+00:00)
Title: Fix retry-on-forbidden

There are some issues with your proposal that are fixed with this merge request:

* `login` and `password` need to be stored in instance variables, otherwise they are not present for re-authentication.
* 401 and 403 responses need to be handled.
* The merge of `connection.headers` and `headers` in `get` won’t work as `headers` will be handled as if it were passed to `get` after `retry` and consequently the old cookie would overwrite the new cookie; the merges are removed as `post` doesn’t do that either.

Here’s a run with re-authentication:

$ ruby retry-on-forbidden-test.rb
I, [2014-06-14T20:43:37.943930 #90184] INFO -- : post https://172.16.57.152:8834/login
D, [2014-06-14T20:43:37.944110 #90184] DEBUG -- request: User-Agent: "Nessus.rb v0.1.0.beta.18"
Content-Type: "application/x-www-form-urlencoded"
I, [2014-06-14T20:43:37.944429 #90184] INFO -- Status: 200
D, [2014-06-14T20:43:37.944567 #90184] DEBUG -- response: date: "Sat, 14 Jun 2014 18:43:37 GMT"
server: "NessusWWW"
connection: "close"
expires: "Sat, 14 Jun 2014 18:43:37 GMT, 0"
content-length: "385"
content-type: "text/xml"
x-frame-options: "DENY"
set-cookie: "token=a79319aae7b5f6b44bf980ecd4b3326ef1e3193ee714875c; path=/; expires=Sun, 17-Jan-2038 13:17:07 GMT; secure; HttpOnly"
cache-control: ""
pragma: ""
I, [2014-06-14T20:45:08.003461 #90184] INFO -- : get https://172.16.57.152:8834/scan/list?json=1
D, [2014-06-14T20:45:08.003574 #90184] DEBUG -- request: User-Agent: "Nessus.rb v0.1.0.beta.18"
Cookie: "token=a79319aae7b5f6b44bf980ecd4b3326ef1e3193ee714875c"
I, [2014-06-14T20:45:08.003869 #90184] INFO -- Status: 403
D, [2014-06-14T20:45:08.003974 #90184] DEBUG -- response: date: "Sat, 14 Jun 2014 18:45:07 GMT"
server: "NessusWWW"
connection: "close"
expires: "Sat, 14 Jun 2014 18:45:07 GMT, 0"
content-length: "61"
content-type: "text/html"
x-frame-options: "DENY"
cache-control: ""
pragma: ""
I, [2014-06-14T20:45:09.116815 #90184] INFO -- : post https://172.16.57.152:8834/login
D, [2014-06-14T20:45:09.116924 #90184] DEBUG -- request: User-Agent: "Nessus.rb v0.1.0.beta.18"
Cookie: "token=a79319aae7b5f6b44bf980ecd4b3326ef1e3193ee714875c"
Content-Type: "application/x-www-form-urlencoded"
I, [2014-06-14T20:45:09.120852 #90184] INFO -- Status: 200
D, [2014-06-14T20:45:09.120990 #90184] DEBUG -- response: date: "Sat, 14 Jun 2014 18:45:09 GMT"
server: "NessusWWW"
connection: "close"
expires: "Sat, 14 Jun 2014 18:45:09 GMT, 0"
content-length: "385"
content-type: "text/xml"
x-frame-options: "DENY"
set-cookie: "token=fb14c575583712af992cbcff715e36d1146b25a6ed7c9bac; path=/; expires=Sun, 17-Jan-2038 13:17:07 GMT; secure; HttpOnly"
cache-control: ""
pragma: ""
I, [2014-06-14T20:45:09.176432 #90184] INFO -- : get https://172.16.57.152:8834/scan/list?json=1
D, [2014-06-14T20:45:09.176556 #90184] DEBUG -- request: User-Agent: "Nessus.rb v0.1.0.beta.18"
Cookie: "token=fb14c575583712af992cbcff715e36d1146b25a6ed7c9bac"
I, [2014-06-14T20:45:09.176850 #90184] INFO -- Status: 200
D, [2014-06-14T20:45:09.176954 #90184] DEBUG -- response: date: "Sat, 14 Jun 2014 18:45:09 GMT"
server: "NessusWWW"
connection: "close"
expires: "Sat, 14 Jun 2014 18:45:09 GMT, 0"
content-length: "103"
content-type: "text/html"
x-frame-options: "DENY"
cache-control: ""
pragma: ""
{"policies"=>{"policies"=>{"policy"=>[]}}, "scans"=>{"scanList"=>{"scan"=>[]}}, "templates"=>{}}