From 46d46a4e3660a712800155fc1bb3776b4224e1e4 Mon Sep 17 00:00:00 2001 From: Pin Date: Sun, 2 Oct 2022 12:31:34 -0400 Subject: [PATCH] first functional commit --- .gitignore | 18 ++++ README.md | 33 +++++++ _libs/libbase.sh | 84 +++++++++++++++++ localImages/Dockerfile | 6 ++ localImages/init.sh | 14 +++ main.tf | 74 +++++++++++++++ requierments.txt | 7 ++ roles/CVE-2011-2523/.travis.yml | 29 ++++++ roles/CVE-2011-2523/README.md | 38 ++++++++ roles/CVE-2011-2523/defaults/main.yml | 2 + roles/CVE-2011-2523/files/vsftpd.conf | 114 +++++++++++++++++++++++ roles/CVE-2011-2523/files/vsftpd.service | 10 ++ roles/CVE-2011-2523/handlers/main.yml | 7 ++ roles/CVE-2011-2523/meta/kybus.yml | 4 + roles/CVE-2011-2523/meta/main.yml | 52 +++++++++++ roles/CVE-2011-2523/tasks/main.yml | 73 +++++++++++++++ roles/CVE-2011-2523/tests/inventory | 2 + roles/CVE-2011-2523/tests/test.yml | 5 + roles/CVE-2011-2523/vars/main.yml | 2 + roles/CVE-2019-10149/README.md | 38 ++++++++ roles/CVE-2019-10149/defaults/main.yml | 2 + roles/CVE-2019-10149/handlers/main.yml | 2 + roles/CVE-2019-10149/meta/kybus.yml | 4 + roles/CVE-2019-10149/meta/main.yml | 52 +++++++++++ roles/CVE-2019-10149/tasks/main.yml | 7 ++ roles/CVE-2019-10149/tests/inventory | 2 + roles/CVE-2019-10149/tests/test.yml | 5 + roles/CVE-2019-10149/vars/main.yml | 2 + roles/CVE-2021-3156/.travis.yml | 29 ++++++ roles/CVE-2021-3156/README.md | 38 ++++++++ roles/CVE-2021-3156/defaults/main.yml | 2 + roles/CVE-2021-3156/handlers/main.yml | 2 + roles/CVE-2021-3156/meta/main.yml | 52 +++++++++++ roles/CVE-2021-3156/tasks/main.yml | 27 ++++++ roles/CVE-2021-3156/tests/inventory | 2 + roles/CVE-2021-3156/tests/test.yml | 5 + roles/CVE-2021-3156/vars/main.yml | 2 + roles/test/.travis.yml | 29 ++++++ roles/test/README.md | 38 ++++++++ roles/test/defaults/main.yml | 2 + roles/test/handlers/main.yml | 2 + roles/test/meta/main.yml | 52 +++++++++++ roles/test/tasks/main.yml | 6 ++ roles/test/tests/inventory | 2 + roles/test/tests/test.yml | 5 + roles/test/vars/main.yml | 2 + run.sh | 106 +++++++++++++++++++++ setup.sh | 42 +++++++++ src/main.py | 39 ++++++++ templates/cloud_init.cfg | 16 ++++ templates/site.temp | 6 ++ templates/vars.temp | 22 +++++ 52 files changed, 1216 insertions(+) create mode 100644 .gitignore create mode 100644 _libs/libbase.sh create mode 100644 localImages/Dockerfile create mode 100755 localImages/init.sh create mode 100644 main.tf create mode 100644 requierments.txt create mode 100644 roles/CVE-2011-2523/.travis.yml create mode 100644 roles/CVE-2011-2523/README.md create mode 100644 roles/CVE-2011-2523/defaults/main.yml create mode 100644 roles/CVE-2011-2523/files/vsftpd.conf create mode 100644 roles/CVE-2011-2523/files/vsftpd.service create mode 100644 roles/CVE-2011-2523/handlers/main.yml create mode 100644 roles/CVE-2011-2523/meta/kybus.yml create mode 100644 roles/CVE-2011-2523/meta/main.yml create mode 100644 roles/CVE-2011-2523/tasks/main.yml create mode 100644 roles/CVE-2011-2523/tests/inventory create mode 100644 roles/CVE-2011-2523/tests/test.yml create mode 100644 roles/CVE-2011-2523/vars/main.yml create mode 100644 roles/CVE-2019-10149/README.md create mode 100644 roles/CVE-2019-10149/defaults/main.yml create mode 100644 roles/CVE-2019-10149/handlers/main.yml create mode 100644 roles/CVE-2019-10149/meta/kybus.yml create mode 100644 roles/CVE-2019-10149/meta/main.yml create mode 100644 roles/CVE-2019-10149/tasks/main.yml create mode 100644 roles/CVE-2019-10149/tests/inventory create mode 100644 roles/CVE-2019-10149/tests/test.yml create mode 100644 roles/CVE-2019-10149/vars/main.yml create mode 100644 roles/CVE-2021-3156/.travis.yml create mode 100644 roles/CVE-2021-3156/README.md create mode 100644 roles/CVE-2021-3156/defaults/main.yml create mode 100644 roles/CVE-2021-3156/handlers/main.yml create mode 100644 roles/CVE-2021-3156/meta/main.yml create mode 100644 roles/CVE-2021-3156/tasks/main.yml create mode 100644 roles/CVE-2021-3156/tests/inventory create mode 100644 roles/CVE-2021-3156/tests/test.yml create mode 100644 roles/CVE-2021-3156/vars/main.yml create mode 100644 roles/test/.travis.yml create mode 100644 roles/test/README.md create mode 100644 roles/test/defaults/main.yml create mode 100644 roles/test/handlers/main.yml create mode 100644 roles/test/meta/main.yml create mode 100644 roles/test/tasks/main.yml create mode 100644 roles/test/tests/inventory create mode 100644 roles/test/tests/test.yml create mode 100644 roles/test/vars/main.yml create mode 100755 run.sh create mode 100755 setup.sh create mode 100644 src/main.py create mode 100644 templates/cloud_init.cfg create mode 100644 templates/site.temp create mode 100644 templates/vars.temp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d007885 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +**/*.swp +**/*.lock.hcl + +download/ + +kybus.conf +.kybusenv + +.terraform/ +**/*.tfstate +**/*.tfstate.backup +vars.tf +main.tf + +**/*.tar.gz + +src/download/ +venv/ diff --git a/README.md b/README.md index 980ee7f..9b447aa 100644 --- a/README.md +++ b/README.md @@ -1 +1,34 @@ # Kybus + +Kybus is a repository + +## Requirements + +Docker, or podman with appropriate aliases is required to be installed. +Docker version `20.10.21` is the version using during testing; however, most version should work. + +Python3 is required for certain support functions; version `3.10.8` was used during testing. + +Libvirt is used for VM deployment; version `8.9.0` was used during testing. + +All versions mentioned above are only what was used during testing, other versions will mostly work. + +### Quick Reference + +- Docker or podman with appropriate aliases +- Python3 +- libvirt/virt-manager + +## Getting Started + +Running `setup.sh` will ensure requisites are installed and download needed VM images. +The Kybus container image will also be generated during this process + +## Writing a Plugin + +Initial plugin structure can be generated using `ansible-galaxy role init {plugin name}`. +Plugin names are suggested to be the relavent CVE record; however, certain plugins exist as helpers and may deviate. + +Once the plugin is created + +## diff --git a/_libs/libbase.sh b/_libs/libbase.sh new file mode 100644 index 0000000..239636e --- /dev/null +++ b/_libs/libbase.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +set -e + +# Function: EnsureRoot +# Ensures that commands are being executed as root. +function EnsureRoot { + if (( EUID != 0 )); then + echo "[X] Must run as root" + exit 100 + fi +} + +# Function: EchoBlanks +# Echo number of blank lines indicated by input +# +# Parameters: +# ${1} - The number of blank lines to echo +function EchoBlanks { + local num_lines + + # Strip non-numbers from input + num_lines="${1//[^0-9]/}" + if [[ -z "${num_lines}" ]]; then + num_lines=0 + fi + + if [[ "${num_lines}" -ne 0 ]]; then + for ((i = 0; i < num_lines; i++)); do + echo "" + done + fi +} + +# Function: StatusEcho +# Echos out provided text in inverted colors so it stands out +# +# Parameters: +# ${1} - The text to send +# ${2} - The number of leading empty lines before the echo +# ${3} - The number of trailing empty lines after the echo +function StatusEcho { + EchoBlanks "${2}" + echo -e "\e[7m${1} \e[0m" + EchoBlanks "${3}" +} + +# Function: WarningEcho +# Echos out provided text as white letters on a red background so it stands out. +# +# Parameters: +# ${1} - The text to send +# ${2} - The number of leading empty lines before the echo +# ${3} - The number of trailing empty lines after the echo +function WarningEcho { + EchoBlanks "${2}" + echo -e "\e[97m\e[41m${1} \e[0m" + EchoBlanks "${3}" +} + +# Function: CyanEcho +# Echos out provided text as Light Cyan letters on a black background so it stands out. +# +# Parameters: +# ${1} - The text to send +# ${2} - The number of leading empty lines before the echo +# ${3} - The number of trailing empty lines after the echo +function CyanEcho { + EchoBlanks "${2}" + echo -e "\e[96m\e[40m${1} \e[0m" + EchoBlanks "${3}" +} + +# Function: pushd +# Overrides default pushd functionatlity to suppress console messages. +function pushd { + command pushd "$@" >/dev/null +} + +# Function: popd +# Overrides default popd functionatlity to suppress console messages. +function popd { + command popd >/dev/null +} diff --git a/localImages/Dockerfile b/localImages/Dockerfile new file mode 100644 index 0000000..f979b7e --- /dev/null +++ b/localImages/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine:3.16 + +RUN apk update && \ + apk add --no-cache terraform python3 libvirt-qemu qemu xorriso ansible gettext + +COPY init.sh / diff --git a/localImages/init.sh b/localImages/init.sh new file mode 100755 index 0000000..41048eb --- /dev/null +++ b/localImages/init.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +cd /mnt || exit 1 + +envsubst < templates/site.temp > site.yml +envsubst < templates/vars.temp > vars.tf + +terraform init + +terraform destroy -auto-approve + +terraform apply -auto-approve + +rm site.yml diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..2a72bf2 --- /dev/null +++ b/main.tf @@ -0,0 +1,74 @@ +terraform { + required_providers { + libvirt = { + source = "dmacvicar/libvirt" + } + } +} + +provider "libvirt" { + uri = "qemu:///system" +} + +data "template_file" "user_data" { + template = "${file("${path.module}/templates/cloud_init.cfg")}" + vars = { + init_ssh_auth_key = var.init_ssh_auth_key + init_user_name = var.init_user_name + } +} + +resource "libvirt_cloudinit_disk" "kybus_commoninit" { + name = "kybus_commoninit.iso" + pool = "default" + user_data = "${data.template_file.user_data.rendered}" +} + +resource "libvirt_volume" "kybus_kybus" { + name = "kybus_kybus" + pool = "default" + source = var.kybus_source + format = "qcow2" +} + +resource "libvirt_volume" "kybus_kybus_resized" { + name = "kybus_kybus_resized" + base_volume_id = libvirt_volume.kybus_kybus.id + pool = "default" + size = var.base_disk_size +} + +resource "libvirt_domain" "kybus_kybus_vm" { + name = "kybus_kybus" + memory = var.base_ram_size + vcpu = 2 + + network_interface { + network_name = "default" + wait_for_lease = true + } + + disk { + volume_id = "${libvirt_volume.kybus_kybus_resized.id}" + } + + cloudinit = "${libvirt_cloudinit_disk.kybus_commoninit.id}" + + console { + type = "pty" + target_type = "serial" + target_port = "0" + } + + graphics { + type = "spice" + listen_type = "address" + autoport = true + } + + provisioner "local-exec" { + command = "sleep 10 && ANSIBLE_STDOUT_CALLBACK=yaml ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u '${var.init_user_name}' --private-key /root/.ssh/key -i '${self.network_interface[0].addresses[0]},' site.yml" + } + +} + diff --git a/requierments.txt b/requierments.txt new file mode 100644 index 0000000..11b77c3 --- /dev/null +++ b/requierments.txt @@ -0,0 +1,7 @@ +args==0.1.0 +certifi==2022.6.15.2 +charset-normalizer==2.1.1 +clint==0.5.1 +idna==3.4 +requests==2.28.1 +urllib3==1.26.12 diff --git a/roles/CVE-2011-2523/.travis.yml b/roles/CVE-2011-2523/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/roles/CVE-2011-2523/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/roles/CVE-2011-2523/README.md b/roles/CVE-2011-2523/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/CVE-2011-2523/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/CVE-2011-2523/defaults/main.yml b/roles/CVE-2011-2523/defaults/main.yml new file mode 100644 index 0000000..9c531c9 --- /dev/null +++ b/roles/CVE-2011-2523/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for CVE-2011-2523 diff --git a/roles/CVE-2011-2523/files/vsftpd.conf b/roles/CVE-2011-2523/files/vsftpd.conf new file mode 100644 index 0000000..0225e69 --- /dev/null +++ b/roles/CVE-2011-2523/files/vsftpd.conf @@ -0,0 +1,114 @@ +# Example config file /etc/vsftpd.conf +# +# The default compiled in settings are fairly paranoid. This sample file +# loosens things up a bit, to make the ftp daemon more usable. +# Please see vsftpd.conf.5 for all compiled in defaults. +# +# READ THIS: This example file is NOT an exhaustive list of vsftpd options. +# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's +# capabilities. +# +# Allow anonymous FTP? (Beware - allowed by default if you comment this out). +anonymous_enable=NO +# +# Uncomment this to allow local users to log in. +local_enable=YES +# +# Uncomment this to enable any form of FTP write command. +#write_enable=YES +# +# Default umask for local users is 077. You may wish to change this to 022, +# if your users expect that (022 is used by most other ftpd's) +#local_umask=022 +# +# Uncomment this to allow the anonymous FTP user to upload files. This only +# has an effect if the above global write enable is activated. Also, you will +# obviously need to create a directory writable by the FTP user. +#anon_upload_enable=YES +# +# Uncomment this if you want the anonymous FTP user to be able to create +# new directories. +#anon_mkdir_write_enable=YES +# +# Activate directory messages - messages given to remote users when they +# go into a certain directory. +dirmessage_enable=YES +# +# Activate logging of uploads/downloads. +xferlog_enable=YES +# +# Make sure PORT transfer connections originate from port 20 (ftp-data). +connect_from_port_20=YES +# +# If you want, you can arrange for uploaded anonymous files to be owned by +# a different user. Note! Using "root" for uploaded files is not +# recommended! +#chown_uploads=YES +#chown_username=whoever +# +# You may override where the log file goes if you like. The default is shown +# below. +#xferlog_file=/var/log/vsftpd.log +# +# If you want, you can have your log file in standard ftpd xferlog format. +# Note that the default log file location is /var/log/xferlog in this case. +#xferlog_std_format=YES +# +# You may change the default value for timing out an idle session. +#idle_session_timeout=600 +# +# You may change the default value for timing out a data connection. +#data_connection_timeout=120 +# +# It is recommended that you define on your system a unique user which the +# ftp server can use as a totally isolated and unprivileged user. +#nopriv_user=ftpsecure +# +# Enable this and the server will recognise asynchronous ABOR requests. Not +# recommended for security (the code is non-trivial). Not enabling it, +# however, may confuse older FTP clients. +#async_abor_enable=YES +# +# By default the server will pretend to allow ASCII mode but in fact ignore +# the request. Turn on the below options to have the server actually do ASCII +# mangling on files when in ASCII mode. +# Beware that on some FTP servers, ASCII support allows a denial of service +# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd +# predicted this attack and has always been safe, reporting the size of the +# raw file. +# ASCII mangling is a horrible feature of the protocol. +#ascii_upload_enable=YES +#ascii_download_enable=YES +# +# You may fully customise the login banner string: +#ftpd_banner=Welcome to blah FTP service. +# +# You may specify a file of disallowed anonymous e-mail addresses. Apparently +# useful for combatting certain DoS attacks. +#deny_email_enable=YES +# (default follows) +#banned_email_file=/etc/vsftpd.banned_emails +# +# You may specify an explicit list of local users to chroot() to their home +# directory. If chroot_local_user is YES, then this list becomes a list of +# users to NOT chroot(). +#chroot_local_user=YES +#chroot_list_enable=YES +# (default follows) +#chroot_list_file=/etc/vsftpd.chroot_list +# +# You may activate the "-R" option to the builtin ls. This is disabled by +# default to avoid remote users being able to cause excessive I/O on large +# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume +# the presence of the "-R" option, so there is a strong case for enabling it. +#ls_recurse_enable=YES +# +# When "listen" directive is enabled, vsftpd runs in standalone mode and +# listens on IPv4 sockets. This directive cannot be used in conjunction +# with the listen_ipv6 directive. +listen=YES +# +# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6 +# sockets, you must run two copies of vsftpd with two configuration files. +# Make sure, that one of the listen options is commented !! +#listen_ipv6=YES diff --git a/roles/CVE-2011-2523/files/vsftpd.service b/roles/CVE-2011-2523/files/vsftpd.service new file mode 100644 index 0000000..38554ac --- /dev/null +++ b/roles/CVE-2011-2523/files/vsftpd.service @@ -0,0 +1,10 @@ +[Unit] +Description=Vsftpd ftp daemon +After=network.target + +[Service] +ExecStart=/usr/local/sbin/vsftpd /etc/vsftpd.conf + +[Install] +WantedBy=multi-user.target + diff --git a/roles/CVE-2011-2523/handlers/main.yml b/roles/CVE-2011-2523/handlers/main.yml new file mode 100644 index 0000000..16fd0d4 --- /dev/null +++ b/roles/CVE-2011-2523/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: VSFTPD Service + ansible.builtin.service: + name: vsftpd + enabled: "yes" + state: restarted +... diff --git a/roles/CVE-2011-2523/meta/kybus.yml b/roles/CVE-2011-2523/meta/kybus.yml new file mode 100644 index 0000000..a3bdaf8 --- /dev/null +++ b/roles/CVE-2011-2523/meta/kybus.yml @@ -0,0 +1,4 @@ +--- +image: ubuntu-20.04-server-cloudimg-amd64.img +holding: bad var +... diff --git a/roles/CVE-2011-2523/meta/main.yml b/roles/CVE-2011-2523/meta/main.yml new file mode 100644 index 0000000..b68de20 --- /dev/null +++ b/roles/CVE-2011-2523/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: Spencer + 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/CVE-2011-2523/tasks/main.yml b/roles/CVE-2011-2523/tasks/main.yml new file mode 100644 index 0000000..e418052 --- /dev/null +++ b/roles/CVE-2011-2523/tasks/main.yml @@ -0,0 +1,73 @@ +--- +- name: Install build deps + ansible.builtin.package: + name: + - make + - gcc + state: present + +- name: Create libcrypt symlink + ansible.builtin.file: + src: /lib/x86_64-linux-gnu/libcrypt.so.1 + dest: /lib/libcrypt.so + owner: root + group: root + state: link + +- name: Create Build Directory + ansible.builtin.file: + path: /tmp/vsftpd_build + state: directory + mode: '0755' + +- name: Unarchive VSFTPD + ansible.builtin.unarchive: + src: vsftpd-2.3.4.tar.gz + dest: /tmp/vsftpd_build + +- name: Create install reqs + ansible.builtin.file: + path: "{{ install_dir }}" + state: directory + loop: + - /usr/local/man/man8 + - /usr/local/man/man5 + - /usr/share/empty + loop_control: + loop_var: install_dir + +- name: Make build and install + make: + chdir: /tmp/vsftpd_build/vsftpd-2.3.4 + target: "{{ make_target }}" + loop: + - vsftpd + - install + loop_control: + loop_var: make_target + +- name: Copy configuration file + ansible.builtin.copy: + src: vsftpd.conf + dest: /etc/vsftpd.conf + owner: root + group: root + mode: '0644' + +- name: Create FTP user + ansible.builtin.user: + name: ftp + home: "/usr/share/empty" + create_home: no + +- name: Copy service file + ansible.builtin.copy: + src: vsftpd.service + dest: /etc/systemd/system/vsftpd.service + owner: root + group: root + mode: '0644' + notify: + - VSFTPD Service +... +# tasks file for CVE-2011-2523 diff --git a/roles/CVE-2011-2523/tests/inventory b/roles/CVE-2011-2523/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/CVE-2011-2523/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/CVE-2011-2523/tests/test.yml b/roles/CVE-2011-2523/tests/test.yml new file mode 100644 index 0000000..903f8b9 --- /dev/null +++ b/roles/CVE-2011-2523/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - CVE-2011-2523 diff --git a/roles/CVE-2011-2523/vars/main.yml b/roles/CVE-2011-2523/vars/main.yml new file mode 100644 index 0000000..0c2ccf4 --- /dev/null +++ b/roles/CVE-2011-2523/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for CVE-2011-2523 diff --git a/roles/CVE-2019-10149/README.md b/roles/CVE-2019-10149/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/CVE-2019-10149/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/CVE-2019-10149/defaults/main.yml b/roles/CVE-2019-10149/defaults/main.yml new file mode 100644 index 0000000..ba82878 --- /dev/null +++ b/roles/CVE-2019-10149/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for CVE-2019-10149 diff --git a/roles/CVE-2019-10149/handlers/main.yml b/roles/CVE-2019-10149/handlers/main.yml new file mode 100644 index 0000000..45f1bc0 --- /dev/null +++ b/roles/CVE-2019-10149/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for CVE-2019-10149 diff --git a/roles/CVE-2019-10149/meta/kybus.yml b/roles/CVE-2019-10149/meta/kybus.yml new file mode 100644 index 0000000..a3bdaf8 --- /dev/null +++ b/roles/CVE-2019-10149/meta/kybus.yml @@ -0,0 +1,4 @@ +--- +image: ubuntu-20.04-server-cloudimg-amd64.img +holding: bad var +... diff --git a/roles/CVE-2019-10149/meta/main.yml b/roles/CVE-2019-10149/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/CVE-2019-10149/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/CVE-2019-10149/tasks/main.yml b/roles/CVE-2019-10149/tasks/main.yml new file mode 100644 index 0000000..c51310b --- /dev/null +++ b/roles/CVE-2019-10149/tasks/main.yml @@ -0,0 +1,7 @@ +--- +- name: + unarchive: + src: https://downloads.exim.org/exim4/old/exim-4.90.tar.gz + dest: /tmp + remote_src: yes +... diff --git a/roles/CVE-2019-10149/tests/inventory b/roles/CVE-2019-10149/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/CVE-2019-10149/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/CVE-2019-10149/tests/test.yml b/roles/CVE-2019-10149/tests/test.yml new file mode 100644 index 0000000..be57269 --- /dev/null +++ b/roles/CVE-2019-10149/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - CVE-2019-10149 diff --git a/roles/CVE-2019-10149/vars/main.yml b/roles/CVE-2019-10149/vars/main.yml new file mode 100644 index 0000000..239b1aa --- /dev/null +++ b/roles/CVE-2019-10149/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for CVE-2019-10149 diff --git a/roles/CVE-2021-3156/.travis.yml b/roles/CVE-2021-3156/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/roles/CVE-2021-3156/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/roles/CVE-2021-3156/README.md b/roles/CVE-2021-3156/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/CVE-2021-3156/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/CVE-2021-3156/defaults/main.yml b/roles/CVE-2021-3156/defaults/main.yml new file mode 100644 index 0000000..be6a43c --- /dev/null +++ b/roles/CVE-2021-3156/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for CVE-2021-3156 diff --git a/roles/CVE-2021-3156/handlers/main.yml b/roles/CVE-2021-3156/handlers/main.yml new file mode 100644 index 0000000..8cd2db5 --- /dev/null +++ b/roles/CVE-2021-3156/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for CVE-2021-3156 diff --git a/roles/CVE-2021-3156/meta/main.yml b/roles/CVE-2021-3156/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/CVE-2021-3156/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/CVE-2021-3156/tasks/main.yml b/roles/CVE-2021-3156/tasks/main.yml new file mode 100644 index 0000000..fbb24b1 --- /dev/null +++ b/roles/CVE-2021-3156/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: Installs Build Deps + package: + name: + - make + - gcc + state: present +- name: Download sudo Package 1.9.5p1 + unarchive: + src: https://www.sudo.ws/dist/sudo-1.9.5p1.tar.gz + dest: /tmp/ + remote_src: yes + +- name: Build Sudo - Configure + command: ./configure + args: + chdir: /tmp/sudo-1.9.5p1 + +- name: Build Sudo + make: + chdir: /tmp/sudo-1.9.5p1 + +- name: Build Sudo - Make install + make: + chdir: /tmp/sudo-1.9.5p1 + target: install +... diff --git a/roles/CVE-2021-3156/tests/inventory b/roles/CVE-2021-3156/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/CVE-2021-3156/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/CVE-2021-3156/tests/test.yml b/roles/CVE-2021-3156/tests/test.yml new file mode 100644 index 0000000..32f873b --- /dev/null +++ b/roles/CVE-2021-3156/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: all + become: "true" + roles: + - CVE-2021-3156 diff --git a/roles/CVE-2021-3156/vars/main.yml b/roles/CVE-2021-3156/vars/main.yml new file mode 100644 index 0000000..56f2879 --- /dev/null +++ b/roles/CVE-2021-3156/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for CVE-2021-3156 diff --git a/roles/test/.travis.yml b/roles/test/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/roles/test/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/roles/test/README.md b/roles/test/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/test/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/test/defaults/main.yml b/roles/test/defaults/main.yml new file mode 100644 index 0000000..9457e0c --- /dev/null +++ b/roles/test/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for test diff --git a/roles/test/handlers/main.yml b/roles/test/handlers/main.yml new file mode 100644 index 0000000..de668c9 --- /dev/null +++ b/roles/test/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for test diff --git a/roles/test/meta/main.yml b/roles/test/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/test/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/test/tasks/main.yml b/roles/test/tasks/main.yml new file mode 100644 index 0000000..56aff19 --- /dev/null +++ b/roles/test/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: Debug + debug: + var: ansible +... +# tasks file for test diff --git a/roles/test/tests/inventory b/roles/test/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/test/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/test/tests/test.yml b/roles/test/tests/test.yml new file mode 100644 index 0000000..ec10bb2 --- /dev/null +++ b/roles/test/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - test diff --git a/roles/test/vars/main.yml b/roles/test/vars/main.yml new file mode 100644 index 0000000..8b5728b --- /dev/null +++ b/roles/test/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..a22baaf --- /dev/null +++ b/run.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +script_file_path="$(realpath "${0}")" +script_dir_path="$(dirname "${script_file_path}")" + +pushd "${script_dir_path}" >/dev/null || exit 1 + +# shellcheck disable=SC1091 +source ./_libs/libbase.sh +# shellcheck disable=SC1091 +source ./kybus.conf + +function initKybus { + StatusEcho "Cleaning up old Environment" + rm -f .kybusenv >/dev/null +} + +function parseKybusRole { + metaKybus=$(cat "roles/${1}/meta/kybus.yml") + + KYBUS_BASE_IMAGE="download/$(echo "${metaKybus}" | grep "^image:" | cut -d " " -f 2-)" + setKybusVariable "KYBUS_BASE_IMAGE" "${KYBUS_BASE_IMAGE}" + + return +} + +function setKybusVariable { + if [[ -z "${1}" || -z ${2} ]]; then + WarningEcho "Variables not passed to setKybusVariable correctly" + exit 1 + fi + + # Create variable file if one does not exist + if [[ ! -e .kybusenv ]]; then + touch .kybusenv + fi + + StatusEcho "Setting ${1}" + + # Set blank variable if it does not already exist + grep "${1}" .kybusenv >/dev/null || echo "${1}=" >>.kybusenv + + # Set variable + sed -i "s|${1}=.*|${1}=${2}|" .kybusenv >/dev/null + + return +} + +function findCVE { + StatusEcho "Attempting to find ${1}" + ls "roles/${1}" &>/dev/null || failed=1 + + if (( failed == 1 )); then + WarningEcho "CVE - ${1} not found" + exit 1 + fi + + return +} + +function ArgParse { + while (("${#}")); do + case "${1}" in + --cve | -c) + shift + findCVE "${1}" && setKybusVariable "KYBUS_SELECTED_CVE" "${1}" + export KYBUS_SELECTED_CVE=${1} + shift + ;; + --help | -h) + shift + WarningEcho "Not implemented" + ;; + --list-roles) + shift + local roles + roles=$(find roles/* -maxdepth 0 | sed 's|roles/||g') + CyanEcho "Available Roles:" + CyanEcho "${roles}" + unset roles + exit 0 + ;; + --destroy) + terraform destroy -auto-approve + exit 0 + shift + ;; + *) + shift + ;; + esac + done + + return +} + +#initKybus +ArgParse "${@}" +parseKybusRole "${KYBUS_SELECTED_CVE}" + +docker run --rm -v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock -v "$(pwd):/mnt" -v "${SSH_KEY_FILE}:/root/.ssh/key" --env-file kybus.conf --env-file .kybusenv kybus:latest ./init.sh +KYBUS_ADDRESS=$(grep -A 1 addresses /dev/null; then + exitFailure "python3 not installed" + fi + + if ! command docker &>/dev/null; then + exitFailure "docker not installed" + fi + + if [[ ! -e /var/run/libvirt/libvirt-sock ]]; then + exitFailure "libvirt-socket not detected" + fi +} + +function setupEnvironment { + checkDependencies + + if [[ ! -d venv ]]; then + python3 -m venv venv + fi + + # shellcheck disable=SC1091 + . venv/bin/activate + + pip3 install -r ./requierments.txt + +} + +function dockerImageInit { + cd ./localImages || exitFailure "change dir failed" + docker build . -t kybus:latest +} + +setupEnvironment +dockerImageInit diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..59a55b8 --- /dev/null +++ b/src/main.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 +import os +import requests +from clint.textui import progress + +def downloadArtifact(artifactURL: str, downloadPath: str): + print("holding") + +def downloadImage(imageURL: str): + createDownloadFolder() + + # Obtain last segment of URL for file name + fileName = imageURL.split("/")[-1] + + if not os.path.exists("download/" + fileName): + print("Downloading - {}".format(imageURL)) + r = requests.get(imageURL, stream=True) + + with open("download/" + fileName, "wb") as fd: + totalLength = int(r.headers.get('content-length')) + for ch in progress.bar(r.iter_content(chunk_size = 2048), expected_size=(totalLength/2048)): + if ch: + fd.write(ch) + fd.close() + return + + +def createDownloadFolder(): + if not os.path.isdir("download"): + os.mkdir("download") + return + + +#downloadImage("https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2") +#downloadImage("https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img") +#downloadImage("https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img") +downloadImage("http://file.pinfosec.local/file/vm-images/CentOS-7-x86_64-GenericCloud.qcow2") +downloadImage("http://file.pinfosec.local/file/vm-images/jammy-server-cloudimg-amd64.img") +downloadImage("http://file.pinfosec.local/file/vm-images/ubuntu-20.04-server-cloudimg-amd64.img") diff --git a/templates/cloud_init.cfg b/templates/cloud_init.cfg new file mode 100644 index 0000000..d43968f --- /dev/null +++ b/templates/cloud_init.cfg @@ -0,0 +1,16 @@ +#cloud-config + +users: + - name: ${init_user_name} + groups: wheel + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + shell: /bin/bash + ssh_authorized_keys: + - ${init_ssh_auth_key} + +growpart: + mode: auto + devices: ['/'] + +package_update: true +package_upgrade: false diff --git a/templates/site.temp b/templates/site.temp new file mode 100644 index 0000000..5cb9677 --- /dev/null +++ b/templates/site.temp @@ -0,0 +1,6 @@ +--- +- hosts: all + become: true + roles: + - ${KYBUS_SELECTED_CVE} +... diff --git a/templates/vars.temp b/templates/vars.temp new file mode 100644 index 0000000..03b7e02 --- /dev/null +++ b/templates/vars.temp @@ -0,0 +1,22 @@ +variable "init_ssh_auth_key" { + default = ${SSH_PUB_KEY} +} + +variable "init_user_name" { + default = "${SSH_DEFAULT_USER}" +} + +# 30GB default (Size in bytes) +variable "base_disk_size" { + default = ${VM_DISK_SIZE} +} + +# 4GB of RAM per deployed host (Size in bytes) +variable "base_ram_size" { + default = ${VM_RAM_SIZE} +} + +variable "kybus_source" { + default = "${KYBUS_BASE_IMAGE}" +} +