Last active
November 11, 2022 00:04
-
-
Save nginx-gists/0c7a5ee7d2c5dd010b3498c24aa7a867 to your computer and use it in GitHub Desktop.
Filesystem Isolation in NGINX Unit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"listeners": { | |
"*:80": { | |
"pass": "applications/ab_app" | |
} | |
}, | |
"applications": { | |
"ab_app": { | |
"type": "php", | |
"user": "www-data", | |
"script": "index.php", | |
"root": "/", | |
"isolation": { | |
"rootfs": "/www/data/a/" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require '/var/custom/module.php'; // Our hardcoded dependency | |
module_do_stuff("How do you like this?\n"); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, Response | |
import os, stat, subprocess | |
application = Flask(__name__) | |
@application.route("/find/") | |
def find(): | |
l = [] | |
path = request.args.get("path") | |
for root , _, files in os.walk(path): | |
for f in files: | |
try: | |
absp = os.path.join(root, f) | |
if os.stat(absp).st_mode & stat.S_ISUID: | |
l.append(absp) | |
except: | |
pass | |
return Response("\n".join(l), mimetype="text/plain") | |
@application.route("/exfiltrate/") | |
def exfiltrate(): | |
file = request.args.get("file") | |
subprocess.run(args = ["/usr/bin/cp", "--no-preserve=mode", file, "./out"]) | |
return Response(open("./out").read(), mimetype="text/plain") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Version A, stored as /www/data/a/var/custom/module.php | |
function module_do_stuff($stuff) { | |
echo "Implementation A, legacy: ".$stuff; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Version B, stored as /www/data/b/var/custom/module.php | |
function module_do_stuff($stuff) { | |
echo "Implementation B, brand new: ".$stuff; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"listeners": { | |
"*:80": { | |
"pass": "applications/rootfs_demo" | |
} | |
}, | |
"applications": { | |
"rootfs_demo": { | |
"type": "python", | |
"path": "/path/to/rootfs_demo/", | |
"home": "/path/to/rootfs_demo/venv/", | |
"module": "wsgi" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"listeners": { | |
"*:80": { | |
"pass": "applications/rootfs_demo" | |
} | |
}, | |
"applications": { | |
"rootfs_demo": { | |
"type": "python", | |
"path": "/", | |
"home": "/venv/", | |
"module": "wsgi", | |
"isolation": { | |
"rootfs": "/path/to/rootfs_demo/" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"isolation": { | |
"rootfs": "/path/to/rootfs_demo/", | |
"namespaces": { | |
"mount": true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For a discussion of these files, see Filesystem Isolation in NGINX Unit