Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 8th, 2009, 08:29 AM
Registered User
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to executed extended stored procedures as non-sysadmin users????

Hi All,

I have a scenario related to SQL 2005 Security, I have created database "db1" as "sa" user.

Steps followed

1.Created a "dummy" login
2.Created a "dummy" user,mapped to "dummy" login for "db1" database and made database owner.
3.logged in as "dummy" login and created a stored procedure which contains EXEC xp_cmdshell

Statement and while executing the stored procedure, it is throwing below error.

Msg 15153, Level 16, State 1, Procedure xp_cmdshell, Line 1
The xp_cmdshell proxy account information cannot be retrieved or is invalid. Verify that the '##xp_cmdshell_proxy_account##' credential exists and contains valid information.


4. Next, what i done is, i have turned on xp_cmdshell feature and
created a proxy account using Windows Authentication Account.
5. I Again tried to connect to "dummy" login and tried to execute the stored procedure and now it worked.

Now my Question is, what does the below statement do.
EXEC sp_xp_cmdshell_proxy_account 'domain\username', 'domain_user_password'

What affect is there if i created this new account. I know this would create a Proxy Credential but i am wondering how would the "dummy" user can able to utilize this Proxy Account internally because externally/explicitly am not giving/executing any command to make use of this newly created proxy account.

Can anyone please elaborate on how internally this Proxy Account is able to be utilized by the user "dummy" when he is getting logged in.

Am just curious about what is happening internally?

In other words, just want to know how this proxy account is made available to "dummy" user when he is getting logged in.


Commands Used to replicate the scenario.

Step1 : Create the database as "sa" user

use master
go
CREATE DATABASE db1
go

Step2 : Create a login
-- create a login "dummy" as "sa" user
USE [master]
GO
CREATE LOGIN [dummy] WITH PASSWORD=N'dummy', DEFAULT_DATABASE=[db1], CHECK_EXPIRATION=OFF,

CHECK_POLICY=OFF
GO

Step3 : Create a User in "DB1" database and make him database owner.
USE [db1]
GO
CREATE USER [dummy] FOR LOGIN [dummy]
GO
USE [db1]
GO
EXEC sp_addrolemember N'db_owner', N'dummy'
GO

Step4 : login as "dummy" and create a stored procedure which uses xp_cmdshell and when you try to

execute the stored procedure.

It will throw an error.


CREATE PROC USP_TEST
AS
BEGIN
DECLARE @STR VARCHAR(100)
SET @STR = 'GUEST'
PRINT @STR

EXEC sys.xp_cmdshell 'dir c:\*.*'

END

EXEC USP_TEST
/*
GUEST
Msg 15153, Level 16, State 1, Procedure xp_cmdshell, Line 1
The xp_cmdshell proxy account information cannot be retrieved or is invalid. Verify that the

'##xp_cmdshell_proxy_account##' credential exists and contains valid information.

*/

Step5 : Enable the xp_cmdshell feature as "sa" user


EXECUTE sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GO
EXECUTE sp_configure 'xp_cmdshell', '1'
RECONFIGURE WITH OVERRIDE
GO
EXECUTE sp_configure 'show advanced options', 0
RECONFIGURE WITH OVERRIDE
GO

EXEC sys.xp_cmdshell 'dir c:\*.*'



Step6 : Now login as Windows Authentication user and try to create a
proxy account


EXEC sp_xp_cmdshell_proxy_account 'GSPSTRAIL\Administrator', 'mychlocallogin'


Step7: login "dummy" user and again try to execute the stored procedure.
EXEC USP_TEST

Step8: To drop the proxy account, execute the below peice of code.
/*
-- To drop a Proxy Account
-- login as Windows Authentication and execute the below command
/*
EXEC sp_xp_cmdshell_proxy_account NULL
*/


Thanks in Advance.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Extended Stored Procedure. a_boumerhi SQL Server 2000 1 June 4th, 2008 09:23 PM
Stored Procedures help psnow1985 SQL Server 2005 2 April 12th, 2008 01:31 AM
Blocking sysadmin role users...is it possible? Bhalchandra SQL Server 2000 1 November 28th, 2007 06:27 PM
STORED PROCEDURES shazia1 SQL Server ASP 7 September 26th, 2007 06:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.