41

I need to check that an OpenVPN (UDP) server is up and accessible on a given host:port.

I only have a plain Windows XP computer with no OpenVPN client (and no chance to install it) and no keys needed to connect to the server - just common WinXP command line tools, a browser and PuTTY are in my disposition.

If I was testing something like an SMTP or POP3 servert I'd use telnet and see if it responds, but how to do this with OpenVPN (UDP)?

4
  • if openvpn is running via tcp, you could telnet as well – rvs Apr 22 '11 at 9:21
  • OpenVPN is running via UDP – Ivan Apr 22 '11 at 10:06
  • 2
    Can you elaborate on why you would want to solve this from an obsolete Windows system and not from a real monitoring system? – Alex Holst Apr 22 '11 at 13:40
  • 2
    If the UDP openvpn server uses the (recommended) tls-auth configuration option, then it is IMPOSSIBLE (If you don't have at least the outer wrapper key)! Any packet with incorrect HMAC signature will be discarded without response by the server. – Alex Stragies Aug 27 '15 at 20:09
55

Here is a shell one-liner:

echo -e "\x38\x01\x00\x00\x00\x00\x00\x00\x00" | 
   timeout 10 nc -u openvpnserver.com 1194 | cat -v

if there is an openvpn on the other end the output will be

@$M-^HM--LdM-t|M-^X^@^@^@^@^@@$M-^HM--LdM-t|M-^X^@^@^@^@^@@$M-^HM--LdM-t|M-^X...

otherwise it will just be mute and timeout after 10 seconds or display something different.

NOTE: this works only if tls-auth config option is not active, otherwise the server rejects messages with incorrect HMAC.

10
  • 2
    I get something bit different, but I do get something. Thanks. – artfulrobot Feb 6 '13 at 16:27
  • 9
    Just to state the obvious, this is for Linux/Unix, not for Windows. And it requires netcat (not installed by default in some distros). Also, if your Linux distro does not have the "timeout" command, just use the netcat "-w" parameter, like "nc -w 10 -u openvpnserver.com 1194". – MV. May 5 '13 at 0:48
  • 1
    I am wondering, did that work for anybody? I've tried it against a number of OpenVPN servers, but received no response. – ayaz May 29 '13 at 13:57
  • 2
    This will not work in OP scenario, if the server uses the tls-auth config option to drop packets with incorrect HMAC sig. – Alex Stragies Aug 27 '15 at 20:11
  • 3
    I find piping to od -x -N 14 rather than cat -v is much more useful because you can a) see the actual binary content rather than ASCII garbage and b) instantly receive the each line of output as the server sends each handshake packet and stop it right away after the first. -N 14 because the handshake packet is 14 bytes long and just repeats. – BaseZen Feb 5 '17 at 18:53
6

Sorry if I'm a bit late with my answer ;)
Send an udp packet with the following content:
$38$01$00$00$00$00$00$00$00
The server must respond something.
You can forge udp packets with python like this:

import socket
senddata= "\x38\x01\x00\x00\x00\x00\x00\x00\x00"

def checkserver(ip,port):
   print('Checking %s:%s' %(ip,port)) 
   sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
   sock.settimeout(5) # in seconds
   sock.connect((ip, port))
   print("Sending request...")
   sock.send(senddata)
   try:
      dta=sock.recv(100)
      print("Server reply: %s" %(dta))
   except:
      print("Server not responding")
   sock.close()
   print("###########################################################")

def main():
   checkserver("addr.of.server1",1194)
   checkserver("addr.of.server2",1195)

if __name__ == "__main__":
   main()
2
  • 1
    as loic's answer says, this doesn't work for tls-auth. – tedder42 Feb 2 '16 at 18:31
  • 1
    For Python 3 line 10 will cause an issue. Replace "sock.send(senddata)" by "sock.send(senddata.encode())" and it will work. – NDB Feb 15 '17 at 15:31
5

For anyone running across this who's trying to monitor a server that has tls-auth enabled, you can use the python script here: https://github.com/liquidat/nagios-icinga-openvpn

The output is formatted for use in Nagios or Icinga, but it can be run by anything/anyone, provided you have python and the tls keyfile available.

For example, if you are using SHA256 as your digest, you'd use something like:

python check-openvpn.py -p 1194 --tls-auth ta.key --digest SHA256 vpn-server.example.com

Note: you might need to add --tls-auth-inverse depending on the server's key-direction value.

3

You can try to run the following at the CLI

#netstat -ltnup

This should list all processes that are listening on your server/system. Grep for the port number you want

#netstat -ltnup | grep 1194
2
  • OP only has windows XP tools. – user9517 Apr 22 '11 at 13:18
  • 1
    @Iain: The OP had PuTTY, so may be able to SSH into the server. In that case, this very simple check is a useful first step. – mivk Feb 21 '19 at 18:49
0

If you can get an pcap of valid OpenVPN Client to OpenVPN server interaction, you could model the initial set of packets with something like netcat, as suggested by TiZon.

Basically, you want enough of a valid first packet to get the server to respond with at least an error message, so it doesn't have to be perfect, just good enough.

I tried going to http://pcapr.net, but I didn't see an OpenVPN example there. Perhaps, if someone else is claiming the service is up, you could get that other person to grab a pcap of the transaction.

-5

if you have setup openvpn on a tcp listen then its as simple as

telnet vpnserver 1194

assuming 1194 is the port you have it listening on

this should give you a response of some sort to show that the openvpn server is listening

2
  • Are you 100% sure? When I do this, I get "Could not open connection to the host, on port 1194: Connect failed" after some waiting. Isn't a client meant to say something first, before an OpenVPN server responds? – Ivan Apr 22 '11 at 10:02
  • 6
    Note that by default OpenVPN is UDP-only and telnet is meant to use TCP. – Ivan Apr 22 '11 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.