Skip to content

Commit

Permalink
feat: lab7
Browse files Browse the repository at this point in the history
  • Loading branch information
AlaRduTP committed May 2, 2024
1 parent 90d84fa commit 89cf768
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/lab-autograding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number });
const changedFiles = files.data.map((file) => file.filename);
const allowedFileRegex = /^lab\d+\/main_test.js$/;
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md"];
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md", "lab7/sol.py"];
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file)))) {
core.setFailed('The PR contains changes to files other than the allowed files.');
}
Expand Down
7 changes: 7 additions & 0 deletions lab7/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
login: login.o

login.o: login.c

.PHONY: clean
clean:
rm login login.o
25 changes: 25 additions & 0 deletions lab7/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Lab7

## Introduction

In this lab, you will write a python script with Angr to find the password in executalbe file named 'login'.

## Preparation (Important!!!)

1. Sync fork your branch (e.g., `SQLab:311XXXXXX`)
2. `git checkout -b lab7` (**NOT** your student ID !!!)

## Requirement

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.

Please note that you must not alter files other than `sol.py` or just print the input. You will get 0 points if

1. you modify other files to achieve requirements.
2. you can't pass all CI on your PR.

## Submission

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.

Moreover, please submit the URL of your PR to E3. Your submission will only be accepted when you present at both places.
26 changes: 26 additions & 0 deletions lab7/login.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int encrypt(int a1, int a2) {
if ( a1 <= 0x40 || a1 > 90 ) {
puts("Login failed");
exit(1);
}
return (0x1F * a2 + a1 - 65) % 26 + 65;
}

int main(void) {
char secret[0x20] = "VXRRJEURXDASBFHM";
char pwd[0x20] = {0};

printf("Enter the password: ");
scanf("%16s", pwd);
for ( int j = 0; j < 0x10; ++j )
pwd[j] = encrypt(pwd[j], j + 8);
if ( !strcmp(secret, pwd) )
puts("Login successful");
else
puts("Login failed");
return 0;
}
Empty file added lab7/sol.py
Empty file.
42 changes: 42 additions & 0 deletions lab7/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Check for unwanted files
for file in *; do
if [[ $file != "login.c" && $file != "sol.py" && $file != "Makefile" && $file != "README.md" && $file != "validate.sh" ]]; then
echo "[!] Unwanted file detected: $file."
exit 1
fi
done

test_path="${BASH_SOURCE[0]}"
solution_path="$(realpath .)"
tmp_dir=$(mktemp -d -t lab7-XXXXXXXXXX)
answer=""

cd $tmp_dir

pip install angr
rm -rf *
cp $solution_path/Makefile .
cp $solution_path/*.c .
cp $solution_path/sol.py .

make
result=$(python3 sol.py)
if [[ $result != "b'HETOBRCUVWOBFEBB'" ]]; then
echo "[!] Expected: "
echo "b'HETOBRCUVWOBFEBB'"
echo ""
echo "[!] Actual: "
echo $result
echo ""
exit 1
else
echo "[V] Pass"
fi

rm -rf $tmp_dir

exit 0

# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2:

0 comments on commit 89cf768

Please sign in to comment.