| 1 |
#!/usr/bin/perl -w |
|---|
| 2 |
|
|---|
| 3 |
use strict; |
|---|
| 4 |
use Test::More 'no_plan'; |
|---|
| 5 |
$| = 1; |
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
# =begin testing |
|---|
| 10 |
{ |
|---|
| 11 |
diag("Beginning of HoneyClient::Manager::FW testing."); |
|---|
| 12 |
diag("Making sure all Modules are present"); |
|---|
| 13 |
|
|---|
| 14 |
# Make sure Log::Log4perl loads. |
|---|
| 15 |
BEGIN { use_ok('Log::Log4perl') or diag("Can't load Log::Log4perl package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 16 |
require_ok('Log::Log4perl'); |
|---|
| 17 |
use Log::Log4perl; |
|---|
| 18 |
|
|---|
| 19 |
# Make sure Filehandle loads. |
|---|
| 20 |
BEGIN { use_ok('FileHandle') or diag("Can't load FileHandle package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 21 |
require_ok('FileHandle'); |
|---|
| 22 |
use FileHandle; |
|---|
| 23 |
|
|---|
| 24 |
# Make sure IO::File loads. |
|---|
| 25 |
BEGIN { use_ok('IO::File') or diag("Can't load IO::File package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 26 |
require_ok('IO::File'); |
|---|
| 27 |
use IO::File; |
|---|
| 28 |
|
|---|
| 29 |
# Make sure IPTables::IPv4 loads. |
|---|
| 30 |
BEGIN { use_ok('IPTables::IPv4') or diag("Can't load IPTables::IPv4 package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 31 |
require_ok('IPTables::IPv4'); |
|---|
| 32 |
use IPTables::IPv4; |
|---|
| 33 |
|
|---|
| 34 |
# Make sure Config::General loads. |
|---|
| 35 |
BEGIN { use_ok('Config::General') or diag("Can't load Config::General package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 36 |
require_ok('Config::General'); |
|---|
| 37 |
use Config::General; |
|---|
| 38 |
|
|---|
| 39 |
# Make sure use Data::Dumper loads. |
|---|
| 40 |
BEGIN { use_ok('Data::Dumper') or diag("Can't load use Data::Dumper package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 41 |
require_ok('Data::Dumper'); |
|---|
| 42 |
use Data::Dumper; |
|---|
| 43 |
|
|---|
| 44 |
# Make sure use Net::DNS::Resolver loads. |
|---|
| 45 |
BEGIN { use_ok('Net::DNS::Resolver') or diag("Can't load use Net::DNS::Resolver package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 46 |
require_ok('Net::DNS::Resolver'); |
|---|
| 47 |
use Net::DNS::Resolver; |
|---|
| 48 |
|
|---|
| 49 |
# Make sure use Time::HiRes loads. |
|---|
| 50 |
BEGIN { use_ok('Time::HiRes', qw(gettimeofday)) or diag("Can't load use Time::HiRes package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 51 |
require_ok('Time::HiRes'); |
|---|
| 52 |
can_ok('Time::HiRes', 'gettimeofday'); |
|---|
| 53 |
use Time::HiRes qw(gettimeofday); |
|---|
| 54 |
|
|---|
| 55 |
# Make sure use English loads. |
|---|
| 56 |
BEGIN { use_ok('English') or diag("Can't load use English package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 57 |
require_ok('English'); |
|---|
| 58 |
use English '-no_match_vars'; |
|---|
| 59 |
|
|---|
| 60 |
# Make sure use threads loads. |
|---|
| 61 |
BEGIN { use_ok('threads') or diag("Can't load use threads package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 62 |
require_ok('threads'); |
|---|
| 63 |
use threads; |
|---|
| 64 |
|
|---|
| 65 |
# Make sure HoneyClient::Util::Config loads. |
|---|
| 66 |
BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar)) or diag("Can't load HoneyClient::Util::Config package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 67 |
require_ok('HoneyClient::Util::Config'); |
|---|
| 68 |
can_ok('HoneyClient::Util::Config', 'getVar'); |
|---|
| 69 |
use HoneyClient::Util::Config qw(getVar); |
|---|
| 70 |
|
|---|
| 71 |
# Make sure the module loads properly, with the exportable |
|---|
| 72 |
# functions shared. |
|---|
| 73 |
BEGIN { use_ok('HoneyClient::Manager::FW', qw(init_fw destroy_fw _getVMName)) or diag("Can't load HoneyClient::Manager:VM package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 74 |
require_ok('HoneyClient::Manager::FW'); |
|---|
| 75 |
can_ok('HoneyClient::Manager::FW', 'init_fw'); |
|---|
| 76 |
can_ok('HoneyClient::Manager::FW', 'destroy_fw'); |
|---|
| 77 |
can_ok('HoneyClient::Manager::FW', '_getVMName'); |
|---|
| 78 |
use HoneyClient::Manager::FW qw(init_fw destroy_fw _getVMName); |
|---|
| 79 |
|
|---|
| 80 |
# Make sure HoneyClient::Util::SOAP loads. |
|---|
| 81 |
BEGIN { use_ok('HoneyClient::Util::SOAP', qw(getServerHandle getClientHandle)) or diag("Can't load HoneyClient::Util::SOAP package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 82 |
require_ok('HoneyClient::Util::SOAP'); |
|---|
| 83 |
can_ok('HoneyClient::Util::SOAP', 'getServerHandle'); |
|---|
| 84 |
can_ok('HoneyClient::Util::SOAP', 'getClientHandle'); |
|---|
| 85 |
use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle); |
|---|
| 86 |
|
|---|
| 87 |
# Make sure use Proc::ProcessTable loads. |
|---|
| 88 |
BEGIN { use_ok('Proc::ProcessTable') or diag("Can't load use Proc::ProcessTable package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| 89 |
require_ok('Proc::ProcessTable'); |
|---|
| 90 |
use Proc::ProcessTable; |
|---|
| 91 |
|
|---|
| 92 |
diag("Making sure perl and shell scripts exist.\n"); |
|---|
| 93 |
ok( "-f /hc/startFWListener.pl", '/hc/startFWListener.pl is present' ); |
|---|
| 94 |
ok( "-f /hc/startLogListener.pl", '/hc/startLogListener.pl is present' ); |
|---|
| 95 |
ok( "-f /hc/startFWListener.sh", '/hc/startFWListener.sh is present' ); |
|---|
| 96 |
ok( "-f /hc/startLogListener.sh", '/hc/startLogListener.sh is present' ); |
|---|
| 97 |
ok( "-f /etc/honeylog.conf", '/etc/honeylog.conf is present' ); |
|---|
| 98 |
ok("-f /etc/honeyclient.conf", '/etc/honeyclient.conf exists'); |
|---|
| 99 |
#ok( -f , "/proc/sys/net/ipv4/ip_forward", '/proc/sys/net/ipv4/ip_forward does exist'); |
|---|
| 100 |
ok(" -f /etc/resolv.conf", '/etc/resolv.conf file does exist'); |
|---|
| 101 |
ok(" -f /etc/syslog.conf", '/etc/syslog.conf file does exist'); |
|---|
| 102 |
ok( "-f /usr/bin/uptime", '/usr/bin/uptime is present' ); |
|---|
| 103 |
ok(" -f /bin/uname", '/bin/uname exists'); |
|---|
| 104 |
ok(" -f /bin/mail", 'mail() exists'); |
|---|
| 105 |
ok(" -f /sbin/iptables", 'IPTables binary does exist'); |
|---|
| 106 |
diag("Enabling test hash reference here"); |
|---|
| 107 |
my $hashref = { |
|---|
| 108 |
|
|---|
| 109 |
'foo' => { |
|---|
| 110 |
'targets' => { |
|---|
| 111 |
'rcf.mitre.org' => { 'tcp' => [ 80 ], }, |
|---|
| 112 |
}, |
|---|
| 113 |
|
|---|
| 114 |
'resources' => { |
|---|
| 115 |
'http://www.mitre.org' => 1, |
|---|
| 116 |
}, |
|---|
| 117 |
'sources' => { |
|---|
| 118 |
|
|---|
| 119 |
'00:0C:29:94:B9:15' => { |
|---|
| 120 |
'10.0.0.128' => { |
|---|
| 121 |
'tcp' => undef, |
|---|
| 122 |
'udp' => [ 23, 53, '80:1024', ], |
|---|
| 123 |
}, |
|---|
| 124 |
}, |
|---|
| 125 |
}, |
|---|
| 126 |
}, |
|---|
| 127 |
}; |
|---|
| 128 |
|
|---|
| 129 |
#my $hwall = getVar(name => "address"); |
|---|
| 130 |
#my $port = getVar(name => "port"); |
|---|
| 131 |
|
|---|
| 132 |
diag("Beginning our function testing now..."); |
|---|
| 133 |
$URL = HoneyClient::Manager::FW->init_fw(); |
|---|
| 134 |
is($URL, "http://192.168.0.129:8083/", "testing init_fw(), creation of the firewall server") or diag("Failed to start up the FW SOAP server. Check to see if any other daemon is listening on TCP port $PORT."); |
|---|
| 135 |
sleep 3; |
|---|
| 136 |
is(HoneyClient::Manager::FW->destroy_fw(), 1, "destroy_fw(), destruction of the firewall server") or diag("Unable to terminate FW"); |
|---|
| 137 |
sleep 1; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
# =begin testing |
|---|
| 143 |
{ |
|---|
| 144 |
eval{ |
|---|
| 145 |
diag("Testing fwInit()..."); |
|---|
| 146 |
$URL = HoneyClient::Manager::FW->init_fw(); |
|---|
| 147 |
# Wait at least a second, in order to initialize the daemon. |
|---|
| 148 |
sleep(1); |
|---|
| 149 |
# Connect to daemon as a client. |
|---|
| 150 |
$stub = getClientHandle(namespace => "HoneyClient::Manager::FW"); |
|---|
| 151 |
$som = $stub->fwInit($hashref); |
|---|
| 152 |
$som = $stub->_validateInit(); |
|---|
| 153 |
is($som->result, 24, "fwInit current has set up 28 rules") or diag("The fwInit() call failed."); |
|---|
| 154 |
$som = $stub->_setAcceptPolicy(); |
|---|
| 155 |
$som = $stub->_flushChains(); |
|---|
| 156 |
|
|---|
| 157 |
}; |
|---|
| 158 |
|
|---|
| 159 |
# Kill the child daemon, if it still exists. |
|---|
| 160 |
HoneyClient::Manager::FW->destroy_fw(); |
|---|
| 161 |
sleep(1); |
|---|
| 162 |
|
|---|
| 163 |
# Report any failure found. |
|---|
| 164 |
if ($@) { |
|---|
| 165 |
fail($@); |
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
# =begin testing |
|---|
| 173 |
{ |
|---|
| 174 |
eval{ |
|---|
| 175 |
diag("Testing addChain()..."); |
|---|
| 176 |
$URL = HoneyClient::Manager::FW->init_fw(); |
|---|
| 177 |
# Wait at least a second, in order to initialize the daemon. |
|---|
| 178 |
sleep 1; |
|---|
| 179 |
# Connect to daemon as a client. |
|---|
| 180 |
$stub = getClientHandle(namespace => "HoneyClient::Manager::FW"); |
|---|
| 181 |
$som = $stub->addChain($hashref); |
|---|
| 182 |
ok($som->result, "addChain() successfully passed.") or diag("The addChain() call failed."); |
|---|
| 183 |
$som = $stub->_setAcceptPolicy(); |
|---|
| 184 |
$som = $stub->_flushChains(); |
|---|
| 185 |
}; |
|---|
| 186 |
|
|---|
| 187 |
# Kill the child daemon, if it still exists. |
|---|
| 188 |
HoneyClient::Manager::FW->destroy_fw(); |
|---|
| 189 |
sleep 1; |
|---|
| 190 |
|
|---|
| 191 |
# Report any failure found. |
|---|
| 192 |
if ($@) { |
|---|
| 193 |
fail($@); |
|---|
| 194 |
} |
|---|
| 195 |
|
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
# =begin testing |
|---|
| 201 |
{ |
|---|
| 202 |
eval{ |
|---|
| 203 |
diag("Testing deleteChain()..."); |
|---|
| 204 |
$URL = HoneyClient::Manager::FW->init_fw(); |
|---|
| 205 |
# Wait at least a second, in order to initialize the daemon. |
|---|
| 206 |
sleep 1; |
|---|
| 207 |
# Connect to daemon as a client. |
|---|
| 208 |
$stub = getClientHandle(namespace => "HoneyClient::Manager::FW"); |
|---|
| 209 |
$som = $stub->addChain($hashref); |
|---|
| 210 |
sleep 1; |
|---|
| 211 |
$som = $stub->deleteChain($hashref); |
|---|
| 212 |
ok($som->result, "deleteChain() successfully passed.") or diag("The deleteChain() call failed."); |
|---|
| 213 |
$som = $stub->_setAcceptPolicy(); |
|---|
| 214 |
$som = $stub->_flushChains(); |
|---|
| 215 |
|
|---|
| 216 |
}; |
|---|
| 217 |
|
|---|
| 218 |
# Kill the child daemon, if it still exists. |
|---|
| 219 |
HoneyClient::Manager::FW->destroy_fw(); |
|---|
| 220 |
sleep 1; |
|---|
| 221 |
|
|---|
| 222 |
# Report any failure found. |
|---|
| 223 |
if ($@) { |
|---|
| 224 |
fail($@); |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
} |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
# =begin testing |
|---|
| 232 |
{ |
|---|
| 233 |
eval{ |
|---|
| 234 |
diag("Testing addRule()..."); |
|---|
| 235 |
$URL = HoneyClient::Manager::FW->init_fw(); |
|---|
| 236 |
# Wait at least a second, in order to initialize the daemon. |
|---|
| 237 |
sleep 1; |
|---|
| 238 |
# Connect to daemon as a client. |
|---|
| 239 |
$stub = getClientHandle(namespace => "HoneyClient::Manager::FW"); |
|---|
| 240 |
my $som = $stub->fwInit($hashref); |
|---|
| 241 |
$som = $stub->addChain($hashref); |
|---|
| 242 |
$som = $stub->addRule($hashref); |
|---|
| 243 |
ok($som->result, "addRule() successfully passed and added a new rule.") or diag("The addRule() call failed."); |
|---|
| 244 |
$som = $stub->_setAcceptPolicy(); |
|---|
| 245 |
$som = $stub->_flushChains(); |
|---|
| 246 |
}; |
|---|
| 247 |
|
|---|
| 248 |
# Kill the child daemon, if it still exists. |
|---|
| 249 |
HoneyClient::Manager::FW->destroy_fw(); |
|---|
| 250 |
sleep 1; |
|---|
| 251 |
|
|---|
| 252 |
# Report any failure found. |
|---|
| 253 |
if ($@) { |
|---|
| 254 |
fail($@); |
|---|
| 255 |
} |
|---|
| 256 |
} |
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
# =begin testing |
|---|
| 261 |
{ |
|---|
| 262 |
eval{ |
|---|
| 263 |
diag("Testing fwStatus()..."); |
|---|
| 264 |
$URL = HoneyClient::Manager::FW->init_fw(); |
|---|
| 265 |
# Wait at least a second, in order to initialize the daemon. |
|---|
| 266 |
sleep 1; |
|---|
| 267 |
# Connect to daemon as a client. |
|---|
| 268 |
$stub = getClientHandle(namespace => "HoneyClient::Manager::FW"); |
|---|
| 269 |
$som = $stub->getStatus(); |
|---|
| 270 |
# testing to make sure the chains are empty |
|---|
| 271 |
ok(!$som->result, "getStatus() successfully passed.") or diag("The getStatus() call failed."); |
|---|
| 272 |
# $som = $stub->_setAcceptPolicy(); |
|---|
| 273 |
# $som = $stub->_flushChains(); |
|---|
| 274 |
}; |
|---|
| 275 |
|
|---|
| 276 |
# Kill the child daemon, if it still exists. |
|---|
| 277 |
HoneyClient::Manager::FW->destroy_fw(); |
|---|
| 278 |
sleep 1; |
|---|
| 279 |
|
|---|
| 280 |
# Report any failure found. |
|---|
| 281 |
if ($@) { |
|---|
| 282 |
fail($@); |
|---|
| 283 |
} |
|---|
| 284 |
} |
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
# =begin testing |
|---|
| 289 |
{ |
|---|
| 290 |
eval{ |
|---|
| 291 |
|
|---|
| 292 |
diag("Testing _chainExists()..."); |
|---|
| 293 |
$URL = HoneyClient::Manager::FW->init_fw(); |
|---|
| 294 |
# Wait at least a second, in order to initialize the daemon. |
|---|
| 295 |
sleep 1; |
|---|
| 296 |
# Connect to daemon as a client. |
|---|
| 297 |
$stub = getClientHandle(namespace => "HoneyClient::Manager::FW"); |
|---|
| 298 |
my $som = $stub->fwInit($hashref); |
|---|
| 299 |
$som = $stub->addChain($hashref); |
|---|
| 300 |
is($som->result, 1, "_chainExists($hashref) successfully passed.") or diag("The _chainExists() call failed."); |
|---|
| 301 |
$som = $stub->_setAcceptPolicy(); |
|---|
| 302 |
$som = $stub->_flushChains(); |
|---|
| 303 |
}; |
|---|
| 304 |
|
|---|
| 305 |
# Kill the child daemon, if it still exists. |
|---|
| 306 |
HoneyClient::Manager::FW->destroy_fw(); |
|---|
| 307 |
sleep 1; |
|---|
| 308 |
|
|---|
| 309 |
# Report any failure found. |
|---|
| 310 |
if ($@) { |
|---|
| 311 |
fail($@); |
|---|
| 312 |
} |
|---|
| 313 |
} |
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
# =begin testing |
|---|
| 318 |
{ |
|---|
| 319 |
eval{ |
|---|
| 320 |
|
|---|
| 321 |
$URL = HoneyClient::Manager::FW->init_fw(); |
|---|
| 322 |
# Wait at least a second, in order to initialize the daemon. |
|---|
| 323 |
sleep 1; |
|---|
| 324 |
# Connect to daemon as a client. |
|---|
| 325 |
$stub = getClientHandle(namespace => "HoneyClient::Manager::FW"); |
|---|
| 326 |
$som = $stub->starttestProcess(); |
|---|
| 327 |
$som = $stub->fwShutdown(); |
|---|
| 328 |
$som = $stub->findProcess(); |
|---|
| 329 |
ok($som->result, "fwShutdown() successfully passed.") or diag("The FWShutdown() call failed."); |
|---|
| 330 |
}; |
|---|
| 331 |
|
|---|
| 332 |
# Kill the child daemon, if it still exists. |
|---|
| 333 |
HoneyClient::Manager::FW->destroy_fw(); |
|---|
| 334 |
sleep 1; |
|---|
| 335 |
|
|---|
| 336 |
# Report any failure found. |
|---|
| 337 |
if ($@) { |
|---|
| 338 |
fail($@); |
|---|
| 339 |
} |
|---|
| 340 |
} |
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
1; |
|---|