The unified diff between revisions [29881737..] and [535bb2a6..] is displayed below. It can also be downloaded as a raw diff.
#
#
# add_file "plugins/dns.py"
# content [aeb8e0322332d089d16240f709804a3f32cf885f]
#
# patch "plugins/postgresql.py"
# from [31cd15378c86802c279a8a976097103ef22c8387]
# to [f95cb509ba729d6e611c2dc8d53a82321181e1a5]
#
# patch "scan.py"
# from [1d78a0f945e08738983363d8d23348a6250c316e]
# to [4eb1704670d1258628116573a32af771b9d58278]
#
# patch "sql/drop.sql"
# from [bd691296b9667eda345c7af55b6fe2aa8faec42c]
# to [a2b6d0832f32061e54acd2f450fc2510c00220a1]
#
# patch "sql/init.sql"
# from [14a69e794604ec9b377aeb9ae9dc11a70e1d6565]
# to [25b962a1cc0f9df2d96a6245ed63b969c460cc93]
#
============================================================
--- plugins/dns.py aeb8e0322332d089d16240f709804a3f32cf885f
+++ plugins/dns.py aeb8e0322332d089d16240f709804a3f32cf885f
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+
+import socket
+from ftplib import FTP
+import scan
+
+# requires the python-dns package
+import DNS
+
+export = {
+ "name" : "dns",
+ "version" : "0.1",
+ "description" : "Look for open DNS servers",
+ "type" : "scanner",
+ "tcp_ports" : [53],
+ "udp_ports" : [53]
+}
+
+sites = [(scan.urgency_warning, 'www.google.com'), (scan.urgency_info, 'www.uwa.edu.au')]
+
+def host_callback(library, host, tcp_ports, udp_ports):
+ rv = []
+
+ ip_addresses = filter(lambda x: x[1] == "ipv4", host.addresses)
+ if len(ip_addresses) == 0: return rv
+ address, protocol = ip_addresses[0]
+
+ DNS.Base.defaults['server'] = [address]
+
+ for urgency, site in sites:
+ r = DNS.DnsRequest(name=site, qtype='A')
+ a = r.req()
+ if len(a.answers) > 0:
+ response = scan.ScannerResponse()
+ response.plugin_name = export['name']
+ response.address = (address, protocol)
+ response.urgency = urgency
+ response.short_mesg = "Server answers for: " + site
+ response.long_mesg = '%d results' % len(a.answers)
+ rv.append(response)
+
+ return rv
+
============================================================
--- plugins/postgresql.py 31cd15378c86802c279a8a976097103ef22c8387
+++ plugins/postgresql.py f95cb509ba729d6e611c2dc8d53a82321181e1a5
@@ -24,9 +24,8 @@ def initialise(library):
def initialise(library):
global cnx
cnx = libpq.PQconnectdb(library.config.connect_str)
- cnx.query("DELETE FROM proktos_urgency")
- for urgency in library.urgency_to_string:
- cnx.query("INSERT INTO proktos_urgency (urgency,description) VALUES (%d,%s)" % (urgency, q(library.urgency_to_string[urgency])))
+ if hasattr(library.config, "init_sql_command"):
+ cnx.query(library.config.init_sql_command)
def finalise(library):
return
============================================================
--- scan.py 1d78a0f945e08738983363d8d23348a6250c316e
+++ scan.py 4eb1704670d1258628116573a32af771b9d58278
@@ -2,7 +2,6 @@ from goatpy.gen2consume import gen2consu
from goatpy.nmapwrapper import nmap
from goatpy.gen2consume import gen2consume
-import getopt
import ConfigParser
import threading
@@ -16,28 +15,6 @@ import config
import config
-class TextNotify:
- def start_scan(self):
- print "Starting scan."
- def complete_scan(self):
- print "Scan complete."
- def start_host(self, thread_id, host):
- print "[%2d] starting to scan: %-15s (T:%s U:%s)" % (thread_id, host.addresses[0][0], str(host.tcp_ports), str(host.udp_ports))
- def complete_host(self, thread_id, host):
- print "[%2d] %-15s: done with this host" % (thread_id, host.addresses[0][0])
- def start_plugin(self, thread_id, plugin, host):
- print "[%2d] %-15s: run plugin %s" % (thread_id, host.addresses[0][0], plugin.export['name'])
- def complete_plugin(self, thread_id, host):
- pass
- def start_writing_results(self, thread_id, host):
- pass
- def complete_writing_results(self, thread_id, host):
- pass
- def notice(self, str):
- print "%s" % (str)
-
-notification = None
-
# urgency
urgency_info = 0
urgency_notice = 1
@@ -67,18 +44,17 @@ def scan_host(mythread, host, library):
if config.magic_udp_port in host.udp_ports:
host.udp_ports = []
plugins = library.plugins_for_ports(host.tcp_ports, host.udp_ports)
- notification.start_host(mythread.id, host)
+ library.notify("[%2d] %-15s: has been assigned (T:%s U:%s)" % (mythread.id, host.addresses[0][0], str(host.tcp_ports), str(host.udp_ports)))
errors = []
results = []
for plugin in plugins:
tcp_ports = filter(lambda x: x in plugins[plugin][0], host.tcp_ports)
udp_ports = filter(lambda x: x in plugins[plugin][1], host.udp_ports)
try:
- notification.start_plugin(mythread.id, plugin, host)
+ library.notify("[%2d] %-15s: run plugin %s" % (mythread.id, host.addresses[0][0], plugin.export['name']))
mythread.status_string = "in plugin %s" % (plugin.export['name'])
result = plugin.host_callback(library, host, tcp_ports, udp_ports)
mythread.status_string = "completed plugin %s" % (plugin.export['name'])
- notification.complete_plugin(mythread.id, host)
results += result
except:
import traceback
@@ -86,13 +62,11 @@ def scan_host(mythread, host, library):
err_data = '\n'.join(traceback.format_exception(t, v, tr))
errors.append((plugin.export['name'], err_data))
mythread.status_string = "writing results"
- notification.start_writing_results(mythread.id, host)
for plugin in library.output_plugins:
plugin.write_results(library, host, library.scanner_names, results)
plugin.write_errors(library, host, errors)
- notification.complete_writing_results(mythread.id, host)
mythread.status_string = None
- notification.complete_host(mythread.id, host)
+ library.notify("[%2d] %-15s: done with this host" % (mythread.id, host.addresses[0][0]))
# clean up memory explicitly, as otherwise Python might not garbage collect
# quickly enough for us.
del results
@@ -114,7 +88,7 @@ class WaitThread(threading.Thread):
while 1:
try:
procs = os.wait()
- notification.notice("Processes have terminated: %s" % (str(procs)))
+ print "Processes have terminated:", procs
except: pass
# for some reason, sometimes this fails unless
# this check is here. A bit mysterious.
@@ -143,6 +117,8 @@ class PluginLibrary:
if orig_path: sys.path = orig_path
def finalise_plugins(self):
map(lambda x: x.finalise(self), self.output_plugins)
+ def notify(self, str):
+ print "%s" % (str)
def link_ports(self, mod, port_list, hash):
if not port_list: return
for port in port_list:
@@ -152,6 +128,7 @@ class PluginLibrary:
return self.tcp_to_plugin.keys(), self.udp_to_plugin.keys()
def do_load_plugin(self, plugin_name):
mod = __import__('%s' % plugin_name, globals(), locals(), [''])
+# self.notify("Plugin loaded: " + mod.export['name'] + " version " + mod.export['version'] + " (" + mod.export['type'] + ")")
return mod
def plugins_for_ports(self, tcp_ports, udp_ports):
rv = {}
@@ -189,6 +166,8 @@ class Scanner:
self._config_path = config_path
self.config = config
self.library = PluginLibrary(self.config)
+ def notify(self, str):
+ print "%s" % (str)
def scan(self):
nmap_command = self.config.nmap_command + ' ' + self.config.nmap_options
ports = []
@@ -198,14 +177,13 @@ class Scanner:
udp_ports.append(config.magic_udp_port)
ports.append("U:" + ','.join([str(t) for t in udp_ports]))
if not len(ports):
- notification.notice("Nothing to do; no ports requested by plugins.")
+ self.notify("Nothing to do; no ports requested by plugins.")
return
nmap_command += ' -p ' + ','.join(ports)
nmap_command += ' -oX -'
range = ' '.join(self.config.scan_networks)
nmap_command += ' ' + range
- notification.start_scan()
- notification.notice("Scanner command is: %s" % (nmap_command))
+ self.notify("Starting scan: %s" % (nmap_command))
gt = gen2consume(nmap(nmap_command), self.config.max_threads, lambda thread, host: scan_host(thread, host, self.library))
gt.join()
countdown = self.config.thread_wait_time
@@ -214,29 +192,18 @@ class Scanner:
has_status = filter(lambda x: "status_string" in dir(x) and x.status_string != None, running)
cnt = len(running)
reasons = map(lambda x: x.status_string, has_status)
- notification.notice("[%2d secs] Waiting for %d threads (%s)" % (countdown, cnt, ','.join(reasons)))
+ print "[%2d secs] Waiting for %d threads (%s)" % (countdown, cnt, ','.join(reasons))
if cnt == 2: break
countdown -= 1
time.sleep(1)
- notification.notice("Finalising output plugins.")
+ print "Finalising output plugins."
self.library.finalise_plugins()
- notification.notice("Done!")
- notification.complete_scan()
+ print "Done!"
if __name__ == '__main__':
wt = WaitThread()
wt.start()
- matched, remain = getopt.getopt(sys.argv[1:], "c:x")
- output_mode = "text"
- config_file = 'scanner.cfg'
- for opt, value in matched:
- if opt == '-c': config_file = value
- elif opt == '-g': output_mode = "graphical"
- if output_mode == "graphical":
- notification = GraphicalNotify()
- else:
- notification = TextNotify()
- scanner = Scanner(config_file)
+ scanner = Scanner('scanner.cfg')
scanner.scan()
sys.exit(0)
============================================================
--- sql/drop.sql bd691296b9667eda345c7af55b6fe2aa8faec42c
+++ sql/drop.sql a2b6d0832f32061e54acd2f450fc2510c00220a1
@@ -1,5 +1,4 @@
-DROP TABLE results;
+DROP TABLE proktos_results;
+DROP TABLE proktos_urgency;
-DROP TABLE urgency;
-
============================================================
--- sql/init.sql 14a69e794604ec9b377aeb9ae9dc11a70e1d6565
+++ sql/init.sql 25b962a1cc0f9df2d96a6245ed63b969c460cc93
@@ -1,4 +1,4 @@
-CREATE TABLE results (
+CREATE TABLE proktos_results (
updated timestamp without time zone,
address inet,
plugin_name varchar(256),
@@ -10,7 +10,7 @@ CREATE TABLE results (
advice text
);
-CREATE TABLE urgency (
+CREATE TABLE proktos_urgency (
urgency integer,
description varchar(256)
);