Search in sources :

Example 1 with ADTree

use of com.ge.verdict.attackdefensecollector.adtree.ADTree in project VERDICT by ge-high-assurance.

the class VerdictSynthesisTest method partialSolutionTest.

@Test
public void partialSolutionTest() {
    CostModel costModel = new CostModel(new File(getClass().getResource("partialCosts.xml").getPath()));
    int dal = 2;
    SystemModel system = new SystemModel("C1");
    Attack attack1 = new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I);
    Defense defense1 = new Defense(attack1);
    defense1.addDefenseClause(Collections.singletonList(new Defense.DefenseLeaf("D1", Optional.of(new com.ge.verdict.attackdefensecollector.Pair<>("D1", 1)))));
    ADTree adtree = new ADOr(new ADAnd(new ADNot(defense1), attack1));
    for (Approach approach : Approach.values()) {
        {
            DLeaf.Factory factoryPartial = new DLeaf.Factory();
            Optional<Pair<Set<ComponentDefense>, Double>> resultPartial = VerdictSynthesis.performSynthesisSingle(DTreeConstructor.construct(adtree, costModel, dal, true, false, factoryPartial), dal, factoryPartial, approach);
            Assertions.assertThat(resultPartial.isPresent());
            Assertions.assertThat(resultPartial.get().right).isEqualTo(1);
        }
        {
            DLeaf.Factory factoryTotal = new DLeaf.Factory();
            Optional<Pair<Set<ComponentDefense>, Double>> resultTotal = VerdictSynthesis.performSynthesisSingle(DTreeConstructor.construct(adtree, costModel, dal, false, false, factoryTotal), dal, factoryTotal, approach);
            Assertions.assertThat(resultTotal.isPresent());
            Assertions.assertThat(resultTotal.get().right).isEqualTo(2);
        }
    }
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) Set(java.util.Set) ADNot(com.ge.verdict.attackdefensecollector.adtree.ADNot) Optional(java.util.Optional) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) Attack(com.ge.verdict.attackdefensecollector.adtree.Attack) Defense(com.ge.verdict.attackdefensecollector.adtree.Defense) ComponentDefense(com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) SystemModel(com.ge.verdict.attackdefensecollector.model.SystemModel) Approach(com.ge.verdict.synthesis.VerdictSynthesis.Approach) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) File(java.io.File) Pair(com.ge.verdict.synthesis.util.Pair) Test(org.junit.Test)

Example 2 with ADTree

use of com.ge.verdict.attackdefensecollector.adtree.ADTree in project VERDICT by ge-high-assurance.

the class AttackDefenseCollector method perform.

/**
 * Trace all cyber requirements, build attack-defense tree, and calculate probabilities for the
 * loaded model.
 *
 * <p>The bulk of the work is actually done in SystemModel::trace and ConnectionModel::trace.
 */
public List<Result> perform() {
    List<Result> output = new ArrayList<>();
    // We are also ignoring whether or not the cyber requirement is in a mission
    for (SystemModel system : sysNameToSystemModelMap.values()) {
        for (CyberReq cyberReq : system.getCyberReqs()) {
            Optional<ADTree> treeOpt = system.trace(cyberReq.getCondition());
            // Crush the tree to remove redundant nodes
            ADTree crushed = treeOpt.isPresent() ? treeOpt.get().crush() : new ADOr(Collections.emptyList(), true);
            // not enabling this for now because it is potentially inefficient
            // ADTree adtree = CutSetGenerator.generate(crushed);
            ADTree adtree = crushed;
            // Compute probability of attack
            Prob computed = adtree.compute();
            output.add(new Result(system, cyberReq, adtree, computed));
        }
    }
    return output;
}
Also used : ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) SystemModel(com.ge.verdict.attackdefensecollector.model.SystemModel) CyberReq(com.ge.verdict.attackdefensecollector.model.CyberReq) ArrayList(java.util.ArrayList) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr)

Example 3 with ADTree

use of com.ge.verdict.attackdefensecollector.adtree.ADTree in project VERDICT by ge-high-assurance.

the class Main method main.

@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException, CSVFile.MalformedInputException {
    if (arrayContains(args, "--help")) {
        System.out.println("Usage: " + USAGE);
        return;
    }
    long start = System.currentTimeMillis();
    // this argument parsing is pretty bad. but we shouldn't be using this anyway.
    boolean inference = arrayContains(args, "--inference");
    boolean cutSet = arrayContains(args, "--cut-set");
    AttackDefenseCollector attackDefenseCollector;
    // otherwise, we will load csv files
    if (arrayContains(args, "--vdm")) {
        attackDefenseCollector = new AttackDefenseCollector(new File(args[1]), new File(args[0]), inference);
    } else {
        attackDefenseCollector = new AttackDefenseCollector(args[0], inference);
    }
    List<Result> results = attackDefenseCollector.perform();
    for (Result result : results) {
        // Convert adtree to cutset only if --cut-set is on.
        ADTree adtree = cutSet ? CutSetGenerator.generate(result.adtree) : result.adtree;
        Logger.println();
        // The default printer includes indentation for clean-ness
        Logger.println(adtree);
        Logger.println();
        Logger.println("CyberReq: " + result.cyberReq.getName());
        Logger.println("Mission: " + result.cyberReq.getMission());
        Logger.println("Severity: " + result.cyberReq.getSeverity());
        Logger.println("Computed: " + result.prob);
        Logger.println("Successful: " + (Prob.lte(result.prob, result.cyberReq.getSeverity()) ? "Yes" : "No"));
    }
    Logger.println("Total time: " + (System.currentTimeMillis() - start) + " milliseconds");
}
Also used : ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) File(java.io.File) Result(com.ge.verdict.attackdefensecollector.AttackDefenseCollector.Result)

Example 4 with ADTree

use of com.ge.verdict.attackdefensecollector.adtree.ADTree in project VERDICT by ge-high-assurance.

the class DTreeConstructor method perform.

/**
 * This is the part that actually constructs the dtree.
 *
 * @param adtree
 * @return
 */
private DTree perform(ADTree adtree) {
    Optional<DTree> resultOpt = constructInternal(adtree);
    if (!resultOpt.isPresent()) {
        return new DOr(Collections.emptyList());
    } else {
        DTree result = resultOpt.get();
        // remove raw attack leaves that are covered by a defense
        for (Defense defense : defenses) {
            if (!attackALeafMap.containsKey(defense.getAttack())) {
                throw new RuntimeException("defense references undefined attack: " + defense.getAttack().getName());
            }
            // it isn't included in the final tree
            for (ALeaf aleaf : attackALeafMap.get(defense.getAttack())) {
                aleaf.setMitigated();
            }
        }
        // these are the raw attack leaves that aren't covered by a defense
        Set<ALeaf> unmitigated = new LinkedHashSet<>();
        for (Set<ALeaf> set : attackALeafMap.values()) {
            for (ALeaf aleaf : set) {
                if (!aleaf.isMitigated()) {
                    unmitigated.add(aleaf);
                }
            }
        }
        // raw attacks without corresponding defenses
        for (ALeaf aleaf : unmitigated) {
            System.out.println("Warning: Unmitigated attack: " + aleaf.getAttack().toString());
        }
        // connect the defense condition to its corresponding dleaf
        for (DCondition dcond : dconditions) {
            Optional<DLeaf.ComponentDefense> compDef = factory.lookup(dcond.defenseCond.getAttackable().getParentName(), dcond.defenseCond.getDefenseProperty());
            if (compDef.isPresent()) {
                dcond.setCompDef(compDef.get());
            } else {
                // This means that the defense isn't part of the attack-defense tree,
                // so we need to create a dleaf (which implicitly creates an SMT variable)
                // for it so that the DAL can get forced down to zero if necessary
                // TODO this doesn't actually work. This is the screwy case that we need to fix.
                DLeaf dleaf = new DLeaf(dcond.defenseCond.getAttackable().getParentName(), dcond.defenseCond.getDefenseProperty(), "", dcond.defenseCond.getImplDal(), 0, costModel, factory, usePartialSolution, meritAssignment);
                dcond.setCompDef(dleaf.componentDefense);
            }
        }
        // important to call prepare - collapses nested NOTs and removes unmitigated raw attack
        // leaves
        Optional<DTree> prepared = result.prepare();
        return prepared.orElse(new DOr(Collections.emptyList()));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) DTree(com.ge.verdict.synthesis.dtree.DTree) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) DOr(com.ge.verdict.synthesis.dtree.DOr) ALeaf(com.ge.verdict.synthesis.dtree.ALeaf) DCondition(com.ge.verdict.synthesis.dtree.DCondition) Defense(com.ge.verdict.attackdefensecollector.adtree.Defense)

Example 5 with ADTree

use of com.ge.verdict.attackdefensecollector.adtree.ADTree in project VERDICT by ge-high-assurance.

the class DTreeConstructor method constructInternal.

/**
 * Inductively-defined function over attack-defense trees.
 *
 * <p>The mapping from attack-defense tree to defense tree is pretty straightforward. One of the
 * most important things to note is that AND and OR nodes are transposed in the transformation
 * because they mean opposite things in a defense tree compared to an attack-defense tree. (An
 * attack-defense tree is "how to attack", whereas a defense tree is "how to defend".)
 *
 * @param adtree
 * @return
 */
private Optional<DTree> constructInternal(ADTree adtree) {
    if (adtree instanceof Attack) {
        Attack attack = (Attack) adtree;
        ALeaf aleaf = new ALeaf(attack);
        // keep track of all attack leaves
        if (!attackALeafMap.containsKey(attack)) {
            attackALeafMap.put(attack, new LinkedHashSet<>());
        }
        attackALeafMap.get(attack).add(aleaf);
        return Optional.of(aleaf);
    } else if (adtree instanceof Defense) {
        Defense defense = (Defense) adtree;
        defenses.add(defense);
        return Optional.of(new DNot(constructDefenseTree(defense)));
    } else if (adtree instanceof ADAnd) {
        ADAnd adand = (ADAnd) adtree;
        // Transpose and/or
        return Optional.of(new DOr(adand.children().stream().map(this::constructInternal).flatMap(elem -> elem.isPresent() ? Stream.of(elem.get()) : Stream.empty()).collect(Collectors.toList())));
    } else if (adtree instanceof ADOr) {
        ADOr ador = (ADOr) adtree;
        // Transpose and/or
        return Optional.of(new DAnd(ador.children().stream().map(this::constructInternal).flatMap(elem -> elem.isPresent() ? Stream.of(elem.get()) : Stream.empty()).collect(Collectors.toList())));
    } else if (adtree instanceof ADNot) {
        ADNot adnot = (ADNot) adtree;
        return constructInternal(adnot.child()).map(DNot::new);
    } else if (adtree instanceof DefenseCondition) {
        DCondition dcond = new DCondition((DefenseCondition) adtree);
        dconditions.add(dcond);
        return Optional.of(dcond);
    } else {
        throw new RuntimeException("got invalid adtree type: " + adtree.getClass().getCanonicalName());
    }
}
Also used : DCondition(com.ge.verdict.synthesis.dtree.DCondition) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) DefenseCondition(com.ge.verdict.attackdefensecollector.adtree.DefenseCondition) ArrayList(java.util.ArrayList) Attack(com.ge.verdict.attackdefensecollector.adtree.Attack) LinkedHashMap(java.util.LinkedHashMap) Defense(com.ge.verdict.attackdefensecollector.adtree.Defense) Map(java.util.Map) DTree(com.ge.verdict.synthesis.dtree.DTree) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) LinkedHashSet(java.util.LinkedHashSet) DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) DNot(com.ge.verdict.synthesis.dtree.DNot) AttackDefenseCollector(com.ge.verdict.attackdefensecollector.AttackDefenseCollector) Set(java.util.Set) Collectors(java.util.stream.Collectors) ALeaf(com.ge.verdict.synthesis.dtree.ALeaf) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) DAnd(com.ge.verdict.synthesis.dtree.DAnd) DOr(com.ge.verdict.synthesis.dtree.DOr) Collections(java.util.Collections) ADNot(com.ge.verdict.attackdefensecollector.adtree.ADNot) ADNot(com.ge.verdict.attackdefensecollector.adtree.ADNot) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) DOr(com.ge.verdict.synthesis.dtree.DOr) ALeaf(com.ge.verdict.synthesis.dtree.ALeaf) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) DCondition(com.ge.verdict.synthesis.dtree.DCondition) Attack(com.ge.verdict.attackdefensecollector.adtree.Attack) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) DAnd(com.ge.verdict.synthesis.dtree.DAnd) Defense(com.ge.verdict.attackdefensecollector.adtree.Defense) DNot(com.ge.verdict.synthesis.dtree.DNot) ADNot(com.ge.verdict.attackdefensecollector.adtree.ADNot) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) DefenseCondition(com.ge.verdict.attackdefensecollector.adtree.DefenseCondition)

Aggregations

ADTree (com.ge.verdict.attackdefensecollector.adtree.ADTree)12 ADOr (com.ge.verdict.attackdefensecollector.adtree.ADOr)10 ADAnd (com.ge.verdict.attackdefensecollector.adtree.ADAnd)8 ADNot (com.ge.verdict.attackdefensecollector.adtree.ADNot)8 Attack (com.ge.verdict.attackdefensecollector.adtree.Attack)8 Defense (com.ge.verdict.attackdefensecollector.adtree.Defense)8 DLeaf (com.ge.verdict.synthesis.dtree.DLeaf)7 SystemModel (com.ge.verdict.attackdefensecollector.model.SystemModel)6 File (java.io.File)6 DOr (com.ge.verdict.synthesis.dtree.DOr)5 DTree (com.ge.verdict.synthesis.dtree.DTree)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 DAnd (com.ge.verdict.synthesis.dtree.DAnd)4 Fraction (org.apache.commons.math3.fraction.Fraction)4 ALeaf (com.ge.verdict.synthesis.dtree.ALeaf)3 Optional (java.util.Optional)3 Set (java.util.Set)3 AttackDefenseCollector (com.ge.verdict.attackdefensecollector.AttackDefenseCollector)2 Pair (com.ge.verdict.attackdefensecollector.Pair)2