forked from open-education-hub/operating-systems
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chapters/data: Add checkers for
memory-security
tasks
Done solving the issue 134 : chapters/data/memory-security/drills/tasks: Add solutions and checkers #134 Added the generate_skels.py infrastructure to generate the skeletons from the solutions Added checkers for the tasks which needed one Updated the README.md for every task with useful information on how to generate the skels and run the checker Added solution Updated generate_skels.py to add support for a task that requires uncommenting lines in the Makefile. Resolves #134 Signed-off-by: Vica Teodor Andrei <[email protected]>
- Loading branch information
Showing
63 changed files
with
372 additions
and
862 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
chapters/data/memory-security/drills/tasks/aslr/solution/Makefile
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
chapters/data/memory-security/drills/tasks/aslr/solution/Makefile.aslr
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
chapters/data/memory-security/drills/tasks/aslr/solution/aslr.c
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
chapters/data/memory-security/drills/tasks/aslr/solution/src/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/aslr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
chapters/data/memory-security/drills/tasks/aslr/solution/tests/graded_test.inc.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
# | ||
# Print test result. Printed message should fit in 72 characters. | ||
# | ||
# Print format is: | ||
# | ||
# description ...................... passed ... NNN | ||
# description ...................... failed ... NNN | ||
# 32 chars 24 chars 6 3 3 | ||
# | ||
|
||
print_test() | ||
{ | ||
func="$1" | ||
result="$2" | ||
points="$3" | ||
|
||
if test "$points" -gt 999; then | ||
points=999 | ||
fi | ||
|
||
printf "%-32s " "${func:0:31}" | ||
printf "........................" | ||
if test "$result" -eq 0; then | ||
printf " passed ... %3d\n" "$points" | ||
else | ||
printf " failed ... 0\n" | ||
fi | ||
} | ||
|
||
run_test() | ||
{ | ||
func="$1" | ||
points="$2" | ||
# Run in subshell. | ||
(eval "$func") | ||
print_test "$func" "$?" "$points" | ||
} |
14 changes: 6 additions & 8 deletions
14
...-shellcode/support/tests/run_all_tests.sh → ...asks/aslr/solution/tests/run_all_tests.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
chapters/data/memory-security/drills/tasks/aslr/solution/tests/test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
source graded_test.inc.sh | ||
|
||
binary=../src/aslr | ||
|
||
if test -z "$SRC_PATH"; then | ||
SRC_PATH=./../src | ||
fi | ||
|
||
test_aslr() | ||
{ | ||
start_address=$(nm "$binary" | awk '/_start/ {print $1}' | head -n 1) | ||
start_address_decimal=$((0x$start_address)) | ||
if ((start_address_decimal < 0x400000)); then | ||
exit 1 | ||
fi | ||
exit 0 | ||
} | ||
|
||
run_test test_aslr 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 19 additions & 1 deletion
20
chapters/data/memory-security/drills/tasks/bypassing-stack-protector/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
# Bypassing the Stack Protector | ||
|
||
Navigate to `chapters/data/memory-security/drills/tasks/bypassing-stack-protector` and run `make skels` to generate the `support/` folder. | ||
Then navigate to `support/src`. | ||
|
||
|
||
Inspect the `chapters/data/memory-security/drills/tasks/bypassing-stack-protector/support/stack_protector.c` source file. | ||
Compile the program and examine the object code. | ||
Try to identify the canary value. | ||
Using the `addr` variable, write 2 `scanf` instructions: one that overwrites the canary with the correct value and one that overwrites the return address with the address of function `pawned`. | ||
Using the `addr` variable, write 2 instructions: one that indexes `addr` to overwrite the canary with the correct value and one that indexes `addr` to overwrite the return address with the address of function `pawned()`. | ||
In case of a successful exploit a video will be offered as reward. | ||
|
||
If you're having difficulties solving this exercise, go through [this](../../../reading/memory-security.md) reading material. | ||
|
||
## Checker | ||
|
||
To run the checker, go into the `tests` directory located in `src`, then type `make check`. | ||
A successful output of the checker should look like this : | ||
|
||
```console | ||
student@os:~/.../drills/tasks/aslr/support/src/tests make check | ||
test_bypassing-stackprotector ........................ passed ... 100 | ||
|
||
======================================================================== | ||
|
||
Total: 100/100 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
chapters/data/memory-security/drills/tasks/bypassing-stack-protector/solution/src/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/stack_protector |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
chapters/data/memory-security/drills/tasks/bypassing-stack-protector/solution/tests/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
SRC_PATH ?= ../src | ||
FULL_SRC_PATH = $(realpath $(SRC_PATH)) | ||
CPPFLAGS = -I. -I$(realpath $(SRC_PATH)) -I../utils | ||
CFLAGS = -Wall -Wextra | ||
# Remove the line below to disable debugging support. | ||
CFLAGS += -g -O0 | ||
|
||
SRCS = $(wildcard *.asm) | ||
SHELLCODES = $(patsubst %.asm,%,$(SRCS)) | ||
|
||
.PHONY: all src check lint clean | ||
|
||
all: $(SHELLCODES) src | ||
|
||
$(SHELLCODES): %:%.asm | src | ||
nasm -o $@ $< | ||
|
||
src: | ||
make -C $(FULL_SRC_PATH) | ||
|
||
check: $(SHELLCODES) | ||
make -C $(FULL_SRC_PATH) clean | ||
make clean | ||
make -i SRC_PATH=$(FULL_SRC_PATH) | ||
sudo bash ./run_all_tests.sh | ||
|
||
lint: | ||
-cd .. && checkpatch.pl -f src/*.c | ||
-cd .. && checkpatch.pl -f tests/*.sh | ||
-cd .. && cpplint --recursive src/ | ||
-cd .. && shellcheck tests/*.sh | ||
|
||
clean: | ||
-rm -f *~ |
Oops, something went wrong.