scripting

 Scripting, bir dizi komutun yazılıp çalıştırılması işlemidir ve bu komutlar bir metin dosyasında (script) bulunur. Genellikle, komutlar bir kabuk (shell), örneğin PowerShell, içinde çalıştırılmak üzere yazılır. Scripting'in amacı, manuel olarak yapılacak görevlerin otomatikleştirilmesidir. Yani, bilgisayara bir "yapılacaklar listesi" vermek gibidir; her satır bir görevi temsil eder ve bilgisayar bu görevleri otomatik olarak yerine getirir.

Basitçe ifade etmek gerekirse, scripting, bilgisayara her biri belirli bir işi yapan komutlardan oluşan bir liste vermek gibidir. Bu, zaman kazandırır, hata yapma olasılığını azaltır ve manuel olarak yapılması çok karmaşık veya sıkıcı olan görevleri otomatik hale getirir. Shell'ler ve scripting hakkında daha fazla bilgi edinmeye başladıkça, scriptlerin sistem yönetimi, veri işleme ve daha birçok görev için güçlü araçlar olabileceğini keşfedeceksiniz.

PowerShell'de scripting öğrenmek, bu alanın kapsamını aşar. Ancak şunu anlamamız önemlidir ki, PowerShell'in gücü, siber güvenlik alanındaki her rol için kritik bir beceri olmasını sağlar.

  • Blue Team Profesyonelleri: Olay müdahale uzmanları, zararlı yazılım analizörleri ve tehdit avcıları, PowerShell scriptlerini, günlük (log) analizi, anomali tespiti ve zararlılık izleri (IOC'ler) çıkarma gibi birçok farklı görevi otomatikleştirmek için kullanabilirler. Bu scriptler, kötü amaçlı yazılımın tersine mühendisliğini yapmak veya sistemleri saldırı izleri için taramak gibi güvenlik görevlerini de otomatikleştirebilir.

  • Red Team Profesyonelleri: Penetrasyon test uzmanları ve etik hackerlar, PowerShell scriptlerini, sistem envanterleme, uzak komutlar çalıştırma ve savunmaların aşılması için obfuscation (karmaşıklaştırma) yapma gibi görevleri otomatikleştirmek için kullanabilirler. PowerShell'in her tür sistemle derin entegrasyonu, saldırı simülasyonları ve gerçek dünyadaki tehditlere karşı sistem dayanıklılığını test etmek için güçlü bir araç haline getirir.

  • Sistem Yöneticileri: PowerShell scripting, sistem bütünlüğü kontrolü yapma, sistem yapılandırmalarını yönetme ve ağları güvence altına alma gibi görevlerde faydalıdır, özellikle uzak veya büyük ölçekli ortamlar için. PowerShell scriptleri, güvenlik politikalarını uygulamak, sistem sağlığını izlemek ve güvenlik olaylarına otomatik olarak yanıt vermek için tasarlanabilir, böylece genel güvenlik duruşunu güçlendirir.

PowerShell scripting, savunma ya da saldırı amaçlı kullanılsa da, siber güvenlik araç setindeki temel bir beceridir.

Invoke-Command Cmdlet'i de bu bağlamda belirtmek önemlidir. Invoke-Command, uzak sistemlerde komut çalıştırmak için kullanılır ve bu, sistem yöneticileri, güvenlik mühendisleri ve penetrasyon test uzmanları için temel bir araçtır. Invoke-Command, uzak yönetimi verimli hale getirir ve scripting ile birleştirildiğinde birden fazla makine üzerinde görevleri otomatikleştirir. Penetrasyon testlerinde veya saldırganlar tarafından, hedef sistemler üzerinde yükler veya komutlar çalıştırmak için de kullanılabilir.

Invoke-Command'in kullanımı ile ilgili bazı örnekler:

Terminal:

pgsql
PS C:\Users\captain> Get-Help Invoke-Command -examples NAME Invoke-Command SYNOPSIS Runs commands on local and remote computers. ------------- Example 1: Run a script on a server ------------- Invoke-Command -FilePath c:\scripts\test.ps1 -ComputerName Server01 The FilePath parameter specifies a script that is located on the local computer. The script runs on the remote computer and the results are returned to the local computer. --------- Example 2: Run a command on a remote server --------- Invoke-Command -ComputerName Server01 -Credential Domain01\User01 -ScriptBlock { Get-Culture } The ComputerName parameter specifies the name of the remote computer. The Credential parameter is used to run the command in the security context of Domain01\User01, a user who has permission to run commands. The ScriptBlock parameter specifies the command to be run on the remote computer. In response, PowerShell requests the password and an authentication method for the User01 account. It then runs the command on the Server01 computer and returns the result.

Yukarıdaki örnekler, Invoke-Command cmdlet'inin gücünü ve basitliğini ortaya koymaktadır. Birincisi, cmdlet'in herhangi bir özel script ile nasıl kolayca birleştirilebileceğini gösterir. İkincisi ise, script yazmayı bilmesek bile Invoke-Command'in gücünden nasıl faydalanabileceğimizi gösterir; çünkü -ScriptBlock parametresini ekleyerek, uzaktaki bilgisayarda herhangi bir komutu çalıştırabiliriz.


English Translation:

Scripting is the process of writing and executing a series of commands contained in a text file, known as a script, to automate tasks that would typically be performed manually in a shell, like PowerShell.

Simply speaking, scripting is like giving a computer a to-do list, where each line in the script is a task the computer will carry out automatically. This saves time, reduces the chance of errors, and allows tasks that would be too complex or tedious to do manually to be automated. As you learn more about shells and scripting, you'll discover that scripts can be powerful tools for managing systems, processing data, and much more.

Learning scripting with PowerShell goes beyond the scope of this room. Nonetheless, it’s important to understand that its power makes it a crucial skill across all cybersecurity roles.

  • Blue Team Professionals: Incident responders, malware analysts, and threat hunters can use PowerShell scripts to automate many tasks, including log analysis, detecting anomalies, and extracting indicators of compromise (IOCs). These scripts can also be used to reverse-engineer malicious code (malware) or automate scanning of systems for signs of intrusion.

  • Red Team Professionals: Penetration testers and ethical hackers can use PowerShell scripts to automate tasks like system enumeration, executing remote commands, and crafting obfuscated scripts to bypass defenses. Its deep integration with all systems makes it a powerful tool for simulating attacks and testing systems' resilience against real-world threats.

  • System Administrators: PowerShell scripting is beneficial for automating integrity checks, managing system configurations, and securing networks, especially in remote or large-scale environments. PowerShell scripts can be designed to enforce security policies, monitor system health, and respond automatically to security incidents, thereby strengthening the overall security posture.

Whether used defensively or offensively, PowerShell scripting is an essential capability in the cybersecurity toolkit.

Invoke-Command Cmdlet is also worth mentioning in this context. Invoke-Command is essential for executing commands on remote systems, making it fundamental for system administrators, security engineers, and penetration testers. Invoke-Command enables efficient remote management and, when combined with scripting, automates tasks across multiple machines. It can also be used by penetration testers (or attackers) to execute payloads or commands on target systems during an engagement.

Here are some examples of using this powerful cmdlet:

Terminal:

pgsql
PS C:\Users\captain> Get-Help Invoke-Command -examples NAME Invoke-Command SYNOPSIS Runs commands on local and remote computers. ------------- Example 1: Run a script on a server ------------- Invoke-Command -FilePath c:\scripts\test.ps1 -ComputerName Server01 The FilePath parameter specifies a script located on the local computer. The script runs on the remote computer and the results are returned to the local computer. --------- Example 2: Run a command on a remote server --------- Invoke-Command -ComputerName Server01 -Credential Domain01\User01 -ScriptBlock { Get-Culture } The ComputerName parameter specifies the name of the remote computer. The Credential parameter runs the command in the security context of Domain01\User01, a user with permission to run commands. The ScriptBlock parameter specifies the command to be run on the remote computer. In response, PowerShell requests the password and authentication method for the User01 account. It then runs the command on the Server01 computer and returns the result.

The first two examples provided by the Get-Help "examples" page demonstrate the simplicity and power of the Invoke-Command cmdlet. The first shows how easily it can be combined with any custom script to automate tasks on remote computers. The second shows that you don’t need to know how to script to benefit from the power of Invoke-Command. By simply appending the -ScriptBlock parameter, you can execute any command or sequence of commands on a remote computer.