addfirewallrule.cna 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # author REDMED-X
  2. beacon_command_register(
  3. "addfirewallrule", "Add a new inbound/outbound firewall rule.",
  4. "INFO:\nAdd a new inbound/outbound firewall rule using COM.\n\n" .
  5. "ARGUMENTS:\n[<direction>]: specify \"in\" for inbound or \"out\" for outbound.\n[<port>]: specify a single port (80) or port range (80-1000)\n[<rule name>]: specify the name of the new rule.\n[<rule group>]: specify the name of the rule group OR leave empty.\n[<description>]: specify the description of the new rule OR leave empty.\n\n" .
  6. "USAGE:\naddfirewallrule <direction> <port> \"<rule name>\" \"<rule group>\" \"<description>\"\n\n" .
  7. "EXAMPLES:\naddfirewallrule in 80 \"ExampleRuleName1\" \"ExampleGroup1\" \"Test rule\"\naddfirewallrule out 80-1000 \"ExampleRuleName2\" \n\n");
  8. alias addfirewallrule {
  9. $bid = $1;
  10. $direction = $2;
  11. $port = $3;
  12. $name = $4;
  13. $group = $5;
  14. $description = $6;
  15. if ($direction eq "") {
  16. berror($bid, "Please specify one of the following rule options: in | out\n");
  17. return;
  18. }
  19. if ($direction eq "in" || $direction eq "out") {
  20. if ($port eq "") {
  21. berror($bid, "Please specify a single port or port range.\n");
  22. return;
  23. }
  24. if ($name eq "") {
  25. berror($bid, "Please specify a name of the new firewall rule.\n");
  26. return;
  27. }
  28. }
  29. else {
  30. berror($bid, "This option isn't supported. Please specify one of the following options: in | out\n");
  31. return;
  32. }
  33. # Read in the right BOF file
  34. $handle = openf(script_resource("addfirewallrule.o"));
  35. $data = readb($handle, -1);
  36. closef($handle);
  37. # Pack our arguments
  38. $arg_data = bof_pack($bid, "zZZZZ", $direction, $port, $name, $group, $description);
  39. blog($bid, "Tasked to add a new firewall rule..");
  40. beacon_inline_execute($bid, $data, "go", $arg_data);
  41. }