notes on COMP343 lab activities

Table of Contents

this should not be a zettel strictly, but I included it here for reference

1. Lab1

signing up to immersive labs, and look around. immersive labs would provide lab exercises in:

  • linux command line (17 exercises)
  • security
  • penetration testing

1.1. linux command line series

1.1.1. EP.1 intro - prompt

  • [username]@[computerName]:[path][user] in user section $ indicates regular user, # indicates root

1.1.2. EP.2 command

  • ls
  • ls -a -l = ls -al chain parameters (only in commands where it is possible)

1.1.3. EP.3 directory

  • pwd print working directory
  • cd. ~, ., .. - (last directory) change direcotyr
  • cat [filename] concatenate
  • man [command] see manual

1.1.4. EP.4 change stuff

  • mv moving and rename
    • mv stuff [dir] move mv stuff this/that/ -> this/that/stuff
    • mv stuff [file] rename mv stuff this/that -> this/that, that have the same content as stuff

1.1.5. EP.5 file permissions

  • ls -al gives: drwxr-xrw 1 linux linux 4096 Jun 1 11:23
    • d - directory. - regular file
    • rwx first - owner permission; second - group; third - everyone else
  • chmod 756 file number: binary to decimal. 7 = 11 1 = rwx. 5 = 101 = r-x
  • chmod 756 -R .
  • SUID and SGID - always run as user/group. -rwS...... -...rwS...
  • sticky file, cannot be deleted -........t

1.1.6. EP.6 edit file

  • nano
  • vim, vim +25 file open file at line 25

1.1.7. EP.7 word count

wc [filename]
# line word char
# 145 3655 34567
wc -w file
wc -l file
wc -m file # charater

1.1.8. EP.8 text batch manipulation

tr original replacement < input.txt > output.txt
tr [:lower:] [:upper:] < lowercase
sed ‘s/pattern_to_find/pattern_to_replace/g’ filewitherror.txt

charactor set [:alnum:] All letters and digits (A–Z, a–z, 0–9) [:alpha:] All letters (A–Z, a–z) [:digit:] All digits (0–9) [:punct:] All punctuation characters [:chars:]

tr charactor mapping: [aeb] [AEB]

1.1.9. EP.9 streams

  • stdin - the entire command you have inputed, after the first token: “12345” in echo 12345
  • stdout some-program 1> output-and-error.txt 2>&1
  • with redirection >

    whoami
    echo 3 > file # file: 3
    echo 4 >> file # file: 34
    echo 3 1> output # print output of program echo 3 to the file output
    echo 4 2> error
    

1.1.10. EP.10 sudo

sudo -l # list all command you can do with sudo
sudo -u Alice cat file # cat file as if you are Alice
sudo -i # swticht oroot. exit to exit
su # change user to root
su bob # change user to bob

1.1.11. EP.11 ssh

ssh linux@10.10.10.10 # will prompt for password of linux
ssh linux@10.10.10.10 -i /home/linux/myprivatekey # if you have secret key and the corresponding public key is on 10.10.10.10
scp linux@10.10.10.10:/home/linux/this ./this

1.1.12. EP.12 find

find dir -name filename
find dir -name "filename*" # find partial match
find dir -perm 700 # find file with permission 700 (rwx------)
find dir -user alice # find every file owned by alice

1.1.13. EP.13 search plain text

grep word [filename] > [output-filename]. # word is a regexp: "iron*"
sort -r [filename] > [output-filename]

1.1.14. EP.14 screen

screen - multiplexing tool for command line windows

screen -ls # what screens are running
screen -r screen1 # connect to/resume screen1
screen -S screen1 # connect to a new screen, named screen1
CTRL+A CTRL+D # detach from screen
CTRL+A K # kill screen

1.1.15. EP.15 hashing

SHA-1 produces a 160-bit hash value expressed as 40 characters. An empty file called ‘example’ would result in this hash: da39a3ee5e6b4b0d3255bfef95601890afd80709 SHA-256 produces a 256-bit hash value expressed as 64 characters. The same empty file called ‘example’ would result in this hash: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 MD5 produces a 128-bit hash value expressed as 32 hexadecimal characters. The ‘example’ file would result in this hash: d41d8cd98f00b204e9800998ecf8427e

sha1sum filename
sha256sum filename
md5sum filename

1.1.16. EP.16 combining command

a && b # do b if a success
a || b # do b if a failed
a;b # do b after a anyway
a | b # use output of a as input of b
a & b # run a, send a to backgournd, run b

Backlinks

Author: Linfeng He

Created: 2024-04-03 Wed 23:22