ค้นหาเว็บไซต์

การค้นหาบัญชีบริการเพื่ออำนวยความสะดวกในการจัดการและการล้างข้อมูล


โพสต์นี้จะอธิบายวิธีรวบรวมรายการโดยละเอียดของบัญชีบริการ Active Directory ของคุณ เพื่อให้คุณสามารถใช้การกำกับดูแลที่เหมาะสมเพื่อลดพื้นที่การโจมตีของคุณ

โดยเฉพาะอย่างยิ่ง ให้รายละเอียดวิธีการระบุบัญชีบริการที่ใช้ดังต่อไปนี้:

  • บริการวินโดวส์
  • งานที่กำหนดเวลาไว้
  • พูลแอปพลิเคชัน IIS

ซึ่งจะช่วยให้คุณสามารถระบุส่วนสำคัญของบัญชีบริการของคุณได้ อย่างไรก็ตาม โปรดทราบว่าบัญชีบริการยังสามารถใช้ในไดเร็กทอรีเสมือน การตั้งค่าการรับรองความถูกต้อง ฯลฯ โพสต์ในบล็อกนี้ไม่ครอบคลุมถึงวิธีการระบุบัญชีบริการเหล่านั้น

บริการวินโดวส์

ตำแหน่งที่ชัดเจนที่สุดในการค้นหาบัญชีบริการที่ใช้งานอยู่คือ Windows Services (Services.msc) เพียงคลิกเมนู Start พิมพ์ “บริการ” ในช่องค้นหา และคลิก บริการ คุณจะเห็นรายการบริการและบัญชีที่ใช้ในการดำเนินการ:

หรือคุณสามารถใช้ PowerShell และ WMI เพื่อดึงข้อมูลนี้และจัดเก็บไว้ในไฟล์ CSV เพื่อการประมวลผลในภายหลัง ต่อไปนี้เป็นสคริปต์สามรายการที่คุณสามารถเลือกได้:

# WMI Query to Retrieve All Services, Get the Accounts Used to Log on to Them, and Export Them to a CSV File on the Local Computer

$CSV_File_Path  = "" #Path to excel file to export information to

$Services = Get-WmiObject Win32_Service

$Services_Info = $Services | Select-Object Name, Caption, StartName, StartMode

$Services_Info | Export-Csv $CSV_File_Path

# WMI Query to a Remote Computer to Retrieve Service Information

$CSV_File_Path = "" #Path to excel file to export information to

$Computer_Name = "" #Name or IP Address of the computer to query

$Services = Get-WmiObject Win32_Service -ComputerName $Computer_Name

$Services_Info = $Services | Select-Object PSComputerName, Name, Caption, StartName, StartMode

$Services_Info | Export-Csv $CSV_File_Path

# Query Multiple Computers using a CSV List

$CSV_Input_File = "" # Path to CSV File where A1 is a header called ComputerName and A2 and below are Computer Names

$CSV_File_Path = "" #Path to excel file to export information to

$Computer_Names_Import = Import-Csv $CSV_Input_File

foreach ($Computer_Name in $Computer_Names_Import)

{

      $Computer_Name = $Computer_Name.ComputerName

      $Services = Get-WmiObject Win32_Service -ComputerName $Computer_Name

      $Services_Info = $Services | Select-Object PSComputerName, Name, Caption, StartName, StartMode

      $Services_Info | Export-Csv $CSV_File_Path -Append

}

จากนั้น คุณสามารถเปิดไฟล์ใน Excel และใช้ตัวกรองเพื่อเจาะลึกรายละเอียดสำคัญที่แสดงด้านล่าง:

ตรวจสอบให้แน่ใจว่าได้รันสคริปต์บนเซิร์ฟเวอร์ทั้งหมดของคุณ

งานที่กำหนดเวลาไว้

บัญชีบริการมักใช้เพื่อรันงานที่กำหนดเวลาไว้ ด้วยวิธีนี้ ผู้ดูแลระบบสามารถให้สิทธิ์แก่บัญชีเฉพาะสิทธิ์ที่จำเป็นสำหรับงานนี้เท่านั้น

หากคุณใช้ GUI เพื่อค้นหาบัญชีบริการเหล่านี้ คุณจะต้องตรวจสอบงานที่กำหนดเวลาไว้แต่ละรายการสำหรับบัญชีที่ใช้ในการเรียกใช้:

Windows เวอร์ชันล่าสุดจะสร้างงานให้กับผู้ใช้ทุกคนที่เข้าสู่ระบบ ซึ่งหมายความว่างานต่างๆ ข้างต้น (User_Feed_Synchronization) สามารถละเว้นได้อย่างปลอดภัย อย่างไรก็ตาม งานอื่นๆ ทั้งหมดควรได้รับการตรวจสอบสำหรับบัญชีบริการ

มีสองวิธีอัตโนมัติในการรวบรวมบัญชีบริการที่ใช้โดยงานที่กำหนดเวลาไว้:

  • การใช้โมดูล ScheduledTasks PowerShell อย่างไรก็ตาม ฉันไม่เชื่อว่าตัวเลือกนี้สามารถใช้เพื่อสืบค้นระบบรุ่นเก่าได้
  • การใช้ไฟล์ใน C:WindowsSystem32Tasks

การใช้ ScheduledTasks Cmdlets

การใช้ ScheduledTasks cmdlets เป็นตัวเลือกที่ง่ายกว่าหากทำงานบนเซิร์ฟเวอร์ทั้งหมดที่คุณต้องการสืบค้น ด้านล่างนี้เป็นตัวอย่าง PowerShell สำหรับสร้างไฟล์ CSV ที่แสดงรายการงานที่มีชื่อผู้ใช้และประเภทการเข้าสู่ระบบที่เกี่ยวข้อง:

# Getting Scheduled Tasks using Get-ScheduledTask

$CSV_File_Path = "" #Path to excel file to export information to

$All_Scheduled_Tasks = Get-ScheduledTask #This will also include the default microsoft ones

$Scheduled_Tasks_ExMicrosoft = $All_Scheduled_Tasks | Where-Object { $_.TaskPath -notlike "Microsoft*" } # Exclude the Microsoft Tasks

$Scheduled_Tasks_Info = $Scheduled_Tasks_ExMicrosoft | Select-Object TaskPath, TaskName, @{ Name = "Username"; Expression = { $_.Principal.UserID } }, @{ Name = "LogonType";  Expression = { $_.Principal.LogonType } }

$Scheduled_Tasks_Info | Export-Csv $CSV_File_Path

การใช้ข้อมูล XML ของงาน

การใช้ไฟล์งานเพื่อรับข้อมูลดูเหมือนว่าจะทำงานได้ดีในทุกระบบปฏิบัติการ แต่จะน่าเบื่อกว่าเล็กน้อย:

# Getting Scheduled Tasks using XML Files in C:WindowsSystem32Tasks

$CSV_File_Path = "" #Path to excel file to export information to

$Task_Folder_Location = "C:WindowsSystem32Tasks" # Path to the Scheduled Tasks folder

$Task_XML_Files_All = Get-ChildItem $Task_XML_Files -Recurse

$Task_XML_Files_Filtered = $Task_XML_Files_All | Where-Object { $_.FullName -notlike "$Task_Folder_LocationMicrosoft*" }

foreach ($Task_XML_File in $Task_XML_Files_Filtered)

{

      $Task_XML_File_Path = $Task_XML_File.FullName

      #Getting the Principal and Logon Type

      [XML]$XML_Content = Get-Content $Task_XML_File_Path

      $Task_Principal = $XML_Content.Task.Principals.Principal.UserID

      $Task_LogonType = $XML_Content.Task.Principals.Principal.LogonType

      $Output = $Task_XML_File | Select-Object Name, FullName, @{ Name = "Task_Principal"; Expression = { $Task_Principal } }, @{ Name = "Task_LogonType"; Expression = { $Task_LogonType } }

      $Output | Export-Csv $CSV_File_Path -Append

}

พูลแอปพลิเคชัน IIS

กลุ่มแอปพลิเคชัน IIS ยังคงพบเห็นได้ทั่วไป โดยเฉพาะอย่างยิ่งสำหรับการใช้งานเว็บไซต์ภายใน องค์กรสามารถใช้บัญชีบริการเพื่อบังคับใช้สิทธิ์การเข้าถึงขั้นต่ำสำหรับแต่ละกลุ่มแอปพลิเคชันได้

หากต้องการค้นหาบัญชีบริการที่ใช้ในการเรียกใช้กลุ่มแอปพลิเคชันโดยใช้ GUI ให้ทำตามคำแนะนำด้านล่าง:

การค้นหาข้อมูลนี้โดยใช้ PowerShell ค่อนข้างยุ่งยากเล็กน้อย ขั้นแรก คุณต้องตรวจสอบให้แน่ใจว่าเซิร์ฟเวอร์ที่คุณต้องการซักถามมีการติดตั้งฟีเจอร์สคริปต์การจัดการและเครื่องมือของ IIS แล้ว ใช้ข้อมูลโค้ด PowerShell ต่อไปนี้:

# Check whether the IIS Management Scripts and Tools feature is installed. If not, then install it.

$Feature_Name = "Web-Scripting-Tools"

$Feature = Get-WindowsFeature -Name $Feature_Name

If (-not ($Feature.Installed))

{

      Install-WindowsFeature -Name $Feature_Name

}

ตอนนี้คุณสามารถใช้โมดูล WebAdministration เพื่อรับข้อมูลบัญชีบริการสำหรับพูลแอปพลิเคชัน IIS บนเครื่องหนึ่งเครื่องขึ้นไป:

# Get Application Pools using WebAdministration Module on a Single Machine
$CSV_File_Path = "" #Path to excel file to export information to
$Application_Pools = Get-ChildItem "IIS:AppPools"
$Application_Pools_WithUsername = $Application_Pools | Select-Object Name, State, @{ Name = "Username"; Expression = { $_.ProcessModel.Username } }
$Application_Pools_WithUsername | Export-Csv $CSV_File_Path

# Get Application Pools Using WebAdministration on Multiple Machines
$CSV_Input_File = "" # Path to CSV file with A1 set to ComputerName and then A2 and below being the actual computer names
$CSV_File_Path = "" # Path to excel file to export information to
$Output_Folder = "" # Path to a folder to import all the export files to
$CSV_Computers = Import-Csv $CSV_Input_File
$Computers = $CSV_Computers.ComputerName
Invoke-Command -ComputerName $Computers -ArgumentList $CSV_File_Path -ScriptBlock {
	param($CSV_File_Path)
	$Application_Pools = Get-ChildItem "IIS:AppPools"
	$Application_Pools_WithUsername = $Application_Pools | Select-Object Name, State, @{ Name = "Username"; Expression = { $_.ProcessModel.Username } }
	$Application_Pools_WithUsername | Export-Csv $CSV_File_Path
}

# Collecting the output files by using Admin shares and modifying the $CSV_File_Path parameter to get the location on target machine
foreach ($Computer in $Computers)
{
	$UNC_File_Path = "\$Computer$($CSV_File_Path -replace ':', '$')"
	Move-Item -Path $UNC_File_Path -Destination "$Output_Folder$Computer.csv"
}

# Merging the files into a single CSV file called Merge.csv
$All_CSV_To_Merge = Get-ChildItem -Path $Output_Folder
foreach ($CSV in $All_CSV_To_Merge)
{
	$CSV_Import = Import-Csv $CSV.FullName
	$CSV_Import_Update = $CSV_Import | Select-Object Name, State, Username, @{ Name = "ComputerName"; Expression = { $CSV.Name } }
	$CSV_Import_Update | Export-Csv "$Output_FolderMerge.csv" -Append
}

การใช้รายการบัญชีบริการที่รวบรวมไว้

ตอนนี้เรามีไฟล์ CSV ที่แสดงบัญชีบริการที่ใช้โดย:

  • บริการวินโดวส์
  • งานที่กำหนดเวลาไว้
  • กลุ่มแอปพลิเคชัน IIS

แต่ละไฟล์เหล่านี้จะมีฟิลด์ ComputerName หรือ PSComputerName ซึ่งสามารถใช้เพื่อรับมุมมองที่ดีขึ้นเกี่ยวกับสิ่งที่กำหนดค่าไว้บนเซิร์ฟเวอร์ แต่ละรายการจะมีช่องชื่อผู้ใช้ ซึ่งสามารถใช้เพื่อกำหนดจำนวนเซิร์ฟเวอร์ที่บัญชีใดบัญชีหนึ่งสามารถใช้ได้

เพื่อปรับปรุงการวิเคราะห์ คุณสามารถใช้สูตร Excel VLOOKUP เพื่อจัดระเบียบข้อมูลได้ หรือคุณสามารถนำเข้าไฟล์ CSV ลงในฐานข้อมูล ตั้งค่าความสัมพันธ์ระหว่างฟิลด์ และใช้แบบสอบถามเพื่อรับข้อมูลที่คุณต้องการ

Netwrix ช่วยได้อย่างไร?

แม้ว่าจะใช้ PowerShell การรวบรวมและเปรียบเทียบข้อมูลในบัญชีบริการก็อาจค่อนข้างยุ่งยาก Netwrix StealthAUDIT มีรายงานที่ใช้งานง่ายเกี่ยวกับบัญชีบริการ รวมถึงข้อมูลดิบหากคุณต้องการ

นอกจากนี้ Netwrix StealthAUDIT ยังช่วยให้คุณ:

  • ระบุช่องโหว่ที่ผู้โจมตีสามารถใช้เพื่อโจมตีระบบ Windows และเข้าถึงข้อมูลของคุณ
  • แก้ไขช่องว่างด้านความปลอดภัยโดยการประเมินระดับแพตช์ระบบอย่างรวดเร็วและมีประสิทธิภาพ
  • บังคับใช้นโยบายความปลอดภัยและการดำเนินงานผ่านการวิเคราะห์การกำหนดค่าพื้นฐาน
  • ตรวจสอบและควบคุมบัญชีสิทธิพิเศษ
  • พิสูจน์การปฏิบัติตามข้อกำหนดได้ง่ายขึ้นด้วยรายงานที่สร้างไว้ล่วงหน้าและความโปร่งใสของระบบที่สมบูรณ์

บทความที่เกี่ยวข้อง