Module: PWN::Plugins::Sock
- Defined in:
- lib/pwn/plugins/sock.rb
Overview
This plugin was created to support fuzzing various networking protocols
Constant Summary collapse
Class Method Summary collapse
-
.authors ⇒ Object
- Author(s)
-
0day Inc.
-
.connect(opts = {}) ⇒ Object
- Supported Method Parameters
-
sock_obj = PWN::Plugins::Sock.connect( target: ‘required - target host or ip’, port: ‘required - target port’, protocol: ‘optional - :tcp || :udp (defaults to tcp)’, tls: ‘optional - boolean connect to target socket using TLS (defaults to false)’ ).
-
.disconnect(opts = {}) ⇒ Object
- Supported Method Parameters
-
sock_obj = PWN::Plugins::Sock.disconnect( sock_obj: ‘required - sock_obj returned from #connect method’ ).
-
.help ⇒ Object
Display Usage for this Module.
-
.listen(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::Sock.listen( server_ip: ‘required - target host or ip to listen’, port: ‘required - target port’, protocol: ‘optional - :tcp || :udp (defaults to tcp)’, tls: ‘optional - boolean listen on TLS-enabled socket (defaults to false)’ ).
Class Method Details
.authors ⇒ Object
- Author(s)
-
0day Inc. <[email protected]>
123 124 125 126 127 |
# File 'lib/pwn/plugins/sock.rb', line 123 public_class_method def self. "AUTHOR(S): 0day Inc. <[email protected]> " end |
.connect(opts = {}) ⇒ Object
- Supported Method Parameters
-
sock_obj = PWN::Plugins::Sock.connect(
target: 'required - target host or ip', port: 'required - target port', protocol: 'optional - :tcp || :udp (defaults to tcp)', tls: 'optional - boolean connect to target socket using TLS (defaults to false)')
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 |
# File 'lib/pwn/plugins/sock.rb', line 20 public_class_method def self.connect(opts = {}) target = opts[:target].to_s.scrub port = opts[:port].to_i opts[:protocol].nil? ? protocol = :tcp : protocol = opts[:protocol].to_s.downcase.to_sym opts[:tls].nil? ? tls = false : tls = true case protocol when :tcp if tls sock = TCPSocket.open(target, port) tls_context = OpenSSL::SSL::SSLContext.new tls_context.set_params(verify_mode: OpenSSL::SSL::VERIFY_NONE) tls_sock = OpenSSL::SSL::SSLSocket.new(sock, tls_context) sock_obj = tls_sock.connect else sock_obj = TCPSocket.open(target, port) end when :udp sock_obj = UDPSocket.new sock_obj.connect(target, port) else raise "Unsupported protocol: #{protocol}" end sock_obj rescue StandardError => e sock_obj = disconnect(sock_obj: sock_obj) unless sock_obj.nil? raise e end |
.disconnect(opts = {}) ⇒ Object
- Supported Method Parameters
-
sock_obj = PWN::Plugins::Sock.disconnect(
sock_obj: 'required - sock_obj returned from #connect method')
113 114 115 116 117 118 119 |
# File 'lib/pwn/plugins/sock.rb', line 113 public_class_method def self.disconnect(opts = {}) sock_obj = opts[:sock_obj] sock_obj.close sock_obj = nil rescue StandardError => e raise e end |
.help ⇒ Object
Display Usage for this Module
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/pwn/plugins/sock.rb', line 131 public_class_method def self.help puts "USAGE: sock_obj = #{self}.connect( target: 'required - target host or ip', port: 'required - target port', protocol: 'optional - :tcp || :udp (defaults to tcp)', tls: 'optional - boolean connect to target socket using TLS (defaults to false)' ) #{self}.listen( server_ip: 'required - target host or ip to listen', port: 'required - target port', protocol: 'optional - :tcp || :udp (defaults to tcp)', tls: 'optional - boolean listen on TLS-enabled socket (defaults to false)' ) sock_obj = PWN::Plugins::Sock.disconnect( sock_obj: 'required - sock_obj returned from #connect method' ) #{self}.authors " end |
.listen(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::Sock.listen(
server_ip: 'required - target host or ip to listen', port: 'required - target port', protocol: 'optional - :tcp || :udp (defaults to tcp)', tls: 'optional - boolean listen on TLS-enabled socket (defaults to false)')
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/pwn/plugins/sock.rb', line 58 public_class_method def self.listen(opts = {}) server_ip = opts[:server_ip].to_s.scrub port = opts[:port].to_i opts[:protocol].nil? ? protocol = :tcp : protocol = opts[:protocol].to_s.downcase.to_sym opts[:tls].nil? ? tls = false : tls = true case protocol when :tcp if tls # Multi-threaded - Not working sock = TCPServer.open(server_ip, port) tls_context = OpenSSL::SSL::SSLContext.new tls_context.set_params(verify_mode: OpenSSL::SSL::VERIFY_NONE) listen_obj = OpenSSL::SSL::SSLServer.new(sock, tls_context) # loop do # Thread.start(listen_obj.accept) do |client_thread| # while (client_input = client_thread.gets) # puts client_input # end # client_thread.close # end # end else # Multi-threaded listen_obj = TCPServer.open(server_ip, port) loop do Thread.start(listen_obj.accept) do |client_thread| while (client_input = client_thread.gets) puts client_input end client_thread.close end end end when :udp # Single Threaded listen_obj = UDPSocket.new listen_obj.bind(server_ip, port) while (client_input = listen_obj.recvmsg) puts client_input[0].to_s end else raise "Unsupported protocol: #{protocol}" end rescue StandardError => e raise e ensure listen_obj = disconnect(sock_obj: listen_obj) unless listen_obj.nil? end |