xp_cmdshell confused

I am trying to execute a file, tried both a .bat file that kicks off the .exe and the .exe file that I want to run.  I don't get an error, the results tab gives me a 1 and null and the messages tab says one row affected.  But the file is never executed.  I can do a directory   of the c:\c folder, and create directories in that folder using xp_cmdshell so security on the folder should be ok.  But the file is never executed.  The executable writes a log file that is how I know it doesn't execute.  Any ideas?

DECLARE @rc AS INT
DECLARE @sqlcmd AS VARCHAR(100)

SET @sqlcmd = 'c:\c\7.bat'
EXEC @rc = master.dbo.xp_cmdshell @sqlcmd
go

Open in new window


Thanks

Dan
DanDWolffAsked:
Who is Participating?
 
Bill BachConnect With a Mentor PresidentCommented:
Are you sure that it doesn't run?  Remember that this process will not be running in your native user context.  As a result, the log file may be in a completely different location that where you expect, or it may lack the rights to write the log file to the location you wanted.

First, verify that the log file is being written to a specific directory, not the CWD.  Second, make sure that "Everyone" has write access to that folder.
0
 
DanDWolffAuthor Commented:
Thanks for the quick response.  I double checked and Everyone has modify rights to the folder.  I did a search of my entire computer for the log file and search didn't find any copies.

I added a print command to the @RC variable after the exec command it it returns the following code in the messages tab -1066598274.  I would have expected a 1 or 0.  Going to try looking that up.

DECLARE @rc AS INT
DECLARE @sqlcmd AS VARCHAR(100)

SET @sqlcmd = 'c:\c\7.bat'
EXEC @rc = master.dbo.xp_cmdshell @sqlcmd
PRINT @RC
go

Open in new window

0
 
Scott PletcherSenior DBACommented:
The .bat file cannot be interactive in any way; that is, it cannot ask qs or for any input from the caller.  You can only call code that can run directly from the command line input, not requiring any direct user input at all.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
DanDWolffAuthor Commented:
The .bat file is very basic it calls a .exe and passes a commandline argument to it.

@echo off
cd \
cd c
c:\c\ssmgr.exe -fid 4

Open in new window


ssmgr.exe doesn't have anything output the the screen either.  Presently all it does it read an sql database using the commandline and output a text file based on what it reads in the database.  Both the bat file and exe run from command prompt like they should.
0
 
DanDWolffAuthor Commented:
it is something with my security on the folder I am trying to run the executable from.  If I move everything to the root c:\  it works just like it is supposed to.  The security on the folder that I am trying to run it from is as follows:

Everyone - modify
authenticated users - modify
system - full
domain\computername$ - modify
administrators - full
user - full - trying anything at this point but this is not an option for me when I move this to production.

Any ideas what I am missing?

Thanks

Dan
0
 
DanDWolffAuthor Commented:
I feel dumb, I forgot the sp_xp_cmdshell_proxy_account.  I gave that account access to the folder and all is well.

Thanks to everybody that looked at this for me.

Dan
0
 
DanDWolffAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for DanDWolff's comment #a38419067

for the following reason:

I figured out what I missed on my own before the experts did.
0
 
Bill BachPresidentCommented:
it may lack the rights to write the log file to the location you wanted.
Wasn't this the crux of my first answer???
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.