Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                PrintUsage();
                return;
            }

            var modelContext = TlsConversationContext.CreateInMemory();

            if (String.Equals("extract", args[0], StringComparison.InvariantCultureIgnoreCase))
            {
                var filepath         = args[1];
                var frameKeyProvider = new FrameKeyProvider();
                var keyFile          = Path.ChangeExtension(filepath, "key");
                var secretMap        = File.Exists(keyFile) ? TlsMasterSecretMap.LoadFromFile(keyFile): new TlsMasterSecretMap();
                var packets          = FastPcapFileReaderDevice.ReadAll(args[1]).Select((p, i) => (Key: frameKeyProvider.GetKey(p), Value: (Meta: new PacketMeta {
                    Number = i + 1, Timestamp = p.Timestamp
                }, Packet: p)));
                var flows            = from packet in packets
                                       group packet by packet.Key;

                var conversations = TcpStreamConversation.CreateConversations(flows.ToDictionary(x => x.Key, x => x.Select(y => y.Value)));

                foreach (var conversation in conversations)
                {
                    var modelBuilder   = new TlsConversationModelBuilder(modelContext);
                    var decoderBuilder = new TlsDecoderBuilder();
                    var processor      = new TlsSessionProcessor(modelBuilder, decoderBuilder);
                    processor.ProcessConversation(conversation);


                    var model = modelBuilder.ToModel();
                    modelContext.SaveChanges();


                    var tlsDecoder   = decoderBuilder.ToDecoder();
                    var masterSecret = secretMap.GetMasterSecret(ByteString.ByteArrayToString(tlsDecoder.ClientRandom));
                    if (masterSecret != null)
                    {
                        tlsDecoder.MasterSecret = ByteString.StringToByteArray(masterSecret);
                        var tlsSecurityParameters = TlsSecurityParameters.Create(tlsDecoder.ProtocolVersion, tlsDecoder.CipherSuite.ToString(), tlsDecoder.Compression);
                        tlsDecoder.InitializeKeyBlock(tlsSecurityParameters);

                        // USE TLS DECODER
                        DumpConversationContent(tlsDecoder, conversation, processor.ClientDataRecords, processor.ServerDataRecords);
                    }
                }
                CsvFeatureWriter.WriteCsv(Path.ChangeExtension(filepath, "csv"), modelContext);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads key log from file.
        /// </summary>
        /// <param name="path">Path.</param>
        /// <remarks>
        /// The keylog file has the following format:
        /// # Cipher Suite ECDHE-RSA-AES256-GCM-SHA384
        /// CLIENT_RANDOM 52362c10a2665e323a2adb4b9da0c10d4a8823719272f8b4c97af24f92784812 9F9A0F19A02BDDBE1A05926597D622CCA06D2AF416A28AD9C03163B87FF1B0C67824BBDB595B32D8027DB566EC04FB25
        /// </remarks>
        public static TlsMasterSecretMap LoadFromFile(string path)
        {
            var msm = new TlsMasterSecretMap();

            foreach (var line in File.ReadAllLines(path).Where(s => !(s.Trim().StartsWith('#') || String.IsNullOrWhiteSpace(s))))
            {
                var parts = line.Split(' ');
                if (String.Equals(parts[0], "CLIENT_RANDOM"))
                {
                    var clientRandom = parts[1];
                    var premaster    = parts[2];
                    msm.m_dictionary.Add(clientRandom, premaster);
                }
            }
            return(msm);
        }