Search This Blog
Sunday, November 20, 2022
Review: Xiaomi Redmi 10C
Wednesday, November 16, 2022
Windows: Maintenance and debloating
Commands to run in PowerShell
When changes have been made to the group policy you can try this command to force an update. Pay attention to what settings that override which as well so that you aren't waiting for an update that might not show up.
Some programs to run
Apart from these commands that you can run as admin in the PowerShell window, there are a few built-in programs that you find by searching in your start menu. These are just a good habit to run once in a while to do some cleaning:
Debloating script
# Silence errors
$ErrorActionPreference = 'SilentlyContinue';
# App list
$applist = "*3dbuilder*","*windowsalarms*","*windowscommunicationsapps*","*windowscamera*",
"*officehub*","*skypeapp*","*getstarted*","*zunemusic*","*windowsmaps*","*solitairecollection*",
"*bingfinance*","*zunevideo*","*bingnews*","*onenote*","*people*","*bingsports*","*soundrecorder*",
"*bingweather*","*xboxapp*","*xbox*","*Microsoft.MixedReality.Portal*","*GetHelp*","*Microsoft.Messaging*",
"*sketch*","*sticky*","*phone*","*sticky*","*photos*","*calc*","*gethelp*","*camera*"
foreach ($app in $applist) {Get-AppxPackage $app | Remove-AppxPackage}
Monday, November 14, 2022
PowerShell: Password generating function
Passwords - the basics
Having a long password is usually better than just a complex short password. When attackers attempt to crack your password they will try different techniques such as brute forcing. That is when they have a dictionary of common passwords that they try to use to get into your account. Sometimes they will try one sequence of characters after another.
AAAA... AAAB.... ABCC....ABCD... and eventually the account goes "pop".
Just like a padlock there is a fixed amount of combinations.
A padlock has 0-9 per wheel usually. Which is ten characters per wheel. You can calculate the total amount of combinations like Characters per wheel to the power of the number of wheels.
Four wheels with 10 numbers (0 through 9) is 10 x 10 x 10 x 10. Which also is written as 10^4. When scripting in PowerShell you write [math]::Pow(10,4). Here is the answer, 10000 combinations.
Let's say that the brute forcing computer can guess 1000 passwords per second. That leaves your account safe for 10 seconds if you have a 4 character long password.
By increasing the variation of characters (increasing the numbers per wheel on your padlock) and increasing the amount of characters in your password (increasing the amount of wheels on your padlock) your password will take longer time to crack.
However, store it well and preferably don't store it at all if possible. It doesn't matter if your password is 20 characters long and has a good complexity if it is stored in plain text in a file called "passwords.txt".
Those who store your password often store it "hashed" and "salted", to add extra complexity. Hashing uses a hashing function to scramble the password and salting adds random characters. If the passwords are leaked they will not be in plain text. Therefore some malicious actors will store pre-hashed password lists to match with the leaked hashed list of passwords to then compare the two.
Generating a password using PowerShell
<# Parameters with default values #>
[alias("npwd")]
[cmdletbinding()]
param
(
[Parameter()]
[alias("Length")]
[int]$DesiredPasswordLength = 15,
[alias("c", "copy")]
[switch]$CopyPassword = $False
)
<# Available characters #>
[string]$AvailableCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!?@#";
<# Random letter from available characters #>
function Get-RandomLetter {
$AvailableCharacters[(Get-Random ($AvailableCharacters.Length))]
}
<# Build string #>
[string]$Password = ""
Do {$Password += Get-RandomLetter;} While ($Password.Length -lt $DesiredPasswordLength)
$PasswordLength = $Password.Length
<# Output #>
[float]$NumberOfCombinations = [math]::Pow($AvailableCharacters.Length,$Password.Length)
Write-Output "Your generated password is $Password and is $PasswordLength characters long. Complexity: $NumberOfCombinations combinations."
if ($CopyPassword) {$Password | Set-Clipboard} else {Break}
}
A few last thoughts
Tuesday, November 8, 2022
PowerShell: Send email with attachment
It was when I was working on a hobby project that I did some research on how to send emails using PowerShell.
It wasn't the first time I managed to pull it off but I had forgotten how to script it, so I did some research.
Two parts at least seems to be needed, the credentials for the sender and the necessary variables for the email itself, such as header and content.
In this post I will discuss the credentials first, then the sending part. All this code was tested using PowerShell ISE. Microsoft writes that the cmdlet Send-Mailmessage is a bit outdated, so be wary.
Credentials
Sending the email
Conclusion
Friday, November 4, 2022
Registry: Modifying the context menu
Whenever you are right-clicking in your explorer or on your desktop you bring out what is called the context menu.
After doing some research and testing I found ways to add programs of my liking to this menu by editing the registry.
In this example, I used pestudio, a program that you can investigate .exe-files with. You can download it from this page for free. I wanted to add this program to the menu in order to open other files with it.
Step one is to navigate to HKEY_CLASSES_ROOT\*\shell\
Then you create a subkey called whatever you want the menu to display, such as "Open with PE". Within this key you then create another key called command, and this is something you do regardless of what program you are going to add.
Step two is to edit the default file located in "command". Set the value to the file path within quotation marks, followed by space, followed by %1 in quotation marks. For example:
"C:\Program Files (x86)\pestudio\pestudio.exe" "%1"
Step three is to add an icon. Enter the parent key this time, by clicking on "Open with PE". Within this key you create a string named Icon with the file path as data. Make sure to put a comma and a 0 at the end to retrieve the built in icon:
Now you should be able to see the icon, the menu name and the program you linked should be able to open the files that you right click.
If you want to turn this into a .reg-file you can use this code:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Open with PE\command]
"(Default)"="\"C:\Program Files (x86)\pestudio\pestudio.exe\" \"%1\""
[HKEY_CLASSES_ROOT\*\shell\Open with PE]
"Icon"="C:\Program Files (x86)\pestudio\pestudio.exe,0"