Skip to content

Commit f58b66a

Browse files
committed
Docs and more robust code
1 parent f5c401b commit f58b66a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/msf/core/post/windows/accounts.rb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ module Accounts
2424
['ClientSiteName',:LPSTR]
2525
]
2626

27+
##
28+
# get_domain(server_name=nil)
29+
#
30+
# Summary:
31+
# Retrieves the current DomainName the given server is
32+
# a member of.
33+
#
34+
# Parameters
35+
# server_name - DNS or NetBIOS name of the remote server
36+
# Returns:
37+
# The DomainName of the remote server or nil if windows
38+
# could not retrieve the DomainControllerInfo or encountered
39+
# an exception.
40+
#
41+
##
2742
def get_domain(server_name=nil)
2843
domain = nil
2944
result = session.railgun.netapi32.DsGetDcNameA(
@@ -36,14 +51,16 @@ def get_domain(server_name=nil)
3651

3752
begin
3853
dc_info_addr = result['DomainControllerInfo']
39-
dc_info = session.railgun.util.read_data(DOMAIN_CONTROLLER_INFO, dc_info_addr)
40-
pointer = session.railgun.util.unpack_pointer(dc_info['DomainName'])
41-
domain = session.railgun.util.read_string(pointer)
54+
unless dc_info_addr == 0
55+
dc_info = session.railgun.util.read_data(DOMAIN_CONTROLLER_INFO, dc_info_addr)
56+
pointer = session.railgun.util.unpack_pointer(dc_info['DomainName'])
57+
domain = session.railgun.util.read_string(pointer)
58+
end
4259
ensure
4360
session.railgun.netapi32.NetApiBufferFree(dc_info_addr)
4461
end
4562

46-
return domain
63+
domain
4764
end
4865

4966
##

0 commit comments

Comments
 (0)