[![logo](https://www.hongsnet.net/images/logo.gif)](https://www.hongsnet.net)

# Ansible을 이용한 보안취약점 조치

> 시스템 내에 SUID, SGID Bit가 설정된 파일에 설정을 제거한다.


## Inventory 설정

```bash
# cat hosts
[ALL_HOSTS]
172.16.0.100 managed_ip=172.16.0.100 des="2020-12-03"

[ALL_HOSTS_OK]
```

대상 호스트는 172.16.0.100이며, 추가는 2020-12-03에 수행한다. 참고적으로 **ALL_HOSTS_OK** 호스트 그룹은 작업이 완료된 호스트의 history를 위한 그룹이다.


## Host Variables 설정

```bash
# cat host_vars/172.16.0.100
ansible_ssh_host: 172.16.0.100
ansible_ssh_port: SSH_포트번호
ansible_ssh_user: 사용자 아이디
ansible_ssh_pass: "사용자 패스워드"
ansible_become: yes
ansible_become_method: su
ansible_become_user: root
ansible_become_pass: "!root_패스워드"
ansible_python_interpreter: python2.7
```

## Playbook 설정

```python
---
- name: SUID/SGID Bits Remove
  hosts: ALL_HOSTS
  tasks:
    - name: Remove SGID, SUID Permission Bit
      file:
        path: "{{ item }}"
        owner: root
        group: root
        mode: 00755
      with_items:
        - /usr/bin/newgrp
        - /sbin/unix_chkpwd
        - /usr/bin/at
```

`보안취약점 조치`에 대한 Playbook 분석

* [ ] SUID(4xxx), SGID(X200) 가 적용된 파일 중 보안에 취약점 명령을 755로 설정한다.


## playbook 실행

```bash
# ansible-playbook -i hosts suid_sgid_remote.yml
```