<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Firewall on devcodenote.gitlab.io</title><link>https://devcodenote.gitlab.io/tags/firewall/</link><description>Recent content in Firewall on devcodenote.gitlab.io</description><generator>Hugo -- gohugo.io</generator><language>es-es</language><lastBuildDate>Sat, 07 Jun 2025 10:30:00 -0600</lastBuildDate><atom:link href="https://devcodenote.gitlab.io/tags/firewall/index.xml" rel="self" type="application/rss+xml"/><item><title>Cómo instalar un servidor OpenVPN y evadir los firewalls (DPI)</title><link>https://devcodenote.gitlab.io/posts/c%C3%B3mo-instalar-un-servidor-openvpn-y-evadir-los-firewalls-dpi/</link><pubDate>Sat, 07 Jun 2025 10:30:00 -0600</pubDate><guid>https://devcodenote.gitlab.io/posts/c%C3%B3mo-instalar-un-servidor-openvpn-y-evadir-los-firewalls-dpi/</guid><description>&lt;img src="https://devcodenote.gitlab.io/images/e3938bc2bb3eae0744a63c2b4563ee8362cdda7453ab06b4adb34b890796d6fdcbb31ad740c4acde96dc746179c5eeb695acb3b459c4e633d3d24ac5e6444d90.png" alt="Featured image of post Cómo instalar un servidor OpenVPN y evadir los firewalls (DPI)" />&lt;p>Se mostrará como instalar OpenVPN y como evadir los Firewall que suelen usar Deep Packet Inspection para identificar el tipo de protocolo que son los paquetes, muchos de estos suelen bloquear las conexiones VPN, el funcionamiento se basa en identificar el handshake de OpenVPN entonces si logramos ofuscar el handshake podemos saltarnos esa restricción, por suerte se implemento tls-crypt-v2 lo que reduce significativamente la dificultad.&lt;/p>
&lt;h2 id="instalacion">Instalacion
&lt;/h2>&lt;p>Lo primero es instalar openvpn y easy-rsa&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo apt install openvpn easy-rsa
&lt;/code>&lt;/pre>&lt;p>Lo primero configuramos easyrsa&lt;/p>
&lt;pre tabindex="0">&lt;code>cp -r /usr/share/easy-rsa /etc/
cd /etc/easy-rsa/
./easyrsa init-pki
&lt;/code>&lt;/pre>&lt;p>Generamos el certificado y la clave de la autoridad de certificación&lt;/p>
&lt;pre tabindex="0">&lt;code>cd /etc/easy-rsa/
./easyrsa build-ca nopass
./easyrsa gen-dh
./easyrsa build-server-full server nopass
openvpn --genkey secret /etc/easy-rsa/pki/ta.key
./easyrsa gen-crl
cp -rp /etc/easy-rsa/pki/{ca.crt,dh.pem,ta.key,crl.pem,issued,private}
/etc/openvpn/server/
&lt;/code>&lt;/pre>&lt;h2 id="creacion-del-handshake-encryption--tls-crypt-v2">Creacion del handshake encryption [tls-crypt-v2]
&lt;/h2>&lt;pre tabindex="0">&lt;code>Entonces nos ubicamos en
cd /etc/openvpn/server
Para generar el cifrado o el cifrado de handsacke para el lado del server es
openvpn --genkey tls-crypt-v2-server handshake_encryption_server.key
Para el lado del cliente es
openvpn --tls-crypt-v2 handshake_encryption_server.key --genkey tls-crypt-v2-client handshake_encryption_client.key
&lt;/code>&lt;/pre>&lt;h2 id="creacion-de-los-cientes-para-openvpn">Creacion de los cientes para openvpn
&lt;/h2>&lt;p>para este caso nos debemos ubicar en la carpeta que copiamos de easyrsa&lt;/p>
&lt;pre tabindex="0">&lt;code>cd /etc/easy-rsa
./easyrsa build-client-full User1 nopass
./easyrsa build-client-full User2 nopass
&lt;/code>&lt;/pre>&lt;p>Ahora vamos a copiar a los usuarios a la carpeta de openvpn, cada uno en su respectiva carpeta&lt;/p>
&lt;pre tabindex="0">&lt;code>mkdir /etc/openvpn/client/{User1,User2}
cp -rp /etc/easy-rsa/pki/{ca.crt,issued/User1.crt,private/User1.key} /etc/openvpn/client/User1
cp -rp /etc/easy-rsa/pki/{ca.crt,issued/User2.crt,private/User2.key} /etc/openvpn/client/User2
&lt;/code>&lt;/pre>&lt;h2 id="editar-la-configuracion">Editar la configuracion
&lt;/h2>&lt;p>En este caso es mas facil usar la plantilla de configuracion de OpenVPN&lt;/p>
&lt;pre tabindex="0">&lt;code>cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf /etc/openvpn/server/
cd /etc/openvpn/server/
&lt;/code>&lt;/pre>&lt;p>Ubicamos los siguientes parámetros y los modificamos un ejemplo:&lt;/p>
&lt;pre tabindex="0">&lt;code>ca ca.crt
cert issued/server.crt
key private/server.key # This file should be kept secret
dh dh.pem
tls-crypt-v2 handshake_encryption_server.key
push &amp;#34;dhcp-option DNS 1.1.1.1&amp;#34;
tls-auth ta.key 0
log-append /var/log/openvpn/openvpn.log
server-ipv6 fd93:b56d:6365::/64
push &amp;#34;dhcp-option DNS6 2606:4700:4700::1111&amp;#34;
push &amp;#34;dhcp-option DNS6 2606:4700:4700::1001&amp;#34;
push &amp;#34;redirect-gateway ipv6 def1 bypass-dhcp&amp;#34;
push &amp;#34;route-ipv6 fd93:b56d:6365::/64&amp;#34;
&lt;/code>&lt;/pre>&lt;p>Ejecutamos este comando para hablilitar el server y verificamos que este funcionando&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo systemctl start openvpn-server@server.service
root@i:/etc/openvpn/server# sudo service openvpn-server@server status
● openvpn-server@server.service - OpenVPN service for server
Loaded: loaded (/usr/lib/systemd/system/openvpn-server@.service; disabled; preset: enabled)
Active: active (running) since Wed 2024-10-23 00:55:49 UTC; 4min 39s ago
Docs: man:openvpn(8)
https://openvpn.net/community-resources/reference-manual-for-openvpn-2-6/
https://community.openvpn.net/openvpn/wiki/HOWTO
Main PID: 20333 (openvpn)
Status: &amp;#34;Initialization Sequence Completed&amp;#34;
Tasks: 1 (limit: 482)
Memory: 1.4M (peak: 1.7M)
CPU: 32ms
CGroup: /system.slice/system-openvpn\x2dserver.slice/openvpn-server@server.service
└─20333 /usr/sbin/openvpn --status /run/openvpn-server/status-server.log --status-version 2 --suppress-timestamps --config server.conf
Oct 23 00:55:48 Server systemd[1]: Starting openvpn-server@server.service - OpenVPN service for server...
Oct 23 00:55:49 Server systemd[1]: Started openvpn-server@server.service - OpenVPN service for server.
&lt;/code>&lt;/pre>&lt;h2 id="crear-el-ovpn">Crear el ovpn
&lt;/h2>&lt;p>Los archivospara crear el .ovpn estan en /etc/openvpn/client/User1&lt;/p>
&lt;pre tabindex="0">&lt;code>root@Server:/etc/openvpn/client/User1# ls
User1.crt User1.key ca.crt
&lt;/code>&lt;/pre>&lt;p>lo mismo con tls-crypt-v2 es el archivo que creamos como handshake_encryption_client.key&lt;/p>
&lt;pre tabindex="0">&lt;code> cat handshake_encryption_client.key
-----BEGIN OpenVPN tls-crypt-v2 client key-----
pKYdZklpqoO/XhsJnzn/RX7zTPsqLxgL+0PG3tuzqwyX27IscNXeViVwCwWAYwHU
IdvcrL6AgxgA22QQ.............
-----END OpenVPN tls-crypt-v2 client key-----
&lt;/code>&lt;/pre>&lt;h4 id="creación-del-ovpn">Creación del .ovpn
&lt;/h4>&lt;p>para crear el archivo de ovpn se debe usar el siguiente formato y solo modificar los campos de las claves, certificados y remote.&lt;/p>
&lt;pre tabindex="0">&lt;code>client
dev tun
proto udp
remote address port
resolv-retry infinite
nobind
persist-key
persist-tun
verb 4
data-ciphers-fallback AES-128-CBC
data-ciphers AES-256-CBC:AES-256-CFB:AES-256-CFB1:AES-256-CFB8:AES-256-OFB:AES-256-GCM
tls-cipher &amp;#34;DEFAULT:@SECLEVEL=0&amp;#34;
auth SHA256
key-direction 1
&amp;lt;ca&amp;gt;
-----BEGIN CERTIFICATE-----
MIIDSzCCAjOgAwIBAgIUAbBDafoK+M02UQCliU5DLxMZ2hQwDQYJKoZIhvcNAQEL
BQAwFjEUMBIGA1UEAwwLRWFzeS1SU0EgQ0EwHhcNMjQxMDIzMDAxODI1WhcNMz....
-----END CERTIFICATE-----
&amp;lt;/ca&amp;gt;
&amp;lt;cert&amp;gt;
Certificate:
Data:......
-----BEGIN CERTIFICATE-----
MIIDUzCCAjugAwIBAgIQKEeHa0xsNPRzkQFHiHubCTANBgkqhkiG9w0BAQsFADAW.........
-----END CERTIFICATE-----
&amp;lt;/cert&amp;gt;
&amp;lt;key&amp;gt;
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDe8LAxZblRxaDj
8NEaq0Mq4.......
-----END PRIVATE KEY-----
&amp;lt;/key&amp;gt;
&amp;lt;tls-crypt-v2&amp;gt;
-----BEGIN OpenVPN tls-crypt-v2 client key-----
pKYdZklpqoO/XhsJnzn/RX7zTPsqLxgL+0PG3tuzqwyX27IscNXeViVwCwWAYwHU.
Idvc.................
-----END OpenVPN tls-crypt-v2 client key-----
&amp;lt;/tls-crypt-v2&amp;gt;
&lt;/code>&lt;/pre>&lt;pre tabindex="0">&lt;code>sysctl net.ipv4.ip_forward=1
iptables -t nat -I POSTROUTING -o ens5 -j MASQUERADE
&lt;/code>&lt;/pre>&lt;h2 id="deteccion-por-deep-packet-inspection--dpi">Deteccion por Deep Packet Inspection (DPI)
&lt;/h2>&lt;p>Los firewall usan Deep Packet Inspection para reconocer ciertos protocolos&lt;/p>
&lt;p>&lt;img src="https://devcodenote.gitlab.io/images/e3938bc2bb3eae0744a63c2b4563ee8362cdda7453ab06b4adb34b890796d6fdcbb31ad740c4acde96dc746179c5eeb695acb3b459c4e633d3d24ac5e6444d90.png"
loading="lazy"
alt="Name"
>&lt;/p>
&lt;p>Desde ver el SNI en el Hello Client, identificar P2P, SSH, QUIC, etc.&lt;/p>
&lt;p>En este caso se detectó la conexión de openvpn y esto se debe a que el handshake tiene patrones muy reconocibles.&lt;/p>
&lt;p>&lt;img src="https://devcodenote.gitlab.io/images/8e739d64413c7701beb26d276162ace7bb861ea1bc39eb7f22699e8d8b8270631c537c27f1d86e04b70fedbb7af084254a0a3a9c30a09f0da59d550c0e453b79.png"
loading="lazy"
alt="Name"
>&lt;/p>
&lt;hr>
&lt;p>Lo primero que tenemos que hacer es cambiar el puerto porque el puerto default es de openvpn.&lt;/p>
&lt;p>&lt;img src="https://devcodenote.gitlab.io/images/cf7fb424a3f3c78234f4af9bb1db37233d9da8724da4209b1e880faf1eae8285b3040d524144153e0e86cf99238cc24deb956a03c4a5a06a84dbbc756308dfc0.png"
loading="lazy"
alt="Name"
>&lt;/p>
&lt;p>en la configuración usamos tls-crypt-v2 que nos permite ofuscar el handshake de openvpn.&lt;/p>
&lt;p>podemos ver la documentacion de tls-crypt-v2&lt;/p>
&lt;p>&lt;a class="link" href="https://github.com/OpenVPN/openvpn/blob/master/doc/tls-crypt-v2.txt" target="_blank" rel="noopener"
>https://github.com/OpenVPN/openvpn/blob/master/doc/tls-crypt-v2.txt&lt;/a>&lt;/p>
&lt;hr>
&lt;p>&lt;em>ls-crypt-v2 uses an encrypted cookie mechanism to introduce client-specific tls-crypt keys without introducing a lot of server-side state. The client-specific key is encrypted using a server key. The server key is the same for all servers in a group. When a client connects, it first sends the encrypted key to the server, such that the server can decrypt the key and all messages can thereafter be encrypted using the client-specific key.&lt;/em>&lt;/p>
&lt;p>&lt;em>A wrapped (encrypted and authenticated) client-specific key can also contain metadata. The metadata is wrapped together with the key, and can be used to allow servers to identify clients and/or key validity. This allows the server to abort the connection immediately after receiving the first packet, rather than performing an entire TLS handshake. Aborting the connection this early greatly improves the DoS resilience and reduces attack surface against malicious clients that have the tls-crypt or tls-auth key. This is particularly relevant for large deployments (think lost key or disgruntled employee) and VPN providers (clients are not trusted).&lt;/em>&lt;/p>
&lt;hr>
&lt;p>Una vez que usamos tls-crypt-v2 ya no es detecatdo por el Deep Packet Inspection
&lt;img src="https://devcodenote.gitlab.io/images/6a447095ab96f0e0c7ba6014a0f72ccdc12871632c5f09e0ad9d6c2fadf647f5f7f56183a3f0ce5fcf96085e6177f072f9d73787e24e1219882383df5d4f4838.png"
loading="lazy"
alt="Name"
>&lt;/p>
&lt;p>&lt;img src="https://devcodenote.gitlab.io/images/cd742e78ab8f75f43e5cc75f28c473ae00eaeb5c5659b83de68f1f6b7ac9573068f5681d2863ef67c0ddc4657703b1635d3aba24b7c6937bd9ce2e7434d2c61c.png"
loading="lazy"
alt="Name"
>&lt;/p>
&lt;p>&lt;img src="https://devcodenote.gitlab.io/images/7cd41183b6f6c952ad63be22d0d948c53fdf0a4daa4b5857c1822f669cbbe3a3f129fd03b000a3fc5e0efd203c53b19da3d9a0a9162aad00846fa0f7340cb5f4.png"
loading="lazy"
alt="Name"
>&lt;/p></description></item></channel></rss>