Last active
June 17, 2022 03:17
-
-
Save yike5460/bbecd850744daf20f05578a3f59808c5 to your computer and use it in GitHub Desktop.
Preflight scan with given domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# scan given domain with dig command | |
# | |
# Usage: | |
# ./dig_scan.py <domain> | |
# | |
# Example: | |
# ./dig_scan.py example.com | |
# | |
# Output: | |
# | |
# example.com | |
# | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
def main(): | |
import sys | |
import subprocess | |
import re | |
if len(sys.argv) != 2: | |
print("Usage: ./dig_scan.py <domain>") | |
sys.exit(1) | |
domain = sys.argv[1] | |
# run dig command to query MX records and extract AUTHORITY SECTION from output | |
cmd = ["dig", "+noall", "+answer", "+authority", domain] | |
try: | |
output = subprocess.check_output(cmd) | |
except subprocess.CalledProcessError as e: | |
logging.error(e) | |
sys.exit(1) | |
# extract string contain with cloudfare | |
# and print domain if found | |
for line in output.decode("utf-8").split("\n"): | |
if "cloudflare.com" in line: | |
pass | |
# branch for cloudflare | |
elif "bigdaddy.com" in line: | |
pass | |
# branch for big daddy | |
# run dig command to query all A records | |
cmd = ["dig", "+noall", "+answer", "A", domain] | |
try: | |
output = subprocess.check_output(cmd) | |
except subprocess.CalledProcessError as e: | |
logging.error(e) | |
sys.exit(1) | |
# extract IP addresses and print them | |
for line in output.decode("utf-8").split("\n"): | |
if "A" in line: | |
ip = re.search(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', line) | |
if ip: | |
logging(ip.group()) | |
# run dig command to query all AAAA records | |
# cmd = ["dig", "+short", "AAAA", domain] | |
# run dig command to fetch all records | |
cmd = ["dig", "+noall", "+answer", "ANY", domain] | |
# TBD, fetch and filter all records | |
""" | |
baidu.com. 83 IN A 220.181.38.251 | |
baidu.com. 83 IN A 220.181.38.148 | |
baidu.com. 27266 IN NS dns.baidu.com. | |
baidu.com. 27266 IN NS ns7.baidu.com. | |
baidu.com. 27266 IN NS ns2.baidu.com. | |
baidu.com. 27266 IN NS ns4.baidu.com. | |
baidu.com. 27266 IN NS ns3.baidu.com. | |
""" | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment