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
8 from optparse
import OptionParser
10 sys
.path
.insert(0, "bin/python")
12 import samba
.getopt
as options
13 from samba
.dcerpc
import drsuapi
, misc
16 '''make a DsBind call, returning the binding handle'''
17 bind_info
= drsuapi
.DsBindInfoCtr()
19 bind_info
.info
= drsuapi
.DsBindInfo28()
20 bind_info
.info
.supported_extensions
= 0
21 (info
, handle
) = drs
.DsBind(misc
.GUID(drsuapi
.DRSUAPI_DS_BIND_GUID
), bind_info
)
25 ########### main code ###########
26 if __name__
== "__main__":
27 parser
= OptionParser("crackname server [options]")
28 sambaopts
= options
.SambaOptions(parser
)
29 parser
.add_option_group(sambaopts
)
30 credopts
= options
.CredentialsOptionsDouble(parser
)
31 parser
.add_option_group(credopts
)
33 parser
.add_option("", "--name", type='str',
34 default
='{ED9F5546-9729-4B04-9385-3FCFE2B17BA1}', help="name to crack")
35 parser
.add_option("", "--outformat", type='int',
36 default
=drsuapi
.DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
37 help='format desired')
38 parser
.add_option("", "--informat", type='int',
39 default
=drsuapi
.DRSUAPI_DS_NAME_FORMAT_GUID
,
40 help='format offered')
42 (opts
, args
) = parser
.parse_args()
44 lp
= sambaopts
.get_loadparm()
45 creds
= credopts
.get_credentials(lp
)
48 parser
.error("You must supply a server")
50 if creds
.is_anonymous():
51 parser
.error("You must supply credentials")
55 binding_str
= "ncacn_ip_tcp:%s[seal,print]" % server
57 drs
= drsuapi
.drsuapi(binding_str
, lp
, creds
)
58 drs_handle
= do_DsBind(drs
)
59 print "DRS Handle: %s" % drs_handle
61 req
= drsuapi
.DsNameRequest1()
62 names
= drsuapi
.DsNameString()
68 req
.format_offered
= opts
.informat
69 req
.format_desired
= opts
.outformat
73 (result
, ctr
) = drs
.DsCrackNames(drs_handle
, 1, req
)
74 print "# of result = %d" %ctr
.count
76 print "status = %d" % ctr
.array
[0].status
77 print "result name = %s" % ctr
.array
[0].result_name
78 print "domain = %s" % ctr
.array
[0].dns_domain_name