使用 ansible expect 创建 nessus 用户 (nessuscli) [英] using ansible expect to create nessus user (nessuscli)

查看:33
本文介绍了使用 ansible expect 创建 nessus 用户 (nessuscli)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ansible expect 为我的 nessus 创建一个用户(通过使用 nessuscli).期望应该回答以下几个问题(我添加了数字 1-5).我的期望卡在数字 5.数字 5 的最后一个字母是(用户可以设置一个空规则集)",然后是下一行(回车).这导致了问题,因为我不知道如何告诉期望有一个短语后跟下一行.我试过 \r \n 但没有一个成功!任何治疗表示赞赏.

I'm using ansible expect to create a user for my nessus (by using the nessuscli). the expect should answer few question as below (I added the numbers 1-5). My expect get stuck at number 5. the last letters of number 5 is the "(the user can have an empty rules set)" and then the next line (carriage return). This makes the issue as I dont know how to tell expect that there is a phrase that is followed by a next line. I tried \r \n and none of them worked! any healp is appreciated.

另外,你可以在下面看到我的 ansible 代码.

Also, you can see my ansible code below.

谢谢

你可以在这里看到nessus cli propmt的截图:nessucli propmpt 截图

you can see the screenshot of the nessus cli propmt here: screenshot of nessucli propmpt

============ Nessuscli adduser 提示==========

============ Nessuscli adduser Prompt(s) ==========

1- 登录:

2- 登录密码:

3- 登录密码(再次):

3- Login password (again):

4- 您是否希望此用户成为 Nessus 的系统管理员"用户(可以上传插件等)?(y/n) [n]: y

4- Do you want this user to be a Nessus 'system administrator' user (can upload plugins, etc.)? (y/n) [n]: y

5- 用户规则

nessusd 有一个规则系统,允许您限制主机该测试有权进行测试.例如,你可能想要他只能扫描自己的主机.

nessusd has a rules system which allows you to restrict the hosts that test has the right to test. For instance, you may want him to be able to scan his own host only.

有关规则语法,请参阅 Nessus 命令行参考

Please see the Nessus Command Line Reference for the rules syntax

输入此用户的规则,完成后输入一个空行:(用户可以设置一个空的规则)

Enter the rules for this user, and enter a BLANK LINE once you are done : (the user can have an empty rules set)

====================================================

===================================================

我的 Ansible 代码:

My Ansible Code:

名称:创建nessus用户

name: create nessus user

expect:
  command: /opt/nessus/sbin/nessuscli adduser
  responses:
    'Login: ': "{{nessus_username}}" # answer number 1
    'Login password: ': "{{nessus_pass}}" # answer number 2
    'Login password \(again\): ': "{{nessus_pass}}" # answer number 3
    '\[n\]: ': 'y' # answer number 4
    'set\)\\n ': "\n" # answer number 5 which doesnt work
    '\[n\]: ': 'y' # answer the next propmpt (not in question and works)

推荐答案

经过多次修改后,我做到了:

After much tinkering, this did it for me:

  - name: Add user
    expect:
      echo: yes
      timeout: 5
      command: "{{ nessus_cli_bin }} adduser"
      responses:
        (.*)Login(.*): "{{ nessus_user }}"
        (.*)Login password(.*): "{{ nessus_pass }}"
        (.*)Login password(.*): "{{ nessus_pass }}"
        (.*)system administrator(.*): "y"
        (.*)rules set(.*): "\n"
        (.*)ok(.*): "y"

这篇关于使用 ansible expect 创建 nessus 用户 (nessuscli)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆