Exemple #1
0
        /// <inheritdoc />
        public override void Process(BotData data)
        {
            base.Process(data);

            var localInputStrings = ReplaceValuesRecursive(inputString, data);
            var outputs           = new List <string>();

            for (int i = 0; i < localInputStrings.Count; i++)
            {
                var localInputString = localInputStrings[i];
                var outputString     = "";

                switch (FunctionType)
                {
                case Function.Constant:
                    outputString = localInputString;
                    break;

                case Function.Base64Encode:
                    outputString = localInputString.ToBase64();
                    break;

                case Function.Base64Decode:
                    outputString = localInputString.FromBase64();
                    break;

                case Function.HTMLEntityEncode:
                    outputString = WebUtility.HtmlEncode(localInputString);
                    break;

                case Function.HTMLEntityDecode:
                    outputString = WebUtility.HtmlDecode(localInputString);
                    break;

                case Function.Hash:
                    outputString = GetHash(localInputString, hashType).ToLower();
                    break;

                case Function.HMAC:
                    outputString = Hmac(localInputString, hashType, ReplaceValues(hmacKey, data), hmacBase64, keyBase64);
                    break;

                case Function.Translate:
                    outputString = localInputString;
                    foreach (var entry in TranslationDictionary.OrderBy(e => e.Key.Length).Reverse())
                    {
                        if (outputString.Contains(entry.Key))
                        {
                            outputString = outputString.Replace(entry.Key, entry.Value);
                            if (StopAfterFirstMatch)
                            {
                                break;
                            }
                        }
                    }
                    break;

                case Function.DateToUnixTime:
                    outputString = localInputString.ToDateTime(dateFormat).ToUnixTimeSeconds().ToString();
                    break;

                case Function.Length:
                    outputString = localInputString.Length.ToString();
                    break;

                case Function.ToLowercase:
                    outputString = localInputString.ToLower();
                    break;

                case Function.ToUppercase:
                    outputString = localInputString.ToUpper();
                    break;

                case Function.Replace:
                    if (useRegex)
                    {
                        outputString = Regex.Replace(localInputString, ReplaceValues(replaceWhat, data), ReplaceValues(replaceWith, data));
                    }
                    else
                    {
                        outputString = localInputString.Replace(ReplaceValues(replaceWhat, data), ReplaceValues(replaceWith, data));
                    }
                    break;

                case Function.RegexMatch:
                    outputString = Regex.Match(localInputString, ReplaceValues(regexMatch, data)).Value;
                    break;

                case Function.Unescape:
                    outputString = Regex.Unescape(localInputString);
                    break;

                case Function.URLEncode:
                    // The maximum allowed Uri size is 2083 characters, we use 2080 as a precaution
                    outputString = string.Join("", SplitInChunks(localInputString, 2080).Select(s => Uri.EscapeDataString(s)));
                    break;

                case Function.URLDecode:
                    outputString = Uri.UnescapeDataString(localInputString);
                    break;

                case Function.UnixTimeToDate:
                    outputString = double.Parse(localInputString).ToDateTime().ToString(dateFormat);
                    break;

                case Function.CurrentUnixTime:
                    outputString = DateTime.UtcNow.ToUnixTimeSeconds().ToString();
                    break;

                case Function.UnixTimeToISO8601:
                    outputString = double.Parse(localInputString).ToDateTime().ToISO8601();
                    break;

                case Function.RandomNum:
                    var min             = int.Parse(ReplaceValues(randomMin, data));
                    var max             = int.Parse(ReplaceValues(randomMax, data));
                    var randomNumString = data.random.Next(min, max).ToString();
                    outputString = randomZeroPad ? randomNumString.PadLeft(max.ToString().Length, '0') : randomNumString;
                    break;

                case Function.RandomString:
                    outputString = localInputString;
                    outputString = Regex.Replace(outputString, @"\?l", m => _lowercase[data.random.Next(_lowercase.Length)].ToString());
                    outputString = Regex.Replace(outputString, @"\?u", m => _uppercase[data.random.Next(_uppercase.Length)].ToString());
                    outputString = Regex.Replace(outputString, @"\?d", m => _digits[data.random.Next(_digits.Length)].ToString());
                    outputString = Regex.Replace(outputString, @"\?s", m => _symbols[data.random.Next(_symbols.Length)].ToString());
                    outputString = Regex.Replace(outputString, @"\?h", m => _hex[data.random.Next(_hex.Length)].ToString());
                    outputString = Regex.Replace(outputString, @"\?a", m => _allChars[data.random.Next(_allChars.Length)].ToString());
                    outputString = Regex.Replace(outputString, @"\?m", m => _udChars[data.random.Next(_udChars.Length)].ToString());
                    outputString = Regex.Replace(outputString, @"\?i", m => _ludChars[data.random.Next(_ludChars.Length)].ToString());
                    break;

                case Function.Ceil:
                    outputString = Math.Ceiling(Decimal.Parse(localInputString, _style, _provider)).ToString();
                    break;

                case Function.Floor:
                    outputString = Math.Floor(Decimal.Parse(localInputString, _style, _provider)).ToString();
                    break;

                case Function.Round:
                    outputString = Math.Round(Decimal.Parse(localInputString, _style, _provider), 0, MidpointRounding.AwayFromZero).ToString();
                    break;

                case Function.Compute:
                    outputString = new DataTable().Compute(localInputString.Replace(',', '.'), null).ToString();
                    break;

                case Function.CountOccurrences:
                    outputString = CountStringOccurrences(localInputString, stringToFind).ToString();
                    break;

                case Function.ClearCookies:
                    data.Cookies.Clear();
                    break;

                case Function.RSAEncrypt:
                    outputString = Crypto.RSAEncrypt(
                        localInputString,
                        ReplaceValues(RsaN, data),
                        ReplaceValues(RsaE, data),
                        RsaOAEP
                        );
                    break;

                /*
                 * case Function.RSADecrypt:
                 * outputString = Crypto.RSADecrypt(
                 *  localInputString,
                 *  ReplaceValues(RsaN, data),
                 *  ReplaceValues(RsaD, data),
                 *  RsaOAEP
                 *  );
                 * break;
                 */

                case Function.RSAPKCS1PAD2:
                    outputString = Crypto.RSAPkcs1Pad2(
                        localInputString,
                        ReplaceValues(RsaN, data),
                        ReplaceValues(RsaE, data)
                        );
                    break;

                case Function.Delay:
                    try { Thread.Sleep(int.Parse(localInputString)); } catch { }
                    break;

                case Function.CharAt:
                    outputString = localInputString.ToCharArray()[int.Parse(ReplaceValues(charIndex, data))].ToString();
                    break;

                case Function.Substring:
                    outputString = localInputString.Substring(int.Parse(ReplaceValues(substringIndex, data)), int.Parse(ReplaceValues(substringLength, data)));
                    break;

                case Function.ReverseString:
                    char[] charArray = localInputString.ToCharArray();
                    Array.Reverse(charArray);
                    outputString = new string(charArray);
                    break;

                case Function.Trim:
                    outputString = localInputString.Trim();
                    break;

                case Function.GetRandomUA:
                    if (UserAgentSpecifyBrowser)
                    {
                        outputString = UserAgent.ForBrowser(UserAgentBrowser);
                    }
                    else
                    {
                        outputString = UserAgent.Random(data.random);
                    }
                    break;

                case Function.AESEncrypt:
                    outputString = Crypto.AESEncrypt(localInputString, ReplaceValues(aesKey, data), ReplaceValues(aesIV, data), AesMode, AesPadding);
                    break;

                case Function.AESDecrypt:
                    outputString = Crypto.AESDecrypt(localInputString, ReplaceValues(aesKey, data), ReplaceValues(aesIV, data), AesMode, AesPadding);
                    break;

                case Function.PBKDF2PKCS5:
                    outputString = Crypto.PBKDF2PKCS5(localInputString, ReplaceValues(KdfSalt, data), KdfSaltSize, KdfIterations, KdfKeySize, KdfAlgorithm);
                    break;
                }

                data.Log(new LogEntry(string.Format("Executed function {0} on input {1} with outcome {2}", functionType, localInputString, outputString), Colors.GreenYellow));

                // Add to the outputs
                outputs.Add(outputString);
            }

            var isList = outputs.Count > 1 || InputString.Contains("[*]") || InputString.Contains("(*)") || InputString.Contains("{*}");

            InsertVariable(data, isCapture, isList, outputs, variableName, "", "", false, true);
        }