Skip to content

Instantly share code, notes, and snippets.

@wargg
Forked from mzet-/tlsScrape.sh
Created June 6, 2020 22:13
Show Gist options
  • Save wargg/04ff3aa7ee28431aa7e95e74caf481bd to your computer and use it in GitHub Desktop.
Save wargg/04ff3aa7ee28431aa7e95e74caf481bd to your computer and use it in GitHub Desktop.

Revisions

  1. @mzet- mzet- revised this gist Apr 2, 2020. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions tlsScrape.sh
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,14 @@
    #!/bin/bash

    CIDR="$1"
    TARGETS="$1"
    PORT=443

    IPs="$(masscan -oL - "$CIDR" -p "$PORT" 2>/dev/null | grep -v "^#.*" | cut -d' ' -f4)"
    # if file "$TARGETS" exists use its content as a target specification otherwise treat input as a cidr
    if [ -f "$TARGETS" ]; then
    IPs="$(masscan -oL - -iL "$TARGETS" -p "$PORT" 2>/dev/null | grep -v "^#.*" | cut -d' ' -f4)"
    else
    IPs="$(masscan -oL - "$TARGETS" -p "$PORT" 2>/dev/null | grep -v "^#.*" | cut -d' ' -f4)"
    fi

    extractNames() {
    while read LINE; do
  2. @mzet- mzet- revised this gist Dec 4, 2019. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions tlsScrape.sh
    Original file line number Diff line number Diff line change
    @@ -6,20 +6,20 @@ PORT=443
    IPs="$(masscan -oL - "$CIDR" -p "$PORT" 2>/dev/null | grep -v "^#.*" | cut -d' ' -f4)"

    extractNames() {
    while read LINE; do
    # read Common Name part
    if [[ "$LINE" =~ "subject=" ]]; then
    CN=$(echo $LINE | awk -F "CN = " '{print $2}')
    while read LINE; do
    # read Common Name part
    if [[ "$LINE" =~ "subject=" ]]; then
    CN=$(echo $LINE | awk -F "CN = " '{print $2}')
    # read Alt Names extension
    elif [[ "$LINE" =~ "DNS:" ]]; then
    # remove ' DNS:' substring
    LINE=${LINE// /}
    ALT_NAMES=${LINE//DNS:/}
    else
    continue
    fi
    elif [[ "$LINE" =~ "DNS:" ]]; then
    # remove ' DNS:' substring
    LINE=${LINE// /}
    ALT_NAMES=${LINE//DNS:/}
    else
    continue
    fi
    done < /dev/stdin
    echo "$1:$CN,$ALT_NAMES"
    echo "$1:$CN,$ALT_NAMES"
    }

    [ -n "$IPs" ] && while read IP; do
  3. @mzet- mzet- created this gist Dec 4, 2019.
    28 changes: 28 additions & 0 deletions tlsScrape.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/bin/bash

    CIDR="$1"
    PORT=443

    IPs="$(masscan -oL - "$CIDR" -p "$PORT" 2>/dev/null | grep -v "^#.*" | cut -d' ' -f4)"

    extractNames() {
    while read LINE; do
    # read Common Name part
    if [[ "$LINE" =~ "subject=" ]]; then
    CN=$(echo $LINE | awk -F "CN = " '{print $2}')
    # read Alt Names extension
    elif [[ "$LINE" =~ "DNS:" ]]; then
    # remove ' DNS:' substring
    LINE=${LINE// /}
    ALT_NAMES=${LINE//DNS:/}
    else
    continue
    fi
    done < /dev/stdin
    echo "$1:$CN,$ALT_NAMES"
    }

    [ -n "$IPs" ] && while read IP; do
    echo | timeout 2 openssl s_client -connect "$IP:$PORT" 2>/dev/null | openssl x509 -noout -subject -ext subjectAltName 2>/dev/null | extractNames $IP &
    done <<< "$IPs"
    wait