Exemple #1
0
        internal override bool Query()
        {
            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                string query1_1 = string.Format(
                    "USE {0};\n" +
                    "SELECT  \'{1}\' as [ComputerName],\n" +
                    "\'{2}\' as [Instance],\n" +
                    "\'{0}\' as [DatabaseName],",
                    database, computerName, instance);

                string query1_3 = string.Format(
                    "FROM [{0}].[sys].[database_principals]\n" +
                    "WHERE type like \'R\'",
                    database);

                StringBuilder sb = new StringBuilder();
                sb.Append(query1_1);
                sb.Append(QUERY1_2);
                sb.Append(query1_3);
                if (!string.IsNullOrEmpty(rolePrincipalNameFilter))
                {
                    sb.Append(rolePrincipalNameFilter);
                }
                if (!string.IsNullOrEmpty(roleOwnerFilter))
                {
                    sb.Append(roleOwnerFilter);
                }
#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                databaseRoles = sql.Query <DatabaseRole>(sb.ToString(), new DatabaseRole());
            }

            /*
             * foreach (DataRow row in table.AsEnumerable())
             * {
             *  try
             *  {
             *      DatabaseRole dr = new DatabaseRole
             *      {
             *          ComputerName = computerName,
             *          Instance = instance,
             *          DatabaseName = database,
             *          RolePrincipalId = (int)row["RolePrincipalId"],
             *          RolePrincipalSid = (byte[])row["RolePrincipalSid"],
             *          RolePrincipalName = (string)row["RolePrincipalName"],
             *          RolePrincipalType = (string)row["RolePrincipalType"],
             *          OwnerPrincipalId = (int)row["OwnerPrincipalId"],
             *          OwnerPrincipalName = (string)row["OwnerPrincipalName"],
             *          is_fixed_role = (bool)row["is_fixed_role"],
             *          create_date = (DateTime)row["create_date"],
             *          modify_Date = (DateTime)row["modify_Date"],
             *          default_schema_name = (object)row["default_schema_name"]
             *      };
             #if DEBUG
             *      Misc.PrintStruct<DatabaseRole>(dr);
             #endif
             *      databaseRoles.Add(dr);
             *  }
             *  catch (Exception ex)
             *  {
             *      if (ex is ArgumentNullException)
             *          Console.WriteLine("Empty Response");
             *      else
             *          Console.WriteLine(ex.Message);
             *      return false;
             *  }
             * }
             */
            return(true);
        }
Exemple #2
0
        internal override bool Query()
        {
            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                string query1_1 = string.Format("USE {0};", database);

                string query1_3 = string.Format(
                    "FROM [{0}].[sys].[triggers] WHERE 1=1",
                    database);

                StringBuilder sb = new StringBuilder();
                if (showAll)
                {
                    sb.Append(QUERY2_1);
                }
                else
                {
                    sb.Append(query1_1);
                    sb.Append(QUERY1_2);
                    sb.Append(query1_3);
                    if (!string.IsNullOrEmpty(assemblyNameFilter))
                    {
                        sb.Append(assemblyNameFilter);
                    }
                }

#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                files = sql.Query <AssemblyFiles>(sb.ToString(), new AssemblyFiles());
            }

            /*
             * foreach (DataRow row in table.AsEnumerable())
             * {
             *  try
             *  {
             *      AssemblyFiles af = new AssemblyFiles
             *      {
             *          ComputerName = computerName,
             *          Instance = instance,
             *          DatabaseName = database,
             *          schema_name = (string)row["schema_name"],
             *          file_id = (int)row["file_id"],
             *          file_name = (string)row["file_name"],
             *          clr_name = (string)row["clr_name"],
             *          assembly_id = (int)row["assembly_id"],
             *          assembly_name = (string)row["assembly_name"],
             *          assembly_class = (string)row["assembly_class"],
             *          assembly_method = (string)row["assembly_method"],
             *          sp_object_id = (int)row["sp_object_id"],
             *          sp_name = (string)row["sp_name"],
             *          sp_type = (string)row["sp_type"],
             *          permission_set_desc = (string)row["permission_set_desc"],
             *          create_date = (DateTime)row["create_date"],
             *          modify_date = (DateTime)row["modify_date"],
             *          content = (string)row["content"],
             *      };
             #if DEBUG
             *      Misc.PrintStruct<AssemblyFiles>(af);
             #endif
             *      files.Add(af);
             *  }
             *  catch (Exception ex)
             *  {
             *      if (ex is ArgumentNullException)
             *          Console.WriteLine("Empty Response");
             *      else
             *          Console.WriteLine(ex.Message);
             *      return false;
             *  }
             * }
             */
            return(true);
        }
Exemple #3
0
        internal override bool Query()
        {
            bool isSysAdmin = false;

            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                isSysAdmin = SQLSysadminCheck.Query(instance, computerName, credentials);

                string query = query1_1;
                if (isSysAdmin)
                {
                    query += query1_2;
                }
                query += string.Format("SELECT  \'{0}\' as [ComputerName],\n", computerName);;
                query += query1_4;
                if (isSysAdmin)
                {
                    query += query1_5;
                }
                query += query1_6;

                table = sql.Query(query);
            }

            foreach (DataRow row in table.AsEnumerable())
            {
                try
                {
                    details = new Details
                    {
                        ComputerName           = (string)row["ComputerName"],
                        Instance               = (string)row["Instance"],
                        DomainName             = (string)row["DomainName"],
                        ServiceProcessID       = (int)row["ServiceProcessID"],
                        ServiceName            = (string)row["ServiceName"],
                        ServiceAccount         = (string)row["ServiceAccount"],
                        AuthenticationMode     = (string)row["AuthenticationMode"],
                        ForcedEncryption       = (int)row["ForcedEncryption"],
                        Clustered              = (string)row["Clustered"],
                        SQLServerVersionNumber = (string)row["SQLServerVersionNumber"],
                        SQLServerMajorVersion  = (string)row["SQLServerMajorVersion"],
                        SQLServerEdition       = (string)row["SQLServerEdition"],
                        SQLServerServicePack   = (string)row["SQLServerServicePack"],
                        OSArchitecture         = (string)row["OSArchitecture"],
                        OsVersionNumber        = (string)row["OsVersionNumber"],
                        Currentlogin           = (string)row["Currentlogin"]
                    };

                    if (isSysAdmin)
                    {
                        details.OsMachineType = (string)row["OsMachineType"];
                        details.OSVersionName = (string)row["OSVersionName"];
                    }
#if DEBUG
                    Misc.PrintStruct <Details>(details);
#endif
                    return(true);
                }
                catch (Exception ex)
                {
                    if (ex is ArgumentNullException)
                    {
                        Console.WriteLine("Empty Response");
                    }
                    else
                    {
                        Console.WriteLine(ex.Message);
                    }
                    return(false);
                }
            }
            return(false);
        }
Exemple #4
0
        internal override bool Query()
        {
            bool isSysAdmin = false;

            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                isSysAdmin = SQLSysadminCheck.Query(instance, computerName, credentials);

                StringBuilder sb = new StringBuilder();
                sb.Append(string.Format("USE master;\nSELECT  \'{0}\' as [ComputerName],\n\'{1}\' as [Instance],", computerName, instance));
                sb.Append(QUERY1_2);
                if (!string.IsNullOrEmpty(credentialFilter))
                {
                    sb.Append(credentialFilter);
                }
#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                serverCredentials = sql.Query <ServerCredential>(sb.ToString(), new ServerCredential());
            }

            /*
             * foreach (DataRow row in table.AsEnumerable())
             * {
             *  try
             *  {
             *      ServerCredential sc = new ServerCredential
             *      {
             *          ComputerName = (string)row["ComputerName"],
             *          Instance = (string)row["Instance"],
             *          credential_id = (int)row["credential_id"],
             *          CredentialName = (string)row["CredentialName"],
             *          credential_identity = (string)row["credential_identity"],
             *          create_date = (DateTime)row["create_date"],
             *          modify_date = (DateTime)row["modify_date"],
             *          target_type = (string)row["target_type"],
             *          target_id = (int)row["target_id"]
             *      };
             #if DEBUG
             *      Misc.PrintStruct<ServerCredential>(sc);
             #endif
             *      serverCredentials.Add(sc);
             *      return true;
             *  }
             *  catch (Exception ex)
             *  {
             *      if (ex is ArgumentNullException)
             *          Console.WriteLine("Empty Response");
             *      else
             *          Console.WriteLine(ex.Message);
             *      return false;
             *  }
             * }
             */
            return(false);
        }
Exemple #5
0
        internal override bool Query()
        {
            string query1_1 = string.Format(
                "USE {0};\n" +
                "SELECT  \'{1}\' as [ComputerName],\n" +
                "\'{2}\' as [Instance],",
                database, computerName, instance
                );

            string query1_3 = string.Format(
                "FROM [{0}].[INFORMATION_SCHEMA].[SCHEMATA]",
                database
                );

            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                StringBuilder sb = new StringBuilder();
                sb.Append(query1_1);
                sb.Append(QUERY1_2);
                sb.Append(query1_3);
                if (!string.IsNullOrEmpty(schemaFilter))
                {
                    sb.Append(schemaFilter);
                }
                sb.Append(QUERY1_4);
#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                schemas = sql.Query <Schema>(sb.ToString(), new Schema());
            }

            /*
             * foreach (DataRow row in table.AsEnumerable())
             * {
             *  try
             *  {
             *      Schema s = new Schema
             *      {
             *          ComputerName = (string)row["ComputerName"],
             *          Instance = (string)row["Instance"],
             *          DatabaseName = (string)row["DatabaseName"],
             *          SchemaName = (string)row["SchemaName"],
             *          SchemaOwner = (string)row["SchemaOwner"],
             *      };
             #if DEBUG
             *      Misc.PrintStruct<Schema>(s);
             #endif
             *      schemas.Add(s);
             *  }
             *  catch (Exception ex)
             *  {
             *      if (ex is ArgumentNullException)
             *          Console.WriteLine("Empty Response");
             *      else
             *          Console.WriteLine(ex);
             *      return false;
             *  }
             * }
             */
            return(true);
        }
Exemple #6
0
        internal override bool Query()
        {
            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                StringBuilder sb = new StringBuilder();
                sb.Append(string.Format("USE {0};\n", database));
                sb.Append(string.Format("SELECT  \'{0}\' as [ComputerName],\n", computerName));
                sb.Append(string.Format("\'{0}\' as [Instance],", instance));
                sb.Append(QUERY1_4);
                sb.Append(string.Format("FROM [{0}].[INFORMATION_SCHEMA].[COLUMNS] WHERE 1 = 1", database));
                if (!string.IsNullOrEmpty(columnFilter))
                {
                    sb.Append(columnFilter);
                }
                foreach (string f in columnSearchFilter)
                {
                    sb.Append(f);
                }
                if (!string.IsNullOrEmpty(tableNameFilter))
                {
                    sb.Append(tableNameFilter);
                }
                sb.Append(QUERY1_6);
#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                columns = sql.Query <Column>(sb.ToString(), new Column());
            }

            /*
             * try
             * {
             *  foreach (DataRow row in table.AsEnumerable())
             *  {
             *      Column t = new Column
             *      {
             *          ComputerName = (string)row["ComputerName"],
             *          Instance = (string)row["Instance"],
             *          DatabaseName = (string)row["DatabaseName"],
             *          SchemaName = (string)row["SchemaName"],
             *          TableName = (string)row["TableName"],
             *          ColumnName = (string)row["ColumnName"],
             *          ColumnDataType = (string)row["ColumnDataType"],
             *          ColumnMaxLength = (object)row["ColumnMaxLength"]
             *      };
             #if DEBUG
             *      Misc.PrintStruct<Column>(t);
             #endif
             *      columns.Add(t);
             *  }
             * }
             * catch (Exception ex)
             * {
             *  if (ex is ArgumentNullException)
             *      Console.WriteLine("Empty Response");
             *  else
             *      Console.WriteLine(ex);
             *  return false;
             * }
             */
            return(true);
        }
Exemple #7
0
        internal override bool Query()
        {
            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                for (int i = start; i <= end; i++)
                {
                    string query1_1 = string.Format(
                        "SELECT \'{0}\' as [ComputerName],\n" +
                        "\'{1}\' as [Instance],\n" +
                        "\'{2}\' as [ObjectId],\n" +
                        "OBJECT_NAME({2}) as [ObjectName]",
                        computerName, instance, i
                        );
#if DEBUG
                    Console.WriteLine(query1_1);
#endif
                    table = sql.Query(query1_1);

                    foreach (DataRow row in table.AsEnumerable())
                    {
                        try
                        {
                            Fuzz f = new Fuzz
                            {
                                ComputerName = computerName,
                                Instance     = instance,
                                ObjectId     = (string)row["ObjectId"],
                            };
                            if (!(row["ObjectName"] is DBNull))
                            {
                                f.ObjectName = (string)row["ObjectName"];
                            }

#if DEBUG
                            Misc.PrintStruct <Fuzz>(f);
#endif
                            fuzzed.Add(f);
                        }
                        catch (Exception ex)
                        {
                            if (ex is ArgumentNullException)
                            {
                                continue;
                            }
                            else
                            {
                                Console.WriteLine(ex.Message);
                            }
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemple #8
0
        internal override bool Query()
        {
            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                string query1_1 = string.Format("" +
                                                "SELECT \'{0}\' as [ComputerName],\n" +
                                                "\'{1}\' as [Instance],\n" +
                                                "\'{3}\' as [DatabaseName],\n",
                                                computerName, instance, database);

                StringBuilder sb = new StringBuilder();
                sb.Append(query1_1);
                sb.Append(QUERY1_2);
                if (!string.IsNullOrEmpty(assemblyNameFilter))
                {
                    sb.Append(assemblyNameFilter);
                }

#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                table = sql.Query(sb.ToString());
            }

            foreach (DataRow row in table.AsEnumerable())
            {
                try
                {
                    Assembly a = new Assembly
                    {
                        ComputerName        = computerName,
                        Instance            = instance,
                        DatabaseName        = database,
                        assembly_id         = (int)row["assembly_id"],
                        assembly_name       = (string)row["assembly_name"],
                        file_id             = (int)row["file_id"],
                        file_name           = (string)row["file_name"],
                        clr_name            = (string)row["clr_name"],
                        content             = (byte[])row["content"],
                        permission_set_desc = (string)row["permission_set_desc"],
                        create_date         = (DateTime)row["create_date"],
                        modify_date         = (DateTime)row["modify_date"],
                        is_user_defined     = (bool)row["is_user_defined"]
                    };
#if DEBUG
                    Misc.PrintStruct <Assembly>(a);
#endif
                    assemblies.Add(a);
                }
                catch (Exception ex)
                {
                    if (ex is ArgumentNullException)
                    {
                        Console.WriteLine("Empty Response");
                    }
                    else
                    {
                        Console.WriteLine(ex.Message);
                    }
                    return(false);
                }
            }
            return(true);
        }
Exemple #9
0
        internal override bool Query()
        {
            string query1_1 = string.Format(
                "USE master;\n" +
                "SELECT  \'{0}\' as [ComputerName],\n" +
                "\'{1}\' as [Instance],\n" +
                "security_id as [PrincipalSid],\n" +
                "login_name as [PrincipalName],\n" +
                "original_login_name as [OriginalPrincipalName],\n" +
                "session_id as [SessionId],\n" +
                "last_request_start_time as [SessionStartTime],\n" +
                "login_time as [SessionLoginTime],\n" +
                "status as [SessionStatus]\n" +
                "FROM[sys].[dm_exec_sessions]\n" +
                "{2}\n" +
                "ORDER BY status\n"
                , computerName, instance, principalName);

            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }
#if DEBUG
                Console.WriteLine(query1_1);
#endif
                //table = sql.Query(query1_1);
                sessions = sql.Query <Sessions>(query1_1, new Sessions());
            }

            /*
             * try
             * {
             *  foreach (var row in table.AsEnumerable())
             *  {
             *      Sessions s = new Sessions
             *      {
             *          ComputerName = (string)row["ComputerName"],
             *          Instance = (string)row["Instance"],
             *          PrincipalSid = (byte[])row["PrincipalSid"],
             *          PrincipalName = (string)row["PrincipalName"],
             *          OriginalPrincipalName = (string)row["OriginalPrincipalName"],
             *          SessionId = row["SessionId"],
             *          SessionStartTime = (DateTime)row["SessionStartTime"],
             *          SessionLoginTime = (DateTime)row["SessionLoginTime"],
             *          SessionStatus = row["SessionStatus"],
             *      };
             #if DEBUG
             *      Misc.PrintStruct<Sessions>(s);
             #endif
             *      sessions.Add(s);
             *  }
             * }
             * catch (Exception ex)
             * {
             *  if (ex is ArgumentNullException)
             *      Console.WriteLine("Empty Response");
             *  else
             *      Console.WriteLine(ex);
             *  return false;
             * }
             */
            return(true);
        }
        internal override bool Query()
        {
            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                string query1_1 = string.Format(
                    "USE {0};\n" +
                    "SELECT \'{1}\' as [ComputerName],\n" +
                    "\'{2}\' as [Instance],\n" +
                    "\'{0}\' as [DatabaseName],",
                    database, computerName, instance);

                string query1_3 = string.Format(
                    "FROM [{0}].[sys].[database_role_members]\n" +
                    "WHERE 1 = 1",
                    database);

                StringBuilder sb = new StringBuilder();
                sb.Append(query1_1);
                sb.Append(QUERY1_2);
                sb.Append(query1_3);
                if (!string.IsNullOrEmpty(rolePrincipalNameFilter))
                {
                    sb.Append(rolePrincipalNameFilter);
                }
                if (!string.IsNullOrEmpty(principalNameFilter))
                {
                    sb.Append(principalNameFilter);
                }
#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                userRoles = sql.Query <UserRole>(sb.ToString(), new UserRole());
            }

            /*
             * foreach (DataRow row in table.AsEnumerable())
             * {
             *  try
             *  {
             *      UserRole ur = new UserRole
             *      {
             *          ComputerName = computerName,
             *          Instance = instance,
             *          DatabaseName = database,
             *          RolePrincipalId = (int)row["RolePrincipalId"],
             *          RolePrincipalName = (string)row["RolePrincipalName"],
             *          PrincipalId = (int)row["PrincipalId"],
             *          PrincipalName = (string)row["PrincipalName"]
             *      };
             #if DEBUG
             *      Misc.PrintStruct<UserRole>(ur);
             #endif
             *      userRoles.Add(ur);
             *  }
             *  catch (Exception ex)
             *  {
             *      if (ex is ArgumentNullException)
             *          Console.WriteLine("Empty Response");
             *      else
             *          Console.WriteLine(ex.Message);
             *      return false;
             *  }
             * }
             */
            return(true);
        }
Exemple #11
0
        internal override bool Query()
        {
            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                string query1_1 = string.Format(
                    "SELECT  \'{0}\' as [ComputerName],\n" +
                    "\'{1}\' as [Instance],",
                    computerName, instance);

                string query1_3 = string.Format(
                    "FROM [{0}].[sys].[triggers] WHERE 1=1",
                    database);

                StringBuilder sb = new StringBuilder();
                sb.Append(query1_1);
                sb.Append(QUERY1_2);
                sb.Append(query1_3);
                if (!string.IsNullOrEmpty(triggerNameFilter))
                {
                    sb.Append(triggerNameFilter);
                }

#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                triggers = sql.Query <TriggerDml>(sb.ToString(), new TriggerDml());
            }

            /*
             * foreach (DataRow row in table.AsEnumerable())
             * {
             *  try
             *  {
             *      TriggerDml td = new TriggerDml
             *      {
             *          ComputerName = computerName,
             *          Instance = instance,
             *          TriggerName = (string)row["TriggerName"],
             *          TriggerId = (int)row["TriggerId"],
             *          TriggerType = (string)row["TriggerType"],
             *          ObjectType = (string)row["ObjectType"],
             *          ObjectClass = (string)row["ObjectClass"],
             *          TriggerDefinition = (string)row["TriggerDefinition"],
             *          create_date = (DateTime)row["create_date"],
             *          modify_date = (DateTime)row["modify_date"],
             *          is_ms_shipped = (bool)row["is_ms_shipped"],
             *          is_disabled = (bool)row["is_disabled"],
             *          is_not_for_replication = (bool)row["is_not_for_replication"],
             *          is_instead_of_trigger = (bool)row["is_instead_of_trigger"],
             *      };
             #if DEBUG
             *      Misc.PrintStruct<TriggerDml>(td);
             #endif
             *      triggers.Add(td);
             *      return true;
             *  }
             *  catch (Exception ex)
             *  {
             *      if (ex is ArgumentNullException)
             *          Console.WriteLine("Empty Response");
             *      else
             *          Console.WriteLine(ex.Message);
             *      return false;
             *  }
             * }
             */
            return(true);
        }
Exemple #12
0
        internal override bool Query()
        {
            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                SQLServerInfo info = new SQLServerInfo(credentials);
                info.SetInstance(instance);
                info.Query();
                SQLServerInfo.Details d = info.GetResults();

                domainName = d.DomainName;

                string query1_1 = string.Format("SELECT SUSER_SID(\'{0}\\{1}\') as DomainGroupSid", domainName, domainGroup);
#if DEBUG
                Console.WriteLine(query1_1);
#endif
                DataTable table    = sql.Query(query1_1);
                byte[]    sidBytes = (byte[])table.AsEnumerable().First()["DomainGroupSid"];
                string    strSid   = BitConverter.ToString(sidBytes).Replace("-", "").Substring(0, 48);

                Console.WriteLine("Base SID: {0}", strSid);

                for (int i = start; i <= end; i++)
                {
                    string strHexI  = i.ToString("x");
                    int    nStrHexI = strHexI.Length;
                    string rid      = strHexI;
                    if (0 != nStrHexI % 2)
                    {
                        rid = "0" + strHexI;
                    }

                    string[] arrSplit = Split(rid, 2).ToArray();
                    Array.Reverse(arrSplit);
                    rid = string.Join("", arrSplit);
                    rid = rid.PadRight(8, '0');
                    rid = "0x" + strSid + rid;

                    string query2_1 = string.Format("SELECT SUSER_SNAME({0}) as [DomainAccount]", rid);
#if DEBUG
                    Console.WriteLine(query2_1);
#endif
                    table = sql.Query(query2_1);

                    foreach (DataRow row in table.AsEnumerable())
                    {
                        try
                        {
                            if (row["DomainAccount"] is DBNull)
                            {
                                continue;
                            }

                            Fuzz f = new Fuzz
                            {
                                ComputerName  = computerName,
                                Instance      = instance,
                                SID           = rid,
                                RID           = i,
                                DomainAccount = (string)row["DomainAccount"],
                            };
                            fuzzed.Add(f);
                        }
                        catch (Exception ex)
                        {
                            if (ex is ArgumentNullException)
                            {
                                continue;
                            }
                            else
                            {
                                Console.WriteLine(ex.Message);
                            }
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemple #13
0
        internal override bool Query()
        {
            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                string query1_1 = string.Format(
                    "SELECT  \'{0}\' as [ComputerName],\n" +
                    "\'{1}\' as [Instance],\n",
                    computerName, instance);

                StringBuilder sb = new StringBuilder();
                sb.Append(query1_1);
                sb.Append(QUERY1_2);
                if (!string.IsNullOrEmpty(principalNameFilter))
                {
                    sb.Append(principalNameFilter);
                }
                if (!string.IsNullOrEmpty(roleOwnerFilter))
                {
                    sb.Append(roleOwnerFilter);
                }
#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                serverRoles = sql.Query <ServerRoleMember>(sb.ToString(), new ServerRoleMember());
            }

            /*
             * foreach (DataRow row in table.AsEnumerable())
             * {
             *  try
             *  {
             *      ServerRoleMember sr = new ServerRoleMember
             *      {
             *          ComputerName = computerName,
             *          Instance = instance,
             *          RolePrincipalId = (int)row["RolePrincipalId"],
             *          RolePrincipalName = (string)row["RolePrincipalName"],
             *          PrincipalId = (int)row["PrincipalId"],
             *          PrincipalName = (string)row["PrincipalName"]
             *      };
             #if DEBUG
             *      Misc.PrintStruct<ServerRoleMember>(sr);
             #endif
             *      serverRoles.Add(sr);
             *      return true;
             *  }
             *  catch (Exception ex)
             *  {
             *      if (ex is ArgumentNullException)
             *          Console.WriteLine("Empty Response");
             *      else
             *          Console.WriteLine(ex.Message);
             *      return false;
             *  }
             * }
             */
            return(true);
        }
Exemple #14
0
        internal override bool Query()
        {
            bool isSysAdmin = false;

            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                isSysAdmin = SQLSysadminCheck.Query(instance, computerName, credentials);

                StringBuilder sb = new StringBuilder();
                sb.Append(QUERY1_1);
                if (isSysAdmin)
                {
                    sb.Append(QUERY1_2);
                }
                sb.Append(QUERY1_3);
                if (isSysAdmin)
                {
                    sb.Append(QUERY1_4);
                }
#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                serverLogins = sql.Query <ServerLogin>(sb.ToString(), new ServerLogin());
            }

            /*
             * foreach (DataRow row in table.AsEnumerable())
             * {
             *  try
             *  {
             *      ServerLogin sl = new ServerLogin
             *      {
             *          ComputerName = computerName,
             *          Instance = instance,
             *          DBEngineLogin = (string)row["DBEngineLogin"],
             *          AgentLogin = (string)row["AgentLogin"],
             *          BrowserLogin = (string)row["BrowserLogin"],
             *          WriterLogin = (string)row["WriterLogin"],
             *          AnalysisLogin = (object)row["AnalysisLogin"],
             *          ReportLogin = (object)row["ReportLogin"],
             *          IntegrationLogin = (object)row["IntegrationLogin"]
             *      };
             #if DEBUG
             *      Misc.PrintStruct<ServerLogin>(sl);
             #endif
             *      serverLogins.Add(sl);
             *      return true;
             *  }
             *  catch (Exception ex)
             *  {
             *      if (ex is ArgumentNullException)
             *          Console.WriteLine("Empty Response");
             *      else
             *          Console.WriteLine(ex.Message);
             *      return false;
             *  }
             * }
             */
            return(true);
        }
Exemple #15
0
        internal override bool Query()
        {
            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                string query1_1 = string.Format(
                    "SELECT \'{0}\' as [ComputerName],\n" +
                    "\'{1}\' as [Instance],\n",
                    computerName, instance);

                StringBuilder sb = new StringBuilder();
                sb.Append(query1_1);
                sb.Append(QUERY1_2);
                if (!string.IsNullOrEmpty(permissionNameFilter))
                {
                    sb.Append(permissionNameFilter);
                }
                sb.Append(QUERY1_3);
#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                serverPrivileges = sql.Query <ServerPrivilege>(sb.ToString(), new ServerPrivilege());
            }

            /*
             * foreach (DataRow row in table.AsEnumerable())
             * {
             *  try
             *  {
             *      ServerPrivilege dp = new ServerPrivilege
             *      {
             *          ComputerName = computerName,
             *          Instance = instance,
             *          GranteeName = (string)row["GranteeName"],
             *          GrantorName = (string)row["GrantorName"],
             *          PermissionClass = (string)row["PermissionClass"],
             *          PermissionName = (string)row["PermissionName"],
             *          PermissionState = (string)row["PermissionState"],
             *          ObjectName = (string)row["ObjectName"],
             *          ObjectType = (string)row["ObjectType"]
             *      };
             #if DEBUG
             *      Misc.PrintStruct<ServerPrivilege>(dp);
             #endif
             *      serverPrivileges.Add(dp);
             *      return true;
             *  }
             *  catch (Exception ex)
             *  {
             *      if (ex is ArgumentNullException)
             *          Console.WriteLine("Empty Response");
             *      else
             *          Console.WriteLine(ex.Message);
             *      return false;
             *  }
             * }
             */
            return(true);
        }
Exemple #16
0
        internal override bool Query()
        {
            string query1_1 = string.Format(
                "USE {0};\n" +
                "SELECT \'{1}\' as [ComputerName],\n" +
                "\'{2}\' as [Instance],",
                database, computerName, instance
                );

            using (SQLConnection sql = new SQLConnection(instance))
            {
                sql.BuildConnectionString(credentials);
                if (!sql.Connect())
                {
                    return(false);
                }

                StringBuilder sb = new StringBuilder();
                sb.Append(query1_1);
                sb.Append(QUERY1_2);
                if (!string.IsNullOrEmpty(viewFilter))
                {
                    sb.Append(viewFilter);
                }
                sb.Append(QUERY1_3);
#if DEBUG
                Console.WriteLine(sb.ToString());
#endif
                //table = sql.Query(sb.ToString());
                views = sql.Query <View>(sb.ToString(), new View());
            }

            /*
             * foreach (DataRow row in table.AsEnumerable())
             * {
             *  try
             *  {
             *      View v = new View
             *      {
             *          ComputerName = (string)row["ComputerName"],
             *          Instance = (string)row["Instance"],
             *          DatabaseName = (string)row["DatabaseName"],
             *          SchemaName = (string)row["SchemaName"],
             *          ViewName = (string)row["ViewName"],
             *          ViewDefinition = (string)row["ViewDefinition"],
             *          IsUpdatable = (string)row["IsUpdatable"],
             *          CheckOption = (string)row["CheckOption"]
             *      };
             #if DEBUG
             *      Misc.PrintStruct<View>(v);
             #endif
             *      views.Add(v);
             *  }
             *  catch (Exception ex)
             *  {
             *      if (ex is ArgumentNullException)
             *          Console.WriteLine("Empty Response");
             *      else
             *          Console.WriteLine(ex);
             *      return false;
             *  }
             * }
             */
            return(true);
        }