【问题标题】:Ansible privilege escalation with limited sudo有限 sudo 的 Ansible 权限提升
【发布时间】:2020-12-28 15:21:11
【问题描述】:

在我的公司,我们有有限的 root 访问权限,通过这种方式在 sudoers.d 上:

user hostname =(root) PASSWD: /bin/su

我正在尝试使 ansible 模仿:

all:
  vars:
    ansible_connection: ssh
    ansible_become: true
    ansible_become_pass: 'password'
    become_flags: '/bin/su - root /bin/bash -c'

worker:
  hosts:
    hostname

但是,我所做的每一个证明都以这个错误结束:

hostname | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "module_stderr": "Shared connection to hostname closed.\r\n",
    "module_stdout": "\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

我已阅读有关权限升级和受限 sudo 的信息: ansible privilege escalation

但是,在主机上,我们可以通过这种方式启动任何 sudo 命令:

 sudo su -s /bin/sh -c "ls"

有没有办法让ansible使用这种方法还是不可能?

谢谢

【问题讨论】:

  • 只检查这里:你唯一能做的就是通过/bin/su成为root,你需要密码吗?

标签: ansible su


【解决方案1】:

可以,但不推荐,因为它需要root的密码:

all:
  vars:
    ansible_connection: ssh
    ansible_become: true
    ansible_become_pass: 'root password'
    ansible_become_method: su
    become_flags: '-s /bin/bash'

在客户端的文件/etc/sudoers.d/ansible文件中是:

ansible hostname =(root) PASSWD: /bin/su

运行以下命令以显示升级工作:

$ ansible -m shell -a "whoami" Client1 
Client1 | CHANGED | rc=0 >>
root

$ ansible -m shell -a "who am i" Client1 
Client1 | CHANGED | rc=0 >>
ansible  pts/0        2020-12-28 19:06 (192.168.122.36)

【讨论】:

    猜你喜欢
    • 2019-09-24
    • 1970-01-01
    • 1970-01-01
    • 2016-09-16
    • 1970-01-01
    • 2013-01-19
    • 2016-01-17
    • 1970-01-01
    • 2013-09-22
    相关资源
    最近更新 更多