đź… |
|
|
| |
reverse proxy 19/02/2018 mini 28/07/2020 divers 21/08/2023 | ||
De nombreux équipements connectés au réseau local embarquent un petit serveur web rustique. (imprimantes, camera IP ou même box internet) Il ne serait pas sage de les mettre en accès libre sur internet. Le Raspberry Pi peut au contraire gérer un serveur web Appache ou Nginx par exemple. Il peut faire office de frontal grâce à la fonction "reverse proxy" ( mandataire inverse ). et ajouter une demande de mot de passe. | ||
#! /bin/bash # un mini serveur de pages web statiques # abstract : tiny out of tiniest web servers DO NOT USE IT unless with chroot and still # ATTENTION usage non sécurisé sans chroot tu meurs # sinon tappe python3 -m http.server # ou mieux installe lighttpd depuis la logithèque type nc || exec echo "$0 : commande nc alias netcat prérequise" >&2 PMIN=1024 # port minimum sinon reservé à root ROOTDOC=${1:-.} # repertoir des pages en parametre ou local par defaut test -d "$ROOTDOC" || exec echo "$0 : $ROOTDOC n'est pas un repertoir" PORT=${2:-$PMIN} # d'écoute IP second parametre ou $PMIN echo -n "$0 : sert les pages web de $ROOTDOC sur le port " >&2 grep -w "^[[:digit:]]*$" <<< "$PORT" >&2 || exec echo "$PORT non numérique ne convient pas" >&2 test $PORT = 0 && exec echo "le port ne convient pas" test $PORT -ge $PMIN || test "$LOGNAME" = root || exec echo "les ports sous $PMIN sont réservés à root" >&2 echo "pour arreter : Ctrl C" >&2 traite_page() { DEMANDE=$(head -8) echo "$DEMANDE" >&2 # main courante dans la sortie des erreurs PAGE=$(head -1 <<< $DEMANDE | cut -d' ' -f2) # awk exige trop de bibliotheques test -d "$ROOTDOC$PAGE" && PAGE=${PAGE}/ test "${PAGE:$((${#PAGE}-1))}" = "/" && test -f "${ROOTDOC}${PAGE}index.html" && PAGE="${PAGE}index.html" test "${PAGE:$((${#PAGE}-1))}" = "/" && test -f "${ROOTDOC}${PAGE}index.htm" && PAGE="${PAGE}index.htm" test "${PAGE:$((${#PAGE}-5))}" = ".html" && echo -e "HTTP/1.1 200 OK\n" test "${PAGE:$((${#PAGE}-4))}" = ".htm" && echo -e "HTTP/1.1 200 OK\n" test -f "$ROOTDOC$PAGE" && exec cat "$ROOTDOC$PAGE" test "$PAGE" != /favicon.ico || test -f "${ROOTDOC}/favicon.ico" || ! test -x /usr/bin/base64 || exec /usr/bin/base64 -d <<+++ AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAlZiUAAHoAAMrx1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAIiIiIiIiIiIiIiIiIiIiIiIgICAgICAiIgICAgICAgIiAgICAgICAiICIgIi AiICIiIiIiIiIiIiIiIiIiIiIiAgICAgISAiICAgICAhICIgICAgICEgIiAAAiAgAiAiIiIiIiIi IiIiIiIgIiIgIiIiIiIiIiIiIiIiIiIiIiIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +++ echo -e "HTTP/1.1 200 OK\n\n<html><body><center><h1>$PAGE page inconnue</h1></center></body></html>" } # fin de la fonction traite_page trap "exec rm -f /tmp/tuyau$$" 2 rm -f /tmp/tuyau$$; mknod /tmp/tuyau$$ p; while traite_page < /tmp/tuyau$$ | nc -l $PORT > /tmp/tuyau$$; do echo +++ >&2; done | ||
PC dans le navigateur www.onworks.net pour trouver les repertoires d'un serveur web par force brut dirb |