#!/usr/bin/perl # Copyright Andrew Gavin 2009, 2010 # # This file is part of OpenDLP. # # OpenDLP is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenDLP is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with OpenDLP. If not, see . use CGI qw/:standard/; use DBI; my $user = remote_user(); my $db_admin_file = "../etc/db_admin"; my $is_valid = 1; my %systems = (); open( DB, $db_admin_file ); my $db_line = ; close( DB ); chomp $db_line; my ($db_username, $db_password) = split( ":", $db_line ); header(); my $query = CGI->new; my $scanname = $query->param('scanname'); if( $scanname ne "" && $scanname !~ /^[a-z0-9\ \,\.\-\_]+$/i ) { $is_valid = 0; print "Invalid scan name

\n"; } my $system = $query->param('system'); if( $system ne "" && $system !~ /^[A-Z0-9]{32}$/ ) { $is_valid = 0; print "Invalid system tracker

\n"; } if( $is_valid ) { print "View Results

\n"; # if no arguments are given if( $system eq "" && $scanname eq "" ) { my %scans = (); print "On this screen, you can:
\n"; print "
  • Select a scan to view its systems and results
  • \n"; print "
  • Pause, Resume, or Stop/Uninstall agents on all systems in scan
  • \n"; print "
    For a more granular way to control agents, select the scan and click \"View Scan Details\".

    \n"; print "
    \n"; print "\n"; print "\n"; my $dbh = DBI->connect("DBI:mysql:database=OpenDLP;host=localhost",$db_username,$db_password); my $string = "SELECT DISTINCT scan,ip,control FROM systems"; my $sth = $dbh->prepare( $string ); $sth->execute(); while( my $results = $sth->fetchrow_arrayref() ) { if( $$results[2] eq "running" ) { $scans{$$results[0]}{running}++; } elsif( $$results[2] eq "finished" ) { $scans{$$results[0]}{finished}++; } elsif( $$results[2] eq "stopped" ) { $scans{$$results[0]}{stopped}++; } elsif( $$results[2] eq "uninstalled" ) { $scans{$$results[0]}{uninstalled}++; } } foreach my $scankey( sort( keys( %scans ))) { my $total = $scans{$scankey}{running} + $scans{$scankey}{finished} + $scans{$scankey}{stopped} + $scans{$scankey}{uninstalled}; print "\n"; print "\n"; # Finished if( $scans{$scankey}{finished} == 0 ) { print "\n"; } else { print "\n"; } # Running if( $scans{$scankey}{running} == 0 ) { print "\n"; } else { print "\n"; } # Paused if( $scans{$scankey}{stopped} == 0 ) { print "\n"; } else { print "\n"; } # Uninstalled if( $scans{$scankey}{uninstalled} == 0 ) { print "\n"; } else { print "\n"; } print "\n"; if( $total eq $scans{$scankey}{finished} ) { print "\n"; print "\n"; print "\n"; } else { # pause if( $scans{$scankey}{running} > 0 ) { print "\n"; } else { print "\n"; } # resume if( $scans{$scankey}{stopped} > 0 ) { print "\n"; } else { print "\n"; } # uninstall my $stopped_and_running = $scans{$scankey}{stopped} + $scans{$scankey}{running}; if( $stopped_and_running > 0 ) { print "\n"; } else { print "\n"; } } print "\n"; } print "\n"; print "
    DetailsScan nameFinishedRunningPausedUninstalledTotalPauseResumeUninstall
    $scankey0$scans{$scankey}{finished}0$scans{$scankey}{running}0$scans{$scankey}{stopped}0$scans{$scankey}{uninstalled}$totalN/AN/AN/AN/AN/AN/A
    \n"; } # if scanname is given as an argument, but not system elsif( $scanname ne "" && $system eq "" ) { print "Select a system to view its results for scan \"$scanname\":

    \n"; print "
    \n"; print "\n"; print "\n"; print "\n"; my $dbh = DBI->connect("DBI:mysql:database=OpenDLP;host=localhost",$db_username,$db_password); my $string = "SELECT DISTINCT tracker,system,ip,status,filestotal,filesdone,bytestotal,bytesdone,updated,control FROM systems WHERE scan=?"; my $sth = $dbh->prepare( $string ); $sth->execute( $scanname ); while( my $results = $sth->fetchrow_arrayref() ) { $system{$$results[0]}{system} = $$results[1]; $system{$$results[0]}{ip} = $$results[2]; $system{$$results[0]}{status} = $$results[3]; $system{$$results[0]}{filestotal} = $$results[4]; $system{$$results[0]}{filesdone} = $$results[5]; $system{$$results[0]}{bytestotal} = $$results[6]; $system{$$results[0]}{bytesdone} = $$results[7]; $system{$$results[0]}{updated} = $$results[8]; $system{$$results[0]}{control} = $$results[9]; } foreach my $tracking( sort( keys( %system ))) { my $string = "SELECT COUNT(*) FROM results WHERE scan=? AND tracker=?"; $sth = $dbh->prepare( $string ); $sth->execute( $scanname, $tracking ); my $results = $sth->fetchrow_arrayref(); $system{$tracking}{count} = $$results[0]; print "\n\n"; print "\n"; print "\n"; print "\n"; if( $system{$tracking}{status} == -1 ) { print "\n"; } elsif( $system{$tracking}{status} == 0 ) { print "\n"; } elsif( $system{$tracking}{status} == 1 ) { print "\n"; } elsif( $system{$tracking}{status} == 2 ) { print "\n"; } elsif( $system{$tracking}{status} == 3 ) { print "\n"; } if( $system{$tracking}{filesdone} ne "" ) { print "\n"; } else { print "\n"; } if( $system{$tracking}{filestotal} ne "" ) { print "\n"; } else { print "\n"; } if( $system{$tracking}{bytesdone} ne "" ) { print "\n"; } else { print "\n"; } if( $system{$tracking}{bytestotal} ne "" ) { print "\n"; } else { print "\n"; } my $time = localtime( $system{$tracking}{updated} ); my $currenttime = time(); my $time_diff = $currenttime - $system{$tracking}{updated}; print "\n"; print "\n"; # pause if( $system{$tracking}{control} eq "running" ) { print "\n"; } else { print "\n"; } # resume if( $system{$tracking}{control} eq "stopped" ) { print "\n"; } else { print "\n"; } # uninstall if( $system{$tracking}{control} =~ /^(stopped|running)$/i ) { print "\n"; } else { print "\n"; } print "\n"; } print "

    Network nameIP addressStatusStepFiles doneTotal filesBytes doneTotal bytesUpdatedFindingsPauseResumeUninstall
    $system{$tracking}{system}$system{$tracking}{ip}$system{$tracking}{control}-1: Deploying0: All files1: Whitelisting2: Scanning3: Done$system{$tracking}{filesdone}N/A$system{$tracking}{filestotal}N/A$system{$tracking}{bytesdone}N/A$system{$tracking}{bytestotal}N/A$time ($time_diff" . "s ago)$system{$tracking}{count}N/AN/AN/A
    \n"; } # look at details of specific system elsif( $scanname ne "" && $system ne "" ) { my $dbh = DBI->connect("DBI:mysql:database=OpenDLP;host=localhost",$db_username,$db_password); my $string = "SELECT system,ip,status,filestotal,filesdone,bytestotal,bytesdone,updated,profile,control FROM systems WHERE scan=? AND tracker=?"; my $sth = $dbh->prepare( $string ); $sth->execute( $scanname, $system ); my $results = $sth->fetchrow_arrayref(); my $hostname = $$results[0]; my $ip = $$results[1]; my $status = $$results[2]; my $filestotal = $$results[3]; my $filesdone = $$results[4]; my $bytestotal = $$results[5]; my $bytesdone = $$results[6]; my $updated = $$results[7]; my $profile = $$results[8]; my $control = $$results[9]; my $string = "SELECT COUNT(*) FROM results WHERE scan=? AND tracker=?"; $sth = $dbh->prepare( $string ); $sth->execute( $scanname, $system ); my $results = $sth->fetchrow_arrayref(); my $total = $$results[0]; my $string = "SELECT COUNT(*) FROM results WHERE scan=? AND tracker=? AND is_false=\"1\""; $sth = $dbh->prepare( $string ); $sth->execute( $scanname, $system ); my $results = $sth->fetchrow_arrayref(); my $fp_count = $$results[0]; print "Results for $ip"; if( $hostname ne "" ) { print " ($hostname)"; } print ":

    \n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; if( $filesdone ne "" ) { print "\n"; } else { print "\n"; } print "\n"; if( $filestotal ne "" ) { print "\n"; } else { print "\n"; } print "\n"; if( $bytesdone ne "" ) { print "\n"; } else { print "\n"; } print "\n"; if( $bytestotal ne "" ) { print "\n"; } else { print "\n"; } print "\n"; print "\n"; my $diff = $total - $fp_count; print "\n"; my $currenttime = time(); my $updatedtime = localtime( $updated ); my $timediff = $currenttime - $updated; print "\n"; # pause print "\n"; if( $control eq "running" ) { print "\n"; } else { print "\n"; } # resume print "\n"; if( $control eq "stopped" ) { print "\n"; } else { print "\n"; } # uninstall print "\n"; if( $control =~ /^(stopped|running)$/i ) { print "\n"; } else { print "\n"; } print "
    Profile$profile
    Status$control
    Step\n"; if( $status == -1 ) { print "-1: Deploying\n"; } elsif( $status == 0 ) { print "0: All files\n"; } elsif( $status == 1 ) { print "1: Whitelisting\n"; } elsif( $status == 2 ) { print "2: Scanning\n"; } elsif( $status == 3 ) { print "3: Done\n"; } print "
    Files Done$filesdone
    N/A
    Files Total$filestotal
    N/A
    Bytes Done$bytesdone
    N/A
    Bytes Total$bytestotal
    N/A
    Total Findings$total
    False Positives$fp_count
    Valid Findings$diff
    Updated$updatedtime ($timediff" . "s ago)
    Pause
    N/A
    Resume
    N/A
    Stop and Uninstall
    N/A


    \n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; my $string = "SELECT DISTINCT type,pattern,file,offset,md5,number,is_false FROM results WHERE scan=? AND tracker=? AND is_false != \"1\""; my $sth = $dbh->prepare( $string ); $sth->execute( $scanname, $system ); my $row_counter = 1; while( my $results = $sth->fetchrow_arrayref() ) { my $type = $$results[0]; my $pattern = $$results[1]; my $file = $$results[2]; my $offset = $$results[3]; my $md5 = $$results[4]; my $number = $$results[5]; print "\n"; $row_counter++; print "\n"; my $pattern_copy = replacechars( $pattern ); print "\n"; my $file_printme = $file; $file_printme =~ s/\\\\/\\/g; $file_printme = replacechars( $file_printme ); print "\n"; print "\n"; print "\n\n"; # make a fancy false positive interface in the next release # print "\n"; } print "\n"; print "
    #RegexPatternFileByte offsetFalse?
    $row_counter$type$pattern_copy$file_printme$offset
    \n"; } } footer(); sub header { print "Content-type: text/html\n\n"; print "\n\n"; print "OpenDLP 0.1\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; # make a fancy false positive interface in the next release # print qq { # # # }; print "\n"; print "\n"; print '
    ' . "\n"; } sub footer { print "
    \n"; } sub replacechars { my $string = shift; $string =~ s/\&/\&/g; $string =~ s/\#/#/g; $string =~ s/"/"/g; $string =~ s/\%/%/g; $string =~ s/\'/'/g; $string =~ s/\////g; $string =~ s//>/g; $string =~ s/\[/[/g; $string =~ s/\\/\/g; $string =~ s/\]/]/g; $string =~ s/`/`/g; $string =~ s/{/{/g; $string =~ s/\|/|/g; $string =~ s/}/}/g; $string =~ s/\n//g; $string =~ s/\r//g; $string =~ s/\ / /g; return $string; }