PowerShell Introduction
zoziel

PowerShell Introduction

I wrote this article to show a brief introduction about how to use PowerShell daily. Many professionals work effectively with the command line in Linux, but when they need to do the same in windows I'm not a PowerShell professional, but I'd like to share a little bit of knowledge with the community.

What is PowerShell?

PowerShell is a cross-platform task automation solution consisting of a command-line shell, a scripting language, and a configuration management framework. PowerShell runs on Windows, Linux, and macOS. In addition, it's based on the .Net framework and is tightly integrated with Windows.

  • Provides access to almost everything in a Windows platform and Active Directory Environment, which could be helpful for an attacker.
  • Provides the capability of running powerful scripts entirely from memory, making it ideal for foothold shells/boxes.
  • PowerShell is easy to learn and powerful.

In the link below, you'll find more information about PowerShell.

PowerShell System

Let's start talking about the PowerShell Help System and its usability. Many professionals use the command line, but some don’t know how helpful and powerful it can be. On a daily basis when someone forgets what command to use this can be essential to help. This command shows a brief help about cmdlet or topic you wish to understand, it usually comes with various options and filters.

We can user Get-Help, Help, and -?

  • Get-Help

No alt text provided for this image

  • Help

No alt text provided for this image

  • -?

No alt text provided for this image

Please keep in mind the result is the same for the three options. So feel free to use which you think is better.

  • Get-Help * ( Lists everything about the help topics )

No alt text provided for this image

Get-Help test ?( Lists everything which contains the word process )

No alt text provided for this image

  • Get-Help process ( Lists everything which contains the word process )

No alt text provided for this image

  • Get-Help Test-NetConnection ( Lists a simple help about a topic )

No alt text provided for this image

  • Get-Help Test-NetConnection -Full ( Lists full help about a topic, like parameters, Test-NetConnection cmdlet in this case )

No alt text provided for this image

PowerShell Cmdlets

A cmdlet is a lightweight command that is used in the PowerShell environment. The PowerShell runtime invokes these cmdlets within the context of automation scripts that are provided at the command line. The PowerShell runtime also invokes them programmatically through PowerShell APIs.

In the link below, you'll find more information about PowerShell Cmdlets.

We can use the below command for listing all cmdlets

  • Get-Command -CommandType cmdlet

No alt text provided for this image

Get-Alias * ( Lists all aliases created )

No alt text provided for this image

Now I'll list some interesting cmdlets to use on daily basis.

  • Get-Process ( lists all process that is running )

No alt text provided for this image

I create a while using (get-process / ps) to show CPU consumption every 3 seconds used by the processes.

  • While(1) {get-process | sort -des cpu | select -f 15 | ft -a; sleep 3; cls} ( lists the 15 firsts process that is running time each 3 seconds)

No alt text provided for this image

3 seconds after new status about the process

No alt text provided for this image

  • Get-CIMInstance Win32_OperatingSystem | Select FreePhysicalMemory ( lists Memory free )

No alt text provided for this image

  • Get-ChildItem / ls ( lists all files / folders)

No alt text provided for this image

  • New-Item -Path 'new_folder' -ItemType Directory ( Creating a folder )

No alt text provided for this image

  • New-Item -Path '.\new_folder\file.txt' -ItemType File ( Creating a file.txt )

No alt text provided for this image

  • Select-String ( Used to find a specific string )

No alt text provided for this image

  • type .\new_folder\file.txt | Select-String "test3" ( In the example below I created a file with 5 lines and strings differents, I read and after I researched by string "test3" inside the file.txt )

No alt text provided for this image

  • Test-NetConnection -ComputerName hulk -Port 445 ( this substitute telnet command )

No alt text provided for this image

  • Get-WinEvent -ListLog * ( Get all the logs from a local computer )

No alt text provided for this image

  • Get-WinEvent -Path 'C:\Windows\System32\Winevt\Logs\System.evtx' -MaxEvents 6 ( Get a specific number of events from an archived event log )

No alt text provided for this image

  • Get-LocalUser ( Show all users from a local computer )

No alt text provided for this image

  • Get-LocalGroup ( Show all groups from a local computer )

No alt text provided for this image

So this is the first approach to PowerShell and its possibilities. There are several things to use daily. First, PowerShell is essential when you don't have graphic access to the server or workstation. It can be an excellent and powerful tool to use during an incident response, pentest or solve problems. I hope this information is helpful, and I intend to create a part II to discuss more.

Jance Luiz

Information Security Coordinator / Consultant / Analyst

3 年

Parabéns pelo artigo.

Abu Baker Gondal

Chief Technologist @ YOTTABYTE | vCISO | Compliance Management

3 年

Great work Zoziel F.

Fábio C Premoli

IT Security Analyst

3 年

Congratulations Zoziel Pinto F. Powershell, since it was implemented in the Windows operating system, has brought us many facilities for data collection and remote execution, as well as facilitating some malicious activities for malicious agents. Until today many of us were lost with the commands and updates, congratulations again for the article.

Lisa Nguyen

Information Security and Wireless Admin at Saint Paul College-A Community and Technical College

3 年

Thanks for sharing

要查看或添加评论,请登录

Zoziel P.的更多文章

  • From the Zero to Malware Discovery

    From the Zero to Malware Discovery

    Hello people, I was with some time, and I decided to made an analysis using some tools that I commented last post…

    29 条评论
  • Windows Analysis Tips and Tools

    Windows Analysis Tips and Tools

    Hi people, I found some old notes, but useful that I use during an incident, and I decided to share these tools and…

    14 条评论
  • Ransomware is not just a threat, it's a crisis waiting to happen...

    Ransomware is not just a threat, it's a crisis waiting to happen...

    Although I haven't posted anything here, I wanted to share my thoughts on my favorite wicked malware: ransomware. To…

    21 条评论
  • Analyzing Steal Bank Account with Malicious PDF

    Analyzing Steal Bank Account with Malicious PDF

    Hi everyone, as have time I don't post anything, I decided to write one more analysis about stolen bank accounts and…

    11 条评论
  • Analise de arquivos maliciosos - Exemplo 01

    Analise de arquivos maliciosos - Exemplo 01

    English Version O intuito dessa série de artigos é exibir analises de exemplos de arquivos maliciosos que apresentei…

    13 条评论
  • Malicious file analysis - Example 01

    Malicious file analysis - Example 01

    My objective with this series of articles is to show an analysis of examples of malicious files that I presented during…

    3 条评论
  • Analisando ataques de phishing que usam PDFs maliciosos

    Analisando ataques de phishing que usam PDFs maliciosos

    Todos os dias nós recebemos muitos ataques de phishing com documentos(Word, Excel) ou PDFs maliciosos. Resolvi dar uma…

    11 条评论
  • Analyzing Phishing attacks that use malicious PDFs

    Analyzing Phishing attacks that use malicious PDFs

    Portuguese version Every day everybody receives many phishing attacks with malicious docs or PDFs. I decided to take a…

    8 条评论
  • Carreira em Cybersecurity

    Carreira em Cybersecurity

    English Version Fala galera sempre escrevo artigos, compartilho posts de alguns sites que acompanho e acho relevante…

    10 条评论
  • Cybersecurity career

    Cybersecurity career

    Hey guys, I always write articles, share posts from some sites that I follow and find relevant. Among these various…

    4 条评论

社区洞察

其他会员也浏览了