Skip to content

Commit a0e0476

Browse files
author
Brent Cook
committed
rewrite timestomp command dispatcher to deal with file args properly
1 parent 1e8edb3 commit a0e0476

File tree

1 file changed

+78
-59
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/priv

1 file changed

+78
-59
lines changed

lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/timestomp.rb

Lines changed: 78 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module Ui
1313
#
1414
###
1515
class Console::CommandDispatcher::Priv::Timestomp
16-
1716
Klass = Console::CommandDispatcher::Priv::Timestomp
1817

1918
include Console::CommandDispatcher
@@ -28,7 +27,8 @@ class Console::CommandDispatcher::Priv::Timestomp
2827
"-b" => [ false, "Set the MACE timestamps so that EnCase shows blanks" ],
2928
"-r" => [ false, "Set the MACE timestamps recursively on a directory" ],
3029
"-v" => [ false, "Display the UTC MACE values of the file" ],
31-
"-h" => [ false, "Help banner" ])
30+
"-h" => [ false, "Help banner" ]
31+
)
3232

3333
#
3434
# List of supported commands.
@@ -51,91 +51,110 @@ def name
5151
# line timestomp interface provides with a similar argument set.
5252
#
5353
def cmd_timestomp(*args)
54-
if (args.length < 2)
55-
print_line("\nUsage: timestomp OPTIONS file_path\n" +
54+
if args.length < 2
55+
print_line("\nUsage: timestomp <file(s)> OPTIONS\n" +
5656
@@timestomp_opts.usage)
5757
return
5858
end
5959

60-
file_path = nil
61-
args.each { |a| file_path = a unless a[0] == "-" }
62-
63-
if file_path.nil?
64-
print_line("\nNo file_path specified.")
65-
return
66-
end
67-
68-
args.delete(file_path)
60+
paths = []
6961

7062
modified = nil
7163
accessed = nil
7264
creation = nil
7365
emodified = nil
7466

75-
@@timestomp_opts.parse(args) { |opt, idx, val|
67+
blank_file_mace = false
68+
blank_directory_mace = false
69+
get_file_mace = false
70+
71+
@@timestomp_opts.parse(args) do |opt, _idx, val|
7672
case opt
77-
when "-m"
78-
modified = str_to_time(val)
79-
when "-a"
80-
accessed = str_to_time(val)
81-
when "-c"
82-
creation = str_to_time(val)
83-
when "-e"
84-
emodified = str_to_time(val)
85-
when "-z"
86-
print_line("#{val}")
87-
modified = str_to_time(val)
88-
accessed = str_to_time(val)
89-
creation = str_to_time(val)
90-
emodified = str_to_time(val)
91-
when "-f"
92-
print_status("Setting MACE attributes on #{file_path} from #{val}")
93-
client.priv.fs.set_file_mace_from_file(file_path, val)
94-
when "-b"
95-
print_status("Blanking file MACE attributes on #{file_path}")
96-
client.priv.fs.blank_file_mace(file_path)
97-
when "-r"
98-
print_status("Blanking directory MACE attributes on #{file_path}")
99-
client.priv.fs.blank_directory_mace(file_path)
100-
when "-v"
101-
hash = client.priv.fs.get_file_mace(file_path)
102-
103-
print_line("Modified : #{hash['Modified']}")
104-
print_line("Accessed : #{hash['Accessed']}")
105-
print_line("Created : #{hash['Created']}")
106-
print_line("Entry Modified: #{hash['Entry Modified']}")
107-
when "-h"
108-
print_line("\nUsage: timestomp file_path OPTIONS\n" +
109-
@@timestomp_opts.usage)
110-
return
73+
when "-m"
74+
modified = str_to_time(val)
75+
when "-a"
76+
accessed = str_to_time(val)
77+
when "-c"
78+
creation = str_to_time(val)
79+
when "-e"
80+
emodified = str_to_time(val)
81+
when "-z"
82+
modified = str_to_time(val)
83+
accessed = str_to_time(val)
84+
creation = str_to_time(val)
85+
emodified = str_to_time(val)
86+
when "-f"
87+
print_status("Setting MACE attributes on #{path} from #{val}")
88+
hash = client.priv.fs.get_file_mace(path)
89+
if hash
90+
modified = str_to_time(hash['Modified'])
91+
accessed = str_to_time(hash['Accessed'])
92+
creation = str_to_time(hash['Created'])
93+
emodified = str_to_time(hash['Entry Modified'])
94+
end
95+
when "-b"
96+
blank_file_mace = true
97+
when "-r"
98+
blank_directory_mace = true
99+
when "-v"
100+
get_file_mace = true
101+
when "-h"
102+
print_line("\nUsage: timestomp <file(s)> OPTIONS\n" +
103+
@@timestomp_opts.usage)
104+
return nil
105+
when nil
106+
paths << val
107+
end
108+
end
109+
110+
if paths.empty?
111+
print_line("\nNo paths specified.")
112+
return
113+
end
114+
115+
paths.uniq.each do |path|
116+
# If any one of the four times were specified, change them.
117+
if modified || accessed || creation || emodified
118+
print_status("Setting specific MACE attributes on #{path}")
119+
client.priv.fs.set_file_mace(path, modified, accessed, creation, emodified)
120+
end
121+
122+
if blank_file_mace
123+
print_status("Blanking file MACE attributes on #{path}")
124+
client.priv.fs.blank_file_mace(path)
111125
end
112-
}
113126

114-
# If any one of the four times were specified, change them.
115-
if (modified or accessed or creation or emodified)
116-
print_status("Setting specific MACE attributes on #{file_path}")
117-
client.priv.fs.set_file_mace(file_path, modified, accessed,
118-
creation, emodified)
127+
if blank_directory_mace
128+
print_status("Blanking directory MACE attributes on #{path}")
129+
client.priv.fs.blank_directory_mace(path)
130+
end
131+
132+
if get_file_mace
133+
hash = client.priv.fs.get_file_mace(path)
134+
print_status("Showing MACE attributes for #{path}")
135+
print_line("Modified : #{hash['Modified']}")
136+
print_line("Accessed : #{hash['Accessed']}")
137+
print_line("Created : #{hash['Created']}")
138+
print_line("Entry Modified: #{hash['Entry Modified']}")
139+
end
119140
end
120141
end
121142

122-
protected
143+
protected
123144

124145
#
125146
# Converts a date/time in the form of MM/DD/YYYY HH24:MI:SS
126147
#
127148
def str_to_time(str) # :nodoc:
128-
r, mon, day, year, hour, min, sec = str.match("^(\\d+?)/(\\d+?)/(\\d+?) (\\d+?):(\\d+?):(\\d+?)$").to_a
149+
_r, mon, day, year, hour, min, sec = str.match("^(\\d+?)/(\\d+?)/(\\d+?) (\\d+?):(\\d+?):(\\d+?)$").to_a
129150

130-
if (mon == nil)
151+
if mon.nil?
131152
raise ArgumentError, "Invalid date format, expected MM/DD/YYYY HH24:MI:SS (got #{str})"
132153
end
133154

134155
Time.mktime(year, mon, day, hour, min, sec, 0)
135156
end
136-
137157
end
138-
139158
end
140159
end
141160
end

0 commit comments

Comments
 (0)