Exploit database

GH-602ab5e0503d5e4e0d5dc5ac3c652b83

nxvh1337/cve-2021-44142-vulnerable-lab

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2021-44142

4 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files5
nxvh1337/cve-2021-44142-vulnerable-labRevision e93bddb1185f

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

entrypoint.sh

Shell · 3,705 bytes
#!/bin/sh
set -eu

SAMBA_PREFIX="/usr/local/samba"
USER_NAME="${SAMBA_USER:-samba}"
USER_PASS="${SAMBA_PASS:-samba}"
USER_UID="${SAMBA_UID:-1000}"
USER_GID="${SAMBA_GID:-1000}"
GROUP_NAME="${SAMBA_GROUP:-$USER_NAME}"
SHARE_NAME="${SAMBA_SHARE_NAME:-TimeMachineBackup}"
SHARE_PATH="${SAMBA_SHARE_PATH:-/data/xx/diskVolume0/backups/timemachine}"
TM_MAX_SIZE="${SAMBA_TM_MAX_SIZE:-0}"
SHARE_CONF="${SAMBA_SHARE_CONF:-/usr/local/samba/etc/shares.conf}"
GUEST_NAME="${SAMBA_GUEST_USER:-smbguest}"
GUEST_UID="${SAMBA_GUEST_UID:-}"
FRUIT_METADATA="${SAMBA_FRUIT_METADATA:-stream}"
FRUIT_RESOURCE="${SAMBA_FRUIT_RESOURCE:-stream}"

log() {
    printf '[entrypoint] %s\n' "$*"
}

ensure_group() {
    if getent group "${GROUP_NAME}" >/dev/null 2>&1; then
        return
    fi

    if ! getent group "${USER_GID}" >/dev/null 2>&1; then
        groupadd -g "${USER_GID}" "${GROUP_NAME}" >/dev/null 2>&1 || groupadd "${GROUP_NAME}"
    else
        GROUP_NAME="$(getent group "${USER_GID}" | cut -d: -f1)"
        log "Using existing group ${GROUP_NAME} for GID ${USER_GID}"
    fi
}

ensure_user() {
    if getent passwd "${USER_NAME}" >/dev/null 2>&1; then
        return
    fi

    useradd -M -N -u "${USER_UID}" -g "${GROUP_NAME}" -s /usr/sbin/nologin "${USER_NAME}" >/dev/null 2>&1 \
        || useradd -M -N -g "${GROUP_NAME}" -s /usr/sbin/nologin "${USER_NAME}"
}

ensure_guest_user() {
    if getent passwd "${GUEST_NAME}" >/dev/null 2>&1; then
        usermod -a -G "${GROUP_NAME}" "${GUEST_NAME}" >/dev/null 2>&1 || true
        return
    fi

    if [ -n "${GUEST_UID}" ]; then
        useradd -M -N -u "${GUEST_UID}" -g "${GROUP_NAME}" -s /usr/sbin/nologin "${GUEST_NAME}" >/dev/null 2>&1 \
            || useradd -M -N -g "${GROUP_NAME}" -s /usr/sbin/nologin "${GUEST_NAME}"
    else
        useradd -M -N -g "${GROUP_NAME}" -s /usr/sbin/nologin "${GUEST_NAME}" >/dev/null 2>&1 || true
    fi

    usermod -a -G "${GROUP_NAME}" "${GUEST_NAME}" >/dev/null 2>&1 || true
}

ensure_group
ensure_user
ensure_guest_user

mkdir -p "$(dirname "${SHARE_CONF}")"
mkdir -p "${SHARE_PATH}"
chown -R "${USER_NAME}:${GROUP_NAME}" "${SHARE_PATH}"
chmod 2770 "${SHARE_PATH}"

if "${SAMBA_PREFIX}/bin/pdbedit" -L | grep -q "^${USER_NAME}:"; then
    printf '%s\n%s\n' "${USER_PASS}" "${USER_PASS}" | "${SAMBA_PREFIX}/bin/smbpasswd" -s "${USER_NAME}" >/dev/null
else
    printf '%s\n%s\n' "${USER_PASS}" "${USER_PASS}" | "${SAMBA_PREFIX}/bin/smbpasswd" -s -a "${USER_NAME}" >/dev/null
fi

"${SAMBA_PREFIX}/bin/smbpasswd" -e "${USER_NAME}" >/dev/null

log "Writing share definition for ${SHARE_NAME}"
cat <<EOF >"${SHARE_CONF}"
[${SHARE_NAME}]
   path = ${SHARE_PATH}
   browseable = yes
   public = yes
   available = yes
   oplocks = yes
   follow symlinks = yes
   map archive = no
   guest ok = yes
   writable = yes
   read only = no
   inherit permissions = yes
   directory mask = 0770
   create mask = 0660
   force user = ${USER_NAME}
   force group = ${GROUP_NAME}
   ea support = yes
   durable handles = yes
   kernel oplocks = no
   kernel share modes = no
   posix locking = no
   inherit acls = yes
   strict sync = yes
   vfs objects = catia fruit streams_xattr
   fruit:metadata = ${FRUIT_METADATA}
   fruit:resource = ${FRUIT_RESOURCE}
   fruit:aapl = yes
   fruit:locking = none
   fruit:encoding = native
   fruit:posix_rename = yes
   fruit:time machine = yes
   fruit:time machine max size = ${TM_MAX_SIZE}
   fruit:wipe_intentionally_left_blank_rfork = yes
   fruit:zero_file_id = yes
   fruit:delete_empty_adfiles = yes
EOF

log "Validating smb.conf"
"${SAMBA_PREFIX}/bin/testparm" -s >/dev/null

log "Starting smbd for user ${USER_NAME}"
exec "${SAMBA_PREFIX}/sbin/smbd" -F --no-process-group -S