Curl

Voir uniquement les headers et suivre les redirections

# curl -I -L https://google.fr
HTTP/2 301 
location: https://www.google.fr/
content-type: text/html; charset=UTF-8
date: Thu, 16 Apr 2020 15:02:43 GMT
expires: Sat, 16 May 2020 15:02:43 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 219
x-xss-protection: 0
x-frame-options: SAMEORIGIN
alt-svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,h3-T050=":443"; ma=2592000

HTTP/2 200 
date: Thu, 16 Apr 2020 15:02:43 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
server: gws
x-xss-protection: 0
x-frame-options: SAMEORIGIN
set-cookie: 1P_JAR=2020-04-16-15; expires=Sat, 16-May-2020 15:02:43 GMT; path=/; domain=.google.fr; Secure
set-cookie: NID=202=LPunTOssuEitx5yBl338FqBlsb11Enm76igNf7VXAONFw4pR6gyKH9vjHGK7mNsF0x8pzjcEB_lwqXV9G0N1T0NpjKpFw4fjfuo4jae-vDuxLmk9Gk7CsUABKfHCrOQokTya5XvpaCWsRdHkqP6DuwC2eRHFW15TESq84pjYOR0; expires=Fri, 16-Oct-2020 15:02:43 GMT; path=/; domain=.google.fr; HttpOnly
alt-svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,h3-T050=":443"; ma=2592000
accept-ranges: none
vary: Accept-Encoding

Authentification par form

https://forum.ubuntu-fr.org/viewtopic.php?id=1988093

#!/bin/bash
 
gMonsite="http://demo.redmine.org/login"
gPaheAAtteindre="http://demo.redmine.org/my/page"
gLogin="xxxxxxxx"
gPass="xxxxxxxx"
 
gFichierCookie="/tmp/cookie"
 
 
urlencode() {
    local length="${#1}"
    for (( i = 0; i < length; i++ )); do
        local c="${1:i:1}"
        case $c in
            [a-zA-Z0-9.~_-]) printf "$c" ;;
            *) printf '%%%02X' "'$c"
        esac
    done
}
 
urldecode() {
    local url_encoded="${1//+/ }"
    printf '%b' "${url_encoded//%/\\x}"
}
 
 
# 1/ On récupère un 1er cookie + authentification
gTokenAuthentification=`curl "${gMonsite}" -c "${gFichierCookie}" -s 	|\
          grep csrf-token                				|\
 	  sed -e 's/.*content="//ig' -e 's/".*//ig'`
gTokenAuthentification=$(urlencode "${gTokenAuthentification}")
 
# 2/ On s'authentifie sur le site
curl "${gMonsite}" \
 -s \
 -b "${gFichierCookie}" \
 -c "${gFichierCookie}" \
 --data "authenticity_token=${gTokenAuthentification}" \
 --data "username=${gLogin}" \
 --data "password=${gPass}" \
 --data "login=Connexion" \
 > /dev/null
 
# 3/ On va à la page correspondante, en faisant un grep
curl "${gPaheAAtteindre}" \
 -s \
 -b "${gFichierCookie}" |\
grep -c "129254"