Created
July 24, 2023 19:50
-
-
Save malefficient/4ca9a2cd6d9296b348c8c89a25378ea4 to your computer and use it in GitHub Desktop.
simple scapy dns resolver example
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
#!/usr/bin/env python3 | |
from scapy.all import * | |
def parse_args(): | |
argc = len(sys.argv) | |
if (argc <= 1 or argc > 3): | |
print('Usage: %s: q_name resolver_ip') | |
sys.exit(0) | |
if (argc == 2): | |
resolver='1.1.1.1' | |
if (argc == 3): | |
resolver=sys.argv[2] | |
return (sys.argv[1], resolver) | |
def craft_query(_qname, _resolver_ip): | |
Q=IP(dst=_resolver_ip)/UDP(dport=53)/DNS(rd=1,qd=DNSQR(qname=_qname)) | |
return Q | |
if __name__ == '__main__': | |
qname, resolver = parse_args() | |
print("--- Crafting DNS query for %s to %s: " %(qname, resolver)) | |
Q = craft_query(qname, resolver) | |
print("--- Transmiting DNS query for %s to %s: " %(qname, resolver)) | |
R = sr1(Q, verbose=0) | |
#ls(R) | |
print("--- Results: %s" %(R)) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment