-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shell improvements in GreyNoise-Canary script #5
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,16 @@ | |
# Canary support will be happy to enable API access to your console. See the README for further information. | ||
|
||
# Replace these placeholder values with your own | ||
export CANARY_HASH="abcd1234" | ||
export CANARY_TOKEN="11a2222bb3333c444d555e6f777ggg88" | ||
CANARY_HASH="abcd1234" | ||
CANARY_TOKEN="11a2222bb3333c444d555e6f777ggg88" | ||
CANARY_IP_LIST="canary-ips-$(date +%Y-%m-%d).txt" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Date changes every midnight - putting it into a variable |
||
|
||
# Query Canary API for all events, extract IPs, remove double quotes, and write to a text file for GreyNoise | ||
curl https://$CANARY_HASH.canary.tools/api/v1/incidents/outside_bird/search -d auth_token=$CANARY_TOKEN -d node_ids="INSERT_NODE_IDS" -G | jq '.src_ips[] | .ip_address' | sed 's/\"//g' | cat > canary-ips-$(date +%Y-%m-%d).txt | ||
curl "https://${CANARY_HASH}.canary.tools/api/v1/incidents/outside_bird/search -d auth_token=${CANARY_TOKEN}" -d node_ids="INSERT_NODE_IDS" -G \ | ||
| jq --raw-output '.src_ips[] | .ip_address' > "${CANARY_IP_LIST}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
# Read through each line of the text file, send each IP to the GreyNoise Community API for context, and write the results to a JSON file | ||
file="canary-ips-$(date +%Y-%m-%d).txt" | ||
lines=$(cat $file) | ||
|
||
for line in $lines | ||
while read -r ip_address | ||
do | ||
curl "https://api.greynoise.io/v3/community/$line" | jq '.' | cat >> GreyNoise-Canary-Threat-Intel-Report-$(date +%Y-%m-%d).json | ||
done | ||
|
||
curl "https://api.greynoise.io/v3/community/${ip_address}" | jq '.' | ||
done < "${CANARY_IP_LIST}" > "GreyNoise-Canary-Threat-Intel-Report-$(date +%Y-%m-%d).json" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how one reads lines from a file - Please consider using https://github.com/koalaman/shellcheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for EXPORT, we use these variables inside the script