public static StatusObject ClearTables(JARVISDataSource DictionaryStorage) { StatusObject SO = new StatusObject(); try { string TruncateTableQuery = "select 'drop table '+TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_NAME like 'RAINBOW%'"; SqlConnection tempConnection = DictionaryStorage.GetSQLConnection(); SqlCommand TruncateTableCommand = new SqlCommand(TruncateTableQuery, tempConnection); tempConnection.Open(); SqlDataReader Reader = TruncateTableCommand.ExecuteReader(); while (Reader.Read()) { Console.WriteLine(Reader[0]); StatusObject SO_AddRecord = DictionaryStorage.ExecuteNonReaderQuery(Reader[0].ToString()); if (SO_AddRecord.Status == StatusCode.FAILURE) { Console.WriteLine(SO_AddRecord.ErrorMessage); } } tempConnection.Close(); } catch (Exception e) { SO = new StatusObject(StatusCode.FAILURE, "ClearTable_ERROR", e.Message, e.ToString()); } return(SO); }
public StatusObject AnalyzeRequestAudit(JARVISDataSource ActiveDataSource) { StatusObject SO = new StatusObject(); try { Directory.CreateDirectory(CustomAlgorithmInputPath); Directory.CreateDirectory(CustomAlgorithmOutputPath); FileStream TargetFile = File.Open(this.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); BufferedStream TargetFileBuffered = new BufferedStream(TargetFile); StreamReader TargetFileBufferedReader = new StreamReader(TargetFileBuffered); string Record; while ((Record = TargetFileBufferedReader.ReadLine()) != null) { List <string> RecordParameters = Record.Split('\t').ToList(); //Console.WriteLine(RecordParameters.ElementAtOrDefault(0)); //Console.WriteLine(RecordParameters.ElementAtOrDefault(1)); //Console.WriteLine(RecordParameters.ElementAtOrDefault(2)); //Console.WriteLine(RecordParameters.ElementAtOrDefault(3)); //Console.WriteLine(RecordParameters.ElementAtOrDefault(4)); Console.WriteLine(RecordParameters.ElementAtOrDefault(5)); //Console.WriteLine(RecordParameters.ElementAtOrDefault(6)); Thread.Sleep(3000); } } catch (Exception e) { SO = new StatusObject(StatusCode.FAILURE, "JARVISFILECUSTOMALGO_ANALYZEREQUESTAUDIT_FAILURE", e.Message, e.ToString()); } return(SO); }
public static StatusObject SetActiveDataSource() { StatusObject SO = new StatusObject(); try { string Server; string Database; string UserID; string Password; Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("START: Set Active DataSource"); Console.WriteLine("----------------------------------------------------------"); Console.Write("Server: "); Server = Console.ReadLine(); Console.Write("Database: "); Database = Console.ReadLine(); Console.Write("UserID (Press enter to skip if using Windows Authentication): "); UserID = Console.ReadLine(); Console.Write("Password (Press enter to skip if using Windows Authentication): "); Password = Console.ReadLine(); JARVISDataSource PrimaryDataSource = new JARVISDataSource(Server, Database, UserID, Password); PrimaryDataSource.GetSQLConnection(); Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("END: Set Active DataSource"); Console.WriteLine("----------------------------------------------------------"); SO.UDDynamic = PrimaryDataSource; } catch (Exception e) { SO = new StatusObject(StatusCode.FAILURE, "", e.Message, e.ToString()); } return(SO); }
public static StatusObject BuildUUIDTable() { StatusObject SO = new StatusObject(); try { JARVISDataSource newDataSource = new JARVISDataSource("sql2008kl", "shawn_db", "sa", "password"); Guid.NewGuid(); } catch (Exception e) { } return(SO); }
public StatusObject AnalyzeClaimAudit() { StatusObject SO = new StatusObject(); try { Directory.CreateDirectory(CustomAlgorithmLogPath); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine("Claim Audit Analysis Start"); Console.WriteLine("----------------------------------------------------------------------------"); DateTime StartTime = DateTime.Now; FileStream TargetFile = File.Open(this.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); BufferedStream TargetFileBuffered = new BufferedStream(TargetFile); StreamReader TargetFileBufferedReader = new StreamReader(TargetFileBuffered); string Record; int Count = 0; List <int> ErrorLines = new List <int>(); List <string> ErrorLineDetails = new List <string>(); while ((Record = TargetFileBufferedReader.ReadLine()) != null) { List <string> Fields = Record.Split('^').Select(x => x.Replace("'", "''")).Select(x => x = String.Format("'{0}'", x.Trim())).ToList(); string InsertQuery = String.Format("insert into EtiqaClaimAudit22821 values ({0})", String.Join(",", Fields)); Console.WriteLine(InsertQuery); JARVISDataSource Storage = new JARVISDataSource("sql2008kl", "shawn_db", "sa", "password"); StatusObject ExecuteInsertQuery = Storage.ExecuteNonReaderQuery(InsertQuery); if (ExecuteInsertQuery.Status == StatusCode.FAILURE) { Thread.Sleep(1000); Console.WriteLine(ExecuteInsertQuery.ErrorStackTrace); } Count++; } DateTime EndTime = DateTime.Now; Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine("Claim Audit Analysis End. Time Elapsed: {0} Records: {1}", (StartTime - EndTime).Milliseconds, Count); Console.WriteLine("----------------------------------------------------------------------------"); StreamWriter ErrorLog = new StreamWriter(String.Format(@"{0}\AnalyzeClaimAuditErrors.txt", CustomAlgorithmLogPath), append: true); foreach (int Error in ErrorLines) { ErrorLog.WriteLine(Error); ErrorLog.Close(); } } catch (Exception e) { SO = new StatusObject(StatusCode.FAILURE, "JARVISFILECUSTOMALGO_ANALYZECLAIMAUDIT_FAILURE", e.Message, e.ToString()); } return(SO); }
public static StatusObject ConfigureJARVISDatabase() { StatusObject SO = new StatusObject(); try { if (!File.Exists(String.Format(@"{0}\Database.txt", StartUpFolderPath))) { Directory.CreateDirectory(StartUpFolderPath); string Server; string Database; string UserID; string Password; Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("START: Link JARVIS5 to Database"); Console.WriteLine("----------------------------------------------------------"); Console.Write("Server: "); Server = Console.ReadLine(); Console.Write("Database: "); Database = Console.ReadLine(); Console.Write("UserID (Press enter to skip if using Windows Authentication): "); UserID = Console.ReadLine(); Console.Write("Password (Press enter to skip if using Windows Authentication): "); Password = Console.ReadLine(); JARVISDataSource PrimaryDataSource = new JARVISDataSource(Server, Database, UserID, Password); PrimaryDataSource.GetSQLConnection(); JARVISFile StartupDatabase = new JARVISFile(String.Format(@"{0}\Database.txt", StartUpFolderPath)); StartupDatabase.Overwrite(PrimaryDataSource.GetConnectionString()); Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("END: Link JARVIS5 to Database"); Console.WriteLine("----------------------------------------------------------"); } } catch (Exception e) { Console.WriteLine(e.ToString()); SO = new StatusObject(StatusCode.FAILURE, "", e.Message, e.ToString()); } return(SO); }
public static StatusObject BuildStringPermutationTable(string MinWordLength, string MaxWordLength, JARVISDataSource DictionaryStorage) { StatusObject SO = new StatusObject(); try { Dictionary <string, string> TableCreationQueries = new Dictionary <string, string>(); Dictionary <string, string> IndexCreationQueries = new Dictionary <string, string>(); Dictionary <string, string> HashTypes = new Dictionary <string, string>() { { "MD5", "32" }, { "SHA", "40" }, { "SHA1", "40" }, { "SHA2_256", "64" }, { "SHA2_512", "128" } }; int minWordLength = Convert.ToInt32(MinWordLength); int maxWordLength = Convert.ToInt32(MaxWordLength); TableCreationQueries.Add( "TableCreateQuery", @"CREATE TABLE [dbo].[RAINBOW_{0}_{3}_{1}]( [ID] [int] IDENTITY(1,1) NOT NULL, [Word] [varchar](20) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL, [FirstLetter] [varchar](1) NOT NULL, [LetterCount] [int] NOT NULL, [{1}] [varchar]({2}) NULL, CONSTRAINT [PK_RAINBOW_{0}_{3}_{1}] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]"); IndexCreationQueries.Add( "FirstLetter", @"CREATE NONCLUSTERED INDEX [IX_FIRSTLETTER_{0}_{1}_{2}] ON [dbo].[RAINBOW_{0}_{1}_{2}] ( [FirstLetter] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]"); IndexCreationQueries.Add( "LetterCount", @"CREATE NONCLUSTERED INDEX [IX_LETTERCOUNT_{0}_{1}_{2}] ON [dbo].[RAINBOW_{0}_{1}_{2}] ( [LetterCount] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]"); IndexCreationQueries.Add( "HashQuery", @"CREATE NONCLUSTERED INDEX [IX_{2}_{0}_{1}] ON [dbo].[RAINBOW_{0}_{1}_{2}] ( [{2}] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]"); IndexCreationQueries.Add("IndexWordQuery", @"CREATE UNIQUE INDEX [IX_WORD_{0}_{1}_{2}] ON [dbo].[RAINBOW_{0}_{1}_{2}] ( [Word] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]"); string TargetString = ""; for (int LargeAlphabet = 65; LargeAlphabet <= 90; LargeAlphabet++) { TargetString += (char)LargeAlphabet; } for (int smallAlphabet = 97; smallAlphabet <= 122; smallAlphabet++) { TargetString += (char)smallAlphabet; } for (int Numeric = 48; Numeric <= 57; Numeric++) { TargetString += (char)Numeric; } for (int Symbol = 32; Symbol <= 47; Symbol++) { TargetString += (char)Symbol; } for (int Symbol = 58; Symbol <= 64; Symbol++) { TargetString += (char)Symbol; } for (int Symbol = 91; Symbol <= 96; Symbol++) { TargetString += (char)Symbol; } for (int Symbol = 123; Symbol <= 126; Symbol++) { TargetString += (char)Symbol; } //Create Tables foreach (char Character in TargetString) { foreach (KeyValuePair <string, string> Query in TableCreationQueries) { foreach (KeyValuePair <string, string> HashType in HashTypes) { for (int letterCount = minWordLength; letterCount <= maxWordLength; letterCount++) { Console.WriteLine("Creating Table RAINBOW_{1}_{3}_{2}", Query.Key.Substring(0, 5), (int)Character, HashType.Key, letterCount); Console.WriteLine(String.Format(Query.Value, (int)Character, HashType.Key, HashType.Value, letterCount)); StatusObject SO_CreateTable = DictionaryStorage.ExecuteNonReaderQuery(String.Format(Query.Value, (int)Character, HashType.Key, HashType.Value, letterCount)); if (SO_CreateTable.Status == StatusCode.FAILURE) { Console.WriteLine(SO_CreateTable.ErrorMessage); break; } foreach (KeyValuePair <string, string> IndexQuery in IndexCreationQueries) { StatusObject SO_CreateIndex = DictionaryStorage.ExecuteNonReaderQuery( String.Format( IndexQuery.Value, (int)Character, letterCount, HashType.Key)); if (SO_CreateIndex.Status == StatusCode.FAILURE) { Console.WriteLine(SO_CreateIndex.ErrorMessage); break; } } } } } } } catch (Exception e) { SO = new StatusObject(StatusCode.FAILURE, "StringPermutationError", e.Message, e.ToString()); } return(SO); }
public static StatusObject PopulateStringPermutationTable(string WordLength, string FirstLetter, JARVISDataSource DictionaryStorage) { StatusObject SO = new StatusObject(); try { Dictionary <string, string> HashTypes = new Dictionary <string, string>() { { "MD5", "32" }, { "SHA", "40" }, { "SHA1", "40" }, { "SHA2_256", "64" }, { "SHA2_512", "128" } }; string TargetString = ""; for (int LargeAlphabet = 65; LargeAlphabet <= 90; LargeAlphabet++) { TargetString += (char)LargeAlphabet; } for (int smallAlphabet = 97; smallAlphabet <= 122; smallAlphabet++) { TargetString += (char)smallAlphabet; } for (int Numeric = 48; Numeric <= 57; Numeric++) { TargetString += (char)Numeric; } for (int Symbol = 32; Symbol <= 47; Symbol++) { TargetString += (char)Symbol; } for (int Symbol = 58; Symbol <= 64; Symbol++) { TargetString += (char)Symbol; } for (int Symbol = 91; Symbol <= 96; Symbol++) { TargetString += (char)Symbol; } for (int Symbol = 123; Symbol <= 126; Symbol++) { TargetString += (char)Symbol; } string ReorderedString = ""; char FirstCharacter = (FirstLetter == "space") ? ' ' : FirstLetter.ToCharArray()[0]; ReorderedString += FirstCharacter; foreach (char TargetCharacter in TargetString) { if (TargetCharacter != FirstCharacter) { ReorderedString += TargetCharacter; } } var q = ReorderedString.Select(x => x.ToString()); int size = Convert.ToInt32(WordLength); for (int i = 0; i < size - 1; i++) { q = q.SelectMany(x => ReorderedString, (x, y) => x + y); } foreach (var item in q) { if (item[0] == FirstCharacter) { foreach (KeyValuePair <string, string> HashType in HashTypes) { string insertQuery = String.Format( @"insert into RAINBOW_{3}_{2}_{4} (Word,FirstLetter,LetterCount,{4}) values ( '{0}', '{1}', {2}, convert(varchar({5}),hashbytes('{4}','{0}'),2))", item.Replace("'", "''"), item[0] == '\'' ? "''" : item[0].ToString(), item.Length, (int)item[0], HashType.Key, HashType.Value); Console.WriteLine(insertQuery); StatusObject SO_AddRecord = DictionaryStorage.ExecuteNonReaderQuery(insertQuery); while (SO_AddRecord.Status == StatusCode.FAILURE) { Console.WriteLine(SO_AddRecord.ErrorMessage); SO_AddRecord = DictionaryStorage.ExecuteNonReaderQuery(insertQuery); } } } else { break; } } } catch (Exception e) { SO = new StatusObject(StatusCode.FAILURE, "StringPermutationError", e.Message, e.ToString()); } return(SO); }
static void Main(string[] args) { Console.WriteLine(System.Reflection.Assembly.GetEntryAssembly().Location); bool programRunning = true; string userInput = ""; StatusObject SO_PrimaryDatabaseSetup = new StatusObject(); JARVISDataSource primaryDataSource; JARVISDataSource activeDataSource = null; Dictionary <string, JARVISDataSource> userDefinedDataSources = new Dictionary <string, JARVISDataSource>(); /*Execution of all StartUp Files*/ SO_PrimaryDatabaseSetup = JARVISConfig.ConfigureJARVISDatabase(); JARVISConfig.CopyExecutable(); /*Execution of batch files first*/ if (args.Length > 0) { /*If batch execution, do not require user input*/ Console.WriteLine("--------------------------------------------------------------------"); Console.WriteLine("Start Batch Execution"); Console.WriteLine("--------------------------------------------------------------------"); userInput = string.Join(" ", args); Console.WriteLine(userInput); } else { /*If non-batch, require user input*/ Console.Write("Enter Command: "); userInput = Console.ReadLine(); } while (programRunning) { try { if (!userDefinedDataSources.ContainsKey("work")) { userDefinedDataSources.Add("work", new JARVISDataSource("sql2008kl", "shawn_db", "sa", "password")); } if (!userDefinedDataSources.ContainsKey("home")) { userDefinedDataSources.Add("home", new JARVISDataSource("asus", "JARVIS5", "shawn_tan", "root")); } JARVISLogging.LogCommand(userInput); if (userInput != "exit") { List <string> commandParameters = userInput.Split(' ').ToList(); string primaryCommand = commandParameters.ElementAtOrDefault(0); /*Command Sets*/ if (primaryCommand == "help") { string commandGroup = commandParameters.ElementAtOrDefault(1); string commandName = commandParameters.ElementAtOrDefault(2); if (commandGroup != null) { JARVISRuntime.Help(commandGroup); } else { JARVISRuntime.Help(); } } else if (primaryCommand == "datasource") { string secondaryCommand = commandParameters.ElementAtOrDefault(1); string server = commandParameters.ElementAtOrDefault(2); string database = commandParameters.ElementAtOrDefault(3); string userID = commandParameters.ElementAtOrDefault(4); string password = commandParameters.ElementAtOrDefault(5); JARVISDataSource newDataSource = new JARVISDataSource(server, database, userID, password); if (secondaryCommand == "exportssp") { newDataSource.GetSQLConnection(); newDataSource.ExportStoredProcedures(); } else if (secondaryCommand == "add") { newDataSource.GetSQLConnection(); newDataSource.SaveToTextFile(); } else if (secondaryCommand == "setactive") { activeDataSource = new JARVISDataSource(server, database, userID, password); } else if (secondaryCommand == "clearactive") { activeDataSource = null; } else { Console.WriteLine("{0} {1} is not a recognized command", primaryCommand, secondaryCommand); } } else if (primaryCommand == "findtable") { string secondaryCommand = commandParameters.ElementAtOrDefault(1); if (secondaryCommand == "columnname") { string target = userInput.Replace("findtable columnname", "").Trim(); Console.WriteLine(target); JARVISDataSource TargetDataSource = new JARVISDataSource("sql2008kl", "claims_dev", "sa", "password"); TargetDataSource.SearchTablesByColumnName(target); } else if (secondaryCommand == "tablename") { } } else if (primaryCommand == "read") { string secondaryCommand = commandParameters.ElementAtOrDefault(1); string filePath = userInput.Replace("read", "").Replace(secondaryCommand, "").Trim(); if (secondaryCommand == "csvfile") { JARVISFile targetFile = new JARVISFile(filePath); StatusObject SO_ReadFile = targetFile.ReadCSV(); if (SO_ReadFile.Status == StatusCode.FAILURE) { Console.WriteLine(SO_ReadFile.ErrorStackTrace); } } else if (secondaryCommand == "textfile") { JARVISFile targetFile = new JARVISFile(filePath); StatusObject SO_ReadFile = targetFile.AnalyzeRequestAudit(activeDataSource); if (SO_ReadFile.Status == StatusCode.FAILURE) { Console.WriteLine(SO_ReadFile.ErrorStackTrace); } } } else if (primaryCommand == "web") { string secondaryCommand = commandParameters.ElementAtOrDefault(1); Console.WriteLine(secondaryCommand); StatusObject SO_GetRequest = JARVISWeb.HttpGet(secondaryCommand); if (SO_GetRequest.Status == StatusCode.FAILURE) { Console.WriteLine(SO_GetRequest.ErrorStackTrace); } } else if (primaryCommand == "thread") { } else if (primaryCommand == "wordlist") { string secondaryCommand = commandParameters.ElementAtOrDefault(1); string targetDataSource = commandParameters.ElementAtOrDefault(2); string firstLetter = commandParameters.ElementAtOrDefault(3); string MinWordLength = commandParameters.ElementAtOrDefault(4); string MaxWordLength = commandParameters.ElementAtOrDefault(5); if (secondaryCommand == "buildtables") { MinWordLength = commandParameters.ElementAtOrDefault(3); MaxWordLength = commandParameters.ElementAtOrDefault(4); StatusObject SO_BuildTable = JARVISCryptography.BuildStringPermutationTable(MinWordLength, MaxWordLength, userDefinedDataSources[targetDataSource]); if (SO_BuildTable.Status == StatusCode.FAILURE) { Console.WriteLine(SO_BuildTable.ErrorStackTrace); } } else if (secondaryCommand == "populatetables") { JARVISDataSource Storage = userDefinedDataSources[targetDataSource]; StatusObject DictionaryBuilder = JARVISCryptography.PopulateStringPermutationTable(MinWordLength.ToString(), firstLetter, Storage); if (DictionaryBuilder.Status == StatusCode.FAILURE) { Console.WriteLine(DictionaryBuilder.ErrorStackTrace); } } else if (secondaryCommand == "buildbatchfiles") { MinWordLength = commandParameters.ElementAtOrDefault(3); StatusObject SO_BuildBatchFiles = JARVISCryptography.CreateStringPermutationBatchFiles(MinWordLength, targetDataSource); if (SO_BuildBatchFiles.Status == StatusCode.FAILURE) { Console.WriteLine(SO_BuildBatchFiles.ErrorStackTrace); } } else if (secondaryCommand == "cleartables") { StatusObject SO_ClearTables = JARVISCryptography.ClearTables(userDefinedDataSources[targetDataSource]); if (SO_ClearTables.Status == StatusCode.FAILURE) { Console.WriteLine(SO_ClearTables.ErrorStackTrace); } } } else { Console.WriteLine("{0} is not a recognized command", primaryCommand); } if (args.Length > 0) { Console.WriteLine("--------------------------------------------------------------------"); Console.WriteLine("End Batch Execution"); Console.WriteLine("--------------------------------------------------------------------"); Console.ReadKey(); userInput = "exit"; } else { Console.Write("Enter Command: "); userInput = Console.ReadLine(); } } else { Console.WriteLine("Exiting Program"); programRunning = false; userInput = ""; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); programRunning = true; userInput = ""; Console.ReadKey(); } } }