Skip to content

Instantly share code, notes, and snippets.

@ishideo
Last active May 1, 2026 02:03
Show Gist options
  • Select an option

  • Save ishideo/8c5f3cfcd4a29116e641195817161357 to your computer and use it in GitHub Desktop.

Select an option

Save ishideo/8c5f3cfcd4a29116e641195817161357 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
cat cert.tsv | bb -e '
(->> (slurp *in*)
str/split-lines
(mapcat #(re-seq #"\\n\s\sCommonName:\s.*?\\n\\n|\\nDNS Names:\\n.*?\\n\\n" %)))' \
| bb -e '
(->> (slurp *in*)
str/split-lines
(mapcat #(str/split % #"\\\\n"))
(filter #(re-find #"CommonName:|^\s+[\w\*]" %))
(map #(-> % str/trim (str/replace #".*CommonName:\s+" "")))
(remove str/blank?)
(run! println))
' > domains_fofa.tsv
#!/usr/bin/env bash
cat cert.tsv | bb -e '
(->> (slurp *in*)
str/split-lines
(mapcat #(re-seq #"^Subject:\\n\s\sCommon Name:\s\s\s\s\s\s\s\s\s\s.*?\\n|DNS:.*?\\n|DNS:.*?\\n\\n" %)))' \
| bb -e '
(->> (slurp *in*)
str/split-lines
(mapcat #(str/split % #"\\\\n"))
(filter #(re-find #"Common Name:|DNS:|^\s+[\w\*]" %))
(map #(-> % str/trim (str/replace #".*Common Name:\s\s\s\s\s\s\s\s\s\s" "")))
(map #(-> % str/trim (str/replace #".*DNS:\s" "")))
(remove str/blank?)
(run! println))
' > domains_hunterhow.tsv
#!/usr/bin/env bash
cat cert.tsv | bb -e '
(->> (slurp *in*)
str/split-lines
(mapcat #(re-seq #"CN=[^,/\\]+|DNS:\s*[^,\s]+" %))
(map #(-> % (str/replace #"^.*CN=" "") (str/replace #"^.*DNS:\s*" "") str/trim))
(map #(-> % str/trim (str/replace #"\\n$" "")))
(remove str/blank?)
distinct
(sort-by str/lower-case)
(run! println))
' > domains_zoomeye.tsv
@ishideo
Copy link
Copy Markdown
Author

ishideo commented Apr 12, 2026

$ cat cert.tsv | bb -e '
  (->> (slurp *in*)
       str/split-lines
       (mapcat #(re-seq #"\\nSubject:\\n\s\sCommonName:\s.*?\\n\\n|\\nDNS Names:\\n.*?\\n\\n" %)))' | zprint | head
("\\nSubject:\\n  CommonName: example.com\\n\\n"
 "\\nDNS Names:\\n  example.com\\n\\n"
 "\\nDNS Names:\\n  example.com\\n  example2.com\\n  example3.com\\n\\n"
 "\\nSubject:\\n  CommonName: example.com\\n\\n"
 "\\nDNS Names:\\n  example.com\\n  example2.com\\n\\n"
 "\\nSubject:\\n  CommonName: wegenstein.ch\\n\\n"
 "\\nDNS Names:\\n  example.com\\n  www.example.com\\n\\n"
 "\\nSubject:\\n  CommonName: example.jp\\n\\n"
 "\\nDNS Names:\\n  example.jp\\n\\n"
 "\\nSubject:\\n  CommonName: example.co.jp\\n\\n"

@ishideo
Copy link
Copy Markdown
Author

ishideo commented Apr 12, 2026

#!/usr/bin/env bash

cat cert.tsv | bb -e '
(let [normalize #(str/replace % #"^\*\." "")
      tokens    (str/split (slurp *in*) #"\\n")]
  (loop [[x & xs] tokens
         mode nil
         out []]
    (if (nil? x)
      (run! println out)
      (let [t (str/trim x)]
        (cond
          (= t "Subject:")   (recur xs :subject out)
          (= t "DNS Names:") (recur xs :dns out)

          (and (= mode :subject) (str/starts-with? t "CommonName: "))
          (recur xs nil (conj out (normalize (subs t 12))))

          (and (= mode :dns) (not (str/blank? t)) (not (str/ends-with? t ":")))
          (recur xs :dns (conj out (normalize t)))

          :else
          (recur xs nil out))))))
' > domains_fofa.tsv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment