From 4f0d6bf797392081bf12d1c18535241c6d20a5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20K=C3=A1cha?= <ph@cesnet.cz> Date: Thu, 28 Nov 2013 14:42:52 +0100 Subject: [PATCH] Added experimental Warden client library with SOAP::Lite and LWP::Protocol::https replaced by Net::SSLeay and XML::Parser --- src/contrib/warden-client-nosoap/doc/AUTHORS | 25 ++ .../warden-client-nosoap/doc/CHANGELOG | 77 ++++ src/contrib/warden-client-nosoap/doc/INSTALL | 6 + src/contrib/warden-client-nosoap/doc/LICENSE | 27 ++ src/contrib/warden-client-nosoap/doc/README | 61 +++ .../warden-client-nosoap/doc/README.cesnet | 166 ++++++++ .../doc/command-line-sender.pl | 95 +++++ .../doc/example-info.pl.txt | 48 +++ .../doc/example-receiver.pl.txt | 50 +++ .../doc/example-sender-random.pl.txt | 91 +++++ .../doc/example-sender.pl.txt | 59 +++ .../warden-client-nosoap/etc/package_version | 1 + .../etc/warden-client.conf | 61 +++ .../lib/WardenClientCommon.pm | 174 +++++++++ .../lib/WardenClientConf.pm | 40 ++ .../lib/WardenClientReceive.pm | 130 +++++++ .../lib/WardenClientSend.pm | 99 +++++ .../lib/WardenClientSend.t | 32 ++ .../warden-client-nosoap/sh/install.sh | 357 +++++++++++++++++ .../warden-client-nosoap/sh/uninstall.sh | 171 ++++++++ src/contrib/warden-client-nosoap/sh/update.sh | 366 ++++++++++++++++++ 21 files changed, 2136 insertions(+) create mode 100644 src/contrib/warden-client-nosoap/doc/AUTHORS create mode 100644 src/contrib/warden-client-nosoap/doc/CHANGELOG create mode 100644 src/contrib/warden-client-nosoap/doc/INSTALL create mode 100644 src/contrib/warden-client-nosoap/doc/LICENSE create mode 100644 src/contrib/warden-client-nosoap/doc/README create mode 100644 src/contrib/warden-client-nosoap/doc/README.cesnet create mode 100755 src/contrib/warden-client-nosoap/doc/command-line-sender.pl create mode 100755 src/contrib/warden-client-nosoap/doc/example-info.pl.txt create mode 100755 src/contrib/warden-client-nosoap/doc/example-receiver.pl.txt create mode 100755 src/contrib/warden-client-nosoap/doc/example-sender-random.pl.txt create mode 100755 src/contrib/warden-client-nosoap/doc/example-sender.pl.txt create mode 100644 src/contrib/warden-client-nosoap/etc/package_version create mode 100644 src/contrib/warden-client-nosoap/etc/warden-client.conf create mode 100755 src/contrib/warden-client-nosoap/lib/WardenClientCommon.pm create mode 100755 src/contrib/warden-client-nosoap/lib/WardenClientConf.pm create mode 100755 src/contrib/warden-client-nosoap/lib/WardenClientReceive.pm create mode 100755 src/contrib/warden-client-nosoap/lib/WardenClientSend.pm create mode 100644 src/contrib/warden-client-nosoap/lib/WardenClientSend.t create mode 100755 src/contrib/warden-client-nosoap/sh/install.sh create mode 100755 src/contrib/warden-client-nosoap/sh/uninstall.sh create mode 100755 src/contrib/warden-client-nosoap/sh/update.sh diff --git a/src/contrib/warden-client-nosoap/doc/AUTHORS b/src/contrib/warden-client-nosoap/doc/AUTHORS new file mode 100644 index 0000000..836f0d9 --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/AUTHORS @@ -0,0 +1,25 @@ +AUTHORS AND MAINTAINERS : + +PROJECT ARCHITECTS: +Pavel Kacha <ph@cesnet.cz> +Andrea Kropacova <andrea@cesnet.cz> +Jan Vykopal <vykopal@cesnet.cz> + +MAIN DEVELOPERS: +Michal Kostenec <kostenec@cesnet.cz> +Tomas Plesnik <plesnik@cesnet.cz> +Jan Soukal <soukal@cesnet.cz> + +TESTING: +Jakub Cegan <jakubcegan@cesnet.cz> + +CONTRIBUTORS: +Radoslav Bodo <bodik@civ.zcu.cz> +Martin Drasar <drasar@ics.muni.cz> +Vit Slama <slama@cis.vutbr.cz> + +COMMUNITY: +Radomir Orkac <orkac@cesnet.cz> +Daniel Studeny <Daniel.Studeny@cesnet.cz> +Pavel Vachek <Pavel.Vachek@cesnet.cz> +Martin Zadnik <izadnik@fit.vutbr.cz> diff --git a/src/contrib/warden-client-nosoap/doc/CHANGELOG b/src/contrib/warden-client-nosoap/doc/CHANGELOG new file mode 100644 index 0000000..8e4be77 --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/CHANGELOG @@ -0,0 +1,77 @@ +2013-11-28 v.2.2-nosoap-alpha2 +-------------------------------------------------------------------------------- +- replaced SOAP::Lite and LWP::Protocol::https by own Warden specific soap/http + client based on Net::SSLeay and XML::Parser + +2012-12-?? v.2.2-beta version +-------------------------------------------------------------------------------- +- Added support of connection timeout interval (#925) +- Added new getClientInfo() function allowing the client to see (#609) + information regarding other involved clients +- Enhanced handling of errors. Die() functions are removed from (#599) + the code, errors are handled using return values. + +2013-02-05 v.2.1 stable +-------------------------------------------------------------------------------- +- Minor changes in documentation + +2012-11-05 v.2.1-beta version +-------------------------------------------------------------------------------- +- Added WardenClientCommon.pm package containing error-handling and + connect-to-server functions +- Installation of Warden client does not require copying of certificates + and keys (#553) +- Enhanced error messages (#552) +- Reading of configuration file enhanced (#533) +- Added protection from unexpected results in XML data returned from + server (#532) +- Added support for error (debug) logging via STDERR and/or Syslog (#520,#522) +- Receiving of all types of messages now supported +- Unexpected errors does not crush the client application (#519) +- Maximum number of events received ($MAX_RCV_EVENTS_LIMIT) in one + batch can be set in etc/warden-client.conf. Default is 6000. (#504) +- Added support for batch processing (#504) + + +2012-07-27 v.2.0 stable version and bugfix release of warden-client-2.0.0-beta +-------------------------------------------------------------------------------- +- Sender client code fixed, so that it will not terminate "parent" + application when crashed + + +2012-05-10 v.2.0.0-beta beta version of warden-client-2.0.0 +-------------------------------------------------------------------------------- +- Changed communication with server: HTTP layer added (compatible with + Apache mod_perl version of Warden server) +- Removed Linux version check in install.sh, unistall.sh and update.sh +- Removed shell (BASH) dependencies in install.sh, unistall.sh and update.sh + + +2012-03-30 v1.2.0 stable version and bugfix release of warden-client-1.1.0 +-------------------------------------------------------------------------------- +- Fixed SSL certificate/key access privileges security issue +- Fixed client crash after multiple events download +- Fixed install.sh crash when warden client installation dictionary doesn't exist +- Fixed configuration error in permission access to etc directory in update.sh +- Fixed bug in backup process in update.sh +- Fixed several small bugs/issues + + +2012-02-06 v1.1.0 stable version and bugfix release of warden-client-1.0.0 +-------------------------------------------------------------------------------- +- Fixed bug when receiving of events +- Fixed earlier declaration in same scope of variable $data +- Fixed errMsg function -> finishing by the die function +- Added client configuration module WardenClientConf.pm +- Added error message when warden server is down +- Added README.cesnet (CESNET Specifics) file +- Added uninstallation script -> uninstall.sh +- Added update script -> update.sh +- Fixed several small bugs/issues + + +2011-11-16 v1.0.0 stable version +-------------------------------------------------------------------------------- +- Initial package of warden client +- SSL certificate authentication/authorization supported +- Automatized installation process diff --git a/src/contrib/warden-client-nosoap/doc/INSTALL b/src/contrib/warden-client-nosoap/doc/INSTALL new file mode 100644 index 0000000..01b32fd --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/INSTALL @@ -0,0 +1,6 @@ +This code is experimental and does not yet have streamlined instalation. +Simply copy the tree into desired place (usually /opt/warden-client, or +preferably /opt/warden-client-nosoap), add necessary certificates, edit +etc/warden-client.conf to your liking and from your application import +library and call the API exactly the same way you did with original SOAP +client (see the readme or examples in doc directory). diff --git a/src/contrib/warden-client-nosoap/doc/LICENSE b/src/contrib/warden-client-nosoap/doc/LICENSE new file mode 100644 index 0000000..637e108 --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/LICENSE @@ -0,0 +1,27 @@ +BSD License + +Copyright © 2011-2013 Cesnet z.s.p.o +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the Cesnet z.s.p.o nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE Cesnet z.s.p.o BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/contrib/warden-client-nosoap/doc/README b/src/contrib/warden-client-nosoap/doc/README new file mode 100644 index 0000000..03231c3 --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/README @@ -0,0 +1,61 @@ ++------------------------------------------+ +| README - Warden Client 2.2-nosoap-alpha2 | ++------------------------------------------+ + +WARNING - this code is experimental and especially documentation may not +exactly reflect the exact state of affairs. + +Content + + A. Overall Information + B. Installation Dependencies + C. Installation, Configuration, Registration, Usage + + +-------------------------------------------------------------------------------- +A. Overall Information + + 1. About Warden Client + + Warden is a client-based architecture service designed to share detected + security events (issues) among CSIRT and CERT teams in a simple and fast + way. + + This package offers a client capable of both reporting events to server and + retreiving batch of new events from server. It consists of several Perl + modules/libraries which should be included into detection applications. + + This is experimental version of Warden client without dependence on + SOAP::Lite and LWP::Protocol::https. However it is designed to work with + existing SOAP capable Warden server and expose exactly the same API as + SOAP::Lite based client (so there's no need for any changes in existing + applications whatsoever). + +-------------------------------------------------------------------------------- +B. Installation Dependencies + + Perl >= 5.10.1 + SOAP::Lite >= 0.712 + IO::Socket::SSL >= 1.74 + SOAP::Transport::HTTP >= 0.712 + FindBin >= 1.50 + DateTime >= 0.61 + Carp >= 1.11 + +-------------------------------------------------------------------------------- +C. Installation, Configuration, Registration, Usage + + This code is experimental and does not yet have streamlined instalation. + Simply copy the tree into desired place (usually /opt/warden-client, or + preferably /opt/warden-client-nosoap), add necessary certificates, edit + etc/warden-client.conf to your liking and from your application import + library and call the API exactly the same way you did with original SOAP + client (see the readme or examples in doc directory). + + For configuration, registration and usage please refer to documentation + of original SOAP based Warden client. + +-------------------------------------------------------------------------------- + +Copyright (C) 2011-2013 Cesnet z.s.p.o + diff --git a/src/contrib/warden-client-nosoap/doc/README.cesnet b/src/contrib/warden-client-nosoap/doc/README.cesnet new file mode 100644 index 0000000..52cb24b --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/README.cesnet @@ -0,0 +1,166 @@ ++-----------------------------------+ +| README.cesnet - Warden Client 2.1 | +| | +| CESNET Specifics | ++-----------------------------------+ + +Content + + A. Overall Information + B. Registration + C. Description tags + D. Types of events + E. Configuration + F. Testing + G. Authors of this document + +-------------------------------------------------------------------------------- +A. Overall Information + + 1. About CESNET Warden Server + + Warden is a client-based architecture service designed to share detected + security events (issues) among CSIRT and CERT teams in a simple and fast way. + + CESNET offers Warden server for security events exchange within its networks. + + 2. Version + + 2.1 (2013-02-05) + +-------------------------------------------------------------------------------- +B. Registration + + Client attempting to communicate with CESNET Warden server must be + registered. Registration is currently provided by Tomas Plesnik at + mail address plesnik@ics.muni.cz and following information is needed: + + * For sender client: + - hostname of the machine, where client runs, + - client type = sender, + - name of the detection service (for example 'ScanDetector'), + - description tags of sent events (see below) + - CIDR from which client will communicate with Warden server. + + * For receiver client: + - hostname of the machine, where client runs, + - client type = receiver, + - whether client should receive all events, or type of requested + events (for example 'portscan', see below) otherwise + - receiving of sent events from my organization = yes/no (organizations + are separated based on the top-level and second-level domain), + - CIDR from which client will communicate with Warden server. + + Clients need to have valid certificate to prove their identity to the + Warden server. For CESNET network, 'server' type certificate from Terena + Certificate Service (provided by Comodo) is needed. Hostname of the + machine must correspond with certificate subject, Alternative Name + extension is not supported. Administrator of Warden client must be + entitled to obtain this certificate. CESNET TCS request service + interface resides at + + https://tcs.cesnet.cz/ + +-------------------------------------------------------------------------------- +C. Description tags + + Tags are case insensitive alphanumeric strings, designed to allow event + receivers to do more general filtering according to event source. Receiver + can for example decide to use only events originating at honeypots, or + filter out events, generated by human conclusions or correlation engines. + + Sender client specifies its descriptive tags during registration, it is + up to client administrator's judgment to select or omit any particular tag. + Currently tags fall into four general categories - based on event medium, + data source, detection methodology and detector or analyzer product name. + Product name tag is free to choose if same product name was not yet + accepted by registrar, otherwise existing form must be used (registrar will + notify about such cases). + Categories list is certainly not complete. Therefore if new client's + administrator feels that name or type of important feature of his (or + others) detector is not covered, providers of Warden server are glad to + discuss it at registration address or at Warden project mailing list + (warden@cesnet.cz). + However, it may or may not be accepted, as aim is to keep the list of + categories possibly unambiguous, short and usable. + + Following is grouped list of tags together with closer description and + examples. + + 1. Detection medium + + * Network - network data based (Snort, Suricata, Bro, FTAS, LaBrea, Kippo, + Dionaea) + * Host - host based (Swatch, Logcheck) + * Correlation - corellation engines (Prelude, OSSIM) + * External - credible external sources (incident reporting, ticket + systems, human verified events) + + 2. Data source + + * Content - datagram content based detectors (Snort, Bro) + * Flow - netflow based (FTAS, FlowMon, HoneyScan) + * Connection - connection data (portscan, portsweep) + * Data - application data based (SpamAssassin, antiviruses) + * Log - based on system logs, where more specific source is not + applicable (Swatch, Logcheck, SSH scans) + * IR - incident reporting, ticket systems, human verified events + + 3. Detection methodology + + * Honeypot (LaBrea, Kippo, Dionaea) + * Antispam (SpamAssassin, Bogofilter, CRM114, Policyd, greylisting) + * Antivirus (ClamAV) + * IDS - IDS/IPS, Snort, Suricata, Bro + + 4. Detector/analyzer product name examples + + * Snort, FTAS, SpamAssassin, LaBrea, Swatch, Prelude, Kippo, Dionaea + +-------------------------------------------------------------------------------- +D. Types of events + + Event types purpose is to allow event receivers to filter and/or categorise + particular events according to attack characteristics. Types are loosely + chosen as list of common security incidents nowadays observed. List is by no + means complete, however it was created based on expected use cases at + receiving places. Possibility of a new type is also open to discussion. + + * portscan - TCP/UDP port scanning/sweeping + * bruteforce - dictionary/bruteforce attack to services authentication + * probe - other connection attempts (for example ICMP) or + unrecognized/undecided portscan or bruteforce + * spam - unsolicited commercial email (except phishing) + * phishing - email, trying to scam user to revealing personal information + (possibly by some other channel) + * botnet_c_c - botnet command & control master machine + * dos - (possibly distributed) denial of service attack + * malware - virus/malware sample + * copyright - copyright infringement + * webattack - web application attack + * test - clients can use these at will when debugging/testing, these + messages will be processed and stored, but ignored later + * other - the rest, uncategorizable yet + + In case of complex scenarios with structured info more events with + particular parts of information can be created. + +-------------------------------------------------------------------------------- +E. Configuration + + CESNET Warden server resides at URI 'https://warden.cesnet.cz:443/Warden'. + +-------------------------------------------------------------------------------- +F. Testing + + For testing purposes of sender clients, event type 'test' can be used. + These events will end up in server database, but will not be taken + further into consideration. + +-------------------------------------------------------------------------------- +G. Authors of this document + + Pavel Kacha <ph@cesnet.cz> + Jan Soukal <soukal@ics.muni.cz> + +Copyright (C) 2011-2013 Cesnet z.s.p.o diff --git a/src/contrib/warden-client-nosoap/doc/command-line-sender.pl b/src/contrib/warden-client-nosoap/doc/command-line-sender.pl new file mode 100755 index 0000000..75fce01 --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/command-line-sender.pl @@ -0,0 +1,95 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +use strict; +use DateTime; +use Getopt::Long; + +#------------------------------------------------------------------------------- +# Warden 2.2. Command-line Client, Sender +# +# Command-line warden-client sender. For detailed info how to use particular +# variables and/or values see warden-client/doc/README file. +#------------------------------------------------------------------------------- + +#------------------------------------------------------------------------------- +# Preparation of event attributes. + +# Mandatory attributes +my $opt_s; # service +my $opt_t = "" . DateTime->from_epoch(epoch => time()) . ""; # time of detection +my $opt_e; # type of detected event +my $opt_o; # event source type + +# Optional attributes +my $opt_v = ""; # event source value +my $opt_p = ""; # target protocol +my $opt_r = ""; # target port +my $opt_a = ""; # attack scale +my $opt_n = ""; # note + +# Other attributes +my $opt_w = "../../warden-client"; # path to warden directory +my $opt_h; # display help + +# Check whether mandatory fields are given. Otherwise print help and exit. +if (!GetOptions("service|s=s" => \$opt_s, + "timestamp|t=s" => \$opt_t, + "event-type|e=s" => \$opt_e, + "source-type|o=s" => \$opt_o, + "source-value|v=s" => \$opt_v, + "proto|p=s" => \$opt_p, + "port|r=i" => \$opt_r, + "attack-scale|a=i" => \$opt_a, + "note|n=s" => \$opt_n, + "warden-dir|w=s" => \$opt_w, + "help|h" => \$opt_h) || + !defined($opt_s) || !defined($opt_e) || !defined($opt_o) || + $opt_h) { + print "\nAbout command-line-sender.pl\n"; + print "\n Script is supposed to be used as a simple command-line warden client that can send one event to the warden server at a time. For more information about the Warden system and it's events' structure, please see warden-client/doc/README file.\n"; + print "\nUsage:\n\n ./command-line-sender.pl -s <service> -e <event_type> -o <source_type> [-t <timestamp_of_detection>] [-v <source>] [-p <protocol>] [-r <port>] [-a <attack_scale>] [-n <note>] [-w <warden_directory>] [-h]\n"; + print "\nArguments:\n\n"; + print " -s SERVICE, --service=SERVICE - Name of detection service\n\n"; + print " -e EVENT_TYPE, --event-type=EVENT_TYPE - Type of detected event\n\n"; + print " -o SOURCE_TYPE, --source-type=SOURCE_TYPE - Type of detected event\'s source\n\n"; + print "\n"; + print "Optional (but important) arguments:\n\n"; + print " -t TIMESTAMP, --timestamp=TIMESTAMP - Timestamp of detection.\n"; + print " Default is current system time (" . DateTime->from_epoch(epoch => time()) . ")\n\n"; + print " -v SOURCE_VALUE, --source-value=SOURCE_VALUE - Source of detected event\n\n"; + print " -p PROTO, --proto=PROTO - Protocol\n\n"; + print " -r PORT, --port=PORT - Port\n\n"; + print " -a ATTACK_SCALE, --attack-scale=ATTACK_SCALE - Scale of detected event\n\n"; + print " -n NOTE, --note=NOTE - Note, comment or other data\n\n"; + print " -w WARDEN_DIR, --warden-dir=WARDEN_DIR - Path to the warden-client directory. Default is \'../../warden-client\'\n\n"; + print " -h, --help - Print help\n\n"; + + print "\nExample #1: ./command-line-sender.pl -s PhishTracker -e webattack -o URL -v 123.123.098.098 -p TCP -r 443 -a 100 -n \"important notice\"\n"; + print "\nExample #2: ./command-line-sender.pl --service=ScanGuardian --event-type=portscan --source-type=IP --timestamp=\"2013-04-25T13:36:31\" --source-value=\"123.123.1.23\" --proto=TCP --port=25 --attack-scale=1234 --note=\"The very first run of ScanGuardian :)\" --warden-dir \"/opt/warden/warden-client\"\n"; + + print "\nNOTE: For more information how to use particular values see warden-client/doc/README file.\n\n"; + + exit 0; +} + + +my @event = ($opt_s, $opt_t, $opt_e, $opt_o, $opt_v, + $opt_p, $opt_r, $opt_a, $opt_n); + +#------------------------------------------------------------------------------- +# Use of warden-client sender. + +# Path to warden-client folder +my $warden_path = $opt_w; + +# Inclusion of warden-client sender module +require $warden_path . '/lib/WardenClientSend.pm'; + +# Sending event to Warden server +WardenClientSend::saveNewEvent($warden_path, \@event); + +exit 0; diff --git a/src/contrib/warden-client-nosoap/doc/example-info.pl.txt b/src/contrib/warden-client-nosoap/doc/example-info.pl.txt new file mode 100755 index 0000000..3a9d294 --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/example-info.pl.txt @@ -0,0 +1,48 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +use strict; + +#------------------------------------------------------------------------------ +# Warden 2.2 Client, Info, Example +# +# Simple use of warden-client Info functionality to receive information about +# client registered to Warden server. This code illustrates how to integrate +# warden-client info functionality into local applications. +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# This code should developer add into his/her application. + +# Path to warden-client directory +my $warden_path = '/opt/warden-client/'; + +# Inclusion of warden-client receiving functionality +require $warden_path . '/lib/WardenClientCommon.pm'; + +my @clients = WardenClientCommon::getClientsInfo($warden_path) or exit 1; # receive data or exit + +print "+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n"; +print "| Client ID | Hostname | Registered | Requestor | Service | CT | Type | ROE | Description tags | IP Net Client |\n"; +print "+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n"; + +foreach (@clients) { + printf("| %-10s ", $_->{'client_id'} || "NULL"); + printf("| %-30s ", $_->{'hostname'} || "NULL"); + printf("| %19s ", $_->{'registered'} || "NULL"); + printf("| %-23s ", $_->{'requestor'} || "NULL"); + printf("| %-25s ", $_->{'service'} || "NULL"); + printf("| %-2s ", $_->{'client_type'} || "NULL"); + printf("| %-15s ", $_->{'type'} || "NULL"); + printf("| %-4s ", $_->{'receive_own_events'} || "NULL"); + printf("| %-50s ", $_->{'description_tags'} || "NULL"); + printf("| %-18s |\n", $_->{'ip_net_client'} || "NULL"); +} +print "+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n"; +print "\n"; +print "Current registered clients in: " . scalar localtime(time) . "\n"; + +exit 0; diff --git a/src/contrib/warden-client-nosoap/doc/example-receiver.pl.txt b/src/contrib/warden-client-nosoap/doc/example-receiver.pl.txt new file mode 100755 index 0000000..b5d1b3e --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/example-receiver.pl.txt @@ -0,0 +1,50 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +use strict; + +#------------------------------------------------------------------------------ +# Warden 2.2 Client, Receiver, Example +# +# Simple use of warden-client receiver functionality to download new events +# from # Warden server. This code illustrates how to integrate warden-client +# receive functionality into local applications. +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# This code should developer add into his/her application. + +# Path to warden-client directory +my $warden_path = '/opt/warden-client/'; + +# Inclusion of warden-client receiving functionality +require $warden_path . '/lib/WardenClientReceive.pm'; + +# Definition of requested event type. This attributes is also set on server +# and must not change. +my $requested_type = "portscan"; + +#------------------------------------------------------------------------------ +# Simple code that prints out new events obtained from Warden server. + +print "+------------------------------------------------------------------------------------------------------------------------------------------+\n"; +print "| id | hostname | service | detected | type | source_type | source | target_proto | target_port | attack_scale | note | priority | timeout |\n"; +print "+------------------------------------------------------------------------------------------------------------------------------------------+\n"; + +# Download of new evetns from Warden server +while (my @new_events = WardenClientReceive::getNewEvents($warden_path, $requested_type)) { + foreach my $event_ref (@new_events) { + my @event = @$event_ref; + print "| " . join(' | ', map { $_ || '' } @event) . " |" . "\n"; + } +print "+------------------------------------------------------------------------------------------------------------------------------------------+\n"; +} + +print "+------------------------------------------------------------------------------------------------------------------------------------------+"; +print "\n"; +print "Last events in: " . scalar(localtime(time)) . "\n"; + +exit 0; diff --git a/src/contrib/warden-client-nosoap/doc/example-sender-random.pl.txt b/src/contrib/warden-client-nosoap/doc/example-sender-random.pl.txt new file mode 100755 index 0000000..fa15f8a --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/example-sender-random.pl.txt @@ -0,0 +1,91 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +use Switch; +use strict; +use DateTime; + +my $warden_path = '/opt/warden-client'; +require $warden_path . '/lib/WardenClientSend.pm'; + +my $service = "test"; +# service is needed in authorization process of the client, +# therefore it can not be set randomly +#switch (int(rand(3) + 0.5)) { +# case 1 { $service = 'ScanDetector'; } +# case 2 { $service = 'PhiGaro'; } +# case 3 { $service = 'HoneyScan'; } +# } + +my $detected = DateTime->from_epoch(epoch => time()); + +my $type = ""; +switch (int(rand(10) + 0.5)) { + case 1 { $type = 'portscan'; } + case 2 { $type = 'bruteforce'; } + case 3 { $type = 'spam'; } + case 4 { $type = 'phishing'; } + case 5 { $type = 'botnet_c_c'; } + case 6 { $type = 'dos'; } + case 7 { $type = 'malware'; } + case 8 { $type = 'copyright'; } + case 9 { $type = 'webattack'; } + case 10 { $type = 'other'; } + } + +my $source_type = ""; +switch (int(rand(3) + 0.5)) { + case 1 { $source_type = 'IP'; } + case 2 { $source_type = 'URL'; } + case 3 { $source_type = 'Reply-To:'; } + } + +my $source = (int(rand(254) + 0.5) + 1) . "." . (int(rand(254) + 0.5) + 1) . "." . (int(rand(254) + 0.5) + 1) . "." . (int(rand(254) + 0.5) + 1); + +my $target_proto = ""; +switch (int(rand(2) + 0.5)) { + case 1 { $target_proto = 'TCP'; } + case 2 { $target_proto = 'UDP'; } + } + +my $target_port = ""; +switch (int(rand(6) + 0.5)) { + case 1 { $target_port = '22'; } + case 2 { $target_port = '23'; } + case 3 { $target_port = '25'; } + case 4 { $target_port = '443'; } + case 5 { $target_port = '3389'; } + case 6 { $target_port = 'null'; } + } + +my $attack_scale = (int(rand(100000) + 0.5) + 1000); + +my $note = "tohle je takova normalni jednoducha poznamka"; + +my $priority = int(rand(255) + 0.5); + +my $timeout = int(rand(255) + 0.5); + + +my @event = ( + $service, # $service + "$detected", # $detected + $type, # $type + $source_type, # $source_type + $source, # $source + $target_proto, # $target_proto + $target_port, # $target_port + $attack_scale, # $attack_scale + $note, # $note + $priority, # $priority + $timeout, # $timeout + ); + +WardenClientSend::saveNewEvent($warden_path, \@event); + +#foreach (@event) { +# print "$_\n"; +#} diff --git a/src/contrib/warden-client-nosoap/doc/example-sender.pl.txt b/src/contrib/warden-client-nosoap/doc/example-sender.pl.txt new file mode 100755 index 0000000..75a5e67 --- /dev/null +++ b/src/contrib/warden-client-nosoap/doc/example-sender.pl.txt @@ -0,0 +1,59 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +use strict; +use DateTime; + +#------------------------------------------------------------------------------- +# Warden 2.2. Client, Sender, Example +# +# Sample script using warden-client sending functionality. This example is not +# intended to be a standalone script. It only shows how to use warden-client +# functionality. +#------------------------------------------------------------------------------- + +#------------------------------------------------------------------------------- +# Preparation of event attributes. +# This should be handled by detection application. + + +my $local_detected = DateTime->from_epoch(epoch => time()); + + +my $service = "test"; +my $detected = "$local_detected"; +my $type = "portscan"; +my $source_type = "IP"; +my $source = "123.123.123.123"; +my $target_proto = "TCP"; +my $target_port = "22"; +my $attack_scale = "1234567890"; +my $note = "important note or comment"; +my $priority = 1; +my $timeout = 20; + +my @event = ($service, $detected, $type, $source_type, $source, + $target_proto, $target_port, $attack_scale, $note, + $priority, $timeout ); + +#------------------------------------------------------------------------------- +# Use of warden-client sender. +# This code should developer add to his/her detection application +# (with corresponding paths appropriately changed). + +# Path to warden-client folder +my $warden_path = '/opt/warden-client'; + +# Inclusion of warden-client sender module +require $warden_path . '/lib/WardenClientSend.pm'; + +# Sending event to Warden server +for (my $i = 0; $i < 10; $i++) { + print "Sending $i-st event on server\n"; + WardenClientSend::saveNewEvent($warden_path, \@event); + } + +exit 0; diff --git a/src/contrib/warden-client-nosoap/etc/package_version b/src/contrib/warden-client-nosoap/etc/package_version new file mode 100644 index 0000000..2912c9a --- /dev/null +++ b/src/contrib/warden-client-nosoap/etc/package_version @@ -0,0 +1 @@ +warden-client-2.2-nosoap-alpha diff --git a/src/contrib/warden-client-nosoap/etc/warden-client.conf b/src/contrib/warden-client-nosoap/etc/warden-client.conf new file mode 100644 index 0000000..c575797 --- /dev/null +++ b/src/contrib/warden-client-nosoap/etc/warden-client.conf @@ -0,0 +1,61 @@ +# +# warden-client.conf - configuration file for the warden sender/receiver client +# + +#------------------------------------------------------------------------------- +# URI - URI address of Warden server +#------------------------------------------------------------------------------- +$URI = "https://warden-sandbox.cesnet.cz:443/Warden"; + +#------------------------------------------------------------------------------- +# SSL_KEY_FILE - path to client SSL certificate key file +#------------------------------------------------------------------------------- +$SSL_KEY_FILE = "/opt/warden-client/etc/warden-client-key.pem"; + +#------------------------------------------------------------------------------- +# SSL_CERT_FILE - path to client SSL certificate file +#------------------------------------------------------------------------------- +$SSL_CERT_FILE = "/opt/warden-client/etc/warden-client-cert.pem"; + +#------------------------------------------------------------------------------- +# SSL_CA_FILE - path to CA certificate file +#------------------------------------------------------------------------------- +$SSL_CA_FILE = "/opt/warden-client/etc/tcs-ca-bundle.pem"; + +#------------------------------------------------------------------------------- +# MAX_RCV_EVENTS_LIMIT - maximum number of events the client is allowd to get +# from the Warden server in one batch +#------------------------------------------------------------------------------- +$MAX_RCV_EVENTS_LIMIT = 6000; #consumes app. 250 MB of memory + +# !WARNING! - CONNECTION_TIMEOUT is not supported in nosoap client because of +# lack of support in Net::SSLeay +#------------------------------------------------------------------------------- +# CONNECTION_TIMEOUT - interval in seconds to timeout connection with Warden +# server. If your client timeouts, consider using higher +# timeout number. Also, in case of receiving clients, you +# can optimize the MAX_RCV_EVENTS_LIMIT value. +#------------------------------------------------------------------------------- +$CONNECTION_TIMEOUT = 60; + +#------------------------------------------------------------------------------- +# Log options +# +# LOG_STDERR, LOG_SYSLOG - hide (0) or allow (1) error reporting on STDERR +# and/or to Syslog +# LOG_STDERR_VERBOSE, LOG_SYSLOG_VERBOSE - print only error message without +# a stack (0) or print debug info +# including err. message and stack (1) +#------------------------------------------------------------------------------- +$LOG_STDERR = 1; + +$LOG_SYSLOG = 0; +$LOG_SYSLOG_FACILITY = "local7"; + +$LOG_VERBOSE = 1; + + + +1; + + diff --git a/src/contrib/warden-client-nosoap/lib/WardenClientCommon.pm b/src/contrib/warden-client-nosoap/lib/WardenClientCommon.pm new file mode 100755 index 0000000..db5cd58 --- /dev/null +++ b/src/contrib/warden-client-nosoap/lib/WardenClientCommon.pm @@ -0,0 +1,174 @@ +#!/usr/bin/perl -w +# +# WardenClientCommon.pm +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +package WardenClientCommon; + +use strict; +use Carp; +use SOAP::Lite; +use IO::Socket::SSL qw(debug1); +use SOAP::Transport::HTTP; + +our $VERSION = "2.2"; + +#------------------------------------------------------------------------------- +# errMsg - prints error msg and returns undef or prints warning and returns 1 +#------------------------------------------------------------------------------- +sub errMsg +{ + my $msg = shift; + my $type = shift; + defined $type or $type = "err"; # default type is err. Other: warn + + # is this error report and is Verbose logging mode enabled? + if (($type eq "err") && ($WardenClientConf::LOG_VERBOSE)) { # user wants to log debug information + $msg .= "\nStack info: " . Carp::longmess(); + } + + # log into STDERR? + if ($WardenClientConf::LOG_STDERR) { + print STDERR $msg . "\n"; + } + + # log into Syslog? + if ($WardenClientConf::LOG_SYSLOG) { + openlog("Warden-client:", "pid", "$WardenClientConf::LOG_SYSLOG_FACILITY"); + syslog("$type|$WardenClientConf::LOG_SYSLOG_FACILITY", $msg . "\n"); + closelog(); + } + + if ($type eq 'warn') { # case of 'warn' + return 1; + } else { # case of 'err' + return; + } + +} # End of errMsg + + +#------------------------------------------------------------------------------- +# c2s - connect to server, send request and receive response +#------------------------------------------------------------------------------- +sub c2s +{ + my $uri = shift; + my $ssl_key_file = shift; + my $ssl_cert_file = shift; + my $ssl_ca_file = shift; + my $method = shift; + my $data = shift; + + my $client; + my ($server, $port, $service) = $uri =~ /https:\/\/(.+)\:(\d+)\/(.+)/; + eval { + $client = SOAP::Transport::HTTP::Client->new(); + } or return errMsg('Unknown error in c2s() when creating socket, SOAP::Transport::HTTP::Client->new(), ' . $@); + + eval {$client->timeout($WardenClientConf::CONNECTION_TIMEOUT);} + or return errMsg('Unknown error in c2s() when setting socket timeout, ' . $@); + + eval { + $client->ssl_opts(verify_hostname => 1, + SSL_use_cert => 1, + SSL_verify_mode => 0x02, + SSL_key_file => $ssl_key_file, + SSL_cert_file => $ssl_cert_file, + SSL_ca_file => $ssl_ca_file); + return 1; # fix of eval triggering 'or' statement + } or return errMsg('Unknown error in c2s() when setting socket SSL options, ' . $@); + + # setting of URI and serialize SOAP envelope and data object + + my $soap; + eval { + $soap = SOAP::Lite->uri($service)->proxy($uri); + } or return errMsg('Unknown error in c2s() when serializing SOAP object, ' . $@); + + my $envelope; + if (!defined $data) { + eval { + $envelope = $soap->serializer->envelope(method => $method); + } or return errMsg('Unknown error in c2s() when setting enevelope, ' . $@); + } else { + eval { + $envelope = $soap->serializer->envelope(method => $method, $data); + } or return errMsg('Unknown error in c2s() when setting envelope, ' . $@); + } + + # setting of TCP URI and send serialized SOAP envelope and data + my $server_uri = "https://$server:$port/$service"; + my $result; + eval { + $result = $client->send_receive(envelope => $envelope, endpoint => $server_uri); + } or return errMsg('Unknown error in c2s() sending SOAP data, ' . $@); + + # check server response + if (!defined $result) { + errMsg("Server returned empty response. Problem with used SSL ceritificates or Warden server at $server:$port is down."); + } else { + # deserialized response from server -> create SOAP envelope and data object + + my $response; + + eval { + $response = $soap->deserializer->deserialize($result); + } or return errMsg('Unknown error in SOAP data deserialization. Received data: ' . $result . ', ' . $@); + # check SOAP fault status + $response->fault ? return errMsg("Server sent error message:: " . $response->faultstring) : return $response; + } +} + +#------------------------------------------------------------------------------- +# getClientsInfo - retrieve information about other clients from Warden server +#------------------------------------------------------------------------------- +sub getClientsInfo +{ + my $warden_path = shift; + + my $etcdir = $warden_path . "/etc/"; + my $libdir = $warden_path . "/lib/"; + + require $libdir . "WardenClientConf.pm"; + + # read the config file + my $conf_file = $etcdir . "warden-client.conf"; + WardenClientConf::loadConf($conf_file); + + # c2s() returns undef on fail + my $response = c2s($WardenClientConf::URI, $WardenClientConf::SSL_KEY_FILE, $WardenClientConf::SSL_CERT_FILE, $WardenClientConf::SSL_CA_FILE, "getClientInfo"); + + defined $response or return; # receive data or return undef + + # parse returned SOAP data object with clients + my @clients; + my ($client_id, $hostname, $registered, $requestor, $service, $client_type, $type, $receive_own_events, $description_tags, $ip_net_client); + my @response_list = $response->valueof('/Envelope/Body/getClientInfoResponse/client/'); + + while (scalar @response_list) { + my $response_data = shift(@response_list); + my %client; + + $client{'client_id'} = $response_data->{'CLIENT_ID'} ; + $client{'hostname'} = $response_data->{'HOSTNAME'}; + $client{'registered'} = $response_data->{'REGISTERED'}; + $client{'requestor'} = $response_data->{'REQUESTOR'}; + $client{'service'} = $response_data->{'SERVICE'}; + $client{'client_type'} = $response_data->{'CLIENT_TYPE'}; + $client{'type'} = $response_data->{'TYPE'}; + $client{'receive_own_events'} = $response_data->{'RECEIVE_OWN_EVENTS'}; + $client{'description_tags'} = $response_data->{'DESCRIPTION_TAGS'}; + $client{'ip_net_client'} = $response_data->{'IP_NET_CLIENT'}; + + # push received clients from warden server into @clients which is returned + push (@clients,\%client); + } + + return @clients; +} + +1; diff --git a/src/contrib/warden-client-nosoap/lib/WardenClientConf.pm b/src/contrib/warden-client-nosoap/lib/WardenClientConf.pm new file mode 100755 index 0000000..2085d30 --- /dev/null +++ b/src/contrib/warden-client-nosoap/lib/WardenClientConf.pm @@ -0,0 +1,40 @@ +#!/usr/bin/perl -w +# +# WardenClientConf.pm +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +package WardenClientConf; + +use strict; + +# preset of default variables +our $URI = undef; +our $SSL_KEY_FILE = undef; +our $SSL_CERT_FILE = undef; +our $SSL_CA_FILE = undef; +our $MAX_RCV_EVENTS_LIMIT = undef; +our $LOG_STDERR = 1; +our $LOG_SYSLOG = 0; +our $LOG_SYSLOG_FACILITY = "local7"; +our $LOG_VERBOSE = 0; +our $CONNECTION_TIMEOUT = 60; + + +our $VERSION = "2.2"; + +sub loadConf +{ + my $conf_file = shift; + + # load configuration variables set by user + unless (do $conf_file) { + die("Errors in config file '$conf_file': $@") if $@; + die("Can't read config file '$conf_file': $!") unless defined $_; + # if $_ defined, it's retvalue of last statement of conf, for which we don't care + } +} + +1; diff --git a/src/contrib/warden-client-nosoap/lib/WardenClientReceive.pm b/src/contrib/warden-client-nosoap/lib/WardenClientReceive.pm new file mode 100755 index 0000000..14c012b --- /dev/null +++ b/src/contrib/warden-client-nosoap/lib/WardenClientReceive.pm @@ -0,0 +1,130 @@ +#!/usr/bin/perl -w +# +# WardenClientReceive.pm +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +package WardenClientReceive; + +use strict; +use SOAP::Lite; +use IO::Socket::SSL qw(debug1); +use SOAP::Transport::HTTP; +use FindBin; +use Sys::Syslog; + +our $VERSION = "2.2"; + +#------------------------------------------------------------------------------- +# getNewEvents - get new events from warden server greater than last received ID +#------------------------------------------------------------------------------- +sub getNewEvents +{ + my @events; + + my $warden_path = shift; + my $requested_type = shift; + + my $vardir = $warden_path . "/var/"; + my $etcdir = $warden_path . "/etc/"; + my $libdir = $warden_path . "/lib/"; + + require $libdir . "WardenClientConf.pm"; + require $libdir . "WardenClientCommon.pm"; + + # read the config file + my $conf_file = $etcdir . "warden-client.conf"; + WardenClientConf::loadConf($conf_file); + + # set name of ID file for each client aplication + my $caller_name = $FindBin::Script; + my $id_file = $vardir . $caller_name . "-". ($requested_type || "any") . ".id"; + + #----------------------------------------------------------------------------- + # get last ID from ID file (if exist) or + # get last ID from warden server DB and save it into ID file + my $last_id; + if (-e $id_file) { + open(ID, "< $id_file") or return WardenClientCommon::errMsg("Cannot open ID file $id_file: $!"); + foreach(<ID>) { + $last_id = $_; + } + close ID; + } else { + # c2s() returns undef on fail + my $response = WardenClientCommon::c2s($WardenClientConf::URI, $WardenClientConf::SSL_KEY_FILE, $WardenClientConf::SSL_CERT_FILE, $WardenClientConf::SSL_CA_FILE, "getLastId"); + defined $response or return; # receive data or return undef + + $last_id = $response->result; + open(ID, "> $id_file") or return WardenClientCommon::errMsg("Cannot open ID file $id_file: $!"); + print ID $last_id; + close ID; + } + + #----------------------------------------------------------------------------- + # get new events from warden server DB based on gathered last ID + + my $request_data; + eval { + # create SOAP data object + $request_data = SOAP::Data->name( + request => \SOAP::Data->value( + SOAP::Data->name(REQUESTED_TYPE => $requested_type), + SOAP::Data->name(LAST_ID => $last_id), + SOAP::Data->name(MAX_RCV_EVENTS_LIMIT => $WardenClientConf::MAX_RCV_EVENTS_LIMIT) + ) + ) + } or return errMsg('Unknown error when creating SOAP data object, ' . $@); + + # call server method getNewEvents + my $response = WardenClientCommon::c2s($WardenClientConf::URI, $WardenClientConf::SSL_KEY_FILE, $WardenClientConf::SSL_CERT_FILE, $WardenClientConf::SSL_CA_FILE, "getNewEvents", $request_data); + defined $response or return; # connect to warden server or return undef + + # parse returned SOAP data object + my ($id, $hostname, $service, $detected, $type, $source_type, $source, $target_proto, $target_port, $attack_scale, $note, $priority, $timeout); + + my @response_list = $response->valueof('/Envelope/Body/getNewEventsResponse/event/'); + + while (scalar @response_list) { + my $response_data = shift(@response_list); + my @event; + + # parse items of one event + $id = $response_data->{'ID'}; + $hostname = $response_data->{'HOSTNAME'}; + $service = $response_data->{'SERVICE'}; + $detected = $response_data->{'DETECTED'}; + $type = $response_data->{'TYPE'}; + $source_type = $response_data->{'SOURCE_TYPE'}; + $source = $response_data->{'SOURCE'}; + $target_proto = $response_data->{'TARGET_PROTO'}; + $target_port = $response_data->{'TARGET_PORT'}; + $attack_scale = $response_data->{'ATTACK_SCALE'}; + $note = $response_data->{'NOTE'}; + $priority = $response_data->{'PRIORITY'}; + $timeout = $response_data->{'TIMEOUT'}; + + # push new event from warden server into @events which is returned + @event = ($id, $hostname, $service, $detected, $type, $source_type, $source, $target_proto, $target_port, $attack_scale, $note, $priority, $timeout); + push (@events, \@event); + + # set maximum received ID from current batch + if ($id > $last_id) { + $last_id = $id; + } + } #end of while loop + + # write last return ID + if (defined $last_id) { # must be defined for first check ID + open(ID, "> $id_file") or return WardenClientCommon::errMsg("Cannot open ID file $id_file: $!"); + print ID $last_id; + close ID; + } + + return @events; + +} # End of getNewEvents + +1; diff --git a/src/contrib/warden-client-nosoap/lib/WardenClientSend.pm b/src/contrib/warden-client-nosoap/lib/WardenClientSend.pm new file mode 100755 index 0000000..793095e --- /dev/null +++ b/src/contrib/warden-client-nosoap/lib/WardenClientSend.pm @@ -0,0 +1,99 @@ +#!/usr/bin/perl -w +# +# WardenClientSend.pm +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +package WardenClientSend; + +use strict; +use SOAP::Lite; +use IO::Socket::SSL qw(debug1); +use SOAP::Transport::HTTP; +use Sys::Syslog; + +our $VERSION = "2.2"; + +#------------------------------------------------------------------------------- +# saveNewEvent - send new event from detection scripts to warden server +#------------------------------------------------------------------------------- +sub saveNewEvent +{ + my $result; + + my $warden_path = shift; + my $event_ref = shift; + + my $etcdir = $warden_path . "/etc/"; + my $libdir = $warden_path . "/lib/"; + + require $libdir . "WardenClientConf.pm"; + require $libdir . "WardenClientCommon.pm"; + + # read the config file + my $conf_file = $etcdir . "warden-client.conf"; + WardenClientConf::loadConf($conf_file); + + # prepare variables of event + my @event = @{$event_ref}; + my $service = $event[0]; + my $detected = $event[1]; + my $type = $event[2]; + my $source_type = $event[3]; + my $source = $event[4]; + my $target_proto = $event[5]; + my $target_port = $event[6]; + my $attack_scale = $event[7]; + my $note = $event[8]; + my $priority = $event[9]; + my $timeout = $event[10]; + + # Issue #596 - Should be removed in Warden client 3.0. + # Checking for obsolete attributes priority or timeout. If not default or 'undef' values are found, print out warning. + + # check if obsolete event attribute Priority is used + if ((defined $priority) && ($priority >= 1)) { + # print warning + WardenClientCommon::errMsg('Event attribute "Priority" is now obsolete and will be removed in Warden client 3.0', 'warn'); + } + + # check if obsolete event attribute Timeout is used + if ((defined $timeout) && ($timeout >= 0)) { + # print warning + WardenClientCommon::errMsg('Event attribute "Timeout" is now obsolete and will be removed in Warden client 3.0', 'warn'); + } + + # end of Issue #596 + + + my $event; + eval { + # create SOAP data object + $event = SOAP::Data->name( + event => \SOAP::Data->value( + SOAP::Data->name(SERVICE => $service), + SOAP::Data->name(DETECTED => $detected), + SOAP::Data->name(TYPE => $type), + SOAP::Data->name(SOURCE_TYPE => $source_type), + SOAP::Data->name(SOURCE => $source), + SOAP::Data->name(TARGET_PROTO => $target_proto), + SOAP::Data->name(TARGET_PORT => $target_port), + SOAP::Data->name(ATTACK_SCALE => $attack_scale), + SOAP::Data->name(NOTE => $note), + SOAP::Data->name(PRIORITY => $priority), + SOAP::Data->name(TIMEOUT => $timeout) + ) + ); + } # end of eval + or WardenClientCommon::errMsg('Unknown error when creating SOAP data object, ' . $@); + + # c2s() returns undef on fail. + $result = WardenClientCommon::c2s($WardenClientConf::URI, $WardenClientConf::SSL_KEY_FILE, $WardenClientConf::SSL_CERT_FILE, $WardenClientConf::SSL_CA_FILE, "saveNewEvent", $event); + + defined $result ? return 1 : return 0; + +} # End of saveNewEvent + +1; diff --git a/src/contrib/warden-client-nosoap/lib/WardenClientSend.t b/src/contrib/warden-client-nosoap/lib/WardenClientSend.t new file mode 100644 index 0000000..b32a36b --- /dev/null +++ b/src/contrib/warden-client-nosoap/lib/WardenClientSend.t @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; + +use lib '..'; +use WardenClientSend; + +my $uri_ok = 'https://warden-dev.cesnet.cz:443/Warden'; +my $ssl_key_file_ok = '/opt/warden-client/etc/warden-dev.cesnet.cz.key'; +my $ssl_cert_file_ok = '/opt/warden-client/etc/warden-dev.cesnet.cz.pem'; +my $ssl_ca_file_ok = '/opt/warden-client/etc/tcs-ca-meta-bundle.pem'; +my $method_ok = 'saveNewEvent'; +my $data_ok = ''; + +my $warden_path_ok = '/opt/warden-client'; +my $warden_path_fail = '/path/to/fail'; +my @event_ok = ("honeyscan", "1234567890", "portscan","IP", "123.123.123.123", "TCP", "22", "1234567890", "important note or comment", "null", "20"); +my @vent_ok = ('HoneyScan', '2012-09-01T23:02:48', 'webattackReply-To:', '170.96.48.164', 'UDP', '44392354', 'tohle je takova normalni jednoducha poznamka', '180187'); + +my $ret; + +#my ($ret) = WardenClientSend::c2s($uri_ok, $ssl_key_file_ok, $ssl_cert_file_ok, $ssl_ca_file_ok, $method_ok, $data_ok); +#ok ($ret == 1, 'Everything is fine!'); + +$ret = WardenClientSend::saveNewEvent($warden_path_fail,\@event_ok); +ok ($ret == 0, 'Bad Warden path!'); + +$ret = WardenClientSend::saveNewEvent($warden_path_ok,\@event_ok); +ok ($ret == 1, 'Everything is fine.'); diff --git a/src/contrib/warden-client-nosoap/sh/install.sh b/src/contrib/warden-client-nosoap/sh/install.sh new file mode 100755 index 0000000..22b9e10 --- /dev/null +++ b/src/contrib/warden-client-nosoap/sh/install.sh @@ -0,0 +1,357 @@ +#!/bin/bash +# +# install.sh +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + + +VERSION="2.1" + +#------------------------------------------------------------------------------- +# FUNCTIONS +#------------------------------------------------------------------------------- +usage() +{ + echo "Usage: `basename $0` [-d <directory>] [-u <user>] [-k <ssl_key_file>] [-c <ssl_cert_file>] [-a <ssl_ca_file>] [-hV]" + echo "-d <directory> installation directory (default: /opt)" + echo "-u <user> owner of warden client package (user for running detection scripts)" + echo "-k <ssl_key_file> path to SSL certificate key file" + echo "-c <ssl_cert_file> path to SSL certificate file" + echo "-a <ssl_ca_file> path to CA certificate file" + echo "-h print this help" + echo "-V print script version number and exit" + echo + echo "Example: # ./`basename $0` -d /opt -u detector -k /etc/ssl/private/client.key -c /etc/ssl/certs/client.pem -a /etc/ssl/certs/tcs-ca-bundle.pem" + echo + echo "Note: You must be root for running this script." + echo " For more information about installation process, see README file (section Installation)." + echo + exit 0 +} + + +version() +{ + echo "`basename ${0}` - current version is $VERSION" + exit 0 +} + + +err() +{ + echo "FAILED!" + cat $err + rm -rf $err + echo + echo "Installation of $package_version package FAILED!!!" + exit 1 +} + + +err_clean() +{ + echo "FAILED!" + echo " -> Uninstalling client package ... OK" + rm -rf $client_path > /dev/null 2>&1 + cat $err + rm -rf $err + echo + echo "Installation of $package_version package FAILED!!!" + exit 1 +} + + +root_chck() +{ + if [ $UID -ne 0 ]; then + echo "You must be root for running this script!" + exit 1 + fi +} + + +params_chck() +{ + if [ -z $prefix ]; then + prefix=/opt + echo "Warning: parameter -d <directory> is not set - default installation directory is ${prefix}!" + fi + if [ -z $user ]; then + echo "Parameter -u <user> is not set!" + exit 1 + fi + if [ -z $key ]; then + echo "Parameter -k <ssl_key_file> is not set!" + exit 1 + fi + if [ -z $cert ]; then + echo "Parameter -c <ssl_cert_file> is not set!" + exit 1 + fi + if [ -z $ca_file ]; then + echo "Parameter -a <ssl_ca_file> is not set!" + exit 1 + fi +} + + +old_client_chck() +{ + old_package_version_file={$etc}/package_version + if [ -f $old_package_version_file ]; then + old_package_version=`cat $old_package_version_file` + echo "Sorry, but $old_package_version package is installed!" + echo "For update of warden client package please use update.sh script." + exit 1 + fi +} + + +perl_chck() +{ + echo -n "Checking Perl interpreter ... " + if which perl 1> /dev/null; then + echo "OK" + else + echo "FAILED!" + echo "Error: Perl interpreter is not installed!" + exit 1 + fi +} + + +modules_chck() +{ + for module in ${modules[@]}; + do + echo -n "Checking $module module ... " + if perl -e "use $module" 2> $err; then + echo "OK" + else + err + fi + done +} + + +make_warden_dir() +{ + echo -n "Creating warden client directory ... " + + while [ ! -d `echo ${path_to_chown} | rev | cut -d '/' -f2- | rev` ] + do + path_to_chown=`echo ${path_to_chown} | rev | cut -d '/' -f2- | rev` + done + + test -d $prefix || mkdir -p $prefix + + if cp -R ${dirname}/warden-client $prefix 2> $err; then + echo "OK" + else + err_clean + fi + + echo -n "Copying files ... " + + files=(CHANGELOG INSTALL LICENSE README README.cesnet) + for file in ${files[@]}; + do + cp ${dirname}/warden-client/doc/$file ${client_path}/doc + done + + test -d ${client_path}/ || mkdir -p ${client_path}/ + cp ${dirname}/uninstall.sh ${client_path}/ + + echo "OK" +} + + +check_key() +{ + echo -n "Checking certificate key file ... " + if su ${user} -c "test -r ${key}" 2> $err; then + echo "OK" + else + echo "Warning: certificate key file is not readable by user ${user}!" + fi +} + + +check_cert() +{ + echo -n "Checking certificate file ... " + if su ${user} -c "test -r ${key}" 2> $err; then + echo "OK" + else + echo "Warning: certificate file is not readable by user ${user}!" + fi +} + + +make_conf_file() +{ + echo -n "Creating configuration file ... " + echo "# +# warden-client.conf - configuration file for the warden sender/receiver client +# + +#------------------------------------------------------------------------------- +# URI - URI address of Warden server +#------------------------------------------------------------------------------- +\$URI = \"https://warden.cesnet.cz:443/Warden\"; + +#------------------------------------------------------------------------------- +# SSL_KEY_FILE - path to client SSL certificate key file +#------------------------------------------------------------------------------- +\$SSL_KEY_FILE = \"${key}\"; + +#------------------------------------------------------------------------------- +# SSL_CERT_FILE - path to client SSL certificate file +#------------------------------------------------------------------------------- +\$SSL_CERT_FILE = \"${cert}\"; + +#------------------------------------------------------------------------------- +# SSL_CA_FILE - path to CA certificate file +#------------------------------------------------------------------------------- +\$SSL_CA_FILE = \"${ca_file}\"; + +#------------------------------------------------------------------------------- +# MAX_RCV_EVENTS_LIMIT - maximum number of events the client is allowd to get +# from the Warden server in one batch +#------------------------------------------------------------------------------- +\$MAX_RCV_EVENTS_LIMIT = 6000; #consumes app. 250 MB of memory + +#------------------------------------------------------------------------------- +# CONNECTION_TIMEOUT - interval in seconds to timeout connection with Warden +# server. If your client timeouts, consider using higher +# timeout number. Also, in case of receiving clients, you +# can optimize the MAX_RCV_EVENTS_LIMIT value. +#------------------------------------------------------------------------------- +\$CONNECTION_TIMEOUT = 60; + +#------------------------------------------------------------------------------- +# Log options +# +# LOG_STDERR, LOG_SYSLOG - hide (0) or allow (1) error reporting on STDERR +# and/or to Syslog +# LOG_SYSLOG_FACILITY - specify a Syslog facility to log in +# LOG_VERBOSE - print only error message without a stack (0) or print debug info +# including err. message and stack (1) +#------------------------------------------------------------------------------- +\$LOG_STDERR = 1; + +\$LOG_SYSLOG = 0; +\$LOG_SYSLOG_FACILITY = \"local7\"; + +\$LOG_VERBOSE = 0; + + + +1; + +" > $conf_file 2> $err; ret_val=`echo $?` + + if [ $ret_val -eq 0 ]; then + echo "OK" + else + err_clean + fi +} + + +change_permissions() +{ + echo -n "Changing permissions to installed package ... " + chown -R $user: $path_to_chown 2> $err || err_clean + chmod 644 ${etc}/package_version || err_clean + if chmod 600 $conf_file; then + echo "OK" + else + err_clean + fi +} + + + +#------------------------------------------------------------------------------- +# MAIN +#------------------------------------------------------------------------------- + +# list of used Perl modules +modules=(SOAP::Lite IO::Socket::SSL SOAP::Transport::HTTP FindBin DateTime Carp) +# read input +while getopts "d:u:k:c:a:Vh" options; do + case $options in + d ) prefix=$OPTARG;; + u ) user=$OPTARG;; + k ) key=$OPTARG;; + c ) cert=$OPTARG;; + a ) ca_file=$OPTARG;; + h ) usage;; + V ) version;; + * ) usage;; + esac +done + +# root test +root_chck + +# params test +params_chck + +# create variables +dirname=`dirname $0` +package_version=`cat ${dirname}/warden-client/etc/package_version` +key_file=`basename $key` +cert_file=`basename $cert` +[[ $prefix == */ ]] && prefix="${prefix%?}" # remove last char (slash) from prefix +client_path="${prefix}/warden-client" +path_to_chown="${client_path}" +etc="${client_path}/etc" +conf_file="${etc}/warden-client.conf" +err="/tmp/warden-err" + +# check if warden-client is installed +old_client_chck + +echo +echo "------------------------- Dependencies check-in -------------------------" + +# Perl interpreter test +perl_chck + +# Perl modules test +modules_chck + + +echo +echo "------------------------- Installation process --------------------------" + +# make warden client directory +make_warden_dir + +# copy cert key file +check_key + +# copy cert file +check_cert + +# create conf file +make_conf_file + +# change permissions +change_permissions + +echo +echo "Please check configuration file in ${conf_file}!" +echo +echo "Warden client directory: $client_path" +echo +echo "Installation of $package_version package was SUCCESSFUL!!!" + +# cleanup section +rm -rf $err + +exit 0 diff --git a/src/contrib/warden-client-nosoap/sh/uninstall.sh b/src/contrib/warden-client-nosoap/sh/uninstall.sh new file mode 100755 index 0000000..97c5acd --- /dev/null +++ b/src/contrib/warden-client-nosoap/sh/uninstall.sh @@ -0,0 +1,171 @@ +#!/bin/bash +# +# uninstall.sh +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + +VERSION="2.1" + +#------------------------------------------------------------------------------- +# FUNCTIONS +#------------------------------------------------------------------------------- +usage() +{ + echo "Usage: `basename $0` [-d <directory>] [-hV]" + echo "-d <directory> uninstallation directory (default: /opt)" + echo "-h print this help" + echo "-V print script version number and exit" + echo + echo "Example: # ./`basename $0` -d /opt" + echo + echo "Note: You must be root for running this script." + echo " For more information about uninstallation process, see README file (section Uninstallation)." + echo + exit 0 +} + + +version() +{ + echo "`basename ${0}` - current version is $VERSION" + exit 0 +} + + +err() +{ + echo "FAILED!" + cat $err + rm -rf $err $backup_dir + echo + echo "Uninstallation of $package_version package FAILED!!!" + exit 1 +} + + +err_clean() +{ + echo "FAILED!" + echo " -> Reverting changes of warden client package ... OK" + rm -rf ${client_path}/* > /dev/null 2>&1 + cp -R ${backup_dir}/* $client_path + cat $err + rm -rf $err $backup_dir + echo + echo "Uninstallation of $package_version package FAILED!!!" + exit 1 +} + + +root_chck() +{ + if [ $UID -ne 0 ]; then + echo "You must be root for running this script!" + exit 1 + fi +} + + +params_chck() +{ + if [ -z $prefix ]; then + prefix=/opt + echo "Warning: parameter -d <directory> is not set - default uninstallation directory is ${prefix}!" + fi +} + + +obtain_package_version() +{ + if [ -f $old_package_version_file ]; then + package_version=`cat $old_package_version_file` + else + package_version="unknown" + fi +} + + +warden_dir_chck() +{ + echo -n "Checking warden client directory ... " + if [ ! -d $client_path ]; then + echo "FAILED!" + ls $client_path + exit 1 + else + echo "OK" + fi +} + + +backup() +{ + echo -n "Backing-up warden client directory ... " + mkdir $backup_dir + if cp -R ${client_path}/* $backup_dir 2> $err; then + echo "OK" + else + err + fi +} + + +uninstall_warden_client() +{ + echo -n "Uninstalling $package_version package ... " + if rm -rf $client_path 2> $err; then + echo "OK" + else + err_clean + fi +} + +#------------------------------------------------------------------------------- +# MAIN +#------------------------------------------------------------------------------- + +# read input +while getopts "d:Vh" options; do + case $options in + d ) prefix=$OPTARG;; + h ) usage;; + V ) version;; + * ) usage;; + esac +done + +# create variables +[[ $prefix == */ ]] && prefix="${prefix%?}" # remove last char (slash) from prefix +client_path="${prefix}/warden-client" +etc="${client_path}/etc" +old_package_version_file="${etc}/package_version" +err="/tmp/warden-err" +backup_dir="/tmp/warden-backup" + +# obtain version of installed warden-client package +obtain_package_version + +echo +echo "------------------------- Uninstallation process --------------------------------" + +# root check +root_chck + +# check if $prefix/warden-client directory exist +warden_dir_chck + +# make backup of currently installed warden-client package +backup + +# do uninstallation +uninstall_warden_client + +echo +echo "Uninstallation of $package_version package was SUCCESSFUL!!!" + +# cleanup section +rm -rf $err $backup_dir + +exit 0 diff --git a/src/contrib/warden-client-nosoap/sh/update.sh b/src/contrib/warden-client-nosoap/sh/update.sh new file mode 100755 index 0000000..228b429 --- /dev/null +++ b/src/contrib/warden-client-nosoap/sh/update.sh @@ -0,0 +1,366 @@ +#!/bin/bash +# +# update.sh +# +# Copyright (C) 2011-2013 Cesnet z.s.p.o +# +# Use of this source is governed by a BSD-style license, see LICENSE file. + + +VERSION="2.1" + +#------------------------------------------------------------------------------- +# FUNCTIONS +#------------------------------------------------------------------------------- +usage() +{ + echo "Usage: `basename $0` [-d <directory>] [-hV]" + echo "-d <directory> destination directory (default: /opt)" + echo "-h print this help" + echo "-V print script version number and exit" + echo + echo "Example: # ./`basename $0` -d /opt" + echo + echo "Note: You must be root for running this script." + echo " For more information about update process, see README file (section Update)." + echo + exit 0 +} + + +version() +{ + echo "`basename ${0}` - current version is $VERSION" + exit 0 +} + + +err() +{ + echo "FAILED!" + cat $err + rm -rf $err + rm -rf $backup_dir + echo + echo "Update from $old_package_version to $package_version package FAILED!!!" + exit 1 +} + + +err_clean() +{ + echo "FAILED!" + echo " -> Reverting changes of warden client package ... OK" + rm -rf ${client_path}/* > /dev/null 2>&1 + cp -R ${backup_dir}/* $client_path + cat $err + rm -rf $err $backup_dir + echo + echo "Update from $old_package_version to $package_version package FAILED!!!" + exit 1 +} + + +root_chck() +{ + if [ $UID -ne 0 ]; then + echo "You must be root for running this script!" + exit 1 + fi +} + + +params_chck() +{ + if [ -z $prefix ]; then + prefix=/opt + echo "Warning: parameter -d <directory> is not set - default installation directory is ${prefix}!" + fi +} + + +obtain_package_version() +{ + if [ -f $old_package_version_file ]; then + old_package_version=`cat $old_package_version_file` + if [ "$old_package_version" == "$package_version" ]; then + echo "Sorry, but $package_version package is already installed!" + exit 1 + fi + else + echo "Sorry, but warden-client package is not installed!" + echo "For installation of warden client package please use install.sh script." + exit 1 + fi +} + + +perl_chck() +{ + echo -n "Checking Perl interpreter ... " + if which perl 1> /dev/null; then + echo "OK" + else + echo "FAILED!" + echo "Error: Perl interpreter is not installed!" + exit 1 + fi +} + + +modules_chck() +{ + for module in ${modules[@]}; + do + echo -n "Checking $module module ... " + if perl -e "use $module" 2> $err; then + echo "OK" + else + err + fi + done +} + + +warden_dir_chck() +{ + echo -n "Checking warden client directory ... " + if [ ! -d $client_path ]; then + echo "FAILED!" + ls $client_path + exit 1 + else + echo "OK" + fi +} + + +backup() +{ + echo -n "Backing-up warden client directory ... " + mkdir $backup_dir + if cp -R ${client_path}/* $backup_dir 2> $err; then + echo "OK" + else + err +fi +} + + +obtain_warden_user() +{ + echo -n "Obtaining warden client directory owner ... " + if user=`stat -c %U $conf_file` 2> $err; then + echo "OK" + else + err + fi +} + + +update_warden_dir() +{ + echo -n "Updating warden client directory ... " + if rsync -q --recursive --archive --delete --exclude='etc' --exclude='var' ${dirname}/warden-client $prefix 2> $err; then + echo "OK" + else + err_clean + fi + + files=(CHANGELOG INSTALL LICENSE README README.cesnet) + for file in ${files[@]}; + do + cp ${dirname}/$file ${client_path}/doc + done + cp ${dirname}/uninstall.sh $client_path + cp ${dirname}/warden-client/etc/package_version $etc +} + + +make_conf_file() +{ + echo -n "Creating configuration file ... " + uri=`cat $conf_file | grep '$URI'` + ssl_key_file=`cat $conf_file | grep '$SSL_KEY_FILE'` + ssl_cert_file=`cat $conf_file | grep '$SSL_CERT_FILE'` + ssl_ca_file=`cat $conf_file | grep '$SSL_CA_FILE'` + max_rcv_events_limit=`cat $conf_file | grep '$MAX_RCV_EVENTS_LIMIT'` + connection_timeout=`cat $conf_file | grep '$CONNECTION_TIMEOUT'` + + log_stderr=`cat $conf_file | grep '$LOG_STDERR'` + if [ -z $log_stderr ]; then + log_stderr="\$LOG_STDERR = 1;" + fi + + log_syslog=`cat $conf_file | grep '$LOG_SYSLOG'` + if [ -z $log_syslog ]; then + log_syslog="\$LOG_SYSLOG = 0;" + fi + + log_syslog_facility=`cat $conf_file | grep '$LOG_SYSLOG_FACILITY'` + if [ -z $log_syslog_facility ]; then + log_syslog_facility="\$LOG_SYSLOG_FACILITY = \"local7\";" + fi + + log_verbose=`cat $conf_file | grep '$LOG_VERBOSE'` + if [ -z $log_verbose ]; then + log_verbose="\$LOG_VERBOSE = 0;" + fi + + echo "# +# warden-client.conf - configuration file for the warden sender/receiver client +# + +#------------------------------------------------------------------------------- +# URI - URI address of Warden server +#------------------------------------------------------------------------------- +$uri + +#------------------------------------------------------------------------------- +# SSL_KEY_FILE - path to client SSL certificate key file +#------------------------------------------------------------------------------- +$ssl_key_file + +#------------------------------------------------------------------------------- +# SSL_CERT_FILE - path to client SSL certificate file +#------------------------------------------------------------------------------- +$ssl_cert_file + +#------------------------------------------------------------------------------- +# SSL_CA_FILE - path to CA certificate file +#------------------------------------------------------------------------------- +$ssl_ca_file + +#------------------------------------------------------------------------------- +# MAX_RCV_EVENTS_LIMIT - maximum number of events the client is allowd to get +# from the Warden server in one batch +#------------------------------------------------------------------------------- +$max_rcv_events_limit + +#------------------------------------------------------------------------------- +# CONNECTION_TIMEOUT - interval in seconds to timeout connection with Warden +# server. If your client timeouts, consider using higher +# timeout number. Also, in case of receiving clients, you +# can optimize the MAX_RCV_EVENTS_LIMIT value. +#------------------------------------------------------------------------------- +$connection_timeout + +#------------------------------------------------------------------------------- +# Log options +# +# LOG_STDERR, LOG_SYSLOG - hide (0) or allow (1) error reporting on STDERR +# and/or to Syslog +# LOG_SYSLOG_FACILITY - specify a Syslog facility to log in +# LOG_VERBOSE - print only error message without a stack (0) or print debug info +# including err. message and stack (1) +#------------------------------------------------------------------------------- +$log_stderr + +$log_syslog +$log_syslog_facility + +$log_verbose + +1; +" > $conf_file 2> $err; ret_val=`echo $?` + + if [ $ret_val -eq 0 ]; then + echo "OK" + else + err_clean + fi +} + + +change_permissions() +{ + echo -n "Changing permissions to updated package ... " + chown -R $user: $client_path 2>$err || err_clean + chmod 644 $old_package_version_file || err_clean + if chmod 600 $conf_file; then + echo "OK" + else + err_clean + fi +} + + + +#------------------------------------------------------------------------------- +# MAIN +#------------------------------------------------------------------------------- + +# list of used Perl modules +modules=(SOAP::Lite IO::Socket::SSL SOAP::Transport::HTTP FindBin DateTime Carp) + +# read input +while getopts "d:Vh" options; do + case $options in + d ) prefix=$OPTARG;; + h ) usage;; + V ) version;; + * ) usage;; + esac +done + +# root test +root_chck + +# params test +params_chck + +# create variables +dirname=`dirname $0` +package_version=`cat ${dirname}/warden-client/etc/package_version` +[[ $prefix == */ ]] && prefix="${prefix%?}" # remove last char (slash) from prefix +client_path="${prefix}/warden-client" +etc="${client_path}/etc" +old_package_version_file="${etc}/package_version" +conf_file="${etc}/warden-client.conf" +err="/tmp/warden-err" +backup_dir="/tmp/warden-backup" + +# obtain version of old warden client +obtain_package_version + +echo +echo "------------------------- Dependencies check-in -------------------------" + +# Perl interpreter test +perl_chck + +# Perl modules test +modules_chck + +echo +echo "------------------------- Update process --------------------------------" + +# check warden client directory +warden_dir_chck + +# backup old warden client installation +backup + +# obtain current warden client user +obtain_warden_user + +# make warden client directory +update_warden_dir + +# create conf file +make_conf_file + +# change permissions +change_permissions + +echo +echo "Please check configuration file in ${conf_file}!" +echo +echo "Warden client directory: $client_path" +echo +echo "Update from $old_package_version to $package_version package was SUCCESSFUL!!!" + +# cleanup section +rm -rf $err $backup_dir + +exit 0 -- GitLab