Skip to content

Commit a2f55d5

Browse files
committed
Add: lab7
1 parent 2063787 commit a2f55d5

File tree

6 files changed

+100
-1
lines changed

6 files changed

+100
-1
lines changed

.github/workflows/lab-autograding.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ 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-
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md"];
48+
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md, lab7/sol.py"];
4949
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file)))) {
5050
core.setFailed('The PR contains changes to files other than the allowed files.');
5151
}

lab7/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
login: login.o
2+
3+
login.o: login.c
4+
5+
.PHONY: clean
6+
clean:
7+
rm login login.o

lab7/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Lab7
2+
3+
## Introduction
4+
5+
In this lab, you will write a python script with Angr to find the password in executalbe file named 'login'.
6+
7+
## Preparation (Important!!!)
8+
9+
1. Sync fork your branch (e.g., `SQLab:311XXXXXX`)
10+
2. `git checkout -b lab7` (**NOT** your student ID !!!)
11+
12+
## Requirement
13+
14+
1. (100%) Detect the condition that login will print 'Login successful' if login success and print 'Login failed' if login fail, find the input of successful condition by Angr.
15+
16+
Please note that you must not alter files other than `sol.py` or just print the input. You will get 0 points if
17+
18+
1. you modify other files to achieve requirements.
19+
2. you can't pass all CI on your PR.
20+
21+
## Submission
22+
23+
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.
24+
25+
Moreover, please submit the URL of your PR to E3. Your submission will only be accepted when you present at both places.

lab7/login.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
int encrypt(int a1, int a2) {
6+
if ( a1 <= 0x40 || a1 > 90 ) {
7+
puts("Login failed");
8+
exit(1);
9+
}
10+
return (0x1F * a2 + a1 - 65) % 26 + 65;
11+
}
12+
13+
int main(void) {
14+
char secret[0x20] = "VXRRJEURXDASBFHM";
15+
char pwd[0x20] = {0};
16+
17+
printf("Enter the password: ");
18+
scanf("%16s", pwd);
19+
for ( int j = 0; j < 0x10; ++j )
20+
pwd[j] = encrypt(pwd[j], j + 8);
21+
if ( !strcmp(secret, pwd) )
22+
puts("Login successful");
23+
else
24+
puts("Login failed");
25+
return 0;
26+
}

lab7/sol.py

Whitespace-only changes.

lab7/validate.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Check for unwanted files
4+
for file in *; do
5+
if [[ $file != "login.c" && $file != "sol.py" && $file != "Makefile" && $file != "README.md" && $file != "validate.sh" ]]; 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 lab7-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/sol.py .
22+
23+
make
24+
result=$(python3 sol.py)
25+
if [[ $result != "b'HETOBRCUVWOBFEBB'" ]]; then
26+
echo "[!] Expected: "
27+
echo "b'HETOBRCUVWOBFEBB'"
28+
echo ""
29+
echo "[!] Actual: "
30+
echo $result
31+
echo ""
32+
exit 1
33+
else
34+
echo "[V] Pass"
35+
fi
36+
37+
rm -rf $tmp_dir
38+
39+
exit 0
40+
41+
# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2:

0 commit comments

Comments
 (0)