安装 Ansible

1
2
3
sudo apt-add-repository -y ppa:ansible/ansible
sudo apt update
sudo apt install -y ansible

执行模块

通过执行模块内的分控脚本先批量上分控,再通过命令批量执行 playbook 安装模块:

1
ansible-playbook servers -i inventory.ini  EsE.yml

模块集成

以下是模块集成列表:

  • httprobe:获取域列表并探测工作的 HTTP 和 HTTPS 服务器
  • Nuclei:基于模板的快速漏洞扫描器
  • subfinder:子域名扫描工具
  • xray:功能强大的安全评估工具和漏洞扫描工具
  • vscan:
    • 快速的端口扫描、指纹探测功能
    • 快速的登录密码爆破功能
    • 快速的 POC 检测功能
    • 快速的敏感文件检测功能
    • 轻量、开源、跨平台使用
    • 支持指纹 650(eHole) + 3129(本地) + 3053(wappalyzergo) = 6832 条
    • 支持 Xray 和 Nuclei 的 POC 检测
    • 支持多种类型的输入 - STDIN/HOST/IP/CIDR/URL/TXT
    • 支持多种类型的输出 - JSON/TXT/CSV/STDOUT

特点

命令简介

以下是常用命令列表:

  • 执行远程主机上的 ls 命令

    1
    ansible servers -i inventory.ini -a "ls"
  • 带管道命令请使用这个

    1
    ansible  servers -i inventory.ini  -m shell -a "cat url.txt | subfinder -silent | httprobe -c 200" > result.txt
  • 执行远程主机上的命令并将结果输出到文件中

    1
    nohup ansible servers -i inventory.ini -a "df -h" > result.txt  &
  • 注意:Ansible 的默认远程 Shell 是 /bin/sh,如果要使用其他 Shell,可以在命令中指定。例如,在 /bin/bash Shell 中运行命令

    1
    ansible servers -i inventory.ini -a "bash -c 'echo Hello, Ansible!'"
  • 传输文件 q.sh 到指定目录

    1
    ansible servers -i inventory.ini -m copy -a "src=/root/q.sh dest=/q.sh"
  • 执行 playbook

    1
    ansible-playbook  -i inventory.ini  EsE.yml
  • 在使用环境中创建 inventory.ini 文件

    1
    2
    3
    [servers] #模块安装默认使用分组
    s1 ansible_host=127.0.0.1 ansible_user=root #s1是名称可以自行修改
    s2 ansible_host=127.0.0.1 ansible_user=root
  • 使用单台设备或者选中设备

    img

    1
    ansible s1:s2 -i e.ini  -m shell -a "pwd"
  • 结束 Ansible 线程

    1
    ps -ef | grep ansible | awk '{print $2}' | xargs kill
  • 结束 Ansible-playbook 线程

    1
    ps -ef | grep ansible-playbook | awk '{print $2}' | xargs kill