3 # Copyright Matthieu Patou <mat@matws.net> 2011
4 # script to call a DRSUAPI crackname
5 # this is useful for plugfest testing and replication debug
7 from optparse import OptionParser
9 sys.path.insert(0, "bin/python")
11 import samba.getopt as options
12 from samba.dcerpc import drsuapi, misc
15 '''make a DsBind call, returning the binding handle'''
16 bind_info = drsuapi.DsBindInfoCtr()
18 bind_info.info = drsuapi.DsBindInfo28()
19 bind_info.info.supported_extensions = 0
20 (info, handle) = drs.DsBind(misc.GUID(drsuapi.DRSUAPI_DS_BIND_GUID), bind_info)
24 ########### main code ###########
25 if __name__ == "__main__":
26 parser = OptionParser("crackname server [options]")
27 sambaopts = options.SambaOptions(parser)
28 parser.add_option_group(sambaopts)
29 credopts = options.CredentialsOptionsDouble(parser)
30 parser.add_option_group(credopts)
32 parser.add_option("", "--name", type='str',
33 default='{ED9F5546-9729-4B04-9385-3FCFE2B17BA1}', help="name to crack")
34 parser.add_option("", "--outformat", type='int',
35 default=drsuapi.DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
36 help='format desired')
37 parser.add_option("", "--informat", type='int',
38 default=drsuapi.DRSUAPI_DS_NAME_FORMAT_GUID,
39 help='format offered')
41 (opts, args) = parser.parse_args()
43 lp = sambaopts.get_loadparm()
44 creds = credopts.get_credentials(lp)
47 parser.error("You must supply a server")
49 if creds.is_anonymous():
50 parser.error("You must supply credentials")
54 binding_str = "ncacn_ip_tcp:%s[seal,print]" % server
56 drs = drsuapi.drsuapi(binding_str, lp, creds)
57 drs_handle = do_DsBind(drs)
58 print("DRS Handle: %s" % drs_handle)
60 req = drsuapi.DsNameRequest1()
61 names = drsuapi.DsNameString()
67 req.format_offered = opts.informat
68 req.format_desired = opts.outformat
72 (result, ctr) = drs.DsCrackNames(drs_handle, 1, req)
73 print("# of result = %d" %ctr.count)
75 print("status = %d" % ctr.array[0].status)
76 print("result name = %s" % ctr.array[0].result_name)
77 print("domain = %s" % ctr.array[0].dns_domain_name)