Skip to content

Commit

Permalink
Rough draft of vulnerable server variant.
Browse files Browse the repository at this point in the history
This feeds into differential security arguments.
If the vulnerable server is trivially attackable but the
target server is not, then the mitigiations provide value.

This addresses issue #4

Still TODO: Run end-to-end tests against vulnerable server.
  • Loading branch information
mikesamuel committed Nov 5, 2018
1 parent 417c327 commit ba3fb5e
Show file tree
Hide file tree
Showing 4 changed files with 717 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -9,6 +9,8 @@
/pg
# Stores uploaded files
/static/user-uploads
# Server variant
/vulnerable/**

# Emacs droppings
*~
Expand Down
50 changes: 50 additions & 0 deletions scripts/build-vulnerable.sh
@@ -0,0 +1,50 @@
#!/bin/bash

# Builds a variant of the target server but with protective measures disabled.

set -e

force=
if [[ "$1" == "-f" ]]; then
force=1
shift
fi

if [ -z "$force" ] && [ -d vulnerable/ ] && ! git diff --quiet vulnerable/; then
echo "Changes to vulnerable/"
exit 1
fi

source_files="$(
git check-ignore -n -v --no-index \
$( find lib -type f | grep -v lib/framework;
echo package.json main.js scripts/run-locally.js static/* ) \
| perl -ne 'print "$1\n" if m/^::\t(.*)/' | sort
)"

echo Deleting old vulnerable/
rm -rf vulnerable/

echo Copying files over
for f in $source_files; do

mkdir -p vulnerable/"$(dirname "$f")"
cp -r "$f" vulnerable/"$f"
done

rm -rf vulnerable/static/user-uploads

echo Copying node_modules
cp -r node_modules/ vulnerable/node_modules/

echo Patching
pushd vulnerable/ >& /dev/null
echo "#/bin/bash" > scripts/postinstall.sh

for f in node_modules/{module-keys,node-sec-patterns,safesql,sh-template-tag,web-contract-types}; do
echo 'throw new Error(`kapow!`);' > $f/index.js
done

chmod +x scripts/postinstall.sh
patch -p0 < ../vulnerable.patch
popd >& /dev/null
21 changes: 21 additions & 0 deletions scripts/gen-vulnerable-patch.sh
@@ -0,0 +1,21 @@
#!/bin/bash

# Builds a variant of the target server but with protective measures disabled.
#
# Usually run thus:
# ./scripts/gen-vulnerable-patch.sh > vulnerable.patch

set -e

source_files="$(
git check-ignore -n -v --no-index \
$( find lib -type f | grep -v lib/framework;
echo package.json main.js scripts/run-locally.js static/* ) \
| perl -ne 'print "$1\n" if m/^::\t(.*)/' | sort
)"

(
for f in $source_files; do
diff -u "$f" vulnerable/"$f" || true
done
)

0 comments on commit ba3fb5e

Please sign in to comment.