Class: Pwnlib::Tubes::Sock

Inherits:
Tube
  • Object
show all
Defined in:
lib/pwnlib/tubes/sock.rb

Overview

Socket!

Constant Summary

Constants inherited from Tube

Tube::BUFSIZE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Tube

#gets, #interact, #puts, #recv, #recvall, #recvline, #recvn, #recvpred, #recvregex, #recvuntil, #send, #sendline, #unrecv

Constructor Details

#initialize(host, port, timeout: nil) ⇒ Sock

Instantiate a Pwnlib::Tubes::Sock object.



23
24
25
26
27
28
29
# File 'lib/pwnlib/tubes/sock.rb', line 23

def initialize(host, port, timeout: nil)
  super(timeout: timeout)
  @sock = TCPSocket.new(host, port)
  @sock.binmode
  @timeout = nil
  @closed = { read: false, write: false }
end

Instance Attribute Details

#sockTCPSocket (readonly) Also known as: io_out



13
14
15
# File 'lib/pwnlib/tubes/sock.rb', line 13

def sock
  @sock
end

Instance Method Details

#close(direction = :both) ⇒ void

This method returns an undefined value.

Close the TCPSocket if no arguments passed. Or close the direction in sock.

Difference with Python pwntools:

  • In pwntools-python, method shutdown(direction) is for closing socket one side, close() is for closing both side. We merge these two methods into one here.



43
44
45
46
47
48
49
50
51
52
# File 'lib/pwnlib/tubes/sock.rb', line 43

def close(direction = :both)
  if direction == :both
    return if @sock.closed?

    @closed[:read] = @closed[:write] = true
    @sock.close
  else
    shutdown(*normalize_direction(direction))
  end
end