From fb2789d9e456dfc6e0cb1841772e83d01d4b3eac Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sat, 14 Jan 2023 15:10:42 +0100 Subject: [PATCH 1/3] Add mkdocs --- 01-setup.md => docs/01-setup.md | 2 +- .../02-brute-force-ssh.md | 10 ++++---- .../03-add-simple-http-server.md | 18 +++++++------- .../04-add-real-webserver.md | 24 +++++++++---------- apt.md => docs/apt.md | 0 docs/index.md | 3 +++ mkdocs.yml | 3 +++ 7 files changed, 32 insertions(+), 28 deletions(-) rename 01-setup.md => docs/01-setup.md (98%) rename 02-brute-force-ssh.md => docs/02-brute-force-ssh.md (98%) rename 03-add-simple-http-server.md => docs/03-add-simple-http-server.md (90%) rename 04-add-real-webserver.md => docs/04-add-real-webserver.md (93%) rename apt.md => docs/apt.md (100%) create mode 100644 docs/index.md create mode 100644 mkdocs.yml diff --git a/01-setup.md b/docs/01-setup.md similarity index 98% rename from 01-setup.md rename to docs/01-setup.md index 73f6bd1..ff91bc7 100644 --- a/01-setup.md +++ b/docs/01-setup.md @@ -1,4 +1,4 @@ -# Raspberry Pi Training - Setup and Login via SSH +# 01 - Setup and Login via SSH ## Set Up Raspberry Pi diff --git a/02-brute-force-ssh.md b/docs/02-brute-force-ssh.md similarity index 98% rename from 02-brute-force-ssh.md rename to docs/02-brute-force-ssh.md index 7c74cce..0e53cb9 100644 --- a/02-brute-force-ssh.md +++ b/docs/02-brute-force-ssh.md @@ -1,4 +1,4 @@ -# Brute Force Attack Raspberry Pi +# 02 - Brute Force Attack ## Ideas @@ -125,18 +125,18 @@ Why is the math behind this important? Function to calculate the possible password combinations: -```` +``` ^ -```` +``` Further reading: https://www.scientificamerican.com/article/the-mathematics-of-hacking-passwords/ # Lessons Learned - + - Brute force attacks do not scale if the password and the used alphabet have a sufficient size - Trying all username/password combinations will make the problem harder to solve -> this is why not exposing the information if a username is known is a good thing - Don't try stupid things before doing the math - + # Harden Raspberry Pi ## Firewall diff --git a/03-add-simple-http-server.md b/docs/03-add-simple-http-server.md similarity index 90% rename from 03-add-simple-http-server.md rename to docs/03-add-simple-http-server.md index b5e628f..e11263f 100644 --- a/03-add-simple-http-server.md +++ b/docs/03-add-simple-http-server.md @@ -1,4 +1,4 @@ -# Simple HTTP Server +# 03 - Simple HTTP Server Start a simple webserver on the Raspberry Pi: @@ -8,9 +8,9 @@ python3 -m http.server Type the IP address with the Port 8000 into your browser: -````` +``` 192.168.0.1:8000 -````` +``` You should see the file system of the Raspberry Pi in your webbrowser. @@ -18,20 +18,20 @@ You should see the file system of the Raspberry Pi in your webbrowser. Create a folder you want to serve: -```` +``` mkdir /srv/www/ -```` +``` Create an HTML file "index.html" with the following content within the "srv" directory: -```` +```

Hello World

-```` +``` Safe the file and start the Python webserver in that directory: -```` +``` python3 -m http.server -```` +``` Go to your browser and you will see a "Hello World" web page. diff --git a/04-add-real-webserver.md b/docs/04-add-real-webserver.md similarity index 93% rename from 04-add-real-webserver.md rename to docs/04-add-real-webserver.md index d8c3102..bf7749e 100644 --- a/04-add-real-webserver.md +++ b/docs/04-add-real-webserver.md @@ -1,10 +1,10 @@ -# Install a real webserver (Nginx) +# 04 - Real Webserver (Nginx) Install Nginx: -```` +``` sudo apt install nginx -```` +``` # Check hello world page @@ -36,7 +36,6 @@ service nginx start Add a new config file "hello-world" to /etc/nginx/sites-available with the following content: - ``` server { listen 80; @@ -55,33 +54,32 @@ server { Enable the config in Nginx by creating a symlink to /etc/nginx/sites-enabled: -```` +``` sudo su cd /etc/nginx/sites-enabled ln -s ../sites-available . -````` +``` Reload Nginx Configuration: -```` +``` service nginx reload -```` +``` Check output and make sure there are no error traces. If there is a problem check the Nginx error log with: -```` +``` tail -f /var/log/nginx/error.log -```` +``` Now we have to edit the hosts configuration file on our local machine (not the Raspberry Pi!). Add the following line to your /etc/hosts file: -```` +``` 192.168.178.160 helloworld.de -```` +``` Type "helloworld.de" into your browser window. You should see your hello world HTML page content. - diff --git a/apt.md b/docs/apt.md similarity index 100% rename from apt.md rename to docs/apt.md diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..bac741d --- /dev/null +++ b/docs/index.md @@ -0,0 +1,3 @@ +# Start + +Learn the basics of Operation Systems and Networks with the Raspberry Pi. diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..b239bfe --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,3 @@ +site_name: Raspberry Pi Training +theme: + name: material From 04a0c88d2d137b4ba3b8207fd671286a4e94375e Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sun, 15 Jan 2023 11:30:57 +0100 Subject: [PATCH 2/3] Add hd.md --- .gitignore | 3 + docs/hd.md | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 .gitignore create mode 100644 docs/hd.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..681a17b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin/ +lib/ +pyvenv.cfg diff --git a/docs/hd.md b/docs/hd.md new file mode 100644 index 0000000..8403d91 --- /dev/null +++ b/docs/hd.md @@ -0,0 +1,172 @@ +# Hard Disk + +## Connect + +Connect a hard disk to the Raspberry Pi via an SATA to USB adapter. + +Check if HD has been detected with "df": + +``` +$ df -h +Dateisystem Größe Benutzt Verf. Verw% Eingehängt auf +/dev/root 15G 5,9G 7,8G 43% / +devtmpfs 776M 0 776M 0% /dev +tmpfs 937M 0 937M 0% /dev/shm +tmpfs 375M 1,2M 374M 1% /run +tmpfs 5,0M 4,0K 5,0M 1% /run/lock +/dev/mmcblk0p1 255M 51M 205M 20% /boot +tmpfs 188M 24K 188M 1% /run/user/1000 +/dev/sda2 112G 18G 95G 16% /media/leo/886 +``` + +## Check HD + +Install smartmontools: + +``` +sudo apt install smartmontools +``` + +Check smart status of HD: + +``` +sudo smartctl --all /dev/sda2 +smartctl 7.2 2020-12-30 r5155 [armv7l-linux-5.15.76-v7l+] (local build) +Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org + +=== START OF INFORMATION SECTION === +Vendor: Hitachi +Product: HTS542512K9SA00 +Revision: BB2A +User Capacity: 120.034.122.240 bytes [120 GB] +Logical block size: 512 bytes +scsiModePageOffset: response length too short, resp_len=4 offset=4 bd_len=0 +scsiModePageOffset: response length too short, resp_len=4 offset=4 bd_len=0 +>> Terminate command early due to bad response to IEC mode page +A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options. +``` + +Run Test: + +``` +$ sudo smartctl --test=long /dev/sda2 +smartctl 7.2 2020-12-30 r5155 [armv7l-linux-5.15.76-v7l+] (local build) +Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org + +Long (extended) offline self test failed [unsupported field in scsi command] +``` + +Check smart status for external HD via USB: + +``` +sudo smartctl -A -d sat /dev/sda +smartctl 7.2 2020-12-30 r5155 [armv7l-linux-5.15.76-v7l+] (local build) +Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org + +=== START OF READ SMART DATA SECTION === +SMART Attributes Data Structure revision number: 16 +Vendor Specific SMART Attributes with Thresholds: +ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE + 1 Raw_Read_Error_Rate 0x000b 100 100 062 Pre-fail Always - 0 + 2 Throughput_Performance 0x0005 100 100 040 Pre-fail Offline - 0 + 3 Spin_Up_Time 0x0007 253 253 033 Pre-fail Always - 1 + 4 Start_Stop_Count 0x0012 063 063 000 Old_age Always - 58487 + 5 Reallocated_Sector_Ct 0x0033 100 100 005 Pre-fail Always - 0 + 7 Seek_Error_Rate 0x000b 100 100 067 Pre-fail Always - 0 + 8 Seek_Time_Performance 0x0005 100 100 040 Pre-fail Offline - 0 + 9 Power_On_Hours 0x0012 075 075 000 Old_age Always - 11207 + 10 Spin_Retry_Count 0x0013 100 100 060 Pre-fail Always - 0 + 12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 289 +191 G-Sense_Error_Rate 0x000a 100 100 000 Old_age Always - 0 +192 Power-Off_Retract_Count 0x0032 100 100 000 Old_age Always - 58 +193 Load_Cycle_Count 0x0012 071 071 000 Old_age Always - 292283 +194 Temperature_Celsius 0x0002 229 229 000 Old_age Always - 24 (Min/Max 18/53) +195 Hardware_ECC_Recovered 0x000a 100 100 000 Old_age Always - 0 +196 Reallocated_Event_Count 0x0032 100 100 000 Old_age Always - 0 +197 Current_Pending_Sector 0x0022 100 100 000 Old_age Always - 0 +198 Offline_Uncorrectable 0x0008 100 100 000 Old_age Offline - 0 +199 UDMA_CRC_Error_Count 0x000a 200 200 000 Old_age Always - 0 +223 Load_Retry_Count 0x000a 100 100 000 Old_age Always - 0 +``` + +Run test on USB hd: + +``` +sudo smartctl -A -d sat --test=long /dev/sda +smartctl 7.2 2020-12-30 r5155 [armv7l-linux-5.15.76-v7l+] (local build) +Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org + +=== START OF READ SMART DATA SECTION === +SMART Attributes Data Structure revision number: 16 +Vendor Specific SMART Attributes with Thresholds: +ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE + 1 Raw_Read_Error_Rate 0x000b 100 100 062 Pre-fail Always - 0 + 2 Throughput_Performance 0x0005 100 100 040 Pre-fail Offline - 0 + 3 Spin_Up_Time 0x0007 253 253 033 Pre-fail Always - 1 + 4 Start_Stop_Count 0x0012 063 063 000 Old_age Always - 58488 + 5 Reallocated_Sector_Ct 0x0033 100 100 005 Pre-fail Always - 0 + 7 Seek_Error_Rate 0x000b 100 100 067 Pre-fail Always - 0 + 8 Seek_Time_Performance 0x0005 100 100 040 Pre-fail Offline - 0 + 9 Power_On_Hours 0x0012 075 075 000 Old_age Always - 11208 + 10 Spin_Retry_Count 0x0013 100 100 060 Pre-fail Always - 0 + 12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 289 +191 G-Sense_Error_Rate 0x000a 100 100 000 Old_age Always - 0 +192 Power-Off_Retract_Count 0x0032 100 100 000 Old_age Always - 58 +193 Load_Cycle_Count 0x0012 071 071 000 Old_age Always - 292285 +194 Temperature_Celsius 0x0002 229 229 000 Old_age Always - 24 (Min/Max 18/53) +195 Hardware_ECC_Recovered 0x000a 100 100 000 Old_age Always - 0 +196 Reallocated_Event_Count 0x0032 100 100 000 Old_age Always - 0 +197 Current_Pending_Sector 0x0022 100 100 000 Old_age Always - 0 +198 Offline_Uncorrectable 0x0008 100 100 000 Old_age Offline - 0 +199 UDMA_CRC_Error_Count 0x000a 200 200 000 Old_age Always - 0 +223 Load_Retry_Count 0x000a 100 100 000 Old_age Always - 0 + +=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION === +Sending command: "Execute SMART Extended self-test routine immediately in off-line mode". +Drive command "Execute SMART Extended self-test routine immediately in off-line mode" successful. +Testing has begun. +Please wait 56 minutes for test to complete. +Test will complete after Sun Jan 15 10:29:39 2023 GMT +Use smartctl -X to abort test. +``` + +Check status again after test has ended: + +``` +$ sudo smartctl -A -d sat /dev/sda +smartctl 7.2 2020-12-30 r5155 [armv7l-linux-5.15.76-v7l+] (local build) +Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org + +=== START OF READ SMART DATA SECTION === +SMART Attributes Data Structure revision number: 16 +Vendor Specific SMART Attributes with Thresholds: +ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE + 1 Raw_Read_Error_Rate 0x000b 100 100 062 Pre-fail Always - 0 + 2 Throughput_Performance 0x0005 100 100 040 Pre-fail Offline - 0 + 3 Spin_Up_Time 0x0007 253 253 033 Pre-fail Always - 1 + 4 Start_Stop_Count 0x0012 063 063 000 Old_age Always - 58491 + 5 Reallocated_Sector_Ct 0x0033 100 100 005 Pre-fail Always - 0 + 7 Seek_Error_Rate 0x000b 100 100 067 Pre-fail Always - 0 + 8 Seek_Time_Performance 0x0005 100 100 040 Pre-fail Offline - 0 + 9 Power_On_Hours 0x0012 075 075 000 Old_age Always - 11208 + 10 Spin_Retry_Count 0x0013 100 100 060 Pre-fail Always - 0 + 12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 289 +191 G-Sense_Error_Rate 0x000a 100 100 000 Old_age Always - 0 +192 Power-Off_Retract_Count 0x0032 100 100 000 Old_age Always - 58 +193 Load_Cycle_Count 0x0012 071 071 000 Old_age Always - 292290 +194 Temperature_Celsius 0x0002 220 220 000 Old_age Always - 25 (Min/Max 18/53) +195 Hardware_ECC_Recovered 0x000a 100 100 000 Old_age Always - 0 +196 Reallocated_Event_Count 0x0032 100 100 000 Old_age Always - 0 +197 Current_Pending_Sector 0x0022 100 100 000 Old_age Always - 0 +198 Offline_Uncorrectable 0x0008 100 100 000 Old_age Offline - 0 +199 UDMA_CRC_Error_Count 0x000a 200 200 000 Old_age Always - 0 +223 Load_Retry_Count 0x000a 100 100 000 Old_age Always - 0 +``` + +## Format HD + +todo? + +## Mount HD + +todo? From f01fa86ea80e0412fcbc396c1abd9f31be44c351 Mon Sep 17 00:00:00 2001 From: jackahl Date: Fri, 20 Jan 2023 12:21:10 +0100 Subject: [PATCH 3/3] initial python setup files --- Makefile | 18 ++++++++++++++++++ requirements.txt | 26 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Makefile create mode 100644 requirements.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e515436 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +api/bin/pip: + @echo "$(GREEN)==> Setup Virtual Env$(RESET)" + python3 -m venv . + +.PHONY: start +start: + @echo "start mkdocs server" + bin/mkdocs serve + +.PHONY: install +install: api/bin/pip + @echo "setting up mkdocs server" + bin/pip install -r requirements.txt + +.PHONY: clean +clean: + @echo "removing py build" + rm -rf bin lib pyvenv.cfg diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..35430e0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,26 @@ +certifi==2022.12.7 +charset-normalizer==3.0.1 +click==8.1.3 +colorama==0.4.6 +ghp-import==2.1.0 +idna==3.4 +importlib-metadata==6.0.0 +Jinja2==3.1.2 +Markdown==3.3.7 +MarkupSafe==2.1.2 +mergedeep==1.3.4 +mkdocs==1.4.2 +mkdocs-material==9.0.6 +mkdocs-material-extensions==1.1.1 +packaging==23.0 +Pygments==2.14.0 +pymdown-extensions==9.9.1 +python-dateutil==2.8.2 +PyYAML==6.0 +pyyaml_env_tag==0.1 +regex==2022.10.31 +requests==2.28.2 +six==1.16.0 +urllib3==1.26.14 +watchdog==2.2.1 +zipp==3.11.0