Advertisement
bueddl

Untitled

May 22nd, 2013
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1.     // Initialize Firewall
  2.     Firewall::Firewall firewall = Firewall::Firewall();
  3.  
  4.     /////////////////////////////////////////// SSH SERVER ///////////////////////////////////////////
  5.    
  6.     // Create INPUT Chain Rule for SSH
  7.    
  8.     // allow to connect from everywhere
  9.     TCPRule *input_rule = new TCPRule( Net::IPNet("0.0.0.0", 0), Net::IPNet("0.0.0.0", 0) );
  10.     // server port is 22
  11.     input_rule->addDestPort( Net::Ports(22) );
  12.     // must be a client, sourcePort >= 1024
  13.     input_rule->addSourcePort( Net::Ports(1024, 65535) );
  14.    
  15.     // allow only incoming packets to establish the connection
  16.     State *stateIn = new State();
  17.     stateIn->addState(S_NEW);
  18.     stateIn->addState(S_ESTABLISHED);
  19.     stateIn->addState(S_RELATED);
  20.    
  21.     // add the module to the rule
  22.     input_rule->addModule(stateIn);
  23.    
  24.     // finnaly tell the rule how to deal with that (target)
  25.     input_rule->Accept();
  26.  
  27.     // insert the rule into the input chain
  28.     Firewall::Firewall::Input->Insert(input_rule);
  29.  
  30.    
  31.     // Create OUTPUT Chain Rule for SSH
  32.    
  33.     // allow to connect from everywhere
  34.     TCPRule *output_rule = new TCPRule( Net::IPNet("0.0.0.0", 0), Net::IPNet("0.0.0.0", 0) );
  35.     // must be a client, sourcePort >= 1024
  36.     output_rule->addDestPort( Net::Ports(1024, 65535) );
  37.     // server port is 22
  38.     output_rule->addSourcePort( Net::Ports(22) );
  39.    
  40.     // allow only established connections to pass
  41.     State *stateOut = new State();
  42.     stateOut->addState(S_ESTABLISHED);
  43.     stateOut->addState(S_RELATED);
  44.    
  45.     // add the module to the rule
  46.     output_rule->addModule(stateOut);
  47.    
  48.     // finnaly tell the rule how to deal with that (target)
  49.     output_rule->Accept();
  50.  
  51.     // insert the rule into the output chain
  52.     Firewall::Firewall::Output->Insert(output_rule);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement