ronin-web 1.0.1 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +3 -2
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +5 -0
  5. data/ChangeLog.md +46 -1
  6. data/Gemfile +25 -12
  7. data/README.md +486 -39
  8. data/Rakefile +9 -0
  9. data/data/completions/ronin-web +203 -0
  10. data/gemspec.yml +18 -5
  11. data/lib/ronin/web/cli/browser_options.rb +92 -0
  12. data/lib/ronin/web/cli/browser_shell.rb +448 -0
  13. data/lib/ronin/web/cli/command.rb +1 -1
  14. data/lib/ronin/web/cli/commands/browser.rb +373 -0
  15. data/lib/ronin/web/cli/commands/completion.rb +63 -0
  16. data/lib/ronin/web/cli/commands/diff.rb +60 -8
  17. data/lib/ronin/web/cli/commands/html.rb +21 -33
  18. data/lib/ronin/web/cli/commands/irb.rb +1 -1
  19. data/lib/ronin/web/cli/commands/new/{webapp.rb → app.rb} +8 -8
  20. data/lib/ronin/web/cli/commands/new/nokogiri.rb +4 -4
  21. data/lib/ronin/web/cli/commands/new/server.rb +1 -1
  22. data/lib/ronin/web/cli/commands/new/spider.rb +1 -1
  23. data/lib/ronin/web/cli/commands/new.rb +5 -3
  24. data/lib/ronin/web/cli/commands/reverse_proxy.rb +1 -1
  25. data/lib/ronin/web/cli/commands/screenshot.rb +186 -0
  26. data/lib/ronin/web/cli/commands/server.rb +3 -3
  27. data/lib/ronin/web/cli/commands/session_cookie.rb +265 -0
  28. data/lib/ronin/web/cli/commands/spider.rb +60 -466
  29. data/lib/ronin/web/cli/commands/user_agent.rb +177 -0
  30. data/lib/ronin/web/cli/commands/vulns.rb +463 -0
  31. data/lib/ronin/web/cli/commands/wordlist.rb +484 -0
  32. data/lib/ronin/web/cli/commands/xml.rb +149 -0
  33. data/lib/ronin/web/cli/js_shell.rb +69 -0
  34. data/lib/ronin/web/cli/ruby_shell.rb +1 -1
  35. data/lib/ronin/web/cli/spider_options.rb +919 -0
  36. data/lib/ronin/web/cli.rb +3 -1
  37. data/lib/ronin/web/html.rb +1 -1
  38. data/lib/ronin/web/root.rb +1 -1
  39. data/lib/ronin/web/version.rb +2 -2
  40. data/lib/ronin/web/xml.rb +1 -1
  41. data/lib/ronin/web.rb +4 -364
  42. data/man/ronin-web-browser.1 +92 -0
  43. data/man/ronin-web-browser.1.md +96 -0
  44. data/man/ronin-web-completion.1 +76 -0
  45. data/man/ronin-web-completion.1.md +78 -0
  46. data/man/ronin-web-diff.1 +14 -21
  47. data/man/ronin-web-diff.1.md +13 -6
  48. data/man/ronin-web-html.1 +30 -46
  49. data/man/ronin-web-html.1.md +27 -17
  50. data/man/ronin-web-irb.1 +9 -16
  51. data/man/ronin-web-irb.1.md +6 -2
  52. data/man/ronin-web-new-app.1.md +39 -0
  53. data/man/ronin-web-new-nokogiri.1 +9 -20
  54. data/man/ronin-web-new-nokogiri.1.md +5 -5
  55. data/man/ronin-web-new-server.1 +11 -23
  56. data/man/ronin-web-new-server.1.md +5 -5
  57. data/man/ronin-web-new-spider.1 +44 -88
  58. data/man/ronin-web-new-spider.1.md +37 -37
  59. data/man/ronin-web-new.1 +18 -30
  60. data/man/ronin-web-new.1.md +15 -11
  61. data/man/ronin-web-reverse-proxy.1 +33 -38
  62. data/man/ronin-web-reverse-proxy.1.md +20 -14
  63. data/man/ronin-web-screenshot.1 +56 -0
  64. data/man/ronin-web-screenshot.1.md +56 -0
  65. data/man/ronin-web-server.1 +15 -29
  66. data/man/ronin-web-server.1.md +13 -9
  67. data/man/ronin-web-session-cookie.1 +38 -0
  68. data/man/ronin-web-session-cookie.1.md +41 -0
  69. data/man/ronin-web-spider.1 +121 -130
  70. data/man/ronin-web-spider.1.md +115 -66
  71. data/man/ronin-web-user-agent.1 +44 -0
  72. data/man/ronin-web-user-agent.1.md +46 -0
  73. data/man/ronin-web-vulns.1 +175 -0
  74. data/man/ronin-web-vulns.1.md +177 -0
  75. data/man/ronin-web-wordlist.1 +258 -0
  76. data/man/ronin-web-wordlist.1.md +263 -0
  77. data/man/ronin-web-xml.1 +43 -0
  78. data/man/ronin-web-xml.1.md +46 -0
  79. data/man/ronin-web.1 +67 -18
  80. data/man/ronin-web.1.md +55 -4
  81. data/scripts/setup +58 -0
  82. metadata +122 -31
  83. data/lib/ronin/web/mechanize.rb +0 -82
  84. data/man/ronin-web-new-webapp.1.md +0 -39
  85. /data/data/new/{webapp → app}/.gitignore +0 -0
  86. /data/data/new/{webapp → app}/.ruby-version.erb +0 -0
  87. /data/data/new/{webapp → app}/Dockerfile.erb +0 -0
  88. /data/data/new/{webapp → app}/Gemfile +0 -0
  89. /data/data/new/{webapp → app}/app.rb.erb +0 -0
  90. /data/data/new/{webapp → app}/config.ru +0 -0
  91. /data/data/new/{webapp → app}/docker-compose.yml.erb +0 -0
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
- # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ # Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
4
4
  #
5
5
  # ronin-web is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -27,11 +27,11 @@ module Ronin
27
27
  module Commands
28
28
  class New < Command
29
29
  #
30
- # Generate a new ronin-web-server based webapp.
30
+ # Generate a new ronin-web-server based web app.
31
31
  #
32
32
  # ## Usage
33
33
  #
34
- # ronin-web new webapp [options] DIR
34
+ # ronin-web new app [options] DIR
35
35
  #
36
36
  # ## Options
37
37
  #
@@ -45,11 +45,11 @@ module Ronin
45
45
  #
46
46
  # DIR The directory to create
47
47
  #
48
- class Webapp < Command
48
+ class App < Command
49
49
 
50
50
  include Core::CLI::Generator
51
51
 
52
- template_dir File.join(ROOT,'data','new','webapp')
52
+ template_dir File.join(ROOT,'data','new','app')
53
53
 
54
54
  usage '[options] DIR'
55
55
 
@@ -75,12 +75,12 @@ module Ronin
75
75
  argument :dir, required: true,
76
76
  desc: 'The directory to create'
77
77
 
78
- description 'Generate a new ronin-web-server based webapp'
78
+ description 'Generate a new ronin-web-server based app'
79
79
 
80
- man_page 'ronin-web-new-webapp.1'
80
+ man_page 'ronin-web-new-app.1'
81
81
 
82
82
  #
83
- # Runs the `ronin-web new webapp` command.
83
+ # Runs the `ronin-web new app` command.
84
84
  #
85
85
  # @param [String] path
86
86
  # The path to the new project directory to create.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
- # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ # Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
4
4
  #
5
5
  # ronin-web is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ module Ronin
27
27
  module Commands
28
28
  class New < Command
29
29
  #
30
- # Generates a new nokogiri Ruby script.
30
+ # Generates a new nokogiri Ruby script for parsing HTML/XML.
31
31
  #
32
32
  # ## Usage
33
33
  #
@@ -58,9 +58,9 @@ module Ronin
58
58
  desc: 'Optional URL for the script'
59
59
 
60
60
  argument :file, required: true,
61
- desc: 'The file to create'
61
+ desc: 'The file to create'
62
62
 
63
- description 'Generates a new nokogiri Ruby script'
63
+ description 'Generates a new nokogiri Ruby script for parsing HTML/XML'
64
64
 
65
65
  man_page 'ronin-web-new-nokogiri.1'
66
66
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
- # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ # Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
4
4
  #
5
5
  # ronin-web is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
- # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ # Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
4
4
  #
5
5
  # ronin-web is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
- # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ # Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
4
4
  #
5
5
  # ronin-web is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@ module Ronin
28
28
  #
29
29
  # ## Usage
30
30
  #
31
- # ronin-web new {nokogiri | server | spider | webapp}
31
+ # ronin-web new {nokogiri | server | app | spider}
32
32
  #
33
33
  # ## Options
34
34
  #
@@ -42,11 +42,11 @@ module Ronin
42
42
  #
43
43
  # ## Commands
44
44
  #
45
+ # app
45
46
  # help
46
47
  # nokogiri
47
48
  # server
48
49
  # spider
49
- # webapp
50
50
  #
51
51
  class New < Command
52
52
 
@@ -55,6 +55,8 @@ module Ronin
55
55
  namespace: "#{self}"
56
56
  )
57
57
 
58
+ description 'Creates new projects or scripts'
59
+
58
60
  man_page 'ronin-web-new.1'
59
61
 
60
62
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web - A collection of useful web helper methods and commands.
4
4
  #
5
- # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU General Public License as published by
@@ -0,0 +1,186 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-web - A collection of useful web helper methods and commands.
4
+ #
5
+ # Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-web is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-web is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ronin-web. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/web/cli/command'
22
+ require 'ronin/web/cli/browser_options'
23
+
24
+ require 'ronin/core/cli/logging'
25
+
26
+ module Ronin
27
+ module Web
28
+ class CLI
29
+ module Commands
30
+ #
31
+ # Screenshots one or more URLs.
32
+ #
33
+ # ## Usage
34
+ #
35
+ # ronin-web screenshot [options] {URL [...] | --file FILE}
36
+ #
37
+ # ## Options
38
+ #
39
+ # -B, --browser NAME|PATH The browser name or path to execute
40
+ # -W, --width WIDTH Sets the width of the browser viewport (Default: 1024)
41
+ # -H, --height HEIGHT Sets the height of the browser viewport (Default: 768)
42
+ # -f, --file FILE Input file to read URLs from
43
+ # -F, --format png|jpg Screenshot image format (Default: png)
44
+ # -d, --directory DIR Directory to save images to (Default: /data/home/postmodern/code/ronin-rb/ronin-web)
45
+ # --full Screenshots the full page
46
+ # -C, --css-path CSSPath The CSSpath selector to screenshot
47
+ # -h, --help Print help information
48
+ #
49
+ # ## Arguments
50
+ #
51
+ # URL ... The URL visit and screenshot
52
+ #
53
+ class Screenshot < Command
54
+
55
+ include Core::CLI::Logging
56
+ include BrowserOptions
57
+
58
+ usage '[options] {URL [...] | --file FILE}'
59
+
60
+ option :file, short: '-f',
61
+ value: {
62
+ type: String,
63
+ usage: 'FILE'
64
+ },
65
+ desc: 'Input file to read URLs from'
66
+
67
+ option :format, short: '-F',
68
+ value: {
69
+ type: [:png, :jpg],
70
+ default: :png
71
+ },
72
+ desc: 'Screenshot image format'
73
+
74
+ option :directory, short: '-d',
75
+ value: {
76
+ type: String,
77
+ usage: 'DIR',
78
+ default: Dir.pwd
79
+ },
80
+ desc: 'Directory to save images to'
81
+
82
+ option :full, desc: 'Screenshots the full page'
83
+
84
+ option :css_path, short: '-C',
85
+ value: {
86
+ type: String,
87
+ usage: 'CSSPath'
88
+ },
89
+ desc: 'The CSSpath selector to screenshot'
90
+
91
+ argument :url, required: true,
92
+ repeats: true,
93
+ desc: 'The URL visit and screenshot'
94
+
95
+ description 'Screenshots one or more URLs'
96
+
97
+ man_page 'ronin-web-screenshot.1'
98
+
99
+ #
100
+ # Runs the `ronin-web screenshot` command.
101
+ #
102
+ # @param [Array<String>] urls
103
+ # The URLs to screenshot.
104
+ #
105
+ def run(*urls)
106
+ if options[:file]
107
+ File.open(options[:file]) do |file|
108
+ file.each_line(chomp: true) do |url|
109
+ process_url(url)
110
+ end
111
+ end
112
+ elsif !urls.empty?
113
+ urls.each do |url|
114
+ process_url(url)
115
+ end
116
+ else
117
+ print_error "must specify --file or URL arguments"
118
+ exit(-1)
119
+ end
120
+ end
121
+
122
+ #
123
+ # Visits and screenshots a URL.
124
+ #
125
+ # @param [String] url
126
+ # The URL to screenshot.
127
+ #
128
+ def process_url(url)
129
+ begin
130
+ browser.goto(url)
131
+ rescue Ferrum::StatusError
132
+ print_error "failed to request URL: #{url}"
133
+ end
134
+
135
+ image_path = image_path_for(url)
136
+ FileUtils.mkdir_p(File.dirname(image_path))
137
+
138
+ log_info "Screenshotting #{url} to #{image_path} ..."
139
+ browser.screenshot(
140
+ path: image_path,
141
+ format: options[:format],
142
+ full: options[:full],
143
+ selector: options[:css_path]
144
+ )
145
+ end
146
+
147
+ #
148
+ # Parses a URL.
149
+ #
150
+ # @param [String] url
151
+ # The URL string to parse.
152
+ #
153
+ # @return [URI::HTTP, URI::HTTPS]
154
+ # The parsed URL.
155
+ #
156
+ def parse_url(url)
157
+ URI.parse(url)
158
+ rescue URI::InvalidURI
159
+ print_error "invalid URI: #{url}"
160
+ exit(1)
161
+ end
162
+
163
+ #
164
+ # Generates the image path for a given URL.
165
+ #
166
+ # @param [String] url
167
+ # The given URL.
168
+ #
169
+ # @return [String]
170
+ # The relative image path that represents the URL.
171
+ #
172
+ def image_path_for(url)
173
+ uri = parse_url(url)
174
+
175
+ path = File.join(options[:directory],uri.host,uri.request_uri)
176
+ path << 'index' if path.end_with?('/')
177
+ path << ".#{options[:format]}"
178
+
179
+ return path
180
+ end
181
+
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-web - A collection of useful web helper methods and commands.
4
4
  #
5
- # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-web is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU General Public License as published by
@@ -58,7 +58,7 @@ module Ronin
58
58
  default: 'localhost'
59
59
  },
60
60
  desc: 'Host name or IP to bind to' do |host|
61
- App.host = host
61
+ App.bind = host
62
62
  end
63
63
 
64
64
  option :port, short: '-p',
@@ -144,7 +144,7 @@ module Ronin
144
144
  end
145
145
  end
146
146
 
147
- log_info "Starting web server listening on #{App.host}:#{App.port} ..."
147
+ log_info "Starting web server listening on #{App.bind}:#{App.port} ..."
148
148
  begin
149
149
  App.run!
150
150
  rescue Errno::EADDRINUSE => error
@@ -0,0 +1,265 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-web - A collection of useful web helper methods and commands.
4
+ #
5
+ # Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-web is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-web is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ronin-web. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/web/cli/command'
22
+ require 'ronin/web/session_cookie'
23
+ require 'ronin/support/network/http'
24
+ require 'ronin/support/encoding/hex'
25
+
26
+ require 'command_kit/options/verbose'
27
+ require 'command_kit/printing/indent'
28
+
29
+ module Ronin
30
+ module Web
31
+ class CLI
32
+ module Commands
33
+ #
34
+ # Parses and deserializes various session cookie formats.
35
+ #
36
+ # ## Usage
37
+ #
38
+ # ronin-web session_cookie [options] {URL | COOKIE}
39
+ #
40
+ # ## Options
41
+ #
42
+ # -v, --verbose Enables verbose output
43
+ # -F, --format ruby|json|yaml The format to print the session cookie params (Default: ruby)
44
+ # -h, --help Print help information
45
+ #
46
+ # ## Arguments
47
+ #
48
+ # URL | COOKIE The URL or the session cookie to parse
49
+ #
50
+ # @since 2.0.0
51
+ #
52
+ class SessionCookie < Command
53
+
54
+ include CommandKit::Options::Verbose
55
+ include CommandKit::Printing::Indent
56
+
57
+ usage '[options] {URL | COOKIE}'
58
+
59
+ option :format, short: '-F',
60
+ value: {
61
+ type: [:ruby, :json, :yaml],
62
+ default: :ruby
63
+ },
64
+ desc: 'The format to print the session cookie params'
65
+
66
+ argument :url_or_cookie, required: true,
67
+ usage: 'URL | COOKIE',
68
+ desc: 'The URL or the session cookie to parse'
69
+
70
+ description 'Parses and deserializes various session cookie formats'
71
+
72
+ examples [
73
+ '"rack.session=BAh7CEkiD3Nlc3Npb25faWQGOgZFVG86HVJhY2s6OlNlc3Npb246OlNlc3Npb25JZAY6D0BwdWJsaWNfaWRJIkUyYWJkZTdkM2I0YTMxNDE5OThiYmMyYTE0YjFmMTZlNTNlMWMzYWJlYzhiYzc4ZjVhMGFlMGUwODJmMjJlZGIxBjsARkkiCWNzcmYGOwBGSSIxNHY1TmRCMGRVaklXdjhzR3J1b2ZhM2xwNHQyVGp5ZHptckQycjJRWXpIZz0GOwBGSSINdHJhY2tpbmcGOwBGewZJIhRIVFRQX1VTRVJfQUdFTlQGOwBUSSItOTkxNzUyMWYzN2M4ODJkNDIyMzhmYmI5Yzg4MzFmMWVmNTAwNGQyYwY7AEY%3D--02184e43850f38a46c8f22ffb49f7f22be58e272"'
74
+ ]
75
+
76
+ man_page 'ronin-web-session-cookie.1'
77
+
78
+ #
79
+ # Runs the `ronin-web session-cookie` command.
80
+ #
81
+ # @param [String] arg
82
+ #
83
+ def run(arg)
84
+ session_cookie = if arg.start_with?('https://') ||
85
+ arg.start_with?('http://')
86
+ fetch_session_cookie(arg)
87
+ else
88
+ parse_session_cookie(arg)
89
+ end
90
+
91
+ if session_cookie
92
+ print_session_cookie(session_cookie)
93
+ else
94
+ print_error "no session cookie found"
95
+ exit(-1)
96
+ end
97
+ end
98
+
99
+ #
100
+ # Fetches the session cookie from the URL.
101
+ #
102
+ # @param [String] url
103
+ # The URL to request.
104
+ #
105
+ # @return [Ronin::Web::SessionCookie::Django, Ronin::Web::SessionCookie::JWT, Ronin::Web::SessionCookie::Rack, nil]
106
+ # The parses session cookie.
107
+ #
108
+ def fetch_session_cookie(url)
109
+ response = begin
110
+ Support::Network::HTTP.get(url)
111
+ rescue => error
112
+ print_error "failed to request URL (#{url.inspect}): #{error.message}"
113
+ exit(-1)
114
+ end
115
+
116
+ Web::SessionCookie.extract(response)
117
+ end
118
+
119
+ #
120
+ # Parses a session cookie.
121
+ #
122
+ # @param [String] cookie
123
+ # The session cookie to parse.
124
+ #
125
+ # @return [Ronin::Web::SessionCookie::Django, Ronin::Web::SessionCookie::JWT, Ronin::Web::SessionCookie::Rack, nil]
126
+ # The parses session cookie.
127
+ #
128
+ def parse_session_cookie(cookie)
129
+ Web::SessionCookie.parse(cookie)
130
+ end
131
+
132
+ #
133
+ # Prints a session cookie.
134
+ #
135
+ # @param [Ronin::Web::SessionCookie::Django, Ronin::Web::SessionCookie::JWT, Ronin::Web::SessionCookie::Rack] session_cookie
136
+ #
137
+ # @raise [NotImplementedError]
138
+ # The session cookie was not `Ronin::Web::SessionCookie::Django`,
139
+ # `Ronin::Web::SessionCookie::JWT`, or
140
+ # `Ronin::Web::SessionCookie::Rack`.
141
+ #
142
+ def print_session_cookie(session_cookie)
143
+ case session_cookie
144
+ when Web::SessionCookie::Django
145
+ print_django_session_cookie(session_cookie)
146
+ when Web::SessionCookie::JWT
147
+ print_jwt_session_cookie(session_cookie)
148
+ when Web::SessionCookie::Rack
149
+ print_rack_session_cookie(session_cookie)
150
+ else
151
+ raise(NotImplementedError,"cannot print session cookie: #{session_cookie.inspect}")
152
+ end
153
+ end
154
+
155
+ #
156
+ # Prints a Django session cookie.
157
+ #
158
+ # @param [Ronin::Web::SessionCookie::Django] session_cookie
159
+ #
160
+ def print_django_session_cookie(session_cookie)
161
+ if verbose?
162
+ puts "Type: Django"
163
+ puts "Params:"
164
+ puts
165
+
166
+ indent do
167
+ print_params(session_cookie.params)
168
+ end
169
+ puts
170
+
171
+ puts "Salt: #{session_cookie.salt}"
172
+ puts "HMAC: #{Support::Encoding::Hex.quote(session_cookie.hmac)}"
173
+ else
174
+ print_params(session_cookie.params)
175
+ end
176
+ end
177
+
178
+ #
179
+ # Prints a JWT session cookie.
180
+ #
181
+ # @param [Ronin::Web::SessionCookie::JWT] session_cookie
182
+ #
183
+ def print_jwt_session_cookie(session_cookie)
184
+ if verbose?
185
+ puts "Type: JWT"
186
+ puts "Header:"
187
+ puts
188
+
189
+ indent do
190
+ print_params(session_cookie.header)
191
+ end
192
+ puts
193
+
194
+ puts "Params:"
195
+ puts
196
+
197
+ indent do
198
+ print_params(session_cookie.params)
199
+ end
200
+ puts
201
+
202
+ puts "HMAC: #{Support::Encoding::Hex.quote(session_cookie.hmac)}"
203
+ else
204
+ print_params(session_cookie.params)
205
+ end
206
+ end
207
+
208
+ #
209
+ # Prints a Rack session cookie.
210
+ #
211
+ # @param [Ronin::Web::SessionCookie::Rack] session_cookie
212
+ #
213
+ def print_rack_session_cookie(session_cookie)
214
+ if verbose?
215
+ puts "Type: Rack"
216
+ puts "Params:"
217
+ puts
218
+
219
+ indent do
220
+ print_params(session_cookie.params)
221
+ end
222
+ puts
223
+
224
+ puts "HMAC: #{session_cookie.hmac}"
225
+ else
226
+ print_params(session_cookie.params)
227
+ end
228
+ end
229
+
230
+ #
231
+ # Prints the session cookie params as JSON.
232
+ #
233
+ # @param [Hash] params
234
+ # The params to print.
235
+ #
236
+ def print_params(params)
237
+ format_params(params).each_line do |line|
238
+ puts line
239
+ end
240
+ end
241
+
242
+ #
243
+ # Formats the params based on the `--format` option.
244
+ #
245
+ def format_params(params)
246
+ case options[:format]
247
+ when :ruby
248
+ require 'pp'
249
+ params.pretty_print_inspect
250
+ when :json
251
+ require 'json'
252
+ JSON.pretty_generate(params)
253
+ when :yaml
254
+ require 'yaml'
255
+ YAML.dump(params)
256
+ else
257
+ raise(NotImplementedError,"unsupported format: #{options[:format].inspect}")
258
+ end
259
+ end
260
+
261
+ end
262
+ end
263
+ end
264
+ end
265
+ end