Skip to content

Commit f77eb23

Browse files
author
Sorin Birchi
committed
welcome-to-linux: Rework session according to OpenEdu methodology
Transitioned the 'welcome-to-linux' directory to meet the requirements of the OpenEdu Methodology. Signed-off-by: Sorin Birchi <sb.birchi.sorin@gmail.com>
1 parent 5d93f1b commit f77eb23

File tree

25 files changed

+216
-161
lines changed

25 files changed

+216
-161
lines changed

chapters/scratch-linux/welcome-to-linux/drills/did-you-look-everywhere/sol/solution.sh

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Did You Look Everywhere?
2+
3+
We assure you the flag is somewhere in the `/home/ctf` directory.
4+
5+
If you're having difficulties solving this exercise, go through [this](../../../reading/README.md) reading material.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/bash
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
cd south-park/al-gore/manbearpig || exit
5+
ls -a
6+
cat .flag
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# In Your Face
2+
3+
The flag is literally in your face.
4+
5+
Connect to the specified virtual machine and use `ls` to explore your surroundings:
6+
7+
```console
8+
ctf@tutorial:~$ ls
9+
flag
10+
```
11+
12+
Now just use `cat` to extract the content of the `flag` file:
13+
14+
```console
15+
ctf@tutorial:~$ cat flag
16+
<your_flag_is_here>
17+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Jumbled
2+
3+
The flag you're given in `jumbled/support/flag` does contain the actual flag, but not quite.
4+
Use your Python skills to reconstruct it.
5+
You'll also need some trial and error here.
6+
7+
If you're having difficulties solving this exercise, go through [this](../../../reading/README.md##Enter-Python) reading material.

chapters/scratch-linux/welcome-to-linux/drills/jumbled/sol/solution.py chapters/scratch-linux/welcome-to-linux/drills/tasks/jumbled/solution/solution.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
flag_file = open('../src/flag', 'rb')
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
3+
flag_file = open("../src/flag", "rb")
24
jumbled_flag = flag_file.read()
35

4-
# Ther are no hints, so we have to generate all possible flags.
6+
# There are no hints, so we have to generate all possible flags.
57
# This means all permutations of printable characters in the given flag
6-
chunks = jumbled_flag[4:-1].split(b'\x80\x80\x80')
8+
chunks = jumbled_flag[4:-1].split(b"\x80\x80\x80")
9+
710

811
def permutations(l):
912
if not l: # Check if list is empty
@@ -16,14 +19,15 @@ def permutations(l):
1619

1720
for i in range(len(l)):
1821
tmp = l[i]
19-
rest = l[:i] + l[i+1:] # All l elements except the ith.
22+
rest = l[:i] + l[i + 1 :] # All l elements except the ith.
2023

2124
# Generate all permutations that start with tmp
2225
for p in permutations(rest):
2326
new_l.append([tmp] + p)
2427

2528
return new_l
2629

30+
2731
# Now try each of them until you find the one that works.
2832
for p in permutations(chunks):
2933
print(f'SSS{{{b"".join(p).decode()}}}')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Quick Mafs
2+
3+
The flag's format is the classic `SSS{...}`, where `...` represent a string obtained by concatenating the **first 10 numbers** obtained by performing the computations below.
4+
5+
Let each number be `n[i]`, where `i` is its index.
6+
`n[0] = 1337`.
7+
This is your first number.
8+
The next numbers are defined by the formula below, where `^` signifies exponentiation.
9+
10+
```text
11+
n[i] = (n[i - 1]^3 * 67 + 31) % 2000, for all i > 0
12+
```
13+
14+
And, please, don't compute the numbers manually.
15+
You've just learned a cool new programming language that you can use!
16+
17+
If you're having difficulties solving this exercise, go through [this](../../../reading/README.md##Enter-Python) reading material.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
13
num = 1337
2-
flag = 'SSS{' + str(num)
4+
flag = "SSS{" + str(num)
35

46
for i in range(1, 10):
57
num = (num**3 * 67 + 31) % 2000
68
flag += str(num)
79

8-
print(flag + '}')
10+
print(flag + "}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# What's Running?
2+
3+
Did you know flags can **run**?
4+
If you're having difficulties solving this exercise, go through [this](../../../reading/README.md###Processes) reading material.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#! /bin/bash
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
ps -ef
5+
# Now scroll through the output until you see a process whose name starts with `SSS`.
6+
7+
# Or, if you've learnt about `|`, you can use it to ease your work:
8+
pgrep -lf SSS

chapters/scratch-linux/welcome-to-linux/drills/whats-running/sol/solution.sh

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
#!/bin/bash
12
# Use echo to display text to the terminal.
23
echo "Moving to welcome-to-linux/activities"
3-
cd ..
4+
cd .. || exit
45
ls
56

67
echo "Moving to welcome-to-linux"
7-
cd ..
8+
cd .. || exit
89
ls
910

1011
echo "Moving to back to welcome-to-linux/activities/00-demo_bash"
11-
cd activities/demo-bash
12+
cd activities/demo-bash || exit
1213
ls
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
my_dict = {
2-
"SSS": "Rullz",
3-
"Essentials": 10,
4-
True: 0.2,
5-
2.2: 99
6-
}
1+
# SPDX-License-Identifier: BSD-3-Clause
72

8-
print(my_dict['SSS']) # Will print "Rullz"
3+
my_dict = {"SSS": "Rullz", "Essentials": 10, True: 0.2, 2.2: 99}
4+
5+
print(my_dict["SSS"]) # Will print "Rullz"
96
print(my_dict[True]) # Will print 0.2
107
# And so on...
118

129
# Keys and values can be added or modified simply by referencing them.
13-
my_dict['CTF'] = 'pwned'
10+
my_dict["CTF"] = "pwned"
1411
print(f'Added key CTF with value {my_dict["CTF"]}')
1512

1613
# You can also modify values in the same way.
1714
my_dict[True] = 2.22
18-
print(f'After the modfication: my_dict[True] = {my_dict[True]}')
15+
print(f"After the modfication: my_dict[True] = {my_dict[True]}")
1916

2017
# You can check if a key is in a dictionary just like you would do for a list:
2118
print(f'Is "SSS" in my_dict? {"SSS" in my_dict}')
2219
print(f'Is "bananas" in my_dict? {"bananas" in my_dict}')
2320

2421
# Accessing the value of a non-existent key results in a KeyError.
25-
print(my_dict['bananas'])
22+
print(my_dict["bananas"])
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
fin = open('../../README.md') # Use the default mode: rt = read + text
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
3+
fin = open("../../README.md") # Use the default mode: rt = read + text
24

35
# Use the readline function to, well... read one line from the opened file.
46
line = fin.readline()
5-
print(line, end='') # The line we've just read already contains a trailing \n.
7+
print(line, end="") # The line we've just read already contains a trailing \n.
68

79
# The file object (f) maintains an internal cursor, which is an offset from the
810
# beginning of the file, where the next operation (read/write) will take place.
911
# For this reason, the next calls to readline return the correct lines in the
1012
# file.
11-
print(fin.readline(), end='') # Second line is empty
12-
print(fin.readline(), end='') # Third line
13+
print(fin.readline(), end="") # Second line is empty
14+
print(fin.readline(), end="") # Third line
1315

1416
# There are situations where it is necessary to move the cursor ourselves.
1517
# For this, we have the the seek function.
1618
# First, let's see where our cursor is now.
17-
print(f'fin cursor is initially at {fin.tell()} bytes')
19+
print(f"fin cursor is initially at {fin.tell()} bytes")
1820

1921
# The seek function takes 2 parameters:
2022
# - offset: The number of bytes to move the cursor. Can be negative to move the cursor back
@@ -23,19 +25,19 @@
2325
# - 1: from the cursor's current position
2426
# - 2: from the end of the file.
2527
fin.seek(0, 0) # Move the cursor to the beginning of the file
26-
print(f'after fin.seek(0, 0), fin cursor is at {fin.tell()} bytes')
28+
print(f"after fin.seek(0, 0), fin cursor is at {fin.tell()} bytes")
2729
# Let's try to read a line and see if it truly is the first.
28-
print('First line of README.md:', fin.readline(), end='') # It is.
30+
print("First line of README.md:", fin.readline(), end="") # It is.
2931

3032
# The other modes are available only when opening the file in binary mode.
3133
# We will do this in the next section.
3234

3335
# It's good practice to close a file when you no longer use it.
3436
fin.close()
3537

36-
fout = open('output.txt', 'w') # Open output.txt for writing text
38+
fout = open("output.txt", "w") # Open output.txt for writing text
3739
# Unlike print, write does not add a \n character at the end of our text.
38-
fout.write('This is the first line in output.txt\n')
39-
fout.write('SSS Rulz!\n')
40+
fout.write("This is the first line in output.txt\n")
41+
fout.write("SSS Rulz!\n")
4042

4143
fout.close()
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
3+
14
# The code inside the function isn't run when we run the script.
25
# It's only run when specifically called:
3-
6+
# SPDX-License-Identifier: BSD-3-Clause
47
def replicate(s, n=3):
58
"""
69
This is a docstring comment. They are used in order to document the
@@ -14,46 +17,51 @@ def replicate(s, n=3):
1417
n (int): the number of times to replicate it. 3 by default
1518
1619
Returns:
17-
String made up of s replicated n times
20+
String made up of s replicated n times
1821
"""
19-
acc = ''
22+
acc = ""
2023

2124
for _ in range(n):
2225
acc += s
2326

2427
return acc
2528

29+
2630
# Implementation using list comprehensions and the join function.
2731
# Check the links at the end of the lecture for details
2832
def replicate_fancy(s, n=3):
29-
return ''.join([s for _ in range(n)])
33+
return "".join([s for _ in range(n)])
3034

31-
my_string = 'SSS Rulz!'
35+
36+
my_string = "SSS Rulz!"
3237
my_replicated_string = replicate(my_string, 4)
33-
print(f'Initial string is unchanged: {my_string}')
34-
print(f'Returned string is: {my_replicated_string}')
38+
print(f"Initial string is unchanged: {my_string}")
39+
print(f"Returned string is: {my_replicated_string}")
3540

3641
# We can also specify any function parameter by name, like so:
3742
my_replicated_string = replicate(s=my_string, n=2)
38-
print(f'New returned string is: {my_replicated_string}')
43+
print(f"New returned string is: {my_replicated_string}")
3944

4045
# The print function can also take some default parameters, such as end:
4146
# end is the string to be placed at the end of what's printed.
4247
# By default it's \n.
4348
print(my_string, end="$$$\n") # This now prints 'SSS Rulz!'$$$
4449

50+
4551
# Similarly, range also takes 2 default parameters: start=0 and step=1.
4652
# As a result, its signature could look like this:
4753
def range(end, start=0, step=1):
4854
pass # we can use this keyword when we want to leave functions unimplemented
4955

56+
5057
# Functions can also have multiple return variables
5158
def multiple_returns(ret_type):
5259
if ret_type == 1:
53-
return 1
60+
return 1
5461
else:
55-
return 'there you go'
62+
return "there you go"
63+
5664

57-
print('\nMultiple Returns')
58-
print(f'Function returning an int: {multiple_returns(1)}')
65+
print("\nMultiple Returns")
66+
print(f"Function returning an int: {multiple_returns(1)}")
5967
print(f'Same function returning a string: "{multiple_returns(0)}"')
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
13
if False:
2-
print('This code is not executed')
4+
print("This code is not executed")
35
if True:
4-
print('This code is executed')
6+
print("This code is executed")
57

68
a = 0
79
b = 1
810

911
if a == 0:
10-
print('This is a correct if statement')
11-
b = 2
12+
print("This is a correct if statement")
13+
b = 2
1214
# The line above is not indented at the same level as the one above.
1315
# Thus, it is not contained in the body of the above if statement.
1416

1517
# Python does not have a switch instruction.
1618
# In order to create something similar to it, you'll have to use elifs:
1719
if b == 1:
18-
print('b = 1')
20+
print("b = 1")
1921
elif b == 2:
20-
print('b = 2')
22+
print("b = 2")
2123
elif b == 3:
22-
print('b == 3')
24+
print("b == 3")
2325
else:
24-
print('You get the point')
26+
print("You get the point")
2527

2628
# In order to create more complex if conditions Python does not use && and ||.
2729
# It simply uses the keywords and, or.
2830
if a == 0 and b == 2:
29-
print('This is a correct if condition: a == 0 and b == 2')
31+
print("This is a correct if condition: a == 0 and b == 2")
3032
if a == 1 or b == 2:
31-
print('This is another correct if condition: a == 1 and b == 2')
33+
print("This is another correct if condition: a == 1 and b == 2")
3234

3335
# Similarly, in order to negate an expression, we use the not keyword.
3436
if not a: # Equivalent to if (!a) in C
35-
print('a == 0, thus not a is True')
37+
print("a == 0, thus not a is True")
3638

3739
# To create even more complex boolean expressions you can use parentheses,
3840
# just like you would for arithmetic expressions.

0 commit comments

Comments
 (0)