Skip to content

Commit 5a4163c

Browse files
committed
feat: lab5
1 parent e64221a commit 5a4163c

File tree

9 files changed

+212
-1
lines changed

9 files changed

+212
-1
lines changed

.github/workflows/lab-autograding.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ jobs:
4545
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number });
4646
const changedFiles = files.data.map((file) => file.filename);
4747
const allowedFileRegex = /^lab\d+\/main_test.js$/;
48-
if (!changedFiles.every((file) => allowedFileRegex.test(file))) {
48+
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c"];
49+
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file))) {
4950
core.setFailed('The PR contains changes to files other than the allowed files.');
5051
}
5152
return labNumber;

lab5/Answer.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Answer
2+
3+
Name:
4+
ID:
5+
6+
## Test Valgrind and ASan
7+
### Result
8+
| | Valgrind | Asan |
9+
| -------------------- | -------- | ---- |
10+
| Heap out-of-bounds | | |
11+
| Stack out-of-bounds | | |
12+
| Global out-of-bounds | | |
13+
| Use-after-free | | |
14+
| Use-after-return | | |
15+
16+
### Heap out-of-bounds
17+
#### Source code
18+
```
19+
20+
```
21+
#### Valgrind Report
22+
```
23+
24+
```
25+
### ASan Report
26+
```
27+
28+
```
29+
30+
### Stack out-of-bounds
31+
#### Source code
32+
```
33+
34+
```
35+
#### Valgrind Report
36+
```
37+
38+
```
39+
### ASan Report
40+
```
41+
42+
```
43+
44+
### Global out-of-bounds
45+
#### Source code
46+
```
47+
48+
```
49+
#### Valgrind Report
50+
```
51+
52+
```
53+
### ASan Report
54+
```
55+
56+
```
57+
58+
### Use-after-free
59+
#### Source code
60+
```
61+
62+
```
63+
#### Valgrind Report
64+
```
65+
66+
```
67+
### ASan Report
68+
```
69+
70+
```
71+
72+
### Use-after-return
73+
#### Source code
74+
```
75+
76+
```
77+
#### Valgrind Report
78+
```
79+
80+
```
81+
### ASan Report
82+
```
83+
84+
```
85+
86+
## ASan Out-of-bound Write bypass Redzone
87+
### Source code
88+
```
89+
90+
```
91+
### Why
92+

lab5/Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: all
2+
all: uaf_asan
3+
4+
uaf_asan: uaf.c libantiasan.so
5+
gcc -fsanitize=address -Og -g -o $@ $< -lantiasan -L.
6+
7+
libantiasan.so: antiasan.c
8+
gcc -g -fPIC -c antiasan.c
9+
gcc -shared antiasan.o -o libantiasan.so
10+
11+
.PHINY: run
12+
run:
13+
LD_LIBRARY_PATH=. ./uaf_asan
14+
15+
.PHONY: clean
16+
clean:
17+
rm uaf_asan antiasan.o libantiasan.so

lab5/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Lab4
2+
3+
## Introduction
4+
5+
In this lab, you will write tests in `main_test.js`. You can learn how to use [Puppeteer](https://pptr.dev/) to tests a web UI.
6+
7+
## Preparation (Important!!!)
8+
9+
1. Sync fork your branch (e.g., `SQLab:311XXXXXX`)
10+
2. `git checkout -b lab4` (**NOT** your student ID !!!)
11+
12+
## Requirement
13+
14+
1. (100%) Goto https://pptr.dev/, type `chipi chipi chapa chapa` into the search box, click on **1st** result in the **Docs** section, and print the title.
15+
16+
For the detailed steps and hints, please check the slide of this lab.
17+
18+
You can run `validate.sh` in your local to test if you satisfy the requirements.
19+
20+
Please note that you must not alter files other than `main_test.js`. You will get 0 points if
21+
22+
1. you modify other files to achieve requirements.
23+
2. you can't pass all CI on your PR.
24+
25+
## Submission
26+
27+
You need to open a pull request to your branch (e.g. 311XXXXXX, your student number) and contain the code that satisfies the abovementioned requirements.
28+
29+
Moreover, please submit the URL of your PR to E3. Your submission will only be accepted when you present at both places.

lab5/ans

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
LD_LIBRARY_PATH=. ./uaf_asan
2+
s[0x10] = H
3+
s[0x10] = H

lab5/antiasan.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// TODO:
2+
void antiasan(unsigned long addr)
3+
{
4+
5+
}

lab5/antiasan.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef HIJACK_H
2+
#define HIJACK_H
3+
4+
void antiasan(unsigned long);
5+
6+
#endif

lab5/uaf.c

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include "antiasan.h"
5+
6+
int main(void)
7+
{
8+
char *s = (char *)malloc(0x18);
9+
strcpy(s, "HAHAHAHAHAHAHAHAHAHAHAH");
10+
printf("s[0x10] = %c\n", s[0x10]);
11+
free(s);
12+
antiasan((unsigned long)&s[0x10]);
13+
printf("s[0x10] = %c\n", s[0x10]);
14+
return 0;
15+
}

lab5/validate.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
# Check for unwanted files
4+
for file in *; do
5+
if [[ $file != "uaf.c" && $file != "antiasan.c" && $file != "antiasan.h" && $file != "Makefile" && $file != "README.md" && $file != "Answer.md" && $file != "validate.sh" && $file != "ans" ]]; then
6+
echo "[!] Unwanted file detected: $file."
7+
exit 1
8+
fi
9+
done
10+
11+
test_path="${BASH_SOURCE[0]}"
12+
solution_path="$(realpath .)"
13+
tmp_dir=$(mktemp -d -t lab5-XXXXXXXXXX)
14+
answer=""
15+
16+
cd $tmp_dir
17+
18+
rm -rf *
19+
cp $solution_path/Makefile .
20+
cp $solution_path/*.c .
21+
cp $solution_path/*.h .
22+
cp $solution_path/ans .
23+
24+
make
25+
make run > out 2>&1
26+
result=$(diff ans out)
27+
if [[ -n $result ]]; then
28+
echo "[!] Expected: "
29+
cat ans
30+
echo ""
31+
echo "[!] Actual: "
32+
cat out
33+
echo ""
34+
exit 1
35+
else
36+
echo "[V] Pass"
37+
fi
38+
39+
rm -rf $tmp_dir
40+
41+
exit 0
42+
43+
# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2:

0 commit comments

Comments
 (0)