Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_isIPv4 vulnerability based on existing files in /acme.sh #4971

Open
Hossy opened this issue Jan 29, 2024 · 2 comments
Open

_isIPv4 vulnerability based on existing files in /acme.sh #4971

Hossy opened this issue Jan 29, 2024 · 2 comments

Comments

@Hossy
Copy link

Hossy commented Jan 29, 2024

Steps to reproduce

  1. touch /acme.sh/1
  2. Make request for *.*.*.*

https://github.com/acmesh-official/acme.sh/blob/master/acme.sh#L4266

Recommend pulling out the 'not all number' check like this:

  if [ "$1" != "$(echo "$1" | tr -cd '[0-9].')" ]; then
    #not all number
    return 1
  fi
  for seg in $(echo "$1" | tr '.' ' '); do
Copy link

Please upgrade to the latest code and try again first. Maybe it's already fixed. acme.sh --upgrade If it's still not working, please provide the log with --debug 2, otherwise, nobody can help you.

@Hossy
Copy link
Author

Hossy commented Jan 29, 2024

Alternatively, this might be a less vulnerable function, POSIX safe, and only return 0 when a valid IPv4 address is provided (the current function returns 0 with "1" or "1.1"):

_isIPv4() {
    # Disable pathname expansion
    set -f

    # Save the current value of IFS
    _isIPv4_saveIFS="$IFS"
    IFS='.'

    # Split the IP into octets
    _chk_ipv4="$1"
    # We specifically want word splitting here.  We have disabled pathname expansion (globbing) with set -f.
    # shellcheck disable=SC2086
    set -- $_chk_ipv4

    # Restore the original value of IFS
    IFS="$_isIPv4_saveIFS"

    # Re-enable pathname expansion
    set +f

    # Check if the IP has exactly 4 octets
    if [ $# -ne 4 ]; then
        # Invalid IPv4 address
        _debug2 "$_chk_ipv4 does not have 4 octets"
        return 1
    fi

    # Validate each octet
    for octet in "$@"; do
        _debug2 octet "$octet"
        # Check if octet is numeric
        if ! [ "$octet" -eq "$octet" ] 2>/dev/null; then
            # octet is not numeric
            return 1
        fi

        # Check if octet is in range 0-255
        if [ "$octet" -lt 0 ] || [ "$octet" -gt 255 ]; then
            # octet is out of range
            return 1
        fi
    done

    # If all checks pass, IP is valid
    return 0
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant