Skip to content

Commit

Permalink
challenge release
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanwu10 committed Jul 15, 2021
0 parents commit 7cfe0df
Show file tree
Hide file tree
Showing 32 changed files with 3,568 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/build
/build
*/build
/out
/pack
.cache
39 changes: 39 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.20)
project(rp2sm_chall LANGUAGES CXX)

# GLOBAL COMPILE SETTINGS
# TODO: should be moved into a utility library somewhere probably
include(CheckPIESupported)
check_pie_supported()

include(CheckCXXCompilerFlag)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
check_cxx_compiler_flag(-fstack-protector-strong has_stack_protector_strong)
if(has_stack_protector_strong)
add_compile_options(-fstack-protector-strong)
else()
check_cxx_compiler_flag(-fstack-protector has_stack_protector)
if(has_stack_protector)
add_compile_options(-fstack-protector)
else()
message(WARNING "Stack protector could not be enabled")
endif()
endif()
# TODO: use tests
add_link_options(LINKER:--sort-common,--as-needed,-z,relro,-z,now)

# MAIN CODE

add_subdirectory(rp2sm)

add_executable(chall
chall/main.cpp
)
target_link_libraries(chall rp2sm)

# packing
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}")
include(CPack)
install(TARGETS chall rp2sm)
set_target_properties(chall PROPERTIES INSTALL_RPATH "\${ORIGIN}/../lib")
34 changes: 34 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"generator": "Ninja Multi-Config",
"binaryDir": "build",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-O3 -g -DNDEBUG",
"CMAKE_CXX_FLAGS_DEBUG": "-Og -g",
"CMAKE_BUILD_RPATH_USE_ORIGIN": "ON",
"CPACK_GENERATOR": "TGZ"
},
"environment": {
"CC": "clang",
"CXX": "clang++"
}
},
{
"name": "docker",
"inherits": "default",
"generator": "Unix Makefiles",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
]
}
661 changes: 661 additions & 0 deletions COPYING

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
DOCKER ?= docker
DOCKER-BUILD ?= $(DOCKER) buildx build
GIT ?= git
TAR ?= tar # must be GNU tar
TARFLAGS := --numeric-owner --owner=0 --group=0 --sort=name --mtime=1970-01-01T00:00Z --no-xattr $(TARFLAGS)

dist_files = $(shell $(GIT) ls-files deploy) $(shell find out -type f) run.Dockerfile
source_files = $(dist_files) flag1.txt flag2.txt solve/loader.py solve/stg1.rp2b solve/stg2.rp2b
tar_transform = --transform 's|^|rp2sm/|;s|\brun\.Dockerfile\b|Dockerfile|'

.PHONY: default
default: help

.PHONY: all
all: pack/source.tar pack/dist.tar out
@true

.PHONY: out
out:
$(DOCKER-BUILD) . -f build.Dockerfile --target extractor -o type=local,dest=out

out/%: out
@# dummy dependency resolution target
@true

pack/source.tar: $(source_files)
@mkdir -p pack
$(TAR) $(TARFLAGS) $(tar_transform) -cf $@ $^

pack/dist.tar: $(dist_files)
@mkdir -p pack
$(TAR) $(TARFLAGS) $(tar_transform) -cf $@ $^

.PHONY: help
help:
@echo "Available targets:"
@echo ""
@echo " out: compile binaries (in out/)"
@echo " pack/source.tar: create \"source\" tarball (for challenge builds)"
@echo " pack/dist.tar: create player-facing tarball"
@echo " all: all of the above"
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# rp2sm

A rev/pwn challenge for [redpwnCTF 2021](https://github.com/redpwn/redpwnctf-2021-challenges).

Some rough notes I made for myself are in [notes.md](notes.md). The assembler
I wrote is in [assembler/assembler.hs](assembler/assembler.hs), and is used for
assembling the solutions in [solve/](solve/). Reproducible builds of challenge
artifacts are done with Docker; `make out` will build the binaries, and
`make pack/dist.tar` creates the tarball of files distrbuted to competitors.

[Author writeup](https://ethanwu.dev/blog/2021/07/14/redpwn-ctf-2021-rp2sm/)
3 changes: 3 additions & 0 deletions assembler/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.hi
*.o
assembler
Loading

0 comments on commit 7cfe0df

Please sign in to comment.