Class: Xploit::Sock
- Inherits:
-
Object
- Object
- Xploit::Sock
- Defined in:
- lib/xploit/sock.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(host, port, timeout = nil, debug = false) ⇒ Sock
constructor
A new instance of Sock.
- #recv(n = nil, delim = nil) ⇒ Object
- #recvline ⇒ Object
- #recvuntil(delim) ⇒ Object
- #send(data) ⇒ Object
- #sendline(msg) ⇒ Object
- #shell ⇒ Object
Constructor Details
#initialize(host, port, timeout = nil, debug = false) ⇒ Sock
Returns a new instance of Sock.
15 16 17 18 19 20 |
# File 'lib/xploit/sock.rb', line 15 def initialize(host, port, timeout = nil, debug = false) @sock = TCPSocket.open(host, port) @timeout = 0.5 @debug = debug puts "[\e[32m*\e[0m] Connect to #{host}:#{port}" end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
13 14 15 |
# File 'lib/xploit/sock.rb', line 13 def debug @debug end |
#timeout ⇒ Object
Returns the value of attribute timeout.
13 14 15 |
# File 'lib/xploit/sock.rb', line 13 def timeout @timeout end |
Class Method Details
.open(host, port, timeout = nil, debug = false) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/xploit/sock.rb', line 22 def self.open(host, port, timeout = nil, debug = false) if block_given? s = Sock.new(host, port, timeout, debug) yield(s) s.close else Sock.new(host, port, timeout, debug) end end |
Instance Method Details
#close ⇒ Object
88 89 90 91 |
# File 'lib/xploit/sock.rb', line 88 def close puts "[\e[32m*\e[0m] Close the connection" @sock.close end |
#recv(n = nil, delim = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/xploit/sock.rb', line 48 def recv(n = nil, delim = nil) puts "[ \e[35mRECV\e[0m ]" if @debug unless n.nil? res = @sock.read(n) Hexdump.dump(res) if @debug return res end res = "" while select([@sock], nil, nil,timeout=@timeout) s = @sock.read(1) raise RecvError if s.length != 1 res << s break res if not delim.nil? and res.include?(delim) end Hexdump.dump(res) if @debug res end |
#recvline ⇒ Object
76 77 78 |
# File 'lib/xploit/sock.rb', line 76 def recvline() recvuntil("\n") end |
#recvuntil(delim) ⇒ Object
72 73 74 |
# File 'lib/xploit/sock.rb', line 72 def recvuntil(delim) self.recv(n = nil, delim) end |
#send(data) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/xploit/sock.rb', line 32 def send(data) puts "[\e[34m SEND \e[0m]" if @debug len = @sock.write(data) raise SendError if len != data.bytesize Hexdump.dump(data) if @debug return len end |
#sendline(msg) ⇒ Object
44 45 46 |
# File 'lib/xploit/sock.rb', line 44 def sendline(msg) send(msg + "\n") end |
#shell ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/xploit/sock.rb', line 80 def shell STDOUT.sync = true while s = STDIN.gets self.send(s) puts self.recv(n = nil, delim = nil) end end |