From 5710f284ba8188bbca2471af713fbe40481e1d24 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sun, 26 Jul 2026 18:35:20 -0700 Subject: [PATCH] Add automatic removal of metasploit if it is no longer true. --- local.yml | 1 - tasks/general/software/metasploit.yml | 30 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/local.yml b/local.yml index e49e7e2..1289339 100644 --- a/local.yml +++ b/local.yml @@ -109,7 +109,6 @@ when: ansible_system == "FreeBSD" - include_tasks: tasks/general/software/metasploit.yml - when: pentesting == true when: provision == true diff --git a/tasks/general/software/metasploit.yml b/tasks/general/software/metasploit.yml index 3207d8e..d61334e 100644 --- a/tasks/general/software/metasploit.yml +++ b/tasks/general/software/metasploit.yml @@ -5,6 +5,7 @@ set_fact: metasploit_installer: msfinstall when: ansible_system in ("Linux", "Darwin") + and pentesting == true - name: General | Software | Metasploit | Check Install Status stat: @@ -18,8 +19,9 @@ - "mv -fv /usr/share/keyrings/metasploit-framework.gpg /tmp/apt/metasploit-framework.gpg.old" - "mv -fv /etc/apt/sources.list.d/metasploit-framework.list /tmp/apt/metasploit-framework.list.old" - "mv -fv /etc/apt/preferences.d/pin-metasploit.pref /tmp/apt/pin-metasploit.pref.old" - when: ansible_system in ("Linux") and - not metasploit_status.stat.exists + when: ansible_system in ("Linux") and ansible_pkg_mgr == "apt" + and not metasploit_status.stat.exists + and pentesting == true ignore_errors: true - name: General | Software | Metasploit | Install @@ -28,7 +30,25 @@ - "curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > {{ metasploit_installer }}" - "chmod 755 {{ metasploit_installer }}" - "mkdir -p {{ global_bin }}" - - "mv -fv ./msfinstall {{ global_bin }}/{{ metasploit_installer }}" + - "mv -fv ./{{ metasploit_installer }} {{ global_bin }}/{{ metasploit_installer }}" - yes y | "{{ global_bin }}/{{ metasploit_installer }}" - when: ansible_system in ("Linux", "Darwin") and - not metasploit_status.stat.exists + when: ansible_system in ("Linux", "Darwin") + and not metasploit_status.stat.exists + and pentesting == true + +- name: General | Software | Metasploit | Remove (Darwin) + shell: "{{ item }}" + loop: + - "/opt/metasploit-framework/bin/msfremove" + when: ansible_system in ("Darwin") + and not metasploit_status.stat.exists + and pentesting == false + +- name: General | Software | Metasploit | Remove (APT) + shell: "{{ item }}" + loop: + - "apt purge metasploit-framework" + - "apt autoremove --purge" + when: ansible_system in ("Linux") and ansible_pkg_mgr == "apt" + and not metasploit_status.stat.exists + and pentesting == false