Skip to content

Instantly share code, notes, and snippets.

@marcwickenden
Created February 1, 2012 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcwickenden/1719670 to your computer and use it in GitHub Desktop.
Save marcwickenden/1719670 to your computer and use it in GitHub Desktop.
stat_file method added to lib/msf/core/post/file.rb
def stat_file(file_name)
data = []
stat = {}
if session.type == "meterpreter"
raise "I think you can do this with session.fs.file.stat"
elsif session.respond_to? :shell_command_token
print_debug("platform is #{session.platform}")
case session.platform
when /windows/
raise "Windows platform not supported"
when /linux/
# make stat output *almost* like OSX - some of these are just guessed or padded
stat_cmd = "/usr/bin/stat -c \"%d %i %A %h %U %G %s %t %X %X %Y %Z %b %d %D %n\""
when /osx/
# OSX stat gives us less options so we make Linux like this
stat_cmd = "/usr/bin/stat -t %s"
end
end
data = session.shell_command_token("#{stat_cmd} \'#{file_name}\'").split
stat = { 'file_name' => data[15],
'user' => data[4],
'group' => data[5],
'inode' => data[1],
'a_time' => data[9],
'm_time' => data[10],
'c_time' => data[11]
}
stat
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment