CRITICAL ENGINEERING
SUMMER INTENSIVES, BERLIN 2017 FOUNDATIONS
COMMAND LINE BOOTSTRAP
WITH JULIAN OLIVER AND DANJA VASILIEV
Live Notes by: Hen of StratoFyzika
Introduction:
The Linux system is ubiquitous.
used in planes, trains, automobile and now with the use Smart line devices
Interacting with servers (machines with no screen interface) requires the use of the command line
ex. Raspberry Pi
This is a fast crash course in basic command line:
Terminal
inside is the shell
user is the name you log in as @ signifies the user is working on a particular machine
: separates between the files system part, ~ is a shortcut from your home directory /home/user
First Command (present working directory)
pwd
tells us where we are
ls (list)
it is like a light that you turn on in a room
ls De (plus tab, creates a shortcut to reach) ls Desktop/
cd Desktop/
~Desktop$ pwd
touch list.txt
touch creates a file, and updates the date on the file
creates an empty file on the desktop
touch list.jpg
content is the data
cat list.txt
reflects what is in the .txt
echo “lalala” > list.txt
redirecting the text into the file
spaces are very important in the shell
echo “glah blah blah” >>list.txt
the use of two arrows tells it to not overwrite the whole file
use the arrow keys to scroll through your history
mkdir archived
creates a file called archived
mv list.txt archived/
moves the file list.txt to that folder
cp list.txt archived/list2_backup.txt
clear
shortcut is ctrl + l
(histroy is saved but refreshed the terminal screen)
- r
stands for recursive (the nesting of one thing inside another)
rm
to remove files
rm -r archived
because it is a folder, you must include recursion
mkdir -p 1/2/3/4/5/6/7/8
creates folders within folders
ctrl a(beginning of the line), ctrl e (end)
cd -
takes you back between folders
cd …/
Full Path would be written
cd /home/user/Desktop?1/2/3
cd
takes you home
`/Desktop/1/2/3
tilda is a shortcut for cd
Variables
a=371.56
echo $a
echo$HOME
Linux File System:
Full path gets defined by the use of a slash at the beginning, which represents the root directory of any unix like file system (like the trunk of tree)
/
If you type ls /
You get the directory:
Bin
Boot
Dev
Ect
Home
Lib
Media
Met
proc
ls /bin/
insert file directory photo here
green files are programs
locate list.txt
goes through the files system and finds where it is
sudo updatedb
superuser
enter password
locate *.txt
locates all .txt files
find
for a specific name in a particular directorz
find requires a .
find . ~name list.txt
find . ~name *.jpg
Find /usr /share/ ~name *.wav
File
Command will tell you what kind of file it is
File /usr/share/sounds/alsa/Noise.wav
**You can use this command to check information about a file
ex.
Cp /bin/ls ~desktop/letter .txt
You can use File ~/desktop/letter.txt to check the contents of this file which is in fact a binary file
If you check it using File and it reflects the contents of your directory, then there are files being uploaded from your computer.
What is useful about this is that you can see what is really there rather than taking ones word for it
Linux environment can Cache value to look at the Footprint of a file
Sha
Is the command
Sha256sum
You can scan the system for the id number which is unique to that file.
Can be checked to see if someone has modified a file like a .jpg, for instance
Ls - l
figlet “you have been owned!”
figlet “you have been owned!” > ls
Nano ls
Ls -la
Replaced the system binder with a script
And put it on the list
Cheatsheet, downloads, cheatsheet pdf
GNU all the tools onto of the linux kernel
Zip ~r archived_backup.zip archived_backup
working with text
to check the number of characters, lines, words
-c
-l
-w
changing instances of words from one to another
there is one to check it
and there is one to overwrite it
sed 's/more/messy/' rand.txt > messy.txt
cat messy.txt
join big chunks of data together
cat 0.txt >>rand.txt
>>
is adding to a file instead of overwriting it
NANO
nano newfile.txt
at the bottom of this page there are many shortcuts
ex. Write out
ctrl + x to exit
nano newfile.txt
nano anotherfile.txt
nano anotherfile.txt
Learn VIM
Date and Time
cal
cal june 2018
date
More Commands
ubuntu/debian
repository is like an app store
commad line interfaces:
ubuntu mirrors, represented by a separate package
APT
apt-get
receive and install software
sudo apt-get update
sudo apt-cache search links
sudo apt-cache search console | grep -i music
text based software such as lynx links
sudo apt-get install lynx links
install
Links
can look at the barebones of a website
can download an image
Lynx
you can also run a website directly in the command line
press g in the program and search directly for the url
also good for viewing html files
open and esc to get to the other menu
enter a website
mk dir web-dumps
cd web-dumps/
ls
wget - - help
help page opens
WGET
wget -r https://weise7.org
w
download the whole site page by page
will be a mirror on your local file system
man wget
help page
fetch remote pages/files
retrieve a url directly to your own machine
Linux is what the internet was built on
- amazing networking stack
- stable
Whois
who is behind spiegel.de
whois spiegel.de
looks up the contact info
ip address
host spiegel.de
geoiplookup (enter ip address)
host spektrumberlin.de
Ping
ping pong with a data packet to a remote server
ex. google"s zms server 8. 8. 8. 8
ctrl + c will end the ping
Remember the terminal hosts the shell
what about when interacting with a remote machine
on virtual machine, run:
sudo apt-get install arp-scan
sudo apt-get install net-tools
change the from NAT to bridged adapter, randomize the mac address
rerun
ifconfig
ex ip: 192.168.12.139
invoke a remote shell on another machine
SSH
sudo apt-get install openssh-server
now when i run ifconfig
you can see you are now on that ip
ssh is used by govt, banks, encrpted
pass ssh a command (shell users), execute a command and log out again
ssh user @192.168.12.137 "ls -l Pictures
“ls-l Desktop”
You can leave a msg on your desktop if you know the ip and the password and the correct user
Copy Forward
cd Desktop
ls
mv image…jpg
scp some.jpg
some copy user@ip address:.
. represents home directory
:Desktop/
would be the desktop
Tunnel
Reverse Copy
scp user@ip address:Desktop/lala.txt .
(reverse the syntax)
mkdir hens - desktop
scp -r user@ipaddress:Desktop/* Hens-Desktop/
Can you see the differences between Copy fwd and Reverse copy?!
stealthy technique: create a space so that it would never be kept in the history " ls Desktop"
Remote Device Command
ssh into the device, pi
ssh pi@192.168.12.13
asks for password
now displays pi@raspberrypi ~ $
ls /dev/
printf (something similar to echo)
printf "\x7C\x00 Message from the net" > /dev/tty50
tells the screen to clear out and then you can print your message
exit
from pi
NCAT
nc 192.168.12.13. 3333
ctrl + c to exit
Shell Scripting
combination of comands
commands logically following each other
mkdir foo; cd foo
semicolon expreses, after doing that first step, do the second step
while true; do date; sleep 1; done
this is a very simple program which requires ctrl + c to exit
nano current-time.sh
sh indicates shellscript
#! /bin/bash
bash is born again shell, default on osx
while true;
do
date
sleep 1
done
chmod +x current-time.sh
add executability to this file, so it can be run as a program
-x
is to disable a program
./
means execute this file here
./current-time.sh
the space between the do and the dont, any commands can be run.
if [ -f letter.txt ] ; then
else
mail -s “letter.txt was removed!” ^email@address