!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache. PHP/7.3.33 

uname -a: Linux acloudg.aryanict.com 4.18.0-513.9.1.lve.el8.x86_64 #1 SMP Mon Dec 4 15:01:22 UTC
2023 x86_64
 

uid=1095(katebhospital) gid=1098(katebhospital) groups=1098(katebhospital) 

Safe-mode: OFF (not secure)

/opt/scripts/hv/   drwxr-xr-x
Free 293.6 GB of 429.69 GB (68.33%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     ipmi.sh (11.13 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/bin/bash
#
# Bash script to automate configuration of IPMI in Linux.
#
# Last Edited Date: 11.26.2019
#
# Author: Nate Kennison
#
# Version 1.9.10

clear

Config_IPMI () {
    #auto set gateway for private IPMI addresses
    IFS=. read ip1 ip2 ip3 ip4 <<< "$IPMIIP"
    
    if [[ `echo $ip4 | egrep '^([2-9]|[1-5][0-9]|6[0-2])$'` ]]; then
            IPMIGW=1
    
    elif [[ `echo $ip4 | egrep '^(6[6-9]|[7-9][0-9]|1[0-1][0-9]|12[0-6])$'` ]]; then
            IPMIGW=65
    
    elif [[ `echo $ip4 | egrep '^(1[3-8][0-9]|190)$'` ]]; then
            IPMIGW=129
    
    elif [[ `echo $ip4 | egrep '^(19[4-9]|2[0-5][0-9]|25[0-4])$'` ]]; then
            IPMIGW=193
    fi
    
    #automatically set subnet mask or ask if not private IPMI address
    if [[ `echo $IPMIIP | grep -E '10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'` ]]; then
            IPMIMASK=192
    else
            echo 'Subnet mask last octet (ie. 255.255.255.x) replace X'
            read IPMIMASK
        
            echo 'Gateway last octet (ie. x.x.x.y) replace y'
            read IPMIGW
    fi
    
    #Use passed password variable or set password variable
    if [[ -n ${PW} ]]; then
        echo "Password already set."
    else
        echo "Server Password ("user" account password:"
        read PW
        PW=$PW!
    fi
    
    sleep 1
    clear
    
    #determine if redhat or debian & install packages
    if [ -f /etc/redhat-release ]; then
    #    if [[ `egrep -iq 'CentOS|Redhat|Enterprise|Fedora' /etc/redhat-release` ]]; then
            echo "Redhat or Derivative Detected."
            echo "Installing needed packages...  (This may take a minute)"
            yum -y install OpenIPMI unzip curl>/dev/null 2>&1
            service ipmi start >/dev/null 2>&1
            curl -m 10 -o tmp.html http://ipmiutil.sourceforge.net/FILES/ >/dev/null 2>&1
            #if download fails, drop to backup source
            if [ $? -ne 0 ]; then
                filename="ipmiutil-2.9.2-1_rhel6.x86_64.rpm"
                wget scripts.hivelocity.net/harden/files/ipmiutil-2.9.2-1_rhel6.x86_64.rpm >/dev/null 2>&1
            else
                filename=$(cat tmp.html |grep -o -E "[^<>]*?el6.x86_64.rpm" | grep -v devel | tail -1 | cut -d'"' -f2-)
                url="http://ipmiutil.sourceforge.net/FILES/$filename"
                wget $url >/dev/null 2>&1
                rm -rf tmp.html >/dev/null 2>&1
            fi
            #if [ $? -ne 0 ]; then
            #echo "Download of ipmiutil failed, they likely updated the file.  Update the link in the script."
            #sleep 3
            #fi
            yum -y install $filename > /dev/null 2>&1
            rm -rf ipmiutil*.rpm
            yum -y install ipmitool > /dev/null 2>&1
    
    elif [ -f /etc/debian_version ]; then
    
            echo "Debian or Derivative Detected."
            echo "Installing needed packages...  (This may take a minute)"
            apt-get update >/dev/null 2>&1
            apt-get -y install unzip >/dev/null 2>&1
            apt-get -y install openipmi >/dev/null 2>&1
            apt-get -y install ipmitool >/dev/null 2>&1
            apt-get -y install curl >/dev/null 2>&1
            curl -m 10 -o tmp.html http://ipmiutil.sourceforge.net/FILES/ >/dev/null 2>&1
            #if download fails, drop to backup source
            if [ $? -ne 0 ]; then
                filename="ipmiutil_2.9.2-1_debian_amd64.deb"
                wget scripts.hivelocity.net/harden/files/ipmiutil_2.9.2-1_debian_amd64.deb >/dev/null 2>&1
            else
                filename=$(cat tmp.html |grep -o -E "[^<>]*?debian_amd64.deb" | grep -v devel | tail -1)
                url="http://ipmiutil.sourceforge.net/FILES/$filename"
                wget $url >/dev/null 2>&1
                rm -rf tmp.html >/dev/null 2>&1
            fi
            #wget http://ipmiutil.sourceforge.net/FILESutil_3.0.4-1_debian_amd64.deb > /dev/null 2>&1
            #if [ $? -ne 0 ]; then
            #echo "Download of ipmiutil failed, they likely updated the file.  Update the link in the script."
            #sleep 3
            #fi
            dpkg -i $filename > /dev/null 2>&1
            rm -rf ipmiutil*.deb > /dev/null 2>&1
            /etc/init.d/openipmi start >/dev/null 2>&1
    fi
    
    #install ipmicfg
    cd /root >/dev/null 2>&1
    wget scripts.hivelocity.net/harden/files/IPMICFG_1.24.0_general_20160105.zip >/dev/null 2>&1
    unzip IPMICFG_* >/dev/null 2>&1
    rm -rf IPMICFG_*.zip >/dev/null 2>&1
    mv IPMICFG_* ipmicfg >/dev/null 2>&1
    chmod +x /root/ipmicfg/linux/32bit/ipmicfg-linux.x86 >/dev/null 2>&1
    chmod +x /root/ipmicfg/linux/64bit/ipmicfg-linux.x86_64 >/dev/null 2>&1
    cd
    
    
    #determine and set architecture
    UNAME64=$(uname -ar | grep 64)
    UNAME686=$(uname -ar | grep 686)
    
    if [ "$UNAME64" ]; then
        arch=x86_64
        dir=64bit
    elif [ "$UNAME686" ]; then
        arch=x86
        dir=32bit
    fi
    
    #Check if Dell or Supermicro
    if [[ `/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -user list | egrep 'root'` ]]; then
        hw=dell
    
    elif [[ `/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -user list | egrep 'ADMIN'` ]]; then
        hw=supermicro   
    fi
    
    if [[ `echo $hw | egrep dell` ]]; then
        passwd=root
    
    elif [[ `echo $hw | egrep supermicro` ]]; then
        passwd=ADMIN
    fi
    
    #Set the IPMI config
    echo "Setting IPMI configuration..."
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -fde > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -nm reset > /dev/null 2>&1
    sleep 60
    until ipmitool lan print |grep Auth&>/dev/null;do :;done
    sleep 10
    chmod +x /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch > /dev/null 2>&1
    ipmiutil smcoem lanport dedicated > /dev/null 2>&1
    ipmiutil delloem lan set dedicated > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -dhcp off > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -m $IPMIIP > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -k 255.255.255.$IPMIMASK > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -g ${IPMIIP%.*}.$IPMIGW > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -user del 3 > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -user add 3 user $PW 3 > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -user setpwd 2 $passwd > /dev/null 2>&1
    ipmitool user set password 2 Password!
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -user setpwd 1 $passwd > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -user level 1 1 > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -m $IPMIIP > /dev/null 2>&1
    /root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -user list > /dev/null 2>&1

    
    #set configured settings variables
    SIPMIIP=`/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -m`
    SIPMIMASK=`/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -k`
    SIPMIGW=`/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -g`
    SIPMIUSERS=`/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -user list`

    #Export IPs to finish script if ran from finish scripts.
    if [[ -n ${source} ]]; then
    export SIPMIIP=`/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -m`
    export SIPMIMASK=`/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -k`
    export SIPMIGW=`/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -g`
    export SIPMIUSERS=`/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -user list`
    fi
}

function setnewmac {
    echo "Fixing a zero MAC..."
    #gets mac of first nic and changes : to - for ipmiutil to use
    firstnicmac=$(ip a sh | grep link/ether | awk '{print $2}' | awk '{print toupper($0)}' | sed 's/:/-/g' | head -1)
    
    #decrements the last section of the mac for the ipmi to use
    newmac=$(awk 'BEGIN{FS=OFS="-";$0=ARGV[1];$NF=sprintf("%X",("0x"$NF)-1);print}' $firstnicmac)
    
    #ipmiutil command to set the new mac
    ipmiutil lan -e -L 1 -M $newmac -I $IPMIIP > /dev/null 2>&1
    ipmiutil reset -k > /dev/null 2>&1

    #run a loop until the new mac sets
    while [ $currentmac = "00:00:00:00:00:00" ]; do
        echo "Waiting for MAC address to correct - Email nate@hivelocity.net if it gets stuck here for longer than a few minutes."
        sleep 10
        currentmac=$(/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -m | grep MAC | sed 's/MAC=//g')
    done
    echo New MAC Address: $currentmac
}

function checkzeromac {
#ipmicfg check for zero mac
sleep 10
currentmac=$(/root/ipmicfg/linux/$dir/ipmicfg-linux.$arch -m | grep MAC | sed 's/MAC=//g')

#check if current mac is all zeros and fix if it is.
if [[ $currentmac == "00:00:00:00:00:00" ]];then
    setnewmac
else
    echo "MAC address looks good."
fi
}

function flashipmi () {
    localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/')
    if [ `echo $localip | grep 192` ];then
    echo "Server appears to be in the build room.  Would you like to flash the IPMI firmware?"
        read answer
        if [ "$answer" == y ];then
            wget scripts.hivelocity.net/utils/flashipmi.sh
            bash flashipmi.sh
        fi
    fi
}

function setupadminuser {
    echo "Setting ADMIN user..."
    ipmitool user set password 2 $ADMINPW > /dev/null 2>&1
    ipmitool user set name 3 user > /dev/null 2>&1
    ipmitool user set password 3 $PW > /dev/null 2>&1
    ipmitool channel setaccess 1 3 link=on ipmi=on callin=on privilege=3 > /dev/null 2>&1
    ipmitool user priv 3 0x3 1 > /dev/null 2>&1
    ipmitool user enable 3 > /dev/null 2>&1
    ipmitool mc reset cold > /dev/null 2>&1
    echo "Waiting for IPMI to reset..."
    sleep 5
    until ipmitool lan print &>/dev/null;do :;done
}

function showsettings {
    #Display configured settings:
    echo ---------------Configured Settings---------------
    echo "$SIPMIIP"
    echo "$SIPMIMASK"
    echo "$SIPMIGW"
    echo "$SIPMIUSERS"
    echo Configured User Password: "$PW"
    if [[ -n ${ADMINPW} ]]; then
        echo Configured ADMIN Password: "$ADMINPW"
    fi
}

#ask some questions and set the ip variables up
echo 'IP address for IPMI? ([Enter] to Skip IPMI configuration)'
read IPMIIP

echo "Set the ADMIN password? or [Enter] to skip. (Run this in the rack so you can copy paste the password from Intranet)"
read ADMINPW

localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/')
if [ `echo $localip | grep 192` ];then
echo "Server appears to be in the build room.  Would you like to flash the IPMI firmware?"
    read flashanswer
fi

if [ "$flashanswer" == y ];then
    wget scripts.hivelocity.net/utils/flashipmi.sh
    bash flashipmi.sh
fi

#Run or skip setup of IPMI
if [[ -z ${IPMIIP} ]]; then
    echo "Skipping IPMI"
    sleep 1
    rm -rf ipmi.sh
else
    modprobe ipmi_devintf
    modprobe ipmi_si
    Config_IPMI
    #Run or skip setup of ADMIN user
    if [[ -z ${ADMINPW} ]]; then
        echo "Leaving ADMIN the default password."
    else
        setupadminuser
    fi
    checkzeromac
fi

if [[ $@ == *-s* ]];then
    ipmitool raw 0x30 0x70 0x0c 1 1 > /dev/null 2>&1
fi

#Output settings if running standalone
if [[ $(basename "$0") == "ipmi.sh" ]];then
    showsettings
fi

#go home and clean up after yourself!
sleep 2
cd
rm -rf ipmi.sh

#gpu tyan ipmi
#modprobe ipmi_devintf
#ipmitool lan set 0x01 vlan id XXX

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0974 ]--