Giter VIP home page Giter VIP logo

microsoft-sql-server-2014-instance-stig-baseline's Introduction

microsoft-sql-server-2014-instance-stig-baseline

InSpec profile to validate the secure configuration of Microsoft SQL Server 2014 *Instance, against DISA's Microsoft SQL Server 2014 Instance Security Technical Implementation Guide (STIG) Version 1, Release 9.

* In the Microsoft SQL Server domain, an instance is one installed, operational copy of the DBMS software. Although multiple SQL Server instances can coexist on a Windows server, it is customary in a production environment for a single instance to be deployed on a dedicated server.

Getting Started

It is intended and recommended that InSpec run this profile from a "runner" host (such as a DevOps orchestration server, an administrative management system, or a developer's workstation/laptop) against the target remotely over winrm.

For the best security of the runner, always install on the runner the latest version of InSpec and supporting Ruby language components.

Latest versions and installation options are available at the InSpec site.

Tailoring to Your Environment

The following inputs must be configured in an inputs ".yml" file for the profile to run correctly for your specific environment. More information about InSpec inputs can be found in the InSpec Profile Documentation.

# username MSSQL DB Server
user: ''

# password MSSQL DB Server'
password: ''

# hostname MSSQL DB Server'
host: ''

# instance name MSSQL DB Server'
instance: ''

# port MSSQL DB Server
port: 1433

# name of the specific DB being evaluated within the MSSQL server
db_name: ''

# Set to true If SQL Server Trace is in use for audit purposes
server_trace_implemented: true

# Set to true If SQL Server Audit is in use for audit purposes
server_audit_implemented: true

# Set to true if SQL Server Reporting Services is in use
sql_server_reporting_services_used: false

# Set to true if SQL Server data tools is required
sql_server_data_tools_required: false

# Set to true if SQL Server Integration Services is in use
sql_server_integration_services_used: false

# Set to true if SQL Server analysis Services is in use
sql_server_analysis_services_used: false

# Set to true if SQL Server Distributed Replay Client is in use
sql_server_distributed_replay_client_used: false

# Set to true if SQL Server Distributed Replay Controller is in use
sql_server_distributed_replay_controller_used: false

# Set to true if SQL Server full-text search is in use
sql_server_full_text_search_used: false

# Set to true if master data services is in use
master_data_services_used: false

# Set to true if data quality client is in use
data_quality_client_used: false

# Set to true if data quality services is in use
data_quality_services_used: false

# Set to true if data quality services is in use
data_quality_services_used: false

# Set to true if client tools sdk is in use
client_tools_sdk_used: false

# Set to true if sql server management tools is in use
sql_mgmt_tools_used: false

# instance name MSSQL DB Server
server_instance: ''

# List of users with permissions - ALTER TRACE, CREATE TRACE EVENT NOTIFICATION
approved_audit_maintainers: []

# List of users with audit permissions - ALTER ANY SERVER AUDIT, CONTROL SERVER, ALTER ANY DATABASE, CREATE ANY DATABASE
allowed_audit_permissions: []

# List of user with permissions -  ALTER ANY SERVER AUDIT, ALTER ANYDATABASE AUDIT, ALTER TRACE; or EXECUTE
allowed_sql_alter_permissions: []

# List of approved users with access to SQL Server Audits
approved_users_sql_audits: []

# List of sql server users with permissions - alter, create, control
approved_users_server: []

# List of sql database users with permissions - alter, create, control
approved_users_database: []

# List of sql components installed
sql_components: []

# List of authorized network protocols for the SQL server
authorized_protocols: []

# List of authorized network ports for the SQL server
authorized_ports: []

# List of authorized network port names for the SQL server
authorized_ports_name: []

# List of authorized users for the SQL server
authorized_sql_users: []

# List of users allowed to execute privileged functions - create, alter, delete
allowed_users_priv_functions: []

# List of allowed server permissions
allowed_server_permissions: []

# List of allowed database permissions
allowed_database_permissions: []

# List of Databases that require encryption
encrypted_databases: []

# Set to true if data at rest encryption is required
data_at_rest_encryption_required: false

# Set to true if full disk encryption is in place
full_disk_encryption_inplace: false

# List of user allowed to execute privileged functions
allowed_users: []

# Set to true xp cmdshell is required
is_xp_cmdshell_required: false

# List of accounts managed by the sql server
sql_managed_accounts: []

# Set to true if filestream is required
filestream_required: false

# Set to true if filestream transact access is required
filestream_transact_access_only_required: false

Running This Baseline Directly from Github

# How to run
inspec exec https://github.com/mitre/microsoft-sql-server-2014-instance-stig-baseline/archive/master.tar.gz -t winrm://<hostip> --user '<admin-account>' --password=<password> --input-file=<path_to_your_inputs_file/name_of_your_inputs_file.yml> --reporter=cli json:<path_to_your_output_file/name_of_your_output_file.json>

Different Run Options

Full exec options

Running This Baseline from a local Archive copy

If your runner is not always expected to have direct access to GitHub, use the following steps to create an archive bundle of this baseline and all of its dependent tests:

(Git is required to clone the InSpec profile using the instructions below. Git can be downloaded from the Git site.)

When the "runner" host uses this profile baseline for the first time, follow these steps:

mkdir profiles
cd profiles
git clone https://github.com/mitre/microsoft-sql-server-2014-instance-stig-baseline
inspec archive microsoft-sql-server-2014-instance-stig-baseline
inspec exec <name of generated archive> -t winrm://<hostip> --user '<admin-account>' --password=<password> --input-file=<path_to_your_inputs_file/name_of_your_inputs_file.yml> --reporter=cli json:<path_to_your_output_file/name_of_your_output_file.json>

For every successive run, follow these steps to always have the latest version of this baseline:

cd microsoft-sql-server-2014-instance-stig-baseline
git pull
cd ..
inspec archive microsoft-sql-server-2014-instance-stig-baseline --overwrite
inspec exec <name of generated archive> -t winrm://<hostip> --user '<admin-account>' --password=<password> --input-file=<path_to_your_inputs_file/name_of_your_inputs_file.yml> --reporter=cli json:<path_to_your_output_file/name_of_your_output_file.json>

Viewing the JSON Results

The JSON results output file can be loaded into heimdall-lite for a user-interactive, graphical view of the InSpec results.

The JSON InSpec results file may also be loaded into a full heimdall server, allowing for additional functionality such as to store and compare multiple profile runs.

Authors

Special Thanks

Contributing and Getting Help

To report a bug or feature request, please open an issue.

NOTICE

© 2018-2020 The MITRE Corporation.

Approved for Public Release; Distribution Unlimited. Case Number 18-3678.

NOTICE

MITRE hereby grants express written permission to use, reproduce, distribute, modify, and otherwise leverage this software to the extent permitted by the licensed terms provided in the LICENSE.md file included with this project.

NOTICE

This software was produced for the U. S. Government under Contract Number HHSM-500-2012-00008I, and is subject to Federal Acquisition Regulation Clause 52.227-14, Rights in Data-General.

No other use other than that granted to the U. S. Government, or to those acting on behalf of the U. S. Government under that Clause is authorized without the express written permission of The MITRE Corporation.

For further information, please contact The MITRE Corporation, Contracts Management Office, 7515 Colshire Drive, McLean, VA 22102-7539, (703) 983-6000.

NOTICE

DISA STIGs are published by DISA IASE, see: https://iase.disa.mil/Pages/privacy_policy.aspx

microsoft-sql-server-2014-instance-stig-baseline's People

Contributors

aaronlippold avatar asturtevant avatar djhaynes avatar ejaronne avatar georgedias avatar hackershark avatar karikarshivani avatar rx294 avatar samcornwell avatar superyarick avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

microsoft-sql-server-2014-instance-stig-baseline's Issues

Default values of attributes should reflect least required privilege

Please review default values assigned to attributes to reflect minimum required permissions

For example allowed_sql_alter_permissions should not include public...

when in doubt i suggest leaving such instance dependent variables empty so as not to allow such situations

  - name: allowed_sql_alter_permissions
    description: 'List of user with permissions -  ALTER ANY SERVER AUDIT, ALTER ANYDATABASE AUDIT, ALTER TRACE; or EXECUTE'
    type: array
    default: [
            'SERVER_AUDIT_MAINTAINERS',
            '##MS_AgentSigningCertificate##',
            'NT AUTHORITY\SYSTEM',
            '##MS_AgentSigningCertificate##',
            '##MS_PolicyEventProcessingLogin##',
            'public']

Warnings during the run--V-67929 and several others

Lot of warnings are generated during inspec run with the current defenition of query_audits in V-67929

W, [2018-11-21T01:53:22.904812 #73824]  WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#class defined in Kernel. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
  query_audits = %(
    SELECT * FROM sys.server_audit_specification_details WHERE audit_action_name IN
  (
  'DATABASE_OBJECT_OWNERSHIP_CHANGE_GROUP',
  'DATABASE_OBJECT_PERMISSION_CHANGE_GROUP',
  'DATABASE_OWNERSHIP_CHANGE_GROUP',
  'DATABASE_PERMISSION_CHANGE_GROUP',
  'DATABASE_ROLE_MEMBER_CHANGE_GROUP',
  'SCHEMA_OBJECT_OWNERSHIP_CHANGE_GROUP',
  'SCHEMA_OBJECT_PERMISSION_CHANGE_GROUP',
  'SERVER_OBJECT_OWNERSHIP_CHANGE_GROUP',
  'SERVER_OBJECT_PERMISSION_CHANGE_GROUP',
  'SERVER_PERMISSION_CHANGE_GROUP',
  'SERVER_ROLE_MEMBER_CHANGE_GROUP',
  'SCHEMA_OBJECT_ACCESS_GROUP'
  );
  )

Consider updating as show below

  query_audits = %(
    SELECT audited_result FROM sys.server_audit_specification_details WHERE audit_action_name IN
  (
  'DATABASE_OBJECT_OWNERSHIP_CHANGE_GROUP',
  'DATABASE_OBJECT_PERMISSION_CHANGE_GROUP',
  'DATABASE_OWNERSHIP_CHANGE_GROUP',
  'DATABASE_PERMISSION_CHANGE_GROUP',
  'DATABASE_ROLE_MEMBER_CHANGE_GROUP',
  'SCHEMA_OBJECT_OWNERSHIP_CHANGE_GROUP',
  'SCHEMA_OBJECT_PERMISSION_CHANGE_GROUP',
  'SERVER_OBJECT_OWNERSHIP_CHANGE_GROUP',
  'SERVER_OBJECT_PERMISSION_CHANGE_GROUP',
  'SERVER_PERMISSION_CHANGE_GROUP',
  'SERVER_ROLE_MEMBER_CHANGE_GROUP',
  'SCHEMA_OBJECT_ACCESS_GROUP'
  );
  )

Same issue seem to appear in several other controls:

V-67769
V-67771
V-67903
V-67917
V-67919
V-67921
V-67923
V-67925
V-67927
V-67929
V-67931
V-67933
V-67935
V-67937
V-67939

General Fixes

  • Fix typo in V-67879
    nonsecurity - > non-security

  • Add your name to authors on readme

  • Update Usage guidance on Readme

from

$ inspec exec microsoft_sql_2014_server_stig_baseline-t ssh://user@password:example.com --attrs attributes.yml --reporter cli json:output.json

to

$inspec exec microsoft_sql_2014_server_stig_baseline -t winrm://$winhostip --user 'Administrator' --password=Pa55w0rd --attrs attributes.yml --reporter cli json:output.json
  • Remove commented out code in multiple controls

V-67843

Current definition leads to erroneous reporting:

  ×  V-67843: SQL Server must have the Data Quality Services software component
    removed if it is unused. (2 failed)
     ×  Master Data Services is in use should equal true

     expected true
          got false

     ×  List if data quality services is used should be empty
     expected `["----", "-------------"].empty?` to return true, got false
     ✔  File C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Binn\DQSInstaller.exe should not exist

Please update the query as shown below

  query = %(
  SELECT name FROM sys.databases WHERE name in ('DQS_MAIN', 'DQS_PROJECTS', 'DQS_STAGING_DATA');

  )

V-67849 redo

The checks definitions is different from the check text guidance.
Please go through the check text and review the code.

Run `inspec check /path/to/profile`

Use the inspec check module to find profiles that have either no tests defined or have chance of no tests being run ie profile errors

for example when describe statements are defined within a loop
have a guard case for when the loop might not run

  !  ./inspec.yml:0:0: Missing profile summary in inspec.yml
  !  ./controls/V-67905.rb:13: Control V-67905 has no tests defined
  !  ./controls/V-67791.rb:1: Control V-67791 has no tests defined
  !  ./controls/V-67861.rb:13: Control V-67861 has no tests defined
  !  ./controls/V-67901.rb:35: Control V-67901 has no tests defined
  !  ./controls/V-67851.rb:12: Control V-67851 has no tests defined
  !  ./controls/V-67795.rb:18: Control V-67795 has no tests defined
  !  ./controls/V-67767.rb:14: Control V-67767 has no tests defined
  !  ./controls/V-67815.rb:23: Control V-67815 has no tests defined
  !  ./controls/V-67805.rb:14: Control V-67805 has no tests defined
  !  ./controls/V-67859.rb:15: Control V-67859 has no tests defined
  !  ./controls/V-67789.rb:1: Control V-67789 has no tests defined
  !  ./controls/V-67797.rb:15: Control V-67797 has no tests defined
  !  ./controls/V-67863.rb:34: Control V-67863 has no tests defined
  !  ./controls/V-67793.rb:1: Control V-67793 has no tests defined
  !  ./controls/V-67803.rb:12: Control V-67803 has no tests defined

General update suggestions using example V-67759

  get_accounts = command("Invoke-Sqlcmd -Query \"SELECT name FROM sys.sql_logins WHERE type_desc = 'SQL_LOGIN' AND is_disabled = 0;\" -ServerInstance '#{SERVER_INSTANCE}'").stdout.strip.split("\n")
  get_accounts.each do | account|  
    a = account.strip
    describe "#{a}" do
      it { should be_in SQL_MANAGED_ACCOUNTS }
    end  
  end if get_accounts != [] >>>> redundant

  describe "There are no sql managed accounts, control not applicable" do
    skip "There are no sql managed accounts, control not applicable"
  end if get_accounts == []

suggested implementation:

  query = %(
    SELECT
        name
    FROM
        sys.sql_logins
    WHERE
        type_desc = 'SQL_LOGIN'
        AND is_disabled = 0;
  )

 sql_session = mssql_session(user: attribute('user'),
                              password: attribute('password'),
                              host: attribute('host'),
                              instance: attribute('instance'),
                              port: attribute('port'),
                              db_name: attribute('db_name'))

 account_list = sql_session.query(query).column('name')

  if account_list.empty?
    impact 0.0
    desc 'There are no sql managed accounts, control not applicable'

    describe "There are no sql managed accounts, control not applicable" do
      skip "There are no sql managed accounts, control not applicable"
    end
  else
    account_list.each do |account|
      describe "sql managed account: #{account}" do
        subject {account}
        it { should be_in SQL_MANAGED_ACCOUNTS }
      end
    end
  end

As we talked you will be recoding to use the mssql_session resource ...I have added and example to the above implementation.

Please add the code to check for registry key as specified in a checktext
following query works to get the registry value

EXECUTE  xp_instance_regread 
       N'HKEY_LOCAL_MACHINE',
       N'SOFTWARE\Microsoft\MSSQLServer\\MSSQLServer',
       N'LoginMode';

Move attribute definitions to inspec.yml as per the new style

Profile Attributes

Attributes are frequently used to parameterize a profile for use in different environments or targets. It can also be used define secrets, such as user names and passwords, that should not otherwise be stored in plain-text in a cookbook. Attributes may be set for the whole profile in the inspec.yml.

Attributes may contain the following options:

  • Use default to set a default value for the attribute.
  • Use type to restrict an attribute to a specific type (any, string, numeric, array, hash, boolean, regex).
  • Use required to mandate the attribute has a default value or a value from a attribute YAML file.
  • Use description to set a brief description for the attribute.

You can specify attributes in your inspec.yml using the attributes setting. For example, to add a user attribute for your profile:

attributes:
  - name: user
    type: string
    default: bob

Example of adding a array object of servers:

attributes:
  - name: servers
    type: array
    default:
      - server1
      - server2
      - server3

To access an attribute you will use the attribute keyword. You can use this anywhere in your control code.

For example:

current_user = attribute('user')

control 'system-users' do
  describe attribute('user') do
    it { should eq 'bob' }
  end

  describe current_user do
    it { should eq attribute('user') }
  end
end

For sensitive data it is recomended to use a secrets YAML file located on the local machine to populate the values of attributes. A secrets file will always overwrite a attributes default value. To use the secrets file run inspec exec and specify the path to that Yaml file using the --attrs attribute.

V-67855 redundant code

  query_sa = %(
    SELECT * FROM sys.sql_logins WHERE [name] = 'sa';
  )

  query_sa2 = %(
   SELECT * FROM sys.sql_logins WHERE [name] = 'SA';
  )

profile name

Keeping in line with the STIGs, shouldn't this refer to:

Microsoft SQL Server 2014 Instance?

Please use service resource to find services

Affected Controls:
V-67825
V-67827
V-67829
V-67831
V-67833
V-67835

example:

describe service('CryptSvc') do
  it { should be_installed }
end

https://www.inspec.io/docs/reference/resources/service/

describe service('clamd') do
  it { should_not be_enabled }
  it { should_not be_installed }
  it { should_not be_running }
end

incorrect control logic V-67897

The control logic for V-67897 is incorrectly checking whether ntp is using an authorized time server. The second describe block should be moved into an if block based on the ntp type

Inspec Results Jsons

From generic instances of these products only please place “unhardened” and “hardened” jsons in a folder called “sample_evaluations” at the top of the profile directory

@ejaronne

Incorrect array check used

Affected controls:
V-67757.rb
V-67769.rb
V-67771.rb
V-67773.rb
V-67775.rb
V-67777.rb
V-67779.rb
V-67781.rb

Be logic below should_not eq ''"will not check if the array is empty

    describe 'Audited Result for Defined Audit Actions' do
        subject { sql_session.query(query).column('name').uniq }
        it { should_not eq '' }
    end

it will return true because [] does not eq ""

test case:

    describe 'Audited Result for Defined Audit Actions' do
        subject { [] }
        it { should_not eq ''" } # this will return true
    end

Please use the be_empty matcher as below

    describe 'Audited Result for Defined Audit Actions' do
        subject { sql_session.query(query).column('name').uniq }
        it { should_not be_empty }
    end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.