8

Asp.Net Web アプリケーションから実行PSExecしてリモート サーバーに接続しようとしています。どういうわけか"Access Denied Error -5"、資格情報が設定されていない状態で提供され、PSEXECコマンドで資格情報を設定することで "2250 Network connection could not be found". 私はサーバーの管理者であり、Windows authentication and Asp.Net Impersonation有効にしています ( IIS7.5)。さらに興味深いことに、これを aconsole applicationまたは a から実行しようとすると、 を使用するcommand promptだけで正常に動作します。テストとして ping 操作のみを実行しようとしています。

これが私のコードスニペットです:-

            var startInfo = new ProcessStartInfo{
                CreateNoWindow = true,
                UseShellExecute = false,
                FileName = FilePath,
                Arguments = CommandArgs
            }

            Process vsCommandProcess = Process.Start(startInfo);

            vsCommandProcess.WaitForExit();
            var exitCode = vsCommandProcess.ExitCode;
            if (vsCommandProcess.ExitCode != 0)
            {
                ...rest of the code

ここ:-

FilePath --> C:\pstools\psexec.exe
Arguments --> \\servername -accepteula -u domain\userName -p password ipconfig (1)
               \\servername -accepteula ipconfig (2)         

(1) Gives Error 2250 (2) gives Error 5

コンソール アプリケーションでも同じコマンドとコードが機能します。だから私は間違いなくマシンにリモートへの資格情報を引き継ぐことができないAsp.netアプリケーションと関係があると信じています。私はイベントを試みstartInfo.LoadUserProfileましたが、役に立ちませんでした。

あなたの助けに感謝。同様の質問を探してみましたが、直面している問題の解決策が見つかりませんでした。

4

1 に答える 1

2

プロセスを除外することを検討してくださいpsexec。WMI に直接アクセスすると、何が問題なのかについてより多くの洞察が得られる場合があります。

var connOpts = new ConnectionOptions()
{
// Optional, default is to use current identity
    Username = "username",
    Password = "password"
};

// create a handle to the Win32_Process object on the remote computer
ManagementScope mgmtScope = new ManagementScope(@"\\servername\root\cimv2", connOpts);
ManagementClass w32Process = new ManagementClass(mgmtScope, 
    new ManagementPath("Win32_Process"), new ObjectGetOptions());

// create the process itself
object[] createArgs = new object[] {
    // [in]   string CommandLine,
    "notepad.exe", 
    // [in]   string CurrentDirectory,
    null, 
    // [in]   Win32_ProcessStartup ProcessStartupInformation,
    null, 
    // [out]  uint32 ProcessId
    0};

var result = (int)w32Process.InvokeMethod("Create", createArgs);

switch (result)
{
    case 0: /* no-op, successful start */ break;
    case 2: throw new Exception("Access Denied");
    case 3: throw new Exception("Insufficient Privilege");
    case 8: throw new Exception("Unknown failure");
    case 9: throw new Exception("Path not found");
    case 21: throw new InvalidOperationException("Invalid Parameter");
}

それでも偽装の問題が発生する場合は、コンテンツをダンプしてHttpContext.Current.User.IdentityIIS が正しく構成されていることを確認すると役立つ場合があります。さらに、(Negotiate/SPNEGO を介して) Kerberos を使用している場合は、マシンが ID を委任できるようにする必要がある場合があります。マシンが接続する SPN がわかっている場合は、制約付きの委任を使用できますが、多くの場合、ターゲットが事前にわからない場合は、制約のない委任を許可する必要があります。


注: ipconfig を実行するためだけにコンピューターにリモート接続している場合は、WMI を介して同じ情報を取得できSTDOUTます。呼び出し元のコンピューターに出力を戻そうとする必要はありません。Win32_NetworkAdapterConfigurationクラスを見てください。

于 2013-07-04T02:12:04.180 に答える