Difference between revisions of "Curl"
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
| Line 63: | Line 63: | ||
|    cmd="/usr/bin/curl -w \" %{$metric}\" -o /dev/null -s \"$url\"" |    cmd="/usr/bin/curl -w \" %{$metric}\" -o /dev/null -s \"$url\"" | ||
|    metric_value=$(eval "$cmd") |    metric_value=$(eval "$cmd") | ||
| − | elif [[ "$curltype" == " | + | elif [[ "$curltype" == "resolve" ]]; then | 
|    if [[ "$#" -lt 4 ]]; then |    if [[ "$#" -lt 4 ]]; then | ||
|      echo "Usage: $0 <type> <curl metric> <url> <spoof ipaddr>" |      echo "Usage: $0 <type> <curl metric> <url> <spoof ipaddr>" | ||
| − |      echo "Example: $0  | + |      echo "Example: $0 resolve time_total https://example.org 127.0.0.1" | 
|      exit |      exit | ||
|    fi |    fi | ||
| Line 72: | Line 72: | ||
|     host=$(echo "$url" | awk -F/ '{print $3}') |     host=$(echo "$url" | awk -F/ '{print $3}') | ||
|     cmd="/usr/bin/curl -w \"%{time_total}\" -o /dev/null -s --resolve $host:443:$ipaddr \"$url\"" |     cmd="/usr/bin/curl -w \"%{time_total}\" -o /dev/null -s --resolve $host:443:$ipaddr \"$url\"" | ||
| + |    metric_value=$(eval "$cmd") | ||
| + | elif [[ "$curltype" == "connect-to" ]]; then | ||
| + |   if [[ "$#" -lt 4 ]]; then | ||
| + |     echo "Usage: $0 <type> <curl metric> <url> <fqdn>" | ||
| + |     echo "Example: $0 connect-to time_total https://example.org myapp-svc.azurewebsites.net" | ||
| + |     exit | ||
| + |   fi | ||
| + |    dstadc_fqdn=$4 | ||
| + |    host=$(echo "$url" | awk -F/ '{print $3}') | ||
| + |    cmd="/usr/bin/curl -w \"%{time_total}\" -o /dev/null -s --resolve $host:443:$dstadc_fqdn \"$url\"" | ||
|     metric_value=$(eval "$cmd") |     metric_value=$(eval "$cmd") | ||
| else | else | ||
Revision as of 17:23, 28 January 2022
SNI header
curl --connect-to www.example.com:443:example.a:443 https://www.example.com
curl -sv   --resolve $host:443:$ip https://$host
curl --resolve example.com:443:127.0.0.1 https://example.com/
curl -vik --resolve example.com:443:198.18.110.10 https://example.com/
curl.exe --connect-to api.example.com:443:myapp.azurewebsites.net https://api.example.com/mypath/health
curl.exe -w "%{time_total}" --connect-to api.example.com:443:myapp.azurewebsites.net https://api.example.com/mypath/health
tshark -l -i F5_Internal -f 'dst port ( 443 )' -Y 'ssl.handshake.extension.type == "server_name" || http.host' -T fields -e ip.src -e ip.dst -e tcp.dstport -e ssl.handshake.extensions_server_name -e http.host | grep example
Non sni header (port 80 unencrypted header)
curl --header "Host: example.com" http://127.0.0.1/
https://daniel.haxx.se/blog/2018/04/05/curl-another-host/
Testing ciphers
# curl https://www.example.com -k -v --location-trusted --sslv2 curl https://www.example.com -k -v --location-trusted --tlsv1.1 curl https://www.example.com -k -v --location-trusted --tlsv1.2 curl https://www.example.com -k -v --location-trusted --tlsv1.3
for host in 10.1.1.10 10.1.1.52 10.1.1.16 10.1.1.16; do echo $host; curl --header "Host: www.example.org" http://$host/downloads/myfile.png --output /dev/null; done
BASH Wrapper
#!/usr/bin/env bash
if [[ "$#" -lt 3 ]]; then
  echo "Usage: $0 <type> <curl metric> <url>"
  echo "Example: $0 url time_connect https://google.com"
echo "
====URL Type Metrics====
time_namelookup
time_connect
time_appconnec
time_pretransfer
time_redirect
time_starttransfer
time_total
"
  exit
fi
curltype=$1
metric=$2
url=$3
if [[ "$curltype" == "url" ]]; then
  cmd="/usr/bin/curl -w \" %{$metric}\" -o /dev/null -s \"$url\""
  metric_value=$(eval "$cmd")
elif [[ "$curltype" == "resolve" ]]; then
  if [[ "$#" -lt 4 ]]; then
    echo "Usage: $0 <type> <curl metric> <url> <spoof ipaddr>"
    echo "Example: $0 resolve time_total https://example.org 127.0.0.1"
    exit
  fi
   ipaddr=$4
   host=$(echo "$url" | awk -F/ '{print $3}')
   cmd="/usr/bin/curl -w \"%{time_total}\" -o /dev/null -s --resolve $host:443:$ipaddr \"$url\""
   metric_value=$(eval "$cmd")
elif [[ "$curltype" == "connect-to" ]]; then
  if [[ "$#" -lt 4 ]]; then
    echo "Usage: $0 <type> <curl metric> <url> <fqdn>"
    echo "Example: $0 connect-to time_total https://example.org myapp-svc.azurewebsites.net"
    exit
  fi
   dstadc_fqdn=$4
   host=$(echo "$url" | awk -F/ '{print $3}')
   cmd="/usr/bin/curl -w \"%{time_total}\" -o /dev/null -s --resolve $host:443:$dstadc_fqdn \"$url\""
   metric_value=$(eval "$cmd")
else
  echo "E: Unsupported type of check."
fi
code=$?
if [[ "$code" != 0 ]]; then
   # echo error
    echo "$metric_value"
else
    echo "$metric_value"
fi