Skip to content

Instantly share code, notes, and snippets.

@m4t7e0
Forked from leomos/connect-to-fortigate.sh
Last active September 18, 2023 15:51
Show Gist options
  • Save m4t7e0/39bc6f4d20f3fb90fc5cbfe31a0ba161 to your computer and use it in GitHub Desktop.
Save m4t7e0/39bc6f4d20f3fb90fc5cbfe31a0ba161 to your computer and use it in GitHub Desktop.
Fortigate firewall connection
#!/bin/bash
USER="user"
PASSWORD="password"
SEP="+++++"
TMP=`curl -s -D - ident.me | grep window.location`
echo "Header with magic: "$TMP
MAGIC=`echo $TMP | grep -o '[[:alnum:]]\{16\}' | tr -d '\r\n'`
HOST=`echo $TMP | cut -d / -f3 | cut -d : -f1 | tr -d '\r\n'`
PORT=`echo $TMP | cut -d / -f3 | cut -d : -f2 | tr -d '\r\n'`
echo "FortiGate: "$HOST" exposed on port: "$PORT "Sent Magic: "$MAGIC
echo $SEP
echo "First request."
curl --verbose -s 'http://'$HOST':'$PORT'/fgtauth?'$MAGIC -H 'Host:'$HOST':'$PORT -H 'Connection: keep-alive'
sleep 1
echo $SEP
echo "Second request with affermative response to the License Agreement."
curl --verbose -s 'http://'$HOST':'$PORT'/' -H 'Host:'$HOST':'$PORT -H 'Referer: http://'$HOST':'$PORT'/fgtauth?'$MAGIC -H 'Connection: keep-alive' --data '4Tredir=http%3A%2F%2Fident.me%2F&magic='$MAGIC'&answer=1'
sleep 1
echo $SEP
echo "Last request with access credentials."
curl --verbose -s 'http://'$HOST':'$PORT'/' -H 'Host:'$HOST':'$PORT -H 'Referer: http://'$HOST':'$PORT'/' -H 'Connection: keep-alive' --data '4Tredir=http%3A%2F%2Fident.me%2F&magic='$MAGIC'&username='$USER'&password='$PASSWORD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment