Class: Rex::Proto::SMB::SimpleClient::OpenPipe

Inherits:
OpenFile
  • Object
show all
Defined in:
lib/rex/proto/smb/simpleclient.rb

Instance Attribute Summary collapse

Attributes inherited from OpenFile

#chunk_size, #client, #file_id, #name, #tree_id

Instance Method Summary collapse

Methods inherited from OpenFile

#<<, #close, #delete

Constructor Details

#initialize(*args) ⇒ OpenPipe

Returns a new instance of OpenPipe.



125
126
127
128
129
# File 'lib/rex/proto/smb/simpleclient.rb', line 125

def initialize(*args)
	super(*args)
	self.mode = 'rw'
	@buff = ''
end

Instance Attribute Details

#modeObject

Valid modes are: ‘trans’ and ‘rw’



123
124
125
# File 'lib/rex/proto/smb/simpleclient.rb', line 123

def mode
  @mode
end

Instance Method Details

#read(length = nil, offset = 0) ⇒ Object



136
137
138
139
140
141
142
143
144
145
# File 'lib/rex/proto/smb/simpleclient.rb', line 136

def read(length = nil, offset = 0)
	case self.mode
	when 'trans'
		read_buffer(length, offset)
	when 'rw'
		super(length, offset)
	else
		raise ArgumentError
	end
end

#read_buffer(length, offset = 0) ⇒ Object



131
132
133
134
# File 'lib/rex/proto/smb/simpleclient.rb', line 131

def read_buffer(length, offset=0)
	length ||= @buff.length
	@buff.slice!(0, length)
end

#write(data, offset = 0) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
# File 'lib/rex/proto/smb/simpleclient.rb', line 147

def write(data, offset = 0)
	case self.mode
	
	when 'trans'
		write_trans(data, offset)
	when 'rw'
		super(data, offset)
	else
		raise ArgumentError
	end
end

#write_trans(data, offset = 0) ⇒ Object



159
160
161
162
163
164
# File 'lib/rex/proto/smb/simpleclient.rb', line 159

def write_trans(data, offset=0)
	ack = self.client.trans_named_pipe(self.file_id, data)
	doff = ack['Payload'].v['DataOffset']
	dlen = ack['Payload'].v['DataCount']
	@buff << ack.to_s[4+doff, dlen]
end