Lorentz' dev blog

Hacktivitycon writeup - Template Shack

Template Shack was a challenge worth 150 points in the 2020 Hacktivitycon CTF. The template shack appears to be some sort of online shop for bootsrap themes. The site seems to be mostly static and placeholder code. The only thing of note in the source code for the page is a comment that hints at some administration panel that is under construction.

TryHackMe writeup - Overpass

Here’s how I rooted the room overpass on tryhackme.com. All in all, the room was pretty easy, but I actually spent a lot of time figuring it out because I was overthinking.

How to use multiple Microsoft accounts without going insane

For the last couple of weeks I have had sort of an identity crisis. Working as a consultant, I have too many credentials for o365/azure/azure AD; being signed in to the right account at the right time has become impossible. Luckily there is a feature in chrome that will cure you of any virtual schizophrenia. If you click your name at the top of the title bar, you’ll find a menu with a choice to manage people.

The chrome menu that lets you manage your personality disorder

This will take you to a management screen that lets you add people you can switch between. The chrome people management screen

Now you’ll be able to easily switch between your personalities. Each personality has its own private data, so your sessions will be completely separate. They also have a separate window with a custom icon so that it’s easy to distinguish them from each other. Awesome!

Each person gets its own customized icon

Maintain the same version no. across multiple .net assemblies

If you want several projects to always have the same version number, this is a pretty neat trick:

  1. Remove AssemblyVerison and AssemblyFileVersion from existing AssemblyInfo.cs files
  2. Add a CommonAssemblyInfo.cs file to one of the projects containing just:

     using System.Reflection;
    
     [assembly: AssemblyVersion("2.3.1.0")]
     [assembly: AssemblyFileVersion("2.3.1.0")]
    
  3. In the other projects add existing item choose the CommonAssemblyInfo.cs, but remember to add it as a link (click on the arrow on the add button)

Keyed Collection

This week I found a cool .net-class in the System.Collections.ObjectModel namespace; the class KeyedCollection<TKey,TItem>.

It provides a collection that can be indexed by a property. If your item-class has a natural key, all you have to do is derive from the abstract KeyedCollection-class and implement the GetKeyForItem method. It behaves pretty much like a mix between a dictionary and a list. Lookups are indexed by a key you can specify, which in turn is used as the key for an internal dictionary, and so are faster than searching a regular list.

It is documented further here.

public class SchoolClass : KeyedCollection<uint, Student>
{
    protected override uint GetKeyForItem(Student newStudent)
    {
        return newStudent.Number;
    }
}

Euler Problem 92

Here’s my solution to Euler problem 92. The code is pretty simple, it tries to shortcut the sequence by storing every number in a chain along with the number that recurs.

class Euler92:
    def __init__(self):
        self.knownSeq = {}

    def ChainNumber(self,n):
        currentSeq = []
        while not n in [1,89]:
            currentSeq.append(n)
            if(n in self.knownSeq):
                n = self.knownSeq[n]
            else:
                n = SquareDigits(n)
        for x in currentSeq:
            self.knownSeq[x] = n
        return n

    def Solve(self, n):
        return len([x for x in range(2,n) if self.ChainNumber(x) == 89])
        
def SquareDigits(n):
        return sum(map(lambda x: int(x)**2, str(n)))

Euler Problem 59

This is my solution to Euler problem 59 in python. It is pretty straight forward and relies on the heuristics of the problem. Initially it filters out every key that will only produce printable characters for all its corresponding positions in the encrypted text. It then proceeds to combine these keys and check for actual, common English words in the text.

from math import ceil
import string

def test():
    asciis = open('cipher1.txt', 'r').read()
    encCodes = [int(s) for s in asciis.split(',')]

    asciiSum = 0
    
    pKeys = plausibleKeys(encCodes, 3)
    for k0 in pKeys[0]:
        for k1 in pKeys[1]:
            for k2 in pKeys[2]:
                text = "".join(applyKey([k0,k1,k2], encCodes))
                if(properStringProbability(text)):
                    print(text)
                    asciiSum = sum([ord(c) for c in text])
    return asciiSum

def plausibleKeys(encCodes, keyLen):
    pKeys = {
        0: [x for x in range(255)],
        1: [y for y in range(255)],
        2: [z for z in range(255)]
        }

    for i, c in enumerate(encCodes):
        for k in pKeys[i % keyLen]:
            if chr(c ^ k) not in string.printable:
                pKeys[i % keyLen].remove(k)
    return pKeys

def properStringProbability(string):
    cnt = 0
    for word in ["the", "and", "have", "that", "you"]:
        cnt += string.count(word)        
    return cnt > 5


def applyKey(key, asciiText):
    return [chr(x ^ int(y)) for (x,y) in zip(key * int(ceil(len(asciiText) / 3)),asciiText)]