Exemplo n.º 1
0
        public bool Add(RequestSequence sequence)
        {
            List <Response> responses = sequence.GetResponses();
            Response        response  = responses[responses.Count - 1];

            List <TokenCollection> allResults = sequence.GetResults();
            TokenCollection        results    = allResults[allResults.Count - 1];

            SortedSet <string> tokenNames = new SortedSet <string>();

            foreach (IToken token in results)
            {
                if (UseValueOverrides.Contains(token.Name))
                {
                    tokenNames.Add($"{token.Name}:{token.Value}");
                }
                else
                {
                    tokenNames.Add(token.Name);
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.Append(response.Status.ToString());

            if (response.Status != System.Net.HttpStatusCode.RequestTimeout)
            {
                foreach (string name in tokenNames)
                {
                    sb.Append(name);
                }
            }

            if (!sequence.GetDebugMetadata().Exists(x => x.Type == "BucketDebug"))
            {
                sequence.AddMetadata("BucketDebug", sb.ToString());
            }

            if (!Sorted.ContainsKey(sb.ToString()))
            {
                Console.WriteLine($"Added new bucket {sb.ToString()}");
                Sorted.Add(sb.ToString(), new List <RequestSequence>());
                Sorted[sb.ToString()].Add(sequence);
                return(true);
            }

            Sorted[sb.ToString()].Add(sequence);
            return(false);
        }
Exemplo n.º 2
0
        public async Task AddRequestSequence(RequestSequence sequence, FuzzerRunEntity run)
        {
            RequestSequenceEntity model = new RequestSequenceEntity();

            model.request_count      = sequence.StageCount();
            model.substitution_count = sequence.SubstitutionCount();
            model.run_id             = run.id.GetValueOrDefault(0);

            using (var connection = GetConnection())
            {
                connection.Open();

                model.id = connection.Query <int>(
                    @"INSERT INTO sequences
                    ( request_count, substitution_count, run_id ) VALUES 
                    ( @request_count, @substitution_count, @run_id )
                    RETURNING id;", model).First();

                foreach (SequenceMetadata meta in sequence.GetDebugMetadata())
                {
                    SequenceMetadataEntity metadata_entity =
                        new SequenceMetadataEntity {
                        sequence_id = model.id, content = meta.Content, type = meta.Type
                    };

                    connection.Execute(@"INSERT INTO sequence_metadata 
                                         ( sequence_id, type, content ) VALUES
                                         ( @sequence_id, @type, @content );", metadata_entity);
                }
            }

            sequence.Id = model.id;

            List <Response>?results = sequence.GetResponses();

            if (results != null && results.Count == sequence.StageCount())
            {
                for (int i = 0; i < sequence.StageCount(); ++i)
                {
                    Request       request      = sequence.Get(i).Request;
                    RequestEntity requestModel = RequestEntity.FromRequest(request);
                    requestModel.sequence_id       = model.id;
                    requestModel.sequence_position = i;
                    AddExecutedRequest(requestModel);
                    request.Id = requestModel.id;

                    Response       response      = results[i];
                    ResponseEntity responseModel = ResponseEntity.FromResponse(response);
                    responseModel.sequence_id       = model.id;
                    responseModel.sequence_position = i;
                    AddResponse(responseModel);
                    response.Id = responseModel.id;

                    foreach (ISubstitution sub in sequence.Get(i).Substitutions)
                    {
                        SubstitutionEntity subModel = SubstitutionEntity.FromSubstitution(sub);
                        subModel.sequence_id       = model.id;
                        subModel.sequence_position = i;
                        AddSubstitution(subModel);
                    }
                }

                if (sequence.GetLastResponse() != null)
                {
                    int statusCode = (int)sequence.GetLastResponse().Status;
                    RequestSequenceLabelEntity labelEntity = new RequestSequenceLabelEntity();
                    labelEntity.sequence_id = model.id.Value;
                    if (statusCode >= 100 && statusCode < 200)
                    {
                        labelEntity.name = "Informational";
                    }
                    else if (statusCode >= 200 && statusCode < 300)
                    {
                        labelEntity.name = "Success";
                    }
                    else if (statusCode >= 300 && statusCode < 400)
                    {
                        labelEntity.name = "Redirection";
                    }
                    else if (statusCode >= 400 && statusCode < 500)
                    {
                        labelEntity.name = "Client Error";
                    }
                    else if (statusCode >= 500 && statusCode < 600)
                    {
                        labelEntity.name = "Server Error";
                    }
                    else
                    {
                        labelEntity.name = "Unknown Status";
                    }
                    await AddRequestSequenceLabel(labelEntity);
                }
            }
            else
            {
                Console.WriteLine("Warning: Truncated request sequence.");
            }
        }