From 9c90948102261b4aeac1aaea4d39e3b51f1fd480 Mon Sep 17 00:00:00 2001 From: manojampalam Date: Sun, 17 Apr 2016 19:35:50 -0700 Subject: [PATCH] 4-17 C2 --- authfd.c | 15 ++++++++++++++- ssh-add.c | 5 ----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/authfd.c b/authfd.c index d294560..ee27ec1 100644 --- a/authfd.c +++ b/authfd.c @@ -95,6 +95,15 @@ ssh_get_authentication_socket(int *fdp) *fdp = -1; #ifdef WIN32_FIXME +#define SSH_AGENT_ROOT "SYSTEM\\CurrentControlSet\\Control\\SSH\\agent" + HKEY agent_root = 0; + DWORD agent_pid = 0, tmp_size = 4, pipe_server_pid = 0xff; + RegOpenKeyEx(HKEY_LOCAL_MACHINE, SSH_AGENT_ROOT, 0, KEY_QUERY_VALUE, &agent_root); + if (agent_root) { + RegQueryValueEx(agent_root, "ProcessId", 0, NULL, &agent_pid, &tmp_size); + RegCloseKey(agent_root); + } + HANDLE h = CreateFile( "\\\\.\\pipe\\ssh-agent", // pipe name GENERIC_READ | // read and write access @@ -105,10 +114,14 @@ ssh_get_authentication_socket(int *fdp) FILE_FLAG_OVERLAPPED, // attributes NULL); // no template file if (h == INVALID_HANDLE_VALUE) { - debug("cannot open auth socket\n"); return SSH_ERR_AGENT_NOT_PRESENT; } + if (!GetNamedPipeServerProcessId(h, &pipe_server_pid) || (agent_pid != pipe_server_pid)) { + return SSH_ERR_AGENT_COMMUNICATION; + + } + sock = w32_allocate_fd_for_handle(h, FALSE); #else diff --git a/ssh-add.c b/ssh-add.c index f9f8287..1a17901 100644 --- a/ssh-add.c +++ b/ssh-add.c @@ -518,11 +518,6 @@ main(int argc, char **argv) fprintf(stderr, "Could not open a connection to your " "authentication agent.\n"); exit(2); - #ifdef WIN32_FIXME - case SSH_ERR_SYSTEM_ERROR: - fprintf(stderr, "Error connecting to agent: ssh-agent.exe may not be running\n"); - exit(2); - #endif default: fprintf(stderr, "Error connecting to agent: %s\n", ssh_err(r)); exit(2);