Results 1 to 4 of 4

Thread: scanvirus application bash script - clamscan engine - beta3 offical release

  1. #1

    Default scanvirus application bash script - clamscan engine - beta3 offical release

    Hello all. I finally fixed the space in partition name bug and the unmount bug. I'v added new features and design improvements.

    "scanvirus" is an script on top of clamscan to make virus scanning on windows and linux simpler and faster. It includes a current file count, improved logs, and virus vault storage. It requires clamscan and udisks2 installed, nothing else. However, there is one function hidden and will not be supported. It's a shortcut to opening a kde window to view the logs, "scanvirus -vl".

    You can free modify the script for your own use, but don't upload a modified version to any location.
    Software License: https://creativecommons.org/licenses/by-nc-nd/4.0/


    It uses a system folder for logs and this may cause problems. Please post here any conflicts.

    Also, there was a website(s) where I could paste it. I can't find the message. If you know where, please post here.

    Here's are the checksums for the file I have. Copy and paste in file. Press enter on last line and save. Follow instructions in file.

    md5sum scanvirus
    123b06e9265c745e530bdf8822702bc0 scanvirus

    sha512sum scanvirus
    3ff163dec73aa7a17d68dff986c66f21de7f94ea6db053eb19daa673b0ef36b94eeef74758bb2fb43d277892fb1ea07158f52b2641e1195f75f20f732fad5b01 scanvirus



    Code:
    #!/bin/bash
    #: Title       : scanvirus
    #: Date Created: Thu Sep 2 19:27:00 PST 2010
    #: Last Edit   : Tue Nov 29 2:07:00 PST 2016
    #: Author      : Lord Valarian #: Version     : 2.0.0  beta3
    #: Description : virus scanning application, clamscan engine
    
    #Software License: https://creativecommons.org/licenses/by-nc-nd/4.0/
    #Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
    #NonCommercial — You may not use the material for commercial purposes.
    #NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. 
    
    
    #Bug fix: space in partition name
    #upgrades: improved design
    
    #Open bin folder
    #Place this file inside "/home/bin/"
    #
    #Right-click on scanvirus
    #Click on properties
    #Click on permissions
    #Check executable and click ok
    
    #install clamav or run setup
    #Click Control -> Tools -> Open Terminal
    #Enter termal command:  scanvirus --setup
    #Enter admin password, wait for it to finish. Don't close terminal.
    
    #kdeicon disabled (next build)
    #Enter terminal command:  scanvirus --kdeicons
    #close terminal windows
    #
    #Click on either desktop icon to scan
    
    #Warning!  only use control-c to exit
    
    
    Create_KDE_linux_scan_icon() {
      cat > ScanVirus_KDE_Linux_Scan.desktop <<EOF
    #!/usr/bin/env xdg-open
    [Desktop Entry]
    Comment[en_US]=
    Comment=
    Exec=sh scanvirus -linux
    GenericName[en_US]=
    GenericName=
    Icon=kde
    MimeType=
    Name[en_US]=ScanVirus - linux anti-virus scan
    Name=ScanVirus - linux anti-virus scan
    Path=$PATH
    StartupNotify=true
    Terminal=true
    TerminalOptions=\s--noclose
    Type=Application
    X-DBUS-ServiceName=
    X-DBUS-StartupType=
    X-KDE-SubstituteUID=false
    X-KDE-Username=
    X-SuSE-translate=trueEOF
    EOF
    
    #set file permissions
    chmod 744 ScanVirus_KDE_Linux_Scan.desktop
    }
    
    
    Create_KDE_windows_scan_icon() {
      cat > ScanVirus_KDE_Windows_Scan.desktop <<EOF
    #!/usr/bin/env xdg-open
    [Desktop Entry]
    Comment[en_US]=
    Comment=
    Exec=sh scanvirus -mswin
    GenericName[en_US]=
    GenericName=
    Icon=kde
    MimeType=
    Name[en_US]=ScanVirus - windows anti-virus scan
    Name=ScanVirus - windows anti-virus scan
    Path=$PATH
    StartupNotify=true
    Terminal=true
    TerminalOptions=\s--noclose
    Type=Application
    X-DBUS-ServiceName=
    X-DBUS-StartupType=
    X-KDE-SubstituteUID=false
    X-KDE-Username=
    X-SuSE-translate=true
    EOF
    
    #set file permissions
    chmod 744 ScanVirus_KDE_Windows_Scan.desktop
    }
    
    
    
    Virus_Vault_Directory_Check()
    {
         #create var directory if not present
         if [ -d "/var" ]; then
            printf "root--> /var/ directory present\n"
         else
            printf "creating var directory\n"
            mkdir var
            #chmod 744
         fi
    
         #create log directory if not present
         if [ -d "/var/log" ]; then
            printf "root--> /var/log/ directory present\n"
         else
            printf "creating log directory\n"
            mkdir /var/log
            #chmod 744
         fi
    
         #create virus Vault if not present
         if [ -d "/var/log/VirusVault" ]; then
            printf "root--> /var/log/virusvault/ present\n"
         else
            printf "creating virus vault\n"
            mkdir /var/log/VirusVault
            chmod 744 /var/log/VirusVault
         fi
         
         Virus_Vault_Folder='/var/log/VirusVault' 
    }
    
    
    Scan_Results_Filter()
    {
        ScanLine=''
        filecount=0
        
        delete_line_flag=true
        scan_results_flag=false
        
        IFS=''
        
        while read -r ScanLine; do
        
            if [ "$scanvirus_trap_flag" = 'true' ];then
                break
            fi
            
            #get filescan results
            Scanfile_Results=${ScanLine##*:}
            
            #printf "ScanLine= %s\n" $ScanLine
            #printf "Scanfile_Results= %s\n" $Scanfile_Results
            
            if [ "$delete_line_flag" = 'true' ]; then
                echo -en "\E[2K\r"
                delete_line_flag=false
            fi
    
            #if scan summary then stop deleting lines
            if [ "$ScanLine" = '----------- SCAN SUMMARY -----------' ]; then
                #printf "filecount= %i\n" $filecounter
                scan_results_flag=true
            fi
    
            if [ "$scan_results_flag" = 'true' ]; then
                printf "%s\n" $ScanLine | tee -a "${Current_Vault_Folder}/scanresults.log"
    
            elif  [[ "$ScanLine2" == *"Symbolic"* ]];then
                printf "%s\n" $ScanLine
            elif  [[ "$Scanfile_Results" == *"FOUND"* ]];then
                let filecounter=filecounter+1
                printf "%s\n" $ScanLine | tee -a "${Current_Vault_Folder}/scanresults.log"
                  
            elif  [[ "$Scanfile_Results" == *"MOVED TO"* ]];then
                printf "%s\n" $ScanLine | tee -a "${Current_Vault_Folder}/scanresults.log"
                  
            elif  [[ "$Scanfile_Results" == *"OK"* ]] || [[ "$Scanfile_Results" == *"EMPTY"* ]] ;then
                let filecounter=filecounter+1
                printf "%i" $filecounter
                delete_line_flag=true
            fi
    
        done
    
        unset IFS
    }
    
    scanvirus_trap_flag=false
    control_c()
    # run if user hits control-c
    {
        #scanvirus_trap_flag=true
        #if drive mounted, unmount it
        
        #printf "Device_Mounted_Flag = %s   Device_Label= %s\n" $1 $2
        if [ "$1" = 'true' ];then
            command_output_unmount=$(udisksctl unmount -b "$2");unmount_error=$?
            printf "%s\n" $command_output_unmount    
        fi
    
        printf 'exiting...\n'
    }
    
    
    
    #read -p "Done. Press any key..." -n1 -s;printf "";
    
    #####################
    # shortcut code for clamscan #
    #####################
    
    # if not in superuser mode
    if [[ $EUID -ne 0 ]]; then
       printf "--- superuser/root only ---\n"
       exit 1
    fi
     
    # if clamscan not installed 
    clamscan --help > /dev/null 2>&1
    if [[ $? = 127 ]]; then
       echo "clamscan not installed" 1>&2
       exit 1
    fi
    
    # if clamscan not installed 
    udisksctl > /dev/null 2>&1
    if [[ $? = 127 ]]; then
       echo "udisks2 not installed" 1>&2
       exit 1
    fi
     
     #export TERM=vt100
    
        Virus_Vault_Directory_Check;
        freshclam
            
        #commands
        if [ "$1" = "-mswin" ] || [ "$1" = "-w" ]; then
             
            Current_Vault_Folder="$Virus_Vault_Folder/MSWIN "
            Current_Vault_Folder+=$(date)
            mkdir "${Current_Vault_Folder}"
             
            printf "\n.....scanvirus mswin.....\n" | tee "$Current_Vault_Folder/scanresults.log"
      
            IFS=':'
            blkid | sed 's/: /:/g' | sed 's/\" /:/g' | while read -ra line
            do
                 Device_Label=''
                File_System=''
                Drive_Label=''
                Mount_Point=''
    
                Device_Label=${line[0]}
                for blkid_field in ${line[*]}
                do
                    if  [[ "$blkid_field" == "TYPE="* ]];then
                        #cut 'type='
                        File_System=${blkid_field#*\"}
                    elif  [[ "$blkid_field" == *"LABEL="* ]];then
                        #cut 'label='
                        Drive_Label=${blkid_field#*\"}
                    fi
                done
             
                #cut /dev/
                Temp_MP=${Device_Label#/*/}    #printf "Temp_MP= %s\n" ${Temp_MP}
    
                #                                                               cut devicename
                Mount_Point=$( lsblk -l -o name,mountpoint | grep "${Temp_MP}" | sed "s/${Temp_MP} //g" )
    
    
                #if file system vfat or ntfs
                if [ "$File_System" = 'ntfs' ] || [ "$File_System" = 'vfat' ]; then
     
                    if [ "$Drive_Label" = "System Reserved" ]; then
                        #printf "Skipping System Reserved...\n"
                        continue
                    fi
    
                    printf "__________________________________________________\n" | tee -a "${Current_Vault_Folder}/scanresults.log"
                
                    #printf "Device_Label= \'%s\'\n" $Device_Label
                    #printf "File_System= \'%s\'\n" $File_System
                    #printf "Drive_Label= \'%s\'\n" $Drive_Label
                    #printf "Mount_Point= \'%s\'\n" $Mount_Point
                    #printf "\n"
    
                    Device_Mounted_Flag=false
                
                    #if device not mounted
                    if [ "$Mount_Point" = '' ]; then
    
                        command_output_scandir=$(udisksctl mount -b "$Device_Label");mount_error=$?
                        command_output_scandir=${command_output_scandir%.}
                        printf "%s\n" $command_output_scandir
                    
                        #cut out scan directory
                        command_output_scandir=${command_output_scandir#Mounted\ *\ at\ }
                        Mount_Point=$command_output_scandir
                    
                        #printf "%s\n" $Mount_Point
                     
                        if [ "$mount_error" != 0 ]; then
                            printf "Error: mount %s\n" $Drive_Label
                        else
                            Device_Mounted_Flag=true
                        fi
                    fi
    
                    printf "\nscanning: %s %s\n" $Drive_Label $Mount_Point | tee -a "${Current_Vault_Folder}/scanresults.log"
    
                    # trap keyboard interrupt (control-c)
                    trap "control_c $Device_Mounted_Flag $Device_Label" exit
                    
                    #scan only or move files
                    if [ "$2" = "-m" ] || [ "$2" = "-movetovault" ]; then
                        printf "Move to Virus Vault: /var/log/VirusVault/\n"
                        clamscan -r "$Mount_Point" "--move=${Current_Vault_Folder}" --follow-dir-symlinks=0 --follow-file-symlinks=0 --cross-fs=no | Scan_Results_Filter
                    else
                        printf "Scan only\n"
                        clamscan -r "$Mount_Point" --follow-dir-symlinks=0 --follow-file-symlinks=0 --cross-fs=no | Scan_Results_Filter
                    fi
                    #printf "movefile_parm= %s\n" $Movefile_Parm
    
                    #break
                    #if drive mounted, unmount it
                    if [ "$Device_Mounted_Flag" = 'true' ];then
                        command_output_unmount=$(udisksctl unmount -b "$Device_Label");unmount_error=$?
                        printf "%s\n" $command_output_unmount    
                    fi
                    printf "__________________________________________________\n" | tee -a "${Current_Vault_Folder}/scanresults.log"
                fi
    
                #break
             
                if [ "$scanvirus_trap_flag" = 'true' ]; then
                    break
                fi
            
            done
           
            #virus vault files read only
            #chmod 744 "${Current_Vault_Folder}"
           
        elif [ "$1" = "-linux" ] || [ "$1" = "-l" ]; then         
            Current_Vault_Folder="$Virus_Vault_Folder/linux "
            Current_Vault_Folder+=$(date)
            mkdir "${Current_Vault_Folder}"
             
            printf ".....Scanning linux.....\n\n" | tee "${Current_Vault_Folder}/scanresults.log"
    
            clamscan -r / --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev --exclude-dir=/.snapshots --follow-dir-symlinks=0 --follow-file-symlinks=0 --cross-fs=no | Scan_Results_Filter
             
            printf "__________________________________________________\n" | tee -a "${Current_Vault_Folder}/scanresults.log"
    
     
        elif [ "$1" = "-viewlogs" ] || [ "$1" = "-vl" ]; then
            kdesu dolphin /var/log/VirusVault/
        
        elif [ "$1" = "-help" ] || [ "$1" = "-h" ]; then
    
            printf "
    Scan Virus
    help commands
    -------------
    virus scan linux files
         p1: -l or -linux  
    virus scan windows files
         p1: -w or -mswin 
         p2: -m or -movetovault (optional)
    --setup:  install clamscan
    --kdeicons:  setup icons  (disabled)
    \n"           
    
        elif [ "$1" = "--setup" ]; then
            printf "\n"
            printf "ScanVirus Setup...\n"
            zypper --non-interactive install clamav;chkconfig freshclam on;freshclam;exit
            printf "\n"
    
        elif [ "$1" = "--kdeicons" ]; then
            #Create_KDE_linux_scan_icon;
            #Create_KDE_windows_scan_icon;  
            #printf "KDE Icons Created\n";
            printf "Disabled\n";
    
        else
            printf "
    Scan Virus
    help commands
    -------------
    virus scan linux files
         p1: -l or -linux  
    virus scan windows files
         p1: -w or -mswin 
         p2: -m or -movetovault (optional)
    --setup:  install clamscan
    --kdeicons:  setup icons (disabled)
    \n"           
        fi
    exit 0
    # End Of Script

  2. #2

    Default Re: scanvirus application bash script - clamscan engine - beta3 offical release

    This code could be exploited to ignore valid partitions. Trying to scan this partition leads to an error, but the script should run normally. Here's how to patch it.

    Find
    Code:
    if [ "$Drive_Label" = "System Reserved" ]; then
    #printf "Skipping System Reserved...\n"
    continue
    fi
    Replace with
    Code:
    #if [ "$Drive_Label" = "System Reserved" ]; then
    #printf "Skipping System Reserved...\n"
    #continue
    #fi

  3. #3

    Default Re: scanvirus application bash script - clamscan engine - beta3 offical release

    One last promo, the scanvirus logs are a structural improvement to clamscan, much easier to understand and use. No really, this is it.


    New upgrades for beta4:

    Internal code will do blockid scan on all linux partitions with full logging for 'scanvirus -l". Currently, this is only done on a mswin scan.

    Command: "scanvirus -livescan" will set it up with various options. On timer or on system idle.

    Command: "scanvirus -a" scan all available partitions with full logging.

  4. #4
    Join Date
    Jan 2016
    Location
    Manchester, UK
    Posts
    279

    Default Re: scanvirus application bash script - clamscan engine - beta3 offical release

    Brilliant :-)

    Just want to reply to say thank you.
    openSUSE Tumbleweed (usually the latest snapshot) w/ KDE Plasma 5

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •