🕹️
Ghoulsec Vault
Website Toolbase
  • Welcome !
  • 🗃️Exam Prep Notes
    • 📔CEH V13 (Master Edition)
      • Module 02: Footprinting and Reconnaissance
      • Module 03: Scanning Networks
      • Module 04: Enumeration
      • Module 05: Vulnerability Analysis
      • Module 06: System Hacking
      • Module 07: Malware Threats
      • Module 08: Sniffing
      • Module 09 : Social Engineering
      • Module 10: Denial of Service
      • Module 11: Session Hijacking
      • Module 12: Evading IDS, Firewalls , Honeypots
      • Module 13: Hacking web servers
      • Module 14: Hacking Web Applications
      • Module 15:SQL Injection
      • Module 16: Wireless Attacks
      • Module 17: Hacking Mobile Platforms
      • Module 18: IoT & OT Hacking
      • Module 19 : Cloud Computing
      • Module 20 : Cryptography
    • 📘ISC2 -Certified in Cyber Security
      • Chapter -1 Security Principals
      • Chapter -2 Disaster Recovery,Business Continuity & Incident Response
      • Chapter -3 Access Control Concepts
      • Chapter -4 Network Security
      • Chapter -5 Security Operations
    • 📗AZ - 900
      • Basics of Cloud Computing
        • Economic of Scale
        • CapEx & OpEx
        • Consumption based model
        • Cloud Deployment Models
        • Shared Responsibility Model
        • Data centers, Regions & Availability Zones & Geographyies in Azure
        • Resources & Resource Group
        • Azure Access Tools
        • Azure Service Lifecycle
        • Azure SLAs
        • Azure Cloud Adoption Framework
      • Azure Services
        • Azure Computing Services
        • Azure Networking Services
        • Azure Storage Services
        • Azure Database Service
        • Azure Marketplace
        • Big Data & Azure
        • Azure Serverless Computing
        • IoT & Azure
        • Other Azure Services
        • Azure Resource Locks & Resource Tags
        • Azure Security Services
          • Security Groups
          • Routing Tables
          • Azure Firewall
          • Azure DDOS Protection
          • Azure Identity & Access Management (Azure AD)
          • Azure RBAC
          • Azure Security Center
          • Azure Key Vault
      • Azure policies & Blueprints
      • Azure Cost Management
      • Azure Core Tenents
    • 📗SC - 900
      • Zero Trust Model
      • Shared Responsibility Model
      • Defense in Depth
      • Security Controls
      • CIA Triad
      • Encryption / Hashing / Signing
      • Microsoft Security & Compliance Principals
      • Common Identity Attacks
      • Microsoft Identity as Primary Security Perimeter
      • Modern Authentication with Azure AD
      • Azure AD Identity Types
      • Azure External Identities
      • Hybrid Identities
      • Authentication Methods & Password Protection
      • Conditional Access
      • Azure AD Roles & RBAC
      • Governance in Azure AD
      • Azure Identity Protection
      • Azure NSG, DDOS, Firewall
      • Azure Bastion & Keyvault
      • Azure Encryption
      • Azure CSPM
      • Azure Security Center
      • Azure Defender
        • Microsoft O365 Defender
        • Azure Sentinel
      • Microsoft Cloud App Security
      • Microsoft Intune
      • Microsoft Complaince Manager
      • Information Protection
      • Microsoft insider risk capabilities
    • 📔AWS Cloud Practitioner
      • Cloud Deployment
        • AWS Global Infrastructure
      • AWS Cloud Essentials
        • AWS SNS
          • AWS SQS
      • AWS Compute & Container Services
        • AWS EC2
          • Elasticity & Agility
        • AWS Serverless Computing
        • AWS Container Services
        • AWS Beanstalk
        • AWS Load Balancing
      • AWS Storage & Databases
      • AWS Networking
      • AWS Security
        • AWS Organisation
        • AWS Compliance
        • AWS DDOS
        • Additional Security Services
      • AWS Monitoring & Analytics
        • Other Analytics Services
      • AWS Pricing & Support
      • AWS Migration & Innovation
        • Migration Statergies
        • AWS Snow Family
        • AWS Transfer Family
        • Innovation on AWS
      • AWS Well Architecture Framework
      • Other AWS Services
  • 🧑‍💻Cyber Security Base
    • Ghoul's Den
    • Cheatsheets
    • SSL Handbook
      • Installing OpenSSL
      • Encrypting Web Servers using SSL
      • Compiling .pfx file using openssl
      • De-compiling .pfx file
      • Zimbra Mail Server SSL renew
      • SSL Certificates
    • ☁️Cloud Security
      • Amazon Web Services (AWS)
        • AWS - IAM & Policy Management
        • AWS Organization
        • AWS - Roles (Assume Role)
        • AWS - EC2 (Elastic Computing)
        • AWS - VPC
        • AWS - Bastion Host
        • AWS Application Load Balancer
        • AWS Auto Scaling Group
        • AWS WAF
        • AWS - VPC Peering
        • AWS Transit Gateway
        • AWS NAT Gateway
        • AWS - Route 53
        • AWS Certificates Manager
        • AWS Network Load Balancer (NLB)
    • 🕸️Network Security
      • Firewalls
        • Sophos - Security Suite
          • Sophos Firewalls
      • VPN
        • VPNs
          • Wireguard Tunneling
          • StrongSwan Gateway VPN Server on Ubuntu
      • IP Address and IP Subnetting
      • Basic to Advance Networking Materials
    • 🧑‍💻VAPT
      • Sample Report Templete
      • OWASP
        • OWASP Web Application Security & WebGoat
      • Web Application testing checklist
        • Client Side Penetration Testing
          • Clickjacking
          • Websockets
          • CSRF
          • XSS Filters
        • Server Side Penetration Testing
        • Advanced Web Application Pentesting
          • OAuth
          • JWT Injection
          • Server Side Templete Injection
    • ☄️GRC
      • ISMS AUDIT PLAN
      • CIS Compliance Windows
    • 🔍Forensic
      • Forensic Tools
      • EMAIL Forensics
      • File header forensics
    • Trend Micro
      • Deep Security
        • Installation & Prerequisite
          • Microsoft SQL server 2022
          • Postgres 16 Core
          • Installation
    • Practical Malware Analysis & API Threats
  • 🕹️Server are fun !
    • Securing Linux
      • Securing SSH
      • Sudoers
      • UFW (Uncomplicated FW)
      • Unattended Upgrades
      • Password Complexiety
      • Auditing Linux
      • Samba - SMB
      • NFS - Network File System
      • FTP
      • AIDE
    • Servers
      • Linux Sever
        • OpenLDAP Server Setup
          • ldap-account-manager
          • Securing OpenLDAP
          • OpenLDAP client setup
          • Checking LDAP setup
        • Users & Groups
        • Password Policy
        • File & File Permissions
        • Automatic Updates
        • Adding GUI to Ubuntu Server
        • DNS Server
        • NTP Server
      • Windows Sever
        • Deep dive into Windows Server
        • Windows server Installation
        • Disable IPv6
        • Disable Server Manager on startup
        • Promoting OS to AD server
        • AD DNS
        • AD DHCP
        • AD Activation
        • AD Users & Groups
        • AD FileServer
        • Adding Users into AD
        • Bulk Importing users into Domain
        • Windows AD Resources
        • Group Policy Editor
          • Creating First Policy
          • Restricting CMD & Powershell
          • Password Policies
          • Audit Policies
          • Log Retention Policy
          • Windows Defender Firewall
          • Patch Management & Window Updates
        • Setting Up local accounts for windows hosts
    • Hacking Systems
      • Linux Systems
        • Battery Charge Threshold (Linux)
        • Metasploitable OS Complete Solved
      • Tricking Windows
        • Bitlocker & Time based policy bypass
    • Monitoring HeartBeats
    • RAID Technology
    • Managing Partitions
      • Parted
      • Fdisk
      • LVM
        • Re-claiming unused disk space
        • Adding physical volume into VG
        • Removing physical volume from VG
      • SWAP Memory
    • Virtualization
      • Proxmox
        • Proxmox VE Installation
        • Default Storage Expansion
        • Proxmox Network Link Aggegration
        • NAT Interface Configuration
        • Importing disk into proxmox
        • Creating an LVM Thin Pool
        • Proxmox IAM
  • 🙍‍♂️Dan the AI Expert
    • Ollama Ollama ...
      • Ollama
        • Ollama models
        • Open Web UI & Ollama Integration
    • Microsoft Presentation using AI
  • 🛡️Security Operations
    • Wazuh - Open Source XDR. Open Source SIEM.
      • Components
      • Deployment Methods
      • Installation
        • Single Node Installation
          • Wazuh Indexer Installation
          • Wazuh Server Installation
          • Wazuh Dashboard Installation
          • Single node deployment with Script
        • Managing multiple Wazuh clusters with Cross-Cluster Search
          • Cluster Configuration
          • Set up Cross-Cluster Search
        • Upgrading Wazuh Central Components
        • Uninstalling Wazuh
      • Custom Decoder & Rules
        • Pfsense Decoders
        • Pfsense Rules
      • Security Operations Center Tools (Wazuh)
    • IRIS-DFIR / Case Management
    • Graylog & ElasticSearch
    • Zabbix NMS
      • Zabbix Installation
      • Zabbix Database Management
        • Zabbix Database backup
        • Zabbix Database restore
        • MySQL Replication (M-M)
        • MySQL Replication (M-W)
      • Zabbix Geomap Setup
      • Adding Hosts into Zabbix
      • Zabbix Hostgroups
      • Auto Registration Hosts Zabbix
      • Zabbix Globalscrips
      • Zabbix HA Cluster
      • Zabbix Proxy
      • Zabbix Notifications
      • Zabbix Maintainance
      • Zabbix User Management & Authentication
      • Zabbix Housekeeping
      • Scheduled Reporting
      • Service Monitoring using Zabbix
  • Git the master!!
    • Configuring git
    • Git Branches
    • Undoing changes
    • Git - Cheat sheet
    • My first git...
Powered by GitBook
On this page
  • References :
  • Server Side Configuration
  • Client Side Configuration
  • Ubuntu or any Linux:
  • Windows OS :
  1. Cyber Security Base
  2. Network Security
  3. VPN
  4. VPNs

StrongSwan Gateway VPN Server on Ubuntu

PreviousWireguard TunnelingNextIP Address and IP Subnetting

Last updated 22 hours ago

A VPN allows you to access the Internet safely and securely on an untrusted public Wi-Fi network. You can connect to remote VPN servers using the encrypted connection and surf the web anonymously.

strongSwan is free, open-source, and the most widely-used IPsec-based virtual private network implementation, allowing you to create an encrypted secure tunnel between two or more remote networks.

strongSwan uses the IKEv2 protocol, which allows for direct IPSec tunneling between the server and the client. strongSwan stands for Strong Secure WAN and supports both versions of automatic keying exchange in IPsec VPN, IKE V1 and V2.

References :


Server Side Configuration

Update the system :

sudo apt update && sudo apt upgrade -y

Generate Server Keys and Certificate

Use the IPsec command-line utility to create your IPsec private key.

 sudo ipsec pki --gen --size 4096 --type rsa --outform pem > ca.key.pem
 sudo mv ca.key.pem /etc/ipsec.d/private/ca.key.pem
 sudo chmod 600 /etc/ipsec.d/private/ca.key.pem

Create and sign the root certificate with the configurations included below. Ensure you replace the value of the CN configuration with your own desired name for your StrongSwan VPN server.

 sudo ipsec pki --self --in /etc/ipsec.d/private/ca.key.pem --type rsa \
 --dn "CN=<Name of this VPN Server>" --ca --lifetime 3650 --outform pem | \
 sudo tee /etc/ipsec.d/cacerts/ca.cert.pem > /dev/null

Generate the StrongSwan VPN server’s private key and save it to /etc/ipsec.d/private/server.key.pem. This command ensures root permissions for file creation, and suppresses terminal output.

 sudo ipsec pki --gen --size 4096 --type rsa --outform pem | sudo tee /etc/ipsec.d/private/server.key.pem > /dev/null

Generate the host server certificate. There are two ways to generate the certificate, however, they cannot be mixed. The two ways are as follows:

  • Use a local resolver, like DNS, your hosts’ file, or another resolver.

  • Use a static host gateway server by providing its IPv4 address.

Local Resolver Method

 sudo ipsec pki --pub --in /etc/ipsec.d/private/server.key.pem --type rsa | \
 sudo ipsec pki --issue --lifetime 3650 \
 --cacert /etc/ipsec.d/cacerts/ca.cert.pem --cakey /etc/ipsec.d/private/ca.key.pem \
 --dn "CN=<serverhost.ourdomain.tld>" --san="<server.ourdomain.tld>" \
 --flag serverAuth --flag ikeIntermediate --outform pem | \
 sudo tee /etc/ipsec.d/certs/server.cert.pem > /dev/null

Gateway Server or IPV4 Address

sudo ipsec pki --pub --in /etc/ipsec.d/private/server.key.pem --type rsa | \
 sudo ipsec pki --issue --lifetime 3650 \
 --cacert /etc/ipsec.d/cacerts/ca.cert.pem --cakey /etc/ipsec.d/private/ca.key.pem \
 --dn "CN=<server static IP address>" \
 --san="<server static IP address>" --san="<server static IP address>" \
 --flag serverAuth --flag ikeIntermediate --outform pem | \
 sudo tee /etc/ipsec.d/certs/server.cert.pem > /dev/null

Important Locations for Key Management for Strongswan :

/etc/ipsec.d/private/ca.key.pem	        VPN Host Gateway Private Key
/etc/ipsec.d/cacerts/ca.cert.pem	VPN Host Gateway Root Certificate
/etc/ipsec.d/private/server.key.pem	VPN Host Gateway Private Key
/etc/ipsec.d/certs/server.cert.pem	VPN Host Gateway Server Certificate

Configuring Strongswan :

Use your preferred text editor to edit your /etc/sysctl.conf file. The configurations to add enable packet forwarding for IPsec and StrongSwan on your Ubuntu system. Add the following parameters in the end of config file

net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
    

Reload the config changes using the following command:

sysctl -p

Installing Strongswan :

sudo apt install strongswan strongswan-pki libcharon-extra-plugins libcharon-extauth-plugins libstrongswan-extra-plugins libtss2-tcti-tabrmd0 -y

Now for the safer side if something goes wrong we first take the config backup

mv /etc/ipsec.conf /etc/ipsec.conf.bak

Make the new config file :

nano /etc/ipsec.conf

Configure the StrongSwan file. Open your /etc/ipsec.conf file and add the configurations included in the example file below.

Within the context of StrongSwan, the gateway host server (your Ubuntu server) is referred to as left resources. External hosts connecting to the StrongSwan VPN are referred to as right resources.

config setup
    charondebug="ike 2, knl 2, cfg 2, net 2, esp 2, dmn 2, mgr 2"
    strictcrlpolicy=no
    uniqueids=yes
    cachecrls=no

conn ikev2-rw
    auto=add
    compress=no
    type=tunnel
    keyexchange=ikev2
    fragmentation=yes
    forceencaps=yes
    dpdaction=clear
    dpddelay=300s
    rekey=no

    left=%any
    leftid=0.0.0.0/0 OR @example.com <IP/DNS OF THE VPN SERVER>
    leftcert=server.cert.pem
    leftsendcert=always
    leftsubnet=100.100.200.0/24  # Client will have access to this range
    leftsourceip=10.10.69.0/24  # Clients will be assigned IPs from this range

    right=%any
    rightid=%any
    rightauth=eap-mschapv2
    rightsourceip=10.10.69.0/24  # This will allocate IPs in the 10.10.69.x range
    rightdns=8.8.8.8  # DNS server for the client
    rightsendcert=never
    eap_identity=%identity
    ike=chacha20poly1305-sha512-curve25519-prfsha512,aes256gcm16-sha384-prfsha384-ecp384,aes256-sha1-modp1024,aes128-sha1-modp1024,3des-sha1-modp1024!
    esp=chacha20poly1305-sha512,aes256gcm16-ecp384,aes256-sha256,aes256-sha1,3des-sha1!

Create authentication and access secrets. Access control and authentication require that StrongSwan clients provide a username and password. This information is contained in the /etc/ipsec.secrets file.

Using a text editor, create a the /etc/ipsec.secrets file with the following contents:

: RSA "/etc/ipsec.d/private/server.key.pem"
user1 : EAP "password@2"
user2 : EAP "password@1"    

Save and close the file. Then, restart the strongSwan service and enable it to start at reboot:

systemctl restart strongswan-starter.service
systemctl enable strongswan-starter.service
systemctl status strongswan-starter.service

You can also verify the strongSwan certificates using the following command:

ipsec listcerts

Your StrongSwan server is now ready to receive client connections. To check the status of the IPsec tunnel created by StrongSwan, use the following command:

sudo ipsec status

Client Side Configuration

We will consider adding clients on windows & Linux OS in this section

Ubuntu or any Linux:

 sudo apt update && upgrade -y

Install the StrongSwan client and required plugins.

 sudo apt install strongswan libcharon-extra-plugins

Download or copy the StrongSwan host gateway VPN server’s certificate. The certificate is located on the VPN server in /etc/ipsec.d/cacerts/ca.cert.pem. Store the copied or downloaded certificate in the client’s /etc/ipsec.d/cacerts directory.

Add the IPsec secrets file to the StrongSwan client. Using a text editor, add the /etc/ipsec.secrets file. The credentials for this user must exactly match those created on the StrongSwan VPN server.

user1 : EAP "password@1"

Create or modify the /etc/ipsec.conf configuration file. The file can be configured to support a host gateway VPN server configured for a resolver/DNS or to support access via an IPv4 address. Refer to the example configuration below that corresponds to your StrongSwan VPN server.

  • Resolver DNS based :

config setup

conn ikev2-rw
    right=0.0.0.0/0 OR @example.com  # VPN server IP or DNS NAME
    rightid=0.0.0.0/0 OR @example.com  # Server identity (should match server config leftid)
    rightsubnet=100.100.200.0/24  # MATCH LEFT SUBNET OF SERVER # Network the client will have access to 
    rightauth=pubkey
    leftsourceip=%config  # Client will be assigned IP from the server pool (10.10.69.x)
    leftid=vishvam  # This is the EAP identity
    leftauth=eap-mschapv2  # EAP-MSCHAPv2 authentication
    eap_identity=%identity  # EAP identity should match what is on the server
    auto=start

To start the StrongSwan client VPN, use the following command:

 systemctl start strongswan-starter

Verify the StrongSwan connection from the client to server, use the following command:

 sudo ipsec status / ipsec restart

To enable connection on boot :

systemctl enable strongswan-starter
systemctl disable strongswan-starter

Windows OS :

Importing the VPN Root Certificate on Windows 10

To connect to a StrongSwan VPN gateway server, your Windows 10 system needs a copy of the gateway VPN server’s certificate.

  • Import the VPN gateway server’s certificate that is located in /etc/ipsec.d/certs/server.cert.pem. The certificate must be marked as a VPN Root Certificate.

  • Use the Microsoft Management Console/MMC to configure the VPN’s IPsec information.

  1. Open the Run dialog box, (Windows_key-R), or press the Windows key, and enter into the lower-left dialog box, mmc.exe. This starts the Microsoft Management Console/MMC.

  2. From the File menu of the MMC, scroll to Add or Remove Snap-in. Select Certificates from the list, and click Add.

    The Snap-in asks for the account type to manage. From the list that appears, choose Computer account.

    Then, choose Local Compute unless you manage other computers that also use this certificate. Click Finish, and the process is completed.

  3. The Console Root MMC displays a list of certificate types on the left side of the MMC, and in the middle, a list of certificates pertaining to the selection on the left.

    On the left of the MMC, open Trusted Root Certificate Authorities, then click the Certificates folder that appears directly under Trusted Root Certificate Authorities.

  4. From the MMC Action menu, choose All Tasks, then Import. The Certificate Import Wizard appears. Choose Local Machine, then browse to the location where the server.cert.pem file was imported, and select it.

  5. The Certificate Import Wizard asks where to import the certificate. The wizard recognizes the type, and places the certificate into the Trusted Root Certification Authorities certificate store. Click Finish to complete the certificate import process.

Connecting a Windows Client to the StrongSwan Gateway VPN Server

The client authentication process relies on the ipsec.secrets file located on the gateway VPN server.

  1. To configure a new VPN connection on your Windows computer, launch the Control Panel from the Windows menu by pressing the Windows key. Then, select Network and Sharing Center.

  2. Choose Setup a new connection or network and then, select Connect to a workplace. Next, select Choose Use my Internet Connection (VPN).

    During this step, you need some details about your gateway VPN server. You should know the server’s DNS name if that’s how it was configured in the ipsec.conf file. If, however, you used an IPv4 address when configuring the leftid value in the ipsec.conf file, provide the server’s IPv4 address. Finally, you enter a username and password that matches the VPN server’s ipsec.secrets entry.

  3. Start the VPN by clicking its name from the Taskbar Networks list of choices.

  4. To terminate your VPN connection, click the VPN again and you have disconnected another network.

🧑‍💻
🕸️
Install and Configure StrongSwan on Ubuntu 20.04Linode Guides & Tutorials
How to Install and Configure strongSwan VPN on UbuntuAtlantic.Net
Logo
Logo