TryHackMe

TryHackMe(THM): Encryption – Crypto 101 -Writeup

年末の過ごし方ははやっぱり暗号解読だよね!(?)ってことで、TryHackMeの一番最初の暗号に関するRoomやりました。

結論から言うと、日本人はRoomやるよりIPUSIRONさんの翻訳本を読んだほうがわかりやすい気がしますのでおすすめです。

もくじ
  1. Task 1  What will this room cover?
  2. Task2 Key terms
  3. Task 3  Why is Encryption important?
  4. Task 4 Crucial Crypto Maths
  5. Task 5 Types of Encryption
  6. Task 6 RSA-Rivest Shamir Adleman
  7. Task 7 Establishing Keys Using Asymmetric Cryptography
  8. Task 8 Digital signatures and Certificates
  9. Task9 SSH Authentication
  10. Task 10 Explaining Diffie Hellman Key Exchange
  11. Task 11  PGP, GPG and AES
  12. Task 12  The Future – Quantum Computers and Encryption

Task 1  What will this room cover?

No answer needed

Task2 Key terms

No answer needed

I agree not to complain too much about how theory heavy this room is.

このroomの理論がヘビーでも文句言わないことに同意します

アッハイ。暗号難しいよね…。

Are SSH keys protected with a passphrase or a password?

2択。パスフレーズとパスワードの厳密な違いがよくわからない…

パスフレーズはキーを保護するものらしい。

Task 3  Why is Encryption important?

What does SSH stand for?

ぐぐればわかる

Secure Shell

How do webservers prove their identity?

WEBサーバを証明するのは証明書

Certificate

What is the main set of standards you need to comply with if you store or process payment card details?

カード情報のセキュリティ準拠のための基準を答える。日本でどの程度知名度があるのかは知らない。個人的にはたまに話題に上がる程度なんだけどどうなんだろう。

PCI-DSS

Task 4 Crucial Crypto Maths

モジュラー演算子(日本語だと剰余演算)やる

What’s 30 % 5?

せっかくなので(何が?)pythonで解く

What’s 25 % 7

What’s 118613842 % 9091

Task 5 Types of Encryption

Should you trust DES? Yea/Nay

信頼していい暗号化方式を知りたかったらCRYPTREC暗号リストを見たら良い

What was the result of the attempt to make DES more secure so that it could be used for longer?

上のサイトでDESで検索するとヒットする

Triple DES

Is it ok to share your public key? Yea/Nay

パブリックキーは当然パブリックでよい

Task 6 RSA-Rivest Shamir Adleman

p = 4391, q = 6659. What is n?

nはpとqの積で求められる(わざわざpython使う意味はない…)

I understand enough about RSA to move on, and I know where to look to learn more if I want to.

No answer needed

私はRSAについて十分に理解しているので、先に進む

えええ十分に理解してないよー(꒪⌓꒪)

Task 7 Establishing Keys Using Asymmetric Cryptography

I understand how keys can be established using Public Key (asymmetric) cryptography.

No answer needed

公開鍵(非対称)暗号化を使用して鍵を確立する方法を理解しています。

設問用意してほしかった。なんかだんだん投げやりになってきてませんか…(꒪⌓꒪)

Task 8 Digital signatures and Certificates

What company is TryHackMe’s certificate issued to?

TryHackMeのサーバ証明書の発行元を確認する。

chromeの場合は、アドレスバーの鍵マーク > 証明書 をクリックすると発行元が表示される

Task9 SSH Authentication

I recommend giving this a go yourself. Deploy a VM, like Learn Linux and try to add an SSH key and log in with the private key.

No answer needed

他のルームで試せって言われたの初めてだからびっくりした。合理的。

公開鍵でsshログインする

まず、言われたとおりLearn Linuxの環境をDeploy。

準備として自分の端末でキーを生成

ssh-keygen

途中でパスフレーズを聞かれるので適当に入力(してもよい、しなくてもよい)

鍵が2つできる

ここでできた公開鍵をサーバに登録していく。

# 公開鍵
~/.ssh/id_rsa.pub

# 秘密鍵
~/.ssh/id_rsa

やり方はssh-copy-idという便利なコマンドを利用する方法と、手動で登録する方法がある。

手動で登録する方法

まずLearn Linuxのサーバにsshでログインする

ssh shiba1@10.10.19.33
shiba1

フォルダとファイルがなかったのでつくる

mkdir .ssh
touch .ssh/authorized_keys

自分の端末で公開鍵を確認

cat id_rsa.pub

内容をコピーしてLearn Linuxのサーバの方でauthorized_keysに追記

# 鍵のコピー
echo "公開鍵" | cat  >> .ssh/authorized_keys

# 権限つける
chmod 700 .ssh
chmod 600 .ssh/authorized_keys

一回exitして自分が指定した公開鍵でログインできているか確認

ssh-copy-idコマンドを使う方法

ssh-copy-id shiba1@10.10.7.146

手動で登録したときと同様にログインできることを確認

ssh-copy-idのオプションメモ

-p #sshのポート指定
-n #実際に登録しないで処理結果のみ表示




Download the SSH Private Key attached to this room.

No answer needed

What algorithm does the key use?

普通に書いてある

Crack the password with John The Ripper and rockyou, what’s the passphrase for the key?

SSHの秘密鍵をパスフレーズで保護していることがありますが、ハッシュファイルを作って辞書ファイルで探索することができるよって話。

kaliに最初から入っているjohnだとエラーが出て動かなかったので、こちらからもう一度ダウンロードさせていただいた

ssh2johnでハッシュにする

python ssh2john.py idrsa.id_rsa > id_rsa.hash

rockyouリストを使ってハッシュを解析する

sudo john id_rsa.hash -wordlist=rockyou.txt

rockyouリストとは昔RockYouというサービスで情報漏えいしたパスワードのリスト。3200万アカウントあって数が多いので使われてるんだと思う。多分。

なにそれ?って人は rockyou.txt で検索すると良いです。

パスワードがわかった。(゚д゚)ウマー

Task 10 Explaining Diffie Hellman Key Exchange

I understand how Diffie Hellman Key Exchange works at a basic level

No answer needed

うう…理解できている自信がない(꒪⌓꒪)

Task 11  PGP, GPG and AES

PGP stands for Pretty Good Privacy.

PGPはPrettyGoodPrivacyの略…え。そうなの?知らなかった(꒪⌓꒪)

Time to try some GPG. Download the archive attached and extract it somewhere sensible.

No answer needed

You have the private key, and a file encrypted with the public key. Decrypt the file. What’s the secret word?

ダウンロードしてきたzipファイルを展開すると

message.pgp
tryhackme.key

の2つがでてくる

キーをインポートしたあとでgpgコマンドでファイルを復号する。
どうでもいいけど「暗号化」の対義語は「復号」らしい(復号化ではなく)

Task 12  The Future – Quantum Computers and Encryption

量子コンピュータの話、ここまで来るとちょっとトリビア的だ。

I understand that quantum computers affect the future of encryption. I know where to look if I want to learn more.

No answer needed

以上。
暗号はぶっちゃけ難しくて全然I understandじゃないところも多い (数学苦手だし…)
勉強は続けていきたい。