📄 vulnscandconfigfactory.java
字号:
return result; } /** * */ public static int getInterfaceDbNodeId(Connection dbConn, InetAddress ifAddress) throws SQLException { Category log = ThreadCategory.getInstance(VulnscandConfigFactory.class); log.debug("getInterfaceDbNodeId: attempting to lookup interface " + ifAddress.getHostAddress() + " in the database."); // Set connection as read-only // // dbConn.setReadOnly(true); PreparedStatement s = dbConn.prepareStatement(RETRIEVE_IPADDR_NODEID_SQL); s.setString(1, ifAddress.getHostAddress()); ResultSet rs = s.executeQuery(); int nodeid = -1; if (rs.next()) { nodeid = rs.getInt(1); } // Close result set and statement // rs.close(); s.close(); return nodeid; } private static ScanLevel getScanLevel(int level) { Enumeration scanLevels = m_config.enumerateScanLevel(); while (scanLevels.hasMoreElements()) { ScanLevel scanLevel = (ScanLevel) scanLevels.nextElement(); if (level == scanLevel.getLevel()) { return scanLevel; } } throw new ArrayIndexOutOfBoundsException("No scan level with that index could be located in the configuration file, index = " + level); } public void addSpecific(int level, InetAddress specific) { addSpecific(getScanLevel(level), specific); } public void addSpecific(ScanLevel level, InetAddress specific) { level.addSpecific(specific.getHostAddress()); } public void addRange(int level, InetAddress begin, InetAddress end) { addRange(getScanLevel(level), begin, end); } public void addRange(ScanLevel level, InetAddress begin, InetAddress end) { Range addMe = new Range(); addMe.setBegin(begin.getHostAddress()); addMe.setEnd(end.getHostAddress()); level.addRange(addMe); } public void removeSpecific(int level, InetAddress specific) { removeSpecific(getScanLevel(level), specific); } public void removeSpecific(ScanLevel level, InetAddress specific) { level.removeSpecific(specific.getHostAddress()); } public void removeRange(int level, InetAddress begin, InetAddress end) { removeRange(getScanLevel(level), begin, end); } public void removeRange(ScanLevel level, InetAddress begin, InetAddress end) { Range removeMe = new Range(); removeMe.setBegin(begin.getHostAddress()); removeMe.setEnd(end.getHostAddress()); level.removeRange(removeMe); } /** * */ public Set getAllIpAddresses(int level) { return getAllIpAddresses(getScanLevel(level)); } public Set getAllIpAddresses(ScanLevel level) { Set retval = new TreeSet(); Enumeration e = level.enumerateRange(); while (e.hasMoreElements()) { Range ir = (Range) e.nextElement(); try { for (long i = Long.parseLong(ir.getBegin()); i <= Long.parseLong(ir.getEnd()); i++) { retval.add(toInetAddress(i)); } } catch (NumberFormatException ex) { ThreadCategory.getInstance(getClass()).warn("Failed to convert address range (" + ir.getBegin() + ", " + ir.getEnd() + ")", ex); } catch (UnknownHostException ex) { ThreadCategory.getInstance(getClass()).warn("Failed to convert address range (" + ir.getBegin() + ", " + ir.getEnd() + ")", ex); } } e = level.enumerateSpecific(); while (e.hasMoreElements()) { String current = (String) e.nextElement(); try { retval.add(InetAddress.getByName(current)); } catch (UnknownHostException uhE) { ThreadCategory.getInstance().warn("Failed to convert address: " + current, uhE); } } return retval; } public Set getAllExcludes() { Category log = ThreadCategory.getInstance(VulnscandConfigFactory.class); if (m_excludes == null) { m_excludes = new TreeSet(); Excludes excludes = m_config.getExcludes(); if (excludes != null) { if (excludes.getRangeCount() > 0) { Enumeration e = excludes.enumerateRange(); while (e.hasMoreElements()) { Range ir = (Range) e.nextElement(); try { for (long i = Long.parseLong(ir.getBegin()); i <= Long.parseLong(ir.getEnd()); i++) { m_excludes.add(toInetAddress(i)); } } catch (UnknownHostException uhE) { ThreadCategory.getInstance(getClass()).warn("Failed to convert address range (" + ir.getBegin() + ", " + ir.getEnd() + ")", uhE); } } } if (excludes.getSpecificCount() > 0) { Enumeration e = excludes.enumerateSpecific(); while (e.hasMoreElements()) { String current = (String) e.nextElement(); log.debug("excludes: Specific " + current + " Converted:" + new IPv4Address(current).getAddress()); m_excludes.add(current); } } } } return m_excludes; } public void removeExcludeRange(InetAddress begin, InetAddress end) { Range removeMe = new Range(); removeMe.setBegin(begin.getHostAddress()); removeMe.setEnd(end.getHostAddress()); m_config.getExcludes().removeRange(removeMe); } public void removeExcludeSpecific(InetAddress specific) { m_config.getExcludes().removeSpecific(specific.getHostAddress()); } /** * */ public long getRescanFrequency() { long frequency = -1; if (m_config.hasRescanFrequency()) frequency = m_config.getRescanFrequency(); else { ThreadCategory.getInstance(VulnscandConfigFactory.class).warn("Vulnscand configuration file is missing rescan interval, defaulting to 24 hour interval."); frequency = 86400000; // default is 24 hours } return frequency; } /** * */ public long getInitialSleepTime() { long sleep = -1; if (m_config.hasInitialSleepTime()) sleep = m_config.getInitialSleepTime(); else { ThreadCategory.getInstance(VulnscandConfigFactory.class).warn("Vulnscand configuration file is missing initial pause time, defaulting to 5 minutes."); sleep = 300000; // default is 5 minutes } return sleep; } /** * */ public InetAddress getServerAddress() { try { return (InetAddress.getByName(m_config.getServerAddress())); } catch (UnknownHostException ex) { ThreadCategory.getInstance(VulnscandConfigFactory.class).error("Invalid server in config file", ex); return null; } } /** * Gets the cached value of the plugin lists in the config file */ public String[] getPluginLists() { if (m_pluginLists == null) { m_pluginLists = new String[5]; // Dummy value m_pluginLists[0] = ""; try { Enumeration scanLevels = m_config.enumerateScanLevel(); while (scanLevels.hasMoreElements()) { ScanLevel scanLevel = (ScanLevel) scanLevels.nextElement(); String levelPluginList = scanLevel.getPluginList(); // Get rid of all of the carriage returns, tabs, and spaces levelPluginList = levelPluginList.replace('\n', ' '); levelPluginList = levelPluginList.replace('\t', ' '); levelPluginList = m_space.subst(levelPluginList, ""); m_pluginLists[scanLevel.getLevel()] = levelPluginList; } } catch (ArrayIndexOutOfBoundsException ex) { ThreadCategory.getInstance(getClass()).error("Error while loading plugin lists from config file", ex); } } return m_pluginLists; } /** * Gets the cached value of the safe checks settings in the config file */ public boolean[] getSafeChecks() { if (m_safeChecks == null) { m_safeChecks = new boolean[5]; // Dummy value m_safeChecks[0] = true; try { Enumeration scanLevels = m_config.enumerateScanLevel(); while (scanLevels.hasMoreElements()) { ScanLevel scanLevel = (ScanLevel) scanLevels.nextElement(); m_safeChecks[scanLevel.getLevel()] = scanLevel.getSafeChecks(); } } catch (ArrayIndexOutOfBoundsException ex) { ThreadCategory.getInstance(getClass()).error("Error while loading safe checks settings from config file", ex); } } return m_safeChecks; } /** * */ public int getServerPort() { return m_config.getServerPort(); } /** * */ public String getServerUsername() { return m_config.getServerUsername(); } /** * */ public String getServerPassword() { return m_config.getServerPassword(); } /** * */ public boolean getStatus() { return m_config.getStatus(); } /** * */ public boolean getManagedInterfacesStatus() { return m_config.getManagedInterfaces().getStatus(); } /** * */ public int getManagedInterfacesScanLevel() { return m_config.getManagedInterfaces().getScanLevel(); } /** * */ public int getMaxSuspectThreadPoolSize() { return m_config.getMaxSuspectThreadPoolSize(); } /** * */ public int getMaxRescanThreadPoolSize() { return m_config.getMaxRescanThreadPoolSize(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -