Search This Blog

Friday, January 19, 2024

Raspberry Pi 5: Ubuntu server installation

Prerequisites

To get Ubuntu Server on Raspberry Pi it was actually as easy as just getting the Raspberry Pi imager from the official website.

Install it and run it directly.

Choose device (raspberry pi 5), choose OS (other general-purpose OS -> Ubuntu -> Ubuntu Server)

Choose a device to flash it to.

You will have options to include into your file, these are important. You want to set up wifi, make sure SSH is active and set an admin login, this is used later when you SSH in with PowerShell and when you login to the server with RDP. 

Flash the OS to the SD card, you are now done with the first step.

First time booting Ubuntu Server on Raspberry Pi 5

Put the SD card in the device. Keyboard, mouse and monitor is optional as you can manage the device wirelessly and remotely right away if you performed the options detailed in part 1.

Go to your router and find the IP address of the device, this is used in next step.

Open PowerShell and write ssh admin@192.168.0.X where admin is the user name and X is the last part of the IP address. Confirm with password. SSH is a secure alternative to Telnet.

You will then be taken to an admin prompt that takes linux commands.
You might want to start with the following command:

sudo apt-get update && sudo apt-get upgrade

Make sure to confirm if it prompts you.  

GUI and RDP to Ubuntu Server

The last step was to configure a desktop experience and RDP.

For the deskop experience I simply ran two commands, it would seem that the first one is required.

sudo apt install ubuntu-desktop-minimal

sudo apt-get install xfce4

If prompted, I went with the option lightdm and I restarted all serviced that asked me too, some which also disconnected me from the internet.

For the RDP I first ran the following command:

sudo apt install xrdp -y

Followed by this command that shows you if the installation went alright.

sudo systemctl status xrdp

After that I could RDP using the built-in solution on Windows. Some sources claim you need to fix ssl certs and restart the service, but I could start it right away.

Configure your RDP from your Windows computer

Configure a RDP link on your desktop with the following steps:

1. Open remote desktop connection from your start menu

2. Pick "show options"

3. Computer should be the IP address, user name is the one you entered at the flashing of the image

4. Save as, place it in a good location. Now you can use it and just entering your password.

When you login using RDP you will be greeted with a more familiar desktop experience.


Enjoy!

Windows 11: Hosting a Minecraft Bedrock server

This post will cover various steps to get a Minecraft server running on Windows 11.

For my experiment I was running it on an old laptop with x64 processor, it can also run bedrock server on the ARM-architecture and Ubuntu Server. For the sake of this post we will in other words just assume that you are running Win 11 and want to install the Bedrock server.

Prerequisites

I downloaded the server first and noticed that I was missing the Visual C++ Redistributable.
So my recommendation is to download both.



Once both are installed you need extract the bedrock zip-file as well, and place the extracted folder in a place that you are familiar with. I created a C:\Minecraft\ folder in which I placed it.

Configuring your server

As I already have a world on another computer, I wanted to transfer this world and keep it on the server instead.

To find your world, go to %localappdata% then go to 

...\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang\minecraftWorlds

Within this directory each world has its own folder. Move this folder to your server computer.
You will have configuration file in your bedrock server folder in which you can point towards this world.

Getting your server online and available

If you don't make any changes and just run the bedrock_server.exe right of the bat, it becomes instantly available in the Minecraft client on another computer on the same network. Basically it is considered a LAN server and it is not available online for others to join.

Joining the server

To join the server on regular LAN, just open your Minecraft Bedrock client on the computer you intend to play from and make sure you are on the same network. Then you should find the world in the "server" section in the game.


Review: SanDisk Extreme 128GB and Kingston DataTraveler Micro Metal 256GB

As part of my Raspberry Pi 5 inital experimentation, I got some high quality hardware as well.

I decided to test the hardware using CrystalDiskMark.
These are the results of some quick testing.

Kingston DataTraveler Micro Metal 256GB:




SanDisk Extreme 128GB:



As you can see, the SD card performs well where the USB drive is not, and vice versa. I am currently running my Ubuntu Server off of the SD-card and using the USB drive as extra storage.

Raspberry Pi 5: Installing Windows 11

Previously I have had a Raspberry Pi 3b+  and after that I had a Raspberry Pi 4, 8GB, both which I ran Windows 10 on. Times have changed and I got the next generation of this single board computer now. During my research I found out that there now are people that have managed to get Windows 11 Enterprise running on a Raspberry Pi 5. 

Keep in mind that the platform uses ARM processor so that you will get that version of Windows, but it is also supposed to have a built-in system that can simulate the x64 architecture.

One of my experiments that I have planned, is to keep a Minecraft Bedrock server running on my Raspberry Pi 5 that will be installed with Windows 11.

The hardware

For this project I got the following hardware which set me back €178 or 1999 SEK.
The following is a breakdown of the costs converted to EUR.

SanDisk Extreme microSD card (128gb) €27

Kingston DataTraveler Micro Metal (256gb) €22

Raspberry Pi 5 (8gb) €76

Original case with fan €9

Charger €11

Import fee/VAT €33

I bought my Raspberry Pi 5 from The Pi Hut. The purchase experience was relatively smooth, but the transport time was super slow (keep in mind that I had already been waiting quite some time since my pre-purchase). Then the Pi got stuck in transit because I had to pay €30 in import fees as well. It was shipped around 29:th of December and has to this date not yet arrived. Something to keep in mind when you pick your point of purchase in other words.

The installation process

For this experiment, I followed this video to get Windows 11 on Raspberry Pi 5.

You will need UEFI-files (the files used for booting up pretty much) which can be downloaded here
Once downloaded, unzip the archive and place the files on your SD-card. The SD-card needs to be formatted as FAT32, I had trouble flashing it so had to partition it to a part that was smaller than 32GB.

Download the Win11 Enterprise ARM64 image as well from this link, this is what you flash to the USB.
As of January 2024 I used the following settings: Windows 11, latest build, ARM64 architecture, Enterprise edition and English (UK) as language.

You will need the WoR (Windows on Raspberry) program, this contains the script that allows flashing of the iso. Download and then extract contents to a new folder that you name to something intelligible.

Start WoR.exe as admin, go through the guide, make sure to choose Raspberry Pi 3. This is because boot files and main OS are kept separately at this stage. This step took a long time, so make sure to start early.

Put the SD card and the USB into the Raspberry Pi and your peripherals, then boot it up. After that it is pretty much a standard Windows 11 experience, but you are not running an activated version so you will miss out on certain customization.

Verdict

Well, after a lot of struggle I managed to get it running. The experience albeit familiar, it was also extremely slow, you can not do anything practical with this setup at this point. There can be minutes of delay after pressing a key and SFC /scannow and the DISM restorehealth commands can take hours, just to fail. Getting a bedrock server on this setup would not be feasible, neither RDP or Enable-PSRemoting worked.

Perhaps in the future there will be a better experience, but for now my recommendation is to not run with this setup. It was a good experiment.


Sunday, January 14, 2024

Windows 11: Change boot logo follow-up

Fix for missing A: drive during HackBGRT image replacement

This post is a follow-up for the original post that I made, that you can find here. I had just downloaded HackBGRT again after the computer had been trying out different OS:es and had a complete reformatting of the harddrive. This time the changing of the boot logo would not work because I experienced issues during the replacement of the image itself.

When the cmd window that HackBGRT opens up you eventually should be able to see the A: drive using the file explorer from Paints "open file" function. On my computer this time the A: drive would not show up. This post is simply a quick description of how I could work around it.

1. First I ran the script like normal, but I couldn't find the A: drive so I just saved the image over the default image that HackBGRT comes with. Then I exited the script and rebooted, it had at least updated the attached image but not my image. This means that the script is working.

2. I saved my image in a location that was easy to access.

3. Open PowerShell as admin and entered the following commands:
diskpart
sel disk 0
list part
sel part 0 (or whatever number corresponds to your EFI drive)
assign letter=A
exit

4. Still in admin PowerShell I entered the following code to copy the image and overwrite the one in A:
Copy-Item -Path C:\temp\splash.bmp -Destination A:\EFI\HackBGRT\ -Force

5. Reboot the computer and see if the logo has changed.

Tuesday, December 26, 2023

PowerShell: Automating Cheats in Star Wars Knights of the Old Republic

Hello,

This blog post builds a bit on techniques such as sendkey/sendwait, allowing the PowerShell user to automate keystrokes which helps a lot when entering lengthy cheat codes into older games.
As I am using a nordic keyboard layout the way to open the Kotor 2 console is to press shift + backtick.
Keep in mind that you have to edit one of the files in the Steam folder to enable cheats for Knights of the Old Republic 2.

The PowerShell code:

# KOTOR 2 Auto Cheater #

# Sendkey functions #
$Backtick = "+(´)"
$Space = " "
$Enter = "{ENTER}"

<# Cheats hard codes from https://steamcommunity.com/sharedfiles/filedetails/?id=149123471
These variable each contains the actual cheat code of choice, giving you a long list of favorite codes.#>
$treat = "settreatinjury 40"
$compuse = "setcomputeruse 40"
$demo = "setdemolitions 40"
$stealth = "setstealth 40"
$aware = "setawareness 40"
$charm = "setcharisma 40"
$wis = "setwisdom 40"
$int = "setintelligence 40"
$const = "setconstitution 40"
$dex = "setdexterity 40"
$str = "setstrength 40"
$sec = "setsecurity 40"
$rep = "setrepair 40"
$pers = "setpersuade 40"
$exp = "addexp 999999"

# List used in loop, here you simply add variables that you want to include in the loop. #
$listofcheats = $treat, $compuse, $demo, $stealth, $aware, $charm, $wis, $int, $const, $dex, $str, $sec, $rep, $pers, $exp

# This function is responsible for opening the console only. One function, one purpose. #
function Open-Console {
[System.Windows.Forms.SendKeys]::SendWait($Backtick)
[System.Windows.Forms.SendKeys]::SendWait($Space)
}

# This function is responsible for using the cheat that was typed into the Kotor 2 console. #
function Send-Cheat {
[System.Windows.Forms.SendKeys]::SendWait($Enter)
}

<# This is a simple one of function, that accurately lets you reuse a single cheat code without the worry of misspelling #>
function Use-Cheat($code) {
Start-Sleep -Seconds 5;
Open-Console;
[System.Windows.Forms.SendKeys]::SendWait($code);
Send-Cheat;
}

# This is is the automatic function, it runs through the entire list you customize in the script. #
function Use-AllCheats {
    foreach ($cheat in $listofcheats) {
        Start-Sleep -Seconds 5;
        Open-Console;
        [System.Windows.Forms.SendKeys]::SendWait($cheat);
        Send-Cheat;
    }
}

Sunday, December 17, 2023

Windows: Automatic login

Introduction

This post will briefly show how you can set up your Windows device to automatically login upon starting the computer, it works for restarts as well.

It consists of two parts, first part is the GUI way and if that way doesn't work there is registry way.

The necessary security caveat:
Do not add this to a computer that can fall into the hands of the wrong person. It will decrease your device security and it is not encouraged, this post simply illustrates how it can be done.

The GUI way

Start netplwiz from either run or PowerShell.

Right away you will see an option "users must enter a user name and password to use this computer".

Uncheck this, confirm with your password. 

If the option is missing you will have to do the registry way instead.

The registry way

Create a registry file with the following text:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\PasswordLess\Device\]
"DevicePasswordLessBuildVersion"=dword:00000000

After you have saved it as a .reg-file, you can run it and it will make the necessary changes.
You can probably see the option now in step one if you are curious.

Give the computer a restart and it should now automatically log you into the user.


PowerShell: Create scheduled task

Case where a scheduled task comes in handy

Lately I've been suffering from a explorer process that is not starting upon boot of the computer.

I log in to Windows and the screen is completely black, apart from the mouse pointer sometimes. I've had this issue on a couple of computers over the years, while it is nothing dangerous and easy to fix, it is still annoying.

The quick fix is easy, start task manager using Ctrl + Shift + Escape and run the new task "explorer.exe".

However, I wanted to explore the PowerShell way of perhaps creating a scheduled task that simply checks if the explorer is running, and if not, apply the quick fix automatically. Also I explored whether I could use .bat-file to run a PowerShell script that registers this scheduled task. Unfortunately, for a quick and safe fix it didn't work, you either have to write a more complicated workaround or run the bat file as an admin, which then introduced some other issues. The goal was to keep it very simple.

The PowerShell script that is a failsafe for the explorer process

The code for the fix script looks like this:

function Start-Explorer {

    Start-Process explorer.exe;

}

$Explorer = Get-Process -Name explorer -ErrorAction SilentlyContinue

if (-Not($Explorer)) {

    Start-Explorer;

}

Manually scheduling a task in taskschd.msc

It is completely fine to save this to a .ps1-file and then manually create a scheduled task. Simply start task scheduler, hit "new basic task" once you are in the main folder of tasks.

Trigger:
Being logging in.

Action:
Start a program.

Program/script:
powershell.exe

The added arguments:
-windowstyle hidden -executionpolicy bypass -scope currentuser "C:\temp\PathToScript.ps1"

Basically this tells the computer that upon login (by the user creating the task), run the specified script while bypassing execution policy and only for the user, this time.

Scheduling a task using PowerShell, the basics

This is the very basic method of a PowerShell script that is intended to register a task in the task scheduler. When I tried dot sourcing it, it failed to bypass the execution policy and when I dot sourced it as an admin it created a scheduled task for all users of the computer. This could probably be altered with more detailed parameters and a permanent fix of the execution policy, but it is beside the point of this post. The point of this segment is to show the basic mechanics of using PowerShell to schedule a task.

$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-executionpolicy bypass -file `\"C:\Temp\Sample.ps1`\""
$trigger = New-ScheduledTaskTrigger -AtLogon
$task = New-ScheduledTask -Action $action -Trigger $trigger
Register-ScheduledTask NameOfTask -InputObject $task

As you can see it is a quite interesting and straightforward mechanic.

  1. The very first step is that you tell the computer what to do, in this case run a script with a few parameters, the extra symbols in the file path helps to character escape the extra quotes.
  2. Secondly you tell the computer when to do it, the trigger, in this case upon logging in.
  3. Third you combine the what and when into a task variable.
  4. Lastly you register this task, giving it a name and supplying the task variable to the cmdlet.
When working with PowerShell and the task scheduler, you can of course supply much more details, for example which user should be affected. However, from what I could see you are required to run this script as an admin if you want to run it from the console (dot sourcing).

Creating a .bat-file that runs a PowerShell script

As an added bonus and to wrap up the post of today, I will show you a simple way to use a bat file to kickstart a .ps1-file, with supplied parameters like execution policy bypass.

Open notepad, create a file with the following command:

powershell.exe -ExecutionPolicy Bypass -File .\ScriptInSameDirectory.ps1

You can add parameters like 
-nologo 
-windowstyle hidden 
-executionpolicy bypass and to specify current user add -scope currentuser

Note that if the .bat-file is not in the same folder as the target .ps1 you need to specify full path.

Good luck!

Thursday, December 7, 2023

Review: Alogic MX3 Docking station

A while back ago I got an Alogic MX3, it is a docking station with 3 displayports that I use to connect both my work computer and personal computer.

They are both connected using a USB-C cable to the dock, so when my work day is complete I can connect my personal computer instead.

So far I am rather okay with it, but I've noticed some unfortunate characteristics.

It is too underpowered to reliably power my Surface Pro 7, my Surface Dock 2 does not have that issues. The symptom is that the Alogic MX3 dock does show content on all three monitors but it doesn't charge the battery. Peripherals does not seem to be affected. 

When switching from my work computer to my personal computer it sometimes does not activate my third monitor as well.

The solution to the power issue is to turn the dock off for a few seconds and then turn it on again, that way it seems to start charging the computer again. As for the monitor issue it is simply a matter of extending the screen again to the third monitor.

The over all impression is that the dock looks good, has the right ports for my needs, is easy to work with but I would not recommend a purchase due to the quality of life issues I am experiencing.

Sunday, November 26, 2023

Cryptography: Enciphering with PowerShell

The idea came to me after having followed some ARG's (alternate reality games), where people solve puzzles, often decoding some enciphered texts using more or lesser known cipher techniques, such as the classic Caesar Cipher, where you shift a letter in the alphabet a number of steps.

I wanted to see if I could create a script in PowerShell that would perform this action, after prompting ChatGPT a bit I managed to get the main logic behind the shifting.

This was put into an encoding function and a decoding function. Later on after the script matured, I decided to create a basic GUI for it, based off of the simple password generator I had created earlier.

This version offers you case cleaing, optional clipboard copy and decoding/encoding. In the future there might be some error handling put into the code, such as handling empty text fields.




This is what the code looks like:

# Caesar cipher /w GUI #


[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")


$Main = New-Object System.Windows.Forms.Form

$Main.text = "Caesar Cipher 1.1"

$Main.size = New-Object system.drawing.size(600,200)

$Main.BackColor = "DarkGray"

$Main.FormBorderStyle = "FixedDialog"


$PlainText = New-Object System.Windows.Forms.TextBox

$PlainText.Size = New-Object System.Drawing.Size(400,100)

$PlainText.Location = New-Object System.Drawing.Size(50,30)

$PlainText.BackColor = "Black"

$PlainText.ForeColor = "LightGreen"

$Main.Controls.Add($PlainText)


$CipherText = New-Object System.Windows.Forms.TextBox

$CipherText.Size = New-Object System.Drawing.Size(400,100)

$CipherText.Location = New-Object System.Drawing.Size(50,50)

$CipherText.BackColor = "Black"

$CipherText.ForeColor = "LightGreen"

$Main.Controls.Add($CipherText)


$Clipboard = New-Object System.Windows.Forms.CheckBox

$Clipboard.Size = New-Object System.Drawing.Size(80,40)

$Clipboard.Location = New-Object System.Drawing.Size(50,75)

$Clipboard.Checked = $False

$Clipboard.Text = "Clipboard"

$Main.Controls.Add($Clipboard)


$CipherKey = New-Object System.Windows.Forms.TextBox

$CipherKey.Size = New-Object System.Drawing.Size(30,50)

$CipherKey.Location = New-Object System.Drawing.Size(140,87)

$CipherKey.Text = "1"

$Main.Controls.Add($CipherKey)


function Encode-CaesarCipher {

    param ($pt, $ck)

    $pt = $PlainText.Text;

    $ck = $CipherKey.Text;

    $e = ""

    foreach ($c in $pt.ToUpper().ToCharArray()) {

        $x = [int][char]$c

        if ($x -ge 65 -and $x -le 90) { $e += [char](65 + (($x - 65 + $ck) % 26)) }

        elseif ($x -ge 97 -and $x -le 122) { $e += [char](97 + (($x - 97 + $ck) % 26)) }

        else { $e += $c }

    }

    $CipherText.text = $e

    if ($Clipboard.checked) {$e | Set-Clipboard}

}


function Decode-CaesarCipher {

    param ($ct, $ck)

    $ct = $CipherText.Text;

    $ck = $CipherKey.Text;

    $m = ""

    foreach ($c in $ct.ToUpper().ToCharArray()) {

        $x = [int][char]$c

        if ($x -ge 65 -and $x -le 90) { $m += [char](65 + (($x - 65 - $ck + 26) % 26)) }

        elseif ($x -ge 97 -and $x -le 122) { $m += [char](97 + (($x - 97 - $ck + 26) % 26)) }

        else { $m += $c }

    }

    $PlainText.text = $m

    if ($Clipboard.checked) {$m | Set-Clipboard}

}


$EncodeButton = New-Object System.Windows.Forms.Button

$EncodeButton.Size = New-Object System.Drawing.Size(60,40)

$EncodeButton.Location = New-Object System.Drawing.Size(180,87)

$EncodeButton.Text = "Encode"

$EncodeButton.BackColor = "Green"

$EncodeButton.ForeColor = "Yellow"

$EncodeButton.Add_Click({Encode-CaesarCipher;})

$Main.Controls.Add($EncodeButton)


$DecodeButton = New-Object System.Windows.Forms.Button

$DecodeButton.Size = New-Object System.Drawing.Size(60,40)

$DecodeButton.Location = New-Object System.Drawing.Size(250,87)

$DecodeButton.Text = "Decode"

$DecodeButton.BackColor = "Green"

$DecodeButton.ForeColor = "Yellow"

$DecodeButton.Add_Click({Decode-CaesarCipher;})

$Main.Controls.Add($DecodeButton)


[void] $Main.ShowDialog()