<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Security Advancements at the Monastery &#187; PHP</title>
	<atom:link href="http://blog.securitymonks.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.securitymonks.com</link>
	<description>Information about developments at the Monastery</description>
	<lastBuildDate>Fri, 03 Sep 2010 05:41:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Visualization: An Example Graphing NVD CVE Data</title>
		<link>http://blog.securitymonks.com/2010/04/16/google-visualization-an-example-graphing-nvd-cve-data/</link>
		<comments>http://blog.securitymonks.com/2010/04/16/google-visualization-an-example-graphing-nvd-cve-data/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 15:54:42 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[CERT]]></category>
		<category><![CDATA[CVE]]></category>
		<category><![CDATA[CVSS]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Metrics]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[NIST]]></category>
		<category><![CDATA[NVD]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SCAP]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[Vulnerability]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/?p=1825</guid>
		<description><![CDATA[Google visualization offers graphing abilities to any number of projects.  Why should security professionals care?  If you are going to have to collect and present security metrics, it is best to showcase them in the very best manner possible.  Andrew Jaquith in his article, &#8220;Creating meaningful information security metrics&#8221; states, &#8220;For 2010, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/googlevisualization.gif" align="left" width=100/>Google visualization offers graphing abilities to any number of projects.  Why should security professionals care?  If you are going to have to collect and present security metrics, it is best to showcase them in the very best manner possible.  Andrew Jaquith in his article, &#8220;<a href="http://searchsecurity.techtarget.com/magazineFeature/0,296894,sid14_gci1394672_mem1,00.html">Creating meaningful information security metrics</a>&#8221; states, &#8220;For 2010, Forrester Research expects that overall security budgets will rise less than 5 percent over 2009 &#8211;higher than in the previous year, but not by much.&#8221;  Andrew goes on to point out, &#8220;smart security managers, sensing sudden vulnerability in their budgets, seek better ways to measure and prove the value of what they do every day.&#8221;</p>
<p>
In today&#8217;s work environment there is a need to show changes, potential risks, improved performance, etc. in all areas of the company&#8217;s operations.  Security professionals need to be prepared to answer the basic question, &#8220;why should the CIO or CEO care about security?&#8221;  CSO Online has a great quote from the post, &#8220;<a href="http://www.csoonline.com/article/550413/From_the_CIO_Why_You_Didn_t_Get_the_CISO_Job">From the CIO: Why You Didn&#8217;t Get the CISO Job</a>&#8221; that challenges us to consider our views when it comes to security.  The post states, “laser focus on your speciality is great in middle management. It’s what we want. One of the really hard things about jumping from management to executive is a focus on the whole of the business. It’s a rare person who manages it quickly or easily.”  That is basically the problem with metrics.  It is a battle between generalization to the point of uselessness and details to the point of not being understandable or collectible.  At the end of the day, something needs to be done because the security industry is currently leaving upper management in the position of not understanding what is going on within their business.  That is a risk that not acceptable.
</p>
<p>
Andrew&#8217;s article discusses what kind of security metrics should be used.  Additional sources of information on security metrics can be found in a previous post entitled &#8220;<a href="http://blog.securitymonks.com/2007/04/29/security-metrics/">Security Metrics</a>.&#8221;  The post provides links to wonderful sources on security metric information.  You might also want to take a look at the <a href="http://cisecurity.org/en-us/?route=downloads.show.single.metrics.100">CIS Consensus Security Metrics v1.0.0</a> guide, NIST Special Publication (SP) <a href="http://csrc.nist.gov/publications/nistpubs/800-55-Rev1/SP800-55-rev1.pdf">800-55 Rev 1</a> &#8220;Security Metrics Guide for Information Technology Systems&#8221;, <a href="http://csrc.nist.gov/publications/nistir/ir7564/nistir-7564_metrics-research.pdf">NIST IR-7564</a> &#8220;Directions in Security Metrics Research&#8221;,  &#8220;<a href="http://www.gilligangroupinc.com/headlines/2009/feb-23-related/20090223-cag-draft1.0.pdf">Twenty Most Important Controls and Metrics for Effective Cyber Defense and Continuous FISMA Compliance</a>,&#8221; and &#8220;<a href="http://www.slideshare.net/ramsesgallego/metrics-measures-myths">Metrics, measures &#038; Myths</a>.&#8221;  Once you have start gathering metrics, you will want to present them in an easy to understand format.  This is where Google Visualization can help.
</p>
<p>
Today&#8217;s post walks through an example using the data from the National Institute of Standards and Technology (NIST) National Vulnerability Database (<a href="http://nvd.nist.gov/">NVD</a><a>) Common Vulnerabilities and Exposures (</a><a href="http://cve.mitre.org/">CVE</a>) database.  The purpose is to provide a working example from which you can learn and apply to the various metrics gathered at your organization.
</p>
<p><h3>Data Source</h3>
</p>
<p>
A previous post, &#8220;<a href="http://blog.securitymonks.com/2009/08/09/standardization-and-interoperability-in-security/">Standardization and Interoperability in Security</a>,&#8221; discussed how the Security Content Automation Protocol (<a href="http://scap.nist.gov/">SCAP</a>) is an attempt to help defenders by providing a collection of XML schemas/standards that allow technical security information to be exchanged between tools.  SCAP components consists of:</p>
<ul>
<li><a href="http://cce.mitre.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/cce.mitre.org');">Common Configuration Enumeration (CCE)</a>: provide unique identifiers to system configuration issues in order to facilitate fast and accurate correlation of configuration data across multiple information sources and tools.</li>
<li><a href="http://cpe.mitre.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/cpe.mitre.org');">Common Platform Enumeration (CPE)</a>:  a structured naming scheme for information technology systems, platforms, and packages.</li>
<li><a href="http://cve.mitre.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/cve.mitre.org');">Common Vulnerability Enumeration (CVE)</a>: a dictionary of publicly known information security vulnerabilities and exposures.</li>
<li><a href="http://www.first.org/cvss/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.first.org');">Common Vulnerability Scoring System (CVSS)</a>: a vulnerability scoring system designed to provide an open and standardized method of rating IT vulnerabilities.  NIST has even provided a <a href="http://nvd.nist.gov/cvss.cfm?calculator&#038;adv&#038;version=2" onclick="javascript:pageTracker._trackPageview('/outbound/article/nvd.nist.gov');">calculator</a> for creating CVSS vulnerability severity scores. </li>
<li><a href="http://scap.nist.gov/specifications/xccdf/" onclick="javascript:pageTracker._trackPageview('/outbound/article/scap.nist.gov');">eXtensible Checklist Configuration Description Format (XCCDF)</a>: a specification language for writing security checklists, benchmarks, and related kinds of documents.  NIST has released the NIST Interagency Report 7275 Revision 3 &#8220;<a href="http://csrc.nist.gov/publications/nistir/ir7275r3/NISTIR-7275r3.pdf" onclick="javascript:pageTracker._trackPageview('/outbound/article/csrc.nist.gov');">Specification for Extensible Configuration Checklist Description Format (XCCDF) Version 1.1.4</a>.&#8221;</li>
<li><a href="http://oval.mitre.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/oval.mitre.org');">Open Vulnerability Assessment Language (OVAL)</a>: an information security community standard to promote open and publicly available security content, and to standardize the transfer of this information across security tools and services.</li>
</ul>
<p>
We are going to make use of the data from <a href="http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-recent.xml">NVD/CVE XML feed</a> with the Common Vulnerability Scoring System (<a href="http://www.first.org/cvss/cvss-guide.html">CVSS</a>) mappings (version 2.0).  NIST documentation states:<br />
<blockquote>CVSS provides an open framework for communicating the characteristics and impacts of IT vulnerabilities. Its quantitative model ensures repeatable accurate measurement while enabling users to see the underlying vulnerability characteristics that were used to generate the scores. Thus, CVSS is well suited as a standard measurement system for industries, organizations, and governments that need accurate and consistent vulnerability impact scores. Two common uses of CVSS are prioritization of vulnerability remediation activities and in calculating the severity of vulnerabilities discovered on one&#8217;s systems. </p></blockquote>
<p>
NVD provides CVSS &#8216;<b>base scores</b>&#8216; representing the innate characteristics of each vulnerability.  &#8216;<b>Temporal scores</b>,&#8217; which change over time due to events external to the vulnerability, are not provided though NVD does provide a <a href="http://nvd.nist.gov/cvss.cfm?calculator">CVSS score calculator</a>.  This allows an organization to add temporal data and even factor in &#8216;<b>environmental scores</b>&#8216; customized to reflect the impact of the vulnerability on the organization.  Please refer to the <a href="http://www.first.org/cvss/cvss-guide.html">CVSS standards guide</a> and the <a herf="http://www.owasp.org/index.php/OWASP_Risk_Rating_Methodology">OWASP Risk Rating Methodology</a> concerning factors involved in estimating the severity of risks to your business.
</p>
<p><h4><b>NVD CVE XML Schema</b></h4>
</p>
<p>
For our example, we will be using the data feeds <a href="http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-2010.xml">nvdcve-2.0-2010.xml</a> and <a href="http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-2090.xml">nvdcve-2.0-2009.xml</a>.  Examining the <a href="http://nvd.nist.gov/schema/nvd-cve-feed_2.0.xsd">CVE XML 2.0 Schema</a>, we are particularly interested in certain vulnerability and CVSS scoring information.  For example, for CVE-2010-1228, we will parse and pull the following kind of information:
</p>
<p><pre><tt><b><font color="#3366FF">&lt;entry</font></b> <font color="#009900">id</font><font color="#990000">=</font><font color="#CC3333">"CVE-2010-1228"</font><b><font color="#3366FF">&gt;</font></b>
  <b><font color="#3366FF">&lt;vuln:cve-id&gt;</font></b>CVE-2010-1228<b><font color="#3366FF">&lt;/vuln:cve-id&gt;</font></b>
  <b><font color="#3366FF">&lt;vuln:published-datetime&gt;</font></b>2010-04-01T18:30:00.453-04:00
  <b><font color="#3366FF">&lt;/vuln:published-datetime&gt;</font></b>
  <b><font color="#3366FF">&lt;vuln:last-modified-datetime&gt;</font></b>2010-04-05T00:00:00.000-04:00
  <b><font color="#3366FF">&lt;/vuln:last-modified-datetime&gt;</font></b>
  <b><font color="#3366FF">&lt;vuln:cvss&gt;</font></b>
    <b><font color="#3366FF">&lt;cvss:base_metrics&gt;</font></b>
      <b><font color="#3366FF">&lt;cvss:score&gt;</font></b>10.0<b><font color="#3366FF">&lt;/cvss:score&gt;</font></b>
      <b><font color="#3366FF">&lt;cvss:access-vector&gt;</font></b>NETWORK<b><font color="#3366FF">&lt;/cvss:access-vector&gt;</font></b>
      <b><font color="#3366FF">&lt;cvss:access-complexity&gt;</font></b>LOW<b><font color="#3366FF">&lt;/cvss:access-complexity&gt;</font></b>
      <b><font color="#3366FF">&lt;cvss:authentication&gt;</font></b>NONE<b><font color="#3366FF">&lt;/cvss:authentication&gt;</font></b>
      <b><font color="#3366FF">&lt;cvss:confidentiality-impact&gt;</font></b>COMPLETE<b><font color="#3366FF">&lt;/cvss:confidentiality-impact&gt;</font></b>
      <b><font color="#3366FF">&lt;cvss:integrity-impact&gt;</font></b>COMPLETE<b><font color="#3366FF">&lt;/cvss:integrity-impact&gt;</font></b>
      <b><font color="#3366FF">&lt;cvss:availability-impact&gt;</font></b>COMPLETE<b><font color="#3366FF">&lt;/cvss:availability-impact&gt;</font></b>
      <b><font color="#3366FF">&lt;cvss:source&gt;</font></b>http://nvd.nist.gov<b><font color="#3366FF">&lt;/cvss:source&gt;</font></b>
    <b><font color="#3366FF">&lt;/cvss:base_metrics&gt;</font></b>
  <b><font color="#3366FF">&lt;/vuln:cvss&gt;</font></b>
<b><font color="#3366FF">&lt;/entry&gt;</font></b>
</tt></pre>
</p>
<p><h4><b>Using Perl to Retrieve the CVE File</b></h4>
</p>
<p>
Initially we will read the <a href="http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-2010.xml">nvdcve-2.0-2010.xml</a> and <a href="http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-2090.xml">nvdcve-2.0-2009.xml</a> files.  If we start retrieving the file regularly, we would want to change this to <a href="http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-recent.xml">nvdcve-2.0-recent.xml</a>.  Of course, previous years can also be read in to provide a longer perspective on vulnerabilities.  A simple example of a Perl subroutine to read the NVD CVE file and save it locally would be:
</p>
<p><pre><tt><b><font color="#3366FF">sub</font></b> readpage <font color="#CC3333">{</font>
   <b><font color="#3366FF">my</font></b><font color="#990000">(</font><font color="#009900">$url</font><font color="#990000">,</font><font color="#009900">$nvd_file</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#009900">@_</font><font color="#990000">;</font>
   <b><font color="#3366FF">my</font></b><font color="#990000">(</font><font color="#009900">$proxy</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#CC3333">"http://your-proxy-server:proxy-port"</font><font color="#990000">;</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$ua</font> <font color="#990000">=</font> new LWP<font color="#990000">::</font>UserAgent<font color="#990000">;</font>
   <font color="#009900">$ua</font><font color="#990000">-&gt;</font><b><font color="#000000">proxy</font></b><font color="#990000">(</font>http  <font color="#990000">=&gt;</font> <font color="#009900">$proxy</font><font color="#990000">);</font>
   <font color="#009900">$ua</font><font color="#990000">-&gt;</font><b><font color="#000000">proxy</font></b><font color="#990000">(</font>ftp <font color="#990000">=&gt;</font> <font color="#009900">$proxy</font><font color="#990000">);</font>
   <font color="#009900">$ua</font><font color="#990000">-&gt;</font><b><font color="#000000">proxy</font></b><font color="#990000">(</font>https <font color="#990000">=&gt;</font> <font color="#009900">$proxy</font><font color="#990000">);</font>
   <i><font color="#996633"># Go out and retrieve page</font></i>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$req</font> <font color="#990000">=</font> new HTTP<font color="#990000">::</font><b><font color="#000000">Request</font></b><font color="#990000">(</font><font color="#CC3333">'GET'</font><font color="#990000">,</font> <font color="#009900">$url</font><font color="#990000">);</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$res</font> <font color="#990000">=</font> <font color="#009900">$ua</font><font color="#990000">-&gt;</font><b><font color="#000000">request</font></b><font color="#990000">(</font><font color="#009900">$req</font><font color="#990000">);</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$pjstatus</font> <font color="#990000">=</font> <font color="#993399">1</font><font color="#990000">;</font>
   <i><font color="#996633"># Check if the requested webpage is there and return results</font></i>
   <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$res</font><font color="#990000">-&gt;</font>is_success<font color="#990000">)</font> <font color="#CC3333">{</font> <i><font color="#996633"># Request successful</font></i>
       <b><font color="#3366FF">open</font></b><font color="#990000">(</font>OUTFILE<font color="#990000">,</font><font color="#CC3333">"&gt;$nvd_file"</font><font color="#990000">)</font> <font color="#990000">||</font> <font color="#990000">(</font><font color="#009900">$pjstatus</font> <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">);</font>
       <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$pjstatus</font><font color="#990000">)</font> <font color="#CC3333">{</font>
          <b><font color="#3366FF">print</font></b> OUTFILE <font color="#009900">$res</font><font color="#990000">-&gt;</font>content<font color="#990000">;</font>
       <font color="#CC3333">}</font>
       <b><font color="#3366FF">close</font></b><font color="#990000">(</font>OUTFILE<font color="#990000">);</font>
   <font color="#CC3333">}</font>
   <b><font color="#3366FF">else</font></b> <font color="#CC3333">{</font>
      <font color="#009900">$pjstatus</font> <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
   <font color="#CC3333">}</font>
   <b><font color="#3366FF">return</font></b><font color="#990000">(</font><font color="#009900">$pjstatus</font><font color="#990000">);</font>
<font color="#CC3333">}</font>
</tt></pre>
</p>
<p>
Please <b>substitute</b> &#8220;http://your-proxy-server:proxy-port&#8221; with your site&#8217;s proxy server and port, if applicable.
</p>
<p><h4><b>Creating a MYSQL Table to Hold the Data</b></h4>
</p>
<p>
There is a great deal of information in the NVD CVE file.  You will need to determine what information your organization will be interested in storing and graphing.  For better or worse, folks have come to expect vulnerabilities to have a &#8220;Low,&#8221; &#8220;Medium,&#8221; or &#8220;High&#8221; score.  NIST has stated concerning the NVD Vulnerability <b>Severity Ratings</b>:</p>
<blockquote><p>
NVD provides severity rankings of &#8220;Low,&#8221; &#8220;Medium,&#8221; and &#8220;High&#8221; in addition to the numeric CVSS scores but these qualitative rankings are simply mapped from the numeric CVSS scores:<br />
1. Vulnerabilities are labeled &#8220;Low&#8221; severity if they have a CVSS base score of 0.0-3.9.<br />
2. Vulnerabilities will be labeled &#8220;Medium&#8221; severity if they have a base CVSS score of 4.0-6.9.<br />
3. Vulnerabilities will be labeled &#8220;High&#8221; severity if they have a CVSS base score of 7.0-10.0.
</p></blockquote>
<p>
While preferring quantitative over qualitative values, for this example I would like to create a stacked column chart.  We will add a severity column which is based on the CVSS score.  An example table follows:
</p>
<p><pre><tt><b><font color="#3366FF">CREATE</font></b> <b><font color="#3366FF">DATABASE</font></b> vulnerabilities<font color="#990000">;</font>
<b><font color="#3366FF">USE</font></b> vulnerabilities<font color="#990000">;</font>
<b><font color="#3366FF">DROP</font></b> <b><font color="#3366FF">TABLE</font></b> <b><font color="#3366FF">IF</font></b> <b><font color="#3366FF">EXISTS</font></b> <font color="#CC3333">`nvdcve`</font><font color="#990000">;</font>
<b><font color="#3366FF">CREATE</font></b> <b><font color="#3366FF">TABLE</font></b> <font color="#CC3333">`nvdcve`</font> <font color="#990000">(</font>
  <font color="#CC3333">`cve_id`</font> <font color="#009900">varchar</font><font color="#990000">(</font><font color="#993399">13</font><font color="#990000">)</font> <b><font color="#3366FF">NOT</font></b> <b><font color="#3366FF">NULL</font></b><font color="#990000">,</font>
  <font color="#CC3333">`published`</font> <font color="#009900">datetime</font> <b><font color="#3366FF">default</font></b> <b><font color="#3366FF">NULL</font></b><font color="#990000">,</font>
  <font color="#CC3333">`modified`</font> <font color="#009900">datetime</font> <b><font color="#3366FF">default</font></b> <b><font color="#3366FF">NULL</font></b><font color="#990000">,</font>
  <font color="#CC3333">`score`</font> <font color="#009900">DECIMAL</font><font color="#990000">(</font><font color="#993399">5</font><font color="#990000">,</font><font color="#993399">2</font><font color="#990000">)</font> <b><font color="#3366FF">default</font></b> <font color="#CC3333">'0.0'</font><font color="#990000">,</font>
  <font color="#CC3333">`severity`</font> <font color="#009900">varchar</font><font color="#990000">(</font><font color="#993399">6</font><font color="#990000">)</font> <b><font color="#3366FF">default</font></b> <font color="#CC3333">'LOW'</font><font color="#990000">,</font>
  <font color="#CC3333">`vector`</font> <font color="#009900">varchar</font><font color="#990000">(</font><font color="#993399">25</font><font color="#990000">)</font> <b><font color="#3366FF">default</font></b> <b><font color="#3366FF">NULL</font></b><font color="#990000">,</font>
  <font color="#CC3333">`complexity`</font> <font color="#009900">varchar</font><font color="#990000">(</font><font color="#993399">25</font><font color="#990000">)</font> <b><font color="#3366FF">default</font></b> <b><font color="#3366FF">NULL</font></b><font color="#990000">,</font>
  <font color="#CC3333">`authentication`</font> <font color="#009900">varchar</font><font color="#990000">(</font><font color="#993399">25</font><font color="#990000">)</font> <b><font color="#3366FF">default</font></b> <b><font color="#3366FF">NULL</font></b><font color="#990000">,</font>
  <font color="#CC3333">`confidentiality`</font> <font color="#009900">varchar</font><font color="#990000">(</font><font color="#993399">25</font><font color="#990000">)</font> <b><font color="#3366FF">default</font></b> <font color="#CC3333">'NONE'</font><font color="#990000">,</font>
  <font color="#CC3333">`integrity`</font> <font color="#009900">varchar</font><font color="#990000">(</font><font color="#993399">25</font><font color="#990000">)</font> <b><font color="#3366FF">default</font></b> <font color="#CC3333">'NONE'</font><font color="#990000">,</font>
  <font color="#CC3333">`availability`</font> <font color="#009900">varchar</font><font color="#990000">(</font><font color="#993399">25</font><font color="#990000">)</font> <b><font color="#3366FF">default</font></b> <font color="#CC3333">'NONE'</font><font color="#990000">,</font>
  <font color="#CC3333">`summary`</font> <font color="#009900">varchar</font><font color="#990000">(</font><font color="#993399">512</font><font color="#990000">)</font> <b><font color="#3366FF">default</font></b> <b><font color="#3366FF">NULL</font></b><font color="#990000">,</font>
  <b><font color="#3366FF">PRIMARY</font></b> <b><font color="#3366FF">KEY</font></b>  <font color="#990000">(</font><font color="#CC3333">`cve_id`</font><font color="#990000">),</font>
  <b><font color="#3366FF">INDEX</font></b> <font color="#990000">(</font>score<font color="#990000">),</font>
  <b><font color="#3366FF">INDEX</font></b> <font color="#990000">(</font>vector<font color="#990000">)</font>
<font color="#990000">)</font>
</tt></pre>
</p>
<p><h4><b>Using Perl Populating the Database</b></h4>
</p>
<p>
Populating the database table is simply a matter of reading the file and adding the entries to the table.  An example Perl subroutine follows:
</p>
<p>
<!-- Generator: GNU source-highlight 3.1.3<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><b><font color="#3366FF">sub</font></b> readxml <font color="#CC3333">{</font>
   <b><font color="#3366FF">my</font></b><font color="#990000">(</font><font color="#009900">$nvd_file</font><font color="#990000">,</font> <font color="#009900">$dbh</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#009900">@_</font><font color="#990000">;</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$parser</font> <font color="#990000">=</font> XML<font color="#990000">::</font>LibXML<font color="#990000">-&gt;</font> <b><font color="#000000">new</font></b><font color="#990000">();</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$doc</font>    <font color="#990000">=</font> <font color="#009900">$parser</font><font color="#990000">-&gt;</font> <b><font color="#000000">parse_file</font></b><font color="#990000">(</font><font color="#009900">$nvd_file</font><font color="#990000">);</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$xc</font>     <font color="#990000">=</font> XML<font color="#990000">::</font>LibXML<font color="#990000">::</font>XPathContext<font color="#990000">-&gt;</font> <b><font color="#000000">new</font></b><font color="#990000">(</font> <font color="#009900">$doc</font><font color="#990000">-&gt;</font><b><font color="#000000">documentElement</font></b><font color="#990000">()</font> <font color="#990000">);</font>
   <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">registerNs</font></b><font color="#990000">(</font>
      def  <font color="#990000">=&gt;</font> <font color="#CC3333">'http://scap.nist.gov/schema/feed/vulnerability/2.0'</font> <font color="#990000">);</font>
   <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">registerNs</font></b><font color="#990000">(</font>
     vuln <font color="#990000">=&gt;</font> <font color="#CC3333">'http://scap.nist.gov/schema/vulnerability/0.4'</font> <font color="#990000">);</font>
   <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">registerNs</font></b><font color="#990000">(</font> cvss <font color="#990000">=&gt;</font> <font color="#CC3333">'http://scap.nist.gov/schema/cvss-v2/0.2'</font> <font color="#990000">);</font>
   <b><font color="#3366FF">for</font></b> <b><font color="#3366FF">my</font></b> <font color="#009900">$entry</font> <font color="#990000">(</font><font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">findnodes</font></b><font color="#990000">(</font><font color="#CC3333">"/def:nvd/def:entry"</font><font color="#990000">))</font> <font color="#CC3333">{</font>
      <b><font color="#3366FF">my</font></b> <font color="#009900">$cve</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'vuln:cve-id'</font><font color="#990000">,</font><font color="#009900">$entry</font><font color="#990000">);</font>
      <b><font color="#3366FF">my</font></b> <font color="#009900">$published</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'vuln:published-datetime'</font><font color="#990000">,</font> <font color="#009900">$entry</font><font color="#990000">);</font>
      <b><font color="#3366FF">my</font></b> <font color="#009900">$modified</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'vuln:last-modified-datetime'</font><font color="#990000">,</font> <font color="#009900">$entry</font><font color="#990000">);</font>
      <b><font color="#3366FF">my</font></b> <font color="#009900">$summary</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'vuln:summary'</font><font color="#990000">,</font> <font color="#009900">$entry</font><font color="#990000">);</font>
      <b><font color="#3366FF">my</font></b> <font color="#009900">$skip</font> <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
      <b><font color="#3366FF">my</font></b> <font color="#990000">(</font><font color="#009900">$metrics</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">findnodes</font></b><font color="#990000">(</font><font color="#CC3333">'vuln:cvss/cvss:base_metrics'</font><font color="#990000">,</font> <font color="#009900">$entry</font><font color="#990000">)</font> <b><font color="#000000">or</font></b> <font color="#990000">(</font><font color="#009900">$skip</font> <font color="#990000">=</font> <font color="#993399">1</font><font color="#990000">);</font>
      <b><font color="#3366FF">if</font></b> <font color="#990000">(!</font> <font color="#009900">$skip</font><font color="#990000">)</font> <font color="#CC3333">{</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$score</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'cvss:score'</font><font color="#990000">,</font> <font color="#009900">$metrics</font><font color="#990000">);</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$vector</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'cvss:access-vector'</font><font color="#990000">,</font> <font color="#009900">$metrics</font><font color="#990000">);</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$complexity</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'cvss:access-complexity'</font><font color="#990000">,</font> <font color="#009900">$metrics</font><font color="#990000">);</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$authentication</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'cvss:authentication'</font><font color="#990000">,</font> <font color="#009900">$metrics</font><font color="#990000">);</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$confidentiality</font> <font color="#990000">=</font>
            <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'cvss:confidentiality-impact'</font><font color="#990000">,</font> <font color="#009900">$metrics</font><font color="#990000">);</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$integrity</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'cvss:integrity-impact'</font><font color="#990000">,</font> <font color="#009900">$metrics</font><font color="#990000">);</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$availability</font> <font color="#990000">=</font> <font color="#009900">$xc</font><font color="#990000">-&gt;</font> <b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#CC3333">'cvss:availability-impact'</font><font color="#990000">,</font> <font color="#009900">$metrics</font><font color="#990000">);</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$severity</font> <font color="#990000">=</font> <font color="#CC3333">"LOW"</font><font color="#990000">;</font>
         <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><b><font color="#3366FF">int</font></b><font color="#990000">(</font><font color="#009900">$score</font><font color="#990000">)</font> <font color="#990000">&gt;=</font> <font color="#993399">7</font><font color="#990000">)</font> <font color="#CC3333">{</font>
            <font color="#009900">$severity</font> <font color="#990000">=</font> <font color="#CC3333">"HIGH"</font><font color="#990000">;</font>
         <font color="#CC3333">}</font>
         <b><font color="#3366FF">elsif</font></b> <font color="#990000">(</font><b><font color="#3366FF">int</font></b><font color="#990000">(</font><font color="#009900">$score</font><font color="#990000">)</font> <font color="#990000">&gt;=</font> <font color="#993399">4</font><font color="#990000">)</font> <font color="#CC3333">{</font>
            <font color="#009900">$severity</font> <font color="#990000">=</font> <font color="#CC3333">"MEDIUM"</font><font color="#990000">;</font>
         <font color="#CC3333">}</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$sql</font> <font color="#990000">=</font> <b><font color="#3366FF">qq</font></b><font color="#CC3333">{ SELECT count(*) FROM nvdcve WHERE cve_id=? }</font><font color="#990000">;</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$sth</font> <font color="#990000">=</font> <font color="#009900">$dbh</font><font color="#990000">-&gt;</font><b><font color="#000000">prepare</font></b><font color="#990000">(</font> <font color="#009900">$sql</font> <font color="#990000">);</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$rc</font> <font color="#990000">=</font> <font color="#009900">$sth</font><font color="#990000">-&gt;</font><b><font color="#000000">execute</font></b><font color="#990000">(</font><font color="#009900">$cve</font><font color="#990000">);</font>
         <b><font color="#3366FF">if</font></b> <font color="#990000">(</font> <font color="#009900">$rc</font><font color="#990000">)</font> <font color="#CC3333">{</font>
            <b><font color="#3366FF">my</font></b><font color="#990000">(</font><font color="#009900">$exist</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#009900">$sth</font><font color="#990000">-&gt;</font><b><font color="#000000">fetchrow_array</font></b><font color="#990000">();</font>
            <b><font color="#3366FF">if</font></b> <font color="#990000">(!</font> <font color="#009900">$exist</font><font color="#990000">)</font> <font color="#CC3333">{</font>
                <font color="#009900">$sql</font> <font color="#990000">=</font> <b><font color="#3366FF">qq</font></b><font color="#CC3333">{</font> INSERT INTO nvdcve SET cve_id<font color="#990000">=?,</font>
published<font color="#990000">=?,</font> modified<font color="#990000">=?,</font> score<font color="#990000">=?,</font> severity<font color="#990000">=?,</font> vector<font color="#990000">=?,</font> complexity<font color="#990000">=?,</font>
authentication<font color="#990000">=?,</font> confidentiality<font color="#990000">=?,</font> integrity<font color="#990000">=?,</font>availability<font color="#990000">=?,</font> summary<font color="#990000">=?</font> <font color="#CC3333">}</font><font color="#990000">;</font>
               <font color="#009900">$sth</font> <font color="#990000">=</font> <font color="#009900">$dbh</font><font color="#990000">-&gt;</font><b><font color="#000000">prepare</font></b><font color="#990000">(</font> <font color="#009900">$sql</font> <font color="#990000">);</font>
               <font color="#009900">$rc</font> <font color="#990000">=</font> <font color="#009900">$sth</font><font color="#990000">-&gt;</font><b><font color="#000000">execute</font></b><font color="#990000">(</font><font color="#009900">$cve</font><font color="#990000">,</font><font color="#009900">$published</font><font color="#990000">,</font><font color="#009900">$modified</font><font color="#990000">,</font><font color="#009900">$score</font><font color="#990000">,</font>
<font color="#009900">$severity</font><font color="#990000">,</font><font color="#009900">$vector</font><font color="#990000">,</font><font color="#009900">$complexity</font><font color="#990000">,</font><font color="#009900">$authentication</font><font color="#990000">,</font>
<font color="#009900">$confidentiality</font><font color="#990000">,</font><font color="#009900">$integrity</font><font color="#990000">,</font><font color="#009900">$availability</font><font color="#990000">,</font><font color="#009900">$summary</font><font color="#990000">);</font>
            <font color="#CC3333">}</font>
         <font color="#CC3333">}</font>
      <font color="#CC3333">}</font>
   <font color="#CC3333">}</font>
<font color="#CC3333">}</font>
</tt></pre>
</p>
<p><h4><b>The Perl Program to Pull It All Together</b></h4>
</p>
<p>
The above subroutines use the Perl modules <a href="http://search.cpan.org/~gaas/libwww-perl-5.834/lib/LWP/UserAgent.pm">LWP::UserAgent</a>, <a href="http://search.cpan.org/~pajas/XML-LibXML-1.70/LibXML.pod">XML::LibXML</a>, <a href="http://search.cpan.org/~pajas/XML-LibXML-XPathContext/">XML::LibXML::XPathContext</a>, and <a href="http://search.cpan.org/~timb/DBI-1.609/">DBI</a>. A sample Perl program that calls the above subroutines to pull down the NVD CVE data and load it into a MySQL table would be:
</p>
<p>
<!-- Generator: GNU source-highlight 3.1.3<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#996633">#!/usr/local/bin/perl -w</font></i>
<b><font color="#3366FF">use</font></b> LWP<font color="#990000">::</font>UserAgent<font color="#990000">;</font>
<b><font color="#3366FF">use</font></b> XML<font color="#990000">::</font>LibXML<font color="#990000">;</font>
<b><font color="#3366FF">use</font></b> XML<font color="#990000">::</font>LibXML<font color="#990000">::</font>XPathContext<font color="#990000">;</font>
<b><font color="#3366FF">use</font></b> DBI<font color="#990000">;</font>
BEGIN<font color="#CC3333">{</font><b><font color="#3366FF">push</font></b> <font color="#009900">@INC</font><font color="#990000">,</font> <font color="#CC3333">"/home/jgerber/projects/nvd/perl"</font><font color="#CC3333">}</font>
<b><font color="#3366FF">use</font></b> nvdsubs <b><font color="#3366FF">qw</font></b><font color="#990000">(</font><font color="#009900">$db_host</font> <font color="#009900">$db</font> <font color="#009900">$mysql_user</font> <font color="#009900">$mysql_passwd</font> <font color="#009900">$mysql</font><font color="#990000">.</font>sock
readpage readxml <font color="#990000">);</font>
<i><font color="#996633"># Main</font></i>
<b><font color="#3366FF">my</font></b> <font color="#009900">$datadir</font> <font color="#990000">=</font> <font color="#CC3333">"/home/johngerber/projects/nvd/data"</font><font color="#990000">;</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">@timeData</font> <font color="#990000">=</font> <b><font color="#000000">localtime</font></b><font color="#990000">(</font>time<font color="#990000">);</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">$year</font> <font color="#990000">=</font> <font color="#993399">1900</font> <font color="#990000">+</font> <font color="#009900">$timeData</font><font color="#990000">[</font><font color="#993399">5</font><font color="#990000">];</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">$prev_year</font> <font color="#990000">=</font> <font color="#993399">1900</font> <font color="#990000">+</font> <font color="#009900">$timeData</font><font color="#990000">[</font><font color="#993399">5</font><font color="#990000">]</font> <font color="#990000">-</font> <font color="#993399">1</font><font color="#990000">;</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">$url</font> <font color="#990000">=</font> <font color="#CC3333">"http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-"</font> <font color="#990000">.</font>
    <font color="#009900">$year</font> <font color="#990000">.</font> <font color="#CC3333">".xml"</font><font color="#990000">;</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">$prev_url</font> <font color="#990000">=</font> <font color="#CC3333">"http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-"</font> <font color="#990000">.</font>
    <font color="#009900">$prev_year</font> <font color="#990000">.</font> <font color="#CC3333">".xml"</font><font color="#990000">;</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">$nvd_file</font> <font color="#990000">=</font> <font color="#009900">$datadir</font>  <font color="#990000">.</font> <font color="#CC3333">"/nvdcve-"</font><font color="#990000">.</font> <font color="#009900">$year</font> <font color="#990000">.</font> <font color="#CC3333">".xml"</font><font color="#990000">;</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">$prev_nvd_file</font> <font color="#990000">=</font> <font color="#009900">$datadir</font>  <font color="#990000">.</font> <font color="#CC3333">"/nvdcve-"</font><font color="#990000">.</font> <font color="#009900">$prev_year</font> <font color="#990000">.</font> <font color="#CC3333">".xml"</font><font color="#990000">;</font>
<font color="#009900">$db</font> <font color="#990000">=</font> <font color="#CC3333">"vulnerabilities"</font><font color="#990000">;</font>
<b><font color="#3366FF">local</font></b><font color="#990000">(</font><font color="#009900">$dbh</font><font color="#990000">)</font> <font color="#990000">=</font> DBI<font color="#990000">-&gt;</font><b><font color="#000000">connect</font></b><font color="#990000">(</font><font color="#CC3333">"DBI:mysql:mysql_socket=$mysql.sock;$db:$db_host"</font><font color="#990000">,</font>
<font color="#009900">$mysql_user</font><font color="#990000">,</font> <font color="#009900">$mysql_passwd</font><font color="#990000">)</font> <font color="#990000">||</font> <b><font color="#3366FF">die</font></b> <font color="#CC3333">"ERROR: Connecting: $DBI::errstr\n"</font><font color="#990000">;</font>
<b><font color="#3366FF">my</font></b> <font color="#990000">(</font><font color="#009900">$pjstatus</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#990000">&amp;</font><b><font color="#000000">readpage</font></b><font color="#990000">(</font><font color="#009900">$prev_url</font><font color="#990000">,</font><font color="#009900">$prev_nvd_file</font><font color="#990000">);</font>
<b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$pjstatus</font><font color="#990000">)</font> <font color="#CC3333">{</font>
   <font color="#990000">&amp;</font><b><font color="#000000">readxml</font></b><font color="#990000">(</font><font color="#009900">$prev_nvd_file</font><font color="#990000">,</font><font color="#009900">$dbh</font><font color="#990000">);</font>
<font color="#CC3333">}</font>
<font color="#009900">$pjstatus</font> <font color="#990000">=</font> <font color="#990000">&amp;</font><b><font color="#000000">readpage</font></b><font color="#990000">(</font><font color="#009900">$url</font><font color="#990000">,</font><font color="#009900">$nvd_file</font><font color="#990000">);</font>
<b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$pjstatus</font><font color="#990000">)</font> <font color="#CC3333">{</font>
   <font color="#990000">&amp;</font><b><font color="#000000">readxml</font></b><font color="#990000">(</font><font color="#009900">$nvd_file</font><font color="#990000">,</font><font color="#009900">$dbh</font><font color="#990000">);</font>
<font color="#CC3333">}</font>
<b><font color="#3366FF">exit</font></b><font color="#990000">;</font>
</tt></pre>
</p>
<p>
The <b>nvdsubs.pm</b> file will not be included in this post.  The subroutines are defined and the only pieces missing are the MySQL database username and password.  You don&#8217;t need mine.  Add your own.  At this point, we have everything we need to finally use Google Visualization to create a graph.
</p>
<p><h3>Google Visualization</h3>
</p>
<p>
We are going to create a Perl program that will read our MySQL nvdcve table and generate the JavaScript that will render our charts on the client&#8217;s browser.  First, we want to define the JavaScript we want to produce.  Just to alleviate some concerns, with Google Visualization your data is only shared between your server and the client connecting.  This is unlike Google Charts where your data is sent to Google where it is made into a chart and the result is sent back.  Google states concerning the logging of chart data (via Google Charts), &#8220;The chart data included in the HTTP request is saved in temporary logs for no longer than two weeks for internal testing and debugging purposes.&#8221;  Every example in the Google Visualization Gallery will state the data policy.  For Google Charts, stated at the bottom of the page for each gadget description the data policy:
</p>
<p>
<img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/GoogleChartDataPolicy.png" />
</p>
<p>
While Google Visualization gadgets will have the following stated data policy:
</p>
<p>
<img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/GoogleVisDataPolicy.png" />
</p>
<p><h4><b>Loading Google Libraries</b></h4>
</p>
<p>
The first thing the JavaScript needs to do is load the required libraries.  This is accomplished with the lines:
</p>
<p><pre>
&lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
</pre>
</p>
<p><h4><b>Area Chart and Table</b></h4>
</p>
<p>
In this example we are going to create an <a href="http://code.google.com/apis/visualization/documentation/gallery/columnchart.html">column chart</a>. In a later section, &#8220;Other Charting Options&#8221; (see below) we define different Google Visualization charting options.
</p>
<p>
JavaScript code for a sample column chart would be:
</p>
<p>
<!-- Generator: GNU source-highlight 3.1.3<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>    <font color="#990000">&lt;</font>script type<font color="#990000">=</font><font color="#CC3333">'text/javascript'</font><font color="#990000">&gt;</font>
      google<font color="#990000">.</font><b><font color="#000000">load</font></b><font color="#990000">(</font><font color="#CC3333">'visualization'</font><font color="#990000">,</font> <font color="#CC3333">'1'</font><font color="#990000">,</font> <font color="#CC3333">{</font>packages<font color="#990000">:[</font><font color="#CC3333">'columnchart'</font><font color="#990000">]</font><font color="#CC3333">}</font><font color="#990000">);</font>
      google<font color="#990000">.</font><b><font color="#000000">setOnLoadCallback</font></b><font color="#990000">(</font>drawChart<font color="#990000">);</font>
      <b><font color="#008080">function</font></b> <b><font color="#000000">drawChart</font></b><font color="#990000">()</font> <font color="#CC3333">{</font>
        <b><font color="#008080">var</font></b> data <font color="#990000">=</font> <b><font color="#008080">new</font></b> google<font color="#990000">.</font>visualization<font color="#990000">.</font><b><font color="#000000">DataTable</font></b><font color="#990000">();</font>
        data<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'date'</font><font color="#990000">,</font> <font color="#CC3333">'Date'</font><font color="#990000">);</font>
        data<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'High'</font><font color="#990000">);</font>
        data<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'Medium'</font><font color="#990000">);</font>
        data<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'Low'</font><font color="#990000">);</font>
        data<font color="#990000">.</font><b><font color="#000000">addRows</font></b><font color="#990000">([</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">0</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font><font color="#993399">92</font><font color="#990000">,</font><font color="#993399">97</font><font color="#990000">,</font><font color="#993399">3</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">1</font><font color="#990000">,</font> <font color="#993399">27</font><font color="#990000">),</font><font color="#993399">168</font><font color="#990000">,</font><font color="#993399">142</font><font color="#990000">,</font><font color="#993399">25</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">2</font><font color="#990000">,</font> <font color="#993399">31</font><font color="#990000">),</font><font color="#993399">141</font><font color="#990000">,</font><font color="#993399">165</font><font color="#990000">,</font><font color="#993399">9</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">3</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font><font color="#993399">132</font><font color="#990000">,</font><font color="#993399">203</font><font color="#990000">,</font><font color="#993399">12</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">4</font><font color="#990000">,</font> <font color="#993399">29</font><font color="#990000">),</font><font color="#993399">158</font><font color="#990000">,</font><font color="#993399">153</font><font color="#990000">,</font><font color="#993399">8</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">5</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font><font color="#993399">200</font><font color="#990000">,</font><font color="#993399">199</font><font color="#990000">,</font><font color="#993399">22</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">6</font><font color="#990000">,</font> <font color="#993399">31</font><font color="#990000">),</font><font color="#993399">190</font><font color="#990000">,</font><font color="#993399">195</font><font color="#990000">,</font><font color="#993399">11</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">7</font><font color="#990000">,</font> <font color="#993399">31</font><font color="#990000">),</font><font color="#993399">127</font><font color="#990000">,</font><font color="#993399">139</font><font color="#990000">,</font><font color="#993399">14</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">8</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font><font color="#993399">233</font><font color="#990000">,</font><font color="#993399">208</font><font color="#990000">,</font><font color="#993399">14</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">9</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font><font color="#993399">163</font><font color="#990000">,</font><font color="#993399">167</font><font color="#990000">,</font><font color="#993399">18</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">10</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font><font color="#993399">129</font><font color="#990000">,</font><font color="#993399">172</font><font color="#990000">,</font><font color="#993399">8</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">11</font><font color="#990000">,</font> <font color="#993399">31</font><font color="#990000">),</font><font color="#993399">200</font><font color="#990000">,</font><font color="#993399">211</font><font color="#990000">,</font><font color="#993399">19</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2010</font><font color="#990000">,</font> <font color="#993399">0</font><font color="#990000">,</font> <font color="#993399">29</font><font color="#990000">),</font><font color="#993399">157</font><font color="#990000">,</font><font color="#993399">139</font><font color="#990000">,</font><font color="#993399">14</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2010</font><font color="#990000">,</font> <font color="#993399">1</font><font color="#990000">,</font> <font color="#993399">26</font><font color="#990000">),</font><font color="#993399">137</font><font color="#990000">,</font><font color="#993399">143</font><font color="#990000">,</font><font color="#993399">12</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2010</font><font color="#990000">,</font> <font color="#993399">2</font><font color="#990000">,</font> <font color="#993399">31</font><font color="#990000">),</font><font color="#993399">252</font><font color="#990000">,</font><font color="#993399">242</font><font color="#990000">,</font><font color="#993399">18</font><font color="#990000">],</font>
           <font color="#990000">[</font><b><font color="#008080">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2010</font><font color="#990000">,</font> <font color="#993399">3</font><font color="#990000">,</font> <font color="#993399">13</font><font color="#990000">),</font><font color="#993399">92</font><font color="#990000">,</font><font color="#993399">118</font><font color="#990000">,</font><font color="#993399">17</font><font color="#990000">]</font>
        <font color="#990000">]);</font>
        <b><font color="#008080">var</font></b> chart <font color="#990000">=</font> <b><font color="#008080">new</font></b> google<font color="#990000">.</font>visualization<font color="#990000">.</font><b><font color="#000000">ColumnChart</font></b><font color="#990000">(</font>document<font color="#990000">.</font><b><font color="#000000">getElementById</font></b><font color="#990000">(</font><font color="#CC3333">'s4graph'</font><font color="#990000">));</font>
        chart<font color="#990000">.</font><b><font color="#000000">draw</font></b><font color="#990000">(</font>data<font color="#990000">,</font> <font color="#CC3333">{</font>displayAnnotations<font color="#990000">:</font><b><font color="#008080">true</font></b><font color="#990000">,</font> is3D<font color="#990000">:</font> <b><font color="#008080">true</font></b><font color="#990000">,</font> isStacked<font color="#990000">:</font> <b><font color="#008080">true</font></b><font color="#990000">,</font> min<font color="#990000">:</font> <font color="#993399">0</font><font color="#990000">,</font>
          allowHtml<font color="#990000">:</font> <b><font color="#008080">true</font></b><font color="#990000">,</font> colors<font color="#990000">:[</font><font color="#CC3333">{</font>color<font color="#990000">:</font><font color="#CC3333">'#E41B17'</font><font color="#990000">,</font> darker<font color="#990000">:</font><font color="#CC3333">'#C11B17'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#CC3333">{</font>color<font color="#990000">:</font><font color="#CC3333">'#FFA500'</font><font color="#990000">,</font> darker<font color="#990000">:</font><font color="#CC3333">'#E56717'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#CC3333">{</font>color<font color="#990000">:</font><font color="#CC3333">'#FFE87C'</font><font color="#990000">,</font> darker<font color="#990000">:</font><font color="#CC3333">'#C8B560'</font><font color="#CC3333">}</font><font color="#990000">]</font><font color="#CC3333">}</font><font color="#990000">);</font>
      <font color="#CC3333">}</font>
    <font color="#990000">&lt;/</font>script<font color="#990000">&gt;</font>
</tt></pre>
</p>
<p>
The resulting image would be the following column chart:
</p>
<p>
<img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/googlecolumn.png"  width=500 />
</p>
<p><h4><b>Rendering the Table</b></h4>
</p>
<p>
When providing qualitative results, I like to back them up with more accurate numeric values.  Let us include a table with links to the CVSS scores for each vulnerability.
</p>
<p>
<!-- Generator: GNU source-highlight 3.1.3<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>    <font color="#990000">&lt;</font>script type<font color="#990000">=</font><font color="#CC3333">'text/javascript'</font><font color="#990000">&gt;</font>
      google<font color="#990000">.</font><b><font color="#000000">load</font></b><font color="#990000">(</font><font color="#CC3333">'visualization'</font><font color="#990000">,</font> <font color="#CC3333">'1'</font><font color="#990000">,</font> <font color="#CC3333">{</font>packages<font color="#990000">:[</font><font color="#CC3333">'table'</font><font color="#990000">]</font><font color="#CC3333">}</font><font color="#990000">);</font>
      google<font color="#990000">.</font><b><font color="#000000">setOnLoadCallback</font></b><font color="#990000">(</font>drawChart<font color="#990000">);</font>
      <b><font color="#3366FF">function</font></b> <b><font color="#000000">drawChart</font></b><font color="#990000">()</font> <font color="#CC3333">{</font>
        <b><font color="#3366FF">var</font></b> data2 <font color="#990000">=</font> <b><font color="#3366FF">new</font></b> google<font color="#990000">.</font>visualization<font color="#990000">.</font><b><font color="#000000">DataTable</font></b><font color="#990000">();</font>
        data2<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'date'</font><font color="#990000">,</font> <font color="#CC3333">'Date'</font><font color="#990000">);</font>
        data2<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'High'</font><font color="#990000">);</font>
        data2<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'Medium'</font><font color="#990000">);</font>
        data2<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'Low'</font><font color="#990000">);</font>
        data2<font color="#990000">.</font><b><font color="#000000">addRows</font></b><font color="#990000">([</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">0</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-01"&gt;2009-01-30&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">92</font><font color="#990000">,</font><font color="#993399">97</font><font color="#990000">,</font><font color="#993399">3</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">1</font><font color="#990000">,</font> <font color="#993399">27</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-02"&gt;2009-02-27&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">168</font><font color="#990000">,</font><font color="#993399">142</font><font color="#990000">,</font><font color="#993399">25</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">2</font><font color="#990000">,</font> <font color="#993399">31</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-03"&gt;2009-03-31&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">141</font><font color="#990000">,</font><font color="#993399">165</font><font color="#990000">,</font><font color="#993399">9</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">3</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-04"&gt;2009-04-30&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">132</font><font color="#990000">,</font><font color="#993399">203</font><font color="#990000">,</font><font color="#993399">12</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">4</font><font color="#990000">,</font> <font color="#993399">29</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-05"&gt;2009-05-29&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">158</font><font color="#990000">,</font><font color="#993399">153</font><font color="#990000">,</font><font color="#993399">8</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">5</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-06"&gt;2009-06-30&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">200</font><font color="#990000">,</font><font color="#993399">199</font><font color="#990000">,</font><font color="#993399">22</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">6</font><font color="#990000">,</font> <font color="#993399">31</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-07"&gt;2009-07-31&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">190</font><font color="#990000">,</font><font color="#993399">195</font><font color="#990000">,</font><font color="#993399">11</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">7</font><font color="#990000">,</font> <font color="#993399">31</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-08"&gt;2009-08-31&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">127</font><font color="#990000">,</font><font color="#993399">139</font><font color="#990000">,</font><font color="#993399">14</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">8</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-09"&gt;2009-09-30&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">233</font><font color="#990000">,</font><font color="#993399">208</font><font color="#990000">,</font><font color="#993399">14</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">9</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-10"&gt;2009-10-30&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">163</font><font color="#990000">,</font><font color="#993399">167</font><font color="#990000">,</font><font color="#993399">18</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">10</font><font color="#990000">,</font> <font color="#993399">30</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-11"&gt;2009-11-30&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">129</font><font color="#990000">,</font><font color="#993399">172</font><font color="#990000">,</font><font color="#993399">8</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2009</font><font color="#990000">,</font> <font color="#993399">11</font><font color="#990000">,</font> <font color="#993399">31</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2009-12"&gt;2009-12-31&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">200</font><font color="#990000">,</font><font color="#993399">211</font><font color="#990000">,</font><font color="#993399">19</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2010</font><font color="#990000">,</font> <font color="#993399">0</font><font color="#990000">,</font> <font color="#993399">29</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2010-01"&gt;2010-01-29&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">157</font><font color="#990000">,</font><font color="#993399">139</font><font color="#990000">,</font><font color="#993399">14</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2010</font><font color="#990000">,</font> <font color="#993399">1</font><font color="#990000">,</font> <font color="#993399">26</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2010-02"&gt;2010-02-26&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">137</font><font color="#990000">,</font><font color="#993399">143</font><font color="#990000">,</font><font color="#993399">12</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2010</font><font color="#990000">,</font> <font color="#993399">2</font><font color="#990000">,</font> <font color="#993399">31</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2010-03"&gt;2010-03-31&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">252</font><font color="#990000">,</font><font color="#993399">242</font><font color="#990000">,</font><font color="#993399">18</font><font color="#990000">],</font>
           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font><b><font color="#3366FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#993399">2010</font><font color="#990000">,</font> <font color="#993399">3</font><font color="#990000">,</font> <font color="#993399">13</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="/nvd/cvealerts.php?date=2010-04"&gt;2010-04-13&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#993399">92</font><font color="#990000">,</font><font color="#993399">118</font><font color="#990000">,</font><font color="#993399">17</font><font color="#990000">],</font>
        <font color="#990000">]);</font>
        <b><font color="#3366FF">var</font></b> table <font color="#990000">=</font> <b><font color="#3366FF">new</font></b> google<font color="#990000">.</font>visualization<font color="#990000">.</font><b><font color="#000000">Table</font></b><font color="#990000">(</font>document<font color="#990000">.</font><b><font color="#000000">getElementById</font></b><font color="#990000">(</font><font color="#CC3333">'s4graph_tab'</font><font color="#990000">));</font>
        table<font color="#990000">.</font><b><font color="#000000">draw</font></b><font color="#990000">(</font>data2<font color="#990000">,</font> <font color="#CC3333">{</font>showRowNumber<font color="#990000">:</font> <b><font color="#3366FF">true</font></b><font color="#990000">,</font> sortAscending<font color="#990000">:</font> <b><font color="#3366FF">false</font></b><font color="#990000">,</font> sortColumn<font color="#990000">:</font> <font color="#993399">0</font><font color="#990000">,</font> allowHtml<font color="#990000">:</font> <b><font color="#3366FF">true</font></b><font color="#CC3333">}</font><font color="#990000">);</font>
      <font color="#CC3333">}</font>
    <font color="#990000">&lt;/</font>script<font color="#990000">&gt;</font>
</tt></pre>
</p>
<p>
The JavaScript code assumes there is a PHP program called <b>cvealerts.php</b> under the <b>/nvd</b> directory on your web server.  Adjust to your environment.  A sample PHP program that could be used for cvealerts.php is provided below.  The resulting table chart would look like:
</p>
<p>
<img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/googletable.png" width=500 />
</p>
<p><h4><b>Handling Events: Interactions Between Graphs</b></h4>
</p>
<p>
We now have two different types of graphs representing the same data.  We want to add interaction between the graphs so the viewer can see the relationship.  With tables rows are selected when the user clicks, which correspond to the whole column of the stacked column chart.  It is not a perfect fit, but it does demonstrate nicely use of adding interactions.
</p>
<p>
<!-- Generator: GNU source-highlight 3.1.3<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>        <i><font color="#996633">// Set a 'select' event listener for the table.</font></i>
        <i><font color="#996633">// When the table is selected,</font></i>
        <i><font color="#996633">// we set the selection on the line graph.</font></i>
        google<font color="#990000">.</font>visualization<font color="#990000">.</font>events<font color="#990000">.</font><b><font color="#000000">addListener</font></b><font color="#990000">(</font>table<font color="#990000">,</font> <font color="#CC3333">'select'</font><font color="#990000">,</font> <b><font color="#3366FF">function</font></b><font color="#990000">()</font> <font color="#CC3333">{</font>
          chart<font color="#990000">.</font><b><font color="#000000">setSelection</font></b><font color="#990000">([</font><font color="#CC3333">{</font>row<font color="#990000">:</font> table<font color="#990000">.</font><b><font color="#000000">getSelection</font></b><font color="#990000">()[</font><font color="#993399">0</font><font color="#990000">].</font>row<font color="#990000">,</font> column<font color="#990000">:</font> <font color="#993399">1</font><font color="#CC3333">}</font><font color="#990000">]);</font>
         <font color="#CC3333">}</font><font color="#990000">);</font>
        <i><font color="#996633">// Set a 'select' event listener for the graph.</font></i>
        <i><font color="#996633">// When the graph is selected,</font></i>
        <i><font color="#996633">// we set the selection on the table.</font></i>
        google<font color="#990000">.</font>visualization<font color="#990000">.</font>events<font color="#990000">.</font><b><font color="#000000">addListener</font></b><font color="#990000">(</font>chart<font color="#990000">,</font> <font color="#CC3333">'select'</font><font color="#990000">,</font> <b><font color="#3366FF">function</font></b><font color="#990000">()</font> <font color="#CC3333">{</font>
           table<font color="#990000">.</font><b><font color="#000000">setSelection</font></b><font color="#990000">([</font><font color="#CC3333">{</font>row<font color="#990000">:</font> chart<font color="#990000">.</font><b><font color="#000000">getSelection</font></b><font color="#990000">()[</font><font color="#993399">0</font><font color="#990000">].</font>row<font color="#CC3333">}</font><font color="#990000">]);</font>
        <font color="#CC3333">}</font><font color="#990000">);</font>
</tt></pre>
</p>
<p><h4><b>Providing Detailed Information</b></h4>
</p>
<p>
When the table chart link is clicked, we would like to provide some detailed information about the vulnerability.  For this example, we will do this with a simple PHP program placed in the /nvd directory on the web server.  The program is called cvealerts.php.
</p>
<p>
<!-- Generator: GNU source-highlight 3.1.3<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><font color="#990000">&lt;?</font>
<b><font color="#000000">session_start</font></b><font color="#990000">();</font>
<b><font color="#3366FF">function</font></b> <b><font color="#000000">db_connect</font></b><font color="#990000">(</font><font color="#009900">$table</font><font color="#990000">)</font> <font color="#CC3333">{</font>
   <font color="#009900">$result</font> <font color="#990000">=</font> <b><font color="#000000">mysql_pconnect</font></b><font color="#990000">(</font><font color="#CC3333">"&lt;dbhost&gt;:&lt;dbport&gt;"</font><font color="#990000">,</font> <font color="#CC3333">"&lt;username&gt;"</font><font color="#990000">,</font> <font color="#CC3333">"&lt;password&gt;"</font><font color="#990000">);</font>
   <b><font color="#3366FF">if</font></b> <font color="#990000">(!</font><font color="#009900">$result</font><font color="#990000">)</font> <b><font color="#3366FF">return</font></b> false<font color="#990000">;</font>
   <b><font color="#3366FF">if</font></b> <font color="#990000">(!</font><b><font color="#000000">mysql_select_db</font></b><font color="#990000">(</font><font color="#009900">$table</font><font color="#990000">))</font> <b><font color="#3366FF">return</font></b> false<font color="#990000">;</font>
   <b><font color="#3366FF">return</font></b> <font color="#009900">$result</font><font color="#990000">;</font>
<font color="#CC3333">}</font>
<b><font color="#3366FF">function</font></b> <b><font color="#000000">do_html_header</font></b><font color="#990000">(</font><font color="#009900">$title</font><font color="#990000">,</font><font color="#009900">$checkuser</font><font color="#990000">,</font><font color="#009900">$logpage</font><font color="#990000">)</font> <font color="#CC3333">{</font>
<font color="#990000">?&gt;</font>
  <font color="#990000">&lt;</font>html<font color="#990000">&gt;</font> <font color="#990000">&lt;</font>head<font color="#990000">&gt;</font> <font color="#990000">&lt;</font>title<font color="#990000">&gt;&lt;?=</font><font color="#009900">$title</font><font color="#990000">?&gt;&lt;/</font>title<font color="#990000">&gt;&lt;/</font>head<font color="#990000">&gt;</font>
  <font color="#990000">&lt;</font>body bgcolor<font color="#990000">=</font><font color="#CC3333">"#FFFFFF"</font><font color="#990000">&gt;</font>
<font color="#990000">&lt;?</font>
<font color="#CC3333">}</font>
<b><font color="#3366FF">function</font></b> <b><font color="#000000">do_html_footer</font></b><font color="#990000">()</font> <font color="#CC3333">{</font>
<font color="#990000">?&gt;</font>
<font color="#990000">&lt;</font>table<font color="#990000">&gt;</font>
<font color="#990000">&lt;</font>tr<font color="#990000">&gt;&lt;</font>td ALIGN<font color="#990000">=</font>CENTER NOWRAP WIDTH<font color="#990000">=</font><font color="#CC3333">"590"</font><font color="#990000">&gt;&lt;/</font>font<font color="#990000">&gt;</font>
<font color="#990000">&lt;</font>font face<font color="#990000">=</font><font color="#CC3333">"Verdana, Arial, Helvetica"</font> size<font color="#990000">=-</font><font color="#993399">2</font><font color="#990000">&gt;</font>Notice to Users<font color="#990000">:</font> Use
of this system constitutes consent to security monitoring <b><font color="#3366FF">and</font></b> testing<font color="#990000">.</font>
<font color="#990000">&lt;</font>br<font color="#990000">&gt;</font>All activity is logged with your host name <b><font color="#3366FF">and</font></b> IP address<font color="#990000">.&lt;/</font>font<font color="#990000">&gt;</font>
<font color="#990000">&lt;/</font>td<font color="#990000">&gt;&lt;/</font>tr<font color="#990000">&gt;</font>
<font color="#990000">&lt;/</font>table<font color="#990000">&gt;</font>
<font color="#990000">&lt;/</font>body<font color="#990000">&gt;</font>
 <font color="#990000">&lt;/</font>html<font color="#990000">&gt;</font>
<font color="#990000">&lt;?</font>
<font color="#CC3333">}</font>
<i><font color="#996633">// Main</font></i>
<font color="#009900">$dates</font><font color="#990000">=</font> <b><font color="#3366FF">array</font></b><font color="#990000">();</font>
<font color="#009900">$stringlist</font> <font color="#990000">=</font> <font color="#CC3333">""</font><font color="#990000">;</font>
<b><font color="#3366FF">if</font></b> <font color="#990000">(</font><b><font color="#3366FF">isset</font></b><font color="#990000">(</font><font color="#009900">$_GET</font><font color="#990000">[</font><font color="#CC3333">'date'</font><font color="#990000">]))</font> <font color="#CC3333">{</font>
    <font color="#009900">$passdates</font> <font color="#990000">=</font> <b><font color="#000000">explode</font></b><font color="#990000">(</font><font color="#CC3333">","</font><font color="#990000">,</font><font color="#009900">$_GET</font><font color="#990000">[</font><font color="#CC3333">'date'</font><font color="#990000">]);</font>
    <b><font color="#3366FF">for</font></b> <font color="#990000">(</font><font color="#009900">$index</font><font color="#990000">=</font><font color="#993399">0</font><font color="#990000">;</font> <font color="#009900">$index</font><font color="#990000">&lt;</font><b><font color="#000000">count</font></b><font color="#990000">(</font><font color="#009900">$passdates</font><font color="#990000">);</font> <font color="#009900">$index</font><font color="#990000">++)</font> <font color="#CC3333">{</font>
       <b><font color="#000000">array_push</font></b><font color="#990000">(</font><font color="#009900">$dates</font><font color="#990000">,</font> <font color="#009900">$passdates</font><font color="#990000">[</font><font color="#009900">$index</font><font color="#990000">]);</font>
       <font color="#009900">$stringlist</font> <font color="#990000">.=</font> <font color="#009900">$passdates</font><font color="#990000">[</font><font color="#009900">$index</font><font color="#990000">]</font> <font color="#990000">.</font> <font color="#CC3333">" "</font><font color="#990000">;</font>
    <font color="#CC3333">}</font>
<font color="#CC3333">}</font>
<b><font color="#3366FF">else</font></b> <font color="#CC3333">{</font>
  <b><font color="#3366FF">print</font></b><font color="#990000">(</font><font color="#CC3333">"Confusion over how you arrived at this page.&lt;P&gt;\n"</font><font color="#990000">);</font>
  <b><font color="#3366FF">exit</font></b><font color="#990000">;</font>
<font color="#CC3333">}</font>
<font color="#009900">$stringlist</font> <font color="#990000">=</font> <b><font color="#000000">preg_replace</font></b><font color="#990000">(</font><font color="#CC3333">"/ $/"</font><font color="#990000">,</font> <font color="#CC3333">""</font><font color="#990000">,</font><font color="#009900">$stringlist</font><font color="#990000">);</font>
<b><font color="#000000">do_html_header</font></b><font color="#990000">(</font><font color="#CC3333">"Review NVD CVE Announcements for Month Ending $stringlist"</font><font color="#990000">,</font><font color="#993399">1</font><font color="#990000">,</font><font color="#993399">1</font><font color="#990000">);</font>
<font color="#009900">$nvd_host</font> <font color="#990000">=</font> <font color="#CC3333">"http://web.nvd.nist.gov/view/vuln/detail?vulnId="</font><font color="#990000">;</font>
<font color="#009900">$conn</font> <font color="#990000">=</font> <b><font color="#000000">db_connect</font></b><font color="#990000">(</font><font color="#CC3333">"vulnerabilities"</font><font color="#990000">);</font>
<b><font color="#3366FF">if</font></b> <font color="#990000">(!</font><font color="#009900">$conn</font><font color="#990000">)</font>
   <b><font color="#000000">logit</font></b><font color="#990000">(</font><font color="#CC3333">"Could not connect to database vulnerabilities - please try later.\n"</font><font color="#990000">,</font><font color="#993399">1</font><font color="#990000">);</font>
<b><font color="#3366FF">for</font></b> <font color="#990000">(</font><font color="#009900">$index</font><font color="#990000">=</font><font color="#993399">0</font><font color="#990000">;</font> <font color="#009900">$index</font><font color="#990000">&lt;</font><b><font color="#000000">count</font></b><font color="#990000">(</font><font color="#009900">$dates</font><font color="#990000">);</font> <font color="#009900">$index</font><font color="#990000">++)</font> <font color="#CC3333">{</font>
   <font color="#009900">$rule</font> <font color="#990000">=</font> <font color="#009900">$dates</font><font color="#990000">[</font><font color="#009900">$index</font><font color="#990000">];</font>
   <font color="#009900">$sql</font> <font color="#990000">=</font> <font color="#CC3333">"SELECT cve_id,score,published,vector,severity,complexity,left(summary,50)</font>
<font color="#CC3333">    FROM vulnerabilities.nvdcve</font>
<font color="#CC3333">      WHERE date_format(published,'%Y-%m')='$rule'</font>
<font color="#CC3333">       ORDER BY (score+0)"</font><font color="#990000">;</font>
   <font color="#009900">$result</font> <font color="#990000">=</font> <b><font color="#000000">mysql_query</font></b><font color="#990000">(</font><font color="#009900">$sql</font><font color="#990000">,</font><font color="#009900">$conn</font><font color="#990000">);</font>
   <b><font color="#3366FF">if</font></b> <font color="#990000">(!</font><font color="#009900">$result</font><font color="#990000">)</font>
       <b><font color="#000000">logit</font></b><font color="#990000">(</font><font color="#CC3333">"Problem with $sql\n"</font><font color="#990000">,</font><font color="#993399">1</font><font color="#990000">);</font>
   <b><font color="#3366FF">print</font></b><font color="#990000">(</font><font color="#CC3333">"&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt;&lt;table border=0&gt;&lt;tr&gt;&lt;th bgcolor=\"#727D96\"&gt;</font>
<font color="#CC3333">&lt;font color=\"#ffffff\" face=\"arial,helvetica,sanserif\"&gt;Bulletin&lt;/font&gt;&lt;/th&gt;&lt;th bgcolor=\"#727D96\"&gt;</font>
<font color="#CC3333">&lt;font color=\"#ffffff\" face=\"arial,helvetica,sanserif\"&gt;Impact&lt;/font&gt;&lt;/th&gt;&lt;th bgcolor=\"#727D96\"&gt;</font>
<font color="#CC3333">&lt;font color=\"#ffffff\" face=\"arial,helvetica,sanserif\"&gt;Date&lt;/font&gt;&lt;/th&gt;&lt;th bgcolor=\"#727D96\"&gt;</font>
<font color="#CC3333">&lt;font color=\"#ffffff\" face=\"arial,helvetica,sanserif\"&gt;Vector&lt;/font&gt;&lt;/th&gt;&lt;th bgcolor=\"#727D96\"&gt;</font>
<font color="#CC3333">&lt;font color=\"#ffffff\" face=\"arial,helvetica,sanserif\"&gt;Severity&lt;/font&gt;&lt;/th&gt;&lt;th bgcolor=\"#727D96\"&gt;</font>
<font color="#CC3333">&lt;font color=\"#ffffff\" face=\"arial,helvetica,sanserif\"&gt;Complexity&lt;/font&gt;&lt;/th&gt;&lt;th bgcolor=\"#727D96\"&gt;</font>
<font color="#CC3333">&lt;font color=\"#ffffff\" face=\"arial,helvetica,sanserif\"&gt;Short Summary&lt;/font&gt;&lt;/th&gt;&lt;/tr&gt;\n"</font><font color="#990000">);</font>
   <b><font color="#3366FF">for</font></b> <font color="#990000">(</font><font color="#009900">$count</font> <font color="#990000">=</font> <font color="#993399">1</font><font color="#990000">;</font> <b><font color="#3366FF">list</font></b><font color="#990000">(</font><font color="#009900">$cve_id</font><font color="#990000">,</font> <font color="#009900">$score</font><font color="#990000">,</font> <font color="#009900">$date</font><font color="#990000">,</font> <font color="#009900">$vector</font><font color="#990000">,</font> <font color="#009900">$severity</font><font color="#990000">,</font><font color="#009900">$complexity</font><font color="#990000">,</font><font color="#009900">$shortsum</font><font color="#990000">)</font> <font color="#990000">=</font>
     <b><font color="#000000">mysql_fetch_array</font></b> <font color="#990000">(</font><font color="#009900">$result</font><font color="#990000">,</font> MYSQL_NUM<font color="#990000">);</font> <font color="#990000">++</font><font color="#009900">$count</font><font color="#990000">)</font> <font color="#CC3333">{</font>
<font color="#990000">?&gt;</font>
      <font color="#990000">&lt;</font>tr<font color="#990000">&gt;&lt;</font>td CLASS<font color="#990000">=</font><font color="#CC3333">"plfieldhdrleft"</font> WIDTH<font color="#990000">=</font><font color="#CC3333">"20%"</font> BGCOLOR<font color="#990000">=</font><font color="#CC3333">'#F0F5FF'</font><font color="#990000">&gt;</font>
      <font color="#990000">&lt;?</font>  <b><font color="#3366FF">print</font></b><font color="#990000">(</font><font color="#CC3333">"&lt;a href=\"$nvd_host$cve_id\"&gt;$cve_id&lt;/a&gt;"</font><font color="#990000">);</font> <font color="#990000">?&gt;</font>
      <font color="#990000">&lt;/</font>td<font color="#990000">&gt;</font>
      <font color="#990000">&lt;</font>td CLASS<font color="#990000">=</font><font color="#CC3333">"plfieldhdrleft"</font> BGCOLOR<font color="#990000">=</font><font color="#CC3333">'#F9FCFF'</font><font color="#990000">&gt;</font>
      <font color="#990000">&lt;?</font>  <b><font color="#3366FF">print</font></b><font color="#990000">(</font><font color="#009900">$score</font><font color="#990000">);</font> <font color="#990000">?&gt;</font>
      <font color="#990000">&lt;/</font>td<font color="#990000">&gt;</font>
      <font color="#990000">&lt;</font>td CLASS<font color="#990000">=</font><font color="#CC3333">"plfieldhdrleft"</font> BGCOLOR<font color="#990000">=</font><font color="#CC3333">'#F0F5FF'</font><font color="#990000">&gt;</font>
      <font color="#990000">&lt;?</font>  <b><font color="#3366FF">print</font></b><font color="#990000">(</font><font color="#009900">$date</font><font color="#990000">);</font> <font color="#990000">?&gt;</font>
      <font color="#990000">&lt;/</font>td<font color="#990000">&gt;</font>
      <font color="#990000">&lt;</font>td CLASS<font color="#990000">=</font><font color="#CC3333">"plfieldhdrleft"</font> BGCOLOR<font color="#990000">=</font><font color="#CC3333">'#F9FCFF'</font><font color="#990000">&gt;</font>
      <font color="#990000">&lt;?</font>  <b><font color="#3366FF">print</font></b><font color="#990000">(</font><font color="#009900">$vector</font><font color="#990000">);</font> <font color="#990000">?&gt;</font>
      <font color="#990000">&lt;/</font>td<font color="#990000">&gt;</font>
      <font color="#990000">&lt;</font>td CLASS<font color="#990000">=</font><font color="#CC3333">"plfieldhdrleft"</font> BGCOLOR<font color="#990000">=</font><font color="#CC3333">'#F0F5FF'</font><font color="#990000">&gt;</font>
      <font color="#990000">&lt;?</font>  <b><font color="#3366FF">print</font></b><font color="#990000">(</font><font color="#009900">$severity</font><font color="#990000">);</font> <font color="#990000">?&gt;</font>
      <font color="#990000">&lt;/</font>td<font color="#990000">&gt;</font>
      <font color="#990000">&lt;</font>td CLASS<font color="#990000">=</font><font color="#CC3333">"plfieldhdrleft"</font> BGCOLOR<font color="#990000">=</font><font color="#CC3333">'#F9FCFF'</font><font color="#990000">&gt;</font>
      <font color="#990000">&lt;?</font>  <b><font color="#3366FF">print</font></b><font color="#990000">(</font><font color="#009900">$complexity</font><font color="#990000">);</font> <font color="#990000">?&gt;</font>
      <font color="#990000">&lt;/</font>td<font color="#990000">&gt;</font>
      <font color="#990000">&lt;</font>td CLASS<font color="#990000">=</font><font color="#CC3333">"plfieldhdrleft"</font> BGCOLOR<font color="#990000">=</font><font color="#CC3333">'#F0F5FF'</font><font color="#990000">&gt;</font>
      <font color="#990000">&lt;?</font>  <b><font color="#3366FF">print</font></b><font color="#990000">(</font><font color="#009900">$shortsum</font><font color="#990000">);</font> <font color="#990000">?&gt;</font>
      <font color="#990000">&lt;/</font>td<font color="#990000">&gt;</font>
      <font color="#990000">&lt;/</font>tr<font color="#990000">&gt;</font>
<font color="#990000">&lt;?</font>
   <font color="#CC3333">}</font>
<font color="#CC3333">}</font>
<b><font color="#3366FF">print</font></b><font color="#990000">(</font><font color="#CC3333">"&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;"</font><font color="#990000">);</font>
<b><font color="#000000">do_html_footer</font></b><font color="#990000">();</font>
</tt></pre>
</p>
<p>
The PHP program would generate a HTML table displaying the NVD CVE alerts for that month.  The table would look like:
</p>
<p>
<img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/googletable3.png" width=500 />
</p>
<p>
When the CVE link is clicked on, the user is taken to the NIST NVD site where additional information is available.
</p>
<p>
<img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/nvdsite.png" width=500 />
</p>
<p><h4><b>Using Perl to Create the JavaScript</b></h4>
</p>
<p>
The Perl code is rather simple now that we have the MySQL tables defined and the JavaScript we want to generate.  Much of the code consists of the JavaScript listed above.
</p>
<p>
<!-- Generator: GNU source-highlight 3.1.3<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#996633">#!/usr/local/bin/perl -w</font></i>
<b><font color="#3366FF">use</font></b> DBI<font color="#990000">;</font>
<b><font color="#3366FF">use</font></b> Time<font color="#990000">::</font>Local<font color="#990000">;</font>
<b><font color="#3366FF">use</font></b> POSIX <b><font color="#3366FF">qw</font></b><font color="#990000">(</font>strftime<font color="#990000">);</font>
<b><font color="#3366FF">use</font></b> LWP<font color="#990000">::</font>UserAgent<font color="#990000">;</font>
BEGIN<font color="#CC3333">{</font><b><font color="#3366FF">push</font></b> <font color="#009900">@INC</font><font color="#990000">,</font> <font color="#CC3333">"/home/jgerber/projects/nvd/perl"</font><font color="#CC3333">}</font>
<b><font color="#3366FF">use</font></b> ornl_feds <b><font color="#3366FF">qw</font></b><font color="#990000">(</font><font color="#009900">$db_host</font> <font color="#009900">$db</font> <font color="#009900">$mysql_user</font> <font color="#009900">$mysql_passwd</font> <font color="#990000">);</font>
<b><font color="#3366FF">sub</font></b> slide_nvd_alerts <font color="#CC3333">{</font>
  <b><font color="#3366FF">my</font></b><font color="#990000">(</font><font color="#009900">$min_date</font><font color="#990000">,</font><font color="#009900">$graph_name</font><font color="#990000">,</font><font color="#009900">$web_link</font><font color="#990000">,</font><font color="#009900">$dbh</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#009900">@_</font><font color="#990000">;</font>
  <b><font color="#3366FF">my</font></b> <font color="#009900">$slide</font> <font color="#990000">=</font> <font color="#CC3333">""</font><font color="#990000">;</font>
  <b><font color="#3366FF">my</font></b> <font color="#009900">$slide_head</font> <font color="#990000">=</font> <b><font color="#3366FF">qq</font></b><font color="#990000">!</font>
    <font color="#CC3333">&lt;script type='text/javascript'&gt;</font>
      google<font color="#990000">.</font><b><font color="#000000">load</font></b><font color="#990000">(</font><font color="#CC3333">'visualization'</font><font color="#990000">,</font> <font color="#CC3333">'1'</font><font color="#990000">,</font> <font color="#CC3333">{</font>packages<font color="#990000">:[</font><font color="#CC3333">'columnchart,table'</font><font color="#990000">]</font><font color="#CC3333">}</font><font color="#990000">);</font>
      google<font color="#990000">.</font><b><font color="#000000">setOnLoadCallback</font></b><font color="#990000">(</font>drawChart<font color="#990000">);</font>
      function <b><font color="#000000">drawChart</font></b><font color="#990000">()</font> <font color="#CC3333">{</font>
        var data <font color="#990000">=</font> new google<font color="#990000">.</font>visualization<font color="#990000">.</font><b><font color="#000000">DataTable</font></b><font color="#990000">();</font>
        data<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'date'</font><font color="#990000">,</font> <font color="#CC3333">'Date'</font><font color="#990000">);</font>
        data<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'High'</font><font color="#990000">);</font>
        data<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'Medium'</font><font color="#990000">);</font>
        data<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'Low'</font><font color="#990000">);</font>
        data<font color="#990000">.</font><b><font color="#000000">addRows</font></b><font color="#990000">([</font>
<font color="#990000">!;</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$slide_head_table</font> <font color="#990000">=</font> <b><font color="#3366FF">qq</font></b><font color="#990000">!</font>
        var data2 <font color="#990000">=</font> new google<font color="#990000">.</font>visualization<font color="#990000">.</font><b><font color="#000000">DataTable</font></b><font color="#990000">();</font>
        data2<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'date'</font><font color="#990000">,</font> <font color="#CC3333">'Date'</font><font color="#990000">);</font>
        data2<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'High'</font><font color="#990000">);</font>
        data2<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'Medium'</font><font color="#990000">);</font>
        data2<font color="#990000">.</font><b><font color="#000000">addColumn</font></b><font color="#990000">(</font><font color="#CC3333">'number'</font><font color="#990000">,</font> <font color="#CC3333">'Low'</font><font color="#990000">);</font>
        data2<font color="#990000">.</font><b><font color="#000000">addRows</font></b><font color="#990000">([</font>
<font color="#990000">!;</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$table_div</font> <font color="#990000">=</font> <font color="#009900">$graph_name</font> <font color="#990000">.</font> <font color="#CC3333">"_tab"</font><font color="#990000">;</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$slide_tail</font> <font color="#990000">=</font> <b><font color="#3366FF">qq</font></b><font color="#990000">!</font>
        var chart <font color="#990000">=</font> new google<font color="#990000">.</font>visualization<font color="#990000">.</font><b><font color="#000000">ColumnChart</font></b><font color="#990000">(</font>document<font color="#990000">.</font><b><font color="#000000">getElementById</font></b><font color="#990000">(</font><font color="#CC3333">'$graph_name'</font><font color="#990000">));</font>
        chart<font color="#990000">.</font><b><font color="#000000">draw</font></b><font color="#990000">(</font>data<font color="#990000">,</font> <font color="#CC3333">{</font>displayAnnotations<font color="#990000">:</font>true<font color="#990000">,</font> is3D<font color="#990000">:</font> true<font color="#990000">,</font> isStacked<font color="#990000">:</font> true<font color="#990000">,</font> min<font color="#990000">:</font> <font color="#993399">0</font><font color="#990000">,</font> allowHtml<font color="#990000">:</font> true<font color="#990000">,</font>
 colors<font color="#990000">:[</font><font color="#CC3333">{</font>color<font color="#990000">:</font><font color="#CC3333">'#E41B17'</font><font color="#990000">,</font> darker<font color="#990000">:</font><font color="#CC3333">'#C11B17'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#CC3333">{</font>color<font color="#990000">:</font><font color="#CC3333">'#FFA500'</font><font color="#990000">,</font> darker<font color="#990000">:</font><font color="#CC3333">'#E56717'</font><font color="#CC3333">}</font><font color="#990000">,</font>
<font color="#CC3333">{</font>color<font color="#990000">:</font><font color="#CC3333">'#FFE87C'</font><font color="#990000">,</font> darker<font color="#990000">:</font><font color="#CC3333">'#C8B560'</font><font color="#CC3333">}</font><font color="#990000">]</font><font color="#CC3333">}</font><font color="#990000">);</font>
        var table <font color="#990000">=</font> new google<font color="#990000">.</font>visualization<font color="#990000">.</font><b><font color="#000000">Table</font></b><font color="#990000">(</font>document<font color="#990000">.</font><b><font color="#000000">getElementById</font></b><font color="#990000">(</font><font color="#CC3333">'$table_div'</font><font color="#990000">));</font>
        table<font color="#990000">.</font><b><font color="#000000">draw</font></b><font color="#990000">(</font>data2<font color="#990000">,</font> <font color="#CC3333">{</font>showRowNumber<font color="#990000">:</font> true<font color="#990000">,</font> sortAscending<font color="#990000">:</font> false<font color="#990000">,</font> sortColumn<font color="#990000">:</font> <font color="#993399">0</font><font color="#990000">,</font> allowHtml<font color="#990000">:</font> true<font color="#CC3333">}</font><font color="#990000">);</font>
            <font color="#CC3333">//</font> Set a <font color="#CC3333">'select'</font> event listener <b><font color="#3366FF">for</font></b> the table<font color="#990000">.</font>
        <font color="#CC3333">//</font> When the table is selected<font color="#990000">,</font>
        <font color="#CC3333">//</font> we set the selection on the line graph<font color="#990000">.</font>
        google<font color="#990000">.</font>visualization<font color="#990000">.</font>events<font color="#990000">.</font><b><font color="#000000">addListener</font></b><font color="#990000">(</font>table<font color="#990000">,</font> <font color="#CC3333">'select'</font><font color="#990000">,</font> <b><font color="#000000">function</font></b><font color="#990000">()</font> <font color="#CC3333">{</font>
          chart<font color="#990000">.</font><b><font color="#000000">setSelection</font></b><font color="#990000">([</font><font color="#CC3333">{</font>row<font color="#990000">:</font> table<font color="#990000">.</font><b><font color="#000000">getSelection</font></b><font color="#990000">()[</font><font color="#993399">0</font><font color="#990000">].</font>row<font color="#990000">,</font> column<font color="#990000">:</font> <font color="#993399">1</font><font color="#CC3333">}</font><font color="#990000">]);</font>
         <font color="#CC3333">}</font><font color="#990000">);</font>
      <font color="#CC3333">//</font> Set a <font color="#CC3333">'select'</font> event listener <b><font color="#3366FF">for</font></b> the graph<font color="#990000">.</font>
        <font color="#CC3333">//</font> When the graph is selected<font color="#990000">,</font>
        <font color="#CC3333">//</font> we set the selection on the table<font color="#990000">.</font>
        google<font color="#990000">.</font>visualization<font color="#990000">.</font>events<font color="#990000">.</font><b><font color="#000000">addListener</font></b><font color="#990000">(</font>chart<font color="#990000">,</font> <font color="#CC3333">'select'</font><font color="#990000">,</font> <b><font color="#000000">function</font></b><font color="#990000">()</font> <font color="#CC3333">{</font>
           table<font color="#990000">.</font><b><font color="#000000">setSelection</font></b><font color="#990000">([</font><font color="#CC3333">{</font>row<font color="#990000">:</font> chart<font color="#990000">.</font><b><font color="#000000">getSelection</font></b><font color="#990000">()[</font><font color="#993399">0</font><font color="#990000">].</font>row<font color="#CC3333">}</font><font color="#990000">]);</font>
        <font color="#CC3333">}</font><font color="#990000">);</font>
      <font color="#CC3333">}</font>
    <font color="#CC3333">&lt;/script&gt;</font>
<font color="#990000">!;</font>
   <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$min_date</font> <b><font color="#3366FF">eq</font></b> <font color="#CC3333">""</font><font color="#990000">)</font> <font color="#CC3333">{</font>
      <b><font color="#3366FF">my</font></b> <font color="#009900">$sql2</font> <font color="#990000">=</font> <b><font color="#3366FF">qq</font></b><font color="#CC3333">{ SELECT min(published) FROM vulnerabilities.nvdcve }</font><font color="#990000">;</font>
      <b><font color="#3366FF">my</font></b> <font color="#009900">$sth2</font> <font color="#990000">=</font> <font color="#009900">$dbh</font><font color="#990000">-&gt;</font><b><font color="#000000">prepare</font></b><font color="#990000">(</font> <font color="#009900">$sql2</font> <font color="#990000">);</font>
      <b><font color="#3366FF">my</font></b> <font color="#009900">$rc2</font> <font color="#990000">=</font> <font color="#009900">$sth2</font><font color="#990000">-&gt;</font><b><font color="#000000">execute</font></b><font color="#990000">();</font>
      <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$rc2</font><font color="#990000">)</font> <font color="#CC3333">{</font>
         <font color="#009900">$min_date</font> <font color="#990000">=</font> <font color="#009900">$sth2</font><font color="#990000">-&gt;</font><b><font color="#000000">fetchrow_array</font></b><font color="#990000">();</font>
      <font color="#CC3333">}</font>
   <font color="#CC3333">}</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$table_data</font> <font color="#990000">=</font> <font color="#CC3333">""</font><font color="#990000">;</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$graph_data</font> <font color="#990000">=</font> <font color="#CC3333">""</font><font color="#990000">;</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$sql2</font> <font color="#990000">=</font> <b><font color="#3366FF">qq</font></b><font color="#CC3333">{</font> <b><font color="#3366FF">select</font></b> <b><font color="#000000">date_format</font></b><font color="#990000">(</font>published<font color="#990000">,</font><font color="#CC3333">'%Y-%m'</font><font color="#990000">),</font>severity<font color="#990000">,</font><b><font color="#000000">count</font></b><font color="#990000">(</font>severity<font color="#990000">)</font>
      FROM vulnerabilities<font color="#990000">.</font>nvdcve where published <font color="#990000">&gt;=</font> <font color="#990000">?</font> group by <b><font color="#000000">date_format</font></b><font color="#990000">(</font>published<font color="#990000">,</font><font color="#CC3333">'%Y-%m'</font><font color="#990000">),</font>severity <font color="#CC3333">}</font><font color="#990000">;</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$sth2</font> <font color="#990000">=</font> <font color="#009900">$dbh</font><font color="#990000">-&gt;</font><b><font color="#000000">prepare</font></b><font color="#990000">(</font> <font color="#009900">$sql2</font> <font color="#990000">);</font>
   <b><font color="#3366FF">my</font></b> <font color="#009900">$rc2</font> <font color="#990000">=</font> <font color="#009900">$sth2</font><font color="#990000">-&gt;</font><b><font color="#000000">execute</font></b><font color="#990000">(</font><font color="#009900">$min_date</font><font color="#990000">);</font>
   <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$rc2</font><font color="#990000">)</font> <font color="#CC3333">{</font>
      <b><font color="#3366FF">my</font></b> <font color="#990000">(</font><font color="#009900">$change</font><font color="#990000">,</font><font color="#009900">$virgin</font><font color="#990000">,</font><font color="#009900">$ht</font><font color="#990000">,</font><font color="#009900">$mt</font><font color="#990000">,</font><font color="#009900">$lt</font><font color="#990000">,</font><font color="#009900">$mmax_date</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#990000">(</font><font color="#CC3333">""</font><font color="#990000">,</font><font color="#993399">1</font><font color="#990000">,</font><font color="#993399">0</font><font color="#990000">,</font><font color="#993399">0</font><font color="#990000">,</font><font color="#993399">0</font><font color="#990000">,</font><font color="#CC3333">""</font><font color="#990000">);</font>
      <b><font color="#3366FF">while</font></b> <font color="#990000">(</font><b><font color="#3366FF">my</font></b><font color="#990000">(</font><font color="#009900">$snapshot_date</font><font color="#990000">,</font> <font color="#009900">$severity</font><font color="#990000">,</font> <font color="#009900">$pcount</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#009900">$sth2</font><font color="#990000">-&gt;</font><b><font color="#000000">fetchrow_array</font></b><font color="#990000">())</font> <font color="#CC3333">{</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$sql3</font> <font color="#990000">=</font> <b><font color="#3366FF">qq</font></b><font color="#CC3333">{</font> SELECT <b><font color="#000000">max</font></b><font color="#990000">(</font>published<font color="#990000">)</font> FROM vulnerabilities<font color="#990000">.</font>nvdcve where
<b><font color="#000000">date_format</font></b><font color="#990000">(</font>published<font color="#990000">,</font><font color="#CC3333">'%Y-%m'</font><font color="#990000">)=?</font> <font color="#CC3333">}</font><font color="#990000">;</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$sth3</font> <font color="#990000">=</font> <font color="#009900">$dbh</font><font color="#990000">-&gt;</font><b><font color="#000000">prepare</font></b><font color="#990000">(</font> <font color="#009900">$sql3</font> <font color="#990000">);</font>
         <b><font color="#3366FF">my</font></b> <font color="#009900">$rc3</font> <font color="#990000">=</font> <font color="#009900">$sth3</font><font color="#990000">-&gt;</font><b><font color="#000000">execute</font></b><font color="#990000">(</font><font color="#009900">$snapshot_date</font><font color="#990000">);</font>
         <font color="#009900">$max_date</font> <font color="#990000">=</font>  <font color="#009900">$sth3</font><font color="#990000">-&gt;</font><b><font color="#000000">fetchrow_array</font></b><font color="#990000">();</font>
         <font color="#009900">$max_date</font> <font color="#990000">=~</font> <b><font color="#3366FF">s</font></b><font color="#FF6600">/ \S+$//</font><font color="#990000">;</font>
         <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$change</font> ne <font color="#009900">$snapshot_date</font><font color="#990000">)</font> <font color="#CC3333">{</font>
            <b><font color="#3366FF">if</font></b> <font color="#990000">(!</font> <font color="#009900">$virgin</font><font color="#990000">)</font> <font color="#CC3333">{</font>
                <b><font color="#3366FF">my</font></b><font color="#990000">(</font><font color="#009900">$year</font><font color="#990000">,</font><font color="#009900">$month</font><font color="#990000">,</font><font color="#009900">$day</font><font color="#990000">)</font> <font color="#990000">=</font> <b><font color="#3366FF">split</font></b><font color="#990000">(</font><font color="#CC3333">"-"</font><font color="#990000">,</font><font color="#009900">$mmax_date</font><font color="#990000">);</font>
                <b><font color="#3366FF">my</font></b> <font color="#009900">$mmonth</font> <font color="#990000">=</font> <font color="#009900">$month</font><font color="#990000">;</font>
                <font color="#009900">$month</font><font color="#990000">--;</font>
                <font color="#009900">$graph_data</font> <font color="#990000">.=</font> <b><font color="#3366FF">qq</font></b><font color="#990000">!</font>           <font color="#990000">[</font>new <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#009900">$year</font><font color="#990000">,</font> <font color="#009900">$month</font><font color="#990000">,</font> <font color="#009900">$day</font><font color="#990000">),</font><font color="#009900">$ht</font><font color="#990000">,</font><font color="#009900">$mt</font><font color="#990000">,</font><font color="#009900">$lt</font><font color="#990000">],</font>
<font color="#990000">!;</font>
                <font color="#009900">$table_data</font> <font color="#990000">.=</font> <b><font color="#3366FF">qq</font></b><font color="#990000">!</font>           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font>new <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#009900">$year</font><font color="#990000">,</font> <font color="#009900">$month</font><font color="#990000">,</font> <font color="#009900">$day</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="$web_link/cvealerts.php?date=$year-$mmonth"&gt;$mmax_date&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#009900">$ht</font><font color="#990000">,</font><font color="#009900">$mt</font><font color="#990000">,</font><font color="#009900">$lt</font><font color="#990000">],</font>
<font color="#990000">!;</font>
                <font color="#990000">(</font><font color="#009900">$ht</font><font color="#990000">,</font><font color="#009900">$mt</font><font color="#990000">,</font><font color="#009900">$lt</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#990000">(</font><font color="#993399">0</font><font color="#990000">,</font><font color="#993399">0</font><font color="#990000">,</font><font color="#993399">0</font><font color="#990000">);</font>
             <font color="#CC3333">}</font>
             <font color="#009900">$change</font> <font color="#990000">=</font> <font color="#009900">$snapshot_date</font><font color="#990000">;</font>
          <font color="#CC3333">}</font>
          <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$severity</font> <b><font color="#3366FF">eq</font></b> <font color="#CC3333">"HIGH"</font><font color="#990000">)</font> <font color="#CC3333">{</font> <font color="#009900">$ht</font> <font color="#990000">=</font> <font color="#009900">$pcount</font><font color="#990000">;</font> <font color="#CC3333">}</font>
          <b><font color="#3366FF">elsif</font></b> <font color="#990000">(</font><font color="#009900">$severity</font> <b><font color="#3366FF">eq</font></b> <font color="#CC3333">"MEDIUM"</font><font color="#990000">)</font> <font color="#CC3333">{</font> <font color="#009900">$mt</font> <font color="#990000">=</font> <font color="#009900">$pcount</font><font color="#990000">;</font> <font color="#CC3333">}</font>
          <b><font color="#3366FF">elsif</font></b> <font color="#990000">(</font><font color="#009900">$severity</font> <b><font color="#3366FF">eq</font></b> <font color="#CC3333">"LOW"</font><font color="#990000">)</font> <font color="#CC3333">{</font> <font color="#009900">$lt</font> <font color="#990000">=</font> <font color="#009900">$pcount</font><font color="#990000">;</font> <font color="#CC3333">}</font>
          <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$mmax_date</font> <b><font color="#3366FF">eq</font></b> <font color="#CC3333">""</font><font color="#990000">)</font> <font color="#CC3333">{</font> <font color="#009900">$mmax_date</font> <font color="#990000">=</font> <font color="#009900">$max_date</font><font color="#990000">;</font> <font color="#CC3333">}</font>
          <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$mmax_date</font> lt <font color="#009900">$max_date</font><font color="#990000">)</font> <font color="#CC3333">{</font> <font color="#009900">$mmax_date</font> <font color="#990000">=</font> <font color="#009900">$max_date</font><font color="#990000">;</font> <font color="#CC3333">}</font>
          <font color="#009900">$virgin</font> <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
      <font color="#CC3333">}</font>
      <b><font color="#3366FF">my</font></b><font color="#990000">(</font><font color="#009900">$year</font><font color="#990000">,</font><font color="#009900">$month</font><font color="#990000">,</font><font color="#009900">$day</font><font color="#990000">)</font> <font color="#990000">=</font> <b><font color="#3366FF">split</font></b><font color="#990000">(</font><font color="#CC3333">"-"</font><font color="#990000">,</font><font color="#009900">$mmax_date</font><font color="#990000">);</font>
      <b><font color="#3366FF">my</font></b> <font color="#009900">$mmonth</font> <font color="#990000">=</font> <font color="#009900">$month</font><font color="#990000">;</font>
      <font color="#009900">$month</font><font color="#990000">--;</font>
      <font color="#009900">$graph_data</font> <font color="#990000">.=</font> <b><font color="#3366FF">qq</font></b><font color="#990000">!</font>           <font color="#990000">[</font>new <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#009900">$year</font><font color="#990000">,</font> <font color="#009900">$month</font><font color="#990000">,</font> <font color="#009900">$day</font><font color="#990000">),</font><font color="#009900">$ht</font><font color="#990000">,</font><font color="#009900">$mt</font><font color="#990000">,</font><font color="#009900">$lt</font><font color="#990000">]</font>
<font color="#990000">!;</font>
     <font color="#009900">$table_data</font> <font color="#990000">.=</font> <b><font color="#3366FF">qq</font></b><font color="#990000">!</font>           <font color="#990000">[</font><font color="#CC3333">{</font>v<font color="#990000">:</font>new <b><font color="#000000">Date</font></b><font color="#990000">(</font><font color="#009900">$year</font><font color="#990000">,</font> <font color="#009900">$month</font><font color="#990000">,</font> <font color="#009900">$day</font><font color="#990000">),</font>
              f<font color="#990000">:</font><font color="#CC3333">'&lt;a href="$web_link/cvealerts.php?date=$year-$mmonth"&gt;$mmax_date&lt;/a&gt;'</font><font color="#CC3333">}</font><font color="#990000">,</font> <font color="#009900">$ht</font><font color="#990000">,</font><font color="#009900">$mt</font><font color="#990000">,</font><font color="#009900">$lt</font><font color="#990000">],</font>
<font color="#990000">!;</font>
   <font color="#CC3333">}</font>
   <font color="#009900">$table_data</font> <font color="#990000">.=</font> <font color="#CC3333">"        ]);\n"</font><font color="#990000">;</font>
   <font color="#009900">$graph_data</font> <font color="#990000">.=</font> <font color="#CC3333">"        ]);\n"</font><font color="#990000">;</font>
   <font color="#009900">$slide</font> <font color="#990000">=</font> <font color="#009900">$slide_head</font> <font color="#990000">.</font>  <font color="#009900">$graph_data</font> <font color="#990000">.</font> <font color="#009900">$slide_head_table</font> <font color="#990000">.</font> <font color="#009900">$table_data</font> <font color="#990000">.</font> <font color="#009900">$slide_tail</font><font color="#990000">;</font>
   <b><font color="#3366FF">return</font></b><font color="#990000">(</font><font color="#009900">$slide</font><font color="#990000">);</font>
<font color="#CC3333">}</font>
<b><font color="#3366FF">sub</font></b> slide_body <font color="#CC3333">{</font>
  <b><font color="#3366FF">my</font></b><font color="#990000">(</font><font color="#009900">$graph_name</font><font color="#990000">,</font><font color="#009900">$title</font><font color="#990000">,</font><font color="#009900">$style</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#009900">@_</font><font color="#990000">;</font>
  <b><font color="#3366FF">my</font></b> <font color="#009900">$table_name</font> <font color="#990000">=</font> <font color="#009900">$graph_name</font> <font color="#990000">.</font> <font color="#CC3333">"_tab"</font><font color="#990000">;</font>
  <b><font color="#3366FF">my</font></b> <font color="#009900">$table_text</font> <font color="#990000">=</font> <font color="#CC3333">"div id=\"$table_name\""</font><font color="#990000">;</font>
  <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$style</font> ne <font color="#CC3333">""</font><font color="#990000">)</font> <font color="#CC3333">{</font>
     <font color="#009900">$table_text</font> <font color="#990000">.=</font> <font color="#CC3333">" style=\'$style\'"</font><font color="#990000">;</font>
  <font color="#CC3333">}</font>
  <b><font color="#3366FF">my</font></b> <font color="#009900">$slide2</font> <font color="#990000">=</font> <font color="#CC3333">"&lt;h3&gt;$title&lt;/h3&gt;\n"</font><font color="#990000">;</font>
  <b><font color="#3366FF">my</font></b> <font color="#009900">$itext</font> <font color="#990000">=</font> <font color="#CC3333">"div id=\"$graph_name\""</font><font color="#990000">;</font>
  <b><font color="#3366FF">if</font></b> <font color="#990000">(</font><font color="#009900">$style</font> ne <font color="#CC3333">""</font><font color="#990000">)</font> <font color="#CC3333">{</font>
     <font color="#009900">$itext</font> <font color="#990000">.=</font> <font color="#CC3333">" style=\'$style\'"</font><font color="#990000">;</font>
  <font color="#CC3333">}</font>
  <font color="#009900">$slide2</font> <font color="#990000">.=</font> <b><font color="#3366FF">qq</font></b><font color="#CC3333">{</font>
    <font color="#CC3333">&lt;table&gt;&lt;tr&gt;</font>
    <font color="#CC3333">&lt;td valign="top"&gt;&lt;$itext&gt;&lt;/div&gt;&lt;/td&gt;</font>
    <font color="#CC3333">&lt;td valign="top"&gt;&lt;$table_text&gt;&lt;/div&gt;&lt;/td&gt;</font>
    <font color="#CC3333">&lt;td valign="top"&gt;</font>   <font color="#CC3333">&lt;/td&gt;</font>
    <font color="#CC3333">&lt;td valign="top"&gt;&lt;div id="labels"&gt;&lt;/div&gt;&lt;/td&gt;</font>
    <font color="#CC3333">&lt;/tr&gt;&lt;/table&gt;</font>
  <font color="#CC3333">}</font><font color="#990000">;</font>
  <b><font color="#3366FF">return</font></b><font color="#990000">(</font><font color="#009900">$slide2</font><font color="#990000">);</font>
<font color="#CC3333">}</font>
<i><font color="#996633"># Main</font></i>
<b><font color="#3366FF">my</font></b> <font color="#009900">$web_link</font> <font color="#990000">=</font> <font color="#CC3333">"/nvd"</font><font color="#990000">;</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">$results_dir</font> <font color="#990000">=</font> <font color="#CC3333">"/data/html"</font> <font color="#990000">.</font> <font color="#009900">$web_link</font><font color="#990000">;</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">$result_file</font> <font color="#990000">=</font> <font color="#009900">$results_dir</font> <font color="#990000">.</font> <font color="#CC3333">"/nvdcve_stats.html"</font><font color="#990000">;</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">$debug</font> <font color="#990000">=</font> <font color="#993399">1</font><font color="#990000">;</font>
<b><font color="#3366FF">my</font></b> <font color="#009900">$db</font> <font color="#990000">=</font> <font color="#CC3333">"vulnerabilities"</font><font color="#990000">;</font>
<b><font color="#3366FF">local</font></b><font color="#990000">(</font><font color="#009900">$dbh</font><font color="#990000">)</font> <font color="#990000">=</font> DBI<font color="#990000">-&gt;</font><b><font color="#000000">connect</font></b><font color="#990000">(</font><font color="#CC3333">"DBI:mysql:$db:$db_host"</font><font color="#990000">,</font> <font color="#009900">$mysql_user</font><font color="#990000">,</font> <font color="#009900">$mysql_passwd</font><font color="#990000">)</font> <font color="#990000">||</font>
   <b><font color="#3366FF">die</font></b> <font color="#CC3333">"ERROR: Connecting: $DBI::errstr\n"</font><font color="#990000">;</font>
<font color="#009900">$slides_data</font> <font color="#990000">.=</font> <font color="#990000">&amp;</font><b><font color="#000000">slide_body</font></b><font color="#990000">(</font><font color="#CC3333">"s4graph"</font><font color="#990000">,</font><font color="#CC3333">"NVD CVE Alerts"</font><font color="#990000">,</font><font color="#CC3333">"width:700px; height:400px;"</font><font color="#990000">);</font>
<font color="#009900">$slides_head</font> <font color="#990000">.=</font> <font color="#990000">&amp;</font><b><font color="#000000">slide_nvd_alerts</font></b><font color="#990000">(</font><font color="#CC3333">""</font><font color="#990000">,</font><font color="#CC3333">"s4graph"</font><font color="#990000">,</font><font color="#009900">$web_link</font><font color="#990000">,</font><font color="#009900">$dbh</font><font color="#990000">);</font>
<b><font color="#3366FF">open</font></b><font color="#990000">(</font>OUTFILE<font color="#990000">,</font><font color="#CC3333">"&gt;$result_file"</font><font color="#990000">);</font>
<b><font color="#3366FF">print</font></b> OUTFILE <font color="#CC3333">"&lt;HTML&gt;\n&lt;HEAD&gt;&lt;TITLE&gt;NVD CVE Statistics&lt;/TITLE&gt;\n"</font><font color="#990000">;</font>
<b><font color="#3366FF">print</font></b> OUTFILE <font color="#CC3333">"&lt;script type=\"text/javascript\" src=\"http://www.google.com/jsapi\"&gt;&lt;/script&gt;\n"</font><font color="#990000">;</font>
<b><font color="#3366FF">print</font></b> OUTFILE <font color="#009900">$slides_head</font><font color="#990000">;</font>
<b><font color="#3366FF">print</font></b> OUTFILE <font color="#CC3333">"&lt;/HEAD&gt;\n&lt;BODY&gt;\n"</font><font color="#990000">;</font>
<b><font color="#3366FF">print</font></b> OUTFILE <font color="#009900">$slides_data</font><font color="#990000">;</font>
<b><font color="#3366FF">print</font></b> OUTFILE <font color="#CC3333">"&lt;/BODY&gt;\n"</font><font color="#990000">;</font>
<b><font color="#3366FF">close</font></b><font color="#990000">(</font>OUTFILE<font color="#990000">);</font>
<b><font color="#3366FF">exit</font></b><font color="#990000">;</font>
</tt></pre>
</p>
<p><h3>Other Charting Options</h3>
</p>
<p>
Google, Google users, and other companies have <a href="http://code.google.com/apis/visualization/documentation/gallery.html">shared</a> some JavaScript visualizations built on the Google Visualization API to help you get started.  Below are some example:
</p>
<table class="gviz_gallery" id="gviz_gallery" cellpadding="2" cellspacing="0">
<tr class="gallery_filter_featured gallery_filter_charts gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-annotatedtimeline.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://blog.securitymonks.com/apis/visualization/documentation/gallery/annotatedtimeline.html">Annotated Time Line</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">An animated time series chart.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_charts gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/areachart.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-areachart.png" height="60" width="120" /></a></td>
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/areachart.html"  class="gallery_doc_title">Area Chart </a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">Interactive area chart.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_charts gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/barchart.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-barchart.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://blog.securitymonks.com/apis/visualization/documentation/gallery/barchart.html">Bar Chart</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">Interactive bar chart.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_featured gallery_filter_charts gallery_filter_fun">
<td><a href="http://visapi-gadgets.googlecode.com/svn/trunk/barsofstuff/doc.html" onclick="return warn()"><br />
    <img src="http://visapi-gadgets.googlecode.com/svn/trunk/barsofstuff/icon.png" height="60" width="120" /></a></td>
<td><a href="http://visapi-gadgets.googlecode.com/svn/trunk/barsofstuff/doc.html" class="gallery_doc_title" onClick="return warn()">Bars of Stuff</a></p>
<p class="gallery_description">Fun bar charts using images of trains, chocolate, worms, and more.</p>
<p class="gallery_author">By: The visapi project</p>
</td>
</tr>
<tr class="gallery_filter_charts">
<td><a href="http://informatics.systemsbiology.net/visualizations/heatmap/bioheatmap.html" onclick="return warn()"><img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/bioheatmap_screenshot.png" height="60" width="120" /></a></td>
<td><a href="http://informatics.systemsbiology.net/visualizations/heatmap/bioheatmap.html" class="gallery_doc_title" onClick="return warn()">Bio Heat Map</a></p>
<p class="gallery_description">Heatmaps are a useful way to visualize matricies of data. Scientists often use green-black-red heatmaps to visualize gene expression data from microarrays. This visualization supports both three color heatmaps (ex: green to black to red) and two color heatmaps (ex: white to yellow).</p>
<p class="gallery_author">By: <a href="http://www.systemsbiology.org/">Institute for Systems Biology</a></p>
</td>
</tr>
<tr class="gallery_filter_charts gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/columnchart.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-columnchart.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://code.google.com/apis/visualization/documentation/gallery/columnchart.html">Column Chart</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">Interactive column chart.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_featured gallery_filter_project">
<td><a href="http://www.drasticdata.nl/DrasticTreemapGApi/index.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-drastictreemap.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://www.drasticdata.nl/DrasticTreemapGApi/index.html">Drastic Treemap</a></p>
<p class="gallery_description">A dynamic treemap in Flash.</p>
<p class="gallery_author">By: <a href="http://www.drasticdata.nl">DrasticData</a></p>
</td>
</tr>
<tr class="gallery_filter_featured gallery_filter_charts">
<td><a href="http://danvk.org/dygraphs/"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-dygraphs.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://danvk.org/dygraphs/">Dygraphs</a></p>
<p class="gallery_description">The dygraphs JavaScript library produces interactive, zoomable charts of time series.</p>
<p class="gallery_author">By: Dan Vanderkam</p>
</td>
</tr>
<tr class="gallery_filter_tables">
<td><a href="http://informatics.systemsbiology.net/visualizations/heatmap/FilterDataTableControl.html" onclick="return warn()"><img src="http://systemsbiology-visualizations.googlecode.com/svn/trunk/src/main/images/icon_filterDataTableControl.png" height="60" width="120" /></a></td>
<td><a href="http://informatics.systemsbiology.net/visualizations/heatmap/FilterDataTableControl.html" class="gallery_doc_title" onClick="return warn()">Filters </a></p>
<p class="gallery_description">A Visualization that acts as a control over other visualizations. It is rendered within the browser using HTML. This visualization offers the ability to select some criteria to filter the DataTable used by the controlled visualizations.</p>
<p class="gallery_author">By: <a href="http://www.systemsbiology.org/">Institute for Systems Biology</a></p>
</td>
</tr>
<tr class="gallery_filter_featured gallery_filter_charts gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/gauge.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04//icon-gauge.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://code.google.com/apis/visualization/documentation/gallery/gauge.html">Gauge</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">Each numeric value is displayed as a gauge.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_maps gallery_filter_featured gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/geomap.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04//icon-geomap.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://code.google.com/apis/visualization/documentation/gallery/geomap.html">Geo Map</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">A map of a country, continent, or region map, with colors and values assigned to specific regions. Values are displayed as a color scale, and you can specify optional hovertext for regions.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_maps gallery_filter_featured gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/intensitymap.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-intensitymap.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://code.google.com/apis/visualization/documentation/gallery/intensitymap.html">Intensity Map</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">An intensity map that highlights regions or countries based on relative values.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_charts gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/linechart.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-linechart.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://code.google.com/apis/visualization/documentation/gallery/linechart.html">Line Chart</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">Interactive line chart.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_featured gallery_filter_charts gallery_filter_tables gallery_filter_analytics">
<td><a href="http://magic-table.googlecode.com/svn/trunk/magic-table/google_visualisation/example_1.html" onclick="return warn()"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/scatterplot_google_thumb.png" height="60" width="120" /></a></td>
<td><a href="http://magic-table.googlecode.com/svn/trunk/magic-table/google_visualisation/example_1.html" class="gallery_doc_title" onClick="return warn()">Magic-Table</a></p>
<p class="gallery_description">The Magic Table is a JavaScript library that allows you to see more in your data by applying some simple visual techniques to transform a table. The table is displayed in the browser by the canvas element. Internet Explorer is not supported.</p>
<p class="gallery_author">By: <a href="http://code.google.com/p/magic-table/">Greg Ross</a></p>
</td>
</tr>
<tr class="gallery_filter_maps gallery_filter_featured gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/map.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-map.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://code.google.com/apis/visualization/documentation/gallery/map.html">Map</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">An interactive map that uses the <a href="http://code.google.com/apis/maps">Google Maps API</a>.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_featured gallery_filter_charts gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/motionchart.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-motionchart.png" height="60" width="120" /></a></td>
<td>
<p><a class="gallery_doc_title" href="http://code.google.com/apis/visualization/documentation/gallery/motionchart.html">Motion Chart</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">Motion Chart: A dynamic flash based chart to explore several indicators over time. Required columns: bubble name, time and 2 columns of numeric values. Optional columns: Numeric values or categories.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_featured gallery_filter_google gallery_filter_project">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/orgchart.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-orgchart.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://code.google.com/apis/visualization/documentation/gallery/orgchart.html">Organizational Chart</a></p>
<p class="gallery_description">A <a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a> simple organizational chart.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_charts">
<td><a href="http://parallel-coordinates.googlecode.com/svn/trunk/documentation/documentation.html" onclick="return warn()"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/parallelcords.jpg" height="60" width="120" /></a></td>
<td><a href="http://parallel-coordinates.googlecode.com/svn/trunk/documentation/documentation.html" class="gallery_doc_title" onClick="return warn()">Parallel Coordinates Chart</a></p>
<p class="gallery_description">Parallel Coordinates is a method of visualizing multivariate data. An n-dimensional space is represented as n parallel lines.  Works for browsers based on Gecko or Presto (does not work in IE). This is written in Javascript, no Flash required.</p>
<p class="gallery_author">By: <a href="http://sriharsha451.googlepages.com/">Sri Harsha Allamraju</a></p>
</td>
</tr>
<tr class="gallery_filter_charts gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/piechart.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-piechart.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://code.google.com/apis/visualization/documentation/gallery/piechart.html">Pie Chart</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">Interactive pie chart.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_featured gallery_filter_charts gallery_filter_fun">
<td><a href="http://visapi-gadgets.googlecode.com/svn/trunk/pilesofmoney/doc.html" onclick="return warn()"><br />
    <img src="http://visapi-gadgets.googlecode.com/svn/trunk/pilesofmoney/icon.png" height="60" width="120" /></a></td>
<td><a href="http://visapi-gadgets.googlecode.com/svn/trunk/pilesofmoney/doc.html" class="gallery_doc_title" onClick="return warn()">Piles of Money</a></p>
<p class="gallery_description">Column chart made of of money bills.</p>
<p class="gallery_author">By: The visapi project</p>
</td>
</tr>
<tr class="gallery_filter_charts gallery_filter_google">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/scatterchart.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-scatterchart.png" height="60" width="120" /></a></td>
<td><a class="gallery_doc_title" href="http://code.google.com/apis/visualization/documentation/gallery/scatterchart.html">Scatter Chart</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">Interactive scatter chart.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_google gallery_filter_tables">
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/table.html"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/icon-table.png" height="60" width="120" /></a></td>
<td><a href="http://code.google.com/apis/visualization/documentation/gallery/table.html"  class="gallery_doc_title">Table</a> (<a class="gallery_gwt_link" href="http://code.google.com/docreader/#p=gwt-google-apis&amp;s=gwt-google-apis&amp;t=Visualization">GWT Integrated</a>)</p>
<p class="gallery_description">A highly customizable table with sorting, paging and selection capabilities.</p>
<p class="gallery_author">By: Google</p>
</td>
</tr>
<tr class="gallery_filter_featured gallery_filter_text">
<td><a href="http://visapi-gadgets.googlecode.com/svn/trunk/termcloud/doc.html" onclick="return warn()"><br />
    <img src="http://visapi-gadgets.googlecode.com/svn/trunk/termcloud/icon.png" height="60" width="120" /></a></td>
<td><a href="http://visapi-gadgets.googlecode.com/svn/trunk/termcloud/doc.html" class="gallery_doc_title" onClick="return warn()">TermCloud</a></p>
<p class="gallery_description">A list of terms, where the size and color of each word is determined by a specified frequency value (typically the number of times it appears in some text).</p>
<p class="gallery_author">By: The visapi project</p>
</td>
</tr>
<tr class="gallery_filter_featured gallery_filter_maps">
<td><img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/thematicmapping.png" height="60" width="120" /></td>
<td><a href="http://thematicmapping.org/api/gvapi.php" class="gallery_doc_title" onClick="return warn()">Thematic Mapping API</a></p>
<p class="gallery_description">Enables visualization of data in Google Earth or other geobrowsers through the use of the Google Visualization API and KML.</p>
<p class="gallery_author"> By: <a href="http://thematicmapping.org/">Thematicmapping.org</a></p>
</td>
</tr>
<tr class="gallery_filter_text">
<td><a href="http://visapi-gadgets.googlecode.com/svn/trunk/wordcloud/doc.html" onclick="return warn()"><br />
    <img src="http://blog.securitymonks.com/wp-content/uploads/2010/04/worldcloud.png" height="60" width="120" /></a></td>
<td>
<p><a href="http://visapi-gadgets.googlecode.com/svn/trunk/wordcloud/doc.html" class="gallery_doc_title" onClick="return warn()">WordCloud</a>
      </p>
<p class="gallery_description">Displays all words in text with size and color based on the number of time each word appears.</p>
<p class="gallery_author">By: The visapi project</p>
</td>
</tr>
</table>
<p><h3>Additional Information</h3>
</p>
<p>
Below is the talk that Itai Raz, the lead engineer for the Visualization API product at Google, gave at <a href="http://code.google.com/events/io/2009/">Google I/O 2009</a> titled &#8220;Using the Visualization API with GWT:&#8221;
</p>
<p>
<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/5PV8OH-ML-Q&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en_US&#038;feature=player_embedded&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/5PV8OH-ML-Q&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en_US&#038;feature=player_embedded&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="385"></embed></object>
</p>
<p><h3>Additional Possibilities</h3>
</p>
<p>
The work above is meant only to serve as a starting point.  There is a great deal more information to expand upon.  For example, we began this post pulling some information from the XML schema for CVE-2010-1228.  One field we did not pull out from the XML file is:
</p>
<p><pre>    &lt;vuln:cwe id="CWE-362" /&gt;
</pre>
</p>
<p>
The Common Weakness Enumeration (CWE) represents vulnerability types and NIST provides a <a href="http://nvd.nist.gov/cwe.cfm#cwes">CWE Cross Section Mapped into by NVD</a> table.  In the above example, we see an entry:
</p>
<table Border="1">
<tr>
<th>Name</th>
<th width="66">CWE-ID</th>
<th>Description</th>
</tr>
<tr>
<td>
<a name="CWE-362"/>Race Conditions
</td>
<td width="66">
<a href = "http://cwe.mitre.org/data/definitions/362.html" target = "blank">CWE-362</a>
</td>
<td>The state of a resource can change between the time the resource is checked to when it is accessed.</td>
</tr>
</table>
<p>
Clicking on the link will take us to the MITRE site that provides a great deal more information on CWE entries.  It is easy enough to expand on the above program to harvest this information for a richer information database.
</p>
<p>
Another possibility is to expand the above program to pull additional information on the CVE entry.  In additional to the data in the NVD CVE XML file, we could pull information from the NVD site.  Using CVE-2010-1228 as an example, we could have the program pull down the page:
</p>
<p><pre>http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2010-1228</pre>
</p>
<p>
Notice the line:
</p>
<p>
<span class="label">CVSS v2 Base Score:</span><a href="http://nvd.nist.gov/cvss.cfm?version=2&amp;name=CVE-2010-1228&amp;vector=(AV%3AN/AC%3AL/Au%3AN/C%3AC/I%3AC/A%3AC)" target="_blank">10.0</a> (HIGH) <a href="http://nvd.nist.gov/cvss.cfm?version=2&amp;name=CVE-2010-1228&amp;vector=(AV%3AN/AC%3AL/Au%3AN/C%3AC/I%3AC/A%3AC)" target="_blank">(AV:N/AC:L/Au:N/C:C/I:C/A:C)</a> (<a href="http://nvd.nist.gov/cvss.cfm?vectorinfo&amp;version=2" target="_blank">legend</a>)
</p>
<p>
The <b>(AV:N/AC:L/Au:N/C:C/I:C/A:C)</b> provides values that were used in determining the base score.  If you follow the link, you will see the values used in the calculations:
</p>
<ul>
<li><strong>CVSS Base Score</strong>: 10
<ul>
<li><b>Impact Subscore</b>: 10</li>
<li><b>Exploitability Subscore</b>: 10</li>
</ul>
</li>
<li><b>CVSS Temporal Score</b>: Undefined</li>
<li><strong>CVSS Environmental Score</strong>: Undefined</li>
<li><strong>Overall CVSS Score</strong>: 10</li>
</ul>
<p>
NVD has made available <a href="http://nvd.nist.gov/cvsseq2.htm">the equations</a> used in calculating the CVSS base score, temporal score, and environmental score.
</p>
<p>
Three other pieces of information that might provide interesting groupings are:
</p>
<ul>
<li><b>Access Complexity</b>:  Low  **NOTE: Access Complexity scored Low due to insufficient information</li>
<li><b>Authentication</b>:  Not required to exploit</li>
<li><b>Impact Type</b>:  Allows unauthorized disclosure of information; Allows unauthorized modification; Allows disruption of service</li>
</ul>
<p>
What information is of interest and how it is used will be dependent on your organization.  There is a great deal of information available and many directions you start examining.
</p>
<p><h3>Final Thoughts</h3>
</p>
<p>
I am often reminded of the old phrase, “Trust us, we are from the government.”   No one really trusts anyone, especially when it comes to matters they do not understand.  Just because you are from the security group at your organization, is that reason enough for the CEO to give you unlimited money and authority to do what you see fit?  Of course not.  While management might trust you, they may not believe that you are capable of seeing the big picture.  That is after all their job.
</p>
<p>
Another great old saying is that “the devil is in the details.”  Those details will likely fall in the security domain.  In organization across the planet there is a tug of war between the details and the big picture with multiple groups adding in their opinions and views.  You need to make the details understandable to your higher management to effectively argue your view.  Finding effective metrics and finding clear representation is essential in today&#8217;s business.  Google Visualization can be a useful tool in accomplishing this task.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2010/04/16/google-visualization-an-example-graphing-nvd-cve-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Request Tracker Installation  (Part 2 of 2)</title>
		<link>http://blog.securitymonks.com/2008/08/03/request-tracker-installation-part-2-of-2/</link>
		<comments>http://blog.securitymonks.com/2008/08/03/request-tracker-installation-part-2-of-2/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 02:33:46 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Leopard]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[ModSecurity]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[NIST]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Request Tracker]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/?p=211</guid>
		<description><![CDATA[Awhile back, I posted &#8220;Request Tracker Installation  (Part 1 of 2),&#8221; which provided information and additional links concerning Request Tracker (RT).  As a reminder, RT is an enterprise-grade ticketing system which allows for the checking of the status of various tasks including when the tasks were requested, who requested the tasks and why, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/images/opensource.jpg" alt="Open Source Installation" align="left"/>Awhile back, I posted &#8220;<a href="http://blog.securitymonks.com/category/request-tracker">Request Tracker Installation  (Part 1 of 2)</a>,&#8221; which provided information and additional links concerning <a href="http://bestpractical.com/rt/">Request Tracker (RT)</a>.  As a reminder, RT is an enterprise-grade ticketing system which allows for the checking of the status of various tasks including when the tasks were requested, who requested the tasks and why, when the tasks were completed, prioritizing, etc.  I delayed the second part of the post, which was to step through installation of RT, until I could add some background information.  I wanted to walk through implementing secure open source software such as <a href="http://www.apache.org/">Apache</a>, <a href="http://www.php.net">PHP</a>, <a href="http://www.mysql.com">MySQL</a>, <a href="http://www.openssl.org">OpenSSL</a>, and <a href="http://www.modsecurity.org">ModSecurity</a>.  No small task.  It is all about integration both in terms of security and the power that a software package like RT can provide your organization.  That is why I selected the image on the left of all these various open source software symbols for this post on RT.</p>
<p>
If you are going to be using RT, you need to get the &#8220;<a href="http://rtbook.bestpractical.com/">RT Essentials</a>&#8221; book written by Jesse Vincent, Robert Spier, Dave Rolsky, Darren Chamberlain, and Richard Foley.  It is a good reference and a quick read.  For up-to-date information, see the <a href="http://wiki.bestpractical.com/view/HomePage">RT Wiki</a> and the <a href="http://blog.bestpractical.com/">Best Practical Solutions blog site</a>.
</p>
<p><h3>Prerequisites</h3>
<p>To start, please review the following posts:</p>
<ol>
<li><a href="http://blog.securitymonks.com/2008/04/14/an-apache-implementation/">An Apache Implementation</a>
	</li>
<li><a href="http://blog.securitymonks.com/2008/04/24/apache-and-openssl/">Apache and OpenSSL</a></li>
<li><a href="http://blog.securitymonks.com/2008/04/21/php-implementation/">PHP Implementation</a></li>
<ul>
<li><a href="http://blog.securitymonks.com/2008/04/21/php-as-a-module/">PHP as a Module</a></li>
<li><a href="http://blog.securitymonks.com/2008/04/21/php-as-a-cgi/">PHP as a CGI</a></li>
<li><a href="http://blog.securitymonks.com/2008/04/21/php-configuration-modifications/">PHP Configuration Modifications</a></li>
</ul>
<li><a href="http://blog.securitymonks.com/2008/04/07/introduction-to-mysql/">Introduction to MySQL</a></li>
<li><a href="http://blog.securitymonks.com/2008/02/28/setting-up-and-securing-mysql-references/">Setting Up and Securing MySQL: References</a></li>
<li><a href="http://blog.securitymonks.com/2008/07/31/implementing-a-web-application-firewall-with-modsecurity/">Implementing a Web Application Firewall with ModSecurity</a></li>
</ol>
<h3>Install Software</h3>
<p>With Apache, MySQL, PHP, OpenSSL, and ModSecurity installed, we are now ready to focus on software packages required by RT.</p>
<h4><strong>1.  Installing <a href="http://expat.sourceforge.net/">expat</a>.</strong></h4>
<p>Different operating systems will vary on whether <a href="http://expat.sourceforge.net/">expat</a>, the XML parser, is installed.  Expat is needed to complete the cpan install for <a href="http://perl-rss.sourceforge.net/">XML::RSS</a>.  Check your particular operating system.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://downloads.sourceforge.net/expat/expat-2.0.1.tar.gz
 /usr/local/src root# tar xzf expat-2.0.1.tar.gz
 /usr/local/src root# cd expat-2.0.1
 /usr/local/src/expat-2.0.1 root# ./configure
 /usr/local/src/expat-2.0.1 root# make
 /usr/local/src/expat-2.0.1 root# make check
 /usr/local/src/expat-2.0.1 root# make install
</pre>
</td>
</table>
<p></p>
<h4><strong>2.  Install FastCGI</strong></h4>
<p>For RT, you can install <a href="http://perl.apache.org/">mod_perl</a> or <a href="http://www.fastcgi.com/">mod_fastcgi</a>.  In this posting, we are going to walks through the installation of FastCGI.  Information concerning mod_perl will be provided below so the reader can chose what fits best in their environment.  FastCGI is much simpler to install and allows the core Apache process to stay small in size.  With FastCGI, RT runs as a separate process from Apache allowing RT to be stopped and restarted without affecting the Apache server.  In general, FastCGI programs are easier to manage.
</p>
<p>
The Apache module mod_fastcgi allows a web server to run CGI scripts via a separate, persistent program.  PHP comes with FastCGI support compiled in by default, so nothing needs to be done to the PHP installation.
</p>
<p>
You can have the Apache program call FastCGI, and have it run as the same user as the Apache server or use suexec to have FastCGI switch to a different user.  Under some operating systems, suexec may not get compiled and installed when installing Apache.  Check if suexec is installed, and if not go back to the Apache source, compile it, and install it.  Initially, we are not going to use the suexec program.  Instead we will create the group &#8220;rt&#8221;, add user httpd to group rt, and set permissions that way.  You may choose later to use suexec.  </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# ls -la /usr/local/apache/bin/suexec
ls: /usr/local/apache/bin/suexec: No such file or directory
 root# cd /usr/local/src/httpd-2.2.8
 /usr/local/src/httpd-2.2.8 root# make suexec
 /usr/local/src/httpd-2.2.8 root# cp ./support/suexec /usr/local/apache/bin/suexec
</pre>
</td>
</table>
<p>
Now, we are ready to get mod_fastcgi installed.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
 /usr/local/src root# tar xzf mod_fastcgi-2.4.6.tar.gz
 /usr/local/src root# cd mod_fastcgi-2.4.6
 /usr/local/src/mod_fastcgi-2.4.6 root# cp Makefile.AP2 Makefile
 /usr/local/src/mod_fastcgi-2.4.6 root# make top_dir=/usr/local/apache
 /usr/local/src/mod_fastcgi-2.4.6 root# make top_dir=/usr/local/apache install
 /usr/local/src/mod_fastcgi-2.4.6 root# /usr/local/apache/bin/apachectl stop
 /usr/local/src/mod_fastcgi-2.4.6 root# vi /usr/local/apache/conf/httpd.conf
</pre>
</td>
</table>
<p>
Add the following lines to the Apache httpd.conf file:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
# Load the mod_fastcgi module.
LoadModule fastcgi_module modules/mod_fastcgi.so
</pre>
</td>
</table>
<p>
Check if installation and configuration is working.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/mod_fastcgi-2.4.6 root# /usr/local/apache/bin/apachectl configtest
Syntax OK
 /usr/local/src/mod_fastcgi-2.4.6 root# /usr/local/apache/bin/apachectl start
 /usr/local/src/mod_fastcgi-2.4.6 root# cat /var/www/logs/error_log | grep -i fastcgi
[Fri Aug 01 12:17:22 2008] [notice] FastCGI: process manager initialized (pid 15221)
[Fri Aug 01 12:17:22 2008] [notice] Apache/2.2.8 (Unix) mod_ssl/2.2.8
OpenSSL/0.9.7a mod_fastcgi/2.4.6 configured -- resuming normal operations
</pre>
</td>
</table>
<p>
For in depth coverage of mod_perl, <a href="http://stason.org/">Stas Bekman</a> and <a href="http://www.oreillynet.com/pub/au/999">Eric Cholet</a> have written the book, &#8220;<a href="http://modperlbook.org/">Practical mod_perl</a>.&#8221;  They have made the complete book available online in both <a href="http://modperlbook.org/html/index.html">HTML</a> and <a href="http://modperlbook.org/pdf/index.html">PDF</a> format under the <a href="http://creativecommons.org/">Creative Commons</a> Attributes Share-Alike License.  <a href="http://stason.org/">Stas Bekman</a> and <a href="http://www.onyxneon.com/people/jim_brandt.html">Jim Brandt</a> have also written the &#8220;<a href="http://www.amazon.com/gp/product/0977920119?ie=UTF8&#038;tag=theultimatlearna&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0977920119">mod_perl2 User&#8217;s Guide Book</a>&#8221; where 50% of the book&#8217;s proceeds go to <a href="http://www.perlfoundation.org/">The Perl Foundation</a>.
</p>
<p>
If you are installing under Mac OS X, mod_perl may complain about Perl 5.8.8 being built without threads and you will get a message about building perl with -Duserthreads.  If you are determined to use mod_perl, consider dropping back to Apache 1.3.x and using mod_perl 1.x.  While Apache 1.3.x is legacy code, and I tend to want to use the code that is being actively developed, there is an argument for using Apache 1.3.x.  One major feature of Apache 2.x is threading. On Windows, where most basic libraries are and must be threadsafe, Apache 2 is really the only choice.  <a href="http://search.cpan.org/~nwclark/perl-5.8.8/README.macosx">Earlier Mac OS X</a> releases did not include a completely thread-safe libc, so threading is still not fully supported in Perl.  This is why the Perl version that comes with Mac OS X is not compiled to use threads.  To use  Apache2.x, Perl will need to be configured to use threads.  The code is available from the <a href="http://www.perl.com/download.csp">Perl web site</a>.
</p>
<p>
Rather than getting bogged down in compiling Perl to use thread, we will move ahead and use FastCGI.  By the time this post, I will have worked on getting RT installed under Linux, Mac OS X, and FreeBSD.  Figuring out what software works best in a multi OS environment can be challenging.  </p>
<h4><strong>3. Configure RT</strong></h4>
<p>Let us start by adding the group RT.  Under many operating systems, this would be done with the simple command &#8220;<strong>groupadd rt</strong>.&#8221;  Things are always more interesting under Mac OS X, where you would have to first look at what group ids (gid), choose an unused gid, and then create the rt group using that gid.  Under Mac OS X Leopard, group rt would be created with the commands:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# dscl . list /groups PrimaryGroupID | sort -k 2,2 -n
 root# dscl . create /groups/rt gid gid-of-rt
 root# dscl . create /groups/rt passwd '*'
 root# dscl . read /groups/rt
AppleMetaNodeLocation: /Local/Default
Password: *
PrimaryGroupID: gid-of-rt
RecordName: rt
RecordType: dsRecTypeNative:groups
</pre>
</td>
</table>
<p>
RT&#8217;s primary maintenance and documentation site is <a href="http://www.bestpractical.com">http://www.bestpractical.com</a>.   Documentation can be found at the Best Practical Solutions RT Wiki located at <a href="http://wiki.bestpractical.com/view/HomePage">http://wiki.bestpractical.com/</a>. The latest TAR/GZ is located at <a href="http://download.bestpractical.com/pub/rt/release/rt.tar.gz">http://download.bestpractical.com/pub/rt/release/rt.tar.gz</a>. The lack of any version numbers means the version can be updated at any time. The latest version, as of this writing, is 3.8.0.
</p>
<p>
The following are the steps for downloading and configuring RT:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://download.bestpractical.com/pub/rt/release/rt.tar.gz
 /usr/local/src root# tar xzf rt.tar.gz
 /usr/local/src root# cd rt-3.8.0
 /usr/local/src/rt-3.6.5 root# ./configure \
  --with-web-user="httpd" \
  --with-web-group="httpd" \
  --with-rt-user="httpd" \
  --with-rt-group="rt"
</pre>
</td>
</table>
<p></p>
<h4><strong>4.  Install Apache::TEST</strong></h4>
<p>Perl module Apache::TEST will not allow you to run the test check as root. You can download the module separately as a non root user and after configuring, compiling, and testing the program, you install it as root.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# su - goofy
 ~$ cd src
 ~/src goofy$ wget http://search.cpan.org/CPAN/authors/id/P/PH/PHRED/Apache-Test-1.30.tar.gz
 ~/src goofy$ tar xzf Apache-Test-1.30.tar.gz
 ~/src goofy$ cd Apache-Test-1.30
 ~/src goofy$ perl Makefile.PL
 ~/src goofy$ make
 ~/src goofy$ make test
 ~/src goofy$ sudo su root
 root# make instal
</pre>
</td>
</table>
<p></p>
<h4><strong>5.  Run fixdeps Command and Install Perl Modules</strong></h4>
<p>Now you are ready to utilize the <strong>fixedeps</strong> utility that comes with RT to install required Perl modules.  There is also the <strong>testdeps</strong> utility to test if all dependencies are installed and RT is ready to be installed.  You may need to run fixdeps multiple times before testdeps reports that you have all required software packages.  The first time through, it can take awhile (depending on your installation).  Be aware that some perl modules may need to be installed manually.  It various depending on OS and your environment.  You will be able to tell which modules need manual installation by the final message provided by the fixdeps program.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src/rt-3.8.0
 /usr/local/src/rt-3.8.0 root# make fixdeps
 /usr/local/src/rt-3.8.0 root# make fixdeps
 /usr/local/src/rt-3.8.0 root# make testdeps
</pre>
</td>
</table>
<p></p>
<h4><strong>6.  Install RT</strong></h4>
</p>
<p>
The final installation of RT is the easy part.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# make install
</pre>
</td>
</table>
<p></p>
<h4><strong>7.  Configure RT_SiteConfig.pm</strong></h4>
<p>We now will configure /opt/rt3/etc/RT_SiteConfig.pm.  In the next step a database user and a database will be setup.  We are only adding those values to the configuration file in this step.  I am going to set up a hostname (rt.securitymonks.com) for my current machine.  Please do not copy blindly.  Change this to your environment.  We will create the hostname so it only exists locally by adding an entry into the machines /etc/hosts file.  Right now, I am only going to access the Apache server from this machine.  In other words, the client and server will be on the same box.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# vi /etc/hosts
</pre>
</td>
</table>
<p>
Add the following line, adapting it to your organization:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# vi /etc/hosts
##
127.0.0.1       localhost
10.1.218.202   rt.securitymonks.com
</pre>
</td>
</table>
<p>
We are now ready to modify the RT_SiteConfig.pm file.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# vi /opt/rt3/etc/RT_SiteConfig.pm
</pre>
</td>
</table>
<p>
At minimum, add the following linesto /opt/rt3/etc/RT_SiteConfig.pm:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
Set($rtname, 'BRORT');
Set($Organization, 'securitymonks');

Set($CorrespondAddress , 'john@securitymonks.com');
Set($CommentAddress , 'john@securitymonks.com');

Set($Timezone , 'US/Eastern'); # obviously choose what suits you

# THE DATABASE:

Set($DatabaseType, 'mysql'); # e.g. Pg or mysql

# These are the settings we used above when creating the RT database,
# you MUST set these to what you chose in the section above.

Set($DatabaseUser , 'rtuser');
Set($DatabasePassword , 'secret');
Set($DatabaseName , 'rtdb');

# THE WEBSERVER:

Set($WebPath , '');
Set($WebBaseURL , 'https://rt.securitymonks.com');

# Logging
Set($LogToSyslog, '');
Set($LogToFile, 'debug');
Set($LogDir, '/opt/rt3/var/log');
Set($LogToFileNamed, "rt.log");
</pre>
</td>
</table>
<p></p>
<h4><strong>8.  Initialize the Database</strong></h4>
<p>RT needs to create the rtdb database, the rt db users, and initialize some tables.  This can be done with the command <strong>initialize-database</strong>, which should be run only once.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# make initialize-database
 /usr/local/bin/perl sbin/rt-setup-database --action init --dba root --prompt-for-dba-password
In order to create or update your RT database, this script needs to connect to your mysql
instance on localhost as root.  Please specify that user's database password below. If the
user has no database

password, just press return.

Password:
Working with:
Type:   mysql
Host:   localhost
Name:   rtdb
User:   rtuser
DBA:    root
Now creating a mysql database rtdb for RT.
Done.
Now populating database schema.
Done.
Now inserting database ACLs
Granting access to rtuser@'localhost' on rtdb.
Done.
Now inserting RT core system objects
Done.
Now inserting data
Done inserting data
Done.
</pre>
</td>
</table>
<p>
Check the MySQL database out.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# mysql -u rtuser -p
mysql> use rtdb;
</pre>
</td>
</table>
<p>
</p>
<h4><strong>9.  Modify Apache Configuration File</strong> </h4>
<p>Edit the /usr/local/apache/conf/httpd.conf file.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# /usr/local/apache/bin/apachectl stop
 /usr/local/src/rt-3.8.0 root# vi /usr/local/apache/conf/httpd.conf
</pre>
</td>
</table>
<p>
We are going to have the RT server run under our secure web server.  Find the &#8220;<strong>&#60virtualhost _default_:443&#62</strong>&#8221; line, change it to &#8220;<strong>&#60virtualhost 10.1.218.202:443&#62</strong>&#8220;.  Add the following lines to that section (adjusting to your environment):</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
   ServerName rt.securitymonks.com
   DocumentRoot /opt/rt3/share/html
   ErrorLog /usr/local/apache/logs/rt.error
   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
   CustomLog /usr/local/apache/logs/rt.access_log combined
   AddHandler fastcgi-script fcgi
   ScriptAlias / /opt/rt3/bin/mason_handler.fcgi/
</pre>
</td>
</table>
<p>
Add the user the Apache server runs as (httpd by default), to the RT group.  For non Mac OS X, modify group membership by editing the file /etc/group (<strong>vi /etc/group</strong>).  Mac OS X users need to user the dscl command.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# dscl . append /groups/rt GroupMembership httpd
 root# dscl . read /groups/rt
</pre>
</td>
</table>
<p>
Change the group and permission on the log area if you have told RT to log to /opt/rt3/var/log. </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# chgrp rt /opt/rt3/var/log
 root# chmod g+w /opt/rt3/var/log
</pre>
</td>
</table>
<p>
Test the configuration of the file, and if everything checks out start up Apache. </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/rt-3.8.0 root# /usr/local/apache/bin/apachectl configtest
Syntax OK
 /usr/local/src/rt-3.8.0 root# /usr/local/apache/bin/apachectl start
</pre>
</td>
</table>
<p>
 Remember there are now three files to check for problems with RT.
<ul>
<li>/opt/rt3/var/log/rt.log</li>
<li>/usr/local/apache/logs/rt.error</li>
<li>/usr/local/apache/logs/rt.access_log</li>
</ul>
<p>There are many configuration operations.  The options chosen in this post represents only the minimal to get RT running.  Please see the <a href="http://wiki.bestpractical.com/view/FastCGIConfiguration">RT Wiki&#8217;s FastCGIConfiguration</a> page for additional information.</p>
<h4><strong>10.  Access RT and Change the Default Password</strong> </h4>
<p><a href="http://blog.securitymonks.com/images/RT_login.jpg"><img align="left" width="150" title="ModifyUserImage" src="/images/RT_login.jpg"/></a>Now it is time to log in and change the default password.  Using the entry we made in our /etc/hosts file, we can now access the site by going to <strong>https://rt.securitymonks.com</strong>.  This URL should be different for your site.  You will see a login screen similar to the image on the left.</p>
<p>
Log in using the username &#8220;<strong>root</strong>&#8221; and password &#8220;<strong>password</strong>&#8220;.  Once logged in, you will see the screen similar to the image below (click on the image if you need to enlarge):<br />
<a href="http://blog.securitymonks.com/images/RT_ataglance.jpg"><img width="400" title="RT_at_a_glance" src="/images/RT_ataglance.jpg"/></a><br />
Over on the left menu bar, select &#8220;<strong>Configuration</strong>.&#8221;  That will bring you to the &#8220;RT Administration&#8221; screen:<br />
<a href="http://blog.securitymonks.com/images/RT_Administration.jpg"><img width="200" title="RT_administration" src="/images/RT_Administration.jpg"/></a><br />
Select, &#8220;<strong>Users</strong>.&#8221;  That will bring you to the &#8220;Select a user&#8221; screen:<br />
<a href="http://blog.securitymonks.com/images/RT_selectauser.jpg"><img width="300" title="RT_Select_a_User" src="/images/RT_selectauser.jpg"/></a><br />
Select the user &#8220;<strong>root</strong>,&#8221; which will bring you to the &#8220;Modify the user root&#8221; screen.  If you look at the lower left of the screen, there is a &#8220;Access Control area.&#8221;  There is a place to enter &#8220;New Password.&#8221;  Do so.  The screen looks like:<br />
<a href="http://blog.securitymonks.com/images/RT_modifyauser.png"><img width="200"  title="RT_Modify" src="/images/RT_modifyauser.png"/></a><br />
Make sure to hit the &#8220;Save Changes&#8221; button at the bottom of the screen.  With a working copy of RT, you are not ready to start adjusting configurations and working with the program.  For additional information, Please check out the “<a href="http://rtbook.bestpractical.com/">RT Essentials</a>” and the <a href="http://wiki.bestpractical.com/view/HomePage">RT Wiki</a> and the Best Practical Solutions <a href="http://blog.bestpractical.com/">blog site</a>.  Look for future posts to build upon the RT installation and database.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/08/03/request-tracker-installation-part-2-of-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Configuration Modifications</title>
		<link>http://blog.securitymonks.com/2008/04/21/php-configuration-modifications/</link>
		<comments>http://blog.securitymonks.com/2008/04/21/php-configuration-modifications/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 22:09:20 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/2008/04/21/php-configuration-modifications/</guid>
		<description><![CDATA[&#8220;Coming together is a beginning. Keeping together is progress. Working together is success.” &#8212; Henry Ford

Previously, posts discussed PHP Implementation, PHP as a Module, PHP as a CGI, and PHP over FastCGI.  This final post discusses some configuration considerations when implementing PHP.  Earlier, we copied the file php.ini-recommended to /usr/local/apache/php/lib/php.ini.  There are [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;<em>Coming together is a beginning. Keeping together is progress. Working together is success</em>.” &#8212; <a href="http://www.hfmgv.org/exhibits/hf/"><strong>Henry Ford</strong></a></p>
<p>
<a href="http://www.evaborka.co.nz/csardas_ver2.jpg"><img src="/images/csardas_ver2.jpg" alt="Configuration" align="left" width=90 /></a>Previously, posts discussed <a href="http://blog.securitymonks.com/2008/04/21/php-implementation/">PHP Implementation</a>, <a href="http://blog.securitymonks.com/2008/04/21/php-as-a-module/">PHP as a Module</a>, <a href="http://blog.securitymonks.com/2008/04/21/php-as-a-cgi/">PHP as a CGI</a>, and PHP over FastCGI.  This final post discusses some configuration considerations when implementing PHP.  Earlier, we copied the file php.ini-recommended to <strong>/usr/local/apache/php/lib/php.ini</strong>.  There are a few options that need to be configured for a more secure environment.  The below tables outline some options whose values should be understood and adjusted to your environment.  Links, provided by the <a href="http://phpsec.org/">PHP Security Consortium</a>, supply additional security considerations.  No matter which implementation of PHP you choose, make sure to understand the configuration options so you may run PHP as securely as possible.</p>
<table border=1>
<tr>
<th>Variable</th>
<th>Initial Value</th>
<th>Secure Value</th>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/allow_url_fopen.html">allow_url_fopen</a></td>
<td>Off</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">If enabled, allows URLs to be treated as files.  A large number of code injection vulnerabilities reported in PHP-based web applications are caused by the combination of enabling allow_url_fopen and bad input filtering.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/allow_url_fopen.html">allow_url_include</a></td>
<td>Off</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">If enabled, allows remote file access via the include and require statements.  If allow_url_fopen is disabled, allow_url_include is also disabled.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/display_errors.html">display_errors</a></td>
<td>Off</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">Determines whether error messages should be sent to the browser.  Messages frequently contain sensitive information.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/expose_php.html">expose_php</a></td>
<td>On</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">Decides whether PHP may expose the fact that it is installed on the server.  It reports in every request that PHP is being used to process the request, and what version of PHP is installed.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/file_uploads.html">file_uploads</a></td>
<td>On</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">Whether to allow HTTP file uploads.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/force_redirect.html">cgi.force_redirect</a></td>
<td>On</td>
<td>On</td>
</tr>
<tr>
<td colspan="3">Necessary to provide security running PHP as a CGI under most web servers.</td>
</tr>
<tr>
<td>disable_functions</td>
<td></td>
<td>openlog</td>
</tr>
<tr>
<td colspan="3">This directive allows you to disable certain functions for security reasons.  A malicious user could change the name under which the process is visable to syslog and have the Apache messages appear under a different name.</td>
</tr>
<tr>
<td>display_errors</td>
<td>Off</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">When enabled, display errors in the HTML page as they occur.</td>
</tr>
<tr>
<td>display_startup_errors</td>
<td>Off</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">When enabled, display errors during PHP&#8217;s startup sequence.</td>
</tr>
<tr>
<td>enable_dl</td>
<td>On</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">Whether or not to enable the dynamic module loading.  This directive is really only useful in the Apache module version of PHP.  One could write a custom extension to get around limitations imposed in the configuration file.</td>
</tr>
<tr>
<td>error_log</td>
<td></td>
<td>/var/www/logs/php/php_error_log</td>
</tr>
<tr>
<td colspan="3">Log errors to specified file.  Consider: <strong>cd /var/www/logs ; mkdir php ; chown httpd php</strong></td>
</tr>
<tr>
<td>error_reporting</td>
<td>E_ALL</td>
<td>E_ALL</td>
</tr>
<tr>
<td colspan="3">Set error logging to the maximum.</td>
</tr>
<tr>
<td>log_errors</td>
<td>On</td>
<td>On</td>
</tr>
<tr>
<td colspan="3">Log errors.  If left unspecified, log to Apache error log.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/magic_quotes_gpc.html">magic_quotes_gpc</a></td>
<td>Off</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">Magic quotes for incoming GET/POST/Cookie data.  Because it&#8217;s inconsistent and ineffective, it&#8217;s <strong>not</strong> recommended that magic_quotes_gpc be enabled.</td>
</tr>
<tr>
<td>max_input_time</td>
<td>60</td>
<td>60</td>
</tr>
<tr>
<td colspan="3">Maximum amount of time each script may spend parsing request data.  Measure and determine based on your applications.</td>
</tr>
<tr>
<td>max_execution_time</td>
<td>30</td>
<td>30</td>
</tr>
<tr>
<td colspan="3">Maximum execution time of each script, in seconds.  Measure performance of applications.  Decrease the value if possible.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/memory_limit.html">memory_limit</a></td>
<td>128M</td>
<td>8M</td>
</tr>
<tr>
<td colspan="3">Maximum amount of memory a script may consume (default 128MB). Unless you are sure you need more, keep memory_limit no higher than 8 megabytes.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/open_basedir.html">open_basedir</a></td>
<td></td>
<td>&#8220;/var/www/htdocs/&#8221;</td>
</tr>
<tr>
<td colspan="3">If set, limits all file operations to the defined directory and below.  Set open_basedir to only allow access to required portions of the filesystem, like your web site&#8217;s documents and any shared libraries. </td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/post_max_size.html">post_max_size</a></td>
<td>8M</td>
<td>300K</td>
</tr>
<tr>
<td colspan="3">Maximum size of POST data that PHP will accept.  By setting a realistic value here you can mitigate some of the damage by those attacks.  Value should be slightly higher than upload_max_filesize value.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/register_globals.html">register_globals</a></td>
<td>Off</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">Very dangerous.  It automatically transforms requested parameters into PHP global paramters.</td>
</tr>
<tr>
<td>safe_mode</td>
<td>Off</td>
<td>On</td>
</tr>
<tr>
<td colspan="3">An attempt to enhance security imposing a series of restrictions making execution more secure.  A <a href="http://us.php.net/features.safe-mode">full list</a> of safe_mode restrictions can be viewed off the PHP site.</td>
</tr>
<tr>
<td>safe_mode_exec_dir</td>
<td></td>
<td>/var/www/bin</td>
</tr>
<tr>
<td colspan="3">When safe_mode is on, only executables located in the safe_mode_exec_dir will be allowed to be executed via the exec family of functions.  The following functions are affected: exec(), system, passthru(), popen().  </td>
</tr>
<tr>
<td>safe_mode_gid</td>
<td>Off</td>
<td>On</td>
</tr>
<tr>
<td colspan="3">Safe Mode does a UID compare check when opening files.  If files create files at runtime access problems will occur.  Going to relax uid checking, using gid checking instead.</td>
</tr>
<tr>
<td>safe_mode_allowed_env_vars</td>
<td>PHP_</td>
<td>PHP_</td>
</tr>
<tr>
<td colspan="3">With safe mode, write access to environment variables is restricted.  Only variables with listed prefixes may be modified.</td>
</tr>
<tr>
<td>safe_mode_protected_env_vars</td>
<td>LD_LIBRARY_PATH</td>
<td>LD_LIBRARY_PATH</td>
</tr>
<tr>
<td colspan="3">Forbids certain variables from being altered.</td>
</tr>
<tr>
<td>session.save_path</td>
<td>/tmp</td>
<td>/var/www/sessions</td>
</tr>
<tr>
<td colspan="3">This setting specifies where session files should be saved when using the default session handler.  Set save_path to a folder that is outside the document root of your web site and not readable or writable by any other system users.  Any user who can list the contents of the /tmp folder can learn all active session identifiers and hijack sessions.  Consider: <strong>cd /var/www ; mkdir sessions; chown httpd sessions</strong></td>
</tr>
<tr>
<td>session.referer_check</td>
<td></td>
<td><your -domain></your></td>
</tr>
<tr>
<td colspan="3">When enabled, PHP will check the contents of the Referer request header.  It will protect against from simple cross-site request forger (<a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">CSRF</a>) attacks.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/upload_max_filesize.html">upload_max_filesize</a></td>
<td>2M</td>
<td>256K</td>
</tr>
<tr>
<td colspan="3">Maximum allowed size for uploaded files.  Attackers may attempt to send grossly oversized files to exhaust your system resources.</td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/upload_tmp_dir.html">upload_tmp_dir</a></td>
<td>/tmp</td>
<td>/var/www/tmp</td>
</tr>
<tr>
<td colspan="3">Set upload_tmp_dir to a folder that is outside the document root of your web site and not readable or writable by any other system users.  System default normally /tmp will be used.  Consider <strong>cd /var/www ; mkdir tmp; chown httpd tmp</strong></td>
</tr>
<tr>
<td><a href="http://phpsec.org/projects/phpsecinfo/tests/use_trans_sid.html">use_trans_sid</a></td>
<td>Off</td>
<td>Off</td>
</tr>
<tr>
<td colspan="3">When use_trans_sid is enabled, PHP will pass the session ID via the URL. This makes it far easier for a malicious party to obtain an active session ID and hijack the session.  Disable use_trans_sid in your PHP environment.</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/04/21/php-configuration-modifications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP as a CGI</title>
		<link>http://blog.securitymonks.com/2008/04/21/php-as-a-cgi/</link>
		<comments>http://blog.securitymonks.com/2008/04/21/php-as-a-cgi/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 22:07:24 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/2008/04/21/php-as-a-cgi/</guid>
		<description><![CDATA[&#8220;He who would learn to fly one day must first learn to stand and walk and run and climb and dance; one cannot fly into flying.&#8221; &#8212; Friedrich Nietzsche

In the initial post, &#8220;PHP Implementation&#8221; three ways to implement PHP were outlined.  In the previous post, PHP as a Module, PHP configured to run as [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;<em>He who would learn to fly one day must first learn to stand and walk and run and climb and dance; one cannot fly into flying</em>.&#8221; &#8212; <a href="http://en.wikipedia.org/wiki/Friedrich_Nietzsche"><strong>Friedrich Nietzsche</strong></a></p>
<p>
<a href="http://www.evaborka.co.nz/elamor2.jpg"><img src="/images/elamor2.jpg" alt="Configuration" align="left" width=75 /></a>In the initial post, &#8220;<a href="http://blog.securitymonks.com/2008/04/21/php-implementation/">PHP Implementation</a>&#8221; three ways to implement PHP were outlined.  In the previous post, <a href="http://blog.securitymonks.com/2008/04/21/php-as-a-module/">PHP as a Module</a>, PHP configured to run as an Apache module was examined.  Today&#8217;s post follows that up with a discussion of configuring  PHP as a CGI.  There are many options in configuring PHP as a CGI.  This post is only meant as an introduction and an example to get you started.  Please see previously mentioned source for a more in depth discussion.  Configuring PHP as a CGI is not much different from that of a module.  There are two methods:</p>
<ul>
<li>Treat PHP scripts like other CGI scripts.  Execution is carried out by the operating system.  The file must be executable to the Apache user.  The Apache configuration file must have <a href="http://httpd.apache.org/docs/2.2/mod/core.html#options">ExecCGI</a> set.  The PHP <a href="http://us.php.net/manual/en/configure.php">&#8211;enable-discard-path </a>configuration option is used.</li>
<p>  On most Unix systems, the first line in the script tells the system how to execute the script.  For example: #!/bin/sh, #!/usr/bin/perl, or #!/usr/local/apache/php/bin/php.   As an Apache module, PHP scripts do not require this first line so many software packages do not write PHP code in this manner.  Therefor, you would have to modify every code currently installed and many PHP code you would install in the future.</p>
<li>Use the &#8211;enable-force-cgi-redirect option and have Apache post-process the CGI scripts.</li>
</ul>
<p>We are going to use the second method.  Please see previous section, &#8220;Configuring PHP as a Module&#8221; as to the meaning of the additional configuration options. </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src root# cd /usr/local/src/php-5.2.5
 /usr/local/src/php-5.2.5 root# CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" \
CXX=gcc CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
-fno-exceptions -fno-rtti" ./configure --enable-force-cgi-redirect \
--prefix=/usr/local/apache/php --enable-sockets --with-gd --with-mysql=/usr/local/mysql \
--with-zlib-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr
 /usr/local/src/php-5.2.5 root# make
 /usr/local/src/php-5.2.5 root# make install
</pre>
</td>
</table>
<p>To avoid the possibility of anyone exploiting the PHP interpreter by calling it directory, create a separate folder php-cgi-bin.  Only the php interpreter will go there.  Copy <strong>/usr/local/apache/php/bin/php-cgi</strong> into new php-cgi-bin directory.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/php-5.2.5 root# mkdir  /var/www/php-cgi-bin
 /usr/local/src/php-5.2.5 root# chmod uog+rx  /var/www/php-cgi-bin
 /usr/local/src/php-5.2.5 root# cp /usr/local/apache/php/bin/php-cgi  /var/www/php-cgi-bin
 /usr/local/src/php-5.2.5 root# chmod uog+rx  /var/www/php-cgi-bin/php-cgi
</pre>
</td>
</table>
<p>In the Apache configuration file deny all access to the php-cgi-bin directory by using &#8220;Deny from all.&#8221;  Modify the Apache configuration file adding the AddHandler directives.  This is similar to what was done in the previous section, except we no longer have the line &#8220;LoadModule php5_module modules/libphp5.so&#8221;.  Instead we are going to tell Apache what action to take with the line &#8220;Action application/x-httpd-php /php-cgi-bin/php-cgi&#8221;.  The following lines get added to <strong>/usr/local/apache/conf/httpd.conf</strong></p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
# ScriptAlias: This controls which directories contain server scripts.
ScriptAlias /php-cgi-bin/ "/var/www/php-cgi-bin/"
# Associate file extensions with PHP
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php .php3
AddHandler application/x-httpd-php .inc
AddHandler application/x-httpd-php .class
AddHandler application/x-httpd-php .module
# Activates a CGI script for a particular handler or content-type
Action application/x-httpd-php /php-cgi-bin/php-cgi
#
DirectoryIndex index.html index.php
# "/usr/local/apache/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
&lt;Directory "/var/www/php-cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
&lt;/Directory>
</pre>
</td>
</table>
<p>Test that PHP scripts are now running under the Apache web server.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/php-5.2.5 root# echo "&lt;?php phpinfo(); ?>" > /var/www/htdocs/index.php
 /usr/local/src/php-5.2.5 root# chmod uog+rx /var/www/htdocs/index.php
 /usr/local/src/php-5.2.5 root# /usr/local/apache/bin/apachectl start
</pre>
</td>
</table>
<p>Access the index.php file by going to &#8220;http://127.0.0.1/index.php&#8221; with your browser.  Once you see PHP is working, stop the web server, remove the index.php info.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/php-5.2.5 root# /usr/local/apache/bin/apachectl stop
 /usr/local/src/php-5.2.5 root# rm /var/www/htdocs/index.php
</pre>
</td>
</table>
<p>The Apache server can now serve up PHP files.  The problem is the PHP is still running as the Apache user.  Apache running as a non-root user creates a problem in switching user identities.  This is where the use execution wrappers becomes important.  To quote from the <a href="http://httpd.apache.org/docs/2.2/suexec.html">suEXEC Support</a> page, &#8220;<em>The suEXEC feature provides Apache users the ability to run CGI and SSI programs under user IDs different from the user ID of the calling web server. Normally, when a CGI or SSI program executes, it runs as the same user who is running the web server.</em>&#8221;
</p>
<p>
Configuring Apache below, all possible configuration options for suEXEC are included, in addition to the previous configuration options we used for Apache.  While this is unnecessary, it is helpful to see what is being set.  Please see the suEXEC Support for explanation of the options.  In the example below, we will create a specific area, /var/www/htdocs/public_area where we are going to later configure CGIs to run under a certain user.  This is just an example and should be adjusted to your environment and needs.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/ root# cd /usr/local/src/httpd-2.2.8
 /usr/local/src/httpd-2.2.8 root# make clean
 /usr/local/src/httpd-2.2.8 root# ./configure --prefix=/usr/local/apache \
--enable-rewrite \
--enable-so \
--disable-imap \
--disable-userdir --with-mpm=worker \
--enable-suexec \
--with-suexec-bin=/usr/local/apache/bin/suexec \
--with-suexec-caller=httpd \
--with-suexec-userdir=public_html \
--with-suexec-docroot=/var/www/htdocs \
--with-suexec-uidmin=100 \
--with-suexec-gidmin=100 \
--with-suexec-logfile=/var/www/logs/suexec_log \
--with-suexec-safepath=/usr/local/bin:/usr/bin:bin \
--with-suexec-umask-=022
 /usr/local/src/httpd-2.2.8 root# make
 /usr/local/src/httpd-2.2.8 root# make install
 /usr/local/src/httpd-2.2.8 root# /usr/local/apache/bin/apachectl start
</pre>
</td>
</table>
<p>Look in the Apache error log to confirm that suEXEC mechanism is enabled.  There will be a log entry in <strong>/var/www/logs/error_log</strong>:
</p>
<p>
[notice] suEXEC mechanism enabled (wrapper: /usr/local/apache/bin/suexec)
</p>
<p>
Check the parameters used to compiled suEXEC:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/httpd-2.2.8 root# /usr/local/apache/bin/suexec -V
</pre>
</td>
</table>
<p>No let us create a script under /var/www/htdocs/public_html/cgi_bin to run as user jbond.  We will set this up to run under the virtual host 127.0.0.1.  The following is a minimal example of using suEXEC in the Apache configuration file (<strong>/usr/local/apache/conf/httpd.conf</strong>):</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
&lt;VirtualHost 127.0.0.1:80>
# Execute all scripts as user as user jbond, group spy
SuexecUserGroup jbond spy

# Maximum 1 CPU second to be used by a process
RLimitCPU 1 1
# Maximum of 25 processes at any one time
RLimitNPROC 25 25
# Allow 10 MB to be used per-process
RLimitMEM 10000000 10000000

&lt;directory /home/jbond/public_html/cgi_bin>
   Options +ExecCGI
  SetHandler cgi-script
&lt;/directory>
&lt;/VirtualHost 127.0.0.1:80>
</pre>
</td>
</table>
<p>Create a simple &#8220;hello script&#8221; that tells you who is running it in the /var/www/htdocs/public_html/cgi_bin folder.  Call the script test.sh</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
#!/bin/sh
echo "Content-Type: text/html"
echo
echo "Hello world from user &lt;b>`whoami`&lt;/b>! "
</pre>
</td>
</table>
<p>Adjust the owner and group permissions.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/httpd-2.2.8 root# chown -R jbond /var/www/htdocs/public_html
 /usr/local/src/httpd-2.2.8 root# chgrp -R spy /var/www/htdocs/public_html
</pre>
</td>
</table>
<p>You can now get the Apache web server to execute the script /var/www/htdocs/public_htm/cgi_bin/test.sh as user jbond by going to &#8220;http://127.0.0.1/public_html/cgi_bin/test.sh&#8221;.
</p>
<p>
To provide PHP access is not supported by suEXEC except through the use of Apache module mod_rewrite.  A copy of the PHP binary will need to be in each account&#8217;s cgi-bin folder.  Each account can have its own php.ini file for tailoring to specific account requirements.  This will be left as an exercise to the reader, at least until I have time to come back and fill specifics in.
</p>
<p><h3>Final Words</h3>
<p>In the next post, we will examine running PHP over FastCGI.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/04/21/php-as-a-cgi/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP as a Module</title>
		<link>http://blog.securitymonks.com/2008/04/21/php-as-a-module/</link>
		<comments>http://blog.securitymonks.com/2008/04/21/php-as-a-module/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 21:59:45 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/2008/04/21/php-as-a-module/</guid>
		<description><![CDATA[&#8220;You don&#8217;t get harmony when everybody sings the same note.&#8221; &#8212; Doug Floyd

In the previous post, &#8220;PHP Implementation&#8221; we outlined three ways to implement PHP.  In this first post, we will examine PHP as an Apache module.  When PHP is used as a module, it inherits Apache&#8217;s user permissions.  PHP basically is [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;<em>You don&#8217;t get harmony when everybody sings the same note</em>.&#8221; &#8212; <strong>Doug Floyd</strong></p>
<p>
<a href="http://www.evaborka.co.nz/harmony_4_photoprints.jpg"><img src="/images/harmony_4_photoprints.jpg" align="left" width=70/></a>In the previous post, &#8220;<a href="http://blog.securitymonks.com/2008/04/21/php-implementation/">PHP Implementation</a>&#8221; we outlined three ways to implement PHP.  In this first post, we will examine PHP as an Apache module.  When PHP is used as a module, it inherits Apache&#8217;s user permissions.  PHP basically is operating from within your web server.  It starts only once, with the Apache server, loads its settings and extensions only once, and information is stored across sessions.  The main advantage is speed.
</p>
<p>
The configuration, at minimum, will require letting PHP know where the Apache&#8217;s <a href="http://httpd.apache.org/docs/2.2/programs/apxs.html">apxs</a> tool resides.  The apxs tool is a &#8220;<em>tool for building and installing extension modules for the Apache HyperText Transfer Protocol (HTTP) server</em>.&#8221;  In other words, it is the interface between Apache and third-party modules.
</p>
<p>
For Mac OS X Leopard users, Leopard&#8217;s libtool creates <strong>php.dSYM</strong><strong></strong> instead of the php binary.  Gcc calls dsymutil when it creates an executable directly from a source file with debugging enabled so the debugging information will be available.  So, under normal libtool operations, .dSYM should only occurs if the object file (php) is temporary.  Really old autoconfs fail to detect the correct exe extension and instead of &#8221; set it to &#8216;.dSYM&#8217;.  Not really sure what is going on with Leopard, since autoconf is up to date, but I do have a solution.  Compile with the <strong>CFLAGS</strong> set it &#8220;<strong>-O2</strong>.&#8221;  By doing so, you are not having the compiler turn on the -finline-functions, -funit-at-a-time and -frename-registers options.  See GCC Command Options document section &#8220;<a href="http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/gcc/optimize-options.html">4.10. Options That Control Optimization</a>&#8221; for additional details on optimization options.  Not sure why Leopard does not behave with higher optimization, but sometimes you have to do what works.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src root# cd php-5.2.5
 /usr/local/src/php-5.2.5 root#  CC=gcc CFLAGS="-O2" ./configure --with-apxs2=/usr/local/apache/bin/apxs \
--prefix=/usr/local/apache/php
</pre>
</td>
</table>
<p>
Before doing any installation, we need to modify the Apache configuration file to load PHP.  Do this be adding the following lines to the <strong>/usr/local/apache/conf/httpd.conf</strong> file:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
# Load the PHP module
LoadModule php5_module        modules/libphp5.so
# Associate file extensions with PHP
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php .php3
AddHandler application/x-httpd-php .inc
AddHandler application/x-httpd-php .class
AddHandler application/x-httpd-php .module
#
DirectoryIndex index.html index.php
</pre>
</td>
</table>
<p>
At this point, you are ready to make and install PHP.  First, you will need to change the permission of the Apache instdso.sh since we were pretty restrictive of permissions in our Apache installation.  After installing PHP, we will want to place a version of php.ini in /usr/local/apache/php/lib.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/php-5.2.5 root# chmod u+x  /usr/local/apache/build/instdso.sh
 /usr/local/src/php-5.2.5 root# make
 /usr/local/src/php-5.2.5 root# make install
 /usr/local/src/php-5.2.5 root# cp php.ini-recommended /usr/local/apache/php/lib/php.ini
 /usr/local/src/php-5.2.5 root# /usr/local/apache/bin/apachectl configtest
</pre>
</td>
</table>
<p>
As with Apache, PHP has modules.  In PHP documents frequently modules are called functions.  Some functions can be considered dangerous and may be disabled.  Examine which functions are compiled into PHP.  Below is a table of <a href="http://us3.php.net/manual/en/funcref.php">functions</a> that will be compiled in by default:</p>
<table border=1>
<tr>
<th>Module</th>
<th>Description</th>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.ctype.php">ctype</a></td>
<td>Character Type Functions</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.datetime.php">date</a></td>
<td>Date and Time</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.dom.php">dom</a></td>
<td>DOM Extension</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.filter.php">filter</a></td>
<td>Filter Functions</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.hash.php">hash</a></td>
<td>hash Functions</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.iconv.php">iconv</a></td>
<td>Character set conversion module using IConv</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.json.php">json</a></td>
<td>JSON Functions</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.libxml.php">libxml</a></td>
<td></td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.pcre.php">pcre</a></td>
<td>Perl compatible regular expression library</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/intro.pdo.php">PDO</a></td>
<td>The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/ref.pdo-sqlite.php">pdo_sqlite</a></td>
<td>PDO_SQLITE is a driver that implements the PHP Data Objects (PDO) interface to enable access to SQLite 3 databases</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.posix.php">posix</a></td>
<td>Module for accessing POSIX system interface</td>
</tr>
<tr>
<td><a href="http://us.php.net/language.oop5.reflection">Reflection</a></td>
<td>An object-oriented extension to the Zend Engine</td>
</tr>
<tr>
<td><a href="http://us.php.net/manual/en/ref.session.php">session</a></td>
<td>HTTP session support</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/ref.simplexml.php">SimpleXML</a></td>
<td>Provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.spl.php">SPL</a></td>
<td>Standard PHP Library (SPL)</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/intro.sqlite.php">SQLite</a></td>
<td>Extension for the SQLite Embeddable SQL Database Engine</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.spl.php">standard</a></td>
<td>A collection of interfaces and classes that are meant to solve standard problems</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.tokenizer.php">tokenizer</a></td>
<td>Tokenizer module</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.xml.php">xml</a></td>
<td>Extensible Markup Language (XML) parser module</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.xmlreader.php">xmlreader</a></td>
<td>XML Pull parser</td>
</tr>
<tr>
<td><a href="http://us3.php.net/manual/en/book.xmlwriter.php">xmlwriter</a></td>
<td>Wraps the libxml xmlWriter API</td>
</tr>
</table>
<p>The <a href="http://www.php.net/manual/en/ref.posix.php">posix function</a> may be used for reconnaissance exploits.  If it is not required, you should disable it.  For later work, we require it and will leave it enabled.  For those wishing to disable it, do so through the use of the &#8220;<strong>&#8211;disable-posix</strong>&#8221; option to configure.  The important point is to know what is required and choose both functions and configuration options accordingly.  Do not enable everything because you may need it at some point.  This is the incorrect thinking that many software packages, and operating systems, fall into.  The more code, the more possible vulnerabilities that can be exploited.</p>
<p>
We will be building on this implementation of PHP.  We have several future requirements:</p>
<table border=1>
<tr>
<th>Module</th>
<th>Description</th>
</tr>
<tr>
<td><a href="http://us2.php.net/gd">gd</a></td>
<td>GD library of image functions</td>
</tr>
<tr>
<td><a href="http://us.php.net/mysql">mysql</a></td>
<td>Functions allow you to access MySQL database servers</td>
</tr>
<tr>
<td><a href="http://us2.php.net/sockets">sockets</a></td>
<td>Extension implements a low-level interface to the socket communication functions based on the popular BSD sockets, providing the possibility to act as a socket server as well as a client</td>
</tr>
<tr>
<td><a href="http://us3.php.net/zlib">zlib</a></td>
<td>Enables you to transparently read and write gzip (.gz) compressed files, through versions of most of the filesystem functions which work with gzip-compressed files (and uncompressed files, too, but not with sockets)</td>
</tr>
</table>
<p>We add that functionality with the following configuration options:</p>
<ul>
<li><a href="http://us3.php.net/manual/en/image.installation.php">&#8211;with-gd</a> option will enable PHP to create and manipulate image files with the support of the <a href="http://www.libgd.org/">GD library</a>.</li>
<li><a href="http://us3.php.net/manual/en/mysql.installation.php">&#8211;with-mysql </a>option will enable PHP access MySQL database servers.</li>
<li><a href="http://us3.php.net/manual/en/sockets.installation.php">&#8211;enable-sockets</a> option enable socket functions.</li>
<li><a href="http://us3.php.net/manual/en/zlib.installation.php">&#8211;with-zlib</a> option will enable the use of compression libraries.</li>
</ul>
<p><strong>Note:</strong>  Versions of GD older than gd-1.6 support GIF format images, and do not support PNG.  Version of GD greater than gd-1.6 and less than gd-2.0.28 support PNG, but not GIF. GIF support was re-enabled in gd-2.0.28.  If you get complaints about graphic libraries missing, it is likely due to the version of GD installed.
</p>
<p>
Look at the modules/functions installed by default with PHP. </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/php-5.2.5 root# /usr/local/apache/php/bin/php -m
[PHP Modules]
ctype
date
dom
filter
hash
iconv
json
libxml
pcre
PDO
pdo_sqlite
posix
Reflection
session
SimpleXML
SPL
SQLite
standard
tokenizer
xml
xmlreader
xmlwriter
[Zend Modules]
</pre>
</td>
</table>
<p>
In the previous post, &#8220;<a href="http://blog.securitymonks.com/2008/04/07/introduction-to-mysql/">Introduction to MySQL</a>&#8221; MySQL was setup under the /usr/local/mysql directory.  This directory will be used in this configuration to add MySQL support to PHP.
</p>
<p>
If you are compiling under Mac OS X, you should be familiar MacPorts (see posting &#8220;<a href="http://blog.securitymonks.com/2008/04/18/macports-under-mac-os-x-leopard/">MacPorts Under Mac OS X Leopard</a>&#8220;).  Make sure the required libraries libjpeg, libpng, gd, and zlib are installed.  The configuration of PHP requires the locations of these libraries be specified.  All these libraries will be located under /opt/local.
</p>
<p>
There is an issue with Leopards iconv.h file (/usr/include/iconv.h) that can cause the error message &#8220;<strong>Undefined symbols</strong>&#8221; as the compiler complains about &#8220;_iconv_close, referenced from: _php_iconv_string in iconv.o.&#8221;  This is caused by multiple <strong>iconv.h</strong> files on the system.  Try moving the Leopard version of the iconv.h file and then linking it to the Macports version.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/php-5.2.5 root# mv /usr/include/iconv.h \
/usr/include/iconv.h.leo_orig
 /usr/local/src/php-5.2.5 root# ln -s /opt/local/include/iconv.h \
/usr/include/iconv.h
 /usr/local/src/php-5.2.5 root# make clean
 /usr/local/src/php-5.2.5 root# CC=gcc CFLAGS="-O2 -fno-omit-frame-pointer" \
CXX=gcc CXXFLAGS="-O2 -fno-omit-frame-pointer -felide-constructors \
-fno-exceptions -fno-rtti" ./configure --with-apxs2=/usr/local/apache/bin/apxs \
--prefix=/usr/local/apache/php --enable-sockets --with-gd --with-mysql=/usr/local/mysql \
--with-zlib-dir=/opt/local --with-jpeg-dir=/opt/local --with-png-dir=/opt/local
 /usr/local/src/php-5.2.5 root# make
 /usr/local/src/php-5.2.5 root# make test
 /usr/local/src/php-5.2.5 root# make install
</pre>
</td>
</table>
<p>
Under Linux, these libraries will be installed as <a href="http://en.wikipedia.org/wiki/RPM_Package_Manager">RPMs</a> under the /usr area.  The configuration would be slightly different:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/php-5.2.5 root# make clean
 /usr/local/src/php-5.2.5 root# CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" \
CXX=gcc CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
-fno-exceptions -fno-rtti" ./configure --with-apxs2=/usr/local/apache/bin/apxs \
--prefix=/usr/local/apache/php --enable-sockets --with-gd --with-mysql=/usr/local/mysql \
--with-zlib-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr
 /usr/local/src/php-5.2.5 root# make
 /usr/local/src/php-5.2.5 root# make test
 /usr/local/src/php-5.2.5 root# make install
</pre>
</td>
</table>
<p>
Copy the PHP configuration file to the expected location and test the Apache configuration file.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/php-5.2.5 root# cp php.ini-recommended /usr/local/apache/php/lib/php.ini
 /usr/local/src/php-5.2.5 root# /usr/local/apache/bin/apachectl configtest
 /usr/local/src/php-5.2.5 root# /usr/local/apache/bin/apachectl start
</pre>
</td>
</table>
<p></p>
<p>To test if it worked, create a file <strong>/var/www/htdocs/index.php</strong> containing the lines:</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
< ?php
phpinfo();
?>
</pre>
</td>
</table>
<p>
Access the index.php file through your web browser by going to &#8220;http://127.0.0.1/index.php&#8221; and you should see a bunch of information concerning your PHP setup.  Remove the file.  </p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src/php-5.2.5 root# /usr/local/apache/bin/apachectl stop
 /usr/local/src/php-5.2.5 root# /bin/rm /var/www/htdocs/index.php
</pre>
</td>
</table>
<p>
The Apache server can now serve up PHP files.  Remember, PHP is running with the same file permission as the Apache server.  Some important changes need to be made to the php.ini file.  Please see the posting, &#8220;<a href="http://blog.securitymonks.com/2008/04/21/php-configuration-modifications/">PHP Configuration Modifications</a>.&#8221;</p>
<h3>Final Words</h3>
<p>In the next post, we will examine configuring <a href="http://blog.securitymonks.com/2008/04/21/php-as-a-cgi/">PHP as a CGI</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/04/21/php-as-a-module/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP Implementation</title>
		<link>http://blog.securitymonks.com/2008/04/21/php-implementation/</link>
		<comments>http://blog.securitymonks.com/2008/04/21/php-implementation/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 21:57:38 +0000</pubDate>
		<dc:creator>John Gerber</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.securitymonks.com/2008/04/21/php-implementation/</guid>
		<description><![CDATA[&#8220;The act of contemplation then creates the thing created.&#8221; &#8212; Isaac D&#8217;Israeli

My last post, &#8220;An Apache Implementation,&#8221; went through the steps of setting up a secure web server.  The posting ended with the server having no CGI capabilities.  While this might be secure, the usefulness is somewhat limited.  In the next few [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;<em>The act of contemplation then creates the thing created</em>.&#8221; &#8212; <a href="http://en.wikipedia.org/wiki/Isaac_D'Israeli"><strong>Isaac D&#8217;Israeli</strong></a></p>
<p>
<a href="http://www.evaborka.co.nz/artist_in_contemplation_1_samples.jpg"><img src="/images/artist_in_contemplation_1_samples.jpg" align="left" width=75 /></a>My last post, &#8220;<a href="http://blog.securitymonks.com/2008/04/14/an-apache-implementation/">An Apache Implementation</a>,&#8221; went through the steps of setting up a secure web server.  The posting ended with the server having no CGI capabilities.  While this might be secure, the usefulness is somewhat limited.  In the next few posts we are going to install <a href="http://www.php.net/">PHP</a> three different ways.  First, as a an <a href="http://blog.securitymonks.com/2008/04/21/php-as-a-module/">Apache module</a>.  The second way is using <a href="http://blog.securitymonks.com/2008/04/21/php-as-a-cgi/">PHP as a CGI</a>.  Finally by running PHP over <a href="http://www.fastcgi.com">FastCGI</a>.  <a href="http://hudzilla.org/">Paul Hudson</a>, author of <a href="http://www.amazon.com/dp/0596100671?tag=hudzillaorg-20&#038;camp=14573&#038;creative=327641&#038;linkCode=as1&#038;creativeASIN=0596100671&#038;adid=1HXKFWBN2488GSKPWHMY&#038;">PHP in a Nutshell</a> maintains a wiki &#8220;<a href="http://hudzilla.org/phpwiki/index.php?title=Main_Page">Practical PHP Programming</a>.&#8221;  Like his book, the site is a fantastic source of information.  Paul has a section titled, &#8220;<a href="http://hudzilla.org/phpwiki/index.php?title=PHP_as_a_CGI_or_a_module%3F">PHP as a CGI or a module?</a>&#8221; where he outlines the advantages and disadvantage of both approaches:<br />
<blockquote>Running PHP as a CGI means that you basically tell your web server the location of the PHP executable file, and the server runs that executable, giving it the script you called, each time you visit a page. That means each time you load a page, PHP needs to read php.ini and set its settings, it needs to load all its extensions, and then it needs to start work parsing the script – there is a lot of repeated work.</p>
<p>When you run PHP as a module, PHP literally sits inside your web server – it starts only once, loads its settings and extensions only once, and can also store information across sessions. For example, PHP accelerators rely on PHP being able to save cached data across requests, which is impossible using the CGI version.</p>
<p>The obvious advantage of using PHP as a module is speed – you will see a big speed boost if you convert from CGI to a module. Many people, particularly Windows users, do not realise this, and carry on using the php.exe CGI SAPI, which is a shame – the module is usually three to five times faster.</p>
<p>There is one key advantage to using the CGI version, though, and that is that PHP reads its settings every time you load a page. With PHP running as a module, any changes you make in the php.ini file do not kick in until you restart your web server, which makes the CGI version preferable if you are testing a lot of new settings and want to see instant responses. </p></blockquote>
<p>One other advantage of running PHP as a CGI is that you can do so with an execution wrapper.  PHP as a module will perform all operations as the Apache user.  It is a choice between speed verses privilege separation.  Running PHP over FastCGI will add speed while keeping privilege separation.  </p>
<h3>Sources of Information</h3>
<p>There are many great sources of information on PHP.  There are even sites dedicated to trying to list them.  Below are just a few sources that proved most helpful when setting up PHP.</p>
<ul>
<li><a href="http://www.hudzilla.org/">Paul Hudson</a>, author of <a href="http://www.amazon.com/dp/0596100671?tag=hudzillaorg-20&#038;camp=14573&#038;creative=327641&#038;linkCode=as1&#038;creativeASIN=0596100671&#038;adid=0RDAMZKJP0MEGGEB1XZR&#038;">PHP in a Nutshell</a> has created the wiki <a href="http://hudzilla.org/phpwiki/index.php?title=Main_Page">Practical PHP Programming</a> where he has made available all the valuable information from his book.</li>
<li><a href="http://www.apachesecurity.net/">Apache Security</a> by <a href="http://blog.ivanristic.com/">Ivan Ristic</a>. I have mentioned before what a great resource Ivan&#8217;s book is.  From his <a href="http://www.apachesecurity.net/">Apache Security blog</a>, Ivan has made <a href="http://www.apachesecurity.net/download/apachesecurity-ch03.pdf">Chapter 3: PHP</a> available to everyone.</li>
<li><a href="http://www.php.net/manual/en/">PHP Manual</a>.  The best source for most up-to-date information.  Pay particular attention to chapters on &#8220;<a href="http://www.php.net/manual/en/install.php">Installation and Configuration</a>&#8221; and &#8220;<a href="http://www.php.net/manual/en/security.php">Security</a>.&#8221;  The security chapter does have sections on &#8220;<a href="http://www.php.net/manual/en/security.cgi-bin.php">Installed as CGI binary</a>&#8221; and &#8220;<a href="http://www.php.net/manual/en/security.apache.php">Installed as an Apache module</a>.&#8221;</li>
<li><a href="http://www.mono-project.com/FastCGI">FastCGI</a> by <a href="http://kerrick.wordpress.com">Brian Nickel</a> </li>
<li><a href="http://www.seaoffire.net/fcgi-faq.html">Apache + Chroot + FastCGI + PHP FAQ</a>.  While I am not going to use Chroot with this implementation, that FAQ is a good resources and discusses additional security measure that are very useful.</li>
<li>PHP Security Blog by <a href="http://blog.php-security.org/authors/1-Stefan-Esser">Stefan Esser</a>.  Stefan is the developer of Suhosin.  While he has not been posting lately, it is good to look over his site.  Back in December of 2006, Stefan decided to leave the PHP Security Response Team.  His post, <a href="http://blog.php-security.org/archives/61-Retired-from-securityphp.net.html">&#8220;Retired from security@php.net</a>&#8221; provides great insight.</li>
</ul>
<h3>Hardened-PHP</h3>
<p>Additional security for PHP can be found through the <a href="http://www.hardened-php.net/">Hardened-PHP</a> project.  The project was &#8220;<em>founded to protect PHP users and servers against present and future security holes.  Therefor we can help you to protect your application and/or your server</em>.&#8221;  Of particular interest is the project&#8217;s development of <a href="http://www.hardened-php.net/suhosin/index.html">Suhosin</a>.  Suhosin is &#8220;<em>an advanced protection system for PHP installations. It was designed to protect servers and users from known and unknown flaws in PHP applications and the PHP core</em>.&#8221;  Please see the &#8220;<a href="http://www.hardened-php.net/suhosin/a_feature_list.html">Feature List</a>&#8221; page for a listing of all the additional functionality/protection Suhosin adds to PHP.  We are not going to be installing Suhosin today because the latest version of Suhosin is only for PHP 5.1.6.  Because of the bug and security fixes, we will be installing PHP 5.2.5.</p>
<h3>Installing PHP</h3>
<p>Most operating systems have PHP already installed.  This post is going to demonstrate three different ways PHP can be installed on a Linux or Mac OS X system.</p>
<h4><strong>Download PHP</strong></h4>
<p>The first step is to download the latest source code for PHP.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 root# cd /usr/local/src
 /usr/local/src root# wget http://us.php.net/get/php-5.2.5.tar.gz/from/www.php.net/mirror
</pre>
</td>
</table>
<p>At this point, check the integrity.  Calculate the MD5 sum of the source and compare it to the signature file.  Mac OS X users, please note use the command <strong>/sbin/md5</strong> instead of <strong>md5sum</strong>.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src root# md5sum php-5.2.5.tar.gz
61a0e1661b70760acc77bc4841900b7a  php-5.2.5.tar.gz
</pre>
</td>
</table>
<p>
Uncompress and untar the sources.</p>
<table width="100%" cellpadding="0" cellspacing="1" border="1">
<td class="code-outline" BGCOLOR="#F5F5F5">
<pre class="displaycode">
 /usr/local/src root# tar xzf php-5.2.5.tar.gz
</pre>
</td>
</table>
<p></p>
<h3>Final Words</h3>
<p>In the next post, we will examine configuring <a href="http://blog.securitymonks.com/2008/04/21/php-as-a-module/">PHP as a module</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.securitymonks.com/2008/04/21/php-implementation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

