diff --git a/SSUpdate/Program.cs b/SSUpdate/Program.cs index 6fd184e..a5f1284 100644 --- a/SSUpdate/Program.cs +++ b/SSUpdate/Program.cs @@ -1,13 +1,82 @@ using System; using System.Collections.Generic; using System.IO; +using System.Data.SqlClient; using System.Data.SQLite; using System.Reflection; +using System.Text; namespace SSUpdate { public static class Program { + static Program() + { + _inInsertionOrderTableNames = new List(); + _inInsertionOrderTableNames.Add("nvd_db"); + _inInsertionOrderTableNames.Add("cwe_db"); + _inInsertionOrderTableNames.Add("cve_cwe"); + _inInsertionOrderTableNames.Add("cwe_category"); + _inInsertionOrderTableNames.Add("cwe_capec"); + _inInsertionOrderTableNames.Add("cve_cpe"); + _inInsertionOrderTableNames.Add("cve_reference"); + _inInsertionOrderTableNames.Add("map_cve_aixapar"); + _inInsertionOrderTableNames.Add("map_cve_redhat"); + _inInsertionOrderTableNames.Add("map_redhat_bugzilla"); + _inInsertionOrderTableNames.Add("map_cve_suse"); + _inInsertionOrderTableNames.Add("map_cve_debian"); + _inInsertionOrderTableNames.Add("map_cve_mandriva"); + _inInsertionOrderTableNames.Add("map_cve_saint"); + _inInsertionOrderTableNames.Add("map_cve_milw0rm"); + _inInsertionOrderTableNames.Add("map_cve_osvdb"); + _inInsertionOrderTableNames.Add("map_cve_nessus"); + _inInsertionOrderTableNames.Add("map_cve_msf"); + _inInsertionOrderTableNames.Add("map_cve_openvas"); + _inInsertionOrderTableNames.Add("map_cve_scip"); + _inInsertionOrderTableNames.Add("map_cve_iavm"); + _inInsertionOrderTableNames.Add("map_cve_cisco"); + _inInsertionOrderTableNames.Add("map_cve_ubuntu"); + _inInsertionOrderTableNames.Add("map_cve_gentoo"); + _inInsertionOrderTableNames.Add("map_cve_fedora"); + _inInsertionOrderTableNames.Add("map_cve_certvn"); + _inInsertionOrderTableNames.Add("map_cve_ms"); + _inInsertionOrderTableNames.Add("map_cve_mskb"); + _inInsertionOrderTableNames.Add("map_cve_snort"); + _inInsertionOrderTableNames.Add("map_cve_suricata"); + _inInsertionOrderTableNames.Add("map_cve_vmware"); + _inInsertionOrderTableNames.Add("map_cve_bid"); + _inInsertionOrderTableNames.Add("map_cve_hp"); + _inInsertionOrderTableNames.Add("stat_new_cve"); + _inInsertionOrderTableNames.Add("map_cve_exploitdb"); + _inInsertionOrderTableNames.Add("map_cve_nmap"); + _inInsertionOrderTableNames.Add("map_cve_oval"); + _inInsertionOrderTableNames.Add("map_cve_d2"); + _inInsertionOrderTableNames.Add("stat_vfeed_kpi"); + _inInsertionOrderTableNames.Add("capec_db"); + _inInsertionOrderTableNames.Add("capec_mit"); + _inInsertionOrderTableNames.Add("cwe_wasc"); + return; + } + + private static void AssertInputSchema(string tableName, SQLiteDataReader reader) + { + AssertTableInfoColumnsOrder(reader); + List columns = new List(); + while (reader.Read()) { + ColumnInfo thisColumn = new ColumnInfo() { + Name = reader.GetString(TableInfoNameColumIndex), + Type = reader.GetString(TableInfoTypeColumIndex), + Nullable = (0 == reader.GetInt32(TableInfoNullableFlagColumIndex)), + PrimaryKey = reader.GetInt32(TableInfoPrimaryKeyFlagColumIndex) + }; + columns.Add(thisColumn); + } + _tablesByName[tableName] = columns; + // TODO : Make sure the input schema is conformant with the current code line. + // If not throw an exception. + return; + } + private static void AssertTableInfoColumnsOrder(SQLiteDataReader reader) { if (_tableInfoColumnOrderAlreadyAsserted) { return; } @@ -15,28 +84,145 @@ private static void AssertTableInfoColumnsOrder(SQLiteDataReader reader) if (6 < fieldsCount) { throw new ApplicationException("TABLE INFO schema mismatch."); } - if ("name" != reader.GetName(TableInfoNameColumIndex)) { - throw new ApplicationException("TABLE INFO name column schema mismatch."); + string failedColumnName = null; + try { + if ((failedColumnName = "name") != reader.GetName(TableInfoNameColumIndex)) { return; } + if ((failedColumnName = "type") != reader.GetName(TableInfoTypeColumIndex)) { return; } + if ((failedColumnName = "notnull") != reader.GetName(TableInfoNullableFlagColumIndex)) { return; } + if ((failedColumnName = "pk") != reader.GetName(TableInfoPrimaryKeyFlagColumIndex)) { return; } + _tableInfoColumnOrderAlreadyAsserted = true; + failedColumnName = null; + return; } - if ("type" != reader.GetName(TableInfoTypeColumIndex)) { - throw new ApplicationException("TABLE INFO type column schema mismatch."); + finally { + if (null != failedColumnName) { + throw new ApplicationException(string.Format( + "TABLE INFO {0} column schema mismatch.", failedColumnName)); + } } - if ("notnull" != reader.GetName(TableInfoNullableFlagColumIndex)) { - throw new ApplicationException("TABLE INFO notnull column schema mismatch."); + } + + /// This is an helper method that partially reverse the Sqlite database + /// into a Sql Server script. + /// + /// + private static string BuildSqlServerTableCreationInstruction(string tableName) + { + StringBuilder builder = new StringBuilder(); + List columns; + SortedList primaryKeyColumns = new SortedList(); + + if (!_tablesByName.TryGetValue(tableName, out columns)) { + throw new ArgumentException(string.Format("Unknown table '{0}'.", tableName)); + } + builder.AppendFormat("CREATE TABLE [{0}] (\r\n", tableName); + foreach(ColumnInfo column in columns) { + if (0 != column.PrimaryKey) { + primaryKeyColumns.Add(column.PrimaryKey, column); + } + string sqlServerType; + string sqliteType = column.Type.ToLower(); + int firstParenthesisIndex = sqliteType.IndexOf('('); + string sizing = null; + if (-1 != firstParenthesisIndex) { + sizing = sqliteType.Substring(firstParenthesisIndex); + sqliteType = sqliteType.Substring(0, firstParenthesisIndex); + } + switch (sqliteType) { + case "bigint": + case "date": + case "datetime": + case "int": + case "smallint": + case "text": + case "tinyint": + sqlServerType = sqliteType; + break; + case "character": + case "decimal": + case "nchar": + case "nvarchar": + sqlServerType = sqliteType + sizing; + break; + case "varying character": + case "native character": + sqlServerType = "nvarchar" + sizing; + break; + case "boolean": + sqlServerType = "bit"; + break; + case "clob": + sqlServerType = "text"; + break; + case "double": + case "double precision": + sqlServerType = "float"; + break; + case "float": + sqlServerType = "real"; + break; + case "int2": + sqlServerType = "smallint"; + break; + case "int8": + sqlServerType = "bigint"; + break; + case "integer": + sqlServerType = "int"; + break; + case "mediumint": + sqlServerType = "int"; + break; + case "name": + sqlServerType = "sysname"; + break; + case "real": + sqlServerType = "float"; + break; + case "unsigned big int": + sqlServerType = "bigint"; + break; + default: + throw new NotImplementedException( + string.Format("Unrecognized sqlite type '{0}'.", column.Type)); + } + builder.AppendFormat("\t[{0}] {1} {2},\r\n", column.Name, + sqlServerType, column.Nullable ? "NULL" : "NOT NULL"); } - if ("pk" != reader.GetName(TableInfoPrimaryKeyFlagColumIndex)) { - throw new ApplicationException("TABLE INFO pk column schema mismatch."); + if (0 < primaryKeyColumns.Count) { + builder.Append("CONSTRAINT PRIMARY KEY CLUSTERED ("); + foreach(ColumnInfo primaryKeyColumn in primaryKeyColumns.Values) { + if (1 != primaryKeyColumn.PrimaryKey) { builder.Append(", "); } + builder.Append(primaryKeyColumn.Name); + } + builder.Append(")\r\n"); } - _tableInfoColumnOrderAlreadyAsserted = true; - return; + builder.Append(");\r\n"); + return builder.ToString(); + } + + private static SQLiteConnection ConnectToSQLite() + { + SQLiteConnection result = TryConnectToSQLite(); + if (null == result) { throw new ApplicationException(); } + return result; + } + + private static SqlConnection ConnectToSqlServer() + { + SqlConnection result = TryConnectToSqlServer(); + if (null == result) { throw new ApplicationException(); } + return result; } private static void DisplayUsage(string programName) { - Console.WriteLine("{0} [-f |-h]"); + Console.WriteLine("{0} [-f -s -d |-h]"); Console.WriteLine(); + Console.WriteLine("-d : (optional) Sql Server vFeed database name (default vFeed)."); Console.WriteLine("-f : path to vFeed database."); Console.WriteLine("-h : display this help notice."); + Console.WriteLine(@"-s : target SQL server name ex : 'mymachine\SQLEXP12'."); return; } @@ -50,6 +236,85 @@ private static void DisplayVersion(out string name) return; } + private static string GetInsertCommand(string tableName, out int parametersCount) + { + StringBuilder builder = new StringBuilder(); + StringBuilder valuesBuilder = new StringBuilder(); + List columns = _tablesByName[tableName]; + int parameterIndex = 0; + foreach(ColumnInfo column in columns) { + if (0 == builder.Length) { + builder.AppendFormat("INSERT [{0}] (", tableName); + valuesBuilder.AppendFormat(" VALUES ("); + } + else { + builder.Append(", "); + valuesBuilder.Append(", "); + } + builder.Append("[" + column.Name + "]"); + valuesBuilder.AppendFormat("@P{0}", ++parameterIndex); + } + parametersCount = parameterIndex; + builder.Append(")"); + valuesBuilder.Append(")"); + return builder.ToString() + valuesBuilder.ToString(); + } + + private static string GetReadCommand(string tableName) + { + StringBuilder builder = new StringBuilder(); + List columns = _tablesByName[tableName]; + foreach(ColumnInfo column in columns) { + builder.Append((0 == builder.Length) ? "SELECT " : ","); + builder.Append("[" + column.Name + "]"); + } + builder.AppendFormat(" FROM [{0}]", tableName); + return builder.ToString(); + } + + private static bool ImportData() + { + bool atLeastOneIgnored = false; + DateTime startTime = DateTime.Now; + using (SQLiteConnection sqliteConnection = ConnectToSQLite()) { + using (SqlConnection sqlServerConnection = ConnectToSqlServer()) { + foreach(string tableName in _inInsertionOrderTableNames) { +#if DEBUG + bool ignored = false; + foreach(string ignoredTableName in _ignoreTables) { + if (tableName == ignoredTableName) { + Console.WriteLine("Ignoring table '{0}'", ignoredTableName); + ignored = true; + break; + } + } + if (ignored) { + atLeastOneIgnored = true; + continue; + } +#endif + Console.WriteLine("Importing {0} table ", tableName); + int parametersCount; + string readCommand = GetReadCommand(tableName); + string insertCommand = GetInsertCommand(tableName, out parametersCount); + using (SQLiteCommand command = new SQLiteCommand(readCommand, sqliteConnection)) { + using(SQLiteDataReader reader = command.ExecuteReader()) { + Transfer(sqlServerConnection, reader, insertCommand, parametersCount); + } + } + } + } + } + DateTime endTime = DateTime.Now; + Console.WriteLine("Import completed in {0} seconds.", + (int)((endTime - startTime).TotalSeconds)); + if (atLeastOneIgnored) { + Console.WriteLine("WARNING : At least one table has been ignored."); + return false; + } + return true; + } + private static bool LoadSQLiteSchema() { Console.WriteLine("Validating input schema."); @@ -64,7 +329,10 @@ private static bool LoadSQLiteSchema() } } } - foreach(string inputTable in _tablesByName.Keys) { + string[] tableNames = new string[_tablesByName.Keys.Count]; + _tablesByName.Keys.CopyTo(tableNames, 0); + Console.WriteLine("Verifying input database schema."); + foreach (string inputTable in tableNames) { try { VerifyTableDescription(connection, inputTable); } catch (Exception e) { Console.WriteLine("Failed to load schema for table '{0}' : {1}", @@ -76,9 +344,6 @@ private static bool LoadSQLiteSchema() return true; } - private static Dictionary _tablesByName = - new Dictionary(); - public static int Main(string[] args) { int result = 0; @@ -93,9 +358,8 @@ public static int Main(string[] args) DisplayUsage(programName); return result; } - if (!LoadSQLiteSchema()) { - return 2; - } + if (!LoadSQLiteSchema()) { return 2; } + if (!ImportData()) { return 3; } return result; } @@ -117,10 +381,17 @@ private static bool ParseArgs(string[] args) Console.WriteLine("Database '{0}' not found.", _database.FullName); return false; } - using (FileStream data = TryOpenDatabase()) { + using (FileStream data = TryOpenSqliteDatabase()) { if (null == data) { return false; } } break; + case "H": + _displayUsage = true; + return true; + case "S": + _targetSqlServerName = TryGetAdditionalArgument(args, ref argIndex); + if (null == _targetSqlServerName) { return false; } + break; default: unrecognizedArgument = true; break; @@ -132,18 +403,53 @@ private static bool ParseArgs(string[] args) return false; } } - _connectionString = string.Format("Data Source={0};Version=3;", + if (null == _database) { + Console.WriteLine("Mandatory -f parameter is missing."); + return false; + } + _sqliteConnectionString = string.Format("Data Source={0};Version=3;", _database.FullName); using (SQLiteConnection connection = TryConnectToSQLite()) { if (null == connection) { return false; } } + if (string.IsNullOrEmpty(_targetSqlServerName)) { + Console.WriteLine("Mandatory -d parameter is missing."); + return false; + } + _sqlServerConnectionString = string.Format( + "Data Source={0};Initial Catalog={1};Integrated Security=True;MultipleActiveResultSets=True", + _targetSqlServerName, _targetDatabaseName); + using(SqlConnection connection = TryConnectToSqlServer()) { + if (null == connection) { return false; } + } return true; } + private static void Transfer(SqlConnection sqlServerConnection, SQLiteDataReader reader, + string insertCommandText, int parametersCount) + { + int linesCount = 0; + using (SqlCommand insertCommand = new SqlCommand(insertCommandText, sqlServerConnection)) { + SqlParameter[] parameters = new SqlParameter[parametersCount]; + for(int index = 0; index < parametersCount; index++) { + parameters[index] = insertCommand.Parameters.Add(new SqlParameter("@P" + (1 + index).ToString(), null)); + } + while (reader.Read()) { + for(int index = 0; index < parametersCount; index++) { + parameters[index].Value = reader.GetValue(index); + } + insertCommand.ExecuteNonQuery(); + if (0 == (++linesCount % 1000)) { Console.Write("."); } + } + Console.WriteLine("\r\n\r{0} lines imported.", linesCount); + return; + } + } + private static SQLiteConnection TryConnectToSQLite() { try { - SQLiteConnection connection = new SQLiteConnection(_connectionString); + SQLiteConnection connection = new SQLiteConnection(_sqliteConnectionString); connection.Open(); return connection; } @@ -153,6 +459,19 @@ private static SQLiteConnection TryConnectToSQLite() } } + private static SqlConnection TryConnectToSqlServer() + { + try { + SqlConnection connection = new SqlConnection(_sqlServerConnectionString); + connection.Open(); + return connection; + } + catch (Exception e) { + Console.WriteLine("Failed to connect to SqlServer database : {0}", e.Message); + return null; + } + } + private static string TryGetAdditionalArgument(string[] from, ref int index) { string currentArgument = from[index]; @@ -164,7 +483,7 @@ private static string TryGetAdditionalArgument(string[] from, ref int index) return from[index]; } - private static FileStream TryOpenDatabase() + private static FileStream TryOpenSqliteDatabase() { try { return File.Open(_database.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); @@ -176,7 +495,7 @@ private static FileStream TryOpenDatabase() } } - private static object VerifyTableDescription(SQLiteConnection connection, + private static void VerifyTableDescription(SQLiteConnection connection, string tableName) { using (SQLiteCommand command = new SQLiteCommand( @@ -186,23 +505,48 @@ private static object VerifyTableDescription(SQLiteConnection connection, if (!_tableInfoColumnOrderAlreadyAsserted) { AssertTableInfoColumnsOrder(reader); } - throw new NotImplementedException(); + // Load schema. + if (!_schemaAlreadyAsserted) { + AssertInputSchema(tableName, reader); + } } } - return null; + return; } - private const string GetTableColumnsDescriptionCommand = - "PRAGMA table_info('{0}');"; - private const string GetTableListCommand = - "SELECT NAME from sqlite_master"; + private const string GetTableColumnsDescriptionCommand = "PRAGMA table_info('{0}');"; + private const string GetTableListCommand = "SELECT NAME from sqlite_master"; private const int TableInfoNameColumIndex = 1; private const int TableInfoTypeColumIndex = 2; private const int TableInfoNullableFlagColumIndex = 3; private const int TableInfoPrimaryKeyFlagColumIndex = 5; - private static string _connectionString; private static FileInfo _database; private static bool _displayUsage; +#if DEBUG + /// For debugging purpose only. This allow us to bypass + /// already loaded tables and quicker fix a failing table. + /// This table should be empty during normal use. + private static readonly string[] _ignoreTables = new string[] { + "nvd_db", "cwe_db", "cve_cwe", "cwe_category", "cwe_capec", "cve_cpe", + "cve_reference", "map_cve_aixapar" + }; +#endif + private static List _inInsertionOrderTableNames; + private static bool _schemaAlreadyAsserted; + private static string _sqlServerConnectionString; + private static string _sqliteConnectionString; + private static Dictionary> _tablesByName = + new Dictionary>(); private static bool _tableInfoColumnOrderAlreadyAsserted; + private static string _targetDatabaseName = "vFeed"; + private static string _targetSqlServerName; + + private struct ColumnInfo + { + internal string Name { get; set; } + internal bool Nullable { get; set; } + internal int PrimaryKey { get; set; } + internal string Type { get; set; } + } } } diff --git a/SSUpdate/SSUpdate.csproj b/SSUpdate/SSUpdate.csproj index 1cb7967..08e8760 100644 --- a/SSUpdate/SSUpdate.csproj +++ b/SSUpdate/SSUpdate.csproj @@ -49,6 +49,7 @@ + diff --git a/SSUpdate/SqlServerSchema.cs b/SSUpdate/SqlServerSchema.cs new file mode 100644 index 0000000..95a3306 --- /dev/null +++ b/SSUpdate/SqlServerSchema.cs @@ -0,0 +1,214 @@ +namespace SSUpdate +{ + internal static class SqlServerSchema + { + internal const string CreateSqlServerSchema = + "CREATE TABLE[nvd_db] (" + + " [cveid] sysname NOT NULL PRIMARY KEY CLUSTERED," + + " [date_published] date NULL," + + " [date_modified] date NULL," + + " [summary] text NULL," + + " [cvss_base] text NULL," + + " [cvss_impact] text NULL," + + " [cvss_exploit] text NULL," + + " [cvss_access_vector] text NULL," + + " [cvss_access_complexity] text NULL," + + " [cvss_authentication] text NULL," + + " [cvss_confidentiality_impact] text NULL," + + " [cvss_integrity_impact] text NULL," + + " [cvss_availability_impact] text NULL," + + " [cvss_vector] text NULL);" + + "CREATE TABLE[cwe_db] (" + + " [cweid] sysname NOT NULL PRIMARY KEY CLUSTERED," + + " [cwetitle] sysname NULL);" + + "CREATE TABLE[cve_cwe] (" + + " [cweid] sysname NULL CONSTRAINT CveCweCwe FOREIGN KEY REFERENCES [cwe_db]([cweid])," + + " [cveid] sysname NOT NULL CONSTRAINT CveCweNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[cwe_category] (" + + " [categoryid] sysname NULL," + + " [categorytitle] sysname NULL," + + " [cweid] sysname NOT NULL CONSTRAINT CweCategoryCwe FOREIGN KEY REFERENCES [cwe_db]([cweid]));" + + "CREATE TABLE[cwe_capec] (" + + " [capecid] sysname NULL," + + " [cweid] sysname NOT NULL CONSTRAINT CweCapecCwe FOREIGN KEY REFERENCES [cwe_db]([cweid]));" + + "CREATE TABLE[cve_cpe] (" + + " [cpeid] nvarchar(512) NOT NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveCpeNvd FOREIGN KEY REFERENCES [nvd_db]([cveid])" + + " CONSTRAINT [PK_cve_cpe] PRIMARY KEY CLUSTERED ([cpeid], [cveid]));" + + "CREATE TABLE[cve_reference] (" + + " [refsource] sysname NULL," + + " [refname] nvarchar(512) NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveReferenceNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_aixapar] (" + + " [aixaparid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveAixaparNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_redhat] (" + + " [redhatid] sysname NULL," + + " [redhatovalid] sysname NULL," + + " [redhatupdatedesc] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveRedhatNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_redhat_bugzilla] (" + + " [advisory_dateissue] sysname NULL," + + " [bugzillaid] sysname NULL," + + " [bugzillatitle] sysname NULL," + + " [redhatid] text NOT NULL);" + + "CREATE TABLE[map_cve_suse] (" + + " [suseid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveSuseNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_debian] (" + + " [debianid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveDebianNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_mandriva] (" + + " [mandrivaid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveMandrivaNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_saint] (" + + " [saintexploitid] sysname NULL," + + " [saintexploittitle] sysname NULL," + + " [saintexploitlink] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveSaintNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_milw0rm] (" + + " [milw0rmid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveMilw0rmNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_osvdb] (" + + " [osvdbid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveOsvdbNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_nessus] (" + + " [nessus_script_id] sysname NULL," + + " [nessus_script_file] sysname NULL," + + " [nessus_script_name] sysname NULL," + + " [nessus_script_family] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveNessusNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_msf] (" + + " [msfid] sysname NULL," + + " [msf_script_file] sysname NULL," + + " [msf_script_name] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveMsfNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_openvas] (" + + " [openvas_script_id] sysname NULL," + + " [openvas_script_file] sysname NULL," + + " [openvas_script_name] sysname NULL," + + " [openvas_script_family] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveOpenvasNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_scip] (" + + " [scipid] sysname NULL," + + " [sciplink] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveScipNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_iavm] (" + + " [iavmid] sysname NULL," + + " [disakey] sysname NULL," + + " [iavmtitle] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveIavmNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_cisco] (" + + " [ciscoid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveCiscoNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_ubuntu] (" + + " [ubuntuid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveUbuntuNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_gentoo] (" + + " [gentooid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveGentooNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_fedora] (" + + " [fedoraid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveFedoraNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_certvn] (" + + " [certvuid] sysname NULL," + + " [certvulink] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveCertvnNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_ms] (" + + " [msid] sysname NULL," + + " [mstitle] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveMsNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_mskb] (" + + " [mskbid] sysname NULL," + + " [mskbtitle] sysname NULL," + + " [cveid] text NOT NULL);" + + "CREATE TABLE[map_cve_snort] (" + + " [snort_id] sysname NULL," + + " [snort_sig] sysname NULL," + + " [snort_classtype] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveSnortNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_suricata] (" + + " [suricata_id] sysname NULL," + + " [suricata_sig] sysname NULL," + + " [suricata_classtype] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveSuricataNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_vmware] (" + + " [vmwareid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveVmwareNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_bid] (" + + " [bidid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveBidNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_hp] (" + + " [hpid] sysname NULL," + + " [hplink] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveHpNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[stat_new_cve] (" + + " [new_cve_id] sysname NULL CONSTRAINT CveNewNvd FOREIGN KEY REFERENCES [nvd_db]([cveid])," + + " [new_cve_summary] sysname NULL);" + + "CREATE TABLE[map_cve_exploitdb] (" + + " [exploitdbid] sysname NULL," + + " [exploitdbscript] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveExploitdbNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_nmap] (" + + " [nmap_script_id] sysname NULL," + + " [nmap_script_cat] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveNmapNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_oval] (" + + " [ovalid] sysname NULL," + + " [ovalclass] sysname NULL," + + " [ovaltitle] sysname NULL," + + " [cpeid] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveOvalNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[map_cve_d2] (" + + " [d2_script_name] sysname NULL," + + " [d2_script_file] sysname NULL," + + " [cveid] sysname NOT NULL CONSTRAINT CveD2Nvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));" + + "CREATE TABLE[stat_vfeed_kpi] (" + + " [db_version] sysname NULL," + + " [total_cve] sysname NULL," + + " [total_cpe] sysname NULL," + + " [total_cwe] sysname NULL," + + " [total_capec] sysname NULL," + + " [total_bid] sysname NULL," + + " [total_osvdb] sysname NULL," + + " [total_certvu] sysname NULL," + + " [total_iavm] sysname NULL," + + " [total_scip] sysname NULL," + + " [total_aixapar] sysname NULL," + + " [total_suse] sysname NULL," + + " [total_ubuntu] sysname NULL," + + " [total_vmware] sysname NULL," + + " [total_cisco] sysname NULL," + + " [total_debian] sysname NULL," + + " [total_fedora] sysname NULL," + + " [total_gentoo] sysname NULL," + + " [total_hp] sysname NULL," + + " [total_mandriva] sysname NULL," + + " [total_ms] sysname NULL," + + " [total_mskb] sysname NULL," + + " [total_redhat] sysname NULL," + + " [total_redhat_bugzilla] sysname NULL," + + " [total_exploitdb] sysname NULL," + + " [total_msf] sysname NULL," + + " [total_milw0rm] sysname NULL," + + " [total_saint] sysname NULL," + + " [total_nessus] sysname NULL," + + " [total_openvas] sysname NULL," + + " [total_oval] sysname NULL," + + " [total_snort] sysname NULL," + + " [total_nmap] sysname NULL," + + " [total_suricata] sysname NULL," + + " [total_d2exploit] sysname NULL);" + + "CREATE TABLE[capec_db] (" + + " [capecid] sysname NULL," + + " [capectitle] sysname NULL," + + " [attack] sysname NULL);" + + "CREATE TABLE[capec_mit] (" + + " [mitigation] sysname NULL," + + " [capecid] text NOT NULL);" + + "CREATE TABLE[cwe_wasc] (" + + " [wascname] sysname NULL," + + " [wascid] sysname NULL," + + " [cweid] sysname NOT NULL CONSTRAINT CveWascNvd FOREIGN KEY REFERENCES [nvd_db]([cveid]));"; + } +}