Exploit database

GH-6097439bf2aff0588fc0864f3649b2f5

ekamsinghwalia/detection-script-for-cve-2021-23358

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2021-23358

4 sources

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

Repository files3

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

cve-2021-23358.sh

Shell · 6,857 bytes
#!/bin/bash

##############################################################################################
########### CHECKING VERSION OF UNDERSCORE FROM NPM COMMAND #######################################
flag=0
var=$(npm list underscore | grep "underscore" | awk -F '@' '{print $2}' | egrep "^[1]\.(([3-9]*|1[0-1])\.[0-4])|(12\.0)|^1\.13\.0-[0-2]+$")  
if [[ -n $var ]] 
then
    echo "you are vulnerable to the  node-underscore vulnerability cve-2021-23358"                                                                                 
    flag=$((flag+1))
else
    echo "you are NOT vulnerable to the node-underscore vulnerability cve-2021-23358" 
fi



###########################################################################################3
#### CHECKING VERSION OF UNDERSCORE IN PATHS###############################
node_pathf(){
    path_list=$(find / -name $1 -xdev ! -fstype nfs ! -fstype nfs4 ! -fstype cifs ! -fstype smbfs ! -fstype gfs ! -fstype gfs2 ! -fstype safenetfs ! -fstype secfs ! -fstype gpfs ! -fstype smb2 ! -fstype vxfs ! -fstype vxodmfs ! -fstype afs ! -fstype acfs 2>/dev/null)
    for i in $path_list
    do
            node_path=$(echo $i | grep -oP 'node-underscore\S*_\K[0-9.]+|node-underscore[[:blank:]]*\K[\d.]+')
            echo $node_path
            if [ -n $node_path ] 
            then
                echo "Path: $i" | tee -a /node-uderscore_findings.stdout 2>/dev/null
                echo "Version(s): $node_path" | tee -a /node-uderscore_findings.stdout 2>/dev/null
                echo "----------------------------------------" | tee -a /node-uderscore_findings.stdout 2>/dev/null
                node_chk=$(echo "$node_path"| egrep "^[1]\.(([3-9]*|1[0-1])\.[0-4])|(12\.0)|^1\.13\.0-[0-2]+$" 2>/dev/null)
                if [[ -n $node_chk ]]
                then
                    flag=$((flag+1))
                fi
            fi   
    done
}

libjs_pathf(){
    path_list=$(find / -name $1 -xdev ! -fstype nfs ! -fstype nfs4 ! -fstype cifs ! -fstype smbfs ! -fstype gfs ! -fstype gfs2 ! -fstype safenetfs ! -fstype secfs ! -fstype gpfs ! -fstype smb2 ! -fstype vxfs ! -fstype vxodmfs ! -fstype afs ! -fstype acfs 2>/dev/null)
    for i in $path_list
    do
            libjs_path=$(echo $i |grep -oP 'libjs-underscore\S*_\K[0-9.]+|libjs-underscore[[:blank:]]*\K[0-9.]+')
            echo $libjs_path
            if [ -n $libjs ]
            then
                echo "Path: $i" | tee -a /node-underscore_findings.stdout 2>/dev/null
                echo "Version(s): $libjs_path" | tee -a /node-underscore_findings.stdout 2>/dev/null
                echo "----------------------------------------" | tee -a /node-uderscore_findings.stdout 2>/dev/null
                libjs_chk=$(echo "$libjs_path"| egrep "^[1]\.(([3-9]*|1[0-1])\.[0-4])|(12\.0)|^1\.13\.0-[0-2]+$" 2>/dev/null)
                if [[ -n $libjs_chk ]]
                then
                    flag=$((flag+1))
                fi
            fi   
    done
}



pathf(){
    path_list=$(find / -name $1 -xdev ! -fstype nfs ! -fstype nfs4 ! -fstype cifs ! -fstype smbfs ! -fstype gfs ! -fstype gfs2 ! -fstype safenetfs ! -fstype secfs ! -fstype gpfs ! -fstype smb2 ! -fstype vxfs ! -fstype vxodmfs ! -fstype afs ! -fstype acfs 2>/dev/null)
    for i in $path_list
    do
            path=$(echo $i | grep -oP 'underscore\S*_\K[0-9.]+|underscore[[:blank:]]*\K[0-9.]+')
            echo $path
            if [ -n $path ]
            then
                echo "Path: $i" | tee -a /node-underscore_findings.stdout 2>/dev/null
                echo "Version(s): $path" | tee -a /node-underscore_findings.stdout 2>/dev/null
                echo "----------------------------------------" | tee -a /node-underscore_findings.stdout 2>/dev/null
                path_chk=$(echo "$path"| egrep "^[1]\.(([3-9]*|1[0-1])\.[0-4])|(12\.0)|^1\.13\.0-[0-2]+$" 2>/dev/null)
                if [[ -n $path_chk ]]
                then
                    flag=$((flag+1))
                fi
            fi   
    done
}


############################################################################################################
################### CHECKING VERSION OF UNDERSCORE IN LIBRARIES ############################################

underscoref(){
    lib_list=$(find / -name $1 -xdev ! -fstype nfs ! -fstype nfs4 ! -fstype cifs ! -fstype smbfs ! -fstype gfs ! -fstype gfs2 ! -fstype safenetfs ! -fstype secfs ! -fstype gpfs ! -fstype smb2 ! -fstype vxfs ! -fstype vxodmfs ! -fstype afs ! -fstype acfs 2>/dev/null)
    for i in $lib_list
    do
        if ! command -v strings &> /dev/null
        then
            ver=$(grep --text -oP 'underscore\S*_\K[0-9.]+|underscore[[:blank:]]*\K[0-9.]+' $i 2>/dev/null |sort|uniq|tail -n 1|awk '{print $2}' 2>/dev/null)
            if [[ -n $ver ]]
            then
                        echo "Path: $i" | tee -a /node-underscore_findings.stdout 2>/dev/null
                        echo "Version(s): $ver" | tee -a /node-underscore_findings.stdout 2>/dev/null
                        echo "----------------------------------------" | tee -a /node-uderscore_findings.stdout 2>/dev/null
                ver_chk=$(echo "$ver"| egrep "^[1]\.(([3-9]*|1[0-1])\.[0-4])|(12\.0)|^1\.13\.0-[0-2]+$" 2>/dev/null)
                if [[ -n $ver_chk ]]
                then
                    flag=$((flag+1))
                fi
            fi
        else
            ver=$(strings $i 2>/dev/null| grep -oP 'underscore\S*_\K[0-9.]+|underscore[[:blank:]]*\K[0-9.]+' 2>/dev/null|sort|uniq|tail -n 1|awk '{print $2}' 2>/dev/null)
            if [[ -n $ver ]]
            then
                echo "Path: $i" | tee -a /node-underscore_findings.stdout 2>/dev/null
                        echo "Version(s): $ver" | tee -a /node-underscore_findings.stdout 2>/dev/null
                    echo "----------------------------------------" | tee -a /node-underscore_findings.stdout 2>/dev/null
                        ver_chk=$(echo "$ver" | egrep "^[1]\.(([3-9]*|1[0-1])\.[0-4])|(12\.0)|^1\.13\.0-[0-2]+$" 2>/dev/null)
                if [[ -n $ver_chk ]]
                then 
                    flag=$((flag+1))
                fi
            fi
        fi
    done
}

echo "Detecting Underscore version in libraries that underscore uses -> node-underscore* , libjs-underscore* and underscore*"| tee /node-uderscore_findings.stdout 2>/dev/null
echo "----------------------------------------" | tee -a /node-underscore_findings.stdout 2>/dev/null

underscoref node-underscore*
underscoref libjs-underscore*
underscoref underscore*
node_pathf node-underscore*
libjs_pathf libjs-underscore*
pathf underscore*



echo "vulnerabilitiesFound: $flag" | tee -a /node-underscore_findings.stdout 2>/dev/null


if [ $flag -gt 0 ]
then
    echo "you are using libraries of underscore that are vulnerable"
    exit 99
else
    exit 0
fi