1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-05 14:57:30 +01:00

added shutdown, tcp seems to work like a chizzamp

git-svn-id: file:///home/svn/incoming/trunk@2441 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Matt Miller 2005-04-22 03:42:23 +00:00
parent b991d10fbd
commit 42e9b0945e
5 changed files with 49 additions and 9 deletions

View File

@ -11,21 +11,29 @@ client = DemoClient.new(host, port).client
# elements
params = Rex::Socket::Parameters.new(
'PeerHost' => '128.242.160.3',
'PeerPort' => 80,
'PeerPort' => 25,
'Proto' => 'tcp')
# Create the socket for this connection
socket = client.net.socket.create(params)
# Send GET / HTTP/1.0
socket.write("GET / HTTP/1.0\r\n\r\n")
socket.send("HELO hick.org\r\n")
puts "HTTP Response:\n\n"
# Read part of the response
while ((data = socket.read) != nil)
data = socket.recv
puts "#{data}"
socket.send("QUIT\r\n")
socket.sock.shutdown(1)
while ((data = socket.recv) != nil)
puts "#{data}"
end
while (1)
select nil, nil, nil, 5
end
puts "Finished"
#while (1)
# select nil, nil, nil, 5
#end

View File

@ -211,6 +211,16 @@ class Channel
return _close(addends)
end
# Close the channel for future writes
def close_write
return _close
end
# Close the channel for future reads
def close_read
return _close
end
# Closes the channel
def _close(addends = nil)
if (self.cid == nil)

View File

@ -158,7 +158,7 @@ protected
# If the socket closed, notify the other side and remove
# this socket from the monitored socket list
if (closed)
channel.close
channel.close_write
remove_monitored_socket(sock)
# Otherwise, write the data to the remote side

View File

@ -69,6 +69,26 @@ class TcpClientChannel < Rex::Post::Meterpreter::Stream
super(client, cid, type, flags)
end
def close_write
return shutdown(1)
end
# Shutdown the connection
#
# 0 -> future reads
# 1 -> future sends
# 2 -> both
def shutdown(how = 1)
request = Packet.create_request('stdapi_net_socket_tcp_shutdown')
request.add_tlv(TLV_TYPE_SHUTDOWN_HOW, how)
request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)
response = client.send_request(request)
return true
end
end
end; end; end; end; end; end; end

View File

@ -58,6 +58,8 @@ TLV_TYPE_LOCAL_HOST = TLV_META_TYPE_STRING | 1502
TLV_TYPE_LOCAL_PORT = TLV_META_TYPE_UINT | 1503
TLV_TYPE_CONNECT_RETRIES = TLV_META_TYPE_UINT | 1504
TLV_TYPE_SHUTDOWN_HOW = TLV_META_TYPE_UINT | 1530
##
#
# Sys