#
# SARA HTML Tree
#
# Functions
# &table($a, $b,$c,$d,$e)
# &chart($a, $b,$c,$d,$e)
# &sum($a, "string"):     Sums occurrences per host
sub htm_write  {
my @prefix     =  ('A','B','C','D','E','F');
my $total_vul  =  $summary_data{'Red'} + $summary_data{'Yellow'} + $summary_data{'Brown'}; 
my $today      =  &get_todays_date();
my $prefix_cnt =  0;
my $smb_guess =  "";
$smb_guess    = " (Windows password guessing disabled)" if $dont_smb_guess == 1;
#
#  First Page of Report
#
print HTM<<EOF;
<TITLE>Sensitive Security Information</TITLE>\n
  <BODY BGCOLOR="#BBBBBB">
<BODY LINK="#0000ff">
<FONT SIZE=2>$today
<P>
<H4 ALIGN="CENTER">SARA Scan Results of $scan_data{$tag_id}</H4>
<P>
<B>INTRODUCTION</B>
<BR>
<P>A Security Auditor's Research Assistant (SARA) security scan was performed on hosts on the $scan_data{$tag_id} 
sub-nets.  The SARA scan was performed to identify potential security vulnerabilities in the $scan_data{$tag_id} 
sub-domain. The scan was completed on $scan_data{$tag_date} and its scan mode was set to $scan_data{$tag_level}$smb_guess. 
The version of SARA was $scan_data{$tag_version}.
<P>
<B>DISCUSSION</B>
<BR>
EOF
if  ($summary_data{'Total'} == 0) {
print HTM <<EOF;
    SARA detected no hosts with services running.  One of the following
    may be true:
    <P>
    <UL>
    <LI>System may be behind a firewall
    <LI>System may not offer any services
    <LI>System may be off-line
    </UL>
    <P>

EOF
return;
}
print HTM <<EOF;
SARA is a third generation security analysis tool that analyzes network-based services on the target computers.  
SARA classifies a detected service in one of five categories:
<P>
<UL>
<LI>Green - Services found that were not exploitable
<LI>Grey - No services or vulnerabilities
<LI>Red - Services with potentially severe exploits (account compromise)
<LI>Yellow - Services with potentially serious exploits found (data compromise)
<LI>Brown - Possible security problems.
</UL>
<P>
A total of $summary_data{'Total'} devices were detected of which $total_vul are possibly vulnerable.  Figure 1 
summarizes this scan by color where the <I>Green</I> bar indicates hosts with no detected vulnerabilities. 
<I>Gray</I> indicates hosts with no services. The <I>Red</I> bar indicates hosts that have one or more red 
vulnerabilities. The <I>Yellow</I> bar indicates hosts that have one or more yellow vulnerabilities (but no red). 
And the <I>Brown</I> bar indicates hosts that have one or more brown problems (but no red or yellow).
<P>
EOF
$bar_chart = &htm_bar_chart();
print HTM<<EOF;
 $bar_chart
 <P>
 The SARA scan results are distributed as appendices to this paper:
<P>
<UL>
EOF
if ($disable_old_scan_appendix != 1) {
print HTM<<EOF;
</Font><P>
<UL>
<LI><A HREF="#appendixA"><FONT SIZE=2>Appendix A:</FONT></A><FONT SIZE=2>&#9;Previous scan results</Font><BR>
<LI><A HREF="#appendixB"><FONT SIZE=2>Appendix B:</FONT></A><FONT SIZE=2>&#9;Sub-net tables depicting hosts, host-types, and vulnerability counts</Font><BR> 
<LI><A HREF="#appendixC"><FONT SIZE=2>Appendix C:</FONT></A><FONT SIZE=2>&#9;Details on the hosts reported</Font><BR>
<LI><A HREF="#appendixD"><FONT SIZE=2>Appendix D:</FONT></A><FONT SIZE=2>&#9;Vulnerabilities sorted by severity</Font><BR>
<LI><A HREF="#appendixE"><FONT SIZE=2>Appendix E</FONT></A><FONT SIZE=2>:&#9;Description of the vulnerabilities.</Font><BR>
</UL>
<P>
EOF
} else {
print HTM<<EOF;
</FONT><BR>
<UL>
<LI><A HREF="#appendixA"><FONT SIZE=2>Appendix A:</FONT></A><FONT SIZE=2>&#9;Sub-net tables depicting hosts, host-types, and vulnerability counts</Font><BR>
<LI><A HREF="#appendixB"><FONT SIZE=2>Appendix B:</FONT></A><FONT SIZE=2>&#9;Details on the hosts reported</Font><BR>
<LI><A HREF="#appendixC"><FONT SIZE=2>Appendix C:</FONT></A><FONT SIZE=2>&#9;Vulnerabilities sorted by severity</Font><BR>
<LI><A HREF="#appendixD"><FONT SIZE=2>Appendix D</FONT></A><FONT SIZE=2>:&#9;Description of the vulnerabilities.</Font><BR>
</UL>
<P>
EOF
}
print HTM<<EOF;
</UL> </UL>
<P>
Appendices are hyper-linked to assist the reader in navigating through this report.     
The report includes information on all hosts that have one or more vulnerabilities.  
<P>
<B>RECOMMENDATION</B>
<BR>
The identified hosts should be analyzed immediately.  
<HR>
<CENTER><FONT Color = "#C0C0C0">END OF SECTION</FONT></CENTER>
<FONT Color = "Black">
EOF
#
# Beginning of Appendix A
#
if ($disable_old_scan_appendix != 1) {
  $_prefix = $prefix[$prefix_cnt];
  $prefix_cnt++;
  print HTM<<EOF;
  <CENTER>
  <H4><A NAME="appendix$_prefix">Appendix $_prefix</A><BR>
  Previous Scan Results</H4>
  </CENTER>
  <P>
  <UL>This appendix should include previous scan summaries (i.e., first page of last SARA
  scan).  If you do not want this appendix generated, set \$disable_old_scan_appendix="1"
  in <I>config/sara.cf</I>.</U>
  <HR><CENTER><FONT Color = \"#C0C0C0\">END OF SECTION</FONT></CENTER>
<FONT Color = "Black">
EOF
}
#
#  This appendix generates tables of hosts for subnets included in this scan
#
  $_prefix = $prefix[$prefix_cnt];
  $prefix_cnt++;
  print HTM<<EOF;
  <CENTER>
  <H4><A NAME="appendix$_prefix">Appendix $_prefix</A><BR>
  SARA Subnet Summary</H4>
  </CENTER>
EOF
  $caption_cnt = 0;
  for $_net (sort keys %subnet_data) {
    $caption_cnt++;
    $caption     = "Table $_prefix-$caption_cnt: Subnet $_net";
    $subnet_data = &get_subnet_data($_net);   
    print HTM "$subnet_data<P>\n";
    print HTM "<PRE>\n\n\n</PRE>\n";
  }
  print HTM "<HR><CENTER><FONT Color = \"#C0C0C0\">END OF SECTION</FONT></CENTER><FONT Color = \"Black\">\n";

  $_prefix = $prefix[$prefix_cnt];
  $prefix_cnt++;
  print HTM<<EOF;
  <CENTER>
  <H4><A NAME="appendix$_prefix">Appendix $_prefix</A><BR>
  SARA Host Details</H4>
  </CENTER>
EOF

  for $_host (sort keys %host_data) {
#
#  Generate Host detail appendix
#  Test to see if non vulnerable hosts should be displayed
#
   if ($host_data{$_host}{'Vulnerable'} ne "YES") {
     if ($option ne "default" && $novul eq "on") {
       next;
     }
   }

#
#  Generate Host Table
#
   $host_table = &get_host_data($_host);
   print HTM $host_table;
#
#  Generate GREEN Services
#
   print HTM <<EOF;
     <PRE>
     </PRE>
     <Font size=2 Face=Arial>
     <B>Non Vulnerable services</B>
     </Font>
     <P>
EOF
  $host_table = &get_host_svc($_host);
   print HTM "<UL>$host_table</UL>\n";
#
#  Generate Vulnerabilities
      print HTM <<EOF;
      <P>
      <Font size=2 Face=Arial>
      <B>Vulnerabilities</B>
      </Font>
      <P>
EOF
      $host_table=&get_host_vulns($_host);
      print HTM "<UL>$host_table</UL>\n";
      if ($dont_smb_guess == 1) {
        if($host_table =~ /SMB\: User list/) {
          print HTM "<P>Note: SMB password guessing has been disabled\n";
        }
      }
      print HTM <<EOF;
      <HR>
EOF
      }
  print HTM <<EOF;
  </UL>
  <HR><CENTER><FONT Color = "#C0C0C0">END OF SECTION</FONT></CENTER>
  <FONT Color = "Black">
EOF
 $_prefix = $prefix[$prefix_cnt];
  $prefix_cnt++;
  print HTM<<EOF;
  <CENTER>
  <H4><A NAME="appendix$_prefix">Appendix $_prefix</A><BR>
  SARA Vulnerability Summary</H4>
  </CENTER>
EOF
      $vulnerabilities = &get_vulns();
      print HTM "$vulnerabilities\n";
 $_prefix = $prefix[$prefix_cnt];
  $prefix_cnt++;
  print HTM<<EOF;
  <HR><CENTER><FONT Color = "#C0C0C0">END OF SECTION</FONT></CENTER>
  <FONT Color = "Black">
  <CENTER>
  <H4><A NAME="appendix$_prefix">Appendix $_prefix</A><BR>
  SARA Tutorial Summaries</H4>
  </CENTER>
EOF
  $_tutorial = &get_tutorials();
  print HTM "$_tutorial\n";
}
1;
