Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3df9ce77d6 | ||
|
|
99400fb03e | ||
|
|
ca115922bd | ||
|
|
082ae219b1 | ||
|
|
49b360dffa | ||
|
|
811025773e | ||
|
|
111d3bea66 | ||
|
|
4d780e900a |
No files matched your search
@@ -2,20 +2,26 @@
|
|||||||
# Intune custom compliance discovery script for Linux: is Microsoft Defender
|
# Intune custom compliance discovery script for Linux: is Microsoft Defender
|
||||||
# for Endpoint (mdatp) installed, onboarded, licensed and protecting?
|
# for Endpoint (mdatp) installed, onboarded, licensed and protecting?
|
||||||
#
|
#
|
||||||
# Upload in Intune > Devices > Compliance > Scripts (Linux), and pair it with
|
# Upload in Intune > Endpoint security > Device compliance > Scripts (Linux),
|
||||||
# defender-compliance.json in a Linux compliance policy (Custom compliance).
|
# and pair it with defender-compliance.json in a Linux compliance policy
|
||||||
# Himmelblau runs it as root inside himmelblaud-tasks.service and sends the
|
# (Custom compliance). Himmelblau runs it as root inside
|
||||||
# JSON on stdout to Intune, which evaluates it against the rules. Every setting
|
# himmelblaud-tasks.service and sends the JSON on stdout to Intune, which
|
||||||
# is always emitted, so a missing or stopped Defender reads as non-compliant
|
# evaluates it against the rules. Every setting is always emitted, so a missing
|
||||||
# instead of as a script error.
|
# or stopped Defender reads as non-compliant instead of as a script error.
|
||||||
|
|
||||||
MDATP=/usr/bin/mdatp
|
MDATP=/usr/bin/mdatp
|
||||||
|
|
||||||
# Print one `mdatp health` field without quotes or a trailing " [managed]".
|
# Defender won't answer `mdatp health` started from inside himmelblaud-tasks
|
||||||
# Unlicensed or unonboarded, mdatp prints "ATTENTION: ..." lines first.
|
# (it can't read that process while checking the caller), so ask through
|
||||||
|
# systemd, which runs mdatp as its own child. Elsewhere, ask mdatp directly.
|
||||||
|
health="$(systemd-run --quiet --wait --pipe --collect "${MDATP}" health 2>/dev/null)"
|
||||||
|
grep -q '^healthy' <<< "${health}" || health="$("${MDATP}" health 2>/dev/null)"
|
||||||
|
|
||||||
|
# Print one field of the `mdatp health` output ("name : value") without
|
||||||
|
# quotes or a trailing " [managed]".
|
||||||
field() {
|
field() {
|
||||||
"${MDATP}" health --field "$1" 2>/dev/null | grep -v '^ATTENTION' | tail -n1 \
|
grep -m1 "^$1 *:" <<< "${health}" \
|
||||||
| sed -e 's/ \[managed\]$//' -e 's/^"//' -e 's/"$//'
|
| sed -e 's/^[^:]*: *//' -e 's/ \[managed\]$//' -e 's/^"//' -e 's/"$//'
|
||||||
}
|
}
|
||||||
|
|
||||||
bool() {
|
bool() {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ if [[ ! -x "${MDATP}" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# The image finishes the Defender install on first boot (mdatp-firstboot).
|
# The image finishes the Defender install on first boot (mdatp-firstboot).
|
||||||
if [[ ! -f /var/lib/mdatp-firstboot.done ]]; then
|
if [[ -x /usr/libexec/mdatp-firstboot && ! -f /var/lib/mdatp-firstboot.done ]]; then
|
||||||
log "Defender first-boot setup has not completed; starting it."
|
log "Defender first-boot setup has not completed; starting it."
|
||||||
systemctl start mdatp-firstboot.service
|
systemctl start mdatp-firstboot.service
|
||||||
fi
|
fi
|
||||||
@@ -93,18 +93,30 @@ if [[ -z "$(field org_id)" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Settings Defender's own policy manages show " [managed]" and can't be
|
# Settings a managed config (mdatp_managed.json) sets show " [managed]" and
|
||||||
# changed locally; this only fixes a locally disabled real-time protection.
|
# can't be changed locally; these fix devices without one, where behavior
|
||||||
|
# monitoring is off by default. Behavior monitoring needs real-time
|
||||||
|
# protection, so that goes first.
|
||||||
if [[ "$(field real_time_protection_enabled)" != true ]]; then
|
if [[ "$(field real_time_protection_enabled)" != true ]]; then
|
||||||
log "Real-time protection is off; enabling it."
|
log "Real-time protection is off; enabling it."
|
||||||
"${MDATP}" config real-time-protection --value enabled
|
"${MDATP}" config real-time-protection --value enabled
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$(field behavior_monitoring)" != enabled ]]; then
|
||||||
|
log "Behavior monitoring is off; enabling it."
|
||||||
|
"${MDATP}" config behavior-monitoring --value enabled
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$(field cloud_enabled)" != true ]]; then
|
||||||
|
log "Cloud-delivered protection is off; enabling it."
|
||||||
|
"${MDATP}" config cloud --value enabled
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$(field definitions_status)" != up_to_date ]]; then
|
if [[ "$(field definitions_status)" != up_to_date ]]; then
|
||||||
log "Definitions are not up to date; updating them."
|
log "Definitions are not up to date; updating them."
|
||||||
"${MDATP}" definitions update
|
"${MDATP}" definitions update
|
||||||
fi
|
fi
|
||||||
|
|
||||||
healthy="$(field healthy)"
|
healthy="$(field healthy)"
|
||||||
log "healthy=${healthy} licensed=$(field licensed) org_id=$(field org_id) rtp=$(field real_time_protection_enabled) definitions=$(field definitions_status)"
|
log "healthy=${healthy} licensed=$(field licensed) org_id=$(field org_id) rtp=$(field real_time_protection_enabled) behavior_monitoring=$(field behavior_monitoring) cloud=$(field cloud_enabled) definitions=$(field definitions_status)"
|
||||||
[[ "${healthy}" == true ]]
|
[[ "${healthy}" == true ]]
|
||||||
Reference in new issue
Block a user