本文整理汇总了Python中OssimDB.OssimDB类的典型用法代码示例。如果您正苦于以下问题:Python OssimDB类的具体用法?Python OssimDB怎么用?Python OssimDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OssimDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ControlPanel
class ControlPanel (threading.Thread) :
def __init__ (self) :
self.__conf = None # ossim configuration values (ossim.conf)
self.__conn = None # cursor to ossim database
self.__rrd_path = {} # path for global, net, host and level rrds
threading.Thread.__init__(self)
def __startup (self) :
# configuration values
self.__conf = OssimConf (Const.CONFIG_FILE)
# database connection
self.__conn = OssimDB()
self.__conn.connect ( self.__conf["ossim_host"],
self.__conf["ossim_base"],
self.__conf["ossim_user"],
self.__conf["ossim_pass"])
# rrd paths
if self.__conf["rrdtool_path"]:
Const.RRD_BIN = os.path.join(self.__conf["rrdtool_path"], "rrdtool")
try:
for dest in [ "global", "net", "host", "level" ] :
self.__rrd_path[dest] = \
os.path.join(self.__conf["mrtg_rrd_files_path"],
'%s_qualification' % (dest))
except OSError, e:
print >>sys.stderr, "Error reading RRD path: " + e
sys.exit()
示例2: _get_db_conf
def _get_db_conf(self):
# Now, complete config info from Ossim database
db = OssimDB(self[VAR_DB_HOST], self[VAR_DB_SCHEMA], self[VAR_DB_USER], self[VAR_DB_PASSWORD])
db.connect()
#Reads all the frameworkd configuration values.
query = "select * from config"
fmk_table_values = db.exec_query(query)
for row in fmk_table_values:
self._conf[row['conf']] = row['value']
query = ''
if not self._conf.has_key(VAR_KEY_FILE):
self._conf[VAR_KEY_FILE] = '/etc/ossim/framework/db_encryption_key'
keyfile = self._conf[VAR_KEY_FILE]
useEncryption = False
if os.path.isfile(keyfile):
config = ConfigParser.ConfigParser()
keyfile_fd= open(keyfile,'r')
try:
config.readfp(keyfile_fd)
self._conf[VAR_KEY] = config.get('key-value', 'key')
useEncryption = True
except Exception, e:
logger.error("Invalid key file: %s" % str(e))
finally:
示例3: NtopDiscovery
class NtopDiscovery(threading.Thread):
_interval = 100
def __init__(self):
self._tmp_conf = OssimConf (Const.CONFIG_FILE)
#Implement cache with timeout?????
self.inv = Inventory()
self.cache = []
threading.Thread.__init__(self)
def connectDB(self):
self.db = OssimDB()
self.db.connect (self._tmp_conf["ossim_host"],
self._tmp_conf["ossim_base"],
self._tmp_conf["ossim_user"],
self._tmp_conf["ossim_pass"])
def closeDB(self):
self.db.close()
def getDataFromSensor(self, ip, port):
logger.debug("Retrieving NTOP data from %s" % ip)
try:
f = urllib.urlopen("http://%s:%s/python/get.py" % (ip, port))
return f.read()
except IOError, msg:
#print msg
logger.error("Error retrieving NTOP information from %s - msg:%s" % (ip, msg))
return None
示例4: __init__
class SSHInventory:
_interval = 3600
def __init__(self):
self._tmp_conf = OssimConf(Const.CONFIG_FILE)
self.inv = Inventory()
# Implement cache with timeout?????
self.cache = []
# threading.Thread.__init__(self)
def connectDB(self):
self.db = OssimDB()
self.db.connect(
self._tmp_conf["ossim_host"],
self._tmp_conf["ossim_base"],
self._tmp_conf["ossim_user"],
self._tmp_conf["ossim_pass"],
)
def closeDB(self):
self.db.close()
def run(self):
while True:
self.process()
time.sleep(self._interval)
def process(self):
# Check host with local credentials
hosts = self.inv.getHostWithCredentials("SSH")
示例5: __init__
class Vulnerabilities :
def __init__ (self) :
self.__set_debug = True
self.__conf = OssimConf(Const.CONFIG_FILE)
self.__conn = OssimDB()
self.__conn.connect( self.__conf['ossim_host'],
self.__conf['ossim_base'],
self.__conf['ossim_user'],
self.__conf['ossim_pass'])
self.__id_pending = 65001
self.__id_false_positive = 65002
self.__default_incident_type = 'Nessus Vulnerability'
self.__nsr_fd = None
self.__scanner_type = None
self.__scan_time = None
self.__ticket_default_user = "admin"
self.__ticket_default_closed_description = "Automatic closed of the incident"
self.__ticket_default_open_description = "Automatic open of the incident"
def process(self, nsr_file, scan_date, scan_networks, scan_hosts) :
self.__debug("Generating Incidents for found vulnerabilities")
self.__scan_time = strftime('%Y-%m-%d %H:%M:%S')
self.__scanner_type = self.__scanner_type or \
self.__conf["scanner_type"] or \
"openvas2"
try:
self.__nsr_fd = open(nsr_file)
except Exception, e:
self.__debug("Unable to open file %s: %s" % (nsr_file,e))
return
self.__parse_vulns_file()
self.__debug("Automatic close of vulnerabilities")
self.__traverse_vulns_incidents(scan_date, scan_networks, scan_hosts)
self.__debug("Generating Incidents finished ok")
示例6: __init__
class ControlManager:
def __init__(self, conf):
logger.debug("Initialising ControlManager...")
self.control_agents = {}
self.transaction_map = {}
self.__myDB = OssimDB()
self.__myDB_connected = False
self.__myconf = conf
self.__transaction_timeout = 60
self.__ntop_apache_manager = ApacheNtopProxyManager(conf)
self.__control = DoControl(self)
self.__control.start()
self.__ntop_configuration_checked = False
self.__mutexRquest = Lock()
def refreshAgentCache(self, requestor, agent_id,agent_name):
if not self.__myDB_connected:
self.__myDB.connect (self.__myconf["ossim_host"],
self.__myconf["ossim_base"],
self.__myconf["ossim_user"],
self.__myconf["ossim_pass"])
self.__myDB_connected = True
#read host list
query = 'select hostname,ip,fqdns from host where ip in (select host_ip from host_sensor_reference where sensor_name="%s");' % agent_name
tmp = self.__myDB.exec_query(query)
new_command = 'action="refresh_asset_list" list={'
sendCommand = False
for host in tmp:
host_cmd = "%s=%s," % (host['ip'],host['hostname'])
if host['fqdns'] is not None and host['fqdns'] != '':
fqdns_list = host['fqdns'].split(',')
for name in fqdns_list:
host_cmd += "%s," % name
host_cmd = host_cmd[:-1]
host_cmd+=';'
sendCommand = True
new_command += host_cmd
new_command[:-1]
new_command += '}'
# add this connection to the transaction map
#transaction = self.__transaction_id_get()
#self.transaction_map[transaction] = {'socket':requestor, 'time':time.time()}
# append the transaction to the message for tracking
if sendCommand:
if self.control_agents.has_key(agent_id):
try:
self.control_agents[agent_id].wfile.write(new_command + ' transaction="NA"\n')
logger.info("Updating asset list to agent: %s " % (agent_id))
logger.debug("Cmd: %s" % new_command)
except socket.error,e:
logger.warning("it can't send messages to :%s" % agent_id)
else:
logger.warning("No agent :%s" % agent_id)
else:
示例7: __init__
def __init__(self, request):
self.__request = self.parseRequest(request)
self.__responses = {}
self.__conf = OssimConf(Const.CONFIG_FILE)
self.__db = OssimDB()
threading.Thread.__init__(self)
示例8: __init__
def __init__(self):
self.__conf = OssimConf(Const.CONFIG_FILE)
self.__db = OssimDB()
self.__stored_id = 0
self.__stored_num = 0
self.__header_id = 0
threading.Thread.__init__(self)
示例9: __startup
def __startup (self):
self._CONF = OssimConf(Const.CONFIG_FILE)
self._DB = OssimDB()
self._DB.connect(self._CONF['ossim_host'],
self._CONF['ossim_base'],
self._CONF['ossim_user'],
self._CONF['ossim_pass'])
示例10: __get_latest_scan_dates
def __get_latest_scan_dates(self):
scan_date_array = {}
tmp_conf = OssimConf (Const.CONFIG_FILE)
tmp_conn = None
self.__debug("Getting latest scan dates")
tmp_conn = OssimDB()
tmp_conn.connect ( tmp_conf["ossim_host"],
tmp_conf["ossim_base"],
tmp_conf["ossim_user"],
tmp_conf["ossim_pass"])
query = "SELECT hostvul.ip as ip, date_format(hostvul.scan_date,\"%Y%m%d%H%i%s\") as scan_date FROM (SELECT ip, max(scan_date) AS mymax FROM host_vulnerability group by ip) AS myvul, host_vulnerability AS hostvul WHERE hostvul.ip=myvul.ip AND hostvul.scan_date=myvul.mymax"
hash = tmp_conn.exec_query(query)
for row in hash:
scan_date_array[row["ip"]] = row["scan_date"]
return scan_date_array
示例11: connectDB
def connectDB(self):
self.db = OssimDB()
self.db.connect(
self._tmp_conf["ossim_host"],
self._tmp_conf["ossim_base"],
self._tmp_conf["ossim_user"],
self._tmp_conf["ossim_pass"],
)
示例12: __init__
def __init__(self, conf):
self.__newConfigFileTemplateName = "/etc/apache2/conf.d/ntop-%s.conf"
self.__sensorVar = "$(SENSOR_IP)"
self.__myDB = OssimDB()
self.__myDB_connected = False
self.__myconf = conf
self.__sensors = {} #ip = name
self.__firstValidSensorConnected = False
示例13: __startup
def __startup (self) :
# configuration values
self.__conf = OssimConf (Const.CONFIG_FILE)
# database connection
self.__conn = OssimDB()
self.__rand = random.randrange(60, 300)
示例14: __init__
def __init__(self):
self.__conf = OssimConf(Const.CONFIG_FILE)
self.__db = OssimDB()
self.__stored_id = 0
self.__stored_num = 0
self.__header_id = 0
self.__ntop_apache_manager = ApacheNtopProxyManager(self.__conf)
self.__last_ntop_link = ""
threading.Thread.__init__(self)
示例15: __check_sensor_ip
def __check_sensor_ip(self, addr):
"""
Checks if the request is coming from a sensor.
Args:
addr: tuple with ip address and port of the request
Returns:
True if address corresponds to a sensor, false otherwise.
"""
try:
conf = OssimConf()
myDB = OssimDB(conf[VAR_DB_HOST],
conf[VAR_DB_SCHEMA],
conf[VAR_DB_USER],
conf[VAR_DB_PASSWORD])
myDB_connected = myDB.connect ()
except Exception, msg:
# Cannot connect to database, return false.
logger.warning("Cannot find registered sensors: %s" % str(msg))
return False