2019-05-29 05:15:08 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-02-08 03:32:36 +00:00
|
|
|
set -efux -o pipefail
|
2019-05-29 05:15:08 +00:00
|
|
|
|
|
|
|
## Create a temporary working folder
|
2020-02-08 03:32:36 +00:00
|
|
|
mkdir -p "tmp/" && cd "tmp/"
|
2019-05-29 05:15:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Prepare datasets
|
2020-02-08 03:32:36 +00:00
|
|
|
wget "https://urlhaus.abuse.ch/downloads/csv/" -O "../src/URLhaus.csv"
|
|
|
|
wget "https://s3-us-west-1.amazonaws.com/umbrella-static/top-1m.csv.zip" -O "top-1m.csv.zip"
|
2019-05-29 05:15:08 +00:00
|
|
|
|
2020-02-08 03:32:36 +00:00
|
|
|
cp "../src/exclude.txt" "."
|
2019-05-29 05:15:08 +00:00
|
|
|
|
2019-06-16 02:21:36 +00:00
|
|
|
## Clean up URLhaus.csv
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "../src/URLhaus.csv" | \
|
2019-05-29 05:15:08 +00:00
|
|
|
# Convert DOS to Unix line ending
|
|
|
|
dos2unix | \
|
|
|
|
# Remove comment
|
2020-02-08 03:32:36 +00:00
|
|
|
sed "/^#/d" | \
|
2019-06-16 02:21:36 +00:00
|
|
|
# Parse URLs
|
|
|
|
cut -f 6 -d '"' | \
|
2020-02-08 03:32:36 +00:00
|
|
|
cut -f 3- -d "/" | \
|
2019-08-04 07:54:07 +00:00
|
|
|
# Domain must have at least a 'dot'
|
2020-02-08 03:32:36 +00:00
|
|
|
grep -F "." | \
|
2019-05-29 05:15:08 +00:00
|
|
|
# Remove www.
|
2020-02-08 03:32:36 +00:00
|
|
|
sed "s/^www\.//g" | \
|
|
|
|
sort -u > "urlhaus.txt"
|
2019-05-29 05:15:08 +00:00
|
|
|
|
|
|
|
## Parse domain and IP address only
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "urlhaus.txt" | \
|
|
|
|
cut -f 1 -d "/" | \
|
|
|
|
cut -f 1 -d ":" | \
|
|
|
|
sort -u > "urlhaus-domains.txt"
|
2019-05-29 05:15:08 +00:00
|
|
|
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "../src/URLhaus.csv" | \
|
2019-06-13 06:04:13 +00:00
|
|
|
dos2unix | \
|
2020-02-08 03:32:36 +00:00
|
|
|
sed "/^#/d" | \
|
2019-06-13 06:04:13 +00:00
|
|
|
# Parse online URLs only
|
|
|
|
grep '"online"' | \
|
|
|
|
cut -f 6 -d '"' | \
|
2020-02-08 03:32:36 +00:00
|
|
|
cut -f 3- -d "/" | \
|
|
|
|
sed "s/^www\.//g" | \
|
|
|
|
sort -u > "urlhaus-online.txt"
|
2019-06-13 06:04:13 +00:00
|
|
|
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "urlhaus-online.txt" | \
|
|
|
|
cut -f 1 -d "/" | \
|
|
|
|
cut -f 1 -d ":" | \
|
|
|
|
sort -u > "urlhaus-domains-online.txt"
|
2019-06-13 06:04:13 +00:00
|
|
|
|
2019-05-29 05:15:08 +00:00
|
|
|
|
|
|
|
## Parse the Cisco Umbrella 1 Million
|
2020-02-08 03:32:36 +00:00
|
|
|
unzip -p "top-1m.csv.zip" | \
|
2019-05-29 05:15:08 +00:00
|
|
|
dos2unix | \
|
|
|
|
# Parse domains only
|
2020-02-08 03:32:36 +00:00
|
|
|
cut -f 2 -d "," | \
|
|
|
|
grep -F "." | \
|
2019-05-29 05:15:08 +00:00
|
|
|
# Remove www.
|
2020-02-08 03:32:36 +00:00
|
|
|
sed "s/^www\.//g" | \
|
|
|
|
sort -u > "top-1m.txt"
|
2019-05-29 05:15:08 +00:00
|
|
|
|
|
|
|
# Merge Umbrella and self-maintained top domains
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "top-1m.txt" "exclude.txt" | \
|
|
|
|
sort -u > "top-1m-well-known.txt"
|
2019-05-29 05:15:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Parse popular domains from URLhaus
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "urlhaus-domains.txt" | \
|
2019-05-29 05:15:08 +00:00
|
|
|
# grep match whole line
|
2020-02-08 03:32:36 +00:00
|
|
|
grep -Fx -f "top-1m-well-known.txt" > "urlhaus-top-domains.txt"
|
2019-05-29 05:15:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Parse domains from URLhaus excluding popular domains
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "urlhaus-domains.txt" | \
|
|
|
|
grep -F -vf "urlhaus-top-domains.txt" > "malware-domains.txt"
|
2019-05-29 05:15:08 +00:00
|
|
|
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "urlhaus-domains-online.txt" | \
|
|
|
|
grep -F -vf "urlhaus-top-domains.txt" > "malware-domains-online.txt"
|
2019-06-13 06:04:13 +00:00
|
|
|
|
2019-05-29 06:04:31 +00:00
|
|
|
## Parse malware URLs from popular domains
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "urlhaus.txt" | \
|
|
|
|
grep -F -f "urlhaus-top-domains.txt" > "malware-url-top-domains.txt"
|
2019-05-29 05:15:08 +00:00
|
|
|
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "urlhaus-online.txt" | \
|
|
|
|
grep -F -f "urlhaus-top-domains.txt" > "malware-url-top-domains-online.txt"
|
2019-06-13 06:04:13 +00:00
|
|
|
|
2019-05-29 05:15:08 +00:00
|
|
|
|
|
|
|
## Merge malware domains and URLs
|
|
|
|
CURRENT_TIME="$(date -R -u)"
|
|
|
|
FIRST_LINE="! Title: abuse.ch URLhaus Malicious URL Blocklist"
|
|
|
|
SECOND_LINE="! Updated: $CURRENT_TIME"
|
|
|
|
THIRD_LINE="! Expires: 1 day (update frequency)"
|
|
|
|
FOURTH_LINE="! Repo: https://gitlab.com/curben/urlhaus-filter"
|
|
|
|
FIFTH_LINE="! License: https://creativecommons.org/publicdomain/zero/1.0/"
|
|
|
|
SIXTH_LINE="! Source: https://urlhaus.abuse.ch/api/"
|
|
|
|
COMMENT="$FIRST_LINE\n$SECOND_LINE\n$THIRD_LINE\n$FOURTH_LINE\n$FIFTH_LINE\n$SIXTH_LINE"
|
|
|
|
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "malware-domains.txt" "malware-url-top-domains.txt" | \
|
2019-05-29 05:15:08 +00:00
|
|
|
sort | \
|
2020-02-08 03:32:36 +00:00
|
|
|
sed '1 i\'"$COMMENT"'' > "../urlhaus-filter.txt"
|
2019-05-29 05:15:08 +00:00
|
|
|
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "malware-domains-online.txt" "malware-url-top-domains-online.txt" | \
|
2019-06-13 06:04:13 +00:00
|
|
|
sort | \
|
|
|
|
sed '1 i\'"$COMMENT"'' | \
|
2020-02-08 03:32:36 +00:00
|
|
|
sed "1s/Malicious/Online Malicious/" > "../urlhaus-filter-online.txt"
|
2019-06-13 06:04:13 +00:00
|
|
|
|
2019-05-29 05:15:08 +00:00
|
|
|
|
2019-10-01 06:58:46 +00:00
|
|
|
## Host-only blocklist
|
|
|
|
FIRST_LINE="# Title: abuse.ch URLhaus Malicious Hosts Blocklist"
|
|
|
|
SECOND_LINE="# Updated: $CURRENT_TIME"
|
|
|
|
THIRD_LINE="# Repo: https://gitlab.com/curben/urlhaus-filter"
|
|
|
|
FOURTH_LINE="# License: https://creativecommons.org/publicdomain/zero/1.0/"
|
|
|
|
FIFTH_LINE="# Source: https://urlhaus.abuse.ch/api/"
|
|
|
|
COMMENT="$FIRST_LINE\n$SECOND_LINE\n$THIRD_LINE\n$FOURTH_LINE\n$FIFTH_LINE"
|
|
|
|
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "malware-domains.txt" | \
|
2019-10-01 06:58:46 +00:00
|
|
|
sort | \
|
2020-02-08 03:32:36 +00:00
|
|
|
sed '1 i\'"$COMMENT"'' > "../urlhaus-filter-hosts.txt"
|
2019-10-01 06:58:46 +00:00
|
|
|
|
2020-02-08 03:32:36 +00:00
|
|
|
cat "malware-domains-online.txt" | \
|
2019-10-01 06:58:46 +00:00
|
|
|
sort | \
|
|
|
|
sed '1 i\'"$COMMENT"'' | \
|
2020-02-08 03:32:36 +00:00
|
|
|
sed "1s/Malicious/Online Malicious/" > "../urlhaus-filter-hosts-online.txt"
|
2019-10-01 06:58:46 +00:00
|
|
|
|
2020-02-08 03:37:01 +00:00
|
|
|
cd ../ && rm -rf "tmp/"
|