Esempio n. 1
0
    def prepare_new_attacker(self):
        new_attacker_props = [
            AttackerEnvironmentProperties(
                environmentName=self.existing_environment_name_1,
                roles=self.existing_role_names,
                motives=self.existing_motive_names,
                capabilities=self.existing_capabilities),
            AttackerEnvironmentProperties(
                environmentName=self.existing_environment_name_2,
                roles=self.existing_role_names,
                motives=self.existing_motive_names,
                capabilities=self.existing_capabilities)
        ]

        new_attacker = Attacker(attackerId=-1,
                                attackerName='Test attacker',
                                attackerDescription='This is a test attacker',
                                attackerImage='',
                                tags=['test', 'test123'],
                                environmentProperties=[])
        new_attacker.theEnvironmentProperties = new_attacker_props

        new_attacker.theEnvironmentDictionary = {}
        new_attacker.theAttackerPropertyDictionary = {}

        delattr(new_attacker, 'theEnvironmentDictionary')
        delattr(new_attacker, 'theAttackerPropertyDictionary')

        return new_attacker
Esempio n. 2
0
    def testAttacker(self):
        iatkeps = [
            AttackerEnvironmentProperties(
                self.iAttackers[0]["theEnvironmentProperties"][0]["theName"],
                self.iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],
                self.iAttackers[0]["theEnvironmentProperties"][0]
                ["theMotives"], self.iAttackers[0]["theEnvironmentProperties"]
                [0]["theCapabilities"]),
            AttackerEnvironmentProperties(
                self.iAttackers[0]["theEnvironmentProperties"][1]["theName"],
                self.iAttackers[0]["theEnvironmentProperties"][1]["theRoles"],
                self.iAttackers[0]["theEnvironmentProperties"][1]
                ["theMotives"], self.iAttackers[0]["theEnvironmentProperties"]
                [1]["theCapabilities"])
        ]
        iatk = AttackerParameters(self.iAttackers[0]["theName"],
                                  self.iAttackers[0]["theDescription"],
                                  self.iAttackers[0]["theImage"], [], iatkeps)
        b = Borg()
        b.dbProxy.addAttacker(iatk)
        oAttackers = b.dbProxy.getAttackers()
        o = oAttackers[self.iAttackers[0]["theName"]]
        self.assertEqual(iatk.name(), o.name())
        self.assertEqual(iatk.description(), o.description())
        self.assertEqual(iatk.image(), o.image())
        oatkeps = o.environmentProperties()
        self.assertEqual(iatkeps[0].name(), oatkeps[0].name())
        self.assertEqual(str(iatkeps[0].roles()[0]),
                         str(oatkeps[0].roles()[0]))
        self.assertEqual(str(iatkeps[0].roles()[0]), o.roles('Day', '')[0])
        self.assertEqual(iatkeps[0].roles(), list(o.roles('', 'Maximise')))
        self.assertEqual(str(iatkeps[0].motives()[0]),
                         str(oatkeps[0].motives()[0]))
        self.assertEqual(str(iatkeps[0].motives()[0]),
                         str(o.motives('Day', '')[0]))
        self.assertEqual(iatkeps[0].motives(), list(o.motives('', 'Maximise')))
        self.assertEqual(str(iatkeps[0].capabilities()[0][0]),
                         str(oatkeps[0].capabilities()[0][0]))
        self.assertEqual(str(iatkeps[0].capabilities()[0][1]),
                         str(oatkeps[0].capabilities()[0][1]))
        self.assertEqual(iatkeps[0].capabilities()[0][0],
                         o.capability('Day', '')[0][0])
        self.assertEqual(iatkeps[0].capabilities()[0][0],
                         list(o.capability('', 'Maximise'))[0][0])

        iatk.theName = 'Updated name'
        iatk.setId(o.id())
        b.dbProxy.updateAttacker(iatk)
        oAttackers = b.dbProxy.getAttackers()
        o = oAttackers["Updated name"]
        self.assertEqual(o.name(), 'Updated name')

        b.dbProxy.deleteAttacker(o.id())
Esempio n. 3
0
    def testAttacker(self):
        iatkeps = [
            AttackerEnvironmentProperties(
                self.iAttackers[0]["theEnvironmentProperties"][0]["theName"],
                self.iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],
                self.iAttackers[0]["theEnvironmentProperties"][0]
                ["theMotives"], self.iAttackers[0]["theEnvironmentProperties"]
                [0]["theCapabilities"])
        ]
        iatk = AttackerParameters(self.iAttackers[0]["theName"],
                                  self.iAttackers[0]["theDescription"],
                                  self.iAttackers[0]["theImage"], [], iatkeps)
        b = Borg()
        b.dbProxy.addAttacker(iatk)
        oAttackers = b.dbProxy.getAttackers()
        o = oAttackers[self.iAttackers[0]["theName"]]
        self.assertEqual(iatk.name(), o.name())
        self.assertEqual(iatk.description(), o.description())
        self.assertEqual(iatk.image(), o.image())
        oatkeps = o.environmentProperties()
        self.assertEqual(iatkeps[0].name(), oatkeps[0].name())
        self.assertEqual(str(iatkeps[0].roles()[0]),
                         str(oatkeps[0].roles()[0]))
        self.assertEqual(str(iatkeps[0].motives()[0]),
                         str(oatkeps[0].motives()[0]))
        self.assertEqual(str(iatkeps[0].capabilities()[0][0]),
                         str(oatkeps[0].capabilities()[0][0]))
        self.assertEqual(str(iatkeps[0].capabilities()[0][1]),
                         str(oatkeps[0].capabilities()[0][1]))

        b.dbProxy.deleteAttacker(o.id())
Esempio n. 4
0
 def inheritedAttackerProperties(self, attackerId, environmentName):
     environmentId = self.getDimensionId(environmentName, 'environment')
     roles = self.dimensionRoles(attackerId, environmentId, 'attacker')
     capabilities = self.attackerCapabilities(attackerId, environmentId)
     motives = self.attackerMotives(attackerId, environmentId)
     return AttackerEnvironmentProperties(environmentName, roles, motives,
                                          capabilities)
 def environmentProperties(self):
     if (self.theSelectedIdx != -1):
         environmentName = self.environmentList.GetItemText(
             self.theSelectedIdx)
         self.theEnvironmentDictionary[
             environmentName] = AttackerEnvironmentProperties(
                 environmentName, self.roleList.dimensions(),
                 self.motiveList.dimensions(),
                 self.capabilitiesList.capabilities())
     return self.theEnvironmentDictionary.values()
Esempio n. 6
0
  def OnEnvironmentDeselected(self,evt):
    self.theSelectedIdx = evt.GetIndex()
    environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
    self.theEnvironmentDictionary[environmentName] = AttackerEnvironmentProperties(environmentName,self.roleList.dimensions(),self.motiveList.dimensions(),self.capabilitiesList.capabilities())

    self.roleList.setEnvironment('')
    self.roleList.DeleteAllItems() 
    self.motiveList.setEnvironment('')
    self.motiveList.DeleteAllItems() 
    self.capabilitiesList.setEnvironment('')
    self.capabilitiesList.DeleteAllItems()
    self.theSelectedIdx = -1
Esempio n. 7
0
 def setUp(self):
   call([os.environ['CAIRIS_SRC'] + "/test/initdb.sh"])
   cairis.core.BorgFactory.initialise()
   f = open(os.environ['CAIRIS_SRC'] + '/test/threats.json')
   d = json.load(f)
   f.close()
   self.ienvs = d['environments']
   self.iep = EnvironmentParameters(self.ienvs[0]["theName"],self.ienvs[0]["theShortCode"],self.ienvs[0]["theDescription"])
   b = Borg()
   b.dbProxy.addEnvironment(self.iep)
   self.oenvs = b.dbProxy.getEnvironments()
   self.iRoles = d['roles']
   self.irp = RoleParameters(self.iRoles[0]["theName"], self.iRoles[0]["theType"], self.iRoles[0]["theShortCode"], self.iRoles[0]["theDescription"],[])
   b.dbProxy.addRole(self.irp)
   self.oRoles = b.dbProxy.getRoles()
   self.iPersonas = d['personas']
   self.ipp = PersonaParameters(self.iPersonas[0]["theName"],self.iPersonas[0]["theActivities"],self.iPersonas[0]["theAttitudes"],self.iPersonas[0]["theAptitudes"],self.iPersonas[0]["theMotivations"],self.iPersonas[0]["theSkills"],self.iPersonas[0]["theIntrinsic"],self.iPersonas[0]["theContextual"],"","0",self.iPersonas[0]["thePersonaType"],[],[PersonaEnvironmentProperties(self.iPersonas[0]["theEnvironmentProperties"][0]["theName"],(self.iPersonas[0]["theEnvironmentProperties"][0]["theDirectFlag"] == "True"),self.iPersonas[0]["theEnvironmentProperties"][0]["theNarrative"],self.iPersonas[0]["theEnvironmentProperties"][0]["theRole"])],[])
   b.dbProxy.addPersona(self.ipp)
   self.opp = b.dbProxy.getPersonas()
   self.iExternalDocuments = d['external_documents']
   self.iec1 = ExternalDocumentParameters(self.iExternalDocuments[0]["theName"],self.iExternalDocuments[0]["theVersion"],self.iExternalDocuments[0]["thePublicationDate"],self.iExternalDocuments[0]["theAuthors"],self.iExternalDocuments[0]["theDescription"])
   self.iec2 = ExternalDocumentParameters(self.iExternalDocuments[1]["theName"],self.iExternalDocuments[1]["theVersion"],self.iExternalDocuments[1]["thePublicationDate"],self.iExternalDocuments[1]["theAuthors"],self.iExternalDocuments[1]["theDescription"])
   b.dbProxy.addExternalDocument(self.iec1)
   b.dbProxy.addExternalDocument(self.iec2)
   self.oecs = b.dbProxy.getExternalDocuments()
   self.iDocumentReferences = d['document_references']
   self.idr1 = DocumentReferenceParameters(self.iDocumentReferences[0]["theName"],self.iDocumentReferences[0]["theDocName"],self.iDocumentReferences[0]["theContributor"],self.iDocumentReferences[0]["theExcerpt"])
   self.idr2 = DocumentReferenceParameters(self.iDocumentReferences[1]["theName"],self.iDocumentReferences[1]["theDocName"],self.iDocumentReferences[1]["theContributor"],self.iDocumentReferences[1]["theExcerpt"])
   b.dbProxy.addDocumentReference(self.idr1)
   b.dbProxy.addDocumentReference(self.idr2)
   self.odrs = b.dbProxy.getDocumentReferences()
   self.iPersonaCharacteristics = d['persona_characteristics']
   self.ipc1 = PersonaCharacteristicParameters(self.iPersonaCharacteristics[0]["thePersonaName"],self.iPersonaCharacteristics[0]["theModQual"],self.iPersonaCharacteristics[0]["theVariable"],self.iPersonaCharacteristics[0]["theCharacteristic"],[(self.iPersonaCharacteristics[0]["ground"],'','document')],[(self.iPersonaCharacteristics[0]["warrant"],'','document')],[],[])
   b.dbProxy.addPersonaCharacteristic(self.ipc1)
   self.opcs = b.dbProxy.getPersonaCharacteristics()
   self.iAttackers = d['attackers']
   self.iatkeps = [AttackerEnvironmentProperties(self.iAttackers[0]["theEnvironmentProperties"][0]["theName"],self.iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],self.iAttackers[0]["theEnvironmentProperties"][0]["theMotives"],self.iAttackers[0]["theEnvironmentProperties"][0]["theCapabilities"])]
   self.iatk = AttackerParameters(self.iAttackers[0]["theName"], self.iAttackers[0]["theDescription"], self.iAttackers[0]["theImage"],[],self.iatkeps)
   b.dbProxy.addAttacker(self.iatk)
   self.oAttackers = b.dbProxy.getAttackers()
   self.iVtypes = d['valuetypes']
   self.ivt = ValueTypeParameters(self.iVtypes[0]["theName"], self.iVtypes[0]["theDescription"], self.iVtypes[0]["theType"])
   b.dbProxy.addValueType(self.ivt)
   self.ovt = b.dbProxy.getValueTypes('threat_type')
   self.iassets = d['assets']
   self.iaeps = [AssetEnvironmentProperties(self.iassets[0]["theEnvironmentProperties"][0][0],self.iassets[0]["theEnvironmentProperties"][0][1],self.iassets[0]["theEnvironmentProperties"][0][2])]
   self.iap = AssetParameters(self.iassets[0]["theName"],self.iassets[0]["theShortCode"],self.iassets[0]["theDescription"],self.iassets[0]["theSignificance"],self.iassets[0]["theType"],"0","N/A",[],[],self.iaeps)
   b.dbProxy.addAsset(self.iap)
   self.oap = b.dbProxy.getAssets()
   self.iThreats = d['threats']
Esempio n. 8
0
 def OnAddEnvironment(self,evt):
   self.theSelectedIdx = evt.GetIndex()
   environmentName = self.environmentList.GetItemText(self.theSelectedIdx)
   self.theEnvironmentDictionary[environmentName] = AttackerEnvironmentProperties(environmentName,[],[],[])
   self.environmentList.Select(self.theSelectedIdx)
   self.capabilitiesList.setEnvironment(environmentName)
   inheritedEnv = self.environmentList.inheritedEnvironment()
   if (inheritedEnv != '' and self.theAttackerId != None):
     p = self.dbProxy.inheritedAttackerProperties(self.theAttackerId,inheritedEnv)
     self.theEnvironmentDictionary[environmentName] = p
     self.roleList.setEnvironment(environmentName)
     self.roleList.load(p.roles()) 
     self.motiveList.setEnvironment(environmentName)
     self.motiveList.load(p.motives()) 
     self.capabilitiesList.setEnvironment(environmentName)
     self.capabilitiesList.load(p.capabilities())
Esempio n. 9
0
    def convert_props(self, real_props=None, fake_props=None):
        new_props = []
        if real_props is not None:
            if len(real_props) > 0:
                for real_prop in real_props:
                    assert isinstance(real_prop, AttackerEnvironmentProperties)
                    capabilities = []
                    for capability in real_prop.theCapabilities:
                        if len(capability) == 2:
                            capabilities.append({
                                'name': capability[0],
                                'value': capability[1]
                            })
                    real_prop.theCapabilities = capabilities
                    new_props.append(real_prop)
        elif fake_props is not None:
            if len(fake_props) > 0:
                for fake_prop in fake_props:
                    check_required_keys(
                        fake_prop, AttackerEnvironmentPropertiesModel.required)
                    cap_list = []
                    assert isinstance(cap_list, list)
                    for cap in fake_prop['theCapabilities']:
                        cap_list.append((cap['name'], cap['value']))
                    new_prop = AttackerEnvironmentProperties(
                        environmentName=fake_prop['theEnvironmentName'],
                        roles=fake_prop['theRoles'],
                        motives=fake_prop['theMotives'],
                        capabilities=cap_list)
                    new_props.append(new_prop)
        else:
            self.close()
            raise MissingParameterHTTPError(
                param_names=['real_props', 'fake_props'])

        return new_props
Esempio n. 10
0
  def endElement(self,name):
    if name == 'intent':
      self.inIntent = 0
    elif name == 'definition':
      self.inDefinition = 0
    elif name == 'rationale':
      self.inRationale = 0
    elif name == 'motivation':
      self.theMotivations.append((self.theGoal,self.theValue,self.theDescription))
      self.resetMotivationElements()
    elif name == 'participant':
      self.theParticipants.append((self.theParticipant,self.theMotives,self.theResponsibilities))
      self.resetParticipantElements()
    elif name == 'description':
      self.inDescription = 0
      if self.inImplementation:
        self.inImplementation = 0
    elif name == 'consequences':
      self.inConsequences = 0
    elif name == 'implementation':
      self.inImplementation = 0
    elif name == 'known_uses':
      self.inKnownUses = 0
    elif name == 'related_patterns':
      self.inRelatedPatterns = 0
    elif name == 'obstacle':

      self.theObstacles.append( TemplateObstacleParameters(self.theObstacleName,self.theObstacleCategory,self.theDefinition,self.theConcerns,self.theResponsibilities,self.theProbability,self.theRationale))
      self.resetObstacleElements()
    elif name == 'obstacle_association':
      self.theObstacleAssociations.append((self.theObstacleName,self.theRefType,self.theSubObstacleName,self.theRationale))
      self.resetObstacleAssociationElements()
    elif name == 'attack_pattern':
      assetList = self.theTargets + self.theExploits
      for assetName in assetList:
        self.theAssetParameters.append(cairis.core.AssetParametersFactory.buildFromTemplate(assetName,[self.theEnvironment]))

      attackerNames = []
      for attackerName,attackerMotives,attackerCapabilities in self.theParticipants:
        attackerRoles = self.dbProxy.dimensionRoles(self.dbProxy.getDimensionId(attackerName,'persona'),self.dbProxy.getDimensionId(self.theEnvironment,'environment'),'persona')
        ep = AttackerEnvironmentProperties(self.theEnvironment,attackerRoles,attackerMotives,attackerCapabilities)
        p = AttackerParameters(attackerName,'','',[],[ep])
        p.isPersona = True
        self.theAttackerParameters.append(p) 
        attackerNames.append(attackerName)
  
      for tObs in self.theObstacles:
        sgRefs = []
        for resp in tObs.responsibilities():
          sgRefs.append((resp,'role','responsible',0,'None')) 
        ep = ObstacleEnvironmentProperties(self.theEnvironment,'',tObs.definition(),tObs.category(),[],sgRefs,tObs.concerns())
        ep.theProbability = tObs.probability()
        ep.theProbabilityRationale = tObs.probabilityRationale()
        self.theObstacleParameters.append(ObstacleParameters(tObs.name(),self.thePatternName,[],[ep]))

      for obsAssoc in self.theObstacleAssociations:
        obsName = obsAssoc[0]
        refType = obsAssoc[1]
        subObsName = obsAssoc[2]
        assocRationale = obsAssoc[3]  
        self.theObstacleAssociationParameters.append(GoalAssociationParameters(self.theEnvironment,obsName,'obstacle',refType,subObsName,'obstacle',0,assocRationale))
 
      vp = VulnerabilityEnvironmentProperties(self.theEnvironment,self.theSeverity,self.theExploits)
      vulRows = self.dbProxy.getVulnerabilityDirectory(self.theExploit)
      vulData = vulRows[0]
      self.theVulnerabilityParameters = VulnerabilityParameters(self.theExploit,vulData[2],vulData[3],[],[vp])

      spDict = {}
      spDict['confidentiality'] = (0,'None')
      spDict['integrity'] = (0,'None')
      spDict['availability'] = (0,'None')
      spDict['accountability'] = (0,'None')
      spDict['anonymity'] = (0,'None')
      spDict['pseudonymity'] = (0,'None')
      spDict['unlinkability'] = (0,'None')
      spDict['unobservability'] = (0,'None')

      for thrMotivation in self.theMotivations:
        spName = thrMotivation[0]
        spValue = thrMotivation[1]
        spRationale = thrMotivation[2]
        spDict[spName] = (a2i(spValue),spRationale)
      
      cProperty,cRationale = spDict['confidentiality']
      iProperty,iRationale = spDict['integrity']
      avProperty,avRationale = spDict['availability']
      acProperty,acRationale = spDict['accountability']
      anProperty,anRationale = spDict['anonymity']
      panProperty,panRationale = spDict['pseudonymity']
      unlProperty,unlRationale = spDict['unlinkability']
      unoProperty,unoRationale = spDict['unobservability']

      tp = ThreatEnvironmentProperties(self.theEnvironment,self.theLikelihood,self.theTargets,attackerNames,[cProperty,iProperty,avProperty,acProperty,anProperty,panProperty,unlProperty,unoProperty],[cRationale,iRationale,avRationale,acRationale,anRationale,panRationale,unlRationale,unoRationale])
      thrRows = self.dbProxy.getThreatDirectory(self.theAttack)
      thrData = thrRows[0]
      self.theThreatParameters = ThreatParameters(self.theAttack,thrData[3],thrData[2],[],[tp])

      if (self.theAttackObstacle != ''):
        self.theObstacleAssociationParameters.append(GoalAssociationParameters(self.theEnvironment,self.theAttackObstacle,'obstacle','or',self.theAttack,'threat',0,'None'))
      if (self.theExploitObstacle != ''):
        self.theObstacleAssociationParameters.append(GoalAssociationParameters(self.theEnvironment,self.theExploitObstacle,'obstacle','or',self.theExploit,'vulnerability',0,'None'))
      rep = MisuseCaseEnvironmentProperties(self.theEnvironment,self.theImplementation )
      mc = MisuseCase(-1,'Exploit ' + self.thePatternName,[rep],self.thePatternName)
      self.theRiskParameters = RiskParameters(self.thePatternName,self.theAttack,self.theExploit,mc,[],self.theIntent)
Esempio n. 11
0
 def endElement(self, name):
     if name == 'role':
         p = RoleParameters(self.theName, self.theType,
                            unescape(self.theShortCode),
                            unescape(self.theDescription), [])
         self.theRoleParameters.append(p)
         self.resetRoleAttributes()
     elif name == 'asset':
         envDict = {}
         for sp in self.theSecurityProperties:
             envName = sp[0]
             spName = sp[1]
             spValue = a2i(sp[2])
             spRationale = sp[3]
             if envName in envDict:
                 (envDict[envName])[spName] = (spValue, spRationale)
             else:
                 spDict = {}
                 spDict['confidentiality'] = (0, 'None')
                 spDict['integrity'] = (0, 'None')
                 spDict['availability'] = (0, 'None')
                 spDict['accountability'] = (0, 'None')
                 spDict['anonymity'] = (0, 'None')
                 spDict['pseudonymity'] = (0, 'None')
                 spDict['unlinkability'] = (0, 'None')
                 spDict['unobservability'] = (0, 'None')
                 spDict[spName] = (spValue, spRationale)
                 envDict[envName] = spDict
         for envName in envDict:
             spDict = envDict[envName]
             cProperty, cRationale = spDict['confidentiality']
             iProperty, iRationale = spDict['integrity']
             avProperty, avRationale = spDict['availability']
             acProperty, acRationale = spDict['accountability']
             anProperty, anRationale = spDict['anonymity']
             panProperty, panRationale = spDict['pseudonymity']
             unlProperty, unlRationale = spDict['unlinkability']
             unoProperty, unoRationale = spDict['unobservability']
             ep = AssetEnvironmentProperties(envName, [
                 cProperty, iProperty, avProperty, acProperty, anProperty,
                 panProperty, unlProperty, unoProperty
             ], [
                 cRationale, iRationale, avRationale, acRationale,
                 anRationale, panRationale, unlRationale, unoRationale
             ])
             self.theEnvironmentProperties.append(ep)
         p = AssetParameters(self.theName, unescape(self.theShortCode),
                             unescape(self.theDescription),
                             unescape(self.theSignificance),
                             self.theAssetType, self.isCritical,
                             self.theCriticalRationale, self.theTags,
                             self.theInterfaces,
                             self.theEnvironmentProperties)
         self.theAssetParameters.append(p)
         self.resetAssetAttributes()
     elif name == 'security_property':
         self.theSecurityProperties.append(
             (self.theEnvironmentName, self.thePropertyName,
              self.thePropertyValue, unescape(self.theRationale)))
         self.resetSecurityPropertyAttributes()
     elif name == 'threatened_property':
         self.theSpDict[self.thePropertyName] = (self.thePropertyValue,
                                                 unescape(
                                                     self.theRationale))
         self.resetThreatenedPropertyAttributes()
     elif name == 'vulnerability':
         p = VulnerabilityParameters(self.theName,
                                     unescape(self.theDescription),
                                     self.theType, self.theTags,
                                     self.theEnvironmentProperties)
         self.theVulnerabilities.append(p)
         self.resetVulnerabilityAttributes()
     elif name == 'vulnerability_environment':
         p = VulnerabilityEnvironmentProperties(self.theEnvironmentName,
                                                self.theSeverity,
                                                self.theAssets)
         self.theEnvironmentProperties.append(p)
         self.resetVulnerabilityEnvironmentAttributes()
     elif name == 'attacker':
         p = AttackerParameters(self.theName, unescape(self.theDescription),
                                self.theImage, self.theTags,
                                self.theEnvironmentProperties)
         self.theAttackerParameters.append(p)
         self.resetAttackerAttributes()
     elif name == 'attacker_environment':
         p = AttackerEnvironmentProperties(self.theEnvironmentName,
                                           self.theRoles,
                                           self.theMotivations,
                                           self.theCapabilities)
         self.theEnvironmentProperties.append(p)
         self.resetAttackerEnvironmentAttributes()
     elif name == 'threat':
         p = ThreatParameters(self.theName, self.theType,
                              unescape(self.theMethod), self.theTags,
                              self.theEnvironmentProperties)
         self.theThreats.append(p)
         self.resetThreatAttributes()
     elif name == 'threat_environment':
         cProperty, cRationale = self.theSpDict['confidentiality']
         iProperty, iRationale = self.theSpDict['integrity']
         avProperty, avRationale = self.theSpDict['availability']
         acProperty, acRationale = self.theSpDict['accountability']
         anProperty, anRationale = self.theSpDict['anonymity']
         panProperty, panRationale = self.theSpDict['pseudonymity']
         unlProperty, unlRationale = self.theSpDict['unlinkability']
         unoProperty, unoRationale = self.theSpDict['unobservability']
         p = ThreatEnvironmentProperties(
             self.theEnvironmentName, self.theLikelihood, self.theAssets,
             self.theAttackers, [
                 cProperty, iProperty, avProperty, acProperty, anProperty,
                 panProperty, unlProperty, unoProperty
             ], [
                 cRationale, iRationale, avRationale, acRationale,
                 anRationale, panRationale, unlRationale, unoRationale
             ])
         self.theEnvironmentProperties.append(p)
         self.resetThreatEnvironmentAttributes()
     elif name == 'risk':
         mc = MisuseCase(-1, 'Exploit ' + self.theName,
                         self.theEnvironmentProperties, self.theName)
         p = RiskParameters(self.theName, self.theThreat,
                            self.theVulnerability, mc, self.theTags)
         self.theRisks.append(p)
         self.resetRiskAttributes()
     elif name == 'misusecase':
         p = MisuseCaseEnvironmentProperties(self.theEnvironmentName,
                                             unescape(self.theDescription))
         self.theEnvironmentProperties.append(p)
         self.resetRiskEnvironmentAttributes()
     elif name == 'response':
         p = ResponseParameters(self.theType + ' ' + self.theRisk,
                                self.theRisk, self.theTags,
                                self.theEnvironmentProperties, self.theType)
         self.theResponses.append(p)
         self.resetResponseAttributes()
     elif name == 'accept_environment':
         p = AcceptEnvironmentProperties(self.theEnvironmentName,
                                         self.theCost,
                                         unescape(self.theDescription))
         self.theEnvironmentProperties.append(p)
         self.resetResponseEnvironmentAttributes()
     elif name == 'transfer_environment':
         p = TransferEnvironmentProperties(self.theEnvironmentName,
                                           unescape(self.theDescription),
                                           self.theResponseRoles)
         self.theEnvironmentProperties.append(p)
         self.resetResponseEnvironmentAttributes()
     elif name == 'deter_environment':
         p = MitigateEnvironmentProperties(self.theEnvironmentName, 'Deter')
         self.theEnvironmentProperties.append(p)
         self.resetResponseEnvironmentAttributes()
     elif name == 'prevent_environment':
         p = MitigateEnvironmentProperties(self.theEnvironmentName,
                                           'Prevent')
         self.theEnvironmentProperties.append(p)
         self.resetResponseEnvironmentAttributes()
     elif name == 'detect_environment':
         p = MitigateEnvironmentProperties(self.theEnvironmentName,
                                           'Detect', self.theDetectionPoint)
         self.theEnvironmentProperties.append(p)
         self.resetResponseEnvironmentAttributes()
     elif name == 'react_environment':
         p = MitigateEnvironmentProperties(self.theEnvironmentName, 'React',
                                           '', self.theDetectionMechanisms)
         self.theEnvironmentProperties.append(p)
         self.resetResponseEnvironmentAttributes()
     elif name == 'asset_association':
         p = ClassAssociationParameters(
             self.theEnvironmentName, self.theHeadName, 'asset',
             self.theHeadNav, self.theHeadAdornment, self.theHeadNry,
             self.theHeadRole, self.theTailRole, self.theTailNry,
             self.theTailAdornment, self.theTailNav, 'asset',
             self.theTailName, unescape(self.theRationale))
         self.theAssociations.append(p)
         self.resetAssociationAttributes()
     elif name == 'description':
         self.inDescription = 0
     elif name == 'method':
         self.inMethod = 0
     elif name == 'narrative':
         self.inDescription = 0
     elif name == 'rationale':
         self.inRationale = 0
     elif name == 'significance':
         self.inSignificance = 0
     elif name == 'critical':
         self.inCritical = 0
Esempio n. 12
0
    def setUp(self):
        call([os.environ['CAIRIS_CFG_DIR'] + "/initdb.sh"])
        cairis.core.BorgFactory.initialise()
        f = open(os.environ['CAIRIS_SRC'] + '/test/responses.json')
        d = json.load(f)
        f.close()
        ienvs = d['environments']
        iep1 = EnvironmentParameters(ienvs[0]["theName"],
                                     ienvs[0]["theShortCode"],
                                     ienvs[0]["theDescription"])
        b = Borg()
        b.dbProxy.addEnvironment(iep1)
        iRoles = d['roles']
        irp = RoleParameters(iRoles[0]["theName"], iRoles[0]["theType"],
                             iRoles[0]["theShortCode"],
                             iRoles[0]["theDescription"], [])
        b.dbProxy.addRole(irp)
        iAttackers = d['attackers']
        iatkeps = [
            AttackerEnvironmentProperties(
                iAttackers[0]["theEnvironmentProperties"][0]["theName"],
                iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],
                iAttackers[0]["theEnvironmentProperties"][0]["theMotives"],
                iAttackers[0]["theEnvironmentProperties"][0]
                ["theCapabilities"])
        ]
        iatk = AttackerParameters(iAttackers[0]["theName"],
                                  iAttackers[0]["theDescription"],
                                  iAttackers[0]["theImage"], [], iatkeps)
        b.dbProxy.addAttacker(iatk)
        iVtypes = d['valuetypes']
        ivt1 = ValueTypeParameters(iVtypes[0]["theName"],
                                   iVtypes[0]["theDescription"],
                                   iVtypes[0]["theType"])
        ivt2 = ValueTypeParameters(iVtypes[1]["theName"],
                                   iVtypes[1]["theDescription"],
                                   iVtypes[1]["theType"])
        b.dbProxy.addValueType(ivt1)
        b.dbProxy.addValueType(ivt2)
        iassets = d['assets']
        iaeps1 = [
            AssetEnvironmentProperties(
                iassets[0]["theEnvironmentProperties"][0][0],
                iassets[0]["theEnvironmentProperties"][0][1],
                iassets[0]["theEnvironmentProperties"][0][2])
        ]
        iaeps2 = [
            AssetEnvironmentProperties(
                iassets[1]["theEnvironmentProperties"][0][0],
                iassets[1]["theEnvironmentProperties"][0][1],
                iassets[1]["theEnvironmentProperties"][0][2])
        ]
        iaeps3 = [
            AssetEnvironmentProperties(
                iassets[2]["theEnvironmentProperties"][0][0],
                iassets[2]["theEnvironmentProperties"][0][1],
                iassets[2]["theEnvironmentProperties"][0][2])
        ]
        iap1 = AssetParameters(iassets[0]["theName"],
                               iassets[0]["theShortCode"],
                               iassets[0]["theDescription"],
                               iassets[0]["theSignificance"],
                               iassets[0]["theType"], "0", "N/A", [], [],
                               iaeps1)
        iap2 = AssetParameters(iassets[1]["theName"],
                               iassets[1]["theShortCode"],
                               iassets[1]["theDescription"],
                               iassets[1]["theSignificance"],
                               iassets[1]["theType"], "0", "N/A", [], [],
                               iaeps2)
        iap3 = AssetParameters(iassets[2]["theName"],
                               iassets[2]["theShortCode"],
                               iassets[2]["theDescription"],
                               iassets[2]["theSignificance"],
                               iassets[2]["theType"], "0", "N/A", [], [],
                               iaeps3)
        b.dbProxy.addAsset(iap1)
        b.dbProxy.addAsset(iap2)
        b.dbProxy.addAsset(iap3)
        iThreats = d['threats']
        iteps = [
            ThreatEnvironmentProperties(
                iThreats[0]["theEnvironmentProperties"][0]["theName"],
                iThreats[0]["theEnvironmentProperties"][0]["theLikelihood"],
                iThreats[0]["theEnvironmentProperties"][0]["theAssets"],
                iThreats[0]["theEnvironmentProperties"][0]["theAttackers"],
                iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0]
                [1], iThreats[0]["theEnvironmentProperties"][0]
                ["theProperties"][0][1])
        ]
        itps = ThreatParameters(iThreats[0]["theName"], iThreats[0]["theType"],
                                iThreats[0]["theMethod"], [], iteps)
        b.dbProxy.addThreat(itps)
        iVuln = d['vulnerabilities']
        iveps = [
            VulnerabilityEnvironmentProperties(
                iVuln[0]["theEnvironmentProperties"][0]["theName"],
                iVuln[0]["theEnvironmentProperties"][0]["theSeverity"],
                iVuln[0]["theEnvironmentProperties"][0]["theAssets"])
        ]
        ivp = VulnerabilityParameters(iVuln[0]["theName"],
                                      iVuln[0]["theDescription"],
                                      iVuln[0]["theType"], [], iveps)
        b.dbProxy.addVulnerability(ivp)
        imc = d['misuseCase']
        iRisks = d['risks']

        imcep = [
            MisuseCaseEnvironmentProperties(
                imc[0]["theEnvironmentProperties"][0]["theName"],
                imc[0]["theEnvironmentProperties"][0]["theDescription"])
        ]
        imcp = MisuseCase(int(0), imc[0]["theName"], imcep, imc[0]["theRisk"])
        irp = RiskParameters(iRisks[0]["theName"], iRisks[0]["threatName"],
                             iRisks[0]["vulName"], imcp, [])
        b.dbProxy.addRisk(irp)
        self.iResponses = d['responses']
Esempio n. 13
0
    def setUp(self):
        call([os.environ['CAIRIS_SRC'] + "/test/initdb.sh"])
        cairis.core.BorgFactory.initialise()
        f = open(os.environ['CAIRIS_SRC'] + '/test/countermeasures.json')
        d = json.load(f)
        f.close()
        self.ienvs = d['environments']
        self.iep1 = EnvironmentParameters(self.ienvs[0]["theName"],
                                          self.ienvs[0]["theShortCode"],
                                          self.ienvs[0]["theDescription"])
        b = Borg()
        b.dbProxy.addEnvironment(self.iep1)
        self.oenvs = b.dbProxy.getEnvironments()
        self.iRoles = d['roles']
        self.irp = RoleParameters(self.iRoles[0]["theName"],
                                  self.iRoles[0]["theType"],
                                  self.iRoles[0]["theShortCode"],
                                  self.iRoles[0]["theDescription"], [])
        b.dbProxy.addRole(self.irp)
        self.oRoles = b.dbProxy.getRoles()
        self.iPersonas = d['personas']
        self.ipp = PersonaParameters(
            self.iPersonas[0]["theName"], self.iPersonas[0]["theActivities"],
            self.iPersonas[0]["theAttitudes"],
            self.iPersonas[0]["theAptitudes"],
            self.iPersonas[0]["theMotivations"],
            self.iPersonas[0]["theSkills"], self.iPersonas[0]["theIntrinsic"],
            self.iPersonas[0]["theContextual"], "", "0",
            self.iPersonas[0]["thePersonaType"], [], [
                PersonaEnvironmentProperties(
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theName"], (self.iPersonas[0]["theEnvironmentProperties"]
                                  [0]["theDirectFlag"] == "True"),
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theNarrative"], self.iPersonas[0]
                    ["theEnvironmentProperties"][0]["theRole"])
            ], [])
        b.dbProxy.addPersona(self.ipp)
        self.opp = b.dbProxy.getPersonas()
        self.iExternalDocuments = d['external_documents']
        self.iec1 = ExternalDocumentParameters(
            self.iExternalDocuments[0]["theName"],
            self.iExternalDocuments[0]["theVersion"],
            self.iExternalDocuments[0]["thePublicationDate"],
            self.iExternalDocuments[0]["theAuthors"],
            self.iExternalDocuments[0]["theDescription"])
        self.iec2 = ExternalDocumentParameters(
            self.iExternalDocuments[1]["theName"],
            self.iExternalDocuments[1]["theVersion"],
            self.iExternalDocuments[1]["thePublicationDate"],
            self.iExternalDocuments[1]["theAuthors"],
            self.iExternalDocuments[1]["theDescription"])
        b.dbProxy.addExternalDocument(self.iec1)
        b.dbProxy.addExternalDocument(self.iec2)
        self.oecs = b.dbProxy.getExternalDocuments()
        self.iDocumentReferences = d['document_references']
        self.idr1 = DocumentReferenceParameters(
            self.iDocumentReferences[0]["theName"],
            self.iDocumentReferences[0]["theDocName"],
            self.iDocumentReferences[0]["theContributor"],
            self.iDocumentReferences[0]["theExcerpt"])
        self.idr2 = DocumentReferenceParameters(
            self.iDocumentReferences[1]["theName"],
            self.iDocumentReferences[1]["theDocName"],
            self.iDocumentReferences[1]["theContributor"],
            self.iDocumentReferences[1]["theExcerpt"])
        b.dbProxy.addDocumentReference(self.idr1)
        b.dbProxy.addDocumentReference(self.idr2)
        self.odrs = b.dbProxy.getDocumentReferences()
        self.iPersonaCharacteristics = d['persona_characteristics']
        self.ipc1 = PersonaCharacteristicParameters(
            self.iPersonaCharacteristics[0]["thePersonaName"],
            self.iPersonaCharacteristics[0]["theModQual"],
            self.iPersonaCharacteristics[0]["theVariable"],
            self.iPersonaCharacteristics[0]["theCharacteristic"],
            [(self.iPersonaCharacteristics[0]["ground"], '', 'document')],
            [(self.iPersonaCharacteristics[0]["warrant"], '', 'document')], [],
            [])
        b.dbProxy.addPersonaCharacteristic(self.ipc1)
        self.opcs = b.dbProxy.getPersonaCharacteristics()
        self.iAttackers = d['attackers']
        self.iatkeps = [
            AttackerEnvironmentProperties(
                self.iAttackers[0]["theEnvironmentProperties"][0]["theName"],
                self.iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],
                self.iAttackers[0]["theEnvironmentProperties"][0]
                ["theMotives"], self.iAttackers[0]["theEnvironmentProperties"]
                [0]["theCapabilities"])
        ]
        self.iatk = AttackerParameters(self.iAttackers[0]["theName"],
                                       self.iAttackers[0]["theDescription"],
                                       self.iAttackers[0]["theImage"], [],
                                       self.iatkeps)
        b.dbProxy.addAttacker(self.iatk)
        self.oAttackers = b.dbProxy.getAttackers()
        self.iVtypes = d['valuetypes']
        self.ivt1 = ValueTypeParameters(self.iVtypes[0]["theName"],
                                        self.iVtypes[0]["theDescription"],
                                        self.iVtypes[0]["theType"])
        self.ivt2 = ValueTypeParameters(self.iVtypes[1]["theName"],
                                        self.iVtypes[1]["theDescription"],
                                        self.iVtypes[1]["theType"])
        b.dbProxy.addValueType(self.ivt1)
        b.dbProxy.addValueType(self.ivt2)
        self.ovtt = b.dbProxy.getValueTypes('threat_type')
        self.ovtv = b.dbProxy.getValueTypes('vulnerability_type')
        self.iassets = d['assets']
        self.iaeps1 = [
            AssetEnvironmentProperties(
                self.iassets[0]["theEnvironmentProperties"][0][0],
                self.iassets[0]["theEnvironmentProperties"][0][1],
                self.iassets[0]["theEnvironmentProperties"][0][2])
        ]
        self.iaeps2 = [
            AssetEnvironmentProperties(
                self.iassets[1]["theEnvironmentProperties"][0][0],
                self.iassets[1]["theEnvironmentProperties"][0][1],
                self.iassets[1]["theEnvironmentProperties"][0][2])
        ]
        self.iaeps3 = [
            AssetEnvironmentProperties(
                self.iassets[2]["theEnvironmentProperties"][0][0],
                self.iassets[2]["theEnvironmentProperties"][0][1],
                self.iassets[2]["theEnvironmentProperties"][0][2])
        ]
        self.iap1 = AssetParameters(self.iassets[0]["theName"],
                                    self.iassets[0]["theShortCode"],
                                    self.iassets[0]["theDescription"],
                                    self.iassets[0]["theSignificance"],
                                    self.iassets[0]["theType"], "0", "N/A", [],
                                    [], self.iaeps1)
        self.iap2 = AssetParameters(self.iassets[1]["theName"],
                                    self.iassets[1]["theShortCode"],
                                    self.iassets[1]["theDescription"],
                                    self.iassets[1]["theSignificance"],
                                    self.iassets[1]["theType"], "0", "N/A", [],
                                    [], self.iaeps2)
        self.iap3 = AssetParameters(self.iassets[2]["theName"],
                                    self.iassets[2]["theShortCode"],
                                    self.iassets[2]["theDescription"],
                                    self.iassets[2]["theSignificance"],
                                    self.iassets[2]["theType"], "0", "N/A", [],
                                    [], self.iaeps3)
        b.dbProxy.addAsset(self.iap1)
        b.dbProxy.addAsset(self.iap2)
        b.dbProxy.addAsset(self.iap3)
        self.oap = b.dbProxy.getAssets()
        self.iThreats = d['threats']
        self.iteps = [
            ThreatEnvironmentProperties(
                self.iThreats[0]["theEnvironmentProperties"][0]["theName"],
                self.iThreats[0]["theEnvironmentProperties"][0]
                ["theLikelihood"],
                self.iThreats[0]["theEnvironmentProperties"][0]["theAssets"],
                self.iThreats[0]["theEnvironmentProperties"][0]
                ["theAttackers"], self.iThreats[0]["theEnvironmentProperties"]
                [0]["theProperties"][0][1], self.iThreats[0]
                ["theEnvironmentProperties"][0]["theProperties"][0][1])
        ]
        self.itps = ThreatParameters(self.iThreats[0]["theName"],
                                     self.iThreats[0]["theType"],
                                     self.iThreats[0]["theMethod"], [],
                                     self.iteps)
        b.dbProxy.addThreat(self.itps)
        self.otps = b.dbProxy.getThreats()
        self.iVuln = d['vulnerabilities']
        self.iveps = [
            VulnerabilityEnvironmentProperties(
                self.iVuln[0]["theEnvironmentProperties"][0]["theName"],
                self.iVuln[0]["theEnvironmentProperties"][0]["theSeverity"],
                self.iVuln[0]["theEnvironmentProperties"][0]["theAssets"])
        ]
        self.ivp = VulnerabilityParameters(self.iVuln[0]["theName"],
                                           self.iVuln[0]["theDescription"],
                                           self.iVuln[0]["theType"], [],
                                           self.iveps)
        b.dbProxy.addVulnerability(self.ivp)
        self.ovp = b.dbProxy.getVulnerabilities()
        self.imc = d['misuseCase']
        self.iRisks = d['risks']

        imcep = [
            MisuseCaseEnvironmentProperties(
                self.imc[0]["theEnvironmentProperties"][0]["theName"],
                self.imc[0]["theEnvironmentProperties"][0]["theDescription"])
        ]
        imcp = MisuseCase(int(0), self.imc[0]["theName"], imcep,
                          self.imc[0]["theRisk"])
        irp = RiskParameters(self.iRisks[0]["theName"],
                             self.iRisks[0]["threatName"],
                             self.iRisks[0]["vulName"], imcp, [])
        b.dbProxy.addRisk(irp)
        oRisks = b.dbProxy.getRisks()
        self.r = oRisks[self.iRisks[0]["theName"]]
        self.iResponses = d['responses']
        iar1Name = self.iResponses[0]["theType"] + " " + self.iResponses[0][
            "theRisk"]
        iaep1 = AcceptEnvironmentProperties(
            self.iResponses[0]["theEnvironmentProperties"][0],
            self.iResponses[0]["theEnvironmentProperties"][1],
            self.iResponses[0]["theEnvironmentProperties"][2])
        iar1 = ResponseParameters(iar1Name, self.iResponses[0]["theRisk"], [],
                                  [iaep1], self.iResponses[0]["theType"])

        iar2Name = self.iResponses[1]["theType"] + " " + self.iResponses[1][
            "theRisk"]
        iaep2 = MitigateEnvironmentProperties(
            self.iResponses[1]["theEnvironmentProperties"],
            self.iResponses[1]["theType"])
        iar2 = ResponseParameters(iar2Name, self.iResponses[1]["theRisk"], [],
                                  [iaep2], self.iResponses[1]["theType"])

        b.dbProxy.addResponse(iar1)
        b.dbProxy.addResponse(iar2)

        self.ors = b.dbProxy.getResponses()
        self.oar1 = self.ors[iar1Name]
        self.oar2 = self.ors[iar2Name]

        rgp = cairis.core.GoalFactory.build(self.oar2)
        riskParameters = rgp[0]
        riskGoalId = b.dbProxy.addGoal(riskParameters)
        b.dbProxy.addTrace('response_goal', self.oar2.id(), riskGoalId)
        if (rgp > 1):
            threatParameters = rgp[1]
            vulnerabilityParameters = rgp[2]
            b.dbProxy.addGoal(vulnerabilityParameters)
            b.dbProxy.addGoal(threatParameters)
        b.dbProxy.relabelGoals(iaep2.name())

        oGoals = b.dbProxy.getGoals()
        self.rg = oGoals['Deter' + self.oar2.risk()]
        self.vg = oGoals[vulnerabilityParameters.name()]
        self.tg = oGoals[threatParameters.name()]

        ogops = b.dbProxy.getGoalAssociations()
        self.ogop1 = ogops[iaep2.name() + '/' + riskParameters.name() + '/' +
                           threatParameters.name() + '/or']
        self.ogop2 = ogops[iaep2.name() + '/' + riskParameters.name() + '/' +
                           vulnerabilityParameters.name() + '/or']

        self.reqId = b.dbProxy.newId()
        self.irequirements = d['requirements']
        self.ireq = cairis.core.RequirementFactory.build(
            self.reqId, self.irequirements[0]["theLabel"],
            self.irequirements[0]["theName"],
            self.irequirements[0]["theDescription"],
            self.irequirements[0]["thePriority"],
            self.irequirements[0]["theRationale"],
            self.irequirements[0]["theFitCriterion"],
            self.irequirements[0]["theOriginator"],
            self.irequirements[0]["theType"],
            self.irequirements[0]["theReference"], 1)
        b.dbProxy.addRequirement(self.ireq,
                                 self.irequirements[0]["theReference"], True)
        oreqs = b.dbProxy.getRequirements()
        self.oreq = oreqs[self.ireq.description()]

        iga = GoalAssociationParameters(iaep2.name(),
                                        self.vg.name(), 'goal', 'and',
                                        self.oreq.name(), 'requirement', 0,
                                        'None')
        b.dbProxy.addGoalAssociation(iga)
        ogops = b.dbProxy.getGoalAssociations()
        self.ogop3 = ogops[iaep2.name() + '/' + self.vg.name() + '/' +
                           self.oreq.name() + '/and']

        self.iCountermeasures = d['countermeasures']
Esempio n. 14
0
  def setUp(self):
    call([os.environ['CAIRIS_CFG_DIR'] + "/initdb.sh"])
    cairis.core.BorgFactory.initialise()
    f = open(os.environ['CAIRIS_SRC'] + '/test/countermeasures.json')
    d = json.load(f)
    f.close()
    ienvs = d['environments']
    iep1 = EnvironmentParameters(ienvs[0]["theName"],ienvs[0]["theShortCode"],ienvs[0]["theDescription"])
    b = Borg()
    b.dbProxy.addEnvironment(iep1)
    iRoles = d['roles']
    irp = RoleParameters(iRoles[0]["theName"], iRoles[0]["theType"], iRoles[0]["theShortCode"], iRoles[0]["theDescription"],[])
    b.dbProxy.addRole(irp)
    iPersonas = d['personas']
    ipp = PersonaParameters(iPersonas[0]["theName"],iPersonas[0]["theActivities"],iPersonas[0]["theAttitudes"],iPersonas[0]["theAptitudes"],iPersonas[0]["theMotivations"],iPersonas[0]["theSkills"],iPersonas[0]["theIntrinsic"],iPersonas[0]["theContextual"],"","0",iPersonas[0]["thePersonaType"],[],[PersonaEnvironmentProperties(iPersonas[0]["theEnvironmentProperties"][0]["theName"],(iPersonas[0]["theEnvironmentProperties"][0]["theDirectFlag"] == "True"),iPersonas[0]["theEnvironmentProperties"][0]["theNarrative"],iPersonas[0]["theEnvironmentProperties"][0]["theRole"])],[])
    b.dbProxy.addPersona(ipp)
    iAttackers = d['attackers']
    iatkeps = [AttackerEnvironmentProperties(iAttackers[0]["theEnvironmentProperties"][0]["theName"],iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],iAttackers[0]["theEnvironmentProperties"][0]["theMotives"],iAttackers[0]["theEnvironmentProperties"][0]["theCapabilities"])]
    iatk = AttackerParameters(iAttackers[0]["theName"], iAttackers[0]["theDescription"], iAttackers[0]["theImage"],[],iatkeps)
    b.dbProxy.addAttacker(iatk)
    iVtypes = d['valuetypes']
    ivt1 = ValueTypeParameters(iVtypes[0]["theName"], iVtypes[0]["theDescription"], iVtypes[0]["theType"])
    ivt2 = ValueTypeParameters(iVtypes[1]["theName"], iVtypes[1]["theDescription"], iVtypes[1]["theType"])
    b.dbProxy.addValueType(ivt1)
    b.dbProxy.addValueType(ivt2)
    iassets = d['assets']
    iaeps1 = [AssetEnvironmentProperties(iassets[0]["theEnvironmentProperties"][0][0],iassets[0]["theEnvironmentProperties"][0][1],iassets[0]["theEnvironmentProperties"][0][2])]
    iaeps2 = [AssetEnvironmentProperties(iassets[1]["theEnvironmentProperties"][0][0],iassets[1]["theEnvironmentProperties"][0][1],iassets[1]["theEnvironmentProperties"][0][2])]
    iaeps3 = [AssetEnvironmentProperties(iassets[2]["theEnvironmentProperties"][0][0],iassets[2]["theEnvironmentProperties"][0][1],iassets[2]["theEnvironmentProperties"][0][2])]
    iap1 = AssetParameters(iassets[0]["theName"],iassets[0]["theShortCode"],iassets[0]["theDescription"],iassets[0]["theSignificance"],iassets[0]["theType"],"0","N/A",[],[],iaeps1)
    iap2 = AssetParameters(iassets[1]["theName"],iassets[1]["theShortCode"],iassets[1]["theDescription"],iassets[1]["theSignificance"],iassets[1]["theType"],"0","N/A",[],[],iaeps2)
    iap3 = AssetParameters(iassets[2]["theName"],iassets[2]["theShortCode"],iassets[2]["theDescription"],iassets[2]["theSignificance"],iassets[2]["theType"],"0","N/A",[],[],iaeps3)
    b.dbProxy.addAsset(iap1)
    b.dbProxy.addAsset(iap2)
    b.dbProxy.addAsset(iap3)
    iThreats = d['threats']
    iteps = [ThreatEnvironmentProperties(iThreats[0]["theEnvironmentProperties"][0]["theName"],iThreats[0]["theEnvironmentProperties"][0]["theLikelihood"],iThreats[0]["theEnvironmentProperties"][0]["theAssets"],iThreats[0]["theEnvironmentProperties"][0]["theAttackers"],iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0][1],iThreats[0]["theEnvironmentProperties"][0]["theProperties"][0][1])]
    itps = ThreatParameters(iThreats[0]["theName"],iThreats[0]["theType"],iThreats[0]["theMethod"],[],iteps)
    b.dbProxy.addThreat(itps)
    iVuln = d['vulnerabilities']
    iveps = [VulnerabilityEnvironmentProperties(iVuln[0]["theEnvironmentProperties"][0]["theName"],iVuln[0]["theEnvironmentProperties"][0]["theSeverity"],iVuln[0]["theEnvironmentProperties"][0]["theAssets"])]
    ivp = VulnerabilityParameters(iVuln[0]["theName"],iVuln[0]["theDescription"],iVuln[0]["theType"], [], iveps)
    b.dbProxy.addVulnerability(ivp)
    imc = d['misuseCase']
    iRisks = d['risks']
    imcep = [MisuseCaseEnvironmentProperties(imc[0]["theEnvironmentProperties"][0]["theName"],imc[0]["theEnvironmentProperties"][0]["theDescription"])]
    imcp = MisuseCase(int(0), imc[0]["theName"], imcep,imc[0]["theRisk"])
    irp = RiskParameters(iRisks[0]["theName"],iRisks[0]["threatName"],iRisks[0]["vulName"], imcp,[])
    b.dbProxy.addRisk(irp)
    iResponses = d['responses']
    iar1Name = iResponses[0]["theType"] + " " + iResponses[0]["theRisk"] 
    iaep1 = AcceptEnvironmentProperties(iResponses[0]["theEnvironmentProperties"][0],iResponses[0]["theEnvironmentProperties"][1],iResponses[0]["theEnvironmentProperties"][2])
    iar1 = ResponseParameters(iar1Name,iResponses[0]["theRisk"],[],[iaep1], iResponses[0]["theType"])

    iar2Name = iResponses[1]["theType"] + " " + iResponses[1]["theRisk"] 
    iaep2 = MitigateEnvironmentProperties(iResponses[1]["theEnvironmentProperties"],iResponses[1]["theType"])
    iar2 = ResponseParameters(iar2Name,iResponses[1]["theRisk"],[],[iaep2], iResponses[1]["theType"])

    b.dbProxy.addResponse(iar1)
    b.dbProxy.addResponse(iar2)

    ors = b.dbProxy.getResponses()
    oar1 = ors[iar1Name]
    oar2 = ors[iar2Name]

    rgp = cairis.core.GoalFactory.build(oar2)
    riskParameters = rgp[0]
    riskGoalId = b.dbProxy.addGoal(riskParameters)
    b.dbProxy.addTrace('response_goal',oar2.id(),riskGoalId)
    if (len(rgp) > 1):
      threatParameters = rgp[1]
      vulnerabilityParameters = rgp[2]
      b.dbProxy.addGoal(vulnerabilityParameters)
      b.dbProxy.addGoal(threatParameters)
    b.dbProxy.relabelGoals(iaep2.name())

    oGoals = b.dbProxy.getGoals()
    rg = oGoals['Deter' + oar2.risk()]
    vg = oGoals[vulnerabilityParameters.name()]
    tg = oGoals[threatParameters.name()]

    reqId = b.dbProxy.newId()
    irequirements = d['requirements']
    ireq = cairis.core.RequirementFactory.build(reqId,irequirements[0]["theLabel"],irequirements[0]["theName"],irequirements[0]["theDescription"],irequirements[0]["thePriority"],irequirements[0]["theRationale"],irequirements[0]["theFitCriterion"],irequirements[0]["theOriginator"],irequirements[0]["theType"],irequirements[0]["theReference"],1)
    b.dbProxy.addRequirement(ireq,irequirements[0]["theReference"],True)

    oreqs = b.dbProxy.getRequirements()
    oreq = oreqs[ireq.description()]

    iga = GoalAssociationParameters(iaep2.name(),vg.name(),'goal','and',oreq.name(),'requirement',0,'None')
    b.dbProxy.addGoalAssociation(iga)
    ogops = b.dbProxy.getGoalAssociations()
    self.ogop3 = ogops[iaep2.name() + '/' + vg.name() + '/' + oreq.name() + '/and']
    self.iCountermeasures = d['countermeasures']
Esempio n. 15
0
    def endElement(self, name):
        if name == "intent":
            self.inIntent = 0
        elif name == "definition":
            self.inDefinition = 0
        elif name == "rationale":
            self.inRationale = 0
        elif name == "motivation":
            self.theMotivations.append((self.theGoal, self.theValue, self.theDescription))
            self.resetMotivationElements()
        elif name == "participant":
            self.theParticipants.append((self.theParticipant, self.theMotives, self.theResponsibilities))
            self.resetParticipantElements()
        elif name == "description":
            self.inDescription = 0
            if self.inImplementation:
                self.inImplementation = 0
        elif name == "consequences":
            self.inConsequences = 0
        elif name == "implementation":
            self.inImplementation = 0
        elif name == "known_uses":
            self.inKnownUses = 0
        elif name == "related_patterns":
            self.inRelatedPatterns = 0
        elif name == "obstacle":

            self.theObstacles.append(
                TemplateObstacleParameters(
                    self.theObstacleName,
                    self.theObstacleCategory,
                    self.theDefinition,
                    self.theConcerns,
                    self.theResponsibilities,
                    self.theProbability,
                    self.theRationale,
                )
            )
            self.resetObstacleElements()
        elif name == "obstacle_association":
            self.theObstacleAssociations.append(
                (self.theObstacleName, self.theRefType, self.theSubObstacleName, self.theRationale)
            )
            self.resetObstacleAssociationElements()
        elif name == "attack_pattern":
            assetList = self.theTargets + self.theExploits
            for assetName in assetList:
                self.theAssetParameters.append(
                    cairis.core.AssetParametersFactory.buildFromTemplate(assetName, [self.theEnvironment])
                )

            attackerNames = []
            for attackerName, attackerMotives, attackerCapabilities in self.theParticipants:
                attackerRoles = self.dbProxy.dimensionRoles(
                    self.dbProxy.getDimensionId(attackerName, "persona"),
                    self.dbProxy.getDimensionId(self.theEnvironment, "environment"),
                    "persona",
                )
                ep = AttackerEnvironmentProperties(
                    self.theEnvironment, attackerRoles, attackerMotives, attackerCapabilities
                )
                p = AttackerParameters(attackerName, "", "", [], [ep])
                p.isPersona = True
                self.theAttackerParameters.append(p)
                attackerNames.append(attackerName)

            for tObs in self.theObstacles:
                sgRefs = []
                for resp in tObs.responsibilities():
                    sgRefs.append((resp, "role", "responsible", 0, "None"))
                ep = ObstacleEnvironmentProperties(
                    self.theEnvironment, "", tObs.definition(), tObs.category(), [], sgRefs, tObs.concerns()
                )
                ep.theProbability = tObs.probability()
                ep.theProbabilityRationale = tObs.probabilityRationale()
                self.theObstacleParameters.append(ObstacleParameters(tObs.name(), self.thePatternName, [], [ep]))

            for obsAssoc in self.theObstacleAssociations:
                obsName = obsAssoc[0]
                refType = obsAssoc[1]
                subObsName = obsAssoc[2]
                assocRationale = obsAssoc[3]
                self.theObstacleAssociationParameters.append(
                    GoalAssociationParameters(
                        self.theEnvironment, obsName, "obstacle", refType, subObsName, "obstacle", 0, assocRationale
                    )
                )

            vp = VulnerabilityEnvironmentProperties(self.theEnvironment, self.theSeverity, self.theExploits)
            vulRows = self.dbProxy.getVulnerabilityDirectory(self.theExploit)
            vulData = vulRows[0]
            self.theVulnerabilityParameters = VulnerabilityParameters(self.theExploit, vulData[2], vulData[3], [], [vp])

            spDict = {}
            spDict["confidentiality"] = (0, "None")
            spDict["integrity"] = (0, "None")
            spDict["availability"] = (0, "None")
            spDict["accountability"] = (0, "None")
            spDict["anonymity"] = (0, "None")
            spDict["pseudonymity"] = (0, "None")
            spDict["unlinkability"] = (0, "None")
            spDict["unobservability"] = (0, "None")

            for thrMotivation in self.theMotivations:
                spName = thrMotivation[0]
                spValue = thrMotivation[1]
                spRationale = thrMotivation[2]
                spDict[spName] = (a2i(spValue), spRationale)

            cProperty, cRationale = spDict["confidentiality"]
            iProperty, iRationale = spDict["integrity"]
            avProperty, avRationale = spDict["availability"]
            acProperty, acRationale = spDict["accountability"]
            anProperty, anRationale = spDict["anonymity"]
            panProperty, panRationale = spDict["pseudonymity"]
            unlProperty, unlRationale = spDict["unlinkability"]
            unoProperty, unoRationale = spDict["unobservability"]

            tp = ThreatEnvironmentProperties(
                self.theEnvironment,
                self.theLikelihood,
                self.theTargets,
                attackerNames,
                [cProperty, iProperty, avProperty, acProperty, anProperty, panProperty, unlProperty, unoProperty],
                [
                    cRationale,
                    iRationale,
                    avRationale,
                    acRationale,
                    anRationale,
                    panRationale,
                    unlRationale,
                    unoRationale,
                ],
            )
            thrRows = self.dbProxy.getThreatDirectory(self.theAttack)
            thrData = thrRows[0]
            self.theThreatParameters = ThreatParameters(self.theAttack, thrData[3], thrData[2], [], [tp])

            if self.theAttackObstacle != "":
                self.theObstacleAssociationParameters.append(
                    GoalAssociationParameters(
                        self.theEnvironment,
                        self.theAttackObstacle,
                        "obstacle",
                        "or",
                        self.theAttack,
                        "threat",
                        0,
                        "None",
                    )
                )
            if self.theExploitObstacle != "":
                self.theObstacleAssociationParameters.append(
                    GoalAssociationParameters(
                        self.theEnvironment,
                        self.theExploitObstacle,
                        "obstacle",
                        "or",
                        self.theExploit,
                        "vulnerability",
                        0,
                        "None",
                    )
                )
            rep = MisuseCaseEnvironmentProperties(self.theEnvironment, self.theImplementation)
            mc = MisuseCase(-1, "Exploit " + self.thePatternName, [rep], self.thePatternName)
            self.theRiskParameters = RiskParameters(
                self.thePatternName, self.theAttack, self.theExploit, mc, [], self.theIntent
            )
Esempio n. 16
0
    def setUp(self):
        call([os.environ['CAIRIS_SRC'] + "/test/initdb.sh"])
        cairis.core.BorgFactory.initialise()
        f = open(os.environ['CAIRIS_SRC'] + '/test/responses.json')
        d = json.load(f)
        f.close()
        self.ienvs = d['environments']
        self.iep1 = EnvironmentParameters(self.ienvs[0]["theName"],
                                          self.ienvs[0]["theShortCode"],
                                          self.ienvs[0]["theDescription"])
        b = Borg()
        b.dbProxy.addEnvironment(self.iep1)
        self.oenvs = b.dbProxy.getEnvironments()
        self.iRoles = d['roles']
        self.irp = RoleParameters(self.iRoles[0]["theName"],
                                  self.iRoles[0]["theType"],
                                  self.iRoles[0]["theShortCode"],
                                  self.iRoles[0]["theDescription"], [])
        b.dbProxy.addRole(self.irp)
        self.oRoles = b.dbProxy.getRoles()
        self.iPersonas = d['personas']
        self.ipp = PersonaParameters(
            self.iPersonas[0]["theName"], self.iPersonas[0]["theActivities"],
            self.iPersonas[0]["theAttitudes"],
            self.iPersonas[0]["theAptitudes"],
            self.iPersonas[0]["theMotivations"],
            self.iPersonas[0]["theSkills"], self.iPersonas[0]["theIntrinsic"],
            self.iPersonas[0]["theContextual"], "", "0",
            self.iPersonas[0]["thePersonaType"], [], [
                PersonaEnvironmentProperties(
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theName"], (self.iPersonas[0]["theEnvironmentProperties"]
                                  [0]["theDirectFlag"] == "True"),
                    self.iPersonas[0]["theEnvironmentProperties"][0]
                    ["theNarrative"], self.iPersonas[0]
                    ["theEnvironmentProperties"][0]["theRole"])
            ], [])
        b.dbProxy.addPersona(self.ipp)
        self.opp = b.dbProxy.getPersonas()
        self.iExternalDocuments = d['external_documents']
        self.iec1 = ExternalDocumentParameters(
            self.iExternalDocuments[0]["theName"],
            self.iExternalDocuments[0]["theVersion"],
            self.iExternalDocuments[0]["thePublicationDate"],
            self.iExternalDocuments[0]["theAuthors"],
            self.iExternalDocuments[0]["theDescription"])
        self.iec2 = ExternalDocumentParameters(
            self.iExternalDocuments[1]["theName"],
            self.iExternalDocuments[1]["theVersion"],
            self.iExternalDocuments[1]["thePublicationDate"],
            self.iExternalDocuments[1]["theAuthors"],
            self.iExternalDocuments[1]["theDescription"])
        b.dbProxy.addExternalDocument(self.iec1)
        b.dbProxy.addExternalDocument(self.iec2)
        self.oecs = b.dbProxy.getExternalDocuments()
        self.iDocumentReferences = d['document_references']
        self.idr1 = DocumentReferenceParameters(
            self.iDocumentReferences[0]["theName"],
            self.iDocumentReferences[0]["theDocName"],
            self.iDocumentReferences[0]["theContributor"],
            self.iDocumentReferences[0]["theExcerpt"])
        self.idr2 = DocumentReferenceParameters(
            self.iDocumentReferences[1]["theName"],
            self.iDocumentReferences[1]["theDocName"],
            self.iDocumentReferences[1]["theContributor"],
            self.iDocumentReferences[1]["theExcerpt"])
        b.dbProxy.addDocumentReference(self.idr1)
        b.dbProxy.addDocumentReference(self.idr2)
        self.odrs = b.dbProxy.getDocumentReferences()
        self.iPersonaCharacteristics = d['persona_characteristics']
        self.ipc1 = PersonaCharacteristicParameters(
            self.iPersonaCharacteristics[0]["thePersonaName"],
            self.iPersonaCharacteristics[0]["theModQual"],
            self.iPersonaCharacteristics[0]["theVariable"],
            self.iPersonaCharacteristics[0]["theCharacteristic"],
            [(self.iPersonaCharacteristics[0]["ground"], '', 'document')],
            [(self.iPersonaCharacteristics[0]["warrant"], '', 'document')], [],
            [])
        b.dbProxy.addPersonaCharacteristic(self.ipc1)
        self.opcs = b.dbProxy.getPersonaCharacteristics()
        self.iAttackers = d['attackers']
        self.iatkeps = [
            AttackerEnvironmentProperties(
                self.iAttackers[0]["theEnvironmentProperties"][0]["theName"],
                self.iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],
                self.iAttackers[0]["theEnvironmentProperties"][0]
                ["theMotives"], self.iAttackers[0]["theEnvironmentProperties"]
                [0]["theCapabilities"])
        ]
        self.iatk = AttackerParameters(self.iAttackers[0]["theName"],
                                       self.iAttackers[0]["theDescription"],
                                       self.iAttackers[0]["theImage"], [],
                                       self.iatkeps)
        b.dbProxy.addAttacker(self.iatk)
        self.oAttackers = b.dbProxy.getAttackers()
        self.iVtypes = d['valuetypes']
        self.ivt1 = ValueTypeParameters(self.iVtypes[0]["theName"],
                                        self.iVtypes[0]["theDescription"],
                                        self.iVtypes[0]["theType"])
        self.ivt2 = ValueTypeParameters(self.iVtypes[1]["theName"],
                                        self.iVtypes[1]["theDescription"],
                                        self.iVtypes[1]["theType"])
        b.dbProxy.addValueType(self.ivt1)
        b.dbProxy.addValueType(self.ivt2)
        self.ovtt = b.dbProxy.getValueTypes('threat_type')
        self.ovtv = b.dbProxy.getValueTypes('vulnerability_type')
        self.iassets = d['assets']
        self.iaeps1 = [
            AssetEnvironmentProperties(
                self.iassets[0]["theEnvironmentProperties"][0][0],
                self.iassets[0]["theEnvironmentProperties"][0][1],
                self.iassets[0]["theEnvironmentProperties"][0][2])
        ]
        self.iaeps2 = [
            AssetEnvironmentProperties(
                self.iassets[1]["theEnvironmentProperties"][0][0],
                self.iassets[1]["theEnvironmentProperties"][0][1],
                self.iassets[1]["theEnvironmentProperties"][0][2])
        ]
        self.iaeps3 = [
            AssetEnvironmentProperties(
                self.iassets[2]["theEnvironmentProperties"][0][0],
                self.iassets[2]["theEnvironmentProperties"][0][1],
                self.iassets[2]["theEnvironmentProperties"][0][2])
        ]
        self.iap1 = AssetParameters(self.iassets[0]["theName"],
                                    self.iassets[0]["theShortCode"],
                                    self.iassets[0]["theDescription"],
                                    self.iassets[0]["theSignificance"],
                                    self.iassets[0]["theType"], "0", "N/A", [],
                                    [], self.iaeps1)
        self.iap2 = AssetParameters(self.iassets[1]["theName"],
                                    self.iassets[1]["theShortCode"],
                                    self.iassets[1]["theDescription"],
                                    self.iassets[1]["theSignificance"],
                                    self.iassets[1]["theType"], "0", "N/A", [],
                                    [], self.iaeps2)
        self.iap3 = AssetParameters(self.iassets[2]["theName"],
                                    self.iassets[2]["theShortCode"],
                                    self.iassets[2]["theDescription"],
                                    self.iassets[2]["theSignificance"],
                                    self.iassets[2]["theType"], "0", "N/A", [],
                                    [], self.iaeps3)
        b.dbProxy.addAsset(self.iap1)
        b.dbProxy.addAsset(self.iap2)
        b.dbProxy.addAsset(self.iap3)
        self.oap = b.dbProxy.getAssets()
        self.iThreats = d['threats']
        self.iteps = [
            ThreatEnvironmentProperties(
                self.iThreats[0]["theEnvironmentProperties"][0]["theName"],
                self.iThreats[0]["theEnvironmentProperties"][0]
                ["theLikelihood"],
                self.iThreats[0]["theEnvironmentProperties"][0]["theAssets"],
                self.iThreats[0]["theEnvironmentProperties"][0]
                ["theAttackers"], self.iThreats[0]["theEnvironmentProperties"]
                [0]["theProperties"][0][1], self.iThreats[0]
                ["theEnvironmentProperties"][0]["theProperties"][0][1])
        ]
        self.itps = ThreatParameters(self.iThreats[0]["theName"],
                                     self.iThreats[0]["theType"],
                                     self.iThreats[0]["theMethod"], [],
                                     self.iteps)
        b.dbProxy.addThreat(self.itps)
        self.otps = b.dbProxy.getThreats()
        self.iVuln = d['vulnerabilities']
        self.iveps = [
            VulnerabilityEnvironmentProperties(
                self.iVuln[0]["theEnvironmentProperties"][0]["theName"],
                self.iVuln[0]["theEnvironmentProperties"][0]["theSeverity"],
                self.iVuln[0]["theEnvironmentProperties"][0]["theAssets"])
        ]
        self.ivp = VulnerabilityParameters(self.iVuln[0]["theName"],
                                           self.iVuln[0]["theDescription"],
                                           self.iVuln[0]["theType"], [],
                                           self.iveps)
        b.dbProxy.addVulnerability(self.ivp)
        self.ovp = b.dbProxy.getVulnerabilities()
        self.imc = d['misuseCase']
        self.iRisks = d['risks']

        imcep = [
            MisuseCaseEnvironmentProperties(
                self.imc[0]["theEnvironmentProperties"][0]["theName"],
                self.imc[0]["theEnvironmentProperties"][0]["theDescription"])
        ]
        imcp = MisuseCase(int(0), self.imc[0]["theName"], imcep,
                          self.imc[0]["theRisk"])
        irp = RiskParameters(self.iRisks[0]["theName"],
                             self.iRisks[0]["threatName"],
                             self.iRisks[0]["vulName"], imcp, [])
        b.dbProxy.addRisk(irp)
        oRisks = b.dbProxy.getRisks()
        self.r = oRisks[self.iRisks[0]["theName"]]
        self.iResponses = d['responses']
  def endElement(self,name):
    if name == 'intent':
      self.inIntent = 0
    elif name == 'definition':
      self.inDefinition = 0
    elif name == 'rationale':
      self.inRationale = 0
    elif name == 'motivation':
      self.theMotivations.append((self.theGoal,self.theValue,self.theDescription))
      self.resetMotivationElements()
    elif name == 'participant':
      self.theParticipants.append((self.theParticipant,self.theMotives,self.theResponsibilities))
      self.resetParticipantElements()
    elif name == 'description':
      self.inDescription = 0
      if self.inImplementation:
        self.inImplementation = 0
    elif name == 'consequences':
      self.inConsequences = 0
    elif name == 'implementation':
      self.inImplementation = 0
    elif name == 'known_uses':
      self.inKnownUses = 0
    elif name == 'related_patterns':
      self.inRelatedPatterns = 0
    elif name == 'obstacle':

      self.theObstacles.append( TemplateObstacleParameters(self.theObstacleName,self.theObstacleCategory,self.theDefinition,self.theConcerns,self.theResponsibilities,self.theProbability,self.theRationale))
      self.resetObstacleElements()
    elif name == 'obstacle_association':
      self.theObstacleAssociations.append((self.theObstacleName,self.theRefType,self.theSubObstacleName,self.theRationale))
      self.resetObstacleAssociationElements()
    elif name == 'attack_pattern':
      assetList = self.theTargets + self.theExploits
      for assetName in assetList:
        self.theAssetParameters.append(AssetParametersFactory.buildFromTemplate(assetName,[self.theEnvironment]))

      attackerNames = []
      for attackerName,attackerMotives,attackerCapabilities in self.theParticipants:
        attackerRoles = self.dbProxy.dimensionRoles(self.dbProxy.getDimensionId(attackerName,'persona'),self.dbProxy.getDimensionId(self.theEnvironment,'environment'),'persona')
        ep = AttackerEnvironmentProperties(self.theEnvironment,attackerRoles,attackerMotives,attackerCapabilities)
        p = AttackerParameters(attackerName,'','',[],[ep])
        p.isPersona = True
        self.theAttackerParameters.append(p) 
        attackerNames.append(attackerName)
  
      for tObs in self.theObstacles:
        sgRefs = []
        for resp in tObs.responsibilities():
          sgRefs.append((resp,'role','responsible',0,'None')) 
        ep = ObstacleEnvironmentProperties(self.theEnvironment,'',tObs.definition(),tObs.category(),[],sgRefs,tObs.concerns())
        ep.theProbability = tObs.probability()
        ep.theProbabilityRationale = tObs.probabilityRationale()
        self.theObstacleParameters.append(ObstacleParameters(tObs.name(),self.thePatternName,[],[ep]))

      for obsAssoc in self.theObstacleAssociations:
        obsName = obsAssoc[0]
        refType = obsAssoc[1]
        subObsName = obsAssoc[2]
        assocRationale = obsAssoc[3]  
        self.theObstacleAssociationParameters.append(GoalAssociationParameters(self.theEnvironment,obsName,'obstacle',refType,subObsName,'obstacle',0,assocRationale))
 
      vp = VulnerabilityEnvironmentProperties(self.theEnvironment,self.theSeverity,self.theExploits)
      vulRows = self.dbProxy.getVulnerabilityDirectory(self.theExploit)
      vulData = vulRows[0]
      self.theVulnerabilityParameters = VulnerabilityParameters(self.theExploit,vulData[2],vulData[3],[],[vp])

      spDict = {}
      spDict['confidentiality'] = (0,'None')
      spDict['integrity'] = (0,'None')
      spDict['availability'] = (0,'None')
      spDict['accountability'] = (0,'None')
      spDict['anonymity'] = (0,'None')
      spDict['pseudonymity'] = (0,'None')
      spDict['unlinkability'] = (0,'None')
      spDict['unobservability'] = (0,'None')

      for thrMotivation in self.theMotivations:
        spName = thrMotivation[0]
        spValue = thrMotivation[1]
        spRationale = thrMotivation[2]
        spDict[spName] = (a2i(spValue),spRationale)
      
      cProperty,cRationale = spDict['confidentiality']
      iProperty,iRationale = spDict['integrity']
      avProperty,avRationale = spDict['availability']
      acProperty,acRationale = spDict['accountability']
      anProperty,anRationale = spDict['anonymity']
      panProperty,panRationale = spDict['pseudonymity']
      unlProperty,unlRationale = spDict['unlinkability']
      unoProperty,unoRationale = spDict['unobservability']

      tp = ThreatEnvironmentProperties(self.theEnvironment,self.theLikelihood,self.theTargets,attackerNames,[cProperty,iProperty,avProperty,acProperty,anProperty,panProperty,unlProperty,unoProperty],[cRationale,iRationale,avRationale,acRationale,anRationale,panRationale,unlRationale,unoRationale])
      thrRows = self.dbProxy.getThreatDirectory(self.theAttack)
      thrData = thrRows[0]
      self.theThreatParameters = ThreatParameters(self.theAttack,thrData[3],thrData[2],[],[tp])

      if (self.theAttackObstacle != ''):
        self.theObstacleAssociationParameters.append(GoalAssociationParameters(self.theEnvironment,self.theAttackObstacle,'obstacle','or',self.theAttack,'threat',0,'None'))
      if (self.theExploitObstacle != ''):
        self.theObstacleAssociationParameters.append(GoalAssociationParameters(self.theEnvironment,self.theExploitObstacle,'obstacle','or',self.theExploit,'vulnerability',0,'None'))
      rep = MisuseCaseEnvironmentProperties(self.theEnvironment,self.theImplementation )
      mc = MisuseCase(-1,'Exploit ' + self.thePatternName,[rep],self.thePatternName)
      self.theRiskParameters = RiskParameters(self.thePatternName,self.theAttack,self.theExploit,mc,[],self.theIntent,self.theEnvironment)
Esempio n. 18
0
 def setUp(self):
     call([os.environ['CAIRIS_CFG_DIR'] + "/initdb.sh"])
     cairis.core.BorgFactory.initialise()
     f = open(os.environ['CAIRIS_SRC'] + '/test/threats.json')
     d = json.load(f)
     f.close()
     ienvs = d['environments']
     iep = EnvironmentParameters(ienvs[0]["theName"],
                                 ienvs[0]["theShortCode"],
                                 ienvs[0]["theDescription"])
     iep1 = EnvironmentParameters(ienvs[1]["theName"],
                                  ienvs[1]["theShortCode"],
                                  ienvs[1]["theDescription"])
     b = Borg()
     b.dbProxy.addEnvironment(iep)
     b.dbProxy.addEnvironment(iep1)
     iRoles = d['roles']
     irp = RoleParameters(iRoles[0]["theName"], iRoles[0]["theType"],
                          iRoles[0]["theShortCode"],
                          iRoles[0]["theDescription"], [])
     b.dbProxy.addRole(irp)
     iAttackers = d['attackers']
     iatkeps = [
         AttackerEnvironmentProperties(
             iAttackers[0]["theEnvironmentProperties"][0]["theName"],
             iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],
             iAttackers[0]["theEnvironmentProperties"][0]["theMotives"],
             iAttackers[0]["theEnvironmentProperties"][0]
             ["theCapabilities"]),
         AttackerEnvironmentProperties(
             iAttackers[0]["theEnvironmentProperties"][1]["theName"],
             iAttackers[0]["theEnvironmentProperties"][1]["theRoles"],
             iAttackers[0]["theEnvironmentProperties"][1]["theMotives"],
             iAttackers[0]["theEnvironmentProperties"][1]
             ["theCapabilities"])
     ]
     iatk = AttackerParameters(iAttackers[0]["theName"],
                               iAttackers[0]["theDescription"],
                               iAttackers[0]["theImage"], [], iatkeps)
     b.dbProxy.addAttacker(iatk)
     iVtypes = d['valuetypes']
     ivt = ValueTypeParameters(iVtypes[0]["theName"],
                               iVtypes[0]["theDescription"],
                               iVtypes[0]["theType"])
     b.dbProxy.addValueType(ivt)
     iassets = d['assets']
     iaeps = [
         AssetEnvironmentProperties(
             iassets[0]["theEnvironmentProperties"][0][0],
             iassets[0]["theEnvironmentProperties"][0][1],
             iassets[0]["theEnvironmentProperties"][0][2]),
         AssetEnvironmentProperties(
             iassets[0]["theEnvironmentProperties"][1][0],
             iassets[0]["theEnvironmentProperties"][1][1],
             iassets[0]["theEnvironmentProperties"][1][2])
     ]
     iap = AssetParameters(iassets[0]["theName"],
                           iassets[0]["theShortCode"],
                           iassets[0]["theDescription"],
                           iassets[0]["theSignificance"],
                           iassets[0]["theType"], "0", "N/A", [], [], iaeps)
     b.dbProxy.addAsset(iap)
     self.iThreats = d['threats']