Module: ObjectPwnStream::ObjectOutputStream

Includes:
Constants
Included in:
PwnStream
Defined in:
lib/ObjectPwnStream/ObjectOutputStream.rb

Constant Summary

Constants included from Constants

Constants::BASE_WIRE_HANDLE, Constants::STREAM_MAGIC, Constants::STREAM_VERSION, Constants::TC_ARRAY, Constants::TC_BLOCKDATA, Constants::TC_BLOCKDATALONG, Constants::TC_CLASS, Constants::TC_CLASSDESC, Constants::TC_ENDBLOCKDATA, Constants::TC_ENUM, Constants::TC_EXCEPTION, Constants::TC_LONGSTRING, Constants::TC_NULL, Constants::TC_OBJECT, Constants::TC_PROXYCLASSDESC, Constants::TC_REFERENCE, Constants::TC_RESET, Constants::TC_STRING

Instance Method Summary collapse

Instance Method Details

#open_output_streamObject



9
10
11
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 9

def open_output_stream
  write_stream_header(*[Constants::STREAM_MAGIC, Constants::STREAM_VERSION])
end

#reset!Object



88
89
90
91
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 88

def reset!
  @outstream.putc(Constants::TC_RESET)
  @outstream.flush
end

#write_boolean(bool) ⇒ Object



63
64
65
66
67
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 63

def write_boolean(bool)
  write_block_header(Constants::TC_BLOCKDATA, 1)
  @outstream.putc(bool ? 0x1 : 0x0)
  @outstream.flush
end

#write_byte(byte) ⇒ Object



42
43
44
45
46
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 42

def write_byte(byte)
  write_block_header(Constants::TC_BLOCKDATA, 0x1)
  @outstream.putc(byte)
  @outstream.flush
end

#write_bytes(bytes) ⇒ Object



48
49
50
51
52
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 48

def write_bytes(bytes)
  write_block_header(Constants::TC_BLOCKDATA, bytes.size)
  bytes.each {@outstream.putc(_1)}
  @outstream.flush
end

#write_char(char) ⇒ Object



30
31
32
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 30

def write_char(char)
  write_short(char.unpack("U")[0])
end

#write_chars(str) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 34

def write_chars(str)
  conv = Encoding::Converter.new("utf-8", "utf-16")
  data = conv.convert(str)
  write_block_header(Constants::TC_BLOCKDATA, data.bytesize)
  @outstream.write(data)
  @outstream.flush
end

#write_double(double) ⇒ Object



75
76
77
78
79
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 75

def write_double(double)
  write_block_header(Constants::TC_BLOCKDATA, 8)
  @outstream.write([double].pack("G"))
  @outstream.flush
end

#write_float(float) ⇒ Object



69
70
71
72
73
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 69

def write_float(float)
  write_block_header(Constants::TC_BLOCKDATA, 4)
  @outstream.write([float].pack("g"))
  @outstream.flush
end

#write_int(v, signed: false) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 13

def write_int(v, signed: false)
  length = 4
  write_block_header(Constants::TC_BLOCKDATA, length)
  template = (signed ? "l>" : "L>")
  @outstream.write([v].pack(template))
  @outstream.flush
end

#write_long(long, signed: false) ⇒ Object



81
82
83
84
85
86
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 81

def write_long(long, signed: false)
  write_block_header(Constants::TC_BLOCKDATA, 8)
  template = signed ? "q>" : "Q>"
  @outstream.write([long].pack(template))
  @outstream.flush
end

#write_object(payload_path: nil, payload: nil, ysoserial: false) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 93

def write_object(payload_path: nil, payload: nil, ysoserial: false)
  if ysoserial
    @outstream.write(@payload)
    @outstream.flush
  elsif payload
    ObjectInputStream.check_stream_header(payload[...4].unpack("S>*"), provided: true)
    @outstream.write(payload[4..])
    @outstream.flush
  elsif payload_path
    pf = File.open(payload_path, "rb")
    ObjectInputStream.check_stream_header(pf.read(4).unpack("S>*"), provided: true)
    @outstream.write(pf.read(pf.size-4))
    @outstream.flush
  end
end

#write_short(v, signed: false) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 21

def write_short(v, signed: false)
  v &= 0xFFFF
  length = 2
  write_block_header(Constants::TC_BLOCKDATA, length)
  template = (signed ? "s>" : "S>")
  @outstream.write([v].pack(template))
  @outstream.flush
end

#write_utf(str) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/ObjectPwnStream/ObjectOutputStream.rb', line 54

def write_utf(str)
  utf_size = str.bytesize
  write_block_header(Constants::TC_BLOCKDATA, utf_size+2)
  @outstream.write([utf_size].pack("S>"))
  @outstream.write(str)
  @outstream.flush

end