pholus 2.1

This commit is contained in:
Jokob-sk
2022-12-30 12:16:14 +11:00
parent 6ef0ba3098
commit bde96af7da
7 changed files with 179 additions and 119 deletions

View File

@@ -22,6 +22,7 @@ import subprocess
import os
import re
import time
import decimal
import datetime
from datetime import timedelta
# from datetime import datetime
@@ -622,7 +623,7 @@ def main ():
if runPholus:
last_pholus_scheduled_run = datetime.datetime.now(tz).replace(microsecond=0)
performPholusScan()
performPholusScan(PHOLUS_RUN_TIMEOUT)
# Perform an arp-scan if not disable with a file
if last_network_scan + datetime.timedelta(minutes=SCAN_CYCLE_MINUTES) < time_started and os.path.exists(STOPARPSCAN) == False:
@@ -1650,13 +1651,14 @@ def update_devices_names ():
# perform Pholus scan if (unknown) devices found
if PHOLUS_ACTIVE and (len(unknownDevices) > 0 or PHOLUS_FORCE):
performPholusScan()
performPholusScan(PHOLUS_TIMEOUT)
# get names from Pholus scan
sql.execute ('SELECT * FROM Pholus_Scan where "MAC" in (select "dev_MAC" from Devices where "dev_Name" IN ("(unknown)","")) and "Record_Type"="Answer"')
pholusResults = sql.fetchall()
file_print("pholusResults: ", len(pholusResults))
# Number of entries for unknown MACs from the Pholus scan
file_print(" Pholus entries: ", len(pholusResults))
for device in unknownDevices:
# Resolve device name OLD
@@ -1685,7 +1687,7 @@ def update_devices_names ():
# file_print(sql.rowcount)
#-------------------------------------------------------------------------------
def performPholusScan ():
def performPholusScan (timeout):
subnetList = []
@@ -1706,9 +1708,9 @@ def performPholusScan ():
file_print(" Pholus scan on interface: ", interface, " mask: " , mask)
updateState("Scan: Pholus")
file_print('[', timeNow(), '] Scan: Pholus')
file_print('[', timeNow(), '] Scan: Pholus for ', str(timeout), 's ('+ str(round(int(timeout) / 60), 2) +'min)')
pholus_args = ['python3', '/home/pi/pialert/pholus/pholus3.py', interface, "-rdns_scanning", mask, "-stimeout", str(PHOLUS_TIMEOUT)]
pholus_args = ['python3', '/home/pi/pialert/pholus/pholus3.py', interface, "-rdns_scanning", mask, "-stimeout", str(timeout)]
# Execute command
try:
@@ -1722,7 +1724,7 @@ def performPholusScan ():
if output != "":
file_print('[', timeNow(), '] Scan: Pholus SUCCESS')
write_file (logPath + '/pialert_pholus_old.log', output)
write_file (logPath + '/pialert_pholus_lastrun.log', output)
for line in output.split("\n"):
append_line_to_file (logPath + '/pialert_pholus.log', line +'\n')
@@ -2922,9 +2924,6 @@ def hide_email(email):
m = email.split('@')
return f'{m[0][0]}{"*"*(len(m[0])-2)}{m[0][-1] if len(m[0]) > 1 else ""}@{m[1]}'
# Test
print(hide_email('emailsecreto@gmail.com'))
#-------------------------------------------------------------------------------
def runSchedule():
@@ -2934,45 +2933,34 @@ def runSchedule():
result = False
# datetime.now() - timedelta(days=1)
# Initialize the last run time if never run before
if last_pholus_scheduled_run == 0:
# last_pholus_scheduled_run = datetime.datetime.fromtimestamp(pd.Timestamp(year = 2000, month = 1, day = 1, hour = 1, second = 1, tz = TIMEZONE))
last_pholus_scheduled_run = (datetime.datetime.now(tz) - timedelta(days=365)).replace(microsecond=0)
# get the current time with the currently specified timezone
nowTime = datetime.datetime.now(tz).replace(microsecond=0)
# # DEBUG
# file_print("now : ", nowTime.isoformat())
# file_print("last_pholus_scheduled_run: ", last_pholus_scheduled_run.isoformat())
# file_print("last_next_pholus_schedule: ", last_next_pholus_schedule.isoformat())
# file_print("nowTime > last_next_pholus_schedule: ", nowTime > last_next_pholus_schedule)
# file_print("last_pholus_scheduled_run < last_next_pholus_schedule: ", last_pholus_scheduled_run < last_next_pholus_schedule)
file_print("now : ", nowTime.isoformat(), "Type: ", type(nowTime))
file_print("last_pholus_scheduled_run: ", last_pholus_scheduled_run.isoformat(), "Type: ", type(last_pholus_scheduled_run))
file_print("last_next_pholus_schedule: ", last_next_pholus_schedule.isoformat(), "Type: ", type(last_next_pholus_schedule))
file_print("nowTime > last_next_pholus_schedule: ", nowTime > last_next_pholus_schedule)
file_print("last_pholus_scheduled_run < last_next_pholus_schedule: ", last_pholus_scheduled_run < last_next_pholus_schedule)
# Run the schedule if the current time is past the schedule time we saved last time and
# (maybe the following check is unnecessary:)
# if the last run is past the last time we run a scheduled Pholus scan
if nowTime > last_next_pholus_schedule and last_pholus_scheduled_run < last_next_pholus_schedule:
file_print("run: YES")
print_log("Scheduler run: YES")
last_next_pholus_schedule_used = True
result = True
else:
file_print("run: NO")
# file_print("last_next_pholus_schedule lastRunDateTime: ",
# Debug
print_log("Scheduler run: NO")
if last_next_pholus_schedule_used:
last_next_pholus_schedule_used = False
last_next_pholus_schedule = schedule.next()
file_print("runSchedule n : ", last_next_pholus_schedule.isoformat())
return result
#===============================================================================

View File

@@ -11,6 +11,10 @@
var timerRefreshData = ''
var modalCallbackFunction = '';
// urlParams = new Proxy(new URLSearchParams(window.location.search), {
// get: (searchParams, prop) => searchParams.get(prop.toString()),
// });
function getCache(key)
{
// check cache

View File

@@ -353,7 +353,9 @@ if (submit && isset($_POST['skinselector_set'])) {
</div>
<div class="row logs-row" >
<div>
<div class="log-file">pialert.log <div class="logs-size"><?php echo number_format((filesize("./log/pialert.log") / 1000000),2,",",".") . ' MB';?> </div></div><span class="span-padding"><a href="./log/pialert.log" target="_blank"><i class="fa fa-download"></i> </a></span>
<div class="log-file">pialert.log <div class="logs-size"><?php echo number_format((filesize("./log/pialert.log") / 1000000),2,",",".") . ' MB';?>
<span class="span-padding"><a href="./log/pialert.log" target="_blank"><i class="fa fa-download"></i> </a></span>
</div></div>
<div class="log-purge">
<button class="btn btn-primary" onclick="logManage('pialert.log','cleanLog')"><?php echo lang('Gen_Purge');?></button>
</div>
@@ -367,7 +369,9 @@ if (submit && isset($_POST['skinselector_set'])) {
</div>
<div class="row logs-row" >
<div>
<div class="log-file">pialert_front.log<div class="logs-size"><?php echo number_format((filesize("./log/pialert_front.log") / 1000000),2,",",".") . ' MB';?> </div></div><span class="span-padding"><a href="./log/pialert_front.log"><i class="fa fa-download"></i> </a></span>
<div class="log-file">pialert_front.log<div class="logs-size"><?php echo number_format((filesize("./log/pialert_front.log") / 1000000),2,",",".") . ' MB';?>
<span class="span-padding"><a href="./log/pialert_front.log"><i class="fa fa-download"></i> </a></span>
</div></div>
<div class="log-purge">
<button class="btn btn-primary" onclick="logManage('pialert_front.log','cleanLog')"><?php echo lang('Gen_Purge');?></button>
</div>
@@ -382,7 +386,9 @@ if (submit && isset($_POST['skinselector_set'])) {
</div>
<div class="row logs-row" >
<div>
<div class="log-file">pialert_pholus.log<div class="logs-size"><?php echo number_format((filesize("./log/pialert_pholus.log") / 1000000),2,",",".") . ' MB';?> </div></div><span class="span-padding"><a href="./log/pialert_pholus.log"><i class="fa fa-download"></i> </a></span>
<div class="log-file">pialert_pholus.log<div class="logs-size"><?php echo number_format((filesize("./log/pialert_pholus.log") / 1000000),2,",",".") . ' MB';?>
<span class="span-padding"><a href="./log/pialert_pholus.log"><i class="fa fa-download"></i> </a></span>
</div></div>
<div class="log-purge">
<button class="btn btn-primary" onclick="logManage('pialert_pholus.log','cleanLog')"><?php echo lang('Gen_Purge');?></button>
</div>
@@ -392,13 +398,33 @@ if (submit && isset($_POST['skinselector_set'])) {
</div>
<div class="log-area">
<div class="row logs-row">
<textarea id="pialert_pholus_log" class="logs logs-small" cols="70" rows="10" wrap='off' readonly><?php echo file_get_contents( "./log/pialert_pholus_subp.log" ); ?>
</textarea>
</div>
<div class="row logs-row" >
<div>
<div class="log-file">pialert_pholus_subp.log<div class="logs-size"><?php echo number_format((filesize("./log/pialert_pholus_subp.log") / 1000000),2,",",".") . ' MB';?>
<span class="span-padding"><a href="./log/pialert_pholus_subp.log"><i class="fa fa-download"></i> </a></span>
</div></div>
<div class="log-purge">
<button class="btn btn-primary" onclick="logManage('pialert_pholus_subp.log','cleanLog')"><?php echo lang('Gen_Purge');?></button>
</div>
</div>
</div>
</div>
<div class="log-area">
<div class="row logs-row">
<textarea id="IP_changes_log" class="logs logs-small" cols="70" rows="10" readonly><?php echo file_get_contents( "./log/IP_changes.log" ); ?>
</textarea>
</div>
<div class="row logs-row" >
<div>
<div class="log-file">IP_changes.log<div class="logs-size"><?php echo number_format((filesize("./log/IP_changes.log") / 1000000),2,",",".") . ' MB';?> </div></div><span class="span-padding"><a href="./log/IP_changes.log"><i class="fa fa-download"></i> </a></span>
<div class="log-file">IP_changes.log<div class="logs-size"><?php echo number_format((filesize("./log/IP_changes.log") / 1000000),2,",",".") . ' MB';?>
<span class="span-padding"><a href="./log/IP_changes.log"><i class="fa fa-download"></i> </a></span>
</div></div>
<div class="log-purge">
<button class="btn btn-primary" onclick="logManage('IP_changes.log','cleanLog')"><?php echo lang('Gen_Purge');?></button>
</div>
@@ -413,7 +439,9 @@ if (submit && isset($_POST['skinselector_set'])) {
</div>
<div class="row logs-row" >
<div>
<div class="log-file">stdout.log<div class="logs-size"><?php echo number_format((filesize("./log/stdout.log") / 1000000),2,",",".") . ' MB';?> </div></div><span class="span-padding"><a href="./log/stdout.log"><i class="fa fa-download"></i> </a></span>
<div class="log-file">stdout.log<div class="logs-size"><?php echo number_format((filesize("./log/stdout.log") / 1000000),2,",",".") . ' MB';?>
<span class="span-padding"><a href="./log/stdout.log"><i class="fa fa-download"></i> </a></span>
</div></div>
<div class="log-purge">
<button class="btn btn-primary" onclick="logManage('stdout.log','cleanLog')"><?php echo lang('Gen_Purge');?></button>
</div>
@@ -428,7 +456,9 @@ if (submit && isset($_POST['skinselector_set'])) {
</div>
<div class="row logs-row" >
<div>
<div class="log-file">stderr.log<div class="logs-size"><?php echo number_format((filesize("./log/stderr.log") / 1000000),2,",",".") . ' MB';?> </div></div><span class="span-padding"><a href="./log/stderr.log"><i class="fa fa-download"></i> </a></span>
<div class="log-file">stderr.log<div class="logs-size"><?php echo number_format((filesize("./log/stderr.log") / 1000000),2,",",".") . ' MB';?>
<span class="span-padding"><a href="./log/stderr.log"><i class="fa fa-download"></i> </a></span>
</div></div>
<div class="log-purge">
<button class="btn btn-primary" onclick="logManage('stderr.log','cleanLog')"><?php echo lang('Gen_Purge');?></button>
</div>
@@ -703,17 +733,21 @@ function scrollDown()
}
function initializeTabs () {
key = "activeMaintenanceTab"
// Activate panel
if(!emptyArr.includes(getCache("activeMaintenanceTab")))
if(!emptyArr.includes(getCache(key)))
{
selectedTab = getCache("activeMaintenanceTab");
selectedTab = getCache(key);
}
$('.nav-tabs a[id='+ selectedTab +']').tab('show');
// When changed save new current tab
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
setCache("activeMaintenanceTab", $(e.target).attr('id'))
setCache(key, $(e.target).attr('id'))
});
// events on tab change
@@ -741,6 +775,8 @@ window.onload = function asyncFooter()
{
scrollDown();
initializeTabs();
$("#lastCommit").append('<a href="https://github.com/jokob-sk/Pi.Alert/commits" target="_blank"><img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github"></a>');
$("#lastDockerUpdate").append(

View File

@@ -273,7 +273,7 @@ function saveSettings()
displayMessage("<br/>Settings saved to the <code>".$config_file."</code> file.
<br/><br/>Backup of the previous ".$config_file." created here: <br/><br/><code>".$new_name."</code><br/><br/>
<b>Note:</b> Wait <b>5s</b> for the changes to reflect in the UI.",
<b>Note:</b> Wait at least <b>5s</b> for the changes to reflect in the UI. (longer if for example a <a href='#state'>Scan is running</a>)",
FALSE, TRUE, TRUE, TRUE);
}

View File

@@ -552,17 +552,18 @@ the arp-scan will take hours to complete instead of seconds.
'PHOLUS_ACTIVE_name' => 'Enable Pholus scan',
'PHOLUS_ACTIVE_description' => '<a href="https://github.com/jokob-sk/Pi.Alert/tree/main/pholus" target="_blank" >Pholus</a> is a sniffing tool to discover additional information about the devices on the network, including the device name. Please be aware it can spam the network with unnecessary traffic. Depends on the <a href="#SCAN_SUBNETS"><code>SCAN_SUBNETS</code> setting</a>.',
'PHOLUS_TIMEOUT_name' => 'Pholus timeout',
'PHOLUS_TIMEOUT_description' => 'How long (s) should Pholus be sniffing the network. Only used if an <code>(unknown)</code> device is found. The longer you leave it on, the more likely devices would broadcast more info. This timeout adds to the time it takes to perform an arp-scan on your network',
'PHOLUS_TIMEOUT_description' => 'How long in seconds should Pholus be sniffing on each interface. Only used if an <code>(unknown)</code> device is found. The longer you leave it on, the more likely devices would broadcast more info. This timeout adds to the time it takes to perform an arp-scan on your network.',
'PHOLUS_FORCE_name' => 'Force scan',
'PHOLUS_FORCE_description' => 'Force scan every network scan, even if there are no <code>(unknown)</code> devices. Be careful enabling this as the sniffing can easily flood your network.',
'PHOLUS_DAYS_DATA_name' => 'Data retention',
'PHOLUS_DAYS_DATA_description' => 'How many days of Pholus scan entries should be kept (gloablly, not device specific!). The <a href="/maintenance.php#tab_Logging">pialert_pholus.log</a> file is not touched.',
'PHOLUS_RUN_name' => 'Run on schedule',
'PHOLUS_RUN_description' => 'Enable a regular Pholus scan / sniff on your network.',
'PHOLUS_DAYS_DATA_description' => 'How many days of Pholus scan entries should be kept (globally, not device specific!). The <a href="/maintenance.php#tab_Logging_id">pialert_pholus.log</a> file is not touched.',
'PHOLUS_RUN_name' => 'Scheduled scan',
'PHOLUS_RUN_description' => 'Enable a regular Pholus scan / sniff on your network. The scheduling settings can be found below.',
'PHOLUS_RUN_TIMEOUT_name' => 'Scheduled run timeout',
'PHOLUS_RUN_TIMEOUT_description' => 'The timeout (s) for the scheduled Pholus scan.',
'PHOLUS_RUN_TIMEOUT_description' => 'The timeout in seconds for the scheduled Pholus scan. Same notes regarding the duration apply as on the <a href="#PHOLUS_TIMEOUT"><code>PHOLUS_TIMEOUT</code> setting</a>. A scheduled scan doesn\'t check if there are <code>(unknown)</code> devices, the scan is executed either way.',
'PHOLUS_RUN_SCHD_name' => 'Schedule',
'PHOLUS_RUN_SCHD_description' => 'Schedule in cron format. Make sure you enter the schedule in the correct format (e.g. validate your format on <a href="#" onlick="window.open("https://crontab.guru/#" + $(\'#PHOLUS_RUN_SCHD\').val(),replace(\' \', \'_\') , "_blank")" target="_blank">crontab.guru</a>). Will be run NEXT time the time passes.',
'PHOLUS_RUN_SCHD_description' => 'Schedule in cron format. Make sure you enter the schedule in the correct format
(e.g. validate at <a href="https://crontab.guru/" target="_blank">crontab.guru</a>). Will be run NEXT time the time passes. For example <code>0 4 * * *</code> will run the scan after 4 am in the <a href="#TIMEZONE"><code>TIMEZONE</code> you set above</a>.',
);

View File

@@ -4,13 +4,15 @@
// ## Languages
// ###################################
$defaultLang = "en_us";
if(!isset($_COOKIE["language"])) {
$pia_lang_selected = "en_us";
$pia_lang_selected = $defaultLang;
} else {
$pia_lang_selected = $_COOKIE["language"];
}
if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = 'en_us';}
if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = defaultLang;}
require 'en_us.php';
require 'de_de.php';
@@ -18,25 +20,27 @@ require 'es_es.php';
function lang($key)
{
global $pia_lang_selected, $lang ;
global $pia_lang_selected, $lang, $defaultLang;
// try to get the selected language translation
// check if key exists in selected language
if(array_key_exists($key, $lang[$pia_lang_selected]) == FALSE)
{
// check if key exists in the default language if not available in the selected
if (array_key_exists($key, $lang[$defaultLang]) == TRUE)
{
// if found, use default language
$temp = $lang[$defaultLang][$key];
} else
{
// String not found in the default or selected language
$temp = "String not found for key: ".$key;
}
} else
{
// use selected language translation
$temp = $lang[$pia_lang_selected][$key];
if(isset($temp) == FALSE)
{
// if not found, use English
$temp = $lang[$pia_lang_selected]["en_us"];
// echo $temp;
if(isset($temp) == FALSE)
{
// if not found, in English, use placeholder
$temp = "String not found";
}
}
// echo $temp;
return $temp;
}

View File

@@ -9,18 +9,45 @@ import logging
import itertools
import codecs
import ipaddress
import os
import sys
from scapy.utils import PcapWriter
sys.setrecursionlimit(30000)
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)#supress Scapy warnings`
runPath = os.path.dirname(os.path.abspath(__file__))
runPathTmp = runPath + "/.."
logPath = runPathTmp + '/front/log'
#===============================================================================
# UTIL
#===============================================================================
def write_file (pPath, pText):
# Write the text depending using the correct python version
if sys.version_info < (3, 0):
file = io.open (pPath , mode='w', encoding='utf-8')
file.write ( pText.decode('unicode_escape') )
file.close()
else:
file = open (pPath, 'w', encoding='utf-8')
file.write (pText)
file.close()
def file_print(*args):
result = ''
file = open(logPath + "/pialert_pholus_subp.log", "a")
for arg in args:
result += str(arg)
print(result)
file.write(result + '\n')
file.close()
def sanitize_string(input):
if isinstance(input, bytes):
@@ -70,7 +97,7 @@ def get_my_ipv6_addr(interface):
myip=ifaces[0]
return myip
except:
print("The interface",interface,"does not exist. Please, try again.")
file_print("The interface",interface,"does not exist. Please, try again.")
exit(0)
######################################
@@ -82,7 +109,7 @@ def get_my_ipv4_addr(interface):
myip=scapy.arch.get_if_addr(interface)
return myip
except:
print("The interface",interface,"does not exist. Please, try again.")
file_print("The interface",interface,"does not exist. Please, try again.")
exit(0)
##########################
@@ -271,7 +298,7 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
srv_rrname=data+label_data
txt_record=""
rdata=['txtvers=1','qtotal=1','pdl=application/vnd.hp-PCL','ty=MyOfficejet100000','product=(Trexa gureue)','priority=0','adminur=http://'+source_IPv4]
#print(type(rdata))
#file_print(type(rdata))
for r in rdata:
length=hex(len(r))[2:]
#check http://code.activestate.com/recipes/576617-converting-arbitrary-size-python-integers-to-packe/
@@ -417,7 +444,7 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
qname=dnsqr.qname
if qname.endswith('.'):
qname=qname[:-1]
#print("Query Name = ",qname," Type=",dnsqr.qtype)
#file_print("Query Name = ",qname," Type=",dnsqr.qtype)
if unidns:
dns_packet=UDP(sport=5353,dport=5353)/DNS(qr=1,aa=1,rd=0,ancount=1)/DNSRR(rrname=qname,ttl=myttl,rdata=source_IPv4,type="A")
else:
@@ -432,13 +459,13 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
elif dnsqr.qclass==255:
res = res0 + " | Question | "+dnsqr.qname.decode("utf-8") + " "+ dns_type[dnsqr.qtype] + " QM Class:ANY"
else:
print("DNSQR:")
print("-----")
print(dnsqr.show())
print("DEBUGGING IS NEEDED")
file_print("DNSQR:")
file_print("-----")
file_print(dnsqr.show())
file_print("DEBUGGING IS NEEDED")
exit(0)
if print_res==1:
print(res)
file_print(res)
queue.put(res)
block = block.payload
if dns.arcount>0:
@@ -466,7 +493,7 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
optcode=str(edns0tlv.optcode)
res = res + " EDNS0TLV: " + optcode + " " + codecs.encode(edns0tlv.optdata, 'hex_codec').decode("utf-8")
if print_res==1:
print(res)
file_print(res)
queue.put(res)
block = block.payload
elif block.haslayer(DNSRR):
@@ -496,10 +523,10 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
res = str_res0 + " | Question | " + str_qname + " " + str_qtype + " QM Class:ANY"
else:
print("DNSRR:")
print("-----")
print(dnsrr.show())
print("DEBUGGING IS NEEDED HERE")
file_print("DNSRR:")
file_print("-----")
file_print(dnsrr.show())
file_print("DEBUGGING IS NEEDED HERE")
exit(0)
if dnsrr.type==33:#SRV Record
@@ -531,7 +558,7 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
if show_ttl:
res = res + " TTL:"+str(dnsrr.ttl)
if print_res==1:
print(res)
file_print(res)
queue.put(res)
block = block.payload
if dns.ancount>0:
@@ -562,7 +589,7 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
if show_ttl:
res = res + " TTL:"+str(dnsrr.ttl)
if print_res==1:
print(res)
file_print(res)
queue.put(res)
block = block.payload
if dns.nscount>0:
@@ -579,18 +606,18 @@ def ext_handler(packets,queue,unidns,show_ttl,print_res,dos_ttl,conflict,ttl,int
if show_ttl:
res = res + " TTL:"+str(dnsrr.ttl)
if print_res==1:
print(res)
file_print(res)
queue.put(res)
block = block.payload
else:
print("not a DNS Query", dns.summary())
file_print("not a DNS Query", dns.summary())
########################################
########### REQUEST FUNCTION ###########
########################################
def requests(interface,v4,v6,source_mac,target_mac1,target_mac2,source_IPv4,source_IPv6,d4,d6,hlimit,unidns,domain,query,types_of_queries,add_domain,query_class,flood,flooding_interval,flooding_timeout):
if add_domain:
print("Sending mdns requests")
file_print("Sending mdns requests")
domain_list = domain.split(",")
query_list = query.split(",")
if add_domain:
@@ -630,7 +657,7 @@ def send_packets(v4,v6,source_mac,target_mac1,target_mac2,source_IPv4,dst_ipv4,s
packets.append(pkt1)
if flood:
counter=0.0
print("Stop flooding after ",flooding_timeout," sec.")
file_print("Stop flooding after ",flooding_timeout," sec.")
while(counter<float(flooding_timeout)):
for packt in packets:
sendp(pakt,iface=interface)
@@ -643,7 +670,7 @@ def send_packets(v4,v6,source_mac,target_mac1,target_mac2,source_IPv4,dst_ipv4,s
pkt1=Ether(src=source_mac,dst=target_mac1)/packet
if flood:
counter=0.0
print("Stop flooding after ",flooding_timeout," sec.")
file_print("Stop flooding after ",flooding_timeout," sec.")
while(counter<float(flooding_timeout)):
sendp(pkt1,iface=interface)
counter+=float(flooding_interval)
@@ -660,7 +687,7 @@ def send_packets(v4,v6,source_mac,target_mac1,target_mac2,source_IPv4,dst_ipv4,s
packets.append(pkt2)
if flood:
counter=0.0
print("Stop flooding after ",flooding_timeout," sec.")
file_print("Stop flooding after ",flooding_timeout," sec.")
while(counter<float(flooding_timeout)):
for packt in packets:
sendp(pakt,iface=interface)
@@ -673,7 +700,7 @@ def send_packets(v4,v6,source_mac,target_mac1,target_mac2,source_IPv4,dst_ipv4,s
pkt2=Ether(src=source_mac,dst=target_mac2)/packet
if flood:
counter=0.0
print("Stop flooding after ",flooding_timeout," sec.")
file_print("Stop flooding after ",flooding_timeout," sec.")
while(counter<float(flooding_timeout)):
sendp(pkt2,iface=interface)
counter+=float(flooding_interval)
@@ -748,14 +775,14 @@ def main():
values = parser.parse_args()
if values.rpcap:
print("Read packets from a pcap file")
file_print("Read packets from a pcap file")
if not os.path.isfile(values.interface):
print('[-] ' + values.interface + ' does not exist')
file_print('[-] ' + values.interface + ' does not exist')
exit(0)
elif not os.access(values.interface, os.R_OK):
print('[-] ' + values.interface + ' access is denied')
file_print('[-] ' + values.interface + ' access is denied')
exit(0)
print("Press Ctrl-C to exit and print the results")
file_print("Press Ctrl-C to exit and print the results")
q = multiprocessing.Queue()
pr = multiprocessing.Process(target=Sniffer_Offline, args=(values.interface,q,values.show_ttl,values.d4, values.d6, values.target_mac, values.auto_fake_responses,values.source6,values.source4,values.target_mac,values.target_mac,values.source_mac,values.hlimit))
pr.start()
@@ -766,14 +793,14 @@ def main():
myset=set(results)
results=list(myset)
results.sort()
print("\n*********************************************RESULTS*********************************************")
file_print("\n*********************************************RESULTS*********************************************")
for r in results:
print(r)
file_print(r)
exit(0)
else:
#####################################LETS DO SOME CHECKS FIRST TO SEE IF WE CAN WORK####################
if os.geteuid() != 0:
print("You must be root to run this script.")
file_print("You must be root to run this script.")
exit(1)
conf.verb=0
#########################################DEFINE SOURCE ADDRESSES########################################
@@ -786,7 +813,7 @@ def main():
try:
source_mac=get_if_hwaddr(values.interface)
except:
print("interface ",values.interface," does not exist")
file_print("interface ",values.interface," does not exist")
exit(0)
if values.qu:
@@ -804,7 +831,7 @@ def main():
source_IPv4=get_my_ipv4_addr(values.interface)
else:
source_IPv4=values.source4
print("source MAC address:",source_mac,"source IPv4 Address:",source_IPv4,"source IPv6 address:",source_IPv6)
file_print("source MAC address:",source_mac,"source IPv4 Address:",source_IPv4,"source IPv6 address:",source_IPv6)
#########################################################################################################
if values.target_mac:
target_mac1=values.target_mac
@@ -816,33 +843,33 @@ def main():
q = multiprocessing.Queue()
if values.dos_ttl or values.auto_fake_responses:
if values.auto_fake_responses:
print("Send fake responses to requests" )
file_print("Send fake responses to requests" )
if values.target_mac:
myfilter = "not ether src " + source_mac + " and not ether dst " + values.target_mac +" and udp and port 5353"
else:
myfilter = "not ether src " + source_mac + " and udp and port 5353"
elif values.target_mac:
print("Performing implicit DoS by sending automated spoofed DNS Answers with TTL=0" )
file_print("Performing implicit DoS by sending automated spoofed DNS Answers with TTL=0" )
myfilter = "not ether dst " + values.target_mac + " and udp and port 5353"
else:
print("Performing implicit DoS by sending automated spoofed DNS Answers with TTL=0" )
file_print("Performing implicit DoS by sending automated spoofed DNS Answers with TTL=0" )
myfilter = "udp and port 5353"
print("Sniffer filter is:",myfilter)
print("I will sniff for",values.sniffer_timeout,"seconds, unless interrupted by Ctrl-C")
print("Press Ctrl-C to exit")
file_print("Sniffer filter is:",myfilter)
file_print("I will sniff for",values.sniffer_timeout,"seconds, unless interrupted by Ctrl-C")
file_print("Press Ctrl-C to exit")
try:
Sniffer(myfilter, values.interface, float(values.sniffer_timeout),q,values.dns,values.show_ttl, values.dos_ttl, values.conflict, values.ttl,values.d4, values.d6, values.target_mac, values.auto_fake_responses,source_IPv6, source_IPv4, target_mac1, target_mac2,source_mac,values.hlimit,values.workstation,values.printer,values.googlecast,values.airtv,values.flood,values.flooding_timeout,values.flooding_interval,values.v4,values.v6)
except KeyboardInterrupt:
print("Exiting on user's request")
file_print("Exiting on user's request")
exit(0)
exit(0)
myfilter = "not ether src " + source_mac + " and udp and port 5353"
print("Sniffer filter is:",myfilter)
print("I will sniff for",values.sniffer_timeout,"seconds, unless interrupted by Ctrl-C")
file_print("Sniffer filter is:",myfilter)
file_print("I will sniff for",values.sniffer_timeout,"seconds, unless interrupted by Ctrl-C")
pr = multiprocessing.Process(target=Sniffer, args=(myfilter, values.interface, float(values.sniffer_timeout),q,values.dns,values.show_ttl, values.dos_ttl, values.conflict, values.ttl,values.d4,values.d6, values.target_mac, values.auto_fake_responses,source_IPv6, source_IPv4, target_mac1, target_mac2, source_mac,values.hlimit,values.workstation,values.printer,values.googlecast,values.airtv,values.flood,values.flooding_timeout,values.flooding_interval,values.v4,values.v6))
pr.daemon = True
pr.start()
print("------------------------------------------------------------------------")
file_print("------------------------------------------------------------------------")
time.sleep(1)#to make sure than sniffer has started before we proceed, otherwise you may miss some traffic
##########################################################################################################
if values.request:
@@ -961,7 +988,7 @@ def main():
try:
pr.join()
except KeyboardInterrupt:
print("Exiting on user's request")
file_print("Exiting on user's request")
exit(0)
#### AFTER EXITING, PRINT THE RESULTS ####
@@ -989,7 +1016,7 @@ def main():
try:
pr2.join()
except KeyboardInterrupt:
print("Exiting on user's request")
file_print("Exiting on user's request")
while not q2.empty():
results.append(q2.get())
elif values.service_scan:
@@ -1003,14 +1030,14 @@ def main():
r2=r.split(" ")
service=r2[7].strip('"')[:-1]
if (r2[1],service) not in targets:
print((r2[1],service))
file_print((r2[1],service))
targets.append((r2[1],service))
requests(values.interface,values.v4,values.v6,source_mac,target_mac1,target_mac2,source_IPv4,source_IPv6,values.d4,values.d6,values.hlimit,values.dns,values.domain,service,values.qtype,True,q_class,values.flood,values.flooding_interval,values.flooding_timeout)
if pr2:
try:
pr2.join()
except KeyboardInterrupt:
print("Exiting on user's request")
file_print("Exiting on user's request")
while not q2.empty():
results.append(q2.get())
targets2=[]
@@ -1033,12 +1060,12 @@ def main():
try:
pr3.join()
except KeyboardInterrupt:
print("Exiting on user's request")
file_print("Exiting on user's request")
while not q3.empty():
results.append(q3.get())
print("\n*********************************************RESULTS*********************************************")
file_print("\n*********************************************RESULTS*********************************************")
for r in results:
print(r)
file_print(r)
if __name__ == '__main__':
main()