Esempio n. 1
0
 def test_initKEXHash(self):
     netPackets = pcapReader.openPCAPFile(pcapPath)
     ikePackets = pcapReader.getISAKMPPackets(netPackets)
     initSAPacket = ikeParser.getIniatorSAPacket(ikePackets)
     initKEX = ikeParser.getPayloadFromISAKMP(initSAPacket,ikeParser.ISAKMP_KEX_NAME)
     initKEXHash  = sha256(initKEX).hexdigest()
     self.assertEqual(initKEXHash, TestStringMethods.initKEXHash)
Esempio n. 2
0
 def test_respKEXHash(self):
     netPackets = pcapReader.openPCAPFile(pcapPath)
     ikePackets = pcapReader.getISAKMPPackets(netPackets)
     respSAPacket = ikeParser.getResponderSAPacket(ikePackets)
     respKEX = ikeParser.getPayloadFromISAKMP(respSAPacket,ikeParser.ISAKMP_KEX_NAME)
     respKEXHash  = sha256(respKEX).hexdigest()
     self.assertEqual(respKEXHash, TestStringMethods.respKEXHash)
Esempio n. 3
0
 def test_initCookieHash(self):
     netPackets = pcapReader.openPCAPFile(pcapPath)
     ikePackets = pcapReader.getISAKMPPackets(netPackets)
     initSAPacket = ikeParser.getIniatorSAPacket(ikePackets)
     initCookie = ikeParser.getCookieFromISAKMP(respSAPacket,False)
     initCookieHash  = sha256(initCookie).hexdigest()
     self.assertEqual(initCookieHash, TestStringMethods.initCookieHash)
Esempio n. 4
0
 def test_respCookieHash(self):
     netPackets = pcapReader.openPCAPFile(pcapPath)
     ikePackets = pcapReader.getISAKMPPackets(netPackets)
     respSAPacket = ikeParser.getResponderSAPacket(ikePackets)
     respCookie = ikeParser.getCookieFromISAKMP(respSAPacket, True)
     respCookieHash  = sha256(respCookie).hexdigest()
     self.assertEqual(respCookieHash, TestStringMethods.respCookieHash)
Esempio n. 5
0
 def test_respIDHash(self):
     netPackets = pcapReader.openPCAPFile(pcapPath)
     ikePackets = pcapReader.getISAKMPPackets(netPackets)
     respSAPacket = ikeParser.getResponderSAPacket(ikePackets)
     respID = ikeParser.getResponderIDFromRespPacket(respSAPacket)
     respIDHash = sha256(respID).hexdigest()
     self.assertEqual(respIDHash, TestStringMethods.respIDHash)
Esempio n. 6
0
 def test_SAPayloadHash(self):
     netPackets = pcapReader.openPCAPFile(pcapPath)
     ikePackets = pcapReader.getISAKMPPackets(netPackets)
     initSAPacket = ikeParser.getIniatorSAPacket(ikePackets)
     SAPayload = ikeParser.getSAPayloadFromInitPacket(initSAPacket)
     SAPayloadHash = sha256(SAPayload).hexdigest()
     self.assertEqual(SAPayloadHash, TestStringMethods.SAPayloadHash)
Esempio n. 7
0
 def test_targetHash(self):
     netPackets = pcapReader.openPCAPFile(pcapPath)
     ikePackets = pcapReader.getISAKMPPackets(netPackets)
     respSAPacket = ikeParser.getResponderSAPacket(ikePackets)
     targetHash = ikeParser.getRespHashfromPacket(respSAPacket)
     hashTargetHash = sha256(targetHash).hexdigest()
     self.assertEqual(hashTargetHash, TestStringMethods.hashTargetHash)
Esempio n. 8
0
 def test_initSAPacket(self):
     netPackets = pcapReader.openPCAPFile(pcapPath)
     ikePackets = pcapReader.getISAKMPPackets(netPackets)
     initSAPacket = ikeParser.getIniatorSAPacket(ikePackets)
     initHash = sha256(raw(initSAPacket)).hexdigest()
     self.assertEqual(initHash, TestStringMethods.initSAPacketHash)
Esempio n. 9
0
    return hexlify(byteStr)

def computeKeyFromValues(values):
    # value-tuple: 0 = pskIR, 1 = nI, 2 = nR
    return hmac.new(values[0], msg = values[1] + values[2], digestmod = hashlib.sha1).digest()

def computeHashRFromValues(values):
    # value-tuple: 0 = k, 1 = gY, 2 = gX, 3 = ckyR, 4 = ckyI, 5 = SAI, 6 = IDR):
    valueSum = values[1] + values[2] + values[3] + values[4]+ values[5] + values[6]
    return hmac.new(values[0], valueSum, digestmod = hashlib.sha1).digest()


if __name__ == '__main__':

    # 1. open pcap
    packets = pcapReader.getISAKMPPackets(pcapReader.openPCAPFile(pcapPath))

    # 2. get required values
    initSAPacket = packets[0]
    respSAPacket = packets[1]
    nI = ikeParser.getPayloadFromISAKMP(initSAPacket, "ISAKMP_payload_Nonce")
    nR = ikeParser.getPayloadFromISAKMP(respSAPacket, "ISAKMP_payload_Nonce")
    gY = ikeParser.getPayloadFromISAKMP(respSAPacket, "ISAKMP_payload_KE")
    gX = ikeParser.getPayloadFromISAKMP(initSAPacket, "ISAKMP_payload_KE")
    ckyR = ikeParser.getCookieFromISAKMP(respSAPacket, True)
    ckyI = ikeParser.getCookieFromISAKMP(respSAPacket, False)
    SAI = ikeParser.getSAPayloadFromInitPacket(initSAPacket)
    IDR = ikeParser.getResponderIDFromRespPacket(respSAPacket)
    knownCiphertext = ikeParser.getPayloadFromISAKMP(respSAPacket, "ISAKMP_payload_Hash")

    # 3. read dict line by line