Skip to contentSkip to conversation

patch for 2.2.2 to include --script-dir

Openvpn-devel [email protected]... 4 participants 16 messages Aug 23, 2012 – Aug 27, 2012

lore
Share & tools
lore
#0 lore raw

Hello all,

I am submitting a minor patch which includes an option to specify --script-dir. i.e. any user defined script will be run ONLY IF it is present in "script-dir".

The reason I needed this is because I had a frontend to configuration file which allowed administrator to change configuration.

I also have script-security set to 2 because I wanted to run a script when client connects.

These two option make it insecure. As admin (with bad intention or if admin password is leaked) can simply call "rm -rf /" for certain commands.

So my idea was
1) Add a new option called script-dir
2) Frontend will not allow word "script-dir" in config file (so admin cant change it)
3) script-dir will be passed on command line

This way admin can not run anything other than what I have put in script-dir. This also helps prevent accidentally run script in some other path.

Patch also fixes minor bug in init.c where warning for SSEC_PW_ENV actually would never be shown.

So please have a look at it and if acceptable then merge in source tree.

Thanks

AMM.

init.c +7 -3
@@ -2291,9 +2291,13 @@
 #endif
 
   if (script_security >= SSEC_SCRIPTS)
-    msg (M_WARN, "NOTE: the current --script-security setting may allow this configuration to call user-defined scripts");
-  else if (script_security >= SSEC_PW_ENV)
-    msg (M_WARN, "WARNING: the current --script-security setting may allow passwords to be passed to scripts via environmental variables");
+    {
+      msg (M_WARN, "NOTE: the current --script-security setting may allow this configuration to call user-defined scripts");
+      if (script_security >= SSEC_PW_ENV)
+        msg (M_WARN, "WARNING: the current --script-security setting may allow passwords to be passed to scripts via environmental variables");
+      if (script_dir == NULL)
+        msg (M_WARN, "WARNING: setting --script-dir is recommended for higher security");
+    }
   else
     msg (M_WARN, "NOTE: " PACKAGE_NAME " 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables");
 
misc.c +9 -4
@@ -45,6 +45,7 @@
 
 /* contains an SSEC_x value defined in misc.h */
 int script_security = SSEC_BUILT_IN; /* GLOBAL */
+const char *script_dir = NULL; /* GLOBAL */
 
 /* contains SM_x value defined in misc.h */
 int script_method = SM_EXECVE; /* GLOBAL */
@@ -484,10 +485,14 @@
 }
 
 bool
-openvpn_execve_allowed (const unsigned int flags)
+openvpn_execve_allowed (const char *cmd, const unsigned int flags)
 {
   if (flags & S_SCRIPT)
-    return script_security >= SSEC_SCRIPTS;
+    {
+      if (script_dir != NULL && strncmp(script_dir, cmd, strlen(script_dir)))
+	return false;
+      return script_security >= SSEC_SCRIPTS;
+    }
   else
     return script_security >= SSEC_BUILT_IN;
 }
@@ -509,11 +514,11 @@
   if (a && a->argv[0])
     {
 #if defined(ENABLE_EXECVE)
-      if (openvpn_execve_allowed (flags))
+      const char *cmd = a->argv[0];
+      if (openvpn_execve_allowed (cmd, flags))
 	{
 	  if (script_method == SM_EXECVE)
 	    {
-	      const char *cmd = a->argv[0];
 	      char *const *argv = a->argv;
 	      char *const *envp = (char *const *)make_env_array (es, true, &gc);
 	      pid_t pid;
misc.h +2 -1
@@ -133,7 +133,7 @@
 /* wrapper around the execve() call */
 int openvpn_execve (const struct argv *a, const struct env_set *es, const unsigned int flags);
 bool openvpn_execve_check (const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message);
-bool openvpn_execve_allowed (const unsigned int flags);
+bool openvpn_execve_allowed (const char *cmd, const unsigned int flags);
 int openvpn_system (const char *command, const struct env_set *es, unsigned int flags);
 
 static inline bool
@@ -353,6 +353,7 @@
 #define SSEC_SCRIPTS   2 /* allow calling of built-in programs and user-defined scripts */
 #define SSEC_PW_ENV    3 /* allow calling of built-in programs and user-defined scripts that may receive a password as an environmental variable */
 extern int script_security; /* GLOBAL */
+extern const char *script_dir; /* GLOBAL */
 
 #define SM_EXECVE 0      /* call external programs with execve() or CreateProcess() */
 #define SM_SYSTEM 1      /* call external programs with system() */
options.c +6 -0
@@ -218,6 +218,7 @@
   "                  1 -- (default) only call built-ins such as ifconfig\n"
   "                  2 -- allow calling of built-ins and scripts\n"
   "                  3 -- allow password to be passed to scripts via env\n"
+  "--script-dir dir: Only run user-defined scripts if it resides in this directory\n"
   "--shaper n      : Restrict output to peer to n bytes per second.\n"
   "--keepalive n m : Helper option for setting timeouts in server mode.  Send\n"
   "                  ping once every n seconds, restart if ping not received\n"
@@ -4748,6 +4749,11 @@
       else
 	script_method = SM_EXECVE;
     }
+  else if (streq (p[0], "script-dir") && p[1])
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      script_dir = p[1];
+    }
   else if (streq (p[0], "mssfix"))
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
win32.c +2 -2
@@ -956,7 +956,8 @@
 
   if (a && a->argv[0])
     {
-      if (openvpn_execve_allowed (flags))
+      char *cmd = a->argv[0];
+      if (openvpn_execve_allowed (cmd, flags))
 	{
 	  if (script_method == SM_EXECVE)
 	    {
@@ -965,7 +966,6 @@
 
 	      char *env = env_block (es);
 	      char *cl = cmd_line (a);
-	      char *cmd = a->argv[0];
 
 	      CLEAR (start_info);
 	      CLEAR (proc_info);
#1 lore raw

Hi

Quoted 9 lines · On Thu 23 08 2012 21:09:49 [email protected]... wrote:

So my idea was
1) Add a new option called script-dir
2) Frontend will not allow word "script-dir" in config file (so admin cant change it)
3) script-dir will be passed on command line

This way admin can not run anything other than what I have put in script-dir. This also helps prevent accidentally run script in some other path.

As this is very specific to you frontend, why doesn't your frontend simple check the path names in the config for correctness before deploying it?

Regards
Heiko

Signature · 2 lines
Heiko Hund | Sr. Software Engineer | Tel +49-721-25516-237 | Fax -200
SOPHOS NSG | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
author
#2 lore raw

Hi

Quoted 15 lines

________________________________
From: Heiko Hund <[email protected]...>
To: [email protected]; "[email protected]..." <[email protected]...>
Sent: Thursday, 23 August 2012 7:15 PM
Subject: Re: [Openvpn-devel] patch for 2.2.2 to include --script-dir

Hi

Quoted 6 lines · On Thu 23 08 2012 21:09:49 [email protected]... wrote:

So my idea was
1) Add a new option called script-dir
2) Frontend will not allow word "script-dir" in config file (so admin cant change it)
3) script-dir will be passed on command line

Quoted 6 lines
Quoted 3 lines

This way admin can not run anything other than what I have put in script-dir. This also helps prevent accidentally run script in some other path.

As this is very specific to you frontend, why doesn't your frontend simple check the path names in the config for correctness before deploying it?

Umm, I suppose this feature may be useful for other purposes. Atleast adds a level of security.

Regarding my frontend, frontend is very basic, Simple textarea in a form.
I do not want to complicate it by parsing each line, each type of config value and verifying them for correctness and secureness.

Also want it to be forward compatible, in a sense, lets say tomorrow some other config is introduced which runs some other script. Then I do not want to re-code my frontend to check for new config entry.

So best is to make OpenVPN itself secure. And run only scripts from particular directory. (script-dir)

Regards

Amm.

#3 lore raw
Quoted 22 lines · Amm Vpn
Quoted 9 lines

Hi

Quoted 6 lines · On Thu 23 08 2012 21:09:49 [email protected]... wrote:

So my idea was
1) Add a new option called script-dir
2) Frontend will not allow word "script-dir" in config file (so admin cant change it)
3) script-dir will be passed on command line

Quoted 6 lines
Quoted 3 lines

This way admin can not run anything other than what I have put in script-dir. This also helps prevent accidentally run script in some other path.

As this is very specific to you frontend, why doesn't your frontend simple check the path names in the config for correctness before deploying it?

Umm, I suppose this feature may be useful for other purposes. Atleast adds a level of security.

Regarding my frontend, frontend is very basic, Simple textarea in a form.
I do not want to complicate it by parsing each line, each type of config value and verifying them for correctness and secureness.

Quoted 5 lines

Also want it to be forward compatible, in a sense, lets say tomorrow some other config is introduced which runs some other script. Then I do not want to re-code my frontend to check for new config entry.

So best is to make OpenVPN itself secure. And run only scripts from particular directory. (script-dir)

I don't really see how this adds any security. Perhaps it makes it easier to code your front-end, but it doesn't offer anything in the way of security, since it's an option passed in the config or on the command line, it can be changed at-will by whomever runs the program.

-----
Eric F Crist

author
#4 lore raw

----- Original Message -----

Quoted 5 lines

From: Eric Crist <[email protected]...>
To: Amm Vpn <[email protected]...>
Cc: Heiko Hund <[email protected]...>; "[email protected]" <[email protected]>
Sent: Thursday, 23 August 2012 8:19 PM
Subject: Re: [Openvpn-devel] patch for 2.2.2 to include --script-dir

Quoted 8 lines
Quoted 2 lines

So best is to make OpenVPN itself secure. And run only scripts from
particular directory. (script-dir)

I don't really see how this adds any security.  Perhaps it makes it easier to code your front-end, but it doesn't offer anything in the way of security, since it's an option passed in the config or on the command line, it can be changed at-will by whomever runs the program.

Umm, same applies for script-security parameter as well. How does that add security? If person has access to config file he can change script-security level as well and then run any RANDOM command at his will.

So why was such an option added too? Please do not assume that it will be only you who would be modifying config file. In my case I have to allow access to subordinate.

My point here is script-security does not really give you TRUE security.

Script-dir makes sure that ONLY script from particular directory (say /etc/openvpn/scripts) are run. This should infact be hardcoded in openvpn at compile time. (which my patch does not do yet but instead made is config option)

Any script NOT in that directory should not be run at all.

Currently openvpn BLINDLY runs any script which in my opinion is too dangerous. One breach and intruder can simply erase your whole harddisk.

My idea of script-dir is taken from sendmail concept of smrsh.
http://www.faqs.org/docs/securing/chap22sec182.html

In my case person does not have direct access to machine. But only to config file. Now if I make sure that he cant change script-dir, it secures my whole machine.

Otherwise there is noway I can give access to config file to him without worrying about him running "rm -rf /"

Hope I am able to convey my idea. Just trying to patch a flaw in openvpn, in my opinion

Amm

#5 lore raw
Quoted 37 lines · Amm Vpn

----- Original Message -----

Quoted 6 lines

From: Eric Crist <[email protected]...>
To: Amm Vpn <[email protected]...>
Cc: Heiko Hund <[email protected]...>; "[email protected]" <[email protected]>
Sent: Thursday, 23 August 2012 8:19 PM
Subject: Re: [Openvpn-devel] patch for 2.2.2 to include --script-dir

Quoted 8 lines
Quoted 2 lines

So best is to make OpenVPN itself secure. And run only scripts from particular directory. (script-dir)

I don't really see how this adds any security. Perhaps it makes it easier to code your front-end, but it doesn't offer anything in the way of security, since it's an option passed in the config or on the command line, it can be changed at-will by whomever runs the program.

Umm, same applies for script-security parameter as well. How does that add security? If person has access to config file he can change script-security level as well and then run any RANDOM command at his will.

So why was such an option added too? Please do not assume that it will be only you who would be modifying config file. In my case I have to allow access to subordinate.

My point here is script-security does not really give you TRUE security.

Script-dir makes sure that ONLY script from particular directory (say /etc/openvpn/scripts) are run. This should infact be hardcoded in openvpn at compile time. (which my patch does not do yet but instead made is config option)

Any script NOT in that directory should not be run at all.

Currently openvpn BLINDLY runs any script which in my opinion is too dangerous. One breach and intruder can simply erase your whole harddisk.

My idea of script-dir is taken from sendmail concept of smrsh.
http://www.faqs.org/docs/securing/chap22sec182.html

Quoted 7 lines

In my case person does not have direct access to machine. But only to config file. Now if I make sure that he cant change script-dir, it secures my whole machine.

Otherwise there is noway I can give access to config file to him without worrying about him running "rm -rf /"

Hope I am able to convey my idea. Just trying to patch a flaw in openvpn, in my opinion

I still think this doesn't help anything that can't be solved in your own GUI. Simply make sure that you prepend the full path on any scripts setup from your front-end and you help your own cause. Additionally, strip any pathing from the supplied arguments. script-security was added by James before the community got heavily involved in development, so I can't say as to the real reasons for that change. I am still thinking this is an unneeded patch with too-narrow a scope.

-----
Eric F Crist

#6 lore raw
In reply to Amm Vpn

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 4 lines · Amm Vpn

Currently openvpn BLINDLY runs any script which in my opinion is too dangerous. One breach and intruder can simply erase your whole harddisk.

Agreed.

Quoted 7 lines

My idea of script-dir is taken from sendmail concept of smrsh.
http://www.faqs.org/docs/securing/chap22sec182.html

In my case person does not have direct access to machine. But only to config file. Now if I make sure that he cant change script-dir, it secures my whole machine.

Quoted 5 lines

Otherwise there is noway I can give access to config file to him without worrying about him running "rm -rf /"

Hope I am able to convey my idea. Just trying to patch a flaw in openvpn, in my opinion

But you forget one detail. OpenVPN options can be overridden by just appending an extra --script-dir at the command line, due to the nature of the option parser. Which is the same situation for
- --script-security as well. Your patch has the same flaw as
- --script-security.

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlA2TzgACgkQDC186MBRfrrWwgCeOHVUDUWVfSPVoFSSet1BlBU8 fQMAn0Pw9ia3cKkW1wXe3R65brcjHmIV
=ZBlP
-----END PGP SIGNATURE-----

#7 lore raw
In reply to [email protected]...

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 22 lines · On 23/08/12 15:09, [email protected]... wrote:

Hello all,

I am submitting a minor patch which includes an option to specify --script-dir.
i.e. any user defined script will be run ONLY IF it is present in "script-dir".

The reason I needed this is because I had a frontend to configuration file which allowed administrator to change configuration.

I also have script-security set to 2 because I wanted to run a script when client connects.

These two option make it insecure. As admin (with bad intention or if admin password is leaked) can simply call "rm -rf /" for certain commands.

So my idea was
1) Add a new option called script-dir
2) Frontend will not allow word "script-dir" in config file (so admin cant change it)
3) script-dir will be passed on command line

Quoted 3 lines

This way admin can not run anything other than what I have put in script-dir. This also helps prevent accidentally run script in some other path.

This patch will indeed do what you propose, and to some degree I can see the purpose. But this kind of sanity checks does not belong inside OpenVPN, IMO. Putting it here, is the most difficult place to put it.

There are two approaches for this kind of security. If you have a gun, you can either lock it safely inside some lockers, to avoid your kids playing with it. Or you can add an advanced trigger mechanism which checks if it's an adult holding the gun when trigger is pushed. Then let your gun float around on the floors where you find it practical, not minding your kids playing with it. The approach on your patch reminds me of the latter one. I suggest going for the former one.

Rather design your solution so that the OpenVPN executable can 100% trust the input it is given, effectively putting the responsibility for security/sanity to the front-end which starts OpenVPN.

Your patch also adds the condition that *any* front-end cannot allow "script-dir" in the configs. Which means more GUIs needs to be modified to filter out this statement from users configs, if found. This won't work out in reality.

I'm also worried about potential ways this can be abused as well. Something along where the sysadmin prepares /usr/share/openvpn/scripts as the place for all safe scripts. And somehow the user manages to replace this path with /home/mrevil/myscripts ... and then these "evil scripts" in that directory are run with elevated privileges. In this case, --script-dir would cause a false sense of security.

Also adding this as a runtime parameter is tricky, as the options parser is recursive. Lets take an example with three config files and a command line override:

....config-1.cnf......
dev tun
config config-inc.cnf
......................

....config-inc.cnf...
key client.key
cert client.crt
ca ca.crt
.....................

....config-client.cnf.....
client
remote x.x.x.x 1194
..........................

And from the command line:

 $ openvpn --config config-client.cnf \
      --remote y.y.y.y --config config-1.cnf

(of course, it's not a complete config ... but you hopefully get the idea)

And adding --script-dir in a safe way to avoid this to be abused requires a much more well thought patch than this simple approach you suggested here. From where should --script-dir be allowed, and in which order? All to avoid being overridden somehow.

To make your idea bullet-proof inside OpenVPN, --script-dir would have to be a compile time restriction, where OpenVPN is hard-coded with which directory to trust. But this won't scale well, as then each who wants this needs to compile their own OpenVPN according to their requirements.

So for me, it makes more sense to put this --script-dir feature into the GUI/front-end, where it can better do the proper sanity checks of the configs, and prepare a sanctioned openvpn command line *before* OpenVPN is started. This way it will be harder to abuse OpenVPN, if the openvpn binary is well protected.

This way we can also keep OpenVPN simpler, and still stay flexible for those who need more flexibility too. And I hope to see that we can reduce the complexity of OpenVPN even further, preferably so much that it can be configured to be started completely by an unprivileged user on all platforms and still being able to configure the network correctly. The default approach of OpenVPN currently is to depend on root/admin privileges for network configurations.

Bottom line is, I'm giving a NAK to this patch.

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlA2ThsACgkQDC186MBRfrpfAACgjBKKp5I6VByWqYutsuw6l227 698AnRb0MfO0MyAk0CPtWoMAbCPCulA9
=60wm
-----END PGP SIGNATURE-----

author
#8 lore raw

Hello all,

I am attaching a new patch which takes care of few things discussed yesterday.

Summary of patch:
1) Add new option --script-dir which restricts any user defined script to run only from specific directory

2) Backward compatible. If script-dir is not specified then it allows script from any directory.

3) Adds compile time configure option --with-script-dir=/some/path/
If this option is used then script-dir becomes hard-coded and CAN NOT be changed from config file or command line.

This allows flexibility to anyone (people like me) who wants to compile the code on their own making sure that script-dir can not be changed at all.

4) If it is not enabled at compile time then first script-dir has preference.
a) if script-dir is specified on command line, it is given the priority

b) if script-dir is specified twice (either in same config file or included config file) then only 1st occurrence is accepted and warning is logged for the rest of the occurrences.

This allows, easy binary distribution (by not hard-coding the script-dir) and then user can decide on their own script-dir.

Root user can then call OpenVPN with script-dir either on command line or inside parent config file. Parent config file can then call child config (config child.conf). And then "freely" give access to child.conf to other lower admins without worrying about them running any random script.

Even if lower admins specify script-dir, it will be ignored.

Hope that this patch now satisfy everyone in devel group and makes much more sense to be implemented.

Security in my opinion should be prime concern especially when we know that there is a way to run any random script. And hence atleast for such insecure options, sanity checks has to be there in program itself instead of trusting the frontend.

Patch is clean and simple and just about 25 lines of real code addition.

Patch eliminates danger of openvpn running any script blindly.

So please review it and consider to merge in source tree.

Thank you

AMM.

config.h.in +3 -0
@@ -468,6 +468,9 @@
 /* Path to route tool */
 #undef ROUTE_PATH
 
+/* Path to script directory */
+#undef SCRIPTDIR_PATH
+
 /* The size of `unsigned int', as computed by sizeof. */
 #undef SIZEOF_UNSIGNED_INT
 
configure +14 -0
@@ -734,6 +734,7 @@
 with_pkcs11_helper_headers
 with_pkcs11_helper_lib
 with_ifconfig_path
+with_script_dir
 with_iproute_path
 with_route_path
 with_netstat_path
@@ -1409,6 +1410,7 @@
   --with-pkcs11-helper-headers=DIR pkcs11-helper Include files location
   --with-pkcs11-helper-lib=DIR     pkcs11-helper Library location
   --with-ifconfig-path=PATH   Path to ifconfig tool
+  --with-script-dir=PATH      Path to script dir
   --with-iproute-path=PATH    Path to iproute tool
   --with-route-path=PATH  Path to route tool
   --with-netstat-path=PATH  Path to netstat tool
@@ -3400,6 +3402,18 @@
 
 
 
+# Check whether --with-script-dir was given.
+if test "${with_script_dir+set}" = set; then :
+  withval=$with_script_dir; test -n $withval &&
+cat >>confdefs.h <<_ACEOF
+#define SCRIPTDIR_PATH "$withval"
+_ACEOF
+
+
+fi
+
+
+
 # Check whether --with-iproute-path was given.
 if test "${with_iproute_path+set}" = set; then :
   withval=$with_iproute_path; IPROUTE="$withval"
configure.ac +5 -0
@@ -257,6 +257,11 @@
 )
 AC_DEFINE_UNQUOTED(IFCONFIG_PATH, "$IFCONFIG", [Path to ifconfig tool])
 
+AC_ARG_WITH(script-dir,
+   [  --with-script-dir=PATH      Path to script dir],
+   test -n $withval && AC_DEFINE_UNQUOTED(SCRIPTDIR_PATH, "$withval", [Path to script directory])
+)
+
 AC_ARG_WITH(iproute-path,
    [  --with-iproute-path=PATH    Path to iproute tool],
    [IPROUTE="$withval"],
init.c +8 -3
@@ -2291,9 +2291,14 @@
 #endif
 
   if (script_security >= SSEC_SCRIPTS)
-    msg (M_WARN, "NOTE: the current --script-security setting may allow this configuration to call user-defined scripts");
-  else if (script_security >= SSEC_PW_ENV)
-    msg (M_WARN, "WARNING: the current --script-security setting may allow passwords to be passed to scripts via environmental variables");
+    {
+      msg (M_WARN, "NOTE: the current --script-security setting may allow this configuration to call user-defined scripts");
+      if (script_security >= SSEC_PW_ENV)
+        msg (M_WARN, "WARNING: the current --script-security setting may allow passwords to be passed to scripts via environmental variables");
+      if (script_dir == NULL)
+        msg (M_WARN, "WARNING: setting --script-dir is recommended for higher security");
+      else msg (M_WARN, "NOTE: user-defined scripts will be run only from %s", script_dir);
+    }
   else
     msg (M_WARN, "NOTE: " PACKAGE_NAME " 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables");
 
misc.c +14 -4
@@ -45,6 +45,12 @@
 
 /* contains an SSEC_x value defined in misc.h */
 int script_security = SSEC_BUILT_IN; /* GLOBAL */
+#ifdef SCRIPTDIR_PATH
+const char *script_dir = SCRIPTDIR_PATH; /* GLOBAL */
+#else
+#warning use of --with-script-dir=PATH is recommended
+const char *script_dir = NULL; /* GLOBAL */
+#endif
 
 /* contains SM_x value defined in misc.h */
 int script_method = SM_EXECVE; /* GLOBAL */
@@ -484,10 +490,14 @@
 }
 
 bool
-openvpn_execve_allowed (const unsigned int flags)
+openvpn_execve_allowed (const char *cmd, const unsigned int flags)
 {
   if (flags & S_SCRIPT)
-    return script_security >= SSEC_SCRIPTS;
+    {
+      if (script_dir && script_dir[0] && strncmp(script_dir, cmd, strlen(script_dir)))
+	return false;
+      return script_security >= SSEC_SCRIPTS;
+    }
   else
     return script_security >= SSEC_BUILT_IN;
 }
@@ -509,11 +519,11 @@
   if (a && a->argv[0])
     {
 #if defined(ENABLE_EXECVE)
-      if (openvpn_execve_allowed (flags))
+      const char *cmd = a->argv[0];
+      if (openvpn_execve_allowed (cmd, flags))
 	{
 	  if (script_method == SM_EXECVE)
 	    {
-	      const char *cmd = a->argv[0];
 	      char *const *argv = a->argv;
 	      char *const *envp = (char *const *)make_env_array (es, true, &gc);
 	      pid_t pid;
misc.h +2 -1
@@ -133,7 +133,7 @@
 /* wrapper around the execve() call */
 int openvpn_execve (const struct argv *a, const struct env_set *es, const unsigned int flags);
 bool openvpn_execve_check (const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message);
-bool openvpn_execve_allowed (const unsigned int flags);
+bool openvpn_execve_allowed (const char *cmd, const unsigned int flags);
 int openvpn_system (const char *command, const struct env_set *es, unsigned int flags);
 
 static inline bool
@@ -353,6 +353,7 @@
 #define SSEC_SCRIPTS   2 /* allow calling of built-in programs and user-defined scripts */
 #define SSEC_PW_ENV    3 /* allow calling of built-in programs and user-defined scripts that may receive a password as an environmental variable */
 extern int script_security; /* GLOBAL */
+extern const char *script_dir; /* GLOBAL */
 
 #define SM_EXECVE 0      /* call external programs with execve() or CreateProcess() */
 #define SM_SYSTEM 1      /* call external programs with system() */
options.c +9 -0
@@ -218,6 +218,7 @@
   "                  1 -- (default) only call built-ins such as ifconfig\n"
   "                  2 -- allow calling of built-ins and scripts\n"
   "                  3 -- allow password to be passed to scripts via env\n"
+  "--script-dir dir: Only run user-defined script if it resides in this directory\n"
   "--shaper n      : Restrict output to peer to n bytes per second.\n"
   "--keepalive n m : Helper option for setting timeouts in server mode.  Send\n"
   "                  ping once every n seconds, restart if ping not received\n"
@@ -4748,6 +4749,14 @@
       else
 	script_method = SM_EXECVE;
     }
+  else if (streq (p[0], "script-dir") && p[1])
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      if (script_dir)
+	msg (M_WARN, "--script-dir already set, ignoring new value: %s", p[1]);
+      else
+	script_dir = p[1];
+    }
   else if (streq (p[0], "mssfix"))
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
win32.c +2 -2
@@ -956,7 +956,8 @@
 
   if (a && a->argv[0])
     {
-      if (openvpn_execve_allowed (flags))
+      char *cmd = a->argv[0];
+      if (openvpn_execve_allowed (cmd, flags))
 	{
 	  if (script_method == SM_EXECVE)
 	    {
@@ -965,7 +966,6 @@
 
 	      char *env = env_block (es);
 	      char *cl = cmd_line (a);
-	      char *cmd = a->argv[0];
 
 	      CLEAR (start_info);
 	      CLEAR (proc_info);
#9 lore raw

NAK again. This still does not belong in the core OpenVPN, IMO. If you want to have this feature, you need to enforce this in your front-end where you sanitise the config *before* OpenVPN is started. Which was my conclusion from the last time as well.

Having this as a runtime configuration does not add any restriction in reality. You must presume the user have the possibility to tweak the config somehow. And the user is fully capable of discovering a way how to execute your configs directly, skipping the --scripts-dir. So you cannot trust the client config. So the front-end must protect the OpenVPN executable so it is the only one who can start an OpenVPN connection.

Another scenario, if your front-end does not protect the OpenVPN binary, a user can also download an earlier OpenVPN and circumvent this behaviour with your own front-end. So the OpenVPN executable must be protected no matter what, and your front-end is the only thing which the user should be able to use. And then this front-end is the only one which truly can protect you, by sanitising the config *before* the OpenVPN executable is started - where your front-end is the only binary which should have access to the OpenVPN binary.

So bottom line is: This approach does not make sense to apply to the OpenVPN executable. You need to ensure the configs are trustful with a completely different approach.

kind regards,

David Sommerseth

Quoted 63 lines · Amm Vpn

Hello all,

I am attaching a new patch which takes care of few things discussed yesterday.

Summary of patch:
1) Add new option --script-dir which restricts any user defined script to run only from specific directory

2) Backward compatible. If script-dir is not specified then it allows script from any directory.

3) Adds compile time configure option --with-script-dir=/some/path/
If this option is used then script-dir becomes hard-coded and CAN NOT be changed from config file or command line.

This allows flexibility to anyone (people like me) who wants to compile the code on their own making sure that script-dir can not be changed at all.

4) If it is not enabled at compile time then first script-dir has preference.
a) if script-dir is specified on command line, it is given the priority

b) if script-dir is specified twice (either in same config file or included config file) then only 1st occurrence is accepted and warning is logged for the rest of the occurrences.

This allows, easy binary distribution (by not hard-coding the script-dir) and then user can decide on their own script-dir.

Root user can then call OpenVPN with script-dir either on command line or inside parent config file. Parent config file can then call child config (config child.conf). And then "freely" give access to child.conf to other lower admins without worrying about them running any random script.

Even if lower admins specify script-dir, it will be ignored.

Hope that this patch now satisfy everyone in devel group and makes much more sense to be implemented.

Security in my opinion should be prime concern especially when we know that there is a way to run any random script. And hence atleast for such insecure options, sanity checks has to be there in program itself instead of trusting the frontend.

Patch is clean and simple and just about 25 lines of real code addition.

Patch eliminates danger of openvpn running any script blindly.

So please review it and consider to merge in source tree.

Thank you

AMM.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

author
#10 lore raw

Hi,

First I just wanted to know if you are the decision maker for OpenVPN?

Because, the reasons/scenarios you are giving do not make sense to me. You are not at all considering the real danger (a what-if case)

(Do not take it in offensive way please)

I just wanted to make sure I am posting the patch at right place and to right person.

I am talking about two users here, one the root user who has access to system and other a plain admin who has access to config file only. This is a real world scenario in most of cases where assistant just has access to frontend and IT head has root access.

----- Original Message -----

Quoted 1 line

From: David Sommerseth <[email protected]...>

Quoted 6 lines

Having this as a runtime configuration does not add any restriction in reality.  You must presume the user have the possibility to tweak the config somehow.  And the user is fully capable of discovering a way how to execute your configs directly, skipping the --scripts-dir.  So you cannot trust the client config.  So the front-end must protect the OpenVPN executable so it is the only one who can start an OpenVPN connection.

Can you tell me how user can skip script-dir in my new patch? With example config? In my opinion I have already taken care of it, if not then I am ready to patch that as well.

Quoted 7 lines

Another scenario, if your front-end does not protect the OpenVPN binary, a user can also download an earlier OpenVPN and circumvent this behaviour with your own front-end.  So the OpenVPN executable must be protected no matter what, and your front-end is the only thing which the user should be able to use.  And then this front-end is the only one which truly can protect you, by sanitising the config *before* the OpenVPN executable is started - where your front-end is the only binary which should have access to the OpenVPN binary.

Isnt that true for any software?? That user can install unpatched binary and do whatever?? Its like saying, "Hey there is another way a thief can enter the house, so why not let all the doors open?"

And again in my case (infact in most case where root and frontend is handled by different people) this would again not be case. As frontend guy has no root access, so cant install unpatched version.

Thanks and regards,

AMM

#11 lore raw

There are a few decision makers who have sent NAKs regarding your patch. This isn't going to be considered further.

Signature · 1 line
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Amm Vpn <[email protected]...> wrote:

Hi,

First I just wanted to know if you are the decision maker for OpenVPN?

Because, the reasons/scenarios you are giving do not make sense to me. You are not at all considering the real danger (a what-if case)

(Do not take it in offensive way please)

I just wanted to make sure I am posting the patch at right place and to right person.

I am talking about two users here, one the root user who has access to system and other a plain admin who has access to config file only. This is a real world scenario in most of cases where assistant just has access to frontend and IT head has root access.

----- Original Message -----

Quoted 8 lines

From: David Sommerseth <[email protected]...>

Having this as a runtime configuration does not add any restriction in reality. You must presume the user have the possibility to tweak the config somehow. And the user is fully capable of discovering a way how to execute your configs directly, skipping the --scripts-dir. So you cannot trust the client config. So the front-end must protect the OpenVPN executable so it is the only one who can start an OpenVPN connection.

Can you tell me how user can skip script-dir in my new patch? With example config? In my opinion I have already taken care of it, if not then I am ready to patch that as well.

Quoted 7 lines

Another scenario, if your front-end does not protect the OpenVPN binary, a user can also download an earlier OpenVPN and circumvent this behaviour with your own front-end. So the OpenVPN executable must be protected no matter what, and your front-end is the only thing which the user should be able to use. And then this front-end is the only one which truly can protect you, by sanitising the config *before* the OpenVPN executable is started - where your front-end is the only binary which should have access to the OpenVPN binary.

Isnt that true for any software?? That user can install unpatched binary and do whatever?? Its like saying, "Hey there is another way a thief can enter the house, so why not let all the doors open?"

And again in my case (infact in most case where root and frontend is handled by different people) this would again not be case. As frontend guy has no root access, so cant install unpatched version.

Thanks and regards,

AMM

_____________________________________________

Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_____________________________________________

Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#12 lore raw
In reply to Amm Vpn

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 4 lines · Amm Vpn

Hi,

First I just wanted to know if you are the decision maker for OpenVPN?

I am one of more. But I'm kind of the main community gatekeeper for the public git trees. Patches go through me. But I listen to the majority of the trusted community members. Eric is one of them, Heiko is another one. But feel free to approach OpenVPN technology people directly, if you prefer that.

Quoted 5 lines

Because, the reasons/scenarios you are giving do not make sense to me. You are not at all considering the real danger (a what-if case)

(Do not take it in offensive way please)

No problem. But I thought I already did that, even though not explicitly. But from what I understand your clients are Linux or BSD based. And I still do not see your approach as useful.

a) The user can after having established a connection do a 'ps' and list all openvpn processes and it's arguments. Save this and disconnect.

b) Download it's own source code of OpenVPN, and compile it. Either on the same box (if all needed tools are needed) or another one with same libraries and copy over the new executable.

c) Modify the $PATH variable ... or try different approaches to run its own compiled OpenVPN binary with a modified configuration file (without --script-dir).

And if that doesn't work ... the user can boot the box into single-user mode, or with a rescue disk ... and forcefully replace your openvpn binary on the filesystem.

And how does --script-dir change anything in regards to security in here?

A more sane approach to avoid users from execute random scripts as root is to:

1. have openvpn somewhere on the disk where only root can access and execute the binary.

2. Save configs in a directory where only root can read/write and do not allow the user to even read these config files at all.

3. Have a "kick-off" service running, which just takes a reference to a configuration file, which can start the openvpn process with the appropriate config - and nothing more. This needs to be run with root privileges.

4. Have a front-end which the user runs completely unprivileged, which contacts the "kick-off" service with info about which config to start.

Point 3 and 4 is outside the core part of OpenVPN.

This is the only way you can be sure the configurations can't be modified by the user *except* if the user boots the box using a rescue tool or similar, where it gains root access to the file system. Then the game is lost.

Bottom line is, you need to ensure that your configuration files are to be trusted. Telling OpenVPN to bailout if one of the paths in the config file is wrong, won't add much to improve this situation. That's more an annoyance than anything else.

In general, you can't trust any clients. Security needs to be tackled on the places you fully control and where the clients have no possibility to gain root access. In the moment the user can get root access somehow, you're out of control.

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlA7SOgACgkQDC186MBRfrpX7wCfdEUvdSUtnj2svgJKE4WswAYO bnQAoJU1QyBLtC+6/4dNJDB+oX3ZHB2i
=ApYy
-----END PGP SIGNATURE-----

author
#13 lore raw

----- Original Message -----

Quoted 6 lines

From: David Sommerseth <[email protected]...>
To: Amm Vpn <[email protected]...>
Cc: "[email protected]" <[email protected]>
Sent: Monday, 27 August 2012 3:46 PM
Subject: Re: [Openvpn-devel] patch for 2.2.2 to include --script-dir

Hi,

First of all thanks for taking time out to reply.

But based on your replies, I believe you have not understood why I am proposing this patch. The cases you are talking appear completely irrelevant to my (and many other) situations.

Let me explain the situation.
1) We are evaluating OpenVPN for connecting 15-20 locations.

2) We liked it, seems quite convenient.
[SIde note: Even if you do not accept the patch we will still go ahead and patch our own copy of OpenVPN. But we believe in contributing back. We thought this is any important patch so we are proposing (but not trying to force) this patch]

3) I am the one who verifies about how secure the code is and if it insecure, then I try to patch it. If it can not be easily patched, we drop it.

4) Noone has root access to system. Noone can change anything by directly modifying the file on the system via shell.

5) There is password protected web frontend (a textarea HTML field) where select files can be directly edited by those having password.

This situation (point 4-5) will be true for many other companies as well. Where people have separate account for accessing frontend. Not just for OpenVPN but for many other daemons running. Webmin is perfect example for such a system. (Though we are not using webmin for OpenVPN)

Webmin also specifies which admin has access to what module. For now please assume that we are using system somewhat similar to webmin. But an inhouse developed system.

I hope I have explained the situations. So now lets go ahead to your reasons for not including the patch. And why I think the reasons are irrelevant.

Quoted 2 lines

a) The user can after having established a connection do a 'ps' and list all openvpn processes and it's arguments.  Save this and disconnect.

Not possible in situation I have explained.

Quoted 3 lines

b) Download it's own source code of OpenVPN, and compile it.  Either on the same box (if all needed tools are needed) or another one with same libraries and copy over the new executable.

Again not possible in situation I have explained.

Quoted 3 lines

c) Modify the $PATH variable ... or try different approaches to run its own compiled OpenVPN binary with a modified configuration file (without --script-dir).

Again not possible in situation I have explained. But you mentioned without --script-dir which indirectly means that script-dir would have made it secure.(which is why I am proposing this)

Quoted 3 lines

And if that doesn't work ... the user can boot the box into single-user mode, or with a rescue disk ... and forcefully replace your openvpn binary on the filesystem.

Again no physical access. I wonder why are you talking about this and why you have made this as base for rejecting script-dir??

With this argument, I can simply reject all the security code that has ever been written in whole world. I can even say we dont need file permissions that UNIX system gives. We dont need SELINUX and blah blah.. because user can boot the box in single user mode and do whatever?

I hope I make some sense here.

Quoted 7 lines

And how does --script-dir change anything in regards to security in here?

A more sane approach to avoid users from execute random scripts as root is to:

  1. have openvpn somewhere on the disk where only root can access and execute the binary.

Yes this is what we have.

Quoted 2 lines

  2. Save configs in a directory where only root can read/write and do not allow the user to even read these config files at all.

Yes this is what we have.

Quoted 4 lines

  3. Have a "kick-off" service running, which just takes a reference to a configuration file, which can start the openvpn process with the appropriate config - and nothing more.  This needs to be run with root privileges.

Ok ...

Quoted 3 lines

  4. Have a front-end which the user runs completely unprivileged, which contacts the "kick-off" service with info about which config to start.

Ok ...

Quoted 1 line

Point 3 and 4 is outside the core part of OpenVPN.

Agreed ...

Quoted 4 lines

Bottom line is, you need to ensure that your configuration files are to be trusted.  Telling OpenVPN to bailout if one of the paths in the config file is wrong, won't add much to improve this situation.  That's more an annoyance than anything else.

Ok now let me tell you how many things I will have to check IF I DONT patch with script-dir. (this will be true for any frontend developer not just me)

1) I will have to verify for each types of script that openvpn can run. Currently, it can be one of the following: (taken from man page) up, down, ipchange, route-up, tls-verify, auth-user-pass-verify, client-connect, client-disconnect, or learn-address.

2) Tomorrow if new type of script comes, I will have to modify frontend to check that too and then update all the machines with new frontend.

3) Other way is to write a full-fledged key-value based form (instead of textarea) where only allowed config parameters are modify-able. But then this itself will be big code and every time a modify-able item is to be added or removed, frontend needs to be changed at all sites. Like if new feature is added, I will have to enable that in frontend at all sites. If I need to remove deprecated feature I will have to delete that in front end in all locations.

There can be few other ways which I am not sure. Like I am not sure if I should check for "--cd" and "--chroot". I need to think if this can be used to bypass things in frontend. But that later.

As you can see its not easy to write a front end which considers all the cases of security. One slip in check and hostile admin can trigger "rm -rf /" on system. I would never ASSUME that my code is fool-proof.

And writing such a frontend itself will run into writing 100-125 lines of code whereas patch I submitted is just 25 lines or so and it will always be future compatible whatever new types of script is added in future.

With my idea of simple textarea HTML field, local admin himself (without needing me) can enable a feature or remove deprecated feature by simply adding/removing related line. All I have to make sure that disallow word "script-dir" in frontend. And may be few other keywords like "chroot".

My idea is to keep things simple and future compatible. Instead of thinking, re-evaluating everytime a new version of OpenVPN comes.

If you just implement "script-dir", "rm -rf /" will simply never run.

Quoted 4 lines

In general, you can't trust any clients.  Security needs to be tackled on the places you fully control and where the clients have no possibility to gain root access.  In the moment the user can get root access somehow, you're out of control.

Exactly my point security needs to be tackled on place you fully control. You think frontend is what we control. I think OpenVPN is what we control.

With my patch *no matter* what happens on frontend, even if you forget to check something else, no matter what new script-type is added. User will never be able to trigger "rm -rf /" because its been controlled right at OpenVPN level.

So please give a thought again.

Thanks,

AMM.

#14 lore raw
Quoted 4 lines · Amm Vpn

With my idea of simple textarea HTML field, local admin himself (without needing me) can enable a feature or remove deprecated feature by simply adding/removing related line. All I have to make sure that disallow word "script-dir" in frontend. And may be few other keywords like "chroot".

All of this can be solved with sed. No need for an OpenVPN patch that simply makes your life a little easier. This hasn't been requested by 'many' users, like you claim. It's only been requested by you.

-----
Eric F Crist

author
#15 lore raw

----- Original Message -----

Quoted 5 lines

From: Eric Crist <[email protected]...>

All of this can be solved with sed.  No need for an OpenVPN patch that simply makes your life a little easier.  This hasn't been requested by 'many' users, like you claim.  It's only been requested by you.

Ok. No issues. However, I dont think sed solves this.

AMM