![]() |
![]() |
|
June 02, 2004Secure Coding: Running Processes as a Different UserShawn has posted an interesting entry about how in Whidbey you can use the Process class to specify the user context that the new process should run under. This differs significantly from current approaches, as you normally have to P/Invoke CreateProcessWithLogonW to do it through impersonation. I've talked about different approaches before when I discussed spawning external processes securely in Windows and using restricted tokens to execute a process, but this is much more elegant. It's nice to see the Process class add new functionality through the exposure of three new properties on the ProcessStartInfo class: Domain, UserName, and Password. Here is a snippit that Shawn used (although of course you would do better input validation than that :) ): Console.Write("Username: ");
string user = Console.ReadLine(); string[] userParts = user.Split('\\'); Console.Write("Password: "); SecureString password = GetPassword(); try { ProcessStartInfo psi = new ProcessStartInfo(args[0]); psi.UseShellExecute = false; if(userParts.Length == 2) { psi.Domain = userParts[0]; psi.UserName = userParts[1]; } else { psi.UserName = userParts[0]; } psi.Password = password; Process.Start(psi); } catch(Win32Exception e) { Console.WriteLine("Error starting application"); Console.WriteLine(e.Message); } Anyways, nice find Shawn! Posted by SilverStr at June 2, 2004 04:02 PM | TrackBackComments
I wonder what the closest thing would be in the POSIX/Unix/Linux programming world. fork()? sudo/su? Posted by: Wim at June 4, 2004 07:43 PM |
![]() ![]()
My 5 Favorite Books
Writing Secure Code
Secure Programming Cookbook Security Engineering Secure Coding Principles & Practice Inside the Security Mind ![]()
My 5 Favorite Papers
Smashing the Stack
Penetration Studies Covert Channel Analysis of Trusted Systems DoD Trusted Computer System Evaluation Criteria NSA Security Recommendation Guides ![]()
Archives
June 2007
May 2007 April 2007 March 2007 February 2007 January 2007 December 2006 November 2006 October 2006 September 2006 August 2006 July 2006 June 2006 May 2006 April 2006 March 2006 February 2006 January 2006 December 2005 November 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 March 2005 February 2005 January 2005 December 2004 November 2004 October 2004 September 2004 August 2004 July 2004 June 2004 May 2004 April 2004 March 2004 February 2004 January 2004 December 2003 November 2003 October 2003 September 2003 August 2003 July 2003 June 2003 May 2003 April 2003 March 2003 February 2003 January 2003 December 2002 November 2002 October 2002 September 2002 August 2002 July 2002 ![]() |
|