สวัสดีครับ เนื่องจาก ทางลูกค้ามีจำนวน Server Trend Micro Office Scan จำนวนมาก และต้องการกำหนด ให้เครื่อง Server ต่างๆ Update Pattern ช่วงหลังเวลางาน ซึ่งผ่านจาก Web Console นั้นไม่สามารถ ระบุได้ เลยได้ทำการ เขียน Powershell Scripts เพื่อทำการ Copy Pattern ไปยัง Server Trend Micro Office Scan ต่างๆ และได้ทำการเขียนเพื่อ ให้ Check old version และทำการลบ เพื่อไม่ให้เปลือง Disk ที่ Server เองด้วย
$abc=@("ondate","path","lptpath","icrcpath","lptname","locallpt","icrcname","localicrc","Rpath","Rlptpath","Ricrcpath","Rlptname","Ricrcname","abc")
$ondate = get-date -F ddMMyy
remove-item -path d:\powershell\*.txt
<# get pattern number on Local #>
$path='c:\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\'
$lptpath=$path+'lpt$vpn.*'
$icrcpath=$path+'icrc$oth.*'
<# Full name (lpt$vpn.111) #>
$lptname = Get-ChildItem $lptpath -name | select -last 1
<# lpt number #>
$locallpt = $lptname -replace 'lpt\$vpn',''
<# Full name (icrc$oth.111) #>
$icrcname = Get-ChildItem $icrcpath -name | select -last 1
<# icrc number #>
$localicrc = $icrcname -replace 'icrc\$oth',''
<# get pattern number on Remote host #>
("ip,lpt") > d:\Powershell\lpt.txt
("ip,icrc") > d:\Powershell\icrc.txt
Get-Content d:\Powershell\trendlist.csv |Foreach-Object {
($Rpath="\\$_\c$\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\"),
($Rlptpath=$Rpath+'lpt$vpn.*'),
($Ricrcpath=$Rpath+'icrc$oth.*'),
($Rlptname = Get-ChildItem $Rlptpath -name | select -last 1 ),
($Ricrcname = Get-ChildItem $Ricrcpath -name | select -last 1),
("$_,$Rlptname" >> d:\powershell\lpt.txt),
("$_,$Ricrcname" >> d:\powershell\icrc.txt)
}
<# Prepare output file for compare #>
(Get-Content -Path "d:\Powershell\lpt.txt" -ReadCount 0) -replace 'lpt\$vpn', '' | Set-Content -Path "d:\Powershell\lptnew.txt"
(Get-Content -Path "d:\Powershell\icrc.txt" -ReadCount 0) -replace 'icrc\$oth', '' | Set-Content -Path "d:\Powershell\icrcnew.txt"
Clear-Content -Path "d:\Powershell\lpt.txt"
Clear-Content -Path "d:\Powershell\icrc.txt"
Import-Csv d:\powershell\lptnew.txt | Where-Object {$_.lpt -lt "$locallpt" -and $_.lpt -gt "$null"} | ForEach-Object {($_).ip >> d:\Powershell\lpt.txt}
Get-Content -Path "d:\Powershell\lpt.txt" | ForEach-Object {
($Rpath="\\$_\c$\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\"),
(Copy-Item -Path $path$lptname -Destination $Rpath),
((echo "$_,LPT") >> d:\log\$ondate.csv)
}
Import-Csv d:\powershell\icrcnew.txt | Where-Object {$_.icrc -lt "$localicrc" -and $_.icrc -gt "$null"} | ForEach-Object {($_).ip >> d:\Powershell\icrc.txt}
Get-Content -Path "d:\Powershell\icrc.txt" | ForEach-Object {
($Rpath="\\$_\c$\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\"),
(Copy-Item -Path $path$icrcname -Destination $Rpath),
((echo "$_,ICRC") >> d:\log\$ondate.csv)
}
remove-item -path d:\powershell\*.txt
$abc | foreach-object {remove-variable $_}
แสดงบทความที่มีป้ายกำกับ Trend Micro แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ Trend Micro แสดงบทความทั้งหมด
วันอังคารที่ 21 พฤษภาคม พ.ศ. 2562
Check: Computer installation Trend Micro Office Scan
Check: Computer installation Trend Micro Office Scan
ผมเลยทำการ Set Trend Micro Office Scan ให้ส่งข้อมูลมายัง Trend Micro Control Manager และทำการตรวจสอบข้อมูลจาก Database ของ Trend Micro Control Manager ครับ
##distinct เป็นการตัดค่า ซ้ำ ออก##
##EI_IPAddressList like '192.168.1.%' or EI_IPAddressList like '192.168.2.%'
หาข้อมูลจาก IP 192.168.1.x - 192.168.2.x##
##EI_ProductVersion like '11%' เป็นการหาข้อมูล Version Trend Micro ในที่นี้คือที่เป็น Version 11#
select distinct EI_OS_MachineName,EI_OS_MachineName,EI_DomainName,EI_IPAddressList,EI_OS_Name,EI_OS_SPVersion,EI_OS_Version,EI_ProductVersion,EI_ProductBuildNumber
from tb_EntityInfo
where (EI_IPAddressList like '192.168.1.%' or EI_IPAddressList like '192.168.2.%') and EI_ProductVersion like '11%' )
order by EI_IPAddressList
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
}
}
วันพฤหัสบดีที่ 6 กรกฎาคม พ.ศ. 2560
Scripts Command Line: Install and Uninstall Trend Micro Office Scan Agent by Scripts
Scripts Command Line: Install and Uninstall Trend Micro Office Scan Agent by Scripts
:Menu
echo 1. Uninstall TrendMicro.
echo 2. Install TrendMicro.
echo 9. Exit
set /p choice= Please Select Menu:
if %choice%==1 GOTO UninstallTrendMicro
if %choice%==2 GOTO InstallTrendMicro
if %choice%==9 GOTO Exit
if %choice%==null GOTO Exit
rem *************************************************************
:Exit
exit
:UninstallTrendMicro
cls
echo 1. Uninstall TrendMicro on Windows 32bit
echo 2. Uninstall TrendMicro on Windows 64bit
echo 9. Menu
set /p UninstallTrendMicroChoice= Please Select Menu:
if %UninstallTrendMicroChoice%==1 GOTO UninstallTrendMicrox86
if %UninstallTrendMicroChoice%==2 GOTO UninstallTrendMicrox64
if %UninstallTrendMicroChoice%==9 GOTO Menu
if %UninstallTrendMicroChoice%==null GOTO Exit
:UninstallTrendMicrox86
"%programfiles%\Trend Micro\OfficeScan Client\pccntmon" -n
ping 1.1.1.1 -n 1 -w 5000>null
ping 1.1.1.1 -n 1 -w 5000>null
reg add HKEY_LOCAL_MACHINE\SOFTWARE\TrendMicro\PC-cillinNTCorp\CurrentVersion\Misc. /v "Allow Uninstall" /t REG_DWORD /d 1 /f
"%programfiles%\Trend Micro\OfficeScan Client\NTRmv.exe"
echo *************************************************************
set /p afterUninstallTrendMicrox86= Do you Want to use other menu? [Y/N]?
if /i "%afterUninstallTrendMicrox86%" EQU "Y" GOTO :Menu
if /i "%afterUninstallTrendMicrox86%" EQU "N" GOTO :Exit
:UninstallTrendMicrox64
"%programfiles(x86)%\Trend Micro\OfficeScan Client\pccntmon" -n
ping 1.1.1.1 -n 1 -w 5000>null
ping 1.1.1.1 -n 1 -w 5000>null
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432node\TrendMicro\PC-cillinNTCorp\CurrentVersion\Misc. /v "Allow Uninstall" /t REG_DWORD /d 1 /f
"%programfiles(x86)%\Trend Micro\OfficeScan Client\NTRmv.exe"
echo *************************************************************
set /p afterUninstallTrendMicrox64= Do you Want to use other menu? [Y/N]?
if /i "%afterUninstallTrendMicrox64%" EQU "Y" GOTO :Menu
if /i "%afterUninstallTrendMicrox64%" EQU "N" GOTO :Exit
:InstallTrendMicro
cls
echo 1. InstallTrendMicro on Windows 32bit
echo 2. InstallTrendMicro on Windows 64bit
echo 9. Menu
set /p InstallTrendMicroChoice= Please Select Menu:
if %InstallTrendMicroChoice%==1 GOTO InstallTrendMicrox86
if %InstallTrendMicroChoice%==2 GOTO InstallTrendMicrox64
if %InstallTrendMicroChoice%==9 GOTO Menu
if %InstallTrendMicroChoice%==null GOTO Exit
:InstallTrendMicrox86
cls
echo 0. Manu
echo 1. Contoso_HQ_01
set /p InstallTrendMicroChoice= Please Select Menu:
if %InstallTrendMicroChoice%==0 GOTO Menu
if %InstallTrendMicroChoice%==1 GOTO Contoso_HQ_01x86
msiexec /i http://Contoso_HQ_01:8080/officescan/download/agent_cloud_x86.msi PROPERTY=VALUE
echo *************************************************************
set /p afterContoso_HQ_01x86= Do you Want to use other menu? [Y/N]?
if /i "%afterContoso_HQ_01x86%" EQU "Y" GOTO :Menu
if /i "%afterContoso_HQ_01x86%" EQU "N" GOTO :Exit
:InstallTrendMicrox64
cls
echo 0. Manu
echo 1. Contoso_HQ_01
set /p InstallTrendMicroChoice= Please Select Menu:
if %InstallTrendMicroChoice%==0 GOTO Menu
if %InstallTrendMicroChoice%==1 GOTO Contoso_HQ_01x86
:Contoso_HQ_01x64
cls
echo 0. Manu
echo 1. Contoso_HQ_01
set /p InstallTrendMicroChoice= Please Select Menu:
if %InstallTrendMicroChoice%==0 GOTO Menu
if %InstallTrendMicroChoice%==1 GOTO Contoso_HQ_01x86
:Contoso_HQ_01x64
msiexec /i http://Contoso_HQ_01:8080/officescan/download/agent_cloud_x64.msi PROPERTY=VALUE
echo *************************************************************
set /p afterContoso_HQ_01x64= Do you Want to use other menu? [Y/N]?
if /i "%afterContoso_HQ_01x64%" EQU "Y" GOTO :Menu
if /i "%afterContoso_HQ_01x64%" EQU "N" GOTO :Exit
สมัครสมาชิก:
บทความ (Atom)