Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Warden - archive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
713
Warden
Warden - archive
Commits
3f9dc03c
Commit
3f9dc03c
authored
12 years ago
by
Jan Soukal
Browse files
Options
Downloads
Patches
Plain Diff
task #519, kod klienta uzavren do eval bloku
parent
4a2fbcab
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/warden-client/doc/example-receiver.pl.txt
+10
-7
10 additions, 7 deletions
src/warden-client/doc/example-receiver.pl.txt
src/warden-client/lib/WardenClientReceive.pm
+92
-84
92 additions, 84 deletions
src/warden-client/lib/WardenClientReceive.pm
with
102 additions
and
91 deletions
src/warden-client/doc/example-receiver.pl.txt
100644 → 100755
+
10
−
7
View file @
3f9dc03c
...
...
@@ -18,17 +18,14 @@ use strict;
# This code should developer add into his/her application.
# Path to warden-client directory
my $warden_path = '/
opt
/warden-client';
my $warden_path = '/
home/soukal/client-test/2.0.0_beta
/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 = "botnet_c_c";
# Download of new evetns from Warden server
my @new_events = WardenClientReceive::getNewEvents($warden_path, $requested_type);
my $requested_type = "portscan";
#------------------------------------------------------------------------------
# Simple code that prints out new events obtained from Warden server.
...
...
@@ -37,9 +34,15 @@ print "+------------------------------------------------------------------------
print "| id | hostname | service | detected | type | source_type | source | target_proto | target_port | attack_scale | note | priority | timeout |\n";
print "+------------------------------------------------------------------------------------------------------------------------------------------+\n";
foreach (@new_events) {
print "| " . join(' | ', @$_) . " |" . "\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(' | ', @event) . " |" . "\n";
}
print "+------------------------------------------------------------------------------------------------------------------------------------------+\n";
}
print "+------------------------------------------------------------------------------------------------------------------------------------------+";
print "\n";
print "Last events in: " . scalar(localtime(time)) . "\n";
...
...
This diff is collapsed.
Click to expand it.
src/warden-client/lib/WardenClientReceive.pm
+
92
−
84
View file @
3f9dc03c
...
...
@@ -81,94 +81,102 @@ sub c2s
#-------------------------------------------------------------------------------
sub
getNewEvents
{
my
$warden_path
=
shift
;
my
$requested_type
=
shift
;
my
$vardir
=
$warden_path
.
"
/var/
";
my
$etcdir
=
$warden_path
.
"
/etc/
";
my
$libdir
=
$warden_path
.
"
/lib/
";
# read the config file
require
$libdir
.
"
WardenClientConf.pm
";
my
$conf_file
=
$etcdir
.
"
warden-client.conf
";
my
(
$uri
,
$ssl_key_file
,
$ssl_cert_file
,
$ssl_ca_file
,
$max_rcv_events_limit
)
=
WardenClientConf::
loadConf
(
$conf_file
);
# set name of ID file for each client aplication
my
$caller_name
=
$
FindBin::
Script
;
my
$id_file
=
$vardir
.
$caller_name
.
"
.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
")
||
errMsg
("
Cannot open ID file
$id_file
: $!
");
foreach
(
<
ID
>
)
{
$last_id
=
$_
;
my
@events
;
eval
{
my
$warden_path
=
shift
;
my
$requested_type
=
shift
;
my
$vardir
=
$warden_path
.
"
/var/
";
my
$etcdir
=
$warden_path
.
"
/etc/
";
my
$libdir
=
$warden_path
.
"
/lib/
";
# read the config file
require
$libdir
.
"
WardenClientConf.pm
";
my
$conf_file
=
$etcdir
.
"
warden-client.conf
";
my
(
$uri
,
$ssl_key_file
,
$ssl_cert_file
,
$ssl_ca_file
,
$max_rcv_events_limit
)
=
WardenClientConf::
loadConf
(
$conf_file
);
# set name of ID file for each client aplication
my
$caller_name
=
$
FindBin::
Script
;
my
$id_file
=
$vardir
.
$caller_name
.
"
.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
")
||
errMsg
("
Cannot open ID file
$id_file
: $!
");
foreach
(
<
ID
>
)
{
$last_id
=
$_
;
}
close
ID
;
}
else
{
my
$response
=
c2s
(
$uri
,
$ssl_key_file
,
$ssl_cert_file
,
$ssl_ca_file
,
"
getLastId
");
$last_id
=
$response
->
result
;
open
(
ID
,
"
>
$id_file
")
||
die
("
Cannot open ID file
$id_file
: $!
");
print
ID
$last_id
;
close
ID
;
}
close
ID
;
}
else
{
my
$response
=
c2s
(
$uri
,
$ssl_key_file
,
$ssl_cert_file
,
$ssl_ca_file
,
"
getLastId
");
$last_id
=
$response
->
result
;
open
(
ID
,
"
>
$id_file
")
||
die
("
Cannot open ID file
$id_file
: $!
");
print
ID
$last_id
;
close
ID
;
}
#-----------------------------------------------------------------------------
# get new events from warden server DB based on gathered last ID
# create SOAP data obejct
my
$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
=>
$max_rcv_events_limit
)
)
);
#-----------------------------------------------------------------------------
# get new events from warden server DB based on gathered last ID
# create SOAP data obejct
my
$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
=>
$max_rcv_events_limit
)
)
);
# call server method getNewEvents
my
$response
=
c2s
(
$uri
,
$ssl_key_file
,
$ssl_cert_file
,
$ssl_ca_file
,
"
getNewEvents
",
$request_data
);
# parse returned SOAP data object
my
(
$id
,
$hostname
,
$service
,
$detected
,
$type
,
$source_type
,
$source
,
$target_proto
,
$target_port
,
$attack_scale
,
$note
,
$priority
,
$timeout
);
my
@events
;
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
;
# call server method getNewEvents
my
$response
=
c2s
(
$uri
,
$ssl_key_file
,
$ssl_cert_file
,
$ssl_ca_file
,
"
getNewEvents
",
$request_data
);
# parse returned SOAP data object
my
(
$id
,
$hostname
,
$service
,
$detected
,
$type
,
$source_type
,
$source
,
$target_proto
,
$target_port
,
$attack_scale
,
$note
,
$priority
,
$timeout
);
# my @events;
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
")
||
die
("
Cannot open ID file
$id_file
: $!
");
print
ID
$last_id
;
close
ID
;
}
}
#end of while loop
# write last return ID
if
(
defined
$last_id
)
{
# must be defined for first check ID
open
(
ID
,
"
>
$id_file
")
||
die
("
Cannot open ID file
$id_file
: $!
");
print
ID
$last_id
;
close
ID
;
}
}
# End of eval block
or
do
{
return
;
};
return
@events
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment