From 05d45daef1f6beb67649aa482f06aa32e2d263ad Mon Sep 17 00:00:00 2001 From: agatha Date: Sun, 27 Apr 2025 14:21:31 -0400 Subject: [PATCH] add playbook to setup scanners --- .gitignore | 3 ++ README.md | 9 +++++ inventory/test_inventory | 5 ++- playbooks/setup_scanner.yml | 15 +++++++ requirements.yml | 2 + roles/offsec_scanning/README.md | 38 ++++++++++++++++++ roles/offsec_scanning/defaults/main.yml | 2 + roles/offsec_scanning/handlers/main.yml | 2 + roles/offsec_scanning/meta/main.yml | 52 +++++++++++++++++++++++++ roles/offsec_scanning/tasks/main.yml | 33 ++++++++++++++++ roles/offsec_scanning/tests/inventory | 2 + roles/offsec_scanning/tests/test.yml | 5 +++ roles/offsec_scanning/vars/main.yml | 2 + 13 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 playbooks/setup_scanner.yml create mode 100644 requirements.yml create mode 100644 roles/offsec_scanning/README.md create mode 100644 roles/offsec_scanning/defaults/main.yml create mode 100644 roles/offsec_scanning/handlers/main.yml create mode 100644 roles/offsec_scanning/meta/main.yml create mode 100644 roles/offsec_scanning/tasks/main.yml create mode 100644 roles/offsec_scanning/tests/inventory create mode 100644 roles/offsec_scanning/tests/test.yml create mode 100644 roles/offsec_scanning/vars/main.yml diff --git a/.gitignore b/.gitignore index 3f45b22..d12c816 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ generated_passwords.txt # Ignore Vagrant directory .vagrant/ + +# Ignore galaxy roles +roles/geerlingguy.go diff --git a/README.md b/README.md index 279184c..92d3099 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,13 @@ This repository contains a collection of Ansible playbooks and roles for setting up my base Debian systems. +## Requirements +Some playbooks require roles from Ansible Galaxy: + +```bash +ansible-galaxy install -r requirements.yml +``` + ## Roles - **base_setup** - Role to set up a base system - Installs basic packages @@ -11,6 +18,7 @@ my base Debian systems. - Creates user with or without password - **system_update** - Role to update the system - **tor** - Role to install Tor +- **offsec_scanning** - Role to install scanning tools ## Playbooks - **playbooks/setup_base_system.yml** - Sets up the base system @@ -18,6 +26,7 @@ my base Debian systems. - Passwords will be placed in a file called `generated_passwords.txt` - **playbooks/update_systems.yml** - Updates the systems - **playbooks/install_tor.yml** - Installs Tor for all hosts in the `tor_systems` group +- **playbooks/setup_scanner.yml** - Installs scanning tools on all hosts in the `scanners` group. ## Testing If you would like to test out the plays before using them on your live systems, this diff --git a/inventory/test_inventory b/inventory/test_inventory index cfee3aa..f4a543a 100644 --- a/inventory/test_inventory +++ b/inventory/test_inventory @@ -6,4 +6,7 @@ testserver1 ansible_host=192.168.56.11 ansible_ssh_private_key_file=.vagrant/mac testserver2 ansible_host=192.168.56.12 ansible_ssh_private_key_file=.vagrant/machines/testserver2/virtualbox/private_key [tor_systems] -testserver1 \ No newline at end of file +testserver1 + +[scanners] +testserver2 \ No newline at end of file diff --git a/playbooks/setup_scanner.yml b/playbooks/setup_scanner.yml new file mode 100644 index 0000000..c422970 --- /dev/null +++ b/playbooks/setup_scanner.yml @@ -0,0 +1,15 @@ +--- +- name: Set up scanner + hosts: + scanners + become: yes + roles: + - geerlingguy.go + - offsec_scanning + vars: + go_version: "1.24.2" + go_platform: linux + go_arch: amd64 + go_tarball: go{{ go_version }}.{{ go_platform }}-{{ go_arch }}.tar.gz + go_download_url: https://dl.google.com/go/{{ go_tarball }} + go_checksum: '68097bd680839cbc9d464a0edce4f7c333975e27a90246890e9f1078c7e702ad' \ No newline at end of file diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..f8b3ba0 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,2 @@ +--- +- src: geerlingguy.go \ No newline at end of file diff --git a/roles/offsec_scanning/README.md b/roles/offsec_scanning/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/offsec_scanning/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/offsec_scanning/defaults/main.yml b/roles/offsec_scanning/defaults/main.yml new file mode 100644 index 0000000..c3694e1 --- /dev/null +++ b/roles/offsec_scanning/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for roles/offsec_scanning diff --git a/roles/offsec_scanning/handlers/main.yml b/roles/offsec_scanning/handlers/main.yml new file mode 100644 index 0000000..b7dd9a2 --- /dev/null +++ b/roles/offsec_scanning/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for roles/offsec_scanning diff --git a/roles/offsec_scanning/meta/main.yml b/roles/offsec_scanning/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/offsec_scanning/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/offsec_scanning/tasks/main.yml b/roles/offsec_scanning/tasks/main.yml new file mode 100644 index 0000000..ba04ede --- /dev/null +++ b/roles/offsec_scanning/tasks/main.yml @@ -0,0 +1,33 @@ +--- +# tasks file for roles/offsec_scanning +- name: Update package cache + apt: + update_cache: yes + when: ansible_os_family == 'Debian' + +- name: Install apt packages + package: + name: + - masscan + - nmap + - zmap + - jq + - wget + - git + - make + - build-essential + state: present + +- name: Clone zgrab2 repository + git: + repo: https://github.com/zmap/zgrab2.git + dest: /opt/zgrab2 + version: master + +- name: Build zgrab2 and install + ansible.builtin.shell: + cmd: | + . /etc/profile.d/go-path.sh + make + ln -s /opt/zgrab2/zgrab2 /usr/local/bin + chdir: "/opt/zgrab2" \ No newline at end of file diff --git a/roles/offsec_scanning/tests/inventory b/roles/offsec_scanning/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/offsec_scanning/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/offsec_scanning/tests/test.yml b/roles/offsec_scanning/tests/test.yml new file mode 100644 index 0000000..e130cff --- /dev/null +++ b/roles/offsec_scanning/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - roles/offsec_scanning diff --git a/roles/offsec_scanning/vars/main.yml b/roles/offsec_scanning/vars/main.yml new file mode 100644 index 0000000..da35575 --- /dev/null +++ b/roles/offsec_scanning/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for roles/offsec_scanning