ronin-support-web 0.1.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +4 -0
- data/.github/workflows/ruby.yml +47 -0
- data/.gitignore +13 -0
- data/.rspec +1 -0
- data/.rubocop.yml +19 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +165 -0
- data/ChangeLog.md +10 -0
- data/Gemfile +36 -0
- data/README.md +321 -0
- data/Rakefile +31 -0
- data/gemspec.yml +31 -0
- data/lib/ronin/support/web/agent/mixin.rb +361 -0
- data/lib/ronin/support/web/agent.rb +1386 -0
- data/lib/ronin/support/web/html/mixin.rb +115 -0
- data/lib/ronin/support/web/html.rb +116 -0
- data/lib/ronin/support/web/mixin.rb +40 -0
- data/lib/ronin/support/web/version.rb +28 -0
- data/lib/ronin/support/web/websocket/client.rb +129 -0
- data/lib/ronin/support/web/websocket/mixin.rb +888 -0
- data/lib/ronin/support/web/websocket/server.rb +212 -0
- data/lib/ronin/support/web/websocket/socket.rb +185 -0
- data/lib/ronin/support/web/websocket/url_methods.rb +91 -0
- data/lib/ronin/support/web/websocket.rb +360 -0
- data/lib/ronin/support/web/xml/mixin.rb +111 -0
- data/lib/ronin/support/web/xml.rb +110 -0
- data/lib/ronin/support/web.rb +43 -0
- data/ronin-support-web.gemspec +62 -0
- metadata +150 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-support-web - A web support library for ronin-rb.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-support-web is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-support-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 Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-support-web. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/support/web/html'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Support
|
25
|
+
module Web
|
26
|
+
module HTML
|
27
|
+
#
|
28
|
+
# Provides helper methods for working with HTML.
|
29
|
+
#
|
30
|
+
# @api public
|
31
|
+
#
|
32
|
+
module Mixin
|
33
|
+
#
|
34
|
+
# Parses the body of a document into a HTML document object.
|
35
|
+
#
|
36
|
+
# @param [String, IO] html
|
37
|
+
# The HTML to parse.
|
38
|
+
#
|
39
|
+
# @yield [doc]
|
40
|
+
# If a block is given, it will be passed the newly created document
|
41
|
+
# object.
|
42
|
+
#
|
43
|
+
# @yieldparam [Nokogiri::HTML::Document] doc
|
44
|
+
# The new HTML document object.
|
45
|
+
#
|
46
|
+
# @return [Nokogiri::HTML::Document]
|
47
|
+
# The new HTML document object.
|
48
|
+
#
|
49
|
+
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Document
|
50
|
+
# @see HTML.parse
|
51
|
+
#
|
52
|
+
def html_parse(html,&block)
|
53
|
+
HTML.parse(html,&block)
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Opens an HTML file.
|
58
|
+
#
|
59
|
+
# @param [String] path
|
60
|
+
# The path to the HTML file.
|
61
|
+
#
|
62
|
+
# @yield [doc]
|
63
|
+
# If a block is given, it will be passed the newly created document
|
64
|
+
# object.
|
65
|
+
#
|
66
|
+
# @yieldparam [Nokogiri::HTML::Document] doc
|
67
|
+
# The new HTML document object.
|
68
|
+
#
|
69
|
+
# @return [Nokogiri::HTML::Document]
|
70
|
+
# The parsed HTML file.
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# doc = HTML.open('index.html')
|
74
|
+
# # => #<Nokogiri::HTML::Document:...>
|
75
|
+
#
|
76
|
+
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Document
|
77
|
+
# @see HTML.open
|
78
|
+
#
|
79
|
+
def html_open(path,&block)
|
80
|
+
HTML.open(path,&block)
|
81
|
+
end
|
82
|
+
|
83
|
+
alias open_html html_open
|
84
|
+
|
85
|
+
#
|
86
|
+
# Creates a new `Nokogiri::HTML::Builder`.
|
87
|
+
#
|
88
|
+
# @yield []
|
89
|
+
# The block that will be used to construct the HTML document.
|
90
|
+
#
|
91
|
+
# @return [Nokogiri::HTML::Builder]
|
92
|
+
# The new HTML builder object.
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# html_build do
|
96
|
+
# html {
|
97
|
+
# body {
|
98
|
+
# div(style: 'display:none;') {
|
99
|
+
# object(classid: 'blabla')
|
100
|
+
# }
|
101
|
+
# }
|
102
|
+
# }
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Builder
|
106
|
+
# @see HTML.build
|
107
|
+
#
|
108
|
+
def html_build(&block)
|
109
|
+
HTML.build(&block)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-support-web - A web support library for ronin-rb.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-support-web is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-support-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 Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-support-web. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'nokogiri'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Support
|
25
|
+
module Web
|
26
|
+
#
|
27
|
+
# HTML helper methods.
|
28
|
+
#
|
29
|
+
module HTML
|
30
|
+
#
|
31
|
+
# Parses the body of a document into a HTML document object.
|
32
|
+
#
|
33
|
+
# @param [String, IO] html
|
34
|
+
# The HTML to parse.
|
35
|
+
#
|
36
|
+
# @yield [doc]
|
37
|
+
# If a block is given, it will be passed the newly created document
|
38
|
+
# object.
|
39
|
+
#
|
40
|
+
# @yieldparam [Nokogiri::HTML::Document] doc
|
41
|
+
# The new HTML document object.
|
42
|
+
#
|
43
|
+
# @return [Nokogiri::HTML::Document]
|
44
|
+
# The new HTML document object.
|
45
|
+
#
|
46
|
+
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Document
|
47
|
+
#
|
48
|
+
# @api public
|
49
|
+
#
|
50
|
+
def self.parse(html)
|
51
|
+
doc = Nokogiri::HTML.parse(html)
|
52
|
+
yield doc if block_given?
|
53
|
+
return doc
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Opens an HTML file.
|
58
|
+
#
|
59
|
+
# @param [String] path
|
60
|
+
# The path to the HTML file.
|
61
|
+
#
|
62
|
+
# @yield [doc]
|
63
|
+
# If a block is given, it will be passed the newly created document
|
64
|
+
# object.
|
65
|
+
#
|
66
|
+
# @yieldparam [Nokogiri::HTML::Document] doc
|
67
|
+
# The new HTML document object.
|
68
|
+
#
|
69
|
+
# @return [Nokogiri::HTML::Document]
|
70
|
+
# The parsed HTML file.
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# doc = HTML.open('index.html')
|
74
|
+
# # => #<Nokogiri::HTML::Document:...>
|
75
|
+
#
|
76
|
+
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Document
|
77
|
+
#
|
78
|
+
# @api public
|
79
|
+
#
|
80
|
+
def self.open(path)
|
81
|
+
doc = Nokogiri::HTML(File.open(path))
|
82
|
+
yield doc if block_given?
|
83
|
+
return doc
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Creates a new `Nokogiri::HTML::Builder`.
|
88
|
+
#
|
89
|
+
# @yield []
|
90
|
+
# The block that will be used to construct the HTML document.
|
91
|
+
#
|
92
|
+
# @return [Nokogiri::HTML::Builder]
|
93
|
+
# The new HTML builder object.
|
94
|
+
#
|
95
|
+
# @example
|
96
|
+
# HTML.build do
|
97
|
+
# html {
|
98
|
+
# body {
|
99
|
+
# div(style: 'display:none;') {
|
100
|
+
# object(classid: 'blabla')
|
101
|
+
# }
|
102
|
+
# }
|
103
|
+
# }
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Builder
|
107
|
+
#
|
108
|
+
# @api public
|
109
|
+
#
|
110
|
+
def self.build(&block)
|
111
|
+
Nokogiri::HTML::Builder.new(&block)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-support-web - A web support library for ronin-rb.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-support-web is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-support-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 Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-support-web. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/support/web/html/mixin'
|
22
|
+
require 'ronin/support/web/xml/mixin'
|
23
|
+
require 'ronin/support/web/agent/mixin'
|
24
|
+
require 'ronin/support/web/websocket/mixin'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module Support
|
28
|
+
module Web
|
29
|
+
#
|
30
|
+
# Web related helper methods.
|
31
|
+
#
|
32
|
+
module Mixin
|
33
|
+
include HTML::Mixin
|
34
|
+
include XML::Mixin
|
35
|
+
include Agent::Mixin
|
36
|
+
include WebSocket::Mixin
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-support-web - A web support library for ronin-rb.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-support-web is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-support-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 Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-support-web. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Ronin
|
22
|
+
module Support
|
23
|
+
module Web
|
24
|
+
# ronin-support-web version
|
25
|
+
VERSION = '0.1.0.rc1'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-support-web - A web support library for ronin-rb.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-support-web is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-support-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 Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-support-web. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/support/web/websocket/socket'
|
22
|
+
require 'ronin/support/web/websocket/url_methods'
|
23
|
+
require 'ronin/support/network/tcp'
|
24
|
+
require 'ronin/support/network/ssl'
|
25
|
+
|
26
|
+
require 'websocket'
|
27
|
+
|
28
|
+
module Ronin
|
29
|
+
module Support
|
30
|
+
module Web
|
31
|
+
module WebSocket
|
32
|
+
#
|
33
|
+
# Represents a WebSocket client.
|
34
|
+
#
|
35
|
+
class Client < Socket
|
36
|
+
|
37
|
+
include URLMethods
|
38
|
+
|
39
|
+
#
|
40
|
+
# Initializes the WebSocket client.
|
41
|
+
#
|
42
|
+
# @param [String, URI::WS, URI::WSS] url
|
43
|
+
# The `ws://` or `wss://` URL.
|
44
|
+
#
|
45
|
+
# @param [Hash{Symbol => Object}] kwargs
|
46
|
+
# Additional keyword arguments for.
|
47
|
+
#
|
48
|
+
# @option kwargs [String, nil] :bind_host
|
49
|
+
# The optional host to bind the server socket to.
|
50
|
+
#
|
51
|
+
# @option kwargs [Integer, nil] :bind_port
|
52
|
+
# The optioanl port to bind the server socket to. If not specified,
|
53
|
+
# it will default to the port of the URL.
|
54
|
+
#
|
55
|
+
# @param [Hash{Symbol => Object}] ssl
|
56
|
+
# Additional keyword arguments for
|
57
|
+
# `Ronin::Support::Network::SSL.connect`.
|
58
|
+
#
|
59
|
+
# @option ssl [1, 1.1, 1.2, String, Symbol, nil] :version
|
60
|
+
# The SSL version to use.
|
61
|
+
#
|
62
|
+
# @option ssl [Symbol, Boolean] :verify
|
63
|
+
# Specifies whether to verify the SSL certificate.
|
64
|
+
# May be one of the following:
|
65
|
+
#
|
66
|
+
# * `:none`
|
67
|
+
# * `:peer`
|
68
|
+
# * `:fail_if_no_peer_cert`
|
69
|
+
# * `:client_once`
|
70
|
+
#
|
71
|
+
# @option ssl [Crypto::Key::RSA, OpenSSL::PKey::RSA, nil] :key
|
72
|
+
# The RSA key to use for the SSL context.
|
73
|
+
#
|
74
|
+
# @option ssl [String] :key_file
|
75
|
+
# The path to the SSL `.key` file.
|
76
|
+
#
|
77
|
+
# @option ssl [Crypto::Cert, OpenSSL::X509::Certificate, nil] :cert
|
78
|
+
# The X509 certificate to use for the SSL context.
|
79
|
+
#
|
80
|
+
# @option ssl [String] :cert_file
|
81
|
+
# The path to the SSL `.crt` file.
|
82
|
+
#
|
83
|
+
# @option ssl [String] :ca_bundle
|
84
|
+
# Path to the CA certificate file or directory.
|
85
|
+
#
|
86
|
+
def initialize(url, ssl: {}, **kwargs)
|
87
|
+
super(url)
|
88
|
+
|
89
|
+
@socket = case @url.scheme
|
90
|
+
when 'ws'
|
91
|
+
Support::Network::TCP.connect(
|
92
|
+
@host, @port, **kwargs
|
93
|
+
)
|
94
|
+
when 'wss'
|
95
|
+
Support::Network::SSL.connect(
|
96
|
+
@host, @port, **kwargs, **ssl
|
97
|
+
)
|
98
|
+
else
|
99
|
+
raise(ArgumentError,"unsupported websocket scheme: #{url}")
|
100
|
+
end
|
101
|
+
|
102
|
+
send_handshake!
|
103
|
+
|
104
|
+
set_frame_classes(
|
105
|
+
::WebSocket::Frame::Incoming::Client,
|
106
|
+
::WebSocket::Frame::Outgoing::Client
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
#
|
113
|
+
# @api private
|
114
|
+
#
|
115
|
+
def send_handshake!(**kwargs)
|
116
|
+
@handshake = ::WebSocket::Handshake::Client.new(
|
117
|
+
url: @url.to_s, **kwargs
|
118
|
+
)
|
119
|
+
|
120
|
+
@socket.write(@handshake.to_s)
|
121
|
+
|
122
|
+
@handshake << @socket.readpartial(1024) until @handshake.finished?
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|