Skip to content

Commit 9c64461

Browse files
author
Dr. Brandon Wiley
committed
Added counting of observed TLS common names
1 parent e0bcefd commit 9c64461

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

AdversaryLabSwift/Features/Entropy.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func processEntropy(forConnection connection: ObservedConnection) -> (processsed
4141

4242
func calculateEntropy(for packet: Data) -> Double
4343
{
44-
NSLog("Entropy for \(packet as NSData)")
4544
let probabilities: [Double] = calculateProbabilities(for: packet)
4645
var entropy: Double = 0
4746

AdversaryLabSwift/Features/Protocols/TLS12.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ func isTls12(forConnection connection: ObservedConnection) -> Bool
4242
NSLog("TLS response not found \(outPacket as! NSData)")
4343
return false
4444
}
45-
46-
NSLog("Found TLS: \(requestRange) \(responseRange) \(outPacket.count)")
47-
45+
4846
return true
4947
}
5048

5149
func processTls12(_ connection: ObservedConnection) {
52-
NSLog("Processing TLS")
5350
let outPacketHash: RMap<String, Data> = RMap(key: connection.outgoingKey)
54-
51+
let tlsCommonNameSet: RSortedSet<String> = RSortedSet(key: connection.outgoingTlsCommonNameKey)
52+
5553
// Get the out packet that corresponds with this connection ID
5654
guard let outPacket: Data = outPacketHash[connection.connectionID]
5755
else
@@ -62,7 +60,7 @@ func processTls12(_ connection: ObservedConnection) {
6260

6361
let maybeBegin = findCommonNameStart(outPacket)
6462
guard let begin = maybeBegin else {
65-
NSLog("No common name beginning found \(outPacket as! NSData)")
63+
NSLog("No common name beginning found")
6664
NSLog("\(connection.outgoingKey) \(connection.connectionID) \(outPacket.count)")
6765
return
6866
}
@@ -73,9 +71,11 @@ func processTls12(_ connection: ObservedConnection) {
7371
return
7472
}
7573

76-
let commonData = extract(outPacket, begin+commonNameStart.count, end)
74+
let commonData = extract(outPacket, begin+commonNameStart.count, end-1)
7775
let commonName = commonData.string
78-
NSLog("Found TLS 1.2 common name: \(commonName)")
76+
NSLog("Found TLS 1.2 common name: \(commonName) \(commonName.count) \(begin) \(end)")
77+
78+
let _ = tlsCommonNameSet.incrementScore(ofField: commonName, byIncrement: 1)
7979
}
8080

8181
private func findCommonNameStart(_ outPacket: Data) -> Int? {
@@ -84,7 +84,12 @@ private func findCommonNameStart(_ outPacket: Data) -> Int? {
8484
return nil
8585
}
8686

87-
return range.lowerBound
87+
let maybeNextRange = outPacket.range(of: commonNameStart, options: [], in: range.upperBound..<outPacket.count)
88+
guard let nextRange = maybeNextRange else {
89+
return nil
90+
}
91+
92+
return nextRange.lowerBound
8893
}
8994

9095
private func findCommonNameEnd(_ outPacket: Data, _ begin: Int) -> Int? {

AdversaryLabSwift/Helpers/Constants.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ let blockedConnectionsTimeDiffBinsKey = "Blocked:Connections:TimeDifferenceBins"
8282
let requiredTimeDiffKey = "Required:TimeDifference"
8383
let forbiddenTimeDiffKey = "Forbidden:TimeDifference"
8484

85+
let allowedTlsCommonNameKey = "Allowed:Outgoing:TLS:CommonName"
86+
let blockedTlsCommonNameKey = "Blocked:Outgoing:TLS:CommonName"
87+
8588
///
8689
let newConnectionMessage = "NewConnectionAdded"
8790

AdversaryLabSwift/Models/ObservedConnections.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct ObservedConnection
2626
let outgoingFloatingSequencesKey: String
2727
let incomingEntropyKey: String
2828
let outgoingEntropyKey: String
29+
let outgoingTlsCommonNameKey: String
2930

3031
let connectionID: String
3132

@@ -52,6 +53,7 @@ struct ObservedConnection
5253
outgoingFloatingSequencesKey = allowedOutgoingFloatingSequencesKey
5354
incomingEntropyKey = allowedIncomingEntropyKey
5455
outgoingEntropyKey = allowedOutgoingEntropyKey
56+
outgoingTlsCommonNameKey = allowedTlsCommonNameKey
5557
case .blocked:
5658
connectionsKey = blockedConnectionsKey
5759
incomingKey = blockedIncomingKey
@@ -69,6 +71,7 @@ struct ObservedConnection
6971
outgoingFloatingSequencesKey = blockedOutgoingFloatingSequencesKey
7072
incomingEntropyKey = blockedIncomingEntropyKey
7173
outgoingEntropyKey = blockedOutgoingEntropyKey
74+
outgoingTlsCommonNameKey = blockedTlsCommonNameKey
7275
}
7376
}
7477
}

0 commit comments

Comments
 (0)