Skip to content

Using AsaLib

Gabe Stocco edited this page Apr 29, 2020 · 20 revisions

Getting Started

Getting AsaLib

Search Nuget for Microsoft.CST.AttackSurfaceAnalyzer.

API Documentation

API Documentation is available at https://microsoft.github.io/AttackSurfaceAnalyzer/.

Using AsaLib

Setting up for using the database (optional)

DatabaseManager.Setup(dbPath);

For logging messages (optional)

Logger.Setup(false, true);
Strings.Setup();

Disable telemetry (optional)

AsaTelemetry.Setup(test: true);

Collecting

You can perform collection and get the results in memory.

var cc = new CertificateCollector();
cc.Execute();
List<CollectObject> results = cc.Results;

You can also choose to write the results to the database.

cc.Results.AsParallel().ForAll(x => DatabaseManager.Write(x, FirstRunId));

Comparing

From the database

BaseCompare bc = new BaseCompare();
if (!bc.TryCompare(FirstRunId, SecondRunId))
{
    // Error while comparing
}
else
{
    ConcurrentDictionary<(RESULT_TYPE, CHANGE_TYPE), List<CompareResult>> results = bc.Results;
}

From memory

IEnumerable<CollectObject> FirstRunItems = collector1.Results;
IEnumerable<CollectObject> SecondRunItems = collector2.Results;

BaseCompare bc = new BaseCompare();
bc.Compare(FirstRunItems,FirstRunItems,FirstRunId,SecondRunId);

ConcurrentDictionary<(RESULT_TYPE, CHANGE_TYPE), List<CompareResult>> results = bc.Results;

Analyzing

Analysis is performed on CompareResult objects.

BaseCompare bc = new BaseCompare();
bc.Compare(DifferentItems,ModifiedItems,FirstRunId,SecondRunId);

Analyzer analyzer = new Analyzer(PLATFORM.WINDOWS, pathToAnalysisFile);

if (analyzer.VerifyRules().Any()){
   // Error With Rules
}
else {
    foreach (var key in bc.Results.Keys)
    {
        if (bc.Results[key] is List<CompareResult> queue)
        {
            Parallel.ForEach(queue, (res) =>
            {
                res.Rules = analyzer.Analyze(res);
                res.Analysis = res.Rules.Max(x => x.Flag);
            });
        }
    }
}

Clone this wiki locally