mirror of
https://github.com/Kyren223/website.git
synced 2026-04-01 10:31:46 +00:00
More changes to the way blogs looks and minor blog tweaks
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: The search for the perfect SSH key
|
||||
description: How you can embed your name in an SSH key
|
||||
date: 2024-11-14
|
||||
date: 2024-11-15
|
||||
---
|
||||
|
||||
SSH keys are a widely used tool among developers,
|
||||
@@ -9,7 +9,7 @@ they are the equivalent of a username and password in the development world.
|
||||
They allow you to prove your identity and they are the gateway
|
||||
into accessing servers remotely in a secure manner.
|
||||
|
||||
### The ssh public key format
|
||||
## The SSH public key format
|
||||
|
||||
When generating an ssh key, you get 2 files, one with no extension that stores the private key
|
||||
and another that ends with a `.pub`.
|
||||
@@ -21,14 +21,16 @@ Here's how a typical SSH public key looks
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBSSj+yfJLWEb+Df4r4603TOFAUBREYS43qQB+c9i9UW
|
||||
```
|
||||
|
||||
It consists of 2 parts, the algorithm, in this case it's
|
||||
`ssh-ed25519`, other common algorithms are `ssh-rsa` and `ssh-ecdsa`.
|
||||
The second part is a base64 encoded custom binary format.
|
||||
|
||||
Let's break it down
|
||||
|
||||
- The first part `ssh-ed25519` is the algorithm type that was used, other common algorithms are `ssh-rsa` and `ssh-ecdsa`
|
||||
- The second part is a base64-encoded binary format consiting of the following
|
||||
- the length of the algorithm string, for ed25519 it's always 11 (4 bytes long)
|
||||
- the algorithm type, for ed25519 it's always `ssh-ed25519` in binary (11 bytes long)
|
||||
- the length of the key, 32 bytes for ed25519 (4 bytes long)
|
||||
- the raw bytes for the ed25519 key (32 bytes long)
|
||||
- the length of the algorithm string, for ed25519 it's always 11 (4 bytes long)
|
||||
- the algorithm type, for ed25519 it's always `ssh-ed25519` in binary (11 bytes long)
|
||||
- the length of the key, 32 bytes for ed25519 (4 bytes long)
|
||||
- the raw bytes for the ed25519 key (32 bytes long)
|
||||
|
||||
## Embedding a word in base64
|
||||
|
||||
@@ -38,20 +40,20 @@ it uses A-Z, a-z, 0-9, '/' and '+' adding up to 64 unique characters.
|
||||
It's possible to choose specific bytes in a way that when encoding it with base64
|
||||
it will form a word.
|
||||
|
||||
For example, to encode "Kyren" in base64, we can use the following bytes
|
||||
`00101011 00101010 01001110` or in hex `2b 2a de`
|
||||
For example, to encode "Kyren" in base64, we can use the bytes
|
||||
`00101011 00101010 01001110` or in hex `2b 2a de`.
|
||||
|
||||
So by controlling the 32 bytes at the end of the ssh we are able to get
|
||||
a ssh public key containig any keyword we want.
|
||||
|
||||
## Brute Force
|
||||
|
||||
Unfortunately this won't work, we still want to be able to use the key
|
||||
Unfortunately this approach won't work, we still want to be able to use the key
|
||||
so we will need to know the corresponding private key, but it's impossible to reverse engineer
|
||||
the private key using the public one, that's why cryptography is sosecure.
|
||||
the private key using the public one, that's why cryptography is so secure.
|
||||
|
||||
The solution is to just generate a bunch of keys until we get lucky and find the desired keyword.
|
||||
So that's exactly what I have done, here's a basic go program that does that.
|
||||
The solution is simple, just generate a bunch of keys until we get lucky and find the desired keyword.
|
||||
So that's what I have done, here's a basic go program that does exactly that.
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -81,11 +83,11 @@ func main() {
|
||||
```
|
||||
|
||||
I have later improved this program by adding multithreading and made it easier to use.
|
||||
The final code can be seen on my GitHub [in this link](https://github.com/Kyren223/ed25519-key-gen).
|
||||
The final code is available on my GitHub [at this link](https://github.com/Kyren223/ed25519-key-gen).
|
||||
|
||||
## Results
|
||||
|
||||
After running it for 2 days (about 24 hours in total) on my laptop with a AMD Ryzen 5 7530U (12 threads),
|
||||
After running it for 2 days (about 24 hours in total) on my AMD Ryzen 5 7530U laptop (12 threads),
|
||||
here are the results:
|
||||
|
||||
```
|
||||
@@ -96,21 +98,18 @@ Searched: 6733606724 Found: 737
|
||||
|
||||
- Generated and searched 150k SSH keys per second
|
||||
- Found a 5-character keyword every 9.1 million keys or about 1 every minute
|
||||
- Found a 6 character keywords every 1/64 of every 5-character keyword, or about 1 every hour
|
||||
- Found a 6 character keyword every 1/64 of every 5-character keyword, or about 1 every hour
|
||||
- Found 5-character that are at the end of the SSH key 1/50 of every 5-character keyword
|
||||
|
||||
My goal was to find either a `/kyren` or `+kyren` at the end of the key,
|
||||
on average that'd be 1/3200 5-character keywords.
|
||||
At the end after only 1862 5-char keywords I found 3 keys that matched what I was looking for:
|
||||
My goal was to find a `/kyren` at the end of the key,
|
||||
on average that'd be 1 every 3200 5-character keywords.
|
||||
|
||||
At the end after only 1862 keywords I found the key, here it is
|
||||
|
||||
```
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFjS3Pl+DZKyyoAl+ZN0FDsxyOWzLgNQo+YaYe+KYREN
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO7P9K9D5RkBk+JCRRS6AtHuTAc6cRpXfRfRMg/Kyren
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKEKL6f7j8U70si1YGPBUhIcsHtJIUeH+uiUlS+kyren
|
||||
```
|
||||
|
||||
I will be going with the middle one as my permanent SSH key.
|
||||
|
||||
I hope this inspires you to try and find your own SSH key,
|
||||
hopefully your name is not 7 characters long,
|
||||
and if it's 8, I hope you have 170 years to spare.
|
||||
@@ -2,6 +2,8 @@
|
||||
import { getCollection } from "astro:content";
|
||||
import Terminal from "@layouts/Terminal.astro";
|
||||
import BlogItem from "@components/BlogItem.astro";
|
||||
import Link from "@components/Link.astro";
|
||||
import TerminalBorder from "@components/TerminalBorder.astro";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const blogEntries = await getCollection("blogs");
|
||||
@@ -16,8 +18,8 @@ const { Content } = await entry.render();
|
||||
---
|
||||
|
||||
<Terminal path="blogs/">
|
||||
<div class="w-full h-[65vh] overflow-y-auto pr-4">
|
||||
<div class="text-[130%] h-full m-0 p-0">
|
||||
<div class="w-full h-[65vh] overflow-y-auto pr-4 border-box">
|
||||
<div class="text-[130%] h-full">
|
||||
<div class="text-[110%]">
|
||||
<BlogItem
|
||||
title={entry.data.title}
|
||||
@@ -26,16 +28,50 @@ const { Content } = await entry.render();
|
||||
/>
|
||||
</div>
|
||||
<div class="markdown">
|
||||
<h2>Somewhat of a long heading</h2>
|
||||
<Content />
|
||||
<Content components={{ a: Link }} />
|
||||
</div>
|
||||
<div class="ml-[1px] pt-2 grid grid-cols-[1fr_1fr] gap-4">
|
||||
<div class="min-w-0 invisible"></div>
|
||||
<TerminalBorder header="Previous Blog">
|
||||
<Link href="next" newTab={false}
|
||||
>vim ~/blogs/next-blog.md</Link
|
||||
>
|
||||
</TerminalBorder>
|
||||
<TerminalBorder header="Next Blog">
|
||||
<Link href="next" newTab={false}
|
||||
>vim ~/blogs/next-blog.md</Link
|
||||
>
|
||||
</TerminalBorder>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Terminal>
|
||||
|
||||
<style is:global>
|
||||
.markdown {
|
||||
user-select: text;
|
||||
}
|
||||
.markdown a {
|
||||
display: inline-block;
|
||||
font-weight: normal;
|
||||
}
|
||||
.markdown code {
|
||||
background: #333333;
|
||||
color: var(--accent);
|
||||
padding: 0 0.5rem;
|
||||
}
|
||||
.markdown ul {
|
||||
list-style-type: square;
|
||||
margin-left: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 90%;
|
||||
}
|
||||
.markdown li {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.markdown p {
|
||||
padding-bottom: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
user-select: text;
|
||||
}
|
||||
.markdown strong {
|
||||
font-weight: bold;
|
||||
@@ -43,11 +79,14 @@ const { Content } = await entry.render();
|
||||
.markdown h2 {
|
||||
color: var(--secondary);
|
||||
font-size: 125%;
|
||||
padding-bottom: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.markdown h3 {
|
||||
color: var(--secondary);
|
||||
font-size: 110%;
|
||||
padding-bottom: 0.25rem;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
.expressive-code {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user