Skip to content

Commit ac04b8d

Browse files
David MaloneyDavid Maloney
authored andcommitted
a little bit of cleanup
constantise some of the magic numbers in the NTDS Account class MSP-12358
1 parent 9279926 commit ac04b8d

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

lib/metasploit/framework/ntds/account.rb

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ module NTDS
55
# priv extension.
66
class Account
77

8+
# Size of an NTDS Account Struct on the Wire
9+
ACCOUNT_SIZE = 3948
10+
# Size of a Date or Time Format String on the Wire
11+
DATE_TIME_STRING_SIZE = 30
12+
# Size of the AccountDescription Field
13+
DESCRIPTION_SIZE =2048
14+
# Size of a Hash History Record
15+
HASH_HISTORY_SIZE = 792
16+
# Size of a Hash String
17+
HASH_SIZE = 33
18+
# Size of the samAccountName field
19+
NAME_SIZE = 40
20+
821
#@return [String] The AD Account Description
922
attr_accessor :description
1023
#@return [Boolean] If the AD account is disabled
@@ -52,10 +65,10 @@ class Account
5265
# @raise [ArgumentErrror] if a 3948 byte string is not supplied
5366
def initialize(raw_data)
5467
raise ArgumentError, "No Data Supplied" unless raw_data.present?
55-
raise ArgumentError, "Invalid Data" unless raw_data.length == 3948
68+
raise ArgumentError, "Invalid Data" unless raw_data.length == ACCOUNT_SIZE
5669
data = raw_data.dup
57-
@name = get_string(data,40)
58-
@description = get_string(data,2048)
70+
@name = get_string(data,NAME_SIZE)
71+
@description = get_string(data,DESCRIPTION_SIZE)
5972
@rid = get_int(data)
6073
@disabled = get_boolean(data)
6174
@locked = get_boolean(data)
@@ -65,13 +78,13 @@ def initialize(raw_data)
6578
@logon_count = get_int(data)
6679
@nt_history_count = get_int(data)
6780
@lm_history_count = get_int(data)
68-
@expiry_date = get_string(data,30)
69-
@logon_date = get_string(data,30)
70-
@logon_time = get_string(data,30)
71-
@pass_date = get_string(data,30)
72-
@pass_time = get_string(data,30)
73-
@lm_hash = get_string(data,33)
74-
@nt_hash = get_string(data,33)
81+
@expiry_date = get_string(data,DATE_TIME_STRING_SIZE)
82+
@logon_date = get_string(data,DATE_TIME_STRING_SIZE)
83+
@logon_time = get_string(data,DATE_TIME_STRING_SIZE)
84+
@pass_date = get_string(data,DATE_TIME_STRING_SIZE)
85+
@pass_time = get_string(data,DATE_TIME_STRING_SIZE)
86+
@lm_hash = get_string(data,HASH_SIZE)
87+
@nt_hash = get_string(data,HASH_SIZE)
7588
@lm_history = get_hash_history(data)
7689
@nt_history = get_hash_history(data)
7790
@sid = data
@@ -113,7 +126,7 @@ def get_boolean(data)
113126
end
114127

115128
def get_hash_history(data)
116-
raw_history = data.slice!(0,792)
129+
raw_history = data.slice!(0,HASH_HISTORY_SIZE)
117130
split_history = raw_history.scan(/.{1,33}/)
118131
split_history.map!{ |hash| hash.gsub(/\x00/,'')}
119132
split_history.reject!{ |hash| hash.blank? }

modules/post/windows/gather/credentials/domain_hashdump.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,11 @@ def domain_name
7272
end
7373

7474
def is_domain_controller?
75-
status = false
76-
if session.fs.file.exists?('%SystemDrive%\Windows\ntds\ntds.dit')
77-
status = true
78-
end
79-
status
75+
session.fs.file.exists?('%SystemDrive%\Windows\ntds\ntds.dit')
8076
end
8177

8278
def ntdsutil_method
79+
get_env
8380
tmp_path = "#{expand_path("%TEMP%")}\\#{Rex::Text.rand_text_alpha((rand(8)+6))}"
8481
command_arguments = "\"activate instance ntds\" \"ifm\" \"Create Full #{tmp_path}\" quit quit"
8582
result = cmd_exec("ntdsutil.exe", command_arguments)

0 commit comments

Comments
 (0)