bunch of testing stuff

This commit is contained in:
bile0026 2020-11-10 07:45:20 -06:00
parent 9bca20b010
commit 8a842d3c5f
7 changed files with 46 additions and 598 deletions

View File

@ -5,8 +5,8 @@ from pynetbox import api
class NetBoxScanner(object):
def __init__(self, address, token, tls_verify, tag, cleanup):
self.netbox = api(address, token, ssl_verify=tls_verify)
def __init__(self, address, token, tag, cleanup):
self.netbox = api(address, token)
self.tag = tag
self.cleanup = cleanup
self.stats = {
@ -36,7 +36,8 @@ class NetBoxScanner(object):
aux = nbhost.description
nbhost.description = host[1]
nbhost.save()
logging.info(f'updated: {host[0]}/32 "{aux}" -> "{host[1]}"')
logging.info(
f'updated: {host[0]}/32 "{aux}" -> "{host[1]}"')
self.stats['updated'] += 1
else:
logging.info(f'unchanged: {host[0]}/32 "{host[1]}"')

View File

@ -28,4 +28,3 @@ class Nmap(object):
host.find('address').attrib['addr'],
self.unknown
))

View File

@ -1,29 +1,26 @@
[NETBOX]
address = https://netbox.domain
token =
tls_verify = no
logs = .
address = <server>
token = <key>
logs = logs/
[NMAP]
path = samples/nmap
path = ./
unknown = autodiscovered:netbox-scanner
tag = nmap
cleanup = yes
[NETXMS]
address = https://netxms.domain
username =
password =
tls_verify = no
unknown = autodiscovered:netbox-scanner
tag = netxms
cleanup = yes
# [NETXMS]
# address = https://netxms.domain
# username =
# password =
# unknown = autodiscovered:netbox-scanner
# tag = netxms
# cleanup = yes
[PRIME]
address = https://prime.domain/webacs/api/v4
username =
password =
tls_verify = no
unknown = autodiscovered:netbox-scanner
tag = prime
cleanup = yes
# [PRIME]
# address = https://prime.domain/webacs/api/v4
# username =
# password =
# unknown = autodiscovered:netbox-scanner
# tag = prime
# cleanup = yes

View File

@ -28,15 +28,15 @@ else:
netbox = config['NETBOX']
nmap = config['NMAP']
netxms = config['NETXMS']
prime = config['PRIME']
#netxms = config['NETXMS']
#prime = config['PRIME']
parser = ArgumentParser(description='netbox-scanner')
subparsers = parser.add_subparsers(title='Commands', dest='command')
subparsers.required = True
argsp = subparsers.add_parser('nmap', help='Nmap module')
argsp = subparsers.add_parser('netxms', help='NetXMS module')
argsp = subparsers.add_parser('prime', help='Cisco Prime module')
#argsp = subparsers.add_parser('netxms', help='NetXMS module')
#argsp = subparsers.add_parser('prime', help='Cisco Prime module')
args = parser.parse_args()
logfile = '{}/netbox-scanner-{}.log'.format(
@ -58,6 +58,7 @@ def cmd_nmap(s): # nmap handler
h.run()
s.sync(h.hosts)
def cmd_netxms(s): # netxms handler
h = NetXMS(
netxms['address'],
@ -69,6 +70,7 @@ def cmd_netxms(s): # netxms handler
h.run()
s.sync(h.hosts)
def cmd_prime(s): # prime handler
h = Prime(
prime['address'],
@ -85,7 +87,6 @@ if __name__ == '__main__':
scanner = NetBoxScanner(
netbox['address'],
netbox['token'],
netbox.getboolean('tls_verify'),
nmap['tag'],
nmap.getboolean('cleanup')
)

View File

@ -1,72 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet href="file:///usr/local/bin/../share/nmap/nmap.xsl" type="text/xsl"?>
<!-- Nmap 5.59BETA3 scan initiated Fri Sep 9 18:33:41 2011 as:
nmap -T4 -A -p 1-1000 -oX - scanme.nmap.org -->
<nmaprun scanner="nmap" args="nmap -T4 -A -p 1-1000 -oX - scanme.nmap.org" start="1315618421"
startstr="Fri Sep 9 18:33:41 2011" version="5.59BETA3" xmloutputversion="1.03">
<scaninfo type="syn" protocol="tcp" numservices="1000" services="1-1000"/>
<verbose level="0"/>
<debugging level="0"/>
<host starttime="1315618421" endtime="1315618434">
<status state="up" reason="echo-reply"/>
<address addr="74.207.244.221" addrtype="ipv4"/>
<hostnames>
<hostname name="scanme.nmap.org" type="user"/>
<hostname name="li86-221.members.linode.com" type="PTR"/>
</hostnames>
<ports>
<extraports state="closed" count="997">
<extrareasons reason="resets" count="997"/>
</extraports>
<port protocol="tcp" portid="22">
<state state="open" reason="syn-ack" reason_ttl="53"/>
<service name="ssh" product="OpenSSH" version="5.3p1 Debian 3ubuntu7"
extrainfo="protocol 2.0" ostype="Linux" method="probed" conf="10">
<cpe>cpe:/a:openbsd:openssh:5.3p1</cpe>
<cpe>cpe:/o:linux:kernel</cpe>
</service>
<script id="ssh-hostkey"
output="1024 8d:60:f1:7c:ca:b7:3d:0a:d6:67:54:9d:69:d9:b9:dd (DSA)&#xa;
2048 79:f8:09:ac:d4:e2:32:42:10:49:d3:bd:20:82:85:ec (RSA)"/>
</port>
<port protocol="tcp" portid="80">
<state state="open" reason="syn-ack" reason_ttl="53"/>
<service name="http" product="Apache httpd" version="2.2.14"
extrainfo="(Ubuntu)" method="probed" conf="10">
<cpe>cpe:/a:apache:http_server:2.2.14</cpe>
</service>
<script id="http-title" output="Go ahead and ScanMe!"/>
</port>
</ports>
<os>
<portused state="open" proto="tcp" portid="22"/>
<portused state="closed" proto="tcp" portid="1"/>
<portused state="closed" proto="udp" portid="31289"/>
<osclass type="general purpose" vendor="Linux" osfamily="Linux"
osgen="2.6.X" accuracy="100">
<cpe>cpe:/o:linux:linux_kernel:2.6.39</cpe>
</osclass>
<osmatch name="Linux 2.6.39" accuracy="100" line="39278"/>
</os>
<uptime seconds="23450" lastboot="Fri Sep 9 12:03:04 2011"/>
<distance value="11"/>
<tcpsequence index="199" difficulty="Good luck!"
values="49018209,48C3EBED,495A2E7F,493EF30C,48ED43B3,495A9B0C"/>
<ipidsequence class="All zeros" values="0,0,0,0,0,0"/>
<tcptssequence class="1000HZ"
values="165CC09,165CC6E,165CCD2,165CD36,165CD9A,165CE48"/>
<trace port="256" proto="tcp">
<!-- Several hop elements removed for brevity -->
<hop ttl="9" ipaddr="72.52.92.109" rtt="15.69" host="10gigabitethernet1-1.core1.fmt1.he.net"/>
<hop ttl="10" ipaddr="64.62.250.6" rtt="12.06" host="linode-llc.10gigabitethernet2-3.core1.fmt1.he.net"/>
<hop ttl="11" ipaddr="74.207.244.221" rtt="16.55" host="li86-221.members.linode.com"/>
</trace>
<times srtt="26517" rttvar="19989" to="106473"/>
</host>
<runstats>
<finished time="1315618434" timestr="Fri Sep 9 18:33:54 2011" elapsed="13.66"
summary="Nmap done at Fri Sep 9 18:33:54 2011; 1 IP address (1 host up)
scanned in 13.66 seconds" exit="success"/>
<hosts up="1" down="0" total="1"/>
</runstats>
</nmaprun>

File diff suppressed because one or more lines are too long

10
samples/nmap-scan.sh Normal file → Executable file
View File

@ -16,13 +16,15 @@
# to look for XML files.
##
NETWORKS = "10.1.2.3/24 10.2.3.4/32 192.168.0.0/19"
NETWORKS="192.168.252.0/24 192.168.3.0/24"
TODAY="$(date +%d.%m.%yT%H:%M:%S%Z)"
for net in $NETWORKS; do
nmap -T4 -O -F --host-timeout 30s -oX nmap-"$net".xml
NETNAME=$(echo $net | tr -s '/' '-')
#nmap "$net" -T4 -O -F --host-timeout 30s -oX nmap-"$NETNAME".xml
nmap "$net" -T4 -sn --host-timeout 30s -oX nmap-"$NETNAME".xml
done
python ../netbox-scanner.py nmap
tar -czvf nmap-"$TODAY".tar.gz *.xml
python netbox-scanner.py nmap
tar -czvf scans/nmap-"$TODAY".tar.gz *.xml
rm -rf *.xml