Skip to content

Commit 7cfe0df

Browse files
committed
challenge release
0 parents  commit 7cfe0df

32 files changed

+3568
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/build
2+
/build
3+
*/build
4+
/out
5+
/pack
6+
.cache

CMakeLists.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
project(rp2sm_chall LANGUAGES CXX)
3+
4+
# GLOBAL COMPILE SETTINGS
5+
# TODO: should be moved into a utility library somewhere probably
6+
include(CheckPIESupported)
7+
check_pie_supported()
8+
9+
include(CheckCXXCompilerFlag)
10+
11+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
12+
check_cxx_compiler_flag(-fstack-protector-strong has_stack_protector_strong)
13+
if(has_stack_protector_strong)
14+
add_compile_options(-fstack-protector-strong)
15+
else()
16+
check_cxx_compiler_flag(-fstack-protector has_stack_protector)
17+
if(has_stack_protector)
18+
add_compile_options(-fstack-protector)
19+
else()
20+
message(WARNING "Stack protector could not be enabled")
21+
endif()
22+
endif()
23+
# TODO: use tests
24+
add_link_options(LINKER:--sort-common,--as-needed,-z,relro,-z,now)
25+
26+
# MAIN CODE
27+
28+
add_subdirectory(rp2sm)
29+
30+
add_executable(chall
31+
chall/main.cpp
32+
)
33+
target_link_libraries(chall rp2sm)
34+
35+
# packing
36+
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}")
37+
include(CPack)
38+
install(TARGETS chall rp2sm)
39+
set_target_properties(chall PROPERTIES INSTALL_RPATH "\${ORIGIN}/../lib")

CMakePresets.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"version": 2,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 20,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "default",
11+
"generator": "Ninja Multi-Config",
12+
"binaryDir": "build",
13+
"cacheVariables": {
14+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
15+
"CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-O3 -g -DNDEBUG",
16+
"CMAKE_CXX_FLAGS_DEBUG": "-Og -g",
17+
"CMAKE_BUILD_RPATH_USE_ORIGIN": "ON",
18+
"CPACK_GENERATOR": "TGZ"
19+
},
20+
"environment": {
21+
"CC": "clang",
22+
"CXX": "clang++"
23+
}
24+
},
25+
{
26+
"name": "docker",
27+
"inherits": "default",
28+
"generator": "Unix Makefiles",
29+
"cacheVariables": {
30+
"CMAKE_BUILD_TYPE": "Release"
31+
}
32+
}
33+
]
34+
}

COPYING

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
DOCKER ?= docker
2+
DOCKER-BUILD ?= $(DOCKER) buildx build
3+
GIT ?= git
4+
TAR ?= tar # must be GNU tar
5+
TARFLAGS := --numeric-owner --owner=0 --group=0 --sort=name --mtime=1970-01-01T00:00Z --no-xattr $(TARFLAGS)
6+
7+
dist_files = $(shell $(GIT) ls-files deploy) $(shell find out -type f) run.Dockerfile
8+
source_files = $(dist_files) flag1.txt flag2.txt solve/loader.py solve/stg1.rp2b solve/stg2.rp2b
9+
tar_transform = --transform 's|^|rp2sm/|;s|\brun\.Dockerfile\b|Dockerfile|'
10+
11+
.PHONY: default
12+
default: help
13+
14+
.PHONY: all
15+
all: pack/source.tar pack/dist.tar out
16+
@true
17+
18+
.PHONY: out
19+
out:
20+
$(DOCKER-BUILD) . -f build.Dockerfile --target extractor -o type=local,dest=out
21+
22+
out/%: out
23+
@# dummy dependency resolution target
24+
@true
25+
26+
pack/source.tar: $(source_files)
27+
@mkdir -p pack
28+
$(TAR) $(TARFLAGS) $(tar_transform) -cf $@ $^
29+
30+
pack/dist.tar: $(dist_files)
31+
@mkdir -p pack
32+
$(TAR) $(TARFLAGS) $(tar_transform) -cf $@ $^
33+
34+
.PHONY: help
35+
help:
36+
@echo "Available targets:"
37+
@echo ""
38+
@echo " out: compile binaries (in out/)"
39+
@echo " pack/source.tar: create \"source\" tarball (for challenge builds)"
40+
@echo " pack/dist.tar: create player-facing tarball"
41+
@echo " all: all of the above"

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# rp2sm
2+
3+
A rev/pwn challenge for [redpwnCTF 2021](https://github.com/redpwn/redpwnctf-2021-challenges).
4+
5+
Some rough notes I made for myself are in [notes.md](notes.md). The assembler
6+
I wrote is in [assembler/assembler.hs](assembler/assembler.hs), and is used for
7+
assembling the solutions in [solve/](solve/). Reproducible builds of challenge
8+
artifacts are done with Docker; `make out` will build the binaries, and
9+
`make pack/dist.tar` creates the tarball of files distrbuted to competitors.
10+
11+
[Author writeup](https://ethanwu.dev/blog/2021/07/14/redpwn-ctf-2021-rp2sm/)

assembler/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.hi
2+
*.o
3+
assembler

0 commit comments

Comments
 (0)