Skip to content

Commit 6f2ec06

Browse files
author
Dr. Brandon Wiley
committed
Enabled "Remove Packets After Analysis" checkbox
1 parent 34c34ac commit 6f2ec06

3 files changed

Lines changed: 110 additions & 38 deletions

File tree

AdversaryLabSwift/Base.lproj/Main.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@
15571557
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="l29-wR-vQY">
15581558
<rect key="frame" x="418" y="674" width="209" height="18"/>
15591559
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
1560-
<buttonCell key="cell" type="check" title="Remove Packets After Analysis" bezelStyle="regularSquare" imagePosition="left" enabled="NO" inset="2" id="oLi-vs-yls">
1560+
<buttonCell key="cell" type="check" title="Remove Packets After Analysis" bezelStyle="regularSquare" imagePosition="left" inset="2" id="oLi-vs-yls">
15611561
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
15621562
<font key="font" metaFont="system"/>
15631563
</buttonCell>

AdversaryLabSwift/Controllers/ConnectionInspector.swift

Lines changed: 91 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,111 @@ import Auburn
1111

1212
class ConnectionInspector
1313
{
14-
func analyzeConnections(enableSequenceAnalysis: Bool, enableTLSAnalysis: Bool)
14+
func analyzeConnections(enableSequenceAnalysis: Bool, enableTLSAnalysis: Bool, removePackets: Bool)
1515
{
1616
analysisQueue.async
1717
{
1818
// Allowed Connections
19-
let allowedConnectionList: RList<String> = RList(key: allowedConnectionsKey)
20-
while allowedConnectionList.count != 0
21-
{
22-
print("Analyzing an allowed connection async. Allowed connections left:\(allowedConnectionList.count)")
23-
// Get the first connection ID from the list
24-
guard let allowedConnectionID = allowedConnectionList.removeFirst()
25-
else
19+
if removePackets {
20+
NSLog("Analyzed packets and removing")
21+
let allowedConnectionList: RList<String> = RList(key: allowedConnectionsKey)
22+
while allowedConnectionList.count != 0
2623
{
27-
continue
24+
print("Analyzing an allowed connection async. Allowed connections left:\(allowedConnectionList.count)")
25+
// Get the first connection ID from the list
26+
guard let allowedConnectionID = allowedConnectionList.removeFirst()
27+
else
28+
{
29+
continue
30+
}
31+
32+
print("\nPopped Allowed Connection: \(allowedConnectionID)")
33+
34+
if "\(type(of: allowedConnectionID))" == "NSNull"
35+
{
36+
continue
37+
}
38+
39+
let allowedConnection = ObservedConnection(connectionType: .allowed, connectionID: allowedConnectionID)
40+
41+
self.analyze(connection: allowedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
2842
}
2943

30-
print("\nPopped Allowed Connection: \(allowedConnectionID)")
31-
32-
if "\(type(of: allowedConnectionID))" == "NSNull"
44+
// Blocked Connections
45+
let blockedConnectionList: RList<String> = RList(key: blockedConnectionsKey)
46+
while blockedConnectionList.count != 0
3347
{
34-
continue
48+
print("Analyzing a blocked connection async. Blocked connections left: \(blockedConnectionList.count)")
49+
// Get the first connection ID from the list
50+
guard let blockedConnectionID = blockedConnectionList.removeFirst()
51+
else
52+
{
53+
continue
54+
}
55+
print("\nPopped Blocked Connection: \(blockedConnectionID)")
56+
57+
if "\(type(of: blockedConnectionID))" == "NSNull"
58+
{
59+
continue
60+
}
61+
62+
let blockedConnection = ObservedConnection(connectionType: .blocked, connectionID: blockedConnectionID)
63+
64+
self.analyze(connection: blockedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
3565
}
36-
37-
let allowedConnection = ObservedConnection(connectionType: .allowed, connectionID: allowedConnectionID)
38-
39-
self.analyze(connection: allowedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
40-
}
41-
42-
// Blocked Connections
43-
let blockedConnectionList: RList<String> = RList(key: blockedConnectionsKey)
44-
while blockedConnectionList.count != 0
45-
{
46-
print("Analyzing a blocked connection async. Blocked connections left: \(blockedConnectionList.count)")
47-
// Get the first connection ID from the list
48-
guard let blockedConnectionID = blockedConnectionList.removeFirst()
49-
else
66+
} else {
67+
NSLog("Analyzed packets and retaining")
68+
let packetsAnalyzedDictionary: RMap<String, Int> = RMap(key: packetStatsKey)
69+
packetsAnalyzedDictionary[allowedPacketsAnalyzedKey]=0
70+
packetsAnalyzedDictionary[blockedPacketsAnalyzedKey]=0
71+
NotificationCenter.default.post(name: .updateStats, object: nil)
72+
73+
let allowedConnectionList: RList<String> = RList(key: allowedConnectionsKey)
74+
print("Analyzing allowed connections \(allowedConnectionList.count)")
75+
for index in 0..<allowedConnectionList.count
5076
{
51-
continue
77+
print("Analyzing an allowed connection async. \(index)/\(allowedConnectionList.count)")
78+
// Get the first connection ID from the list
79+
guard let allowedConnectionID = allowedConnectionList[index]
80+
else
81+
{
82+
continue
83+
}
84+
85+
print("\nIndexed Allowed Connection: \(allowedConnectionID)")
86+
87+
if "\(type(of: allowedConnectionID))" == "NSNull"
88+
{
89+
continue
90+
}
91+
92+
let allowedConnection = ObservedConnection(connectionType: .allowed, connectionID: allowedConnectionID)
93+
94+
self.analyze(connection: allowedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
5295
}
53-
print("\nPopped Blocked Connection: \(blockedConnectionID)")
5496

55-
if "\(type(of: blockedConnectionID))" == "NSNull"
97+
// Blocked Connections
98+
let blockedConnectionList: RList<String> = RList(key: blockedConnectionsKey)
99+
print("Analyzing blocked connections \(blockedConnectionList.count)")
100+
for index in 0..<blockedConnectionList.count
56101
{
57-
continue
102+
print("Analyzing a blocked connection async. \(index)/\(allowedConnectionList.count)")
103+
// Get the first connection ID from the list
104+
guard let blockedConnectionID = blockedConnectionList[index]
105+
else
106+
{
107+
continue
108+
}
109+
110+
if "\(type(of: blockedConnectionID))" == "NSNull"
111+
{
112+
continue
113+
}
114+
115+
let blockedConnection = ObservedConnection(connectionType: .blocked, connectionID: blockedConnectionID)
116+
117+
self.analyze(connection: blockedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
58118
}
59-
60-
let blockedConnection = ObservedConnection(connectionType: .blocked, connectionID: blockedConnectionID)
61-
62-
self.analyze(connection: blockedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
63119
}
64120

65121
self.scoreConnections(enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)

AdversaryLabSwift/ViewController.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ class ViewController: NSViewController
9393
}
9494
}
9595
}
96+
97+
var removePackets: Bool
98+
{
99+
get
100+
{
101+
switch removePacketsCheck.state
102+
{
103+
case .on:
104+
return true
105+
case .off:
106+
return false
107+
default: //No Mixed State
108+
return false
109+
}
110+
}
111+
}
96112

97113
override func viewDidLoad()
98114
{
@@ -110,7 +126,7 @@ class ViewController: NSViewController
110126

111127
@IBAction func runClick(_ sender: NSButton)
112128
{
113-
self.connectionInspector.analyzeConnections(enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
129+
self.connectionInspector.analyzeConnections(enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis, removePackets: removePackets)
114130
self.loadLabelData()
115131
}
116132

@@ -319,7 +335,7 @@ class ViewController: NSViewController
319335
continue
320336
}
321337

322-
self.connectionInspector.analyzeConnections(enableSequenceAnalysis: self.enableSequenceAnalysis, enableTLSAnalysis: self.enableTLSAnalysis)
338+
self.connectionInspector.analyzeConnections(enableSequenceAnalysis: self.enableSequenceAnalysis, enableTLSAnalysis: self.enableTLSAnalysis, removePackets: self.removePackets)
323339
}
324340
}
325341
}

0 commit comments

Comments
 (0)