Skip to content

Commit

Permalink
Add get-flag and options to change exec command
Browse files Browse the repository at this point in the history
  • Loading branch information
lecafard committed Jul 12, 2024
1 parent bd544b8 commit fc596d5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions vendor/nsjail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Default options are listed below.
JAIL_CWD=/ # default working directory of jail
MOUNT_PROC=false # Whether to mount proc in the child container
PORT=1337 # Listening port
MAX_CONNS_PER_IP=16 # Maximum number of connections per IP address. 0 is unlimited.
EXEC_BIN=/chal/pwn # Program to execute
EXEC_ARG= # Arguments to supply to program
MAX_CONNS_PER_IP=16 # Maximum number of connections per IP address. 0 is unlimited.
MAX_MEMORY=67108864 # Maximum memory that processes can use.
MAX_PIDS=16 # Maximum number of processes.
TIME_LIMIT=60 # Timeout before connection is closed.
Expand All @@ -28,4 +30,4 @@ There is default configuration inside context/nsjail.cfg. Just replace the file
building your image if you need to change more than what is provided through the environment
variables.

The only environment variable that is passed into the nsjail environment is the `FLAG` ENV variable. If it is not set then it is ignored.
The only environment variable that is passed into the nsjail environment is the `FLAG` ENV variable. If it is not set then it is ignored.
4 changes: 4 additions & 0 deletions vendor/nsjail/context/chal/get-flag
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
read FLAG
export FLAG
exec $@
3 changes: 3 additions & 0 deletions vendor/nsjail/context/nsjail-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ CONFIG=`cat "$CONFIG_FILE"`
export MODE=${MODE:-LISTEN}
export MOUNT_PROC=${MOUNT_PROC:-false}
export PORT=${PORT:-1337}
export EXEC_BIN=${EXEC_BIN:-/chal/pwn}
export EXEC_ARG=${EXEC_ARG:-}
export JAIL_CWD=${JAIL_CWD:-/}
export MAX_CONNS_PER_IP=${MAX_CONNS_PER_IP:-16}
export MAX_MEMORY=${MAX_MEMORY:-67108864} # 64MB
Expand Down Expand Up @@ -40,3 +42,4 @@ if [ -f "/sys/fs/cgroup/cgroup.controllers" ]; then
fi

nsjail --config <(echo "$CONFIG" | envsubst) --env FLAG

3 changes: 2 additions & 1 deletion vendor/nsjail/context/nsjail.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ mount: [
]

exec_bin {
path: "/chal/pwn"
path: "$EXEC_BIN"
arg: "$EXEC_ARG"
}

0 comments on commit fc596d5

Please sign in to comment.