Rou$ng  IPSec  Tunnels  to  OpenVPN   networks  using  OpenSWAN.   Lance  Bu?ars   h?p://www.obscuritysystems.com/   OpenVPN  and  IPSec     • OpenVPN  is  not  compa$ble  with  IPSec!   • OpenVPN  !=  IPSec   • VPN  does  not  always  mean  using  IPSec     – (but  that  is  what  the  majority  thinks)   • Using  OpenSWAN  you  can  bridge  an  OpenVPN   network  to  a  IPSec  tunnel.     OpenVPN  vs  IPSec   OpenVPN   • Client  Server   • Single  Port       – You  pick  the  port   • Easy  to  setup.   • Easy  to  Troubleshoot   • More  Secure  than  a   standard  PSK  3-­‐DES   • Works  in  OpenVZ   IPSec   • Peer  to  Peer   • Mul$ple  Ports     – 50  for  ESP  or  AH   – 500  for  ISAKMP   – 4500  for  NAT-­‐T   • Does  not  work  well  with  NAT   • Complicated   • Mostly  uses  PSK  which  can   become  outdated.     • Does  not  work  in  OpenVZ   OpenVPN  Posi$ve   • Easy  RSA  scripts  can  quickly  and  easily  create   cer$ficates  to  issue  connec$vity.   • Server  /  Client  infrastructure  one  point  controls   configura$on  and  forces  all  others  to  comply.   • Uses  a  single  port  can  switch  between  UDP  and   TCP.   • Compression  can  lead  to  faster  Internet   Connec$ons.   • NAT  is  not  a  problem  for  OpenVPN.   OpenVPN  Nega$ve   • Not  supported  with  most  equipment.   • Not  compa$ble  with  IPsec.   • Not  understood  well  by  people  who  don’t  use   it.   • No  RFC  Number  as  of  yet.     IPSec  Posi$ve   • Works  on  older  equipment.   • Most  places  already  have  one  version  of  it  or   another.   • Secure  if  setup  correctly.   • RFC  standard.     IPSec  Nega$ves   Hard  to  configure.   Too  many  op$ons.   Hates  NAT  and  NAT  hates  it.   Peer  to  Peer  architecture  makes  connec$on   setup  between  two  par$es  difficult.   • PSK  results  in  insecure  communica$on  channels.   • Not  compa$ble  with  OpenVPN.   • L2TP  required  for  road  warrior  setup.     • • • • PPTP   (Point-­‐to-­‐Point  Tunneling  Protocol)   • DON’T  USE  IT!   • Requires  GRE  which  can  cause  configura$on   issues.   • Can  easily  be  broken  by  capturing   DataStream.   • Lack  of  Two  face  authen$ca$on.   • Acer  learning  OpenVPN  you  will  never  need  it.     • Uses  MSCHAP2   ISO  Layers   OpenVPN  Setup   • • Debian  Path   cd    /usr/share/doc/openvpn/examples/easy-­‐rsa/2.0/   • vim  vars  (Edit  file)   • Source  var     – Fill  this  file  out  like  a  form   – Loads  environmental  seIngs     • ./clean-­‐all   • ./build-­‐ca   – WARNING:  Only  run  once  cleans  key  directory   – Builds  a  CerRficate  Authority     • ./build-­‐key-­‐server  server     – Builds  OpenVPN  server  cerRficate  and  key   • ./build-­‐key  client1   • ./build-­‐dh   – Builds  client  key  and  cerRficate   – Diffie-­‐Hellman     Security  Files   • ca.crt   – Given  to  every  client  to  use  to  validate  connec$on.   • ca.key   – Keep  Private  (Keys  to  the  VPN  Kingdom)   • dh{n}.pem     – server  only  Diffie  Hellman  parameters   • server.crt     – Server  Cer$ficate   • server.key   –  Server  Key   • client1.crt       – Cer$ficate  for  client   • client1.key     – Key  for  client  key  private  for  client  used  to  connect.   Open  Segngs   /etc/openvpn/server.conf   • port    1923   – Port  Used  to  connect  to  Server   • proto  udp   – proto  tcp  /udp   • ALWAYS  USE  UDP  IF  YOU  CAN   – TCP  does  not  work  well  with  tcp  over  tcp.   • dev  tun   – TAP/TUN     • Type  of  VPN  Tunnel  Layer  3  or  Layer  2   • ca  /etc/openvpn/ca.crt   – Cer$ficate  Path   • cert  /etc/openvpn/test.crt   – Cer$ficate  for  Server   • key  /etc/openvpn/test.key   – Key  for  server   • dh  /etc/openvpn/dh2048.pem   – Dihellmen  key  for  server   OpenVPN  Segng  Part  2   • server  172.16.x.x  255.255.255.0   – Ip  address  pool   • ifconfig-­‐pool-­‐persist  ipp.txt   – Ip  address  pool  log   • keepalive  10  120   – Pings  to  check  to  see  if  other  side  is  s$ll  up   • comp-­‐lzo   – Use  comp-­‐lzo  compression   • user  nobody   – Service  user   • group  users   – Service  group   • status  openvpn-­‐status.log   – verb  3   OpenVPN  Segng  Part  3   • client-­‐to-­‐client   • push  "redirect-­‐gateway  def1  bypass-­‐dhcp“   – Only  use  if  your  segng  up  road  warrior  NATt’ed  setup  will   change  default  gateway  for  all  clients   • • • • push  "dhcp-­‐op$on  DNS  208.67.222.222"   push  "dhcp-­‐op$on  DNS  x.x.x.1"   push  "route  172.x.x.0  255.255.255.0"   push  "route  10.x.x.0  255.255.225.0   Bridging  and  Rou$ng  between   OpenSWAN  and  IPSec     IPSec  Nuts  and  Bolts   • Encryp$on  3DES  AES   – Always  use  AES  ,3DES  has  known  a?acks   • Diffie-­‐Hellman  Key  Exchange   • AH  /  ESP   – Keeps  keys  safe   – Packet  types   • Transport  and  Tunnel  Mode   – Layers   • • Aggressive  Mode  /Main  Mode   Inter  Key  Exchange     – Phase  1  /  Phase  2   • The  NAT  Problem     • • • IKE  daemon  called  Pluto.     NETKEY,  the  2.6  IPsec  Stack     Perfect  Forward  Secrecy   – NAT  -­‐t   AuthenRcaRon  Header   (AH)     • Guarantees  connec$onless  integrity  and  data  origin  authen$ca$on   of  IP  Packets   • Protects  against  replay  a?acks.   • Security  Parameter  Index(SPI)   – Uniquely  Iden$fies  connec$on   • Sequence  Number(SN)   – Uniquely  sets  number  for  every  packet.   • A  cryptographic  checksum.  Integrity     – check  value  (ICV)   – MD5  or  SHA1     • Hash  Message  Authen$ca$on  Code  (HMAC  )   – SPI  +  SN=  ICV   • AH  only  provides  authen$ca$on  and  does  not  encrypt  the  payload     • Since  AH  on  its  own  does  not  offer  encryp$on,  it  is  hardly  used  at   all.     Encapsula$ng  Security  Payload   (ESP)   Encrypts  and  Protects  replay.   Has  SPI,SN  and  ICV.   ESP  now  provides  authen$ca$on.   The  only  reason  AH  is  separate  form  ESP  is   because  of  the  US  Export  Restric$on  that   were  in  effect  when  they  were  created.   • ESP  is  be?er.   • There  is  li?le  or  no  need  for  AH.   • • • • IPSec  Security  Authority  (SA)   • Contract  Between  two  communica$ng   en$$es.   – Contains  database  for  SPI   – Sequence  Number   – Life$me   – Mode   – Tunnel   – Contains  all  configura$on  op$ons   Internet  Key  Exchange  (IKE)   • Phase  1  ISAKMP  SA     – Phase  1  deals  with  obtaining  privacy  through  a  Diffie-­‐Hellman   key  exchange,     • Phase  2  Quick  Mode   – Establishes  what  Ciphers  to  use.   – Which  tunnel  mode  to  use  so  on  forth.   • Main  Mode     – Slower  mode  packets  more  fault  tolerant     • Aggressive  Mode   – Faster  less  packets  more  error  prone   • Pluto     – Handles  IKE  Enable  Pluto  Debugging  to  trouble  shoot  IKE   problems  in  great  depth.   IPSec  Modes   • Tunnel  Mode   – Used  in  most  cases     – Connec$on  between   two  routers   – Also  know  as  an   Encrypted  route   • Transport  Mode   – Is  used  for  LT2P   – Used  for  transpor$ng   Layer  2  traffic.   – only  the  payload  of  the   IP  packet  is  encrytped   and  authen$cated.   –  The  rou$ng  is  intact,   since  the  IP  header  is  not   modified  or  Encrypted     KLIPS  vs  NETKEYS   • Klips   – Most  compile  OpenSWAN  requires  kernel   modules   – NETKEYS   • • • • A  li?le  confusing   Comes  installed  by  default   Cannot  view  routes  from  netstat  -­‐r  command     Does  not  create  virtual  interface.   L2TP   • Point  to  Point  Protocol   – Needs  IPSEC  for  security   • Supported  by  Windows  ,  Apple  and  almost  all   mobile  devices.   • Hard  to  configure   • Uses  port  1701   OpenSWAN  Setup   • • • • • apt-­‐get  install  openswan   apt-­‐get  install  lsof   ipsec  verify   ipsec  setup  start   ipsec.secrets     – /etc,  or  /etc/ipsec/   – Stores  RSA  keys  and  preshared  secrets  (PSKs)     • ipsec.conf     – /etc,  or  some$mes  in  /etc/ipsec     – Contains  all  configura$on  op$ons   #!/bin/bash     #  Disable  send  redirects   echo  0  >  /proc/sys/net/ipv4/conf/all/send_redirects   echo  0  >  /proc/sys/net/ipv4/conf/default/send_redirects   echo  0  >  /proc/sys/net/ipv4/conf/eth0/send_redirects   echo  0  >  /proc/sys/net/ipv4/conf/eth1/send_redirects   echo  0  >  /proc/sys/net/ipv4/conf/lo/send_redirects   echo  0  >  /proc/sys/net/ipv4/conf/ppp0/send_redirects     #  Disable  accept  redirects   echo  0  >  /proc/sys/net/ipv4/conf/all/accept_redirects   echo  0  >  /proc/sys/net/ipv4/conf/default/accept_redirects   echo  0  >  /proc/sys/net/ipv4/conf/eth0/accept_redirects   echo  0  >  /proc/sys/net/ipv4/conf/eth1/accept_redirects   echo  0  >  /proc/sys/net/ipv4/conf/lo/accept_redirects   echo  0  >  /proc/sys/net/ipv4/conf/ppp0/accept_redirects   • #  /etc/ipsec.conf  -­‐  Openswan  IPsec  configura$on  file    config  setup   #  Debug-­‐logging  controls:    "none"  for  (almost)  none,  "all"   for  lots.   •            #  klipsdebug=none   •                #plutodebug="control  parsing"   •                #  For  Red  Hat  Enterprise  Linux  and  Fedora,  leave    protostack=netkey      nat_traversal=yes   •                 virtual_private=   •                oe=off   •                #  Enable  this  if  you  see  "failed  to  find  any  available   worker"   •                nhelpers=0   • #You  may  put  your  configura$on  (.conf)  file  in  the  "/etc/ ipsec.d/"   conn  test                  type=tunnel                  authby  =  secret                  lec  =  x.x.x.36                  lecsubnet  =x.x.x.36/32                  lecsourceip  =  x.x.x.x36  (OpenVPN  Network)                  lecid=x.x.x.181                  lecnexthop=%defaultroute                  righ$d=x.x.x.38                  right=x.x.x.92                  rightsubnet=x.x.x.15/24  #(OpenSWAN  Network)                  esp=aes256-­‐sha1                  ike="aes256-­‐sha1-­‐modp1024"                  keyexchange  =  ike                  pfs  =  no                  auto  =  start                  life$me=86400s                  aggrmode=no   Trouble  Shoo$ng  OpenSWAN  IPSec   • Ipsec  barf   • Ipsec  auto    -­‐-­‐status   • Enabling  pluto  debug  or  disable  pluto   debuging.     OpenVPN  Case  Studies   • Virtual  Private  Servers     – Interserver  (h?p://www.interserver.net/)   – 3mb  up  and  down  376  mb  ram  $6.00  a  month.   » Los  Angles  ,CA   » Secaucus,  NJ   • Santrex  (h?p://www.santrex.net/vps-­‐hos$ng.php)   – OffShore  VPS  $9.00     • Be  Very  Careful  of  Terms  and  Laws  when  crossing  borders!   • France     • Germany     • Luxembourg     • Netherlands     • Romania     • Etc..     Road  warrior  Setup  /  Proxy  setup   IPTables  NATing  OpenVPN  Network   • iptables  -­‐t  nat  -­‐A  POSTROUTING  -­‐s      172.18.x.x/24  -­‐j  SNAT     -­‐-­‐to  x.x.x.x     • iptables  -­‐A  INPUT  -­‐p  udp  -­‐m  udp  -­‐-­‐dport  1074  -­‐m  state      -­‐-­‐state  NEW  -­‐j  ACCEPT       • iptables  -­‐A  FORWARD  -­‐m  state  -­‐-­‐state   RELATED,ESTABLISHED  -­‐j  ACCEPT     • iptables  -­‐A  FORWARD  -­‐s  172.18.x.x/24  -­‐j  ACCEPT     • iptables  -­‐A  FORWARD  -­‐j  REJECT   Rou$ng  in  Linux     • • • • • vim  /etc/sysctl.conf     #  Controls  IP  packet  forwarding   net.ipv4.ip_forward  =    1   Systcl  –p   (don’t  always  turn  this  on  is  off  for  a  reason)   Server  Tethering  To     OpenVPN  Cloud  Server.   OpenVPN  Dial  Back   Monitoring  Services   OpenVPN  Incep$on  Layers?   Stunnel   • Encrypts  Layer  4  in  TLS/SSL  RSA  Encryp$on   – openssl  req  -­‐new  -­‐x509  -­‐days  365  -­‐nodes  -­‐config   stunnel.cnf  -­‐out  stunnel.pem  -­‐keyout  stunnel.pem   – openssl  rsa  -­‐in  original.pem  -­‐out  new.pem     stunnel.conf   • cert  =  /etc/stunnel/stunnel.pem   setuid  =  nobody   setgid  =  nobody   pid  =  /tmp/stunnel.pid   debug  =  7   output  =  stunnel.log   [mysqls]   accept    =  3309   connect  =  3306   Obscurity  Systems   • For  Consul$ng  or  More  Info  My     – Website   • h?p://www.obscuritysystems.com/   – Email   • nemus@grayhatlabs.com     • info@obscuritysystems.com   – Phone  Number   • 801-­‐828-­‐3184   • Sllug  Mailing  list  h?p://www.sllug.org/