Cyber

First complete Lab, then Project

wget (short for "web-get")

Tree Command (Alternative to ls)

sudo apt-get install tree
tree <folder>
#############
#  OUTPUT:  #
#############

/home
└── folder
    ├── unit2
    ├── unit3
    │   ├── cp_leak.txt
    │   └── crackfiles.zip
    └── unit6
        ├── attrib.txt
        ├── cat.jpg
        ├── dog.jpg

PRE-REQ

Project Part: SSH Keys

ssh-keygen -t rsa -b 4096 -C "CYB Ubuntu Key"
  • 4096-bit SSH RSA public and private keys.

  • Commands breakdown:

    • ssh-keygen = the utility used to generate the key pair

    • -t rsa = specifies the type of key to create (e.g., rsa)

    • -C "CYB Ubuntu Key" = provides custom key comment (which will be appended at the end of the public key).

      • Usually an email address is used as a comment, but this time we're labeling it with the machine we'll use it on.

      • Think of it like a label for your key, so you don't mix it up with other keys!

Enter file in which to save the key 
(/home/codepath/.ssh/id_rsa): 
/home/codepath/.ssh/id_rsa_cyb

## No Passphrase
  • Public key is .pub

  • Private key is no extension or .pem

View keys

cat ~/.ssh/id_rsa_cyb101 
#### OUTPUT ####
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn

cat ~/.ssh/id_rsa_cyb101.pub      
#### OUTPUT ####
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5OSa7cKQQg4rWohWVYobfVUhilcojgydrxTOtzRDrYm/W+K1QrndFjxL6CH9JTFPapqkZDk92lDXvrn+qQKNaBkzNDjTyTKJp2cLd5eGIax2CWdSqgZhtjo+kAeB2wnEPU6C2rPqw5EVveATYoPfUBVTtfZt2PsxZGAVp
#### OUTPUT ####
QbFREW0tL05V8T2YHBtvoCeoSlQ1NjMLWvKQ== CYB101 Ubuntu Key

3 main uses of keys: authentication, encryption integrity

Using ssh to connect to remote server

## Example:
ssh -p XXXX -i ~/.ssh/id_rsa_cyb101 codepath@lab-xxxxx.eastus.cloudapp.azure.com

Stuck on this part (might not need):

ssh-copy-id codepath@localhost
  • Their user@domanin: codepath@lab000001

Part 3: Encryption with SSH Keys

Assymetric encryption: - Public key: encrypt - Private key: decrypt

openssl genrsa -out ~/.ssh/privatekey.pem 2048

- creates private.pem file (longer file)

openssl rsa -in  ~/.ssh/privatekey.pem -out ~/.ssh/publickey.pem -pubout -outform PEM

- creates publickey.pem file (shorter file)

echo "MY SECRET MESSAGE" > secret.txt
cat secret.txt

- creates file & display, this is final step to setup

openssl pkeyutl -encrypt -pubin -inkey ~/.ssh/publickey.pem -in secret.txt -out secret.txt.encrypted 

- this encrypts our secret msg with public

cat secret.txt.encrypted

- to view file

openssl pkeyutl -decrypt -inkey  ~/.ssh/privatekey.pem -in secret.txt.encrypted  -out secret.txt.decrypted 

- generate decrypted file

cat secret.txt.decrypted

Last updated