Exemple #1
0
 public void Write(DataFrames.DataFrame frame)
 {
     if (frame == null)
     {
         _eventHandle.Set();
     }
 }
Exemple #2
0
 private void SendPacket(DataFrames.DataFrame frame)
 {
     if (!_drop)
     {
         WriteOutput(frame);
     }
 }
Exemple #3
0
        protected override void OnInput(DataFrames.DataFrame frame)
        {
            DataNode[] nodes = frame.SelectNodes(SelectionPath);

            foreach (DataNode node in nodes)
            {
                byte[] data  = node.ToArray();
                bool   match = false;
                int    i     = 0;

                for (i = 0; i < data.Length - Config.Match.Length + 1; ++i)
                {
                    match = GeneralUtils.MatchArray(data, i, Config.Match);
                    if (match)
                    {
                        break;
                    }
                }

                if (match)
                {
                    byte[] newArray = new byte[data.Length - Config.Match.Length + Config.Replacement.Length];

                    Buffer.BlockCopy(data, 0, newArray, 0, i);
                    Buffer.BlockCopy(Config.Replacement, 0, newArray, i, Config.Replacement.Length);
                    Buffer.BlockCopy(data, i + Config.Match.Length, newArray, i + Config.Replacement.Length, data.Length - i - Config.Match.Length);

                    node.ReplaceNode(newArray);
                }
            }

            WriteOutput(frame);
        }
Exemple #4
0
        protected override void OnInput(DataFrames.DataFrame frame)
        {
            DataNode[] nodes    = frame.SelectNodes(SelectionPath);
            Encoding   encoding = GeneralUtils.GetEncodingFromType(Config.Encoding);

            foreach (DataNode node in nodes)
            {
                MemoryStream  stm     = new MemoryStream(node.ToArray());
                DataReader    reader  = new DataReader(stm);
                StringBuilder builder = new StringBuilder();

                try
                {
                    while (!reader.Eof)
                    {
                        builder.Append(reader.ReadChar(encoding));
                    }
                }
                catch (EndOfStreamException)
                {
                }

                node.ReplaceNode(builder.ToString(), encoding);
            }

            WriteOutput(frame);
        }
Exemple #5
0
        protected override void OnInput(DataFrames.DataFrame frame)
        {
            DataNode node = frame.SelectSingleNode(Config.PathName);

            if (node != null)
            {
                frame.Current = node;
            }

            WriteOutput(frame);
        }
Exemple #6
0
 /// <summary>
 /// Write data adapter
 /// </summary>
 /// <param name="data">The frame to write</param>
 public override void Write(DataFrames.DataFrame data)
 {
     if (_boundAdapter != null)
     {
         _boundAdapter.Write(data);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Exemple #7
0
        protected override void OnInput(DataFrames.DataFrame frame)
        {
            if ((!_init) && (Config.PacketLog != null))
            {
                _packets    = Config.PacketLog.GetPackets();
                _prefix     = Config.Prefix;
                _drop       = Config.DropTrigger;
                _currPacket = 0;
                _init       = true;
            }

            if (!_prefix)
            {
                SendPacket(frame.CloneFrame());
            }

            if (_init)
            {
                if (Config.Sequential)
                {
                    if (_currPacket < _packets.Length)
                    {
                        WriteOutput(_packets[_currPacket++].Frame.CloneFrame());
                    }

                    if (_currPacket == _packets.Length)
                    {
                        if (Config.Repeat)
                        {
                            _currPacket = 0;
                        }
                    }
                }
                else if (!_sent)
                {
                    foreach (LogPacket packet in _packets)
                    {
                        WriteOutput(packet.Frame.CloneFrame());
                    }

                    if (!Config.Repeat)
                    {
                        _sent = true;
                    }
                }
            }

            if (_prefix)
            {
                SendPacket(frame.CloneFrame());
            }
        }
Exemple #8
0
        protected override void OnInput(DataFrames.DataFrame frame)
        {
            DataNode[] nodes = frame.SelectNodes(SelectionPath);

            foreach (DataNode node in nodes)
            {
                DataValue value = node as DataValue;

                if ((value != null) && (value.Value is string))
                {
                    value.Value = _re.Replace(value.Value, Config.Replacement);
                }
                else
                {
                    string s = _re.Replace(_encoding.GetString(node.ToArray()), Config.Replacement);

                    node.ReplaceNode(_encoding.GetBytes(s));
                }
            }

            WriteOutput(frame);
        }
        protected override void OnInput(DataFrames.DataFrame frame)
        {
            DataNode[] nodes        = frame.SelectNodes(SelectionPath);
            DataFrame  preFuzzFrame = null;
            int        nodeCount    = nodes.Length;
            bool       fuzzed       = false;

            if (nodeCount > 0)
            {
                if (Config.LogPackets)
                {
                    preFuzzFrame = frame.CloneFrame();
                }
            }

            foreach (DataNode node in nodes)
            {
                DataValue value = node as DataValue;
                string    fuzzString;

                if ((value != null) && (value.Value is string))
                {
                    fuzzString = value.Value;
                }
                else
                {
                    if (Config.NoConversion)
                    {
                        continue;
                    }

                    value      = null;
                    fuzzString = _encoding.GetString(node.ToArray());
                }

                int    fuzzLength = FuzzerUtils.GetFuzzLength(fuzzString.Length, Config.FuzzStart, Config.FuzzLength);
                string newString;

                if ((Config.FuzzStart == 0) && (fuzzLength == fuzzString.Length))
                {
                    newString = FuzzString(fuzzString);
                }
                else if ((Config.FuzzStart >= 0) && (fuzzLength > 0))
                {
                    string prefixString = fuzzString.Substring(0, Config.FuzzStart);
                    string suffixString = fuzzString.Substring(Config.FuzzStart + fuzzLength);

                    newString = String.Concat(prefixString, FuzzString(fuzzString.Substring(Config.FuzzStart, fuzzLength)), suffixString);
                }
                else
                {
                    continue;
                }

                if (newString != fuzzString)
                {
                    fuzzed = true;
                    if (Config.LogFuzzText)
                    {
                        LogInfo("Fuzzed string '{0}'", fuzzString);
                    }
                }

                if (value != null)
                {
                    value.Value = newString;
                }
                else
                {
                    node.ReplaceNode(_encoding.GetBytes(newString));
                }
            }

            if (nodeCount > 0)
            {
                if (Config.LogPackets)
                {
                    if (fuzzed)
                    {
                        Graph.DoLogPacket(String.Format("{0}: Pre-fuzz", Name), Config.Color, preFuzzFrame, Config.ConvertToBytes);
                        Graph.DoLogPacket(String.Format("{0}: Post-fuzz", Name), Config.Color, frame, Config.ConvertToBytes);
                    }
                }
            }

            WriteOutput(frame);
        }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="frame"></param>
        protected override void OnInput(DataFrames.DataFrame frame)
        {
            bool writtenOutput = false;

            DataNode node = SelectSingleNode(frame);

            if (node != null)
            {
                string name = node.ToString();

                if (_mode == SwitchNodeSelectionMode.ExactMatch)
                {
                    if (HasOutput(name))
                    {
                        WriteOutput(frame, name);
                        writtenOutput = true;
                    }
                }
                else
                {
                    foreach (OutputNode output in _output)
                    {
                        try
                        {
                            if (!String.IsNullOrEmpty(output.PathName))
                            {
                                Regex r;

                                if (_regexs.ContainsKey(output.PathName))
                                {
                                    r = _regexs[output.PathName];
                                }
                                else
                                {
                                    r = _mode == SwitchNodeSelectionMode.RegexMatch
                                        ? new Regex(output.PathName, RegexOptions.Multiline | RegexOptions.IgnoreCase)
                                        : GeneralUtils.GlobToRegex(output.PathName);
                                    _regexs[output.PathName] = r;
                                }

                                if (r.IsMatch(name))
                                {
                                    WriteOutput(frame, output.PathName);
                                    writtenOutput = true;
                                    break;
                                }
                            }
                        }
                        catch (ArgumentException ex)
                        {
                            LogException(ex);
                        }
                    }
                }
            }

            if (!writtenOutput && !_dropUnknown)
            {
                WriteOutput(frame);
            }
        }
Exemple #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="frame"></param>
 protected override sealed void ClientWrite(DataFrames.DataFrame frame)
 {
     WriteClientFrame(_client, frame);
 }
Exemple #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="frame"></param>
 protected override void ServerWrite(DataFrames.DataFrame frame)
 {
     WriteServerFrame(_server, frame);
 }
Exemple #13
0
 protected override void OnInput(DataFrames.DataFrame frame)
 {
     // Do nothing, anything matching the filters should be dropped
 }
Exemple #14
0
 protected override void OnInput(DataFrames.DataFrame frame)
 {
     Frames.Add(frame);
 }
Exemple #15
0
 public override void Write(DataFrames.DataFrame data)
 {
     _adapter.Enqueue(data);
 }
Exemple #16
0
        protected override void OnInput(DataFrames.DataFrame frame)
        {
            DataNode[] nodes   = frame.SelectNodes(SelectionPath);
            DataFrame  preFuzz = null;
            bool       fuzzed  = false;

            if (nodes.Length > 0)
            {
                if (Config.LogPackets)
                {
                    preFuzz = frame.CloneFrame();
                }
            }

            foreach (DataNode node in nodes)
            {
                U[] data = NodeToArray(node);

                if (data == null)
                {
                    LogVerbose(CANAPE.NodeLibrary.Properties.Resources.BaseRandomArrayFuzzer_IgnoringData, node.Name);
                    continue;
                }

                int fuzzLength = FuzzerUtils.GetFuzzLength(data.Length, Config.FuzzStart, Config.FuzzLength);

                if (fuzzLength > 0)
                {
                    int points = GetPointCount(fuzzLength);

                    if (Config.LogFuzzText)
                    {
                        LogVerbose(CANAPE.NodeLibrary.Properties.Resources.BaseRandomArrayFuzzer_FuzzCount, points);
                    }

                    while (points > 0)
                    {
                        int pos = _random.Next(Config.FuzzStart, Config.FuzzStart + fuzzLength);
                        BaseRandomArrayFuzzerConfig.FuzzCombinationMode mode = Config.CombinationMode;

                        if (mode == BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Random)
                        {
                            mode = (BaseRandomArrayFuzzerConfig.FuzzCombinationMode)_random.Next((int)BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Max);
                        }

                        if ((pos >= 0) && (pos < data.Length))
                        {
                            U value = FuzzValue(mode, data[pos]);

                            if (!value.Equals(data[pos]))
                            {
                                fuzzed = true;
                                if (Config.LogFuzzText)
                                {
                                    LogInfo(CANAPE.NodeLibrary.Properties.Resources.BaseRandomArrayFuzzer_FuzzInfo,
                                            pos, data[pos], value);
                                }
                            }

                            data[pos] = value;
                        }

                        points--;
                    }

                    node.ReplaceNode(ArrayToNode(data, node));
                }
            }

            if (fuzzed)
            {
                if (Config.LogPackets)
                {
                    Graph.DoLogPacket(String.Format(CANAPE.NodeLibrary.Properties.Resources.BaseRandomArrayFuzzer_PreFuzzInfo, Name),
                                      Config.Color, preFuzz, Config.ConvertToBytes);
                    Graph.DoLogPacket(String.Format(CANAPE.NodeLibrary.Properties.Resources.BaseRandomArrayFuzzer_PostFuzzInfo, Name),
                                      Config.Color, frame, Config.ConvertToBytes);
                }
            }

            WriteOutput(frame);
        }