Beispiel #1
0
        private async Task PerformObfuscation()
        {
            await Task.Yield();

            //generate a fake username or password here
            List <string> _fakes = new List <string>();

            if (FakeUsernames)
            {
                _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Generating fake username.");
                string user = SimpleRandomGenerator.QuickGetRandomString(
                    SimpleRandomGenerator.CharSelection.Lowercase | SimpleRandomGenerator.CharSelection.Uppercase | SimpleRandomGenerator.CharSelection.Digits,
                    SimpleRandomGenerator.QuickGetRandomInt(4, 12),
                    false);
                string userName = String.Empty;
                if (_domains == null)
                {
                    _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Loading list of domains for first time.");
                    _domains = new List <string>();
                    using (StringReader stringReader = new StringReader(Properties.Resources.domains))
                    {
                        string curLine = stringReader.ReadLine();
                        while (!String.IsNullOrEmpty(curLine))
                        {
                            if (!_domains.Contains(curLine))
                            {
                                _domains.Add(curLine);
                            }
                            curLine = stringReader.ReadLine();
                        }
                    }
                }
                string domain = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(_domains.ToArray());
                userName = String.Format("{0}@{1}", user, domain);
                _fakes.Add(userName);
            }

            if (FakePasswords)
            {
                _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Generating fake password.");
                _fakes.Add(SimpleRandomGenerator.QuickGetRandomString(SimpleRandomGenerator.CharSelection.All, 16, false));
            }

            _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Randomly picking fake data.");
            string fakeEntry = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(_fakes.ToArray());

            _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Fake data picked, invoking obfuscate action.");
            await _action.Invoke(new ClipboardObfuscatorGeneratedFakeEventArgs(fakeEntry));
        }
Beispiel #2
0
        public string GeneratePhrase(string format)
        {
            string phrase = format;

            //we do this in a loop so we can replace individual tokens as we go
            Regex tokenRegex = new Regex("\\{(.*?)\\}");
            Dictionary <string, string> invalidTokens = new Dictionary <string, string>();
            MatchCollection             tokens        = tokenRegex.Matches(phrase);

            while (tokens.Count > 0)
            {
                Match firstMatch = tokens[0];

                string   token      = firstMatch.Value.Trim(new char[] { '{', '}' });
                string[] tokenParts = token.Split(':');
                if (tokenParts.Length == 2)
                {
                    string randomWord = String.Empty;
                    switch (tokenParts[0])
                    {
                    case "verb":
                    {
                        randomWord = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(Verbs.ToArray());
                        break;
                    }

                    case "adjective":
                    {
                        randomWord = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(Adjectives.ToArray());
                        break;
                    }

                    case "noun":
                    {
                        randomWord = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(Nouns.ToArray());
                        break;
                    }

                    case "int":
                    {
                        randomWord = "{int}";
                        break;
                    }

                    case "special1":
                    {
                        randomWord = "{special1}";
                        break;
                    }

                    default:
                    {
                        randomWord = "{invalid}";
                        break;
                    }
                    }
                    bool replace = true;
                    switch (randomWord)
                    {
                    case "{int}":
                    {
                        string   range      = tokenParts[1];
                        string[] rangeParts = range.Split('-');
                        int      min        = int.Parse(rangeParts[0]);
                        int      max        = int.Parse(rangeParts[1]);
                        if (max > min)
                        {
                            int randomInt = SimpleRandomGenerator.QuickGetRandomInt(min, max);
                            randomWord = randomInt.ToString();
                        }
                        else
                        {
                            randomWord = String.Empty;
                        }
                        break;
                    }

                    case "{special1}":
                    {
                        int count = int.Parse(tokenParts[1]);
                        randomWord = SimpleRandomGenerator.QuickGetRandomString(
                            SimpleRandomGenerator.CharSelection.Minus |
                            SimpleRandomGenerator.CharSelection.Underline,
                            count,
                            false);
                        break;
                    }

                    case "{invalid}":
                    {
                        string tempReplacement = String.Format("[invalidtoken:{0}]", invalidTokens.Count);
                        invalidTokens.Add(tempReplacement, firstMatch.Value);
                        phrase  = phrase.Remove(firstMatch.Index, firstMatch.Length);
                        phrase  = phrase.Insert(firstMatch.Index, tempReplacement);
                        replace = false;
                        break;
                    }

                    default:
                    {
                        string casing = tokenParts[1];
                        if (casing == "rc")
                        {
                            casing = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(new string[] { "lc", "uc", "ic" });
                        }
                        switch (casing)
                        {
                        case "lc":
                        {
                            randomWord = randomWord.ToLower();
                            break;
                        }

                        case "uc":
                        {
                            randomWord = randomWord.ToUpper();
                            break;
                        }

                        case "ic":
                        {
                            randomWord = randomWord[0].ToString().ToUpper() + randomWord.Substring(1);
                            break;
                        }
                        }
                        break;
                    }
                    }
                    if (replace)
                    {
                        phrase = phrase.Remove(firstMatch.Index, firstMatch.Length);
                        phrase = phrase.Insert(firstMatch.Index, randomWord);
                    }
                }
                else
                {
                    //invalid token, remove it so that we don't get stuck in the loop
                    string tempReplacement = String.Format("[invalidtoken:{0}]", invalidTokens.Count);
                    invalidTokens.Add(tempReplacement, firstMatch.Value);
                    phrase = phrase.Remove(firstMatch.Index, firstMatch.Length);
                    phrase = phrase.Insert(firstMatch.Index, tempReplacement);
                }

                tokens = tokenRegex.Matches(phrase);
            }

            foreach (string token in invalidTokens.Keys)
            {
                if (phrase.Contains(token))
                {
                    phrase = phrase.Replace(token, invalidTokens[token]);
                }
            }

            return(phrase);
        }