-
Notifications
You must be signed in to change notification settings - Fork 17
/
generic_cookie_grabber.rb
executable file
·89 lines (66 loc) · 2.44 KB
/
generic_cookie_grabber.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
#!/usr/bin/env ruby
# == Author
# Author:: Rory McCune
# Copyright:: Copyright (c) 2014 Rory Mccune
# License:: GPLv3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#Code to get the session tokens after a two stage login
require 'mechanize'
output_file = File.open('tokens','a+')
for i in 1..500
agent = Mechanize.new
#Set proxy to burp for troubleshooting
#agent.set_proxy 'localhost', 8080
#agent.idle_timeout = 1
#agent.keep_alive=false
#Turn off SSL verify when using burp
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
#get the pre-login page
page = agent.get('http://127.0.0.1:3000/login/start')
login_form = page.forms[0]
#Fill in your customer ID here change field name as necessary
login_form.field('username').value = 'admin'
page2 = login_form.click_button
login_form2 = page2.forms[0]
#Here's our sample password
password = ['b','s','i','d','e','s']
#Here for our example we can work out what characters to enter
#based on the numbers from the label elements
c1 = page2.labels[0].to_s[/\d/]
c2 = page2.labels[1].to_s[/\d/]
c3 = page2.labels[2].to_s[/\d/]
#snippet to remove one from each element to match up with the array numbering
c1 = c1.to_i - 1
c2 = c2.to_i - 1
c3 = c3.to_i - 1
#Fill in the elements of the password form with our characters
login_form2.field('char1').value = password[c1]
login_form2.field('char2').value = password[c2]
login_form2.field('char3').value = password[c3]
page3 = login_form2.click_button
#Example of looking for a token in the body of the response
if page3.body[/[a-z]{50}/]
output_file.puts page3.body[/[a-z]{50}/]
else
puts "didn't get a token"
end
#Example of getting the value from a cookie on the page
agent.cookies.each do |cookie|
if cookie.name =~ /<cookie_We_want>/
output_file.puts cookie.value
puts 'captured a cookie'
end
end
end