INTRO
No matter how good you are at CTF Challenges, you may not know how to edit a text file in Powershell. In reality, I don’t not a good score in Windows CTF challenges but these days I am learning more about windows. it is another matter that I can’t run Linux in this new Laptop. I mean, I can but with Virtualization.
PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and the associated scripting language. PowerShell supports aliases to refer to commands by alternate names. Aliasing allows users with experience in other shells to use common command names that they already know for similar operations in PowerShell. basically, it means that you can use cd
command instead of Set-Location
. cd
will be read as Set-Location
by the Powershell. Powershell scripting is mostly related to PHP and Linux shell scripting. all you have to learn new is cmdlets.
We are going to use two methods to edit a text file in Powershell. Both of the methods are going to be super simple. you won’t need to read or watch anything else but this article.
POWERSHELL
The first method we are going to look at is WSL. WLS stands for Windows subsystem for Linux. Windows Subsystem for Linux is a compatibility layer for running Linux binary executables natively on Windows 10 and Windows Server 2019. but this method won’t help you during a CTF. because WSL doesn’t come pre-installed in Windows. You will need to install it through Microsoft Store.
Screenshot:
You can install Ubuntu Linux, Kali Linux and many more Linux systems into your Windows10. once you have it installed, run it easily with a command prompt or any other terminal.
Screenshot:
As you know me, I am a Kali lover. so, I installed Kali. Now you can run nano command while you are in Kali’s terminal. if you want to edit a file which is a file of windows, you can find the file in the /mnt
directory. you will find all of your windows drive there.
Screenshot:
you can find your files there. but that might be frustrating, right? well, you can use the nano command without going into the Kali Linux shell. To do that you can use this command:
bash -c 'nano demo.txt'
Screenshot:
The next method we are going to use is Powershell cmdlets. we will use cmdlets in Powershell and edit a text file. so, open up your Powershell window. use this command to see all the files in the current folder:
Get-ChildItem
Screenshot:
Now, you choose the file to edit. there are basically two commands that you can use to edit a file. The first one is Set-Content
or you can use its alias sc
. it can be used when you want to overwrite a file with your given values. it will remove all the content of the file and then it will write your string value in that file. But To add string, type this command:
Add-Content -Path .\demo.txt -value "`n Nice And Easy"
Screenshot:
-Path
is to specify the path of the text file and -Value
is the string value that you want to insert into the text file. And another important thing to notice here is that I have used `n to add a new line before adding the string to a file. you can use Set-Content too in your case.
Thanks For Visiting.