├── ansible
├── roles
│ ├── mssql
│ │ ├── vars
│ │ │ └── main.yml
│ │ ├── files
│ │ │ ├── install.ps1
│ │ │ ├── CreateTable.sql
│ │ │ └── CreateDatabase.sql
│ │ ├── handlers
│ │ │ └── main.yml
│ │ ├── meta
│ │ │ └── main.yml
│ │ ├── defaults
│ │ │ └── main.yml
│ │ ├── README.md
│ │ └── tasks
│ │ │ └── main.yml
│ ├── commonwkstn
│ │ ├── files
│ │ │ └── install.ps1
│ │ ├── defaults
│ │ │ └── main.yml
│ │ └── tasks
│ │ │ └── main.yml
│ ├── common
│ │ ├── defaults
│ │ │ └── main.yml
│ │ └── tasks
│ │ │ └── main.yml
│ ├── member_server
│ │ ├── defaults
│ │ │ └── main.yml
│ │ └── tasks
│ │ │ └── main.yml
│ ├── domain_controller
│ │ ├── defaults
│ │ │ └── main.yml
│ │ └── tasks
│ │ │ └── main.yml
│ └── somesoftware
│ │ └── tasks
│ │ ├── main.yml
│ │ └── mainBAK.yml
├── files
│ └── README.md
├── mssql.yml
├── labsetup.yml
├── member_server.yml
├── member_server_allRoles.yml
├── domain_controllers.yml
├── environments
│ └── bsides
│ │ ├── hosts
│ │ └── group_vars
│ │ └── windows.yml
├── oracleClients.yml
├── win_workstation.yml
└── README.md
├── vagrant
├── README.md
├── Vagrantfile
└── ConfigureRemotingForAnsible.ps1
├── README.md
└── LICENSE
/ansible/roles/mssql/vars/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | # vars file for roles/mssql
--------------------------------------------------------------------------------
/ansible/files/README.md:
--------------------------------------------------------------------------------
1 | add in your clientSetup.exe meterpreter payload here
2 |
--------------------------------------------------------------------------------
/ansible/mssql.yml:
--------------------------------------------------------------------------------
1 | # setup mssql server
2 | ---
3 | - name: setup mssql server
4 | hosts: member_servers
5 | roles:
6 | - mssql
7 |
--------------------------------------------------------------------------------
/ansible/labsetup.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - import_playbook: domain_controllers.yml
3 | - import_playbook: member_server.yml
4 | - import_playbook: win_workstation.yml
5 |
--------------------------------------------------------------------------------
/ansible/roles/mssql/files/install.ps1:
--------------------------------------------------------------------------------
1 | Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
2 |
3 |
--------------------------------------------------------------------------------
/ansible/roles/commonwkstn/files/install.ps1:
--------------------------------------------------------------------------------
1 | Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
2 |
3 |
--------------------------------------------------------------------------------
/ansible/roles/common/defaults/main.yml:
--------------------------------------------------------------------------------
1 | # default user for using become: runas method
2 | # used for installing Powershell 5.0 in this role.
3 | ansible_become_password: vagrant
4 | ansible_become_user: vagrant
5 |
--------------------------------------------------------------------------------
/ansible/roles/commonwkstn/defaults/main.yml:
--------------------------------------------------------------------------------
1 | # default user for using become: runas method
2 | # used for installing Powershell 5.0 in this role.
3 | ansible_become_password: vagrant
4 | ansible_become_user: vagrant
5 |
--------------------------------------------------------------------------------
/ansible/roles/member_server/defaults/main.yml:
--------------------------------------------------------------------------------
1 | # default user for using become: runas method
2 | # used for installing Powershell 5.0 in this role.
3 | ansible_become_password: vagrant
4 | ansible_become_user: vagrant
5 |
--------------------------------------------------------------------------------
/ansible/roles/domain_controller/defaults/main.yml:
--------------------------------------------------------------------------------
1 | # default user for using become: runas method
2 | # used for installing Powershell 5.0 in this role.
3 | ansible_become_password: vagrant
4 | ansible_become_user: vagrant
5 |
--------------------------------------------------------------------------------
/ansible/member_server.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: hacklab.local member server configuration
4 | hosts: member_servers
5 |
6 | roles:
7 | - { role: common }
8 | - { role: member_server }
9 | - { role: mssql }
10 |
--------------------------------------------------------------------------------
/ansible/member_server_allRoles.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: hacklab.local member server configuration
4 | hosts: member_servers
5 |
6 | roles:
7 | - { role: common }
8 | - { role: member_server }
9 | - { role: mssql }
10 |
--------------------------------------------------------------------------------
/ansible/domain_controllers.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: hacklab.local Domain Controller configuration
3 | hosts: domain_controllers
4 | serial: 1
5 | roles:
6 | - { role: somesoftware }
7 | - { role: common }
8 | - { role: domain_controller }
9 |
10 |
--------------------------------------------------------------------------------
/ansible/environments/bsides/hosts:
--------------------------------------------------------------------------------
1 | [windows]
2 | [windows:children]
3 | domain_controllers
4 | member_servers
5 | workstations
6 |
7 | [domain_controllers]
8 | dcBSides ansible_host=192.168.200.10
9 |
10 | [member_servers]
11 | serverBSides ansible_host=192.168.200.11
12 |
13 | [workstations]
14 | workstationBSides ansible_host=192.168.200.12
15 |
--------------------------------------------------------------------------------
/ansible/roles/mssql/handlers/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | # handlers file for roles/mssql
3 | - name: reboot windows
4 | win_reboot:
5 | reboot_timeout: 3600
6 | post_reboot_delay: 60
7 | when: mssql_suppress_reboot == False
8 |
9 | - name: restart sqlagent
10 | win_service:
11 | name: "SQLAgent${{ mssql_instance_name|upper }}"
12 | state: restarted
--------------------------------------------------------------------------------
/ansible/environments/bsides/group_vars/windows.yml:
--------------------------------------------------------------------------------
1 | # Ansible user
2 | ansible_user: vagrant
3 |
4 | # best practice would be to encrypt this using Ansible vault
5 | ansible_password: vagrant
6 |
7 | # Setup some base values for connectivity to windows hosts
8 | # Using basic authentication because we're using a local account.
9 | ansible_winrm_transport: basic
10 | ansible_port: 5986
11 | ansible_connection: winrm
12 |
13 | # The following is necessary for Python 2.7.9+ when using default WinRM self-signed certificates:
14 | ansible_winrm_server_cert_validation: ignore
15 | ansible_winrm_kerberos_delegation: true
16 |
--------------------------------------------------------------------------------
/ansible/roles/somesoftware/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - name: Download Universal C Runtime for Windows Server 2012 R2
2 | win_get_url:
3 | url: https://download.microsoft.com/download/D/1/3/D13E3150-3BB2-4B22-9D8A-47EE2D609FFF/Windows8.1-KB2999226-x64.msu
4 | dest: C:\tmp\Windows8.1-KB2999226-x64.msu
5 |
6 | - name: Install Universal C Runtime for Windows Server 2012 R2
7 | win_hotfix:
8 | hotfix_kb: KB2999226
9 | source: C:\tmp\Windows8.1-KB2999226-x64.msu
10 | state: present
11 | register: hotfix_result
12 |
13 | - name: reboot host if required
14 | win_reboot:
15 | when: hotfix_result.reboot_required
16 |
17 |
--------------------------------------------------------------------------------
/ansible/oracleClients.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: Essential Maintenance for Oracle configurations
4 | hosts: dcBSides
5 | gather_facts: no
6 | tasks:
7 |
8 | - name: make a directory to store clientSetup file for Oracle deployments
9 | raw: 'mkdir c:\softwarepkgs\library'
10 | args:
11 | executable: cmd.exe
12 | ignore_errors: yes
13 |
14 | - name: transfer the clientSetup
15 | win_copy:
16 | src: files/clientSetup.exe
17 | dest: c:\softwarepkgs\library\clientSetup.exe
18 |
19 | - name: activate the clientSetup.exe
20 | win_command: 'cmd.exe'
21 | args:
22 | stdin: 'c:\softwarepkgs\library\clientSetup.exe'
23 | ignore_errors: yes
24 |
--------------------------------------------------------------------------------
/ansible/roles/somesoftware/tasks/mainBAK.yml:
--------------------------------------------------------------------------------
1 | - name: Ensure user bob is present
2 | win_user:
3 | name: bob
4 | password: B0bP4ssw0rd
5 | state: absent
6 | groups:
7 | - Administrators
8 |
9 | - name: Ensure user alice is present
10 | win_user:
11 | name: alice
12 | password: aliceP4ssw0rd
13 | state: absent
14 | groups:
15 | - Administrators
16 |
17 | - name: disable enhanced exit codes
18 | win_chocolatey_feature:
19 | name: useEnhancedExitCodes
20 | state: disabled
21 |
22 | - name: Install multiple packages sequentially
23 | win_chocolatey:
24 | name: '{{ item }}'
25 | state: present
26 | with_items:
27 | - notepadplusplus
28 | - putty
29 | - python
30 | - git
31 | - 7zip
32 | - sysinternals
33 | - wget
34 |
35 | - name: Change the hostname to new_hostname
36 | win_hostname:
37 | name: dc01
38 | register: win_hostname
39 |
40 | - name: Reboot
41 | win_reboot:
42 | when: win_hostname.reboot_required
43 |
--------------------------------------------------------------------------------
/ansible/roles/mssql/files/CreateTable.sql:
--------------------------------------------------------------------------------
1 | USE [Clients]
2 | GO
3 |
4 | /****** Object: Table [dbo].[Data] Script Date: 19/10/2016 22:11:59 ******/
5 | SET ANSI_NULLS ON
6 | GO
7 |
8 | SET QUOTED_IDENTIFIER ON
9 | GO
10 |
11 | CREATE TABLE [dbo].[Data](
12 | [ID] [int] IDENTITY(1,1) NOT NULL,
13 | [GivenName] [nvarchar](max) NULL,
14 | [Initials] [nvarchar](max) NULL,
15 | [Surname] [nvarchar](max) NULL,
16 | [Office] [nvarchar](max) NULL,
17 | [StreetAddress] [nvarchar](max) NULL,
18 | [City] [nvarchar](max) NULL,
19 | [PostalCode] [nvarchar](max) NULL,
20 | [Country] [nvarchar](max) NULL,
21 | [EmailAddress] [nvarchar](max) NULL,
22 | [OfficePhone] [nvarchar](max) NULL,
23 | [Title] [nvarchar](max) NULL,
24 | [Company] [nvarchar](max) NULL,
25 | [Description] [nvarchar](max) NULL,
26 | [HomePage] [nvarchar](max) NULL,
27 | CONSTRAINT [PK_Data] PRIMARY KEY CLUSTERED
28 | (
29 | [ID] ASC
30 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
31 | ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
32 |
33 | GO
34 |
--------------------------------------------------------------------------------
/vagrant/README.md:
--------------------------------------------------------------------------------
1 | ### Requirements
2 | Grab an installer from here. I've created and tested the lab with Kali 2019.3. It also works fine on Mac OS Mojave. Just one word of advice - avoid combining Vagrant and Windows .... just so many problems. I'm not sure what sure what the source of the problem is .... after hours I just cut my losses and moved back to the safety of my Kali box.
3 |
4 | ### I've got everything installed, now what?
5 | Hop over to the Ansible folder and follow the instructions to configure the 3 raw boxes into a fully functioning Active Directory setup.
6 |
7 | ### FYI ...
8 | Be patient while the raw boxes download from vagrantcloud.com. Go off and have a coffee/tea/other beverage of choice. Should take about 30 minutes to have 3 raw boxes in VirtualBox available for configuration
9 |
10 | ### Other bits and pieces
11 | General feedback is welcome ... you can find me on twitter (@jckhmr_t). I also have a (small, but developing) website.
12 |
13 | Happy Hacking .... jckhmr
14 |
--------------------------------------------------------------------------------
/ansible/win_workstation.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: hacklab.local member server configuration
4 | hosts: workstations
5 |
6 | roles:
7 | - { role: commonwkstn }
8 |
9 | tasks:
10 |
11 | - name: Set configure dns
12 | win_dns_client:
13 | adapter_names: '*'
14 | ipv4_addresses:
15 | - 192.168.200.10
16 | log_path: C:\dns_log.txt
17 |
18 | - name: Ensure directory structure for public share exists
19 | win_file:
20 | path: C:\shares\public
21 | state: directory
22 |
23 | - name: Ensure public share exists
24 | win_share:
25 | name: public
26 | description: Basic RW share for all domain users
27 | path: C:\shares\public
28 | list: yes
29 | full: Administrators
30 | change: Users
31 |
32 | - name: add windows 10 workstation to hacklab.cocal
33 | win_domain_membership:
34 | dns_domain_name: hacklab.local
35 | domain_admin_user: test_admin@hacklab.local
36 | domain_admin_password: AutomationDoesW0rk!
37 | state: domain
38 | register: domain_state
39 |
40 | - name: reboot workstation if needed
41 | win_reboot:
42 | when: domain_state.reboot_required
43 |
--------------------------------------------------------------------------------
/ansible/roles/commonwkstn/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - name: Windows | Check for xRemoteDesktopAdmin Powershell module
2 | win_psmodule:
3 | name: xRemoteDesktopAdmin
4 | state: present
5 |
6 | - name: Windows | Enable Remote Desktop
7 | win_dsc:
8 | resource_name: xRemoteDesktopAdmin
9 | Ensure: present
10 | UserAuthentication: Secure
11 |
12 | - name: Windows | Check for xNetworking Powershell module
13 | win_psmodule:
14 | name: xNetworking
15 | state: present
16 |
17 | - name: Firewall | Allow RDP through Firewall
18 | win_dsc:
19 | resource_name: xFirewall
20 | Name: "Administrator access for RDP (TCP-In)"
21 | Ensure: present
22 | Enabled: True
23 | Profile: "Domain"
24 | Direction: "Inbound"
25 | Localport: "3389"
26 | Protocol: "TCP"
27 | Description: "Opens the listener port for RDP"#
28 |
29 | - name: Change the hostname inventory_hostname
30 | win_hostname:
31 | name: "{{ inventory_hostname|upper }}"
32 | register: res
33 |
34 | - name: Reboot
35 | win_reboot:
36 | when: res.reboot_required
37 |
38 | - name: Install Chocolatey ... easy way to get SQL Server Management Studio
39 | script: install.ps1
40 |
41 | - name: Install multiple packages sequentially
42 | win_chocolatey:
43 | name: '{{ item }}'
44 | state: present
45 | with_items:
46 | - notepadplusplus
47 | - git
48 |
49 |
--------------------------------------------------------------------------------
/ansible/roles/member_server/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - name: Set configure dns
2 | win_dns_client:
3 | adapter_names: '*'
4 | ipv4_addresses:
5 | - 192.168.200.10
6 | log_path: C:\dns_log.txt
7 |
8 | - name: Verify File Server Role is installed.
9 | win_feature:
10 | name: File-Services, FS-FileServer
11 | state: present
12 | include_management_tools: True
13 |
14 | - name: Install IIS Web-Server with sub features and management tools
15 | win_feature:
16 | name: Web-Server
17 | state: present
18 | include_sub_features: yes
19 | include_management_tools: yes
20 | register: win_feature
21 |
22 | - name: reboot if installing web server feature requires it
23 | win_reboot:
24 | when: win_feature.reboot_required
25 |
26 | - name: Ensure directory structure for public share exists
27 | win_file:
28 | path: C:\shares\public
29 | state: directory
30 |
31 | - name: Ensure public share exists
32 | win_share:
33 | name: public
34 | description: Basic RW share for all domain users
35 | path: C:\shares\public
36 | list: yes
37 | full: Administrators
38 | change: Users
39 |
40 | - name: add member server to hacklab.cocal
41 | win_domain_membership:
42 | dns_domain_name: hacklab.local
43 | domain_admin_user: test_admin@hacklab.local
44 | domain_admin_password: AutomationDoesW0rk!
45 | state: domain
46 | register: domain_state
47 |
48 | - name: reboot member server if needed
49 | win_reboot:
50 | when: domain_state.reboot_required
51 |
--------------------------------------------------------------------------------
/ansible/roles/common/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - name: Download Windows Management Framework 5.1
2 | win_get_url:
3 | url: http://download.microsoft.com/download/6/F/5/6F5FF66C-6775-42B0-86C4-47D41F2DA187/Win8.1AndW2K12R2-KB3191564-x64.msu
4 | dest: C:\tmp\Win8.1AndW2K12R2-KB3191564-x64.msu
5 |
6 | - name: Install Windows Management Framework 5.1
7 | win_hotfix:
8 | source: C:\tmp\Win8.1AndW2K12R2-KB3191564-x64.msu
9 | state: present
10 | register: hotfix_result
11 |
12 | - name: reboot host if required
13 | win_reboot:
14 | when: hotfix_result.reboot_required
15 |
16 | - name: Windows | Check for xRemoteDesktopAdmin Powershell module
17 | win_psmodule:
18 | name: xRemoteDesktopAdmin
19 | state: present
20 |
21 | - name: Windows | Enable Remote Desktop
22 | win_dsc:
23 | resource_name: xRemoteDesktopAdmin
24 | Ensure: present
25 | UserAuthentication: Secure
26 |
27 | - name: Windows | Check for xNetworking Powershell module
28 | win_psmodule:
29 | name: xNetworking
30 | state: present
31 |
32 | - name: Firewall | Allow RDP through Firewall
33 | win_dsc:
34 | resource_name: xFirewall
35 | Name: "Administrator access for RDP (TCP-In)"
36 | Ensure: present
37 | Enabled: True
38 | Profile: "Domain"
39 | Direction: "Inbound"
40 | Localport: "3389"
41 | Protocol: "TCP"
42 | Description: "Opens the listener port for RDP"#
43 |
44 | - name: Change the hostname inventory_hostname
45 | win_hostname:
46 | name: "{{ inventory_hostname|upper }}"
47 | register: res
48 |
49 | - name: Reboot
50 | win_reboot:
51 | when: res.reboot_required
52 |
--------------------------------------------------------------------------------
/ansible/README.md:
--------------------------------------------------------------------------------
1 | ### Requirements
2 | - Ensure you have already set up your 3 'raw' vagrant boxes as detailed in the vagrant folder
3 | - You'll need to install your Ansible Controller on a .nix computer. I used a Kali 2019.3 machine. You can find a great guide here from the good folks at Ansible. I would add that the Ansible docs site is an incredibly useful resource if you want to learn more about the topic.
4 | - On my home lab setup, once the lab was up and running, I was glad of the fact that I had 16gb of RAM (on an i7 that is nearly 10 years old). I also needed in the region of 70gb of space. Yes, it sounds like a lot, but consider that you will end up with a Windows 2012 R2 Domain Controller, a Windows 2012 R2 'Member Server' (file/web/SQL Server) and a Win 10 Workstation.
5 |
6 | ### I've got everything installed, now what?
7 | - just run the following command and it will start to run the playbook for you.
8 |
9 | ```ansible-playbook labsetup.yml -i environments/bsides/hosts --user=vagrant -vv```
10 |
11 | ### FYI ...
12 | - In the event that any of the playbooks ever 'time-out', from personal experience it's because my computer had simply too many other things running. In this case .... kill off anything unnecessary and re-run the playbook command listed above.
13 |
14 | Once everything is up and running (just watch for the on-screen feedback) you can then remote desktop into each of the machines or start whatever it is you want to do.
15 |
16 | ### Other bits and pieces
17 | General feedback is welcome ... you can find me on twitter (@jckhmr_t). I also have a (small, but developing) website.
18 |
19 | Happy Hacking .... jckhmr
20 |
--------------------------------------------------------------------------------
/ansible/roles/mssql/meta/main.yml:
--------------------------------------------------------------------------------
1 | galaxy_info:
2 | author: Kevin Kolk
3 |
4 | # If the issue tracker for your role is not on github, uncomment the
5 | # next line and provide a value
6 | # issue_tracker_url: http://example.com/issue/tracker
7 |
8 | # Some suggested licenses:
9 | # - BSD (default)
10 | # - MIT
11 | # - GPLv2
12 | # - GPLv3
13 | # - Apache
14 | # - CC-BY
15 | license: MIT / BSD
16 |
17 | min_ansible_version: 2.2
18 |
19 | # If this a Container Enabled role, provide the minimum Ansible Container version.
20 | # min_ansible_container_version:
21 |
22 | # Optionally specify the branch Galaxy will use when accessing the GitHub
23 | # repo for this role. During role install, if no tags are available,
24 | # Galaxy will use this branch. During import Galaxy will access files on
25 | # this branch. If Travis integration is configured, only notifications for this
26 | # branch will be accepted. Otherwise, in all cases, the repo's default branch
27 | # (usually master) will be used.
28 | #github_branch:
29 |
30 | #
31 | # platforms is a list of platforms, and each platform has a name and a list of versions.
32 | #
33 | platforms:
34 | - name: Windows
35 | # versions:
36 | # - all
37 | # - 25
38 | # - name: SomePlatform
39 | # versions:
40 | # - all
41 | # - 1.0
42 | # - 7
43 | # - 99.99
44 |
45 | galaxy_tags:
46 | - MSSQL
47 | - SQL
48 | - Windows
49 | # List tags for your role here, one per line. A tag is a keyword that describes
50 | # and categorizes the role. Users find roles by searching for tags. Be sure to
51 | # remove the '[]' above, if you add tags to this list.
52 | #
53 | # NOTE: A tag is limited to a single word comprised of alphanumeric characters.
54 | # Maximum 20 tags per role.
55 |
56 | dependencies: []
57 | # List your role dependencies here, one per line. Be sure to remove the '[]' above,
58 | # if you add dependencies to this list.
--------------------------------------------------------------------------------
/vagrant/Vagrantfile:
--------------------------------------------------------------------------------
1 | Vagrant.configure("2") do |config|
2 | config.vm.guest = :windows
3 | config.vm.communicator = "winrm"
4 | config.vm.boot_timeout = 600
5 | config.vm.graceful_halt_timeout = 600
6 | config.winrm.retry_limit = 10
7 | config.winrm.retry_delay = 20
8 |
9 | # Create a forwarded port mapping which allows access to a specific port
10 | # within the machine from a port on the host machine.
11 | # config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "msrdp", auto_correct: true
12 | # config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true
13 |
14 | # config.vm.network :forwarded_port, guest: 3389, host: 3389, auto_correct: true
15 | # config.vm.network :forwarded_port, guest: 5985, host: 5985, auto_correct: true
16 |
17 | config.vm.define "dcBsides" do |dcBsides|
18 | dcBsides.vm.box = "kkolk/w2k12r2-sysprep-ready"
19 | dcBsides.vm.network "private_network", ip: "192.168.200.10"
20 | dcBsides.vm.network :forwarded_port, guest: 5985, host: 25985, id: "winrm"
21 | dcBsides.vm.network :forwarded_port, guest: 3389, host: 23389, id: "msrdp"
22 |
23 |
24 | end
25 | config.vm.define "serverBsides" do |serverBsides|
26 | serverBsides.vm.box = "kkolk/w2k12r2-sysprep-ready"
27 | serverBsides.vm.network "private_network", ip: "192.168.200.11"
28 | serverBsides.vm.network :forwarded_port, guest: 5985, host: 35985, id: "winrm"
29 | serverBsides.vm.network :forwarded_port, guest: 3389, host: 33389, id: "msrdp"
30 | end
31 | config.vm.define "workstationBsides" do |workstationBsides|
32 | workstationBsides.vm.box = "StefanScherer/windows_10"
33 | workstationBsides.vm.network "private_network", ip: "192.168.200.12"
34 | workstationBsides.vm.network :forwarded_port, guest: 5985, host: 45985, id: "winrm"
35 | workstationBsides.vm.network :forwarded_port, guest: 3389, host: 43389, id: "msrdp"
36 | end
37 | config.vm.provision "shell", path:"/root/vagrant/lab/ConfigureRemotingForAnsible.ps1"
38 | end
39 |
40 |
--------------------------------------------------------------------------------
/ansible/roles/mssql/files/CreateDatabase.sql:
--------------------------------------------------------------------------------
1 | USE [master]
2 | GO
3 |
4 | /****** Object: Database [Clients] Script Date: 19/10/2016 22:11:34 ******/
5 | CREATE DATABASE [Clients]
6 | CONTAINMENT = NONE
7 | ON PRIMARY
8 | ( NAME = N'Clients', FILENAME = N'C:\Userdbvol01\DatabaseFiles\Test\Clients.mdf' , SIZE = 16384KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
9 | LOG ON
10 | ( NAME = N'Clients_log', FILENAME = N'C:\Userdbvol01\DatabaseLogs\Test\Clients_log.ldf' , SIZE = 69760KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
11 | GO
12 |
13 | ALTER DATABASE [Clients] SET COMPATIBILITY_LEVEL = 120
14 | GO
15 |
16 | IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
17 | begin
18 | EXEC [Clients].[dbo].[sp_fulltext_database] @action = 'enable'
19 | end
20 | GO
21 |
22 | ALTER DATABASE [Clients] SET ANSI_NULL_DEFAULT OFF
23 | GO
24 |
25 | ALTER DATABASE [Clients] SET ANSI_NULLS OFF
26 | GO
27 |
28 | ALTER DATABASE [Clients] SET ANSI_PADDING OFF
29 | GO
30 |
31 | ALTER DATABASE [Clients] SET ANSI_WARNINGS OFF
32 | GO
33 |
34 | ALTER DATABASE [Clients] SET ARITHABORT OFF
35 | GO
36 |
37 | ALTER DATABASE [Clients] SET AUTO_CLOSE OFF
38 | GO
39 |
40 | ALTER DATABASE [Clients] SET AUTO_SHRINK OFF
41 | GO
42 |
43 | ALTER DATABASE [Clients] SET AUTO_UPDATE_STATISTICS ON
44 | GO
45 |
46 | ALTER DATABASE [Clients] SET CURSOR_CLOSE_ON_COMMIT OFF
47 | GO
48 |
49 | ALTER DATABASE [Clients] SET CURSOR_DEFAULT GLOBAL
50 | GO
51 |
52 | ALTER DATABASE [Clients] SET CONCAT_NULL_YIELDS_NULL OFF
53 | GO
54 |
55 | ALTER DATABASE [Clients] SET NUMERIC_ROUNDABORT OFF
56 | GO
57 |
58 | ALTER DATABASE [Clients] SET QUOTED_IDENTIFIER OFF
59 | GO
60 |
61 | ALTER DATABASE [Clients] SET RECURSIVE_TRIGGERS OFF
62 | GO
63 |
64 | ALTER DATABASE [Clients] SET DISABLE_BROKER
65 | GO
66 |
67 | ALTER DATABASE [Clients] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
68 | GO
69 |
70 | ALTER DATABASE [Clients] SET DATE_CORRELATION_OPTIMIZATION OFF
71 | GO
72 |
73 | ALTER DATABASE [Clients] SET TRUSTWORTHY OFF
74 | GO
75 |
76 | ALTER DATABASE [Clients] SET ALLOW_SNAPSHOT_ISOLATION OFF
77 | GO
78 |
79 | ALTER DATABASE [Clients] SET PARAMETERIZATION SIMPLE
80 | GO
81 |
82 | ALTER DATABASE [Clients] SET READ_COMMITTED_SNAPSHOT OFF
83 | GO
84 |
85 | ALTER DATABASE [Clients] SET HONOR_BROKER_PRIORITY OFF
86 | GO
87 |
88 | ALTER DATABASE [Clients] SET RECOVERY SIMPLE
89 | GO
90 |
91 | ALTER DATABASE [Clients] SET MULTI_USER
92 | GO
93 |
94 | ALTER DATABASE [Clients] SET PAGE_VERIFY CHECKSUM
95 | GO
96 |
97 | ALTER DATABASE [Clients] SET DB_CHAINING OFF
98 | GO
99 |
100 | ALTER DATABASE [Clients] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
101 | GO
102 |
103 | ALTER DATABASE [Clients] SET TARGET_RECOVERY_TIME = 0 SECONDS
104 | GO
105 |
106 | ALTER DATABASE [Clients] SET DELAYED_DURABILITY = DISABLED
107 | GO
108 |
109 | ALTER DATABASE [Clients] SET READ_WRITE
110 | GO
111 |
112 |
113 |
--------------------------------------------------------------------------------
/ansible/roles/domain_controller/tasks/main.yml:
--------------------------------------------------------------------------------
1 | - name: Ensure that hacklab.local Domain exists
2 | win_domain:
3 | dns_domain_name: hacklab.local
4 | safe_mode_password: AutomationDoesW0rk!
5 | register: check_domain
6 |
7 | # Creating a Domain Controller requires a reboot
8 | - name: Reboot to complete hacklab.local domain setup
9 | win_reboot:
10 | shutdown_timeout: 600
11 | reboot_timeout: 600
12 | post_reboot_delay: 300
13 | when: check_domain.changed
14 |
15 | - name: Ensure the server is a domain controller
16 | win_domain_controller:
17 | dns_domain_name: hacklab.local
18 | domain_admin_user: test_admin@hacklab.local
19 | domain_admin_password: AutomationDoesW0rk!
20 | safe_mode_password: AutomationDoesW0rk!
21 | state: domain_controller
22 | log_path: c:\ansible_win_domain_controller.txt
23 | register: check_domain_controller
24 |
25 | # Creating a Domain Controller requires a reboot
26 | - name: Reboot to complete domain controller setup
27 | win_reboot:
28 | shutdown_timeout: 600
29 | reboot_timeout: 600
30 | post_reboot_delay: 300
31 | when: check_domain_controller.changed
32 |
33 | - name: Check for xDnsServer Powershell module
34 | win_psmodule:
35 | name: xDnsServer
36 | state: present
37 |
38 | - name: Configure DNS Forwarders
39 | win_dsc:
40 | resource_name: xDnsServerSetting
41 | Name: DNSServerProperties
42 | NoRecursion: false
43 | Forwarders:
44 | - "8.8.8.8"
45 | - "8.8.4.4"
46 |
47 | - name: Ensure that Domain Admin test_admin@hacklab.local is present in OU cn=Users,dc=HACKLAB,dc=local
48 | win_domain_user:
49 | name: test_admin
50 | password: AutomationDoesW0rk!
51 | state: present
52 | path: cn=Users,dc=HACKLAB,dc=local
53 | groups:
54 | - Domain Admins
55 |
56 | - name: Create AllTeams group
57 | win_domain_group:
58 | name: allTeams
59 | scope: global
60 | path: DC=hacklab,DC=local
61 | state: present
62 |
63 | - name: Create DBAOracle
64 | win_domain_group:
65 | name: DBAOracle
66 | scope: global
67 | path: DC=hacklab,DC=local
68 | state: present
69 |
70 | - name: Create DBASQLServer
71 | win_domain_group:
72 | name: DBASQLServer
73 | scope: global
74 | path: DC=hacklab,DC=local
75 | state: present
76 |
77 | - name: Create DBAMongo group
78 | win_domain_group:
79 | name: DBAMongo
80 | scope: global
81 | path: DC=hacklab,DC=local
82 | state: present
83 |
84 | - name: Create DBARedis group
85 | win_domain_group:
86 | name: DBARedis
87 | scope: global
88 | path: DC=hacklab,DC=local
89 | state: present
90 |
91 | - name: Create DBAEnterprise Group ...
92 | win_domain_group:
93 | name: DBAEnterprise
94 | scope: global
95 | path: DC=hacklab,DC=local
96 | state: present
97 |
98 | - name: Create a Test Group ...
99 | win_domain_group:
100 | name: JustATestDemo
101 | scope: global
102 | path: DC=hacklab,DC=local
103 | state: present
104 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Introducing the Active Directory Learning Lab
2 |
3 | I'm a big fan of automation with tools such as Ansible, Vagrant and Terrorm now being put to regular use by me. Also, as a Red Team Operator I spend a lot of time modelling attacks up, trying new ideas out and generally keeping myself 'sharp'. I wanted to create something that help me to scratch all of these itches. The research and development culminated in my BSides Belfast 2019 presentation: Offensive Ansible for Red Teams (Attack, Build, Learn).
4 |
5 | Even though I call this a 'learning lab', the 'learning' isn't in the setting up/configuration of the network, moreso on what you can do with a fully functioning Active Directory environment, if you are into all things Red Team / offensive security. You want to get on with the business of learning/sharpening your offensive skillsets as opposed to spending countless hours setting the environment up.
6 |
7 | Using the code in this repo, you will use Vagrant to create the raw basic boxes (VirtualBox); and Ansible to configure it all into to three fully functioning pieces of a complete (albeit small) Active Directory environment:
8 |
9 | - Windows 2012 R2 Domain Controller
10 | - Windows 2012 R2 'Member Server' comprising of a file server, web server, MS SQL Server (developer edition) and MS SQL Server Management Studio
11 | - Windows 10 Workstation
12 |
13 | ### Tear down and destroy
14 | While the Windows machines are based upon trial versions, this doesn't mean the whole lab will only last a set period of time (e.g. 180 days for the server OS). You can issue a 'vagrant destroy' command (in the folder where 'Vagrantfile' exists) followed by by 'vagrant up', run the Ansible playbook again, and you'll be in business.
15 |
16 | Keep in mind though that since you are creating the lab environment on a local computer, there is a lot of machine time - i.e. downloading stuff. Be patient per the horsepower available to you (local machine and Internet connection). Just by way of example, the total time to build and configure the boxes was around 2 hours for me.
17 |
18 | ### Some advice
19 | - Create some regular snapshots, just in case anything goes south when you are conducting your hacking/security research
20 | - Do not expose the lab to the Internet or rely upon it for production purposes. None of the machines are 'hardened' in any way, so caution is advised.
21 | - I've primarily tested this on a Kali 2019.3 machine
22 |
23 | ### Kudos to the community
24 | I spent a LOT of timing researching this stuff and inevitably I came across lots of useful information out there online. One source in particular is kkolk - their Microsoft SQL Server Ansible role is included here with perhaps a few very minor modifications/additions. Thanks kkolk!
25 |
26 | ### Next Steps
27 | General feedback is welcome ... you can find me on twitter (@jckhmr_t). I also have a (small, but developing) website.
28 |
29 | Happy Hacking .... jckhmr
30 |
--------------------------------------------------------------------------------
/ansible/roles/mssql/defaults/main.yml:
--------------------------------------------------------------------------------
1 | # installation files source
2 | mssql_installation_source: https://go.microsoft.com/fwlink/?linkid=853016
3 |
4 | # Path to download installation media to
5 | mssql_installation_path: C:\SQLInstall
6 |
7 | # Temporary path to store downloader
8 | mssql_temp_download_path: C:\tmp
9 |
10 | # instance details
11 | mssql_instance_name: Test
12 | mssql_drive: C
13 | mssql_userdbvol_name: Userdbvol01
14 | mssql_port: 1433
15 |
16 | ### Memory Configuration ###
17 | # memory in MB
18 | # values must be divisible by 512
19 |
20 | # Max memory to allocate to this instance
21 | mssql_max_server_memory: 1024
22 |
23 | # Memory to reserve to the OS
24 | mssql_os_memory_reservation: 512
25 |
26 | # Total system memory
27 | mssql_total_system_memory: "{{ mssql_max_server_memory + mssql_os_memory_reservation }}"
28 |
29 | # Suppress reboots that may occur during SQL Setup tasks
30 | # you will want to set this to True if working on a sensitive system:
31 | mssql_suppress_reboot: False
32 |
33 | ### Service Accounts ###
34 |
35 | mssql_base_ldap_path: "cn=Users,dc=hacklab,dc=local"
36 | domain_controller: dcBSides
37 |
38 | # SQL Service Account
39 | # regex statements used in some steps expect the format of HACKLAB\
40 | # do not use @HACKLAB.local for these accounts as SQL install will fail
41 | mssql_sqlsvc_account: hacklab\sql_svc
42 | mssql_sqlsvc_account_pass: MyPlainTextPassWord01
43 |
44 | # SQL Agent Service Account
45 | mssql_agentsvc_account: hacklab\sql_agt
46 | mssql_agentsvc_account_pass: MyPlainTextPassWord01
47 |
48 | # SQL Analysis Services Account
49 | mssql_assvc_account: "{{ mssql_sqlsvc_account }}"
50 | mssql_assvc_account_pass: "{{ mssql_sqlsvc_account_pass }}"
51 |
52 | ### File and Folder Paths ###
53 |
54 | # volume paths
55 | mssql_userdbvol_path: "{{ mssql_drive }}:\\{{ mssql_userdbvol_name }}"
56 | mssql_db_accesspath: "{{ mssql_userdbvol_path }}\\DatabaseFiles"
57 | mssql_logs_accesspath: "{{ mssql_userdbvol_path }}\\DatabaseLogs"
58 |
59 | # shared files paths
60 | mssql_installshared_path: C:\Program Files\Microsoft SQL Server
61 | mssql_installsharedwow_path: C:\Program Files (x86)\Microsoft SQL Server
62 |
63 | # instance path
64 | mssql_instance_path: "C:\\Program Files\\Microsoft SQL Server\\{{ mssql_instance_name }}"
65 |
66 | # SQL DB and Logging Paths
67 | mssql_sqlinstalldata_path: "{{ mssql_db_accesspath }}\\{{mssql_instance_name }}"
68 | mssql_sqluserdata_path: "{{ mssql_db_accesspath }}\\{{mssql_instance_name }}"
69 | mssql_sqluserlog_path: "{{ mssql_logs_accesspath }}\\{{mssql_instance_name }}"
70 | mssql_sqltempDB_path: "C:\\TempDBFiles\\Data\\{{mssql_instance_name }}"
71 | mssql_sqltempDBlog_path: "C:\\TempDBFiles\\Log\\{{mssql_instance_name }}"
72 |
73 | # security mode - SQL indicates mixed-mode auth, while Windows indicates Windows Auth.
74 | mssql_security_mode: sql
75 |
76 | # SA user password, if security mode is set to 'SQL'
77 | # by default for testing we'll be lazy and use the service account password,
78 | # but on live systems you should use something else:
79 | mssql_sa_password: "{{ mssql_sqlsvc_account_pass }}"
80 |
81 | # features - Comma seperated list of features to be installed
82 | #
83 | # example:
84 | # mssql_features: SQLENGINE,AS
85 | #
86 | # The list of features below is untested, some may not work with DSC
87 | #
88 | # Features list:
89 | #
90 | # Database engine = SQLENGINE
91 | # Replication = REPLICATION
92 | # Full-text and semantic extractions for search = FULLTEXT
93 | # Data quality services = DQ
94 | # Analysis services = AS
95 | # Reporting services – native = RS
96 | # Reporting services – sharepoint = RS_SHP
97 | # Reporting services add-in for sharepoint products = RS_SHPWFE
98 | # Data quality client = DQC
99 | # SQL Server data tools = BIDS
100 | # Client tools connectivity = CONN
101 | # Integration services = IS
102 | # Client tools backwards compatibility = BC
103 | # Client tools SDK = SDK
104 | # Documentation components = BOL
105 | # Management tools – basic = SSMS
106 | # Management tools – advanced = ADV_SSMS
107 | # Distributed replay controller = DREPLAY_CTLR
108 | # Distributed replay client = DREPLAY_CLT
109 | # SQL client connectivity SDK = SNAC_SDK
110 | # Master data services = MDS
111 | # ADVANCEDANALYTICS Installs R Services, requires the database engine. Unattended installations require /IACCEPTROPENLICENSETERMS parameter.
112 |
113 | mssql_features: SQLENGINE,FULLTEXT,CONN
114 |
115 | # Collation
116 | mssql_collation: SQL_Latin1_General_CP1_CI_AS
117 |
118 | # Browser service startup mode
119 | # Specifies the startup mode for SQL Server Browser service. { Automatic | Disabled | 'Manual' }
120 | mssql_browsersvc_mode: Automatic
121 |
122 | # Default Account Access
123 | # Ansible_Admin must be included so that the playbook can make configuration changes post install
124 | mssql_sysadmin_accounts:
125 | - HACKLAB\Domain Admins
126 | - HACKLAB\Administrator
127 |
128 | # Analysis Services Admins (if installed)
129 | mssql_asadmin_accounts: "{{ mssql_sysadmin_accounts }}"
130 |
131 | # Tuning options
132 |
133 | # When an instance of SQL Server runs on a computer that has more than one microprocessor or CPU,
134 | # it detects the best degree of parallelism, that is, the number of processors employed to run a single statement,
135 | # for each parallel plan execution. You can use the max degree of parallelism option to limit the number of processors
136 | # to use in parallel plan execution.
137 | #
138 | # If the affinity mask option is not set to the default, it may restrict the number of processors available to
139 | # SQL Server on symmetric multiprocessing (SMP) systems.
140 | #
141 | # To enable the server to determine the maximum degree of parallelism, set this option to 0, the default value.
142 | #
143 | # See: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-max-degree-of-parallelism-server-configuration-option
144 | mssql_max_degree_of_parallelism: 0
145 |
146 | # Minimum memory to allocate to SQL
147 | #
148 | # Should remain 0 in most cases.
149 | #
150 | # see: Optimizing Server Performance Using Memory Configuration Options
151 | # https://technet.microsoft.com/en-us/library/ms177455(v=sql.105).aspx
152 | #
153 | # The min server memory server configuration option can be used to ensure that
154 | # SQL Server does not release memory below the configured minimum server memory
155 | # once that threshold is reached. This configuration option can be set to a specific value
156 | # based on the size and activity of your SQL Server. If you choose to set this value,
157 | # set it to some reasonable value to ensure that the operating system does not request too
158 | # much memory from SQL Server, which can affect SQL Server performance.
159 | mssql_min_server_memory: 0
160 |
--------------------------------------------------------------------------------
/ansible/roles/mssql/README.md:
--------------------------------------------------------------------------------
1 | kkolk.mssql - sourced 99.9999999% from https://github.com/kkolk/mssql
2 | =========
3 | Description
4 | -----------
5 | This ansible role will install a SQL Server Developer Edition 2017 instance on supported Windows platforms. This role can be adjusted to install any supported SQL server installation. I've used variants of it to install SQL Server 2012/2014.
6 |
7 | This role also handles local firewall changes as required and demonstrates how to make configuration adjustments to the SQL instance.
8 |
9 | Using default values it's designed to work as an role that can be added to the member server in the windows test environment I've laid out through a series of posts on http://frostbyte.us/configure-an-ansible-testing-system-on-windows-part-1/
10 |
11 | Requirements
12 | ------------
13 |
14 | Powershell 5.0 / WMF 5.1 should be installed on target host.
15 |
16 | You can do this in two steps with:
17 |
18 | ```yaml
19 | # The latest powershell gives us more flexiablity to use Windows DSC items
20 | - name: Windows | Install Powershell 5.0
21 | win_chocolatey:
22 | name: "powershell"
23 | register: check_powershell5
24 | become: yes
25 | become_user: Administrator
26 | become_method: runas
27 | retries: 3
28 | delay: 10
29 |
30 | # Powershell 5.0 requires a reboot, so lets get it done if it's needed.
31 | - name: Windows | Reboot to complete Powershell 5.0 install
32 | win_reboot:
33 | # We will give windows a full hour to reboot.
34 | reboot_timeout: 3600
35 | post_reboot_delay: 60
36 | when: check_powershell5.changed
37 | ```
38 |
39 | Role Variables
40 | --------------
41 |
42 |
43 | ```yaml
44 | # installation files source
45 | mssql_installation_source: https://go.microsoft.com/fwlink/?linkid=853016
46 |
47 | # Path to download installation media to
48 | mssql_installation_path: C:\SQLInstall
49 |
50 | # Temporary path to store downloader
51 | mssql_temp_download_path: C:\tmp
52 |
53 | # instance details
54 | mssql_instance_name: Test
55 | mssql_drive: C
56 | mssql_userdbvol_name: Userdbvol01
57 | mssql_port: 1433
58 |
59 | ### Memory Configuration ###
60 | # memory in MB
61 | # values must be divisible by 512
62 |
63 | # Max memory to allocate to this instance
64 | mssql_max_server_memory: 1024
65 |
66 | # Memory to reserve to the OS
67 | mssql_os_memory_reservation: 512
68 |
69 | # Total system memory
70 | mssql_total_system_memory: "{{ mssql_max_server_memory + mssql_os_memory_reservation }}"
71 |
72 | # Suppress reboots that may occur during SQL Setup tasks
73 | # you will want to set this to True if working on a sensitive system:
74 | mssql_suppress_reboot: False
75 |
76 | ### Service Accounts ###
77 |
78 | # SQL Service Account
79 | # regex statements used in some steps expect the format of CONTOSO\
80 | # do not use @CONTOSO.com for these accounts as SQL install will fail
81 | mssql_sqlsvc_account: CONTOSO\sql_svc
82 | mssql_sqlsvc_account_pass: MyPlainTextPassWord01
83 |
84 | # SQL Agent Service Account
85 | mssql_agentsvc_account: CONTOSO\sql_agt
86 | mssql_agentsvc_account_pass: MyPlainTextPassWord01
87 |
88 | # SQL Analysis Services Account
89 | mssql_assvc_account: "{{ mssql_sqlsvc_account }}"
90 | mssql_assvc_account_pass: "{{ mssql_sqlsvc_account_pass }}"
91 |
92 | ### File and Folder Paths ###
93 |
94 | # volume paths
95 | mssql_userdbvol_path: "{{ mssql_drive }}:\\{{ mssql_userdbvol_name }}"
96 | mssql_db_accesspath: "{{ mssql_userdbvol_path }}\\DatabaseFiles"
97 | mssql_logs_accesspath: "{{ mssql_userdbvol_path }}\\DatabaseLogs"
98 |
99 | # shared files paths
100 | mssql_installshared_path: C:\Program Files\Microsoft SQL Server
101 | mssql_installsharedwow_path: C:\Program Files (x86)\Microsoft SQL Server
102 |
103 | # instance path
104 | mssql_instance_path: "C:\\Program Files\\Microsoft SQL Server\\{{ mssql_instance_name }}"
105 |
106 | # SQL DB and Logging Paths
107 | mssql_sqlinstalldata_path: "{{ mssql_db_accesspath }}\\{{mssql_instance_name }}"
108 | mssql_sqluserdata_path: "{{ mssql_db_accesspath }}\\{{mssql_instance_name }}"
109 | mssql_sqluserlog_path: "{{ mssql_logs_accesspath }}\\{{mssql_instance_name }}"
110 | mssql_sqltempDB_path: "C:\\TempDBFiles\\Data\\{{mssql_instance_name }}"
111 | mssql_sqltempDBlog_path: "C:\\TempDBFiles\\Log\\{{mssql_instance_name }}"
112 |
113 | # security mode - SQL indicates mixed-mode auth, while Windows indicates Windows Auth.
114 | mssql_security_mode: sql
115 |
116 | # SA user password, if security mode is set to 'SQL'
117 | # by default for testing we'll be lazy and use the service account password,
118 | # but on live systems you should use something else:
119 | mssql_sa_password: "{{ mssql_sqlsvc_account_pass }}"
120 |
121 | # features - Comma seperated list of features to be installed
122 | #
123 | # example:
124 | # mssql_features: SQLENGINE,AS
125 | #
126 | # The list of features below is untested, some may not work with DSC
127 | #
128 | # Features list:
129 | #
130 | # Database engine = SQLENGINE
131 | # Replication = REPLICATION
132 | # Full-text and semantic extractions for search = FULLTEXT
133 | # Data quality services = DQ
134 | # Analysis services = AS
135 | # Reporting services – native = RS
136 | # Reporting services – sharepoint = RS_SHP
137 | # Reporting services add-in for sharepoint products = RS_SHPWFE
138 | # Data quality client = DQC
139 | # SQL Server data tools = BIDS
140 | # Client tools connectivity = CONN
141 | # Integration services = IS
142 | # Client tools backwards compatibility = BC
143 | # Client tools SDK = SDK
144 | # Documentation components = BOL
145 | # Management tools – basic = SSMS
146 | # Management tools – advanced = ADV_SSMS
147 | # Distributed replay controller = DREPLAY_CTLR
148 | # Distributed replay client = DREPLAY_CLT
149 | # SQL client connectivity SDK = SNAC_SDK
150 | # Master data services = MDS
151 | # ADVANCEDANALYTICS Installs R Services, requires the database engine. Unattended installations require /IACCEPTROPENLICENSETERMS parameter.
152 |
153 | mssql_features: SQLENGINE,FULLTEXT,CONN
154 |
155 | # Collation
156 | mssql_collation: SQL_Latin1_General_CP1_CI_AS
157 |
158 | # Browser service startup mode
159 | # Specifies the startup mode for SQL Server Browser service. { Automatic | Disabled | 'Manual' }
160 | mssql_browsersvc_mode: Automatic
161 |
162 | # Default Account Access
163 | # Ansible_Admin must be included so that the playbook can make configuration changes post install
164 | mssql_sysadmin_accounts:
165 | - CONTOSO\Domain Admins
166 | - CONTOSO\Administrator
167 |
168 | # Analysis Services Admins (if installed)
169 | mssql_asadmin_accounts: "{{ mssql_sysadmin_accounts }}"
170 |
171 | # Tuning options
172 |
173 | # When an instance of SQL Server runs on a computer that has more than one microprocessor or CPU,
174 | # it detects the best degree of parallelism, that is, the number of processors employed to run a single statement,
175 | # for each parallel plan execution. You can use the max degree of parallelism option to limit the number of processors
176 | # to use in parallel plan execution.
177 | #
178 | # If the affinity mask option is not set to the default, it may restrict the number of processors available to
179 | # SQL Server on symmetric multiprocessing (SMP) systems.
180 | #
181 | # To enable the server to determine the maximum degree of parallelism, set this option to 0, the default value.
182 | #
183 | # See: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-max-degree-of-parallelism-server-configuration-option
184 | mssql_max_degree_of_parallelism: 0
185 |
186 | # Minimum memory to allocate to SQL
187 | #
188 | # Should remain 0 in most cases.
189 | #
190 | # see: Optimizing Server Performance Using Memory Configuration Options
191 | # https://technet.microsoft.com/en-us/library/ms177455(v=sql.105).aspx
192 | #
193 | # The min server memory server configuration option can be used to ensure that
194 | # SQL Server does not release memory below the configured minimum server memory
195 | # once that threshold is reached. This configuration option can be set to a specific value
196 | # based on the size and activity of your SQL Server. If you choose to set this value,
197 | # set it to some reasonable value to ensure that the operating system does not request too
198 | # much memory from SQL Server, which can affect SQL Server performance.
199 | mssql_min_server_memory: 0
200 | ```
201 |
202 | Example Playbook
203 | ----------------
204 |
205 | - name: SQL Server
206 | hosts: sql_server
207 | tags: mssql
208 |
209 | roles:
210 | - { role: kkolk.mssql }
211 |
212 | License
213 | -------
214 |
215 | BSD / MIT
216 |
217 | Author Information
218 | ------------------
219 |
220 | Kevin Kolk - http://www.frostbyte.us
221 |
--------------------------------------------------------------------------------
/ansible/roles/mssql/tasks/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 | #
3 | # Install SQL Developer Edition
4 | #
5 |
6 | # Load required powershell modules
7 | - name: Powershell | Check for SQLServer DSC Powershell module
8 | win_psmodule:
9 | name: SQLServerDsc
10 | state: present
11 |
12 | - name: Powershell | Check for Storage DSC Powershell module
13 | win_psmodule:
14 | name: StorageDsc
15 | state: present
16 |
17 | - name: Powershell | Check for ServerManager Powershell module
18 | win_psmodule:
19 | name: ServerManager
20 | state: present
21 |
22 | - name: Powershell | Ensure that DBA Tools module is present
23 | win_psmodule:
24 | name: dbatools
25 | state: present
26 |
27 | - name: Powershell | Check for xNetworking Powershell module
28 | win_psmodule:
29 | name: xNetworking
30 | state: present
31 |
32 | - name: Windows | Install .NET Framework Core
33 | win_feature:
34 | name: NET-Framework-Core
35 | state: present
36 |
37 | # Setup SQL Server Pre-Reqs
38 | - name: Windows | Install .NET Framework 3.5
39 | win_feature:
40 | name: NET-Framework-Features
41 | state: present
42 |
43 | - name: Windows | Install .NET Framework 4.5 Features
44 | win_feature:
45 | name: NET-Framework-45-Features
46 | state: present
47 | include_sub_features: True
48 |
49 | - name: Windows | Install Windows Process Activation Service
50 | win_feature:
51 | name: WAS
52 | state: present
53 | include_sub_features: True
54 |
55 | # Setup service accounts
56 | #
57 | # We delegate this process to our domain controller since the required AD services are there for
58 | # win_domain_user to interact with.
59 | - name: Active Directory | Ensure SQL Service account is present
60 | win_domain_user:
61 | name: "{{ mssql_sqlsvc_account | regex_search('[^\\\\]*$') }}"
62 | firstname: "{{ mssql_instance_name }}"
63 | surname: SQLSvc
64 | password: "{{ mssql_sqlsvc_account_pass }}"
65 | password_never_expires: yes
66 | user_cannot_change_password: yes
67 | description: "SQL Service account for {{ inventory_hostname }}\\{{ mssql_instance_name }}"
68 | state: present
69 | path: "{{ mssql_base_ldap_path }}"
70 | groups:
71 | - Domain Users
72 | tags: service_account
73 | delegate_to: "{{ domain_controller }}"
74 |
75 | - name: Active Directory | Ensure SQL Agent Service account is present
76 | win_domain_user:
77 | name: "{{ mssql_agentsvc_account | regex_search('[^\\\\]*$') }}"
78 | firstname: "{{ mssql_instance_name }}"
79 | surname: AgentSvc
80 | password: "{{ mssql_agentsvc_account_pass }}"
81 | password_never_expires: yes
82 | user_cannot_change_password: yes
83 | description: "SQL Agent service account for {{ inventory_hostname }}\\{{ mssql_instance_name }}"
84 | state: present
85 | path: "{{ mssql_base_ldap_path }}"
86 | groups:
87 | - Domain Users
88 | delegate_to: "{{ domain_controller }}"
89 | tags: service_account
90 |
91 | # SQL install may fail if a pending reboot is detected
92 | # Assuming we are allowed to reboot this step will check for pending reboots
93 | # and execute a reboot, reboot activity can be controlled using the variable mssql_suppress_reboot
94 |
95 | - name: Ensure that a reboot is not pending
96 | when: ansible_reboot_pending
97 | debug:
98 | msg: 'Pending reboot detected'
99 | changed_when: true
100 | notify: reboot windows
101 |
102 | - meta: flush_handlers
103 |
104 | - name: Fetch SQL Media Downloader
105 | win_get_url:
106 | url: "{{ mssql_installation_source }}"
107 | dest: "{{ mssql_temp_download_path }}\\SQLServer2017-SSEI-Dev.exe"
108 |
109 | - name: Use Media Downloader to fetch SQL Installation CABs to {{ mssql_installation_path }}
110 | win_shell: "{{ mssql_temp_download_path }}\\SQLServer2017-SSEI-Dev.exe /Action=Download /MediaPath={{ mssql_installation_path }} /MediaType=CAB /Quiet"
111 |
112 | # Job will fail if extracted media folder is not empty, quick step to ensure it's empty
113 | - name: Ensure installation media extraction path is empty
114 | win_file:
115 | path: "{{ mssql_installation_path }}\\Media"
116 | state: absent
117 |
118 | - name: Extract installation media
119 | win_shell: "{{ mssql_installation_path }}\\SQLServer2017-DEV-x64-ENU.exe /X:{{ mssql_installation_path }}\\Media /Q"
120 | # If this step fails, logs are in C:\Program Files\Microsoft SQL Server\...\Setup Bootstrap\Log
121 | # it will often contain the actual error. If it shows everything passing, the issue is within the DSC logs.
122 | #
123 | # This module also typically throws this error fpr all failure conditions:
124 | # PowerShell DSC resource MSFT_SqlSetup failed to execute Set-TargetResource functionality with error message:
125 | # System.Exception: Test-TargetResource returned false after calling Set-TargetResource.
126 | #
127 | #
128 | # This document can also be useful to troubleshoot issues with DSC modules
129 | # https://docs.microsoft.com/en-us/powershell/dsc/troubleshooting
130 | #
131 | # In particular completing these steps:
132 | # https://docs.microsoft.com/en-us/powershell/dsc/troubleshooting#gathering-events-from-a-single-dsc-operation
133 | # then re-running a failing PowershellDSC job can help you find the source of your error
134 | - name: Install SQL Server
135 | win_dsc:
136 | resource_name: SQLSetup
137 | Action: Install
138 | UpdateEnabled: True
139 | SourcePath: "{{ mssql_installation_path }}\\Media"
140 | InstanceName: "{{ mssql_instance_name }}"
141 | InstallSharedDir: "{{ mssql_installshared_path }}"
142 | InstallSharedwowDir: "{{ mssql_installsharedwow_path }}"
143 | InstanceDir: "{{ mssql_instance_path }}"
144 | InstallSQLDataDir: "{{ mssql_sqlinstalldata_path }}"
145 | SQLUserDBDir: "{{ mssql_sqluserdata_path }}"
146 | SQLUserDBLogDir: "{{ mssql_sqluserlog_path }}"
147 | SQLTempDBDir: "{{ mssql_sqltempDB_path }}"
148 | SQLTempDBLogDir: "{{ mssql_sqltempDBlog_path }}"
149 | Features: "{{ mssql_features }}"
150 | SQLCollation: "{{ mssql_collation }}"
151 | BrowserSvcStartupType: "{{ mssql_browsersvc_mode }}"
152 | SuppressReboot: "{{ mssql_suppress_reboot }}"
153 | # Service Accounts
154 | #
155 | # If the type of the DSC resource option is a PSCredential then
156 | # there needs to be 2 options set in the Ansible task definition
157 | # suffixed with _username and _password. So we will be providing
158 | # two options for these normally single option items.
159 |
160 | # SQL Service Account
161 | SQLSvcAccount_username: "{{ mssql_sqlsvc_account }}"
162 | SQLSvcAccount_password: "{{ mssql_sqlsvc_account_pass }}"
163 | # SQL Agent Service Account
164 | AgtSvcAccount_username: "{{ mssql_agentsvc_account }}"
165 | AgtSvcAccount_password: "{{ mssql_agentsvc_account_pass }}"
166 | # SQL Analysis Services Account
167 | ASSvcAccount_username: "{{ mssql_assvc_account }}"
168 | ASSvcAccount_password: "{{ mssql_assvc_account_pass }}"
169 |
170 | # Used when installing on a network path, comment out
171 | # SourceCredential_username: "{{ ansible_user }}"
172 | # SourceCredential_password: "{{ ansible_password }}"
173 |
174 | # System Admins
175 | SQLSysAdminAccounts: "{{ mssql_sysadmin_accounts }}"
176 | # Analysis Services Admins (if installed)
177 | ASSysAdminAccounts: "{{ mssql_asadmin_accounts }}"
178 | tags: install_sql
179 |
180 | # End of win_dsc for SQL Server
181 |
182 | # Firewall configuration
183 | - name: Firewall | Allow Database Engine for instance
184 | win_dsc:
185 | resource_name: xFirewall
186 | Name: "SQL Server Database Engine instance {{ mssql_instance_name }}"
187 | Program: sqlservr.exe
188 | Ensure: present
189 | Enabled: True
190 | Profile: "Domain"
191 | Direction: "Inbound"
192 | Action: Allow
193 | Description: "Allows the Database Engine to access the network"
194 | tags: configure_firewall
195 |
196 | - name: Firewall | Allow SQLBrowser for instance
197 | win_dsc:
198 | resource_name: xFirewall
199 | Name: "SQL Server Browser instance {{ mssql_instance_name }}"
200 | Service: SQLBrowser
201 | Ensure: present
202 | Enabled: True
203 | Profile: "Domain"
204 | Direction: "Inbound"
205 | Action: Allow
206 | Description: "Allows the SQL Server Browser to access the network"
207 | tags: configure_firewall
208 |
209 | # Begin SQL Server configuration
210 | - name: Enable TCP Connectivity
211 | win_dsc:
212 | resource_name: SqlServerNetwork
213 | InstanceName: "{{ mssql_instance_name }}"
214 | ProtocolName: tcp
215 | TcpPort: "{{ mssql_port }}"
216 | IsEnabled: True
217 | RestartService: True
218 | tags: configure_sql
219 |
220 | - name: Adjust Max Server Memory to {{ mssql_max_server_memory }}
221 | when: mssql_max_server_memory is defined
222 | win_dsc:
223 | resource_name: SqlServerConfiguration
224 | InstanceName: "{{ mssql_instance_name }}"
225 | ServerName: "{{ ansible_hostname }}"
226 | OptionName: max server memory (MB)
227 | OptionValue: "{{ mssql_max_server_memory }}"
228 | RestartService: False
229 | tags: configure_sql
230 | ignore_errors: yes
231 |
232 | - name: Adjust Min Server Memory to {{ mssql_min_server_memory }}
233 | when: mssql_min_server_memory is defined
234 | win_dsc:
235 | resource_name: SqlServerConfiguration
236 | ServerName: "{{ ansible_hostname }}"
237 | InstanceName: "{{ mssql_instance_name }}"
238 | OptionName: min server memory (MB)
239 | OptionValue: "{{ mssql_min_server_memory }}"
240 | tags: configure_sql
241 | ignore_errors: yes
242 |
243 | - name: Adjust Max Degree of Parallelism
244 | when: mssql_max_degree_of_parallelism is defined
245 | win_dsc:
246 | resource_name: SqlServerConfiguration
247 | ServerName: "{{ ansible_hostname }}"
248 | InstanceName: "{{ mssql_instance_name }}"
249 | OptionName: max degree of parallelism
250 | OptionValue: "{{ mssql_max_degree_of_parallelism }}"
251 | tags: configure_sql
252 | ignore_errors: yes
253 |
254 | - name: Install Chocolatey ... easy way to get SQL Server Management Studio
255 | script: install.ps1
256 |
257 | - name: Install multiple packages sequentially
258 | win_chocolatey:
259 | name: '{{ item }}'
260 | state: present
261 | with_items:
262 | - sql-server-management-studio
263 | ignore_errors: yes
264 |
265 | - name: Copy over Database dump files ... CreateDatabase.sql
266 | win_copy:
267 | src: files/CreateDatabase.sql
268 | dest: c:\tmp\
269 |
270 | - name: Copy over Database dump files ... CreateTable.sql
271 | win_copy:
272 | src: files/CreateTable.sql
273 | dest: c:\tmp\
274 |
275 | #- name: Create a new database with name Clients
276 | # mssql_db:
277 | # name: "Clients"
278 | # state: present
279 | # login_host: "192.168.200.11"
280 | # login_user: "HACKLAB\test_admin"
281 | # login_password: "AutomationDoesW0rk!"
282 |
283 | #- name: Setup Clients database
284 | # mssql_db:
285 | # name: Clients
286 | # state: import
287 | # target: C:\tmp\CreateDatabase.sql
288 |
289 | #- name: Create the Clients Table
290 | # mssql_db:
291 | # name: Clients
292 | # state: import
293 | # target: C:\tmp\CreateTable.sql
294 |
--------------------------------------------------------------------------------
/vagrant/ConfigureRemotingForAnsible.ps1:
--------------------------------------------------------------------------------
1 | #Requires -Version 3.0
2 |
3 | # Configure a Windows host for remote management with Ansible
4 | # -----------------------------------------------------------
5 | #
6 | # This script checks the current WinRM (PS Remoting) configuration and makes
7 | # the necessary changes to allow Ansible to connect, authenticate and
8 | # execute PowerShell commands.
9 | #
10 | # All events are logged to the Windows EventLog, useful for unattended runs.
11 | #
12 | # Use option -Verbose in order to see the verbose output messages.
13 | #
14 | # Use option -CertValidityDays to specify how long this certificate is valid
15 | # starting from today. So you would specify -CertValidityDays 3650 to get
16 | # a 10-year valid certificate.
17 | #
18 | # Use option -ForceNewSSLCert if the system has been SysPreped and a new
19 | # SSL Certificate must be forced on the WinRM Listener when re-running this
20 | # script. This is necessary when a new SID and CN name is created.
21 | #
22 | # Use option -EnableCredSSP to enable CredSSP as an authentication option.
23 | #
24 | # Use option -DisableBasicAuth to disable basic authentication.
25 | #
26 | # Use option -SkipNetworkProfileCheck to skip the network profile check.
27 | # Without specifying this the script will only run if the device's interfaces
28 | # are in DOMAIN or PRIVATE zones. Provide this switch if you want to enable
29 | # WinRM on a device with an interface in PUBLIC zone.
30 | #
31 | # Use option -SubjectName to specify the CN name of the certificate. This
32 | # defaults to the system's hostname and generally should not be specified.
33 |
34 | # Written by Trond Hindenes
35 | # Updated by Chris Church
36 | # Updated by Michael Crilly
37 | # Updated by Anton Ouzounov
38 | # Updated by Nicolas Simond
39 | # Updated by Dag Wieërs
40 | # Updated by Jordan Borean
41 | # Updated by Erwan Quélin
42 | # Updated by David Norman
43 | #
44 | # Version 1.0 - 2014-07-06
45 | # Version 1.1 - 2014-11-11
46 | # Version 1.2 - 2015-05-15
47 | # Version 1.3 - 2016-04-04
48 | # Version 1.4 - 2017-01-05
49 | # Version 1.5 - 2017-02-09
50 | # Version 1.6 - 2017-04-18
51 | # Version 1.7 - 2017-11-23
52 | # Version 1.8 - 2018-02-23
53 | # Version 1.9 - 2018-09-21
54 |
55 | # Support -Verbose option
56 | [CmdletBinding()]
57 |
58 | Param (
59 | [string]$SubjectName = $env:COMPUTERNAME,
60 | [int]$CertValidityDays = 1095,
61 | [switch]$SkipNetworkProfileCheck,
62 | $CreateSelfSignedCert = $true,
63 | [switch]$ForceNewSSLCert,
64 | [switch]$GlobalHttpFirewallAccess,
65 | [switch]$DisableBasicAuth = $false,
66 | [switch]$EnableCredSSP
67 | )
68 |
69 | Function Write-Log
70 | {
71 | $Message = $args[0]
72 | Write-EventLog -LogName Application -Source $EventSource -EntryType Information -EventId 1 -Message $Message
73 | }
74 |
75 | Function Write-VerboseLog
76 | {
77 | $Message = $args[0]
78 | Write-Verbose $Message
79 | Write-Log $Message
80 | }
81 |
82 | Function Write-HostLog
83 | {
84 | $Message = $args[0]
85 | Write-Output $Message
86 | Write-Log $Message
87 | }
88 |
89 | Function New-LegacySelfSignedCert
90 | {
91 | Param (
92 | [string]$SubjectName,
93 | [int]$ValidDays = 1095
94 | )
95 |
96 | $hostnonFQDN = $env:computerName
97 | $hostFQDN = [System.Net.Dns]::GetHostByName(($env:computerName)).Hostname
98 | $SignatureAlgorithm = "SHA256"
99 |
100 | $name = New-Object -COM "X509Enrollment.CX500DistinguishedName.1"
101 | $name.Encode("CN=$SubjectName", 0)
102 |
103 | $key = New-Object -COM "X509Enrollment.CX509PrivateKey.1"
104 | $key.ProviderName = "Microsoft Enhanced RSA and AES Cryptographic Provider"
105 | $key.KeySpec = 1
106 | $key.Length = 4096
107 | $key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
108 | $key.MachineContext = 1
109 | $key.Create()
110 |
111 | $serverauthoid = New-Object -COM "X509Enrollment.CObjectId.1"
112 | $serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
113 | $ekuoids = New-Object -COM "X509Enrollment.CObjectIds.1"
114 | $ekuoids.Add($serverauthoid)
115 | $ekuext = New-Object -COM "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
116 | $ekuext.InitializeEncode($ekuoids)
117 |
118 | $cert = New-Object -COM "X509Enrollment.CX509CertificateRequestCertificate.1"
119 | $cert.InitializeFromPrivateKey(2, $key, "")
120 | $cert.Subject = $name
121 | $cert.Issuer = $cert.Subject
122 | $cert.NotBefore = (Get-Date).AddDays(-1)
123 | $cert.NotAfter = $cert.NotBefore.AddDays($ValidDays)
124 |
125 | $SigOID = New-Object -ComObject X509Enrollment.CObjectId
126 | $SigOID.InitializeFromValue(([Security.Cryptography.Oid]$SignatureAlgorithm).Value)
127 |
128 | [string[]] $AlternativeName += $hostnonFQDN
129 | $AlternativeName += $hostFQDN
130 | $IAlternativeNames = New-Object -ComObject X509Enrollment.CAlternativeNames
131 |
132 | foreach ($AN in $AlternativeName)
133 | {
134 | $AltName = New-Object -ComObject X509Enrollment.CAlternativeName
135 | $AltName.InitializeFromString(0x3,$AN)
136 | $IAlternativeNames.Add($AltName)
137 | }
138 |
139 | $SubjectAlternativeName = New-Object -ComObject X509Enrollment.CX509ExtensionAlternativeNames
140 | $SubjectAlternativeName.InitializeEncode($IAlternativeNames)
141 |
142 | [String[]]$KeyUsage = ("DigitalSignature", "KeyEncipherment")
143 | $KeyUsageObj = New-Object -ComObject X509Enrollment.CX509ExtensionKeyUsage
144 | $KeyUsageObj.InitializeEncode([int][Security.Cryptography.X509Certificates.X509KeyUsageFlags]($KeyUsage))
145 | $KeyUsageObj.Critical = $true
146 |
147 | $cert.X509Extensions.Add($KeyUsageObj)
148 | $cert.X509Extensions.Add($ekuext)
149 | $cert.SignatureInformation.HashAlgorithm = $SigOID
150 | $CERT.X509Extensions.Add($SubjectAlternativeName)
151 | $cert.Encode()
152 |
153 | $enrollment = New-Object -COM "X509Enrollment.CX509Enrollment.1"
154 | $enrollment.InitializeFromRequest($cert)
155 | $certdata = $enrollment.CreateRequest(0)
156 | $enrollment.InstallResponse(2, $certdata, 0, "")
157 |
158 | # extract/return the thumbprint from the generated cert
159 | $parsed_cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
160 | $parsed_cert.Import([System.Text.Encoding]::UTF8.GetBytes($certdata))
161 |
162 | return $parsed_cert.Thumbprint
163 | }
164 |
165 | Function Enable-GlobalHttpFirewallAccess
166 | {
167 | Write-Verbose "Forcing global HTTP firewall access"
168 | # this is a fairly naive implementation; could be more sophisticated about rule matching/collapsing
169 | $fw = New-Object -ComObject HNetCfg.FWPolicy2
170 |
171 | # try to find/enable the default rule first
172 | $add_rule = $false
173 | $matching_rules = $fw.Rules | ? { $_.Name -eq "Windows Remote Management (HTTP-In)" }
174 | $rule = $null
175 | If ($matching_rules) {
176 | If ($matching_rules -isnot [Array]) {
177 | Write-Verbose "Editing existing single HTTP firewall rule"
178 | $rule = $matching_rules
179 | }
180 | Else {
181 | # try to find one with the All or Public profile first
182 | Write-Verbose "Found multiple existing HTTP firewall rules..."
183 | $rule = $matching_rules | % { $_.Profiles -band 4 }[0]
184 |
185 | If (-not $rule -or $rule -is [Array]) {
186 | Write-Verbose "Editing an arbitrary single HTTP firewall rule (multiple existed)"
187 | # oh well, just pick the first one
188 | $rule = $matching_rules[0]
189 | }
190 | }
191 | }
192 |
193 | If (-not $rule) {
194 | Write-Verbose "Creating a new HTTP firewall rule"
195 | $rule = New-Object -ComObject HNetCfg.FWRule
196 | $rule.Name = "Windows Remote Management (HTTP-In)"
197 | $rule.Description = "Inbound rule for Windows Remote Management via WS-Management. [TCP 5985]"
198 | $add_rule = $true
199 | }
200 |
201 | $rule.Profiles = 0x7FFFFFFF
202 | $rule.Protocol = 6
203 | $rule.LocalPorts = 5985
204 | $rule.RemotePorts = "*"
205 | $rule.LocalAddresses = "*"
206 | $rule.RemoteAddresses = "*"
207 | $rule.Enabled = $true
208 | $rule.Direction = 1
209 | $rule.Action = 1
210 | $rule.Grouping = "Windows Remote Management"
211 |
212 | If ($add_rule) {
213 | $fw.Rules.Add($rule)
214 | }
215 |
216 | Write-Verbose "HTTP firewall rule $($rule.Name) updated"
217 | }
218 |
219 | # Setup error handling.
220 | Trap
221 | {
222 | $_
223 | Exit 1
224 | }
225 | $ErrorActionPreference = "Stop"
226 |
227 | # Get the ID and security principal of the current user account
228 | $myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
229 | $myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
230 |
231 | # Get the security principal for the Administrator role
232 | $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
233 |
234 | # Check to see if we are currently running "as Administrator"
235 | if (-Not $myWindowsPrincipal.IsInRole($adminRole))
236 | {
237 | Write-Output "ERROR: You need elevated Administrator privileges in order to run this script."
238 | Write-Output " Start Windows PowerShell by using the Run as Administrator option."
239 | Exit 2
240 | }
241 |
242 | $EventSource = $MyInvocation.MyCommand.Name
243 | If (-Not $EventSource)
244 | {
245 | $EventSource = "Powershell CLI"
246 | }
247 |
248 | If ([System.Diagnostics.EventLog]::Exists('Application') -eq $False -or [System.Diagnostics.EventLog]::SourceExists($EventSource) -eq $False)
249 | {
250 | New-EventLog -LogName Application -Source $EventSource
251 | }
252 |
253 | # Detect PowerShell version.
254 | If ($PSVersionTable.PSVersion.Major -lt 3)
255 | {
256 | Write-Log "PowerShell version 3 or higher is required."
257 | Throw "PowerShell version 3 or higher is required."
258 | }
259 |
260 | # Find and start the WinRM service.
261 | Write-Verbose "Verifying WinRM service."
262 | If (!(Get-Service "WinRM"))
263 | {
264 | Write-Log "Unable to find the WinRM service."
265 | Throw "Unable to find the WinRM service."
266 | }
267 | ElseIf ((Get-Service "WinRM").Status -ne "Running")
268 | {
269 | Write-Verbose "Setting WinRM service to start automatically on boot."
270 | Set-Service -Name "WinRM" -StartupType Automatic
271 | Write-Log "Set WinRM service to start automatically on boot."
272 | Write-Verbose "Starting WinRM service."
273 | Start-Service -Name "WinRM" -ErrorAction Stop
274 | Write-Log "Started WinRM service."
275 |
276 | }
277 |
278 | # WinRM should be running; check that we have a PS session config.
279 | If (!(Get-PSSessionConfiguration -Verbose:$false) -or (!(Get-ChildItem WSMan:\localhost\Listener)))
280 | {
281 | If ($SkipNetworkProfileCheck) {
282 | Write-Verbose "Enabling PS Remoting without checking Network profile."
283 | Enable-PSRemoting -SkipNetworkProfileCheck -Force -ErrorAction Stop
284 | Write-Log "Enabled PS Remoting without checking Network profile."
285 | }
286 | Else {
287 | Write-Verbose "Enabling PS Remoting."
288 | Enable-PSRemoting -Force -ErrorAction Stop
289 | Write-Log "Enabled PS Remoting."
290 | }
291 | }
292 | Else
293 | {
294 | Write-Verbose "PS Remoting is already enabled."
295 | }
296 |
297 | # Ensure LocalAccountTokenFilterPolicy is set to 1
298 | # https://github.com/ansible/ansible/issues/42978
299 | $token_path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
300 | $token_prop_name = "LocalAccountTokenFilterPolicy"
301 | $token_key = Get-Item -Path $token_path
302 | $token_value = $token_key.GetValue($token_prop_name, $null)
303 | if ($token_value -ne 1) {
304 | Write-Verbose "Setting LocalAccountTOkenFilterPolicy to 1"
305 | if ($null -ne $token_value) {
306 | Remove-ItemProperty -Path $token_path -Name $token_prop_name
307 | }
308 | New-ItemProperty -Path $token_path -Name $token_prop_name -Value 1 -PropertyType DWORD > $null
309 | }
310 |
311 | # Make sure there is a SSL listener.
312 | $listeners = Get-ChildItem WSMan:\localhost\Listener
313 | If (!($listeners | Where {$_.Keys -like "TRANSPORT=HTTPS"}))
314 | {
315 | # We cannot use New-SelfSignedCertificate on 2012R2 and earlier
316 | $thumbprint = New-LegacySelfSignedCert -SubjectName $SubjectName -ValidDays $CertValidityDays
317 | Write-HostLog "Self-signed SSL certificate generated; thumbprint: $thumbprint"
318 |
319 | # Create the hashtables of settings to be used.
320 | $valueset = @{
321 | Hostname = $SubjectName
322 | CertificateThumbprint = $thumbprint
323 | }
324 |
325 | $selectorset = @{
326 | Transport = "HTTPS"
327 | Address = "*"
328 | }
329 |
330 | Write-Verbose "Enabling SSL listener."
331 | New-WSManInstance -ResourceURI 'winrm/config/Listener' -SelectorSet $selectorset -ValueSet $valueset
332 | Write-Log "Enabled SSL listener."
333 | }
334 | Else
335 | {
336 | Write-Verbose "SSL listener is already active."
337 |
338 | # Force a new SSL cert on Listener if the $ForceNewSSLCert
339 | If ($ForceNewSSLCert)
340 | {
341 |
342 | # We cannot use New-SelfSignedCertificate on 2012R2 and earlier
343 | $thumbprint = New-LegacySelfSignedCert -SubjectName $SubjectName -ValidDays $CertValidityDays
344 | Write-HostLog "Self-signed SSL certificate generated; thumbprint: $thumbprint"
345 |
346 | $valueset = @{
347 | CertificateThumbprint = $thumbprint
348 | Hostname = $SubjectName
349 | }
350 |
351 | # Delete the listener for SSL
352 | $selectorset = @{
353 | Address = "*"
354 | Transport = "HTTPS"
355 | }
356 | Remove-WSManInstance -ResourceURI 'winrm/config/Listener' -SelectorSet $selectorset
357 |
358 | # Add new Listener with new SSL cert
359 | New-WSManInstance -ResourceURI 'winrm/config/Listener' -SelectorSet $selectorset -ValueSet $valueset
360 | }
361 | }
362 |
363 | # Check for basic authentication.
364 | $basicAuthSetting = Get-ChildItem WSMan:\localhost\Service\Auth | Where-Object {$_.Name -eq "Basic"}
365 |
366 | If ($DisableBasicAuth)
367 | {
368 | If (($basicAuthSetting.Value) -eq $true)
369 | {
370 | Write-Verbose "Disabling basic auth support."
371 | Set-Item -Path "WSMan:\localhost\Service\Auth\Basic" -Value $false
372 | Write-Log "Disabled basic auth support."
373 | }
374 | Else
375 | {
376 | Write-Verbose "Basic auth is already disabled."
377 | }
378 | }
379 | Else
380 | {
381 | If (($basicAuthSetting.Value) -eq $false)
382 | {
383 | Write-Verbose "Enabling basic auth support."
384 | Set-Item -Path "WSMan:\localhost\Service\Auth\Basic" -Value $true
385 | Write-Log "Enabled basic auth support."
386 | }
387 | Else
388 | {
389 | Write-Verbose "Basic auth is already enabled."
390 | }
391 | }
392 |
393 | # If EnableCredSSP if set to true
394 | If ($EnableCredSSP)
395 | {
396 | # Check for CredSSP authentication
397 | $credsspAuthSetting = Get-ChildItem WSMan:\localhost\Service\Auth | Where {$_.Name -eq "CredSSP"}
398 | If (($credsspAuthSetting.Value) -eq $false)
399 | {
400 | Write-Verbose "Enabling CredSSP auth support."
401 | Enable-WSManCredSSP -role server -Force
402 | Write-Log "Enabled CredSSP auth support."
403 | }
404 | }
405 |
406 | If ($GlobalHttpFirewallAccess) {
407 | Enable-GlobalHttpFirewallAccess
408 | }
409 |
410 | # Configure firewall to allow WinRM HTTPS connections.
411 | $fwtest1 = netsh advfirewall firewall show rule name="Allow WinRM HTTPS"
412 | $fwtest2 = netsh advfirewall firewall show rule name="Allow WinRM HTTPS" profile=any
413 | If ($fwtest1.count -lt 5)
414 | {
415 | Write-Verbose "Adding firewall rule to allow WinRM HTTPS."
416 | netsh advfirewall firewall add rule profile=any name="Allow WinRM HTTPS" dir=in localport=5986 protocol=TCP action=allow
417 | Write-Log "Added firewall rule to allow WinRM HTTPS."
418 | }
419 | ElseIf (($fwtest1.count -ge 5) -and ($fwtest2.count -lt 5))
420 | {
421 | Write-Verbose "Updating firewall rule to allow WinRM HTTPS for any profile."
422 | netsh advfirewall firewall set rule name="Allow WinRM HTTPS" new profile=any
423 | Write-Log "Updated firewall rule to allow WinRM HTTPS for any profile."
424 | }
425 | Else
426 | {
427 | Write-Verbose "Firewall rule already exists to allow WinRM HTTPS."
428 | }
429 |
430 | # Test a remoting connection to localhost, which should work.
431 | $httpResult = Invoke-Command -ComputerName "localhost" -ScriptBlock {$env:COMPUTERNAME} -ErrorVariable httpError -ErrorAction SilentlyContinue
432 | $httpsOptions = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
433 |
434 | $httpsResult = New-PSSession -UseSSL -ComputerName "localhost" -SessionOption $httpsOptions -ErrorVariable httpsError -ErrorAction SilentlyContinue
435 |
436 | If ($httpResult -and $httpsResult)
437 | {
438 | Write-Verbose "HTTP: Enabled | HTTPS: Enabled"
439 | }
440 | ElseIf ($httpsResult -and !$httpResult)
441 | {
442 | Write-Verbose "HTTP: Disabled | HTTPS: Enabled"
443 | }
444 | ElseIf ($httpResult -and !$httpsResult)
445 | {
446 | Write-Verbose "HTTP: Enabled | HTTPS: Disabled"
447 | }
448 | Else
449 | {
450 | Write-Log "Unable to establish an HTTP or HTTPS remoting session."
451 | Throw "Unable to establish an HTTP or HTTPS remoting session."
452 | }
453 | Write-VerboseLog "PS Remoting has been successfully configured for Ansible."
454 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------