วันอังคารที่ 21 พฤษภาคม พ.ศ. 2562

Powershell Scripts: Automate Brute Force,Unload Delete and Install Trend Micro Office Scan

Powershell Scripts: Automate Brute Force,Unload Delete and Install Trend Micro Office Scan

    สวัสดีครับ วันนี้จะมาพูดถึง Automate Scripts การ Brute Force,Unload Delete and Install Trend Micro Office Scan ครับ เนื่องจาก ทางลูกค้ามีเครื่อง Computer จำนวนมาก และมี หลากหลาย Username / Password ซึ่งบางทีก็ไม่สามารถติดต่อไปยังเจ้าของเครื่องได้ครับ ทำให้ทางผมได้ทำการเขียน Scripts ขึ้นมาเพื่อใช้งาน ในการช่วยอำนวย ความสะดวกให้กับลูกค้า (อันนี้เป็น Code ตัวอย่างคร่าวๆนะครับ ยังไงก็ลองเอาไปปรับใช้กันดูครับ)


โดยก่อนที่จะทำการ ใช้งาน Powershell Scripts นี้นะครับ มี Requirement ดังต่อไปนี้
1. ต้องเปิด Policy ให้ Powershell สามารถ Remote Command ได้
https://yingkamol.blogspot.com/2019/05/open-remote-powershell.html

2. psexectools ซึ่งเป็น Tools free จาก Microsoft ครับ
https://docs.microsoft.com/en-us/sysinternals/downloads/psexec

###----------------------------------------------------------###    
### Author : Yingkamol Prukrattanakul---------------###      
###---MCP, MCSA, MCSE, MCT, MCST, SEC+----###    
###-----Email<yingkamol_7@hotmail.com>---------###    
###-----------------------------------------------------------###    
###//////////////////////////...................\\\\\\\\\\\\\\\\\\\\\\\\\\\\###    
###////////////////////////////////.....\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\###


####Get Data In File####

##Get IP Target##
$computers = Get-Content D:\Test_Password_Login\scanlist.txt

##Get Username##
$users = Get-Content D:\Test_Password_Login\user_list.txt

##Get Password##
$passwords = Get-Content D:\Test_Password_Login\password_list.txt

##Get Date##
$ondate = get-date -Format "ddMMyy"

##Check IP from File IP  xxx.xxx. ##
$pattern = "([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))$"

$test = $computers -replace $pattern
##IP  xxx.xxx.2.50 ##
$av = "1.2"

$All = "$test$av"
     
##MSI Download and Install## 
        $msi32 = "msiexec /i 'http://$All':8080/officescan/download/agent_cloud_x86.msi PROPERTY=VALUE /qn"
        $msi64 = "msiexec /i 'http://$All':8080/officescan/download/agent_cloud_x64.msi PROPERTY=VALUE /qn"
     
        $trend64 = "http://192.168.1.2:8080/officescan/download/agent_cloud_x64.msi PROPERTY=VALUE /qn"
        $trend32 = "http://192.168.1.2:8080/officescan/download/agent_cloud_x86.msi PROPERTY=VALUE /qn"


##Loop IP -->Try Username -->Try Password --> ##
##Check OS Architecture -->Unload --> Uninstall --> Install Trend Micro OfficeScan##

ForEach ($computer in $computers)

   try
{
ForEach ($user in $users)
{
try
{
ForEach ($password in $passwords)
{
                                psexec "\\$computer" -u $user -p $password cmd /c "whoami"
                                IF ($LASTEXITCODE -eq '0')
{
echo "$computer $user $password" >> "D:\Test_Password_Login\COMPUTERPASSLIST.txt"

###Check OS Version###
psexec "\\$computer" -u $user -p $password /accepteula cmd /c "cd D:\Program Files (x86)"

IF ($LASTEXITCODE -eq '0')
{
###OS Version 64 Bit###
###Uninstall###
Start-Process -FilePath 'D:\PSexec.exe' -ArgumentList "-s -u $user -p $password \\$computer cmd /c 'D:\Program Files (x86)\Trend Micro\OfficeScan Client\pccntmon' -n" -Wait -Passthru
       
##Sleep 25 = Deley 25 Sec##        sleep 25
                                         
        Start-Process -FilePath 'D:\PSexec.exe' -ArgumentList "-s -u $user -p $password \\$computer cmd /c reg add HKLM\SOFTWARE\Wow6432node\TrendMicro\PC-cillinNTCorp\CurrentVersion\Misc. /v 'Allow Uninstall' /t REG_DWORD /d 1 /f" -Wait -Passthru -WindowStyle Hidden
         sleep 5

         Start-Process -FilePath 'D:\PSexec.exe' -ArgumentList "-s -u $user -p $password \\$computer cmd /c 'D:\Program Files (x86)\Trend Micro\OfficeScan Client\NTRmv.exe"  -Wait -Passthru -WindowStyle Hidden
          sleep 60

         Start-Process -FilePath 'D:\PSexec.exe' -ArgumentList "-s -u $user -p $password \\$computer cmd /c msiexec /i $trend64  " -Wait -Passthru -WindowStyle Hidden
         sleep 60
}
else
{
###OS Version 32 Bit###
###Uninstall###
Start-Process -FilePath 'D:\PSexec.exe' -ArgumentList "-s -u $user -p $password \\$computer cmd /c 'D:\Program Files\Trend Micro\OfficeScan Client\pccntmon' -n"   -Wait -Passthru                                     
        sleep 25

        Start-Process -FilePath 'D:\PSexec.exe' -ArgumentList "-s -u $user -p $password \\$computer reg add HKEY_LOCAL_MACHINE\SOFTWARE\TrendMicro\PC-cillinNTCorp\CurrentVersion\Misc. /v 'Allow Uninstall' /t REG_DWORD /d 1 /f" -Wait -Passthru
       sleep 5
                                         
       Start-Process -FilePath 'D:\PSexec.exe' -ArgumentList "-s -u $user -p $password \\$computer cmd /c D:\Program Files\Trend Micro\OfficeScan Client\NTRmv.exe" -Wait -Passthru
         sleep 60
                                         
        Start-Process -FilePath 'D:\PSexec.exe' -ArgumentList "-s -u $user -p $password \\$computer cmd /c msiexec /i $trend32" -Wait -Passthru
         sleep 60

}
}
else
       {
$FailedPassword = "System FailedPassword:$password"
$FailedPassword | Write-Warning
       }
        }
}
        catch   
{
$FailedUser = "System FailedUser:$user"
$FailedUser | Write-Warning
}
}
}
catch   
{
$NOTCONNECT = "System NOPATCH:$computer"
        $NOTCONNECT | Write-Warning
         }
}






 

ไม่มีความคิดเห็น:

แสดงความคิดเห็น