Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion impacket/smb3.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import random
import string
import struct
import os
from six import indexbytes, b
from binascii import a2b_hex
from contextlib import contextmanager
Expand All @@ -50,6 +51,7 @@
STATUS_NO_MORE_FILES, STATUS_PENDING, STATUS_NOT_IMPLEMENTED, ERROR_MESSAGES
from impacket.spnego import SPNEGO_NegTokenInit, TypesMech, SPNEGO_NegTokenResp, ASN1_OID, asn1encode, ASN1_AID
from impacket.krb5.gssapi import KRB5_AP_REQ
from impacket.krb5.ccache import CCache


# For signing
Expand Down Expand Up @@ -690,7 +692,7 @@ def getCredentials(self):
self.__TGT,
self.__TGS)

def kerberosLogin(self, user, password, domain = '', lmhash = '', nthash = '', aesKey='', kdcHost = '', TGT=None, TGS=None, mutualAuth=False):
def kerberosLogin(self, user, password, domain = '', lmhash = '', nthash = '', aesKey='', kdcHost = '', TGT=None, TGS=None, mutualAuth=False, update_ccache=True):
# If TGT or TGS are specified, they are in the form of:
# TGS['KDC_REP'] = the response from the server
# TGS['cipher'] = the cipher used
Expand Down Expand Up @@ -762,6 +764,10 @@ def kerberosLogin(self, user, password, domain = '', lmhash = '', nthash = '', a
if TGS is None:
serverName = Principal('cifs/%s' % (self._Connection['ServerName']), type=constants.PrincipalNameType.NT_SRV_INST.value)
tgs, cipher, oldSessionKey, sessionKey = getKerberosTGS(serverName, domain, kdcHost, tgt, cipher, sessionKey)
if update_ccache and os.getenv('KRB5CCNAME'):
ccache = CCache.loadFile(os.getenv('KRB5CCNAME'))
ccache.fromTGS(tgs, oldSessionKey, sessionKey)
ccache.saveFile(os.getenv('KRB5CCNAME'), chmod=0o600)
else:
tgs = TGS['KDC_REP']
cipher = TGS['cipher']
Expand Down