|
21 | 21 | <unix:object object_ref="object_group_ownership_var_log" /> |
22 | 22 | <unix:state state_ref="state_group_ownership_adm_var_log_auth_log"/> |
23 | 23 | <unix:state state_ref="state_group_ownership_root_var_log_auth_log"/> |
24 | | - {{%- if product == "ubuntu2204" %}} |
25 | | - <unix:state state_ref="{{{ rule_id }}}_group_only_has_sys_uids"/> |
| 24 | + {{%- if 'ubuntu' in product %}} |
| 25 | + <unix:state state_ref="{{{ rule_id }}}_state_owner_is_system_user"/> |
26 | 26 | {{%- endif %}} |
27 | 27 | </unix:file_test> |
28 | 28 | <unix:file_object comment="/var/log/*" id="object_group_ownership_var_log" version="1"> |
|
96 | 96 | <unix:file_state id="{{{ rule_id }}}_exclude_files_waagent" version="1"> |
97 | 97 | <unix:filename operation="pattern match">^waagent\.log.*$</unix:filename> |
98 | 98 | </unix:file_state> |
99 | | - {{%- if product == "ubuntu2204" %}} |
100 | | - <unix:file_state id="{{{ rule_id }}}_group_only_has_sys_uids" version="1"> |
101 | | - <unix:group_id datatype="int" var_ref="empty_group_ids" var_check="at least one"/> |
| 99 | + {{%- if 'ubuntu' in product %}} |
| 100 | + <unix:file_state id="{{{ rule_id }}}_state_owner_is_system_user" version="1"> |
| 101 | + <unix:group_id datatype="int" operation="equals" var_ref="{{{ rule_id }}}_var_system_gids" var_check="at least one" /> |
102 | 102 | </unix:file_state> |
103 | 103 |
|
104 | | - <local_variable id="empty_group_ids" comment="Group IDs with no members" datatype="int" version="1"> |
105 | | - <object_component item_field="subexpression" object_ref="empty_members_in_etc_group"/> |
106 | | - </local_variable> |
107 | | - |
108 | | - <ind:textfilecontent54_object comment="Groups with no members" id="empty_members_in_etc_group" version="1"> |
109 | | - <ind:filepath>/etc/group</ind:filepath> |
110 | | - <ind:pattern operation="pattern match" var_ref="variable_{{{ rule_id }}}_group_regex" var_check="at least one"/> |
| 104 | + <!-- Fetch all shells designated as valid login shells from /etc/shells --> |
| 105 | + <ind:textfilecontent54_object id="{{{ rule_id }}}_object_valid_shells" version="1" comment="valid shells"> |
| 106 | + <ind:filepath>/etc/shells</ind:filepath> |
| 107 | + <ind:pattern operation="pattern match">^(/.*)$</ind:pattern> |
111 | 108 | <ind:instance datatype="int" operation="greater than or equal">1</ind:instance> |
112 | 109 | </ind:textfilecontent54_object> |
113 | 110 |
|
114 | | - <local_variable id="variable_{{{ rule_id }}}_group_regex" datatype="string" version="1" comment="gid rows retrieved from /etc/passwd"> |
115 | | - <concat> |
116 | | - <literal_component>^[^:]+:[^:]*:(</literal_component> |
117 | | - <object_component item_field="subexpression" object_ref="obj_{{{ rule_id }}}_gids_with_only_sys_uids" /> |
118 | | - <literal_component>):$</literal_component> |
119 | | - </concat> |
| 111 | + <local_variable id="{{{ rule_id }}}_var_valid_shells" comment="list of valid shells" datatype="string" version="1"> |
| 112 | + <object_component item_field="subexpression" object_ref="{{{ rule_id }}}_object_valid_shells" /> |
120 | 113 | </local_variable> |
121 | | - |
122 | | - <ind:textfilecontent54_object id="obj_{{{ rule_id }}}_gids_with_only_sys_uids" version="1"> |
| 114 | + |
| 115 | + <ind:textfilecontent54_object id="{{{ rule_id }}}_object_system_users" version="1" comment="users who have an invalid shell"> |
123 | 116 | <ind:filepath>/etc/passwd</ind:filepath> |
124 | | - <ind:pattern operation="pattern match" var_ref="variable_{{{ rule_id }}}_regex" var_check="at least one"/> |
| 117 | + <ind:pattern operation="pattern match">^[^:]+:[^:]+:[0-9]+:([0-9]+):.*$</ind:pattern> |
125 | 118 | <ind:instance datatype="int" operation="greater than or equal">1</ind:instance> |
| 119 | + <filter action="exclude">{{{ rule_id }}}_state_shell_is_valid</filter> |
126 | 120 | </ind:textfilecontent54_object> |
127 | 121 |
|
128 | | - <local_variable id="variable_{{{ rule_id }}}_regex" datatype="string" version="1" comment="uid rows retrieved from /etc/passwd"> |
| 122 | + <ind:textfilecontent54_state id="{{{ rule_id }}}_state_shell_is_valid" version="1"> |
| 123 | + <ind:text operation="pattern match" var_ref="{{{ rule_id }}}_var_valid_shells_regex" var_check="at least one"></ind:text> |
| 124 | + </ind:textfilecontent54_state> |
| 125 | + |
| 126 | + <local_variable id="{{{ rule_id }}}_var_valid_shells_regex" datatype="string" version="1" comment="regex of valid shells"> |
129 | 127 | <concat> |
130 | | - <literal_component>^[^:]*:[^:]*:</literal_component> |
131 | | - <object_component item_field="subexpression" object_ref="obj_{{{ rule_id }}}_sys_uid" /> |
132 | | - <literal_component>:(\d+):.*$</literal_component> |
| 128 | + <literal_component>^.*:(</literal_component> |
| 129 | + <object_component item_field="subexpression" object_ref="{{{ rule_id }}}_object_valid_shells" /> |
| 130 | + <literal_component>)$</literal_component> |
133 | 131 | </concat> |
134 | 132 | </local_variable> |
135 | 133 |
|
136 | | - <ind:textfilecontent54_object id="obj_{{{ rule_id }}}_sys_uid" version="1"> |
137 | | - <ind:filepath>/etc/passwd</ind:filepath> |
138 | | - <ind:pattern operation="pattern match">^[^:]+:[^:]*:(\d\d?\d?):.*$</ind:pattern> |
139 | | - <ind:instance datatype="int" operation="greater than or equal">1</ind:instance> |
140 | | - </ind:textfilecontent54_object> |
| 134 | + <local_variable id="{{{ rule_id }}}_var_system_gids" comment="GIDs of users with invalid shells" datatype="int" version="1"> |
| 135 | + <object_component item_field="subexpression" object_ref="{{{ rule_id }}}_object_system_users" /> |
| 136 | + </local_variable> |
141 | 137 | {{%- endif %}} |
142 | 138 | </def-group> |
0 commit comments