code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def entries_for(local) ::Dir.entries(local).reject { |v| %w(. ..).include?(v) } end
Returns all directory entries for the given path, removing the '.' and '..' relative paths.
entries_for
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/operations/upload.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/operations/upload.rb
MIT
def update_progress(event, *args) on = "on_#{event}" if progress.respond_to?(on) progress.send(on, self, *args) elsif progress.respond_to?(:call) progress.call(event, self, *args) end end
Attempts to notify the progress monitor (if one was given) about progress made for the given event.
update_progress
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/operations/upload.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/operations/upload.rb
MIT
def initialize(session) @session = session self.logger = session.logger @request_id_counter = -1 end
Create a new instance of a protocol driver, servicing the given session.
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/base.rb
MIT
def parse(packet) case packet.type when FXP_STATUS then parse_status_packet(packet) when FXP_HANDLE then parse_handle_packet(packet) when FXP_DATA then parse_data_packet(packet) when FXP_NAME then parse_name_packet(packet) when FXP_ATTRS then parse_attrs_packet(packet) else raise NotImplementedError, "unknown packet type: #{packet.type}" end end
Attept to parse the given packet. If the packet is of an unsupported type, an exception will be raised. Returns the parsed data as a hash (the keys in the hash are packet-type specific).
parse
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/base.rb
MIT
def send_request(type, *args) @request_id_counter += 1 session.send_packet(type, :long, @request_id_counter, *args) return @request_id_counter end
Send a new packet of the given type, and with the given data arguments. A new request identifier will be allocated to this request, and will be returned.
send_request
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/base.rb
MIT
def elements #:nodoc: @elements ||= [ [:size, :int64, F_SIZE], [:uid, :long, F_UIDGID], [:gid, :long, F_UIDGID], [:permissions, :long, F_PERMISSIONS], [:atime, :long, F_ACMODTIME], [:mtime, :long, F_ACMODTIME], [:extended, :special, F_EXTENDED] ] end
Returns the array of attribute meta-data that defines the structure of the attributes packet as described by this version of the protocol.
elements
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def from_buffer(buffer) flags = buffer.read_long data = {} elements.each do |name, type, condition| if flags & condition == condition if type == :special data[name] = send("parse_#{name}", buffer) else data[name] = buffer.send("read_#{type}") end end end new(data) end
Parses the given buffer and returns an Attributes object compsed from the data extracted from it.
from_buffer
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def parse_extended(buffer) extended = Hash.new buffer.read_long.times do extended[buffer.read_string] = buffer.read_string end extended end
Parse the hash of extended data from the buffer.
parse_extended
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def initialize(attributes={}) @attributes = attributes end
Create a new Attributes instance with the given attributes. The following keys are supported: * :size:: the size of the file * :uid:: the user-id that owns the file (integer) * :gid:: the group-id that owns the file (integer) * :owner:: the name of the user that owns the file (string) * :group:: the name of the group that owns the file (string) * :permissions:: the permissions on the file (integer, e.g. 0755) * :atime:: the access time of the file (integer, seconds since epoch) * :mtime:: the modification time of the file (integer, seconds since epoch) * :extended:: a hash of name/value pairs identifying extended info
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def uid if attributes[:owner] && !attributes.key?(:uid) require 'etc' attributes[:uid] = Etc.getpwnam(attributes[:owner]).uid end attributes[:uid] end
Returns the user-id of the user that owns the file, or +nil+ if that information is not available. If an :owner key exists, but not a :uid key, the Etc module will be used to reverse lookup the id from the name. This might fail on some systems (e.g., Windows).
uid
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def gid if attributes[:group] && !attributes.key?(:gid) require 'etc' attributes[:gid] = Etc.getgrnam(attributes[:group]).gid end attributes[:gid] end
Returns the group-id of the group that owns the file, or +nil+ if that information is not available. If a :group key exists, but not a :gid key, the Etc module will be used to reverse lookup the id from the name. This might fail on some systems (e.g., Windows).
gid
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def owner if attributes[:uid] && !attributes[:owner] require 'etc' attributes[:owner] = Etc.getpwuid(attributes[:uid].to_i).name end attributes[:owner] end
Returns the username of the user that owns the file, or +nil+ if that information is not available. If the :uid is given, but not the :owner, the Etc module will be used to lookup the name from the id. This might fail on some systems (e.g. Windows).
owner
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def group if attributes[:gid] && !attributes[:group] require 'etc' attributes[:group] = Etc.getgrgid(attributes[:gid].to_i).name end attributes[:group] end
Returns the group name of the group that owns the file, or +nil+ if that information is not available. If the :gid is given, but not the :group, the Etc module will be used to lookup the name from the id. This might fail on some systems (e.g. Windows).
group
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def type if permissions & 0140000 == 0140000 then T_SOCKET elsif permissions & 0120000 == 0120000 then T_SYMLINK elsif permissions & 0100000 == 0100000 then T_REGULAR elsif permissions & 060000 == 060000 then T_BLOCK_DEVICE elsif permissions & 040000 == 040000 then T_DIRECTORY elsif permissions & 020000 == 020000 then T_CHAR_DEVICE elsif permissions & 010000 == 010000 then T_FIFO else T_UNKNOWN end end
Inspects the permissions bits to determine what type of entity this attributes object represents. If will return one of the T_ constants.
type
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def symbolic_type case type when T_SOCKET then :socket when T_SYMLINK then :symlink when T_REGULAR then :regular when T_BLOCK_DEVICE then :block_device when T_DIRECTORY then :directory when T_CHAR_DEVICE then :char_device when T_FIFO then :fifo when T_SPECIAL then :special when T_UNKNOWN then :unknown else raise NotImplementedError, "unknown file type #{type} (bug?)" end end
Returns the type as a symbol, rather than an integer, for easier use in Ruby programs.
symbolic_type
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def directory? case type when T_DIRECTORY then true when T_UNKNOWN then nil else false end end
Returns true if these attributes appear to describe a directory.
directory?
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def symlink? case type when T_SYMLINK then true when T_UNKNOWN then nil else false end end
Returns true if these attributes appear to describe a symlink.
symlink?
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def file? case type when T_REGULAR then true when T_UNKNOWN then nil else false end end
Returns true if these attributes appear to describe a regular file.
file?
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def to_s prepare_serialization! flags = 0 self.class.elements.each do |name, type, condition| flags |= condition if attributes[name] end buffer = Net::SSH::Buffer.from(:long, flags) self.class.elements.each do |name, type, condition| if flags & condition == condition if type == :special send("encode_#{name}", buffer) else buffer.send("write_#{type}", attributes[name]) end end end buffer.to_s end
Convert the object to a string suitable for passing in an SFTP packet. This is the raw representation of the attribute packet payload, and is not intended to be human readable.
to_s
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def prepare_serialization! # force the uid/gid to be translated from owner/group, if those keys # were given on instantiation uid gid end
Perform protocol-version-specific preparations for serialization.
prepare_serialization!
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def encode_extended(buffer) buffer.write_long extended.size extended.each { |k,v| buffer.write_string k, v } end
Encodes information about the extended info onto the end of the given buffer.
encode_extended
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/attributes.rb
MIT
def parse_handle_packet(packet) { :handle => packet.read_string } end
Parses the given FXP_HANDLE packet and returns a hash with one key, :handle, which references the handle.
parse_handle_packet
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def parse_status_packet(packet) { :code => packet.read_long } end
Parses the given FXP_STATUS packet and returns a hash with one key, :code, which references the status code returned by the server.
parse_status_packet
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def parse_data_packet(packet) { :data => packet.read_string } end
Parses the given FXP_DATA packet and returns a hash with one key, :data, which references the data returned in the packet.
parse_data_packet
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def parse_attrs_packet(packet) { :attrs => attribute_factory.from_buffer(packet) } end
Parses the given FXP_ATTRS packet and returns a hash with one key, :attrs, which references an Attributes object.
parse_attrs_packet
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def parse_name_packet(packet) names = [] packet.read_long.times do filename = packet.read_string longname = packet.read_string attrs = attribute_factory.from_buffer(packet) names << name_factory.new(filename, longname, attrs) end { :names => names } end
Parses the given FXP_NAME packet and returns a hash with one key, :names, which references an array of Name objects.
parse_name_packet
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def open(path, flags, options) flags = normalize_open_flags(flags) if flags & (IO::WRONLY | IO::RDWR) != 0 sftp_flags = FV1::WRITE sftp_flags |= FV1::READ if flags & IO::RDWR != 0 sftp_flags |= FV1::APPEND if flags & IO::APPEND != 0 else sftp_flags = FV1::READ end sftp_flags |= FV1::CREAT if flags & IO::CREAT != 0 sftp_flags |= FV1::TRUNC if flags & IO::TRUNC != 0 sftp_flags |= FV1::EXCL if flags & IO::EXCL != 0 attributes = attribute_factory.new(options) send_request(FXP_OPEN, :string, path, :long, sftp_flags, :raw, attributes.to_s) end
Sends a FXP_OPEN packet to the server and returns the packet identifier. The +flags+ parameter is either an integer (in which case it must be a combination of the IO constants) or a string (in which case it must be one of the mode strings that IO::open accepts). The +options+ parameter is a hash that is used to construct a new Attribute object, to pass as part of the FXP_OPEN request.
open
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def close(handle) send_request(FXP_CLOSE, :string, handle) end
Sends a FXP_CLOSE packet to the server for the given +handle+ (such as would be returned via a FXP_HANDLE packet). Returns the new packet id.
close
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def read(handle, offset, length) send_request(FXP_READ, :string, handle, :int64, offset, :long, length) end
Sends a FXP_READ packet to the server, requesting that +length+ bytes be read from the file identified by +handle+, starting at +offset+ bytes within the file. The handle must be one that was returned via a FXP_HANDLE packet. Returns the new packet id.
read
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def write(handle, offset, data) send_request(FXP_WRITE, :string, handle, :int64, offset, :string, data) end
Sends a FXP_WRITE packet to the server, requesting that +data+ (a string), be written to the file identified by +handle+, starting at +offset+ bytes from the beginning of the file. The handle must be one that was returned via a FXP_HANDLE packet. Returns the new packet id.
write
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def lstat(path, flags=nil) send_request(FXP_LSTAT, :string, path) end
Sends a FXP_LSTAT packet to the server, requesting a FXP_ATTR response for the file at the given remote +path+ (a string). The +flags+ parameter is ignored in this version of the protocol. #lstat will not follow symbolic links; see #stat for a version that will.
lstat
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def fstat(handle, flags=nil) send_request(FXP_FSTAT, :string, handle) end
Sends a FXP_FSTAT packet to the server, requesting a FXP_ATTR response for the file represented by the given +handle+ (which must have been obtained from a FXP_HANDLE packet). The +flags+ parameter is ignored in this version of the protocol.
fstat
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def setstat(path, attrs) send_request(FXP_SETSTAT, :string, path, :raw, attribute_factory.new(attrs).to_s) end
Sends a FXP_SETSTAT packet to the server, to update the attributes for the file at the given remote +path+ (a string). The +attrs+ parameter is a hash that defines the attributes to set.
setstat
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def fsetstat(handle, attrs) send_request(FXP_FSETSTAT, :string, handle, :raw, attribute_factory.new(attrs).to_s) end
Sends a FXP_FSETSTAT packet to the server, to update the attributes for the file represented by the given +handle+ (which must have been obtained from a FXP_HANDLE packet). The +attrs+ parameter is a hash that defines the attributes to set.
fsetstat
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def opendir(path) send_request(FXP_OPENDIR, :string, path) end
Sends a FXP_OPENDIR packet to the server, to request a handle for manipulating the directory at the given remote +path+.
opendir
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def readdir(handle) send_request(FXP_READDIR, :string, handle) end
Sends a FXP_READDIR packet to the server, to request a batch of directory name entries in the directory identified by +handle+ (which must have been obtained via a FXP_OPENDIR request).
readdir
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def remove(filename) send_request(FXP_REMOVE, :string, filename) end
Sends a FXP_REMOTE packet to the server, to request that the given file be deleted from the remote server.
remove
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def mkdir(path, attrs) send_request(FXP_MKDIR, :string, path, :raw, attribute_factory.new(attrs).to_s) end
Sends a FXP_MKDIR packet to the server, to request that a new directory at +path+ on the remote server be created, and with +attrs+ (a hash) describing the attributes of the new directory.
mkdir
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def rmdir(path) send_request(FXP_RMDIR, :string, path) end
Sends a FXP_RMDIR packet to the server, to request that the directory at +path+ on the remote server be deleted.
rmdir
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def realpath(path) send_request(FXP_REALPATH, :string, path) end
Sends a FXP_REALPATH packet to the server, to request that the given +path+ be canonicalized, taking into account path segments like "..".
realpath
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def stat(path, flags=nil) send_request(FXP_STAT, :string, path) end
Sends a FXP_STAT packet to the server, requesting a FXP_ATTR response for the file at the given remote +path+ (a string). The +flags+ parameter is ignored in this version of the protocol. #stat will follow symbolic links; see #lstat for a version that will not.
stat
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def rename(name, new_name, flags=nil) not_implemented! :rename end
Not implemented in version 1 of the SFTP protocol. Raises a NotImplementedError if called.
rename
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def readlink(path) not_implemented! :readlink end
Not implemented in version 1 of the SFTP protocol. Raises a NotImplementedError if called.
readlink
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def symlink(path, target) not_implemented! :symlink end
Not implemented in version 1 of the SFTP protocol. Raises a NotImplementedError if called.
symlink
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def link(*args) not_implemented! :link end
Not implemented in version 1 of the SFTP protocol. Raises a NotImplementedError if called.
link
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def block(handle, offset, length, mask) not_implemented! :block end
Not implemented in version 1 of the SFTP protocol. Raises a NotImplementedError if called.
block
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def unblock(handle, offset, length) not_implemented! :unblock end
Not implemented in version 1 of the SFTP protocol. Raises a NotImplementedError if called.
unblock
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def not_implemented!(operation) raise NotImplementedError, "the #{operation} operation is not available in the version of the SFTP protocol supported by your server" end
A helper method for implementing wrappers for operations that are not implemented by the current SFTP protocol version. Simply raises NotImplementedError with a message based on the given operation name.
not_implemented!
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def normalize_open_flags(flags) if String === flags case flags.tr("b", "") when "r" then IO::RDONLY when "r+" then IO::RDWR when "w" then IO::WRONLY | IO::TRUNC | IO::CREAT when "w+" then IO::RDWR | IO::TRUNC | IO::CREAT when "a" then IO::APPEND | IO::CREAT | IO::WRONLY when "a+" then IO::APPEND | IO::CREAT | IO::RDWR else raise ArgumentError, "unsupported flags: #{flags.inspect}" end else flags.to_i end end
Normalizes the given flags parameter, converting it into a combination of IO constants.
normalize_open_flags
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/base.rb
MIT
def initialize(name, longname, attributes) @name, @longname, @attributes = name, longname, attributes end
Create a new Name object with the given name, longname, and attributes.
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/name.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/01/name.rb
MIT
def rename(name, new_name, flags=nil) send_request(FXP_RENAME, :string, name, :string, new_name) end
Sends a FXP_RENAME packet to the server to request that the file or directory with the given +name+ (must be a full path) be changed to +new_name+ (which must also be a path). The +flags+ parameter is ignored in this version of the protocol.
rename
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/02/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/02/base.rb
MIT
def readlink(path) send_request(FXP_READLINK, :string, path) end
Sends a FXP_READLINK packet to the server to request that the target of the given symlink on the remote host (+path+) be returned.
readlink
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/03/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/03/base.rb
MIT
def symlink(path, target) send_request(FXP_SYMLINK, :string, path, :string, target) end
Sends a FXP_SYMLINK packet to the server to request that a symlink at the given +path+ be created, pointing at +target+..
symlink
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/03/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/03/base.rb
MIT
def elements #:nodoc: @elements ||= [ [:type, :byte, 0], [:size, :int64, V01::Attributes::F_SIZE], [:owner, :string, F_OWNERGROUP], [:group, :string, F_OWNERGROUP], [:permissions, :long, V01::Attributes::F_PERMISSIONS], [:atime, :int64, F_ACCESSTIME], [:atime_nseconds, :long, F_ACCESSTIME | F_SUBSECOND_TIMES], [:createtime, :int64, F_CREATETIME], [:createtime_nseconds, :long, F_CREATETIME | F_SUBSECOND_TIMES], [:mtime, :int64, F_MODIFYTIME], [:mtime_nseconds, :long, F_MODIFYTIME | F_SUBSECOND_TIMES], [:acl, :special, F_ACL], [:extended, :special, V01::Attributes::F_EXTENDED] ] end
The list of supported elements in the attributes structure as defined by v4 of the sftp protocol.
elements
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/attributes.rb
MIT
def parse_acl(buffer) acl_buf = Net::SSH::Buffer.new(buffer.read_string) acl = [] acl_buf.read_long.times do acl << ACL.new(acl_buf.read_long, acl_buf.read_long, acl_buf.read_long, acl_buf.read_string) end acl end
A helper method for parsing the ACL entry in an Attributes struct.
parse_acl
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/attributes.rb
MIT
def prepare_serialization! # force the group/owner to be translated from uid/gid, if those keys # were given on instantiation owner group end
Perform protocol-version-specific preparations for serialization.
prepare_serialization!
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/attributes.rb
MIT
def encode_acl(buffer) acl_buf = Net::SSH::Buffer.from(:long, acl.length) acl.each do |item| acl_buf.write_long item.type, item.flag, item.mask acl_buf.write_string item.who end buffer.write_string(acl_buf.to_s) end
Performs protocol-version-specific encoding of the access control list, if one exists.
encode_acl
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/attributes.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/attributes.rb
MIT
def stat(path, flags=nil) send_request(FXP_STAT, :string, path, :long, flags || DEFAULT_FLAGS) end
Sends a FXP_STAT packet to the server for the given +path+, and with the given +flags+. If +flags+ is nil, it defaults to F_SIZE | F_PERMISSIONS | F_ACCESSTIME | F_CREATETIME | F_MODIFYTIME | F_ACL | F_OWNERGROUP | F_SUBSECOND_TIMES | F_EXTENDED (see Net::SFTP::Protocol::V04::Attributes for those constants).
stat
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/base.rb
MIT
def lstat(path, flags=nil) send_request(FXP_LSTAT, :string, path, :long, flags || DEFAULT_FLAGS) end
Sends a FXP_LSTAT packet to the server for the given +path+, and with the given +flags+. If +flags+ is nil, it defaults to F_SIZE | F_PERMISSIONS | F_ACCESSTIME | F_CREATETIME | F_MODIFYTIME | F_ACL | F_OWNERGROUP | F_SUBSECOND_TIMES | F_EXTENDED (see Net::SFTP::Protocol::V04::Attributes for those constants).
lstat
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/base.rb
MIT
def fstat(handle, flags=nil) send_request(FXP_FSTAT, :string, handle, :long, flags || DEFAULT_FLAGS) end
Sends a FXP_FSTAT packet to the server for the given +path+, and with the given +flags+. If +flags+ is nil, it defaults to F_SIZE | F_PERMISSIONS | F_ACCESSTIME | F_CREATETIME | F_MODIFYTIME | F_ACL | F_OWNERGROUP | F_SUBSECOND_TIMES | F_EXTENDED (see Net::SFTP::Protocol::V04::Attributes for those constants).
fstat
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/base.rb
MIT
def initialize(name, attributes) @name, @attributes = name, attributes end
Create a new Name object with the given name and attributes.
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/name.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/name.rb
MIT
def longname @longname ||= begin longname = if directory? "d" elsif symlink? "l" else "-" end longname << (attributes.permissions & 0400 != 0 ? "r" : "-") longname << (attributes.permissions & 0200 != 0 ? "w" : "-") longname << (attributes.permissions & 0100 != 0 ? "x" : "-") longname << (attributes.permissions & 0040 != 0 ? "r" : "-") longname << (attributes.permissions & 0020 != 0 ? "w" : "-") longname << (attributes.permissions & 0010 != 0 ? "x" : "-") longname << (attributes.permissions & 0004 != 0 ? "r" : "-") longname << (attributes.permissions & 0002 != 0 ? "w" : "-") longname << (attributes.permissions & 0001 != 0 ? "x" : "-") longname << (" %-8s %-8s %8d " % [attributes.owner, attributes.group, attributes.size]) longname << Time.at(attributes.mtime).strftime("%b %e %H:%M ") longname << name end end
Returns a string representing this file, in a format similar to that used by the unix "ls" utility.
longname
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/name.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/04/name.rb
MIT
def rename(name, new_name, flags=nil) send_request(FXP_RENAME, :string, name, :string, new_name, :long, flags || 0) end
Sends a FXP_RENAME packet to the server to request that the file or directory with the given +name+ (must be a full path) be changed to +new_name+ (which must also be a path). The +flags+ parameter must be either +nil+ or 0 (the default), or some combination of the Net::SFTP::Constants::RenameFlags constants.
rename
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/05/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/05/base.rb
MIT
def open(path, flags, options) flags = normalize_open_flags(flags) sftp_flags, desired_access = if flags & (IO::WRONLY | IO::RDWR) != 0 open = if flags & (IO::CREAT | IO::EXCL) == (IO::CREAT | IO::EXCL) FV5::CREATE_NEW elsif flags & (IO::CREAT | IO::TRUNC) == (IO::CREAT | IO::TRUNC) FV5::CREATE_TRUNCATE elsif flags & IO::CREAT == IO::CREAT FV5::OPEN_OR_CREATE else FV5::OPEN_EXISTING end access = ACE::Mask::WRITE_DATA | ACE::Mask::WRITE_ATTRIBUTES access |= ACE::Mask::READ_DATA | ACE::Mask::READ_ATTRIBUTES if (flags & IO::RDWR) == IO::RDWR if flags & IO::APPEND == IO::APPEND open |= FV5::APPEND_DATA access |= ACE::Mask::APPEND_DATA end [open, access] else [FV5::OPEN_EXISTING, ACE::Mask::READ_DATA | ACE::Mask::READ_ATTRIBUTES] end attributes = attribute_factory.new(options) send_request(FXP_OPEN, :string, path, :long, desired_access, :long, sftp_flags, :raw, attributes.to_s) end
Sends a FXP_OPEN packet to the server and returns the packet identifier. The +flags+ parameter is either an integer (in which case it must be a combination of the IO constants) or a string (in which case it must be one of the mode strings that IO::open accepts). The +options+ parameter is a hash that is used to construct a new Attribute object, to pass as part of the FXP_OPEN request.
open
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/05/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/05/base.rb
MIT
def link(new_link_path, existing_path, symlink) send_request(FXP_LINK, :string, new_link_path, :string, existing_path, :bool, symlink) end
Sends a FXP_LINK packet to the server to request that a link be created at +new_link_path+, pointing to +existing_path+. If +symlink+ is true, a symbolic link will be created; otherwise a hard link will be created.
link
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/06/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/06/base.rb
MIT
def symlink(path, target) link(path, target, true) end
Provided for backwards compatibility; v6 of the SFTP protocol removes the older FXP_SYMLINK packet type, so this method simply calls the #link method.
symlink
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/06/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/06/base.rb
MIT
def block(handle, offset, length, mask) send_request(FXP_BLOCK, :string, handle, :int64, offset, :int64, length, :long, mask) end
Sends a FXP_BLOCK packet to the server to request that a byte-range lock be obtained on the given +handle+, for the given byte +offset+ and +length+. The +mask+ parameter is a bitfield indicating what kind of lock to acquire, and must be a combination of one or more of the Net::SFTP::Constants::LockTypes constants.
block
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/06/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/06/base.rb
MIT
def unblock(handle, offset, length) send_request(FXP_UNBLOCK, :string, handle, :int64, offset, :int64, length) end
Sends a FXP_UNBLOCK packet to the server to request that a previously acquired byte-range lock be released on the given +handle+, for the given byte +offset+ and +length+. The +handle+, +offset+, and +length+ must all exactly match the parameters that were given when the lock was originally acquired (see #block).
unblock
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/06/base.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/net/sftp/protocol/06/base.rb
MIT
def initialize(ssh,opts={}) init_ssh(ssh, opts) end
Initializes the ssh context with the supplied ssh instance which communication with the server will be performed.
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client.rb
MIT
def cleanup_ssh self.fs.sftp.cleanup unless self.fs.nil? or self.fs.sftp.nil? ext.aliases.each_value do | extension | extension.cleanup if extension.respond_to?( 'cleanup' ) end self.thread.kill self.ssh.close end
Cleans up the meterpreter instance, terminating the dispatcher thread.
cleanup_ssh
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client.rb
MIT
def add_extension(name) # Check to see if this extension has already been loaded. if ((klass = self.class.check_ext_hash(name.downcase)) == nil) old = Rex::Post::MetaSSH.constants require("rex/post/meta_ssh/extensions/#{name.downcase}/#{name.downcase}") new = Rex::Post::MetaSSH.constants # No new constants added? if ((diff = new - old).empty?) diff = [ name.capitalize ] end klass = Rex::Post::MetaSSH::Extensions.const_get(diff[0]).const_get(diff[0]) # Save the module name to class association now that the code is # loaded. self.class.set_ext_hash(name.downcase, klass) end # Create a new instance of the extension inst = klass.new(self) self.ext.aliases[inst.name] = inst return true end
# Extension registration # Loads the client half of the supplied extension and initializes it as a registered extension that can be reached through client.ext.[extension].
add_extension
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client.rb
MIT
def register_extension_alias(name, ext) self.ext_aliases.aliases[name] = ext end
Registers an aliased extension that can be referenced through client.name.
register_extension_alias
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client.rb
MIT
def register_extension_aliases(aliases) aliases.each { |a| register_extension_alias(a['name'], a['ext']) } end
Registers zero or more aliases that are provided in an array.
register_extension_aliases
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client.rb
MIT
def initialize(client) super(client, "core") end
Initializes the 'core' portion of the meterpreter client commands.
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client_core.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/client_core.rb
MIT
def initialize(client, name) self.client = client self.name = name end
Initializes the client and name attributes.
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extension.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extension.rb
MIT
def dump_alias_tree(parent_path, current = nil) items = [] if (current == nil) current = self end # If the current object may have object aliases... if (current.kind_of?(Rex::Post::MetaSSH::ObjectAliases)) current.aliases.each_key { |x| current_path = parent_path + '.' + x items << current_path items.concat(dump_alias_tree(current_path, current.aliases[x])) } end return items end
Recursively dumps all of the aliases registered with a class that is kind_of? ObjectAliases.
dump_alias_tree
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/object_aliases.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/object_aliases.rb
MIT
def initialize(client) super(client, 'stdapi') # Alias the following things on the client object so that they # can be directly referenced client.register_extension_aliases( [ { 'name' => 'net', 'ext' => ObjectAliases.new( { 'socket' => Rex::Post::MetaSSH::Extensions::Stdapi::Net::Socket.new(client) }) }, { 'name' => 'fs', 'ext' => ObjectAliases.new( { 'sftp' => Rex::Post::MetaSSH::Extensions::Stdapi::Fs::Sftp.new(client), 'file' => self.file, 'filestat' => self.file_stat, 'dir' => self.dir }) }, { 'name' => 'sys', 'ext' => Rex::Post::MetaSSH::Extensions::Stdapi::Sys.new(client) }, ]) end
Initializes an instance of the standard API extension.
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/stdapi.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/stdapi.rb
MIT
def brand(klass) klass = klass.dup klass.client = self.client return klass end
Sets the client instance on a duplicated copy of the supplied class.
brand
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/stdapi.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/stdapi.rb
MIT
def each(&block) client.fs.sftp.dir.foreach(self.path, &block) end
# Enumeration # Enumerates all of the contents of the directory.
each
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/dir.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/dir.rb
MIT
def initialize(name, mode = "r", perms = nil) self.client = self.class.client begin self.filed = _open(name, mode, perms) rescue Net::SFTP::StatusException => e case e.code when Net::SFTP::Constants::StatusCodes::FX_NO_SUCH_FILE raise Errno::ENOENT when Net::SFTP::Constants::StatusCodes::FX_PERMISSION_DENIED raise Errno::EACCES else raise e end end end
# Constructor # Initializes and opens the specified file with the specified permissions.
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file.rb
MIT
def eof return self.filed.eof? end
# IO implementators # Returns whether or not the file has reach EOF.
eof
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file.rb
MIT
def pos return self.filed.pos end
Returns the current position of the file pointer.
pos
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file.rb
MIT
def sysseek(offset, whence = SEEK_SET) case whence when SEEK_SET new_pos=offset when SEEK_CUR new_pos=offset+pos when SEEK_END new_pos=self.stat.size-offset end self.filed.pos=new_pos return 0 end
Seeks to the supplied offset based on the supplied relativity.
sysseek
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file.rb
MIT
def _open(name, mode = "r", perms = nil) return client.fs.sftp.file.open(client.fs.file.realpath(name,false),mode,perms) end
# Internal methods # Creates a File channel using the supplied information.
_open
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file.rb
MIT
def initialize(file=nil) self.stathash = convert(client.sftp.stat!(client.fs.realpath(file))) if file end
# Constructor # Returns an instance of a FileStat object.
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file_stat.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/file_stat.rb
MIT
def cwd if @cwd.nil? @cwd=self.realpath!(@cwd).name end return @cwd end
SFTP doesn't support the concept of a working directory so we have to hack it in
cwd
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/sftp.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/fs/sftp.rb
MIT
def initialize(client) self.client = client # register the inbound handler for the tcp server channel (allowing us to receive new client connections to a tcp server channel) end
# Constructor # Initialize the socket subsystem and start monitoring sockets as they come in.
initialize
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket.rb
MIT
def create( params ) res = nil if( params.tcp? ) if( params.server? ) res = create_tcp_server_channel( params ) else res = create_tcp_client_channel( params ) end elsif( params.udp? ) res = create_udp_channel( params ) end return res end
# Factory # Creates an arbitrary client socket channel using the information supplied in the socket parameters instance. The 'params' argument is expected to be of type Rex::Socket::Parameters.
create
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket.rb
MIT
def local(*args) if args.length < 3 || args.length > 4 raise ArgumentError, "expected 3 or 4 parameters, got #{args.length}" end bind_address = "127.0.0.1" bind_address = args.shift if args.first.is_a?(String) && args.first =~ /\D/ local_port = args.shift.to_i remote_host = args.shift remote_port = args.shift.to_i socket = TCPServer.new(bind_address, local_port) lport,caddr=nil,nil if (socket.getsockname =~ /127\.0\.0\.1:/) # JRuby ridiculousness caddr, lport = socket.getsockname.split(":") caddr = caddr[1,caddr.length] lport = lport.to_i else # Sane implementations where Socket#getsockname returns a # sockaddr lport, caddr = ::Socket.unpack_sockaddr_in( socket.getsockname ) end @local_forwarded_ports[[lport, caddr]] = socket session.listen_to(socket) do |server| client = server.accept debug { "received connection on #{caddr}:#{lport}" } channel = session.open_channel("direct-tcpip", :string, remote_host, :long, remote_port, :string, caddr, :long, lport) do |achannel| achannel.info { "direct channel established" } end prepare_client(client, channel, :local) channel.on_open_failed do |ch, code, description| channel.error { "could not establish direct channel: #{description} (#{code})" } channel[:socket].close end end socket end
Starts listening for connections on the local host, and forwards them to the specified remote host/port via the SSH connection. This method accepts either three or four arguments. When four arguments are given, they are: * the local address to bind to * the local port to listen on * the remote host to forward connections to * the port on the remote host to connect to If three arguments are given, it is as if the local bind address is "127.0.0.1", and the rest are applied as above. ssh.forward.local(1234, "www.capify.org", 80) ssh.forward.local("0.0.0.0", 1234, "www.capify.org", 80)
local
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket_subsystem/forward_mixin.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket_subsystem/forward_mixin.rb
MIT
def close_write return shutdown(1) end
Closes the write half of the connection.
close_write
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket_subsystem/tcp_client_channel.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket_subsystem/tcp_client_channel.rb
MIT
def shutdown(how = 1) lsock.shutdown(how) return true end
Shutdown the connection 0 -> future reads 1 -> future sends 2 -> both
shutdown
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket_subsystem/tcp_client_channel.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket_subsystem/tcp_client_channel.rb
MIT
def accept( opts={} ) timeout = opts['Timeout'] || -1 if( timeout == -1 ) result = lsock.accept else begin ::Timeout.timeout( timeout ) { result = lsock.accept } rescue Timeout::Error result = nil end end return result end
Accept a new tcp client connection form this tcp server channel. This method will block indefinatly if no timeout is specified.
accept
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket_subsystem/tcp_server_channel.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/extensions/stdapi/net/socket_subsystem/tcp_server_channel.rb
MIT
def interact(&block) init_tab_complete # Run queued commands commands.delete_if { |ent| run_single(ent) true } # Run the interactive loop run { |line| # Run the command run_single(line) # If a block was supplied, call it, otherwise return false if (block) block.call else false end } end
Called when someone wants to interact with the ssh client. It's assumed that init_ui has been called prior.
interact
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console.rb
MIT
def queue_cmd(cmd) self.commands << cmd end
Queues a command to be run when the interactive loop is entered.
queue_cmd
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console.rb
MIT
def run_command(dispatcher, method, arguments) begin super rescue Timeout::Error log_error("Operation timed out.") rescue ::Errno::EPIPE, ::OpenSSL::SSL::SSLError, ::IOError => e log_error("Error running command #{method}: #{e.class} #{e}\n #{e.backtrace.join("\n")}") self.client.kill rescue ::Exception => e log_error("Error running command #{method}: #{e.class} #{e}\n #{e.backtrace.join("\n")}") end end
Runs the specified command wrapper in something to catch meterpreter exceptions.
run_command
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console.rb
MIT
def log_error(msg) print_error(msg) elog(msg, 'meterpreter') dlog("Call stack:\n#{[email protected]("\n")}", 'meterpreter') end
Logs that an error occurred and persists the callstack.
log_error
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console.rb
MIT
def msf_loaded? return @msf_loaded unless @msf_loaded.nil? # if we get here we must not have initialized yet @msf_loaded = !!(client.framework) @msf_loaded end
Returns true if the client has a framework object. Used for firing framework session events
msf_loaded?
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console/command_dispatcher.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console/command_dispatcher.rb
MIT
def _interrupt prompt_yesno("Terminate channel #{self.cid}?") end
Called when an interrupt is sent.
_interrupt
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console/interactive_channel.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console/interactive_channel.rb
MIT
def _interact_complete begin self.interacting=false self.close rescue IOError end end
Closes the channel like it aint no thang.
_interact_complete
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console/interactive_channel.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console/interactive_channel.rb
MIT
def _stream_read_local_write_remote(channel) data = user_input.gets return if not data self.on_command_proc.call(data.strip) if self.on_command_proc self.write(data) end
Reads data from local input and writes it remotely.
_stream_read_local_write_remote
ruby
hahwul/mad-metasploit
mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console/interactive_channel.rb
https://github.com/hahwul/mad-metasploit/blob/master/mad-metasploit-plugins/meta_ssh/lib/rex/post/meta_ssh/ui/console/interactive_channel.rb
MIT