Skip to content

Commit

Permalink
Added auth token check
Browse files Browse the repository at this point in the history
  • Loading branch information
jankais3r authored Mar 25, 2019
1 parent 9221f59 commit 631e505
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions DNoiSe.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def download_domains():
if exists == False:
download_domains()

if auth == "90b03f6fc88f60ff24f4658bbb34c7332f6487b4bd279d0a69001b7f65dc935a":
print >> log_file, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.mktime(datetime.datetime.now().timetuple())))+" You forgot to put in the real auth token. Check the config section at the beginning of the script. Quitting."
exit()

db = sqlite3.connect(working_directory+"domains.sqlite")

while True:
Expand All @@ -124,19 +128,27 @@ def download_domains():

# When determining the rate of DNS queries on the network, we don't want our past fake queries to skew the statistics, therefore we filter out queries made by this machine.
genuine_queries = []
for a in parsed_all_queries["data"]:
if a[3] != client.replace("127.0.0.1","localhost"):
genuine_queries.append(a)
try:
for a in parsed_all_queries["data"]:
if a[3] != client.replace("127.0.0.1","localhost"):
genuine_queries.append(a)
except:
print >> log_file, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.mktime(datetime.datetime.now().timetuple())))+" Pi-hole API response in wrong format. Investigate."
exit()

# Protection in case the pi-hole logs are empty.
if len(genuine_queries) == 0:
genuine_queries.append("Let's not devide by 0")

# We want the types of our fake queries (A/AAA/PTR/…) to proportionally match those of the real traffic.
query_types = []
for a in parsed_all_queries["data"]:
if a[3] != client.replace("127.0.0.1","localhost"):
query_types.append(a[1])
try:
for a in parsed_all_queries["data"]:
if a[3] != client.replace("127.0.0.1","localhost"):
query_types.append(a[1])
except:
print >> log_file, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.mktime(datetime.datetime.now().timetuple())))+" Pi-hole API response in wrong format. Investigate."
exit()

# Default to A request if pi-hole logs are empty
if len(query_types) == 0:
Expand Down

0 comments on commit 631e505

Please sign in to comment.