2006-08-07 19:23:30 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Test script to execute multi-protocol attacks on some test set.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import Scyther
|
|
|
|
|
2006-08-08 14:03:02 +01:00
|
|
|
def MyScyther(protocollist,filter=None):
|
|
|
|
"""
|
|
|
|
Evaluate the composition of the protocols in protocollist.
|
|
|
|
If there is a filter, i.e. "ns3,I1" then only this specific claim
|
|
|
|
will be evaluated.
|
|
|
|
"""
|
2006-08-07 19:23:30 +01:00
|
|
|
s = Scyther.Scyther()
|
2006-08-08 14:03:02 +01:00
|
|
|
s.options = "--match=2"
|
|
|
|
if filter:
|
|
|
|
s.options += " --filter=%s" % (filter)
|
2006-08-07 19:23:30 +01:00
|
|
|
for protocol in protocollist:
|
|
|
|
s.addFile(protocol)
|
|
|
|
s.verify()
|
|
|
|
return s
|
|
|
|
|
|
|
|
def getCorrectIsolatedClaims(protocolset):
|
|
|
|
"""
|
|
|
|
Given a set of protocols, determine the correct claims when run in
|
|
|
|
isolation.
|
2006-08-08 14:03:02 +01:00
|
|
|
Returns a tuple, consisting of
|
|
|
|
- a list of compiling protocols
|
|
|
|
- a list of tuples (protocol,claimid) wich denote correct claims
|
2006-08-07 19:23:30 +01:00
|
|
|
"""
|
2006-08-08 14:03:02 +01:00
|
|
|
correctclaims = []
|
|
|
|
goodprotocols = []
|
2006-08-07 19:23:30 +01:00
|
|
|
for protocol in protocolset:
|
|
|
|
# verify protocol in isolation
|
|
|
|
s = MyScyther([protocol])
|
|
|
|
# investigate the results
|
2006-08-08 14:03:02 +01:00
|
|
|
if not s.errors:
|
|
|
|
goodprotocols.append(protocol)
|
|
|
|
for claim in s.claims:
|
|
|
|
if claim.okay:
|
|
|
|
correctclaims.append((protocol,claim.id))
|
|
|
|
return (goodprotocols,correctclaims)
|
2006-08-07 19:23:30 +01:00
|
|
|
|
|
|
|
def findMPA(protocolset,protocol,claimid,maxcount=3):
|
|
|
|
"""
|
|
|
|
The protocol claim is assumed to be correct. When does it break?
|
|
|
|
"""
|
|
|
|
count = 2
|
2006-08-08 14:03:02 +01:00
|
|
|
if len(protocolset) < maxcount:
|
|
|
|
maxcount = len(protocolset)
|
2006-08-07 19:23:30 +01:00
|
|
|
|
|
|
|
def verifyMPAlist(mpalist):
|
|
|
|
# This should be a more restricted verification
|
2006-08-08 14:03:02 +01:00
|
|
|
s = MyScyther(mpalist,claimid)
|
2006-08-07 19:23:30 +01:00
|
|
|
cl = s.getClaim(claimid)
|
|
|
|
if cl:
|
|
|
|
if not cl.okay:
|
|
|
|
# This is an MPA attack!
|
2006-08-08 14:03:02 +01:00
|
|
|
print "I've found a multi-protocol attack on claim %s in the context %s." % (claimid,str(mpalist))
|
2006-08-07 19:23:30 +01:00
|
|
|
return mpalist
|
|
|
|
|
2006-08-08 14:03:02 +01:00
|
|
|
def constructMPAlist(mpalist,start,callback):
|
2006-08-07 19:23:30 +01:00
|
|
|
if len(mpalist) < count:
|
2006-08-08 14:03:02 +01:00
|
|
|
for pn in range(start,len(protocolset)):
|
|
|
|
p = protocolset[pn]
|
2006-08-07 19:23:30 +01:00
|
|
|
if p not in mpalist:
|
2006-08-08 14:03:02 +01:00
|
|
|
constructMPAlist(mpalist + [p],pn+1,callback)
|
2006-08-07 19:23:30 +01:00
|
|
|
else:
|
2006-08-08 14:03:02 +01:00
|
|
|
callback(mpalist)
|
2006-08-07 19:23:30 +01:00
|
|
|
|
|
|
|
while count <= maxcount:
|
2006-08-08 14:03:02 +01:00
|
|
|
constructMPAlist([protocol],0,verifyMPAlist)
|
2006-08-07 19:23:30 +01:00
|
|
|
count += 1
|
|
|
|
return None
|
|
|
|
|
|
|
|
def findAllMPA(protocolset,maxcount=3):
|
|
|
|
"""
|
|
|
|
Given a set of protocols, find multi-protocol attacks
|
|
|
|
"""
|
2006-08-08 14:03:02 +01:00
|
|
|
(protocolset,correct) = getCorrectIsolatedClaims(protocolset)
|
2006-08-07 19:23:30 +01:00
|
|
|
print correct
|
|
|
|
for (protocol,claimid) in correct:
|
|
|
|
mpalist = findMPA(protocolset,protocol,claimid,maxcount=3)
|
|
|
|
if mpalist:
|
|
|
|
print "Darn, MPA on %s (%s) using %s" % (claimid,protocol,mpalist)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
list = ['me.spdl','ns3.spdl','nsl3.spdl']
|
|
|
|
findAllMPA(list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|