mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-20 12:34:45 +02:00
4-13 C2
This commit is contained in:
parent
491769a99f
commit
4ae341b1e3
@ -56,7 +56,7 @@ void agent_sm_process_action_queue() {
|
||||
break;
|
||||
}
|
||||
else if (action_queue & ACTION_LISTEN) {
|
||||
HANDLE h, temp;
|
||||
HANDLE h;
|
||||
long prev_queue;
|
||||
struct agent_connection* con =
|
||||
(struct agent_connection*)malloc(sizeof(struct agent_connection));
|
||||
@ -64,8 +64,8 @@ void agent_sm_process_action_queue() {
|
||||
h = CreateNamedPipe(
|
||||
AGENT_PIPE_ID, // pipe name
|
||||
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, // read/write access
|
||||
PIPE_TYPE_MESSAGE | // message type pipe
|
||||
PIPE_READMODE_MESSAGE | // message-read mode
|
||||
PIPE_TYPE_BYTE | // message type pipe
|
||||
PIPE_READMODE_BYTE | // message-read mode
|
||||
PIPE_WAIT, // blocking mode
|
||||
PIPE_UNLIMITED_INSTANCES, // max. instances
|
||||
BUFSIZE, // output buffer size
|
||||
@ -78,7 +78,8 @@ void agent_sm_process_action_queue() {
|
||||
con->next = list;
|
||||
list = con;
|
||||
prev_queue = InterlockedAnd(&action_queue, ~ACTION_LISTEN);
|
||||
temp = CreateIoCompletionPort(h, ioc_port, (ULONG_PTR)con, 0);
|
||||
CreateIoCompletionPort(h, ioc_port, (ULONG_PTR)con, 0);
|
||||
ConnectNamedPipe(h, &con->ol);
|
||||
if (prev_queue == ACTION_LISTEN)
|
||||
break;
|
||||
}
|
||||
|
@ -42,21 +42,17 @@ void agent_connection_on_io(struct agent_connection* con, DWORD bytes, OVERLAPPE
|
||||
if (con->state == DONE)
|
||||
DebugBreak();
|
||||
|
||||
while (1) {
|
||||
//while (1)
|
||||
{
|
||||
switch (con->state) {
|
||||
case LISTENING:
|
||||
agent_listen();
|
||||
case WRITING:
|
||||
/* Writing is done, read next request */
|
||||
case LISTENING:
|
||||
con->state = READING_HEADER;
|
||||
if (con->state == LISTENING)
|
||||
agent_listen();
|
||||
ZeroMemory(&con->request, sizeof(con->request));
|
||||
if (ReadFile(con->connection, con->request.buf,
|
||||
HEADER_SIZE, NULL, &con->ol)) {
|
||||
bytes = HEADER_SIZE;
|
||||
continue;
|
||||
}
|
||||
if (GetLastError() != ERROR_IO_PENDING) {
|
||||
if (!ReadFile(con->connection, con->request.buf,
|
||||
HEADER_SIZE, NULL, &con->ol) && (GetLastError() != ERROR_IO_PENDING)) {
|
||||
con->state = DONE;
|
||||
agent_cleanup_connection(con);
|
||||
return;
|
||||
@ -66,25 +62,18 @@ void agent_connection_on_io(struct agent_connection* con, DWORD bytes, OVERLAPPE
|
||||
con->request.read += bytes;
|
||||
if (con->request.read == HEADER_SIZE) {
|
||||
con->request.size = *((DWORD*)con->request.buf);
|
||||
con->request.read = 0;
|
||||
con->state = READING;
|
||||
if (ReadFile(con->connection, con->request.buf,
|
||||
con->request.size, NULL, &con->ol)) {
|
||||
bytes = con->request.size;
|
||||
continue;
|
||||
}
|
||||
if (GetLastError() != ERROR_IO_PENDING) {
|
||||
if (!ReadFile(con->connection, con->request.buf,
|
||||
con->request.size, NULL, &con->ol)&&(GetLastError() != ERROR_IO_PENDING)) {
|
||||
con->state = DONE;
|
||||
agent_cleanup_connection(con);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ReadFile(con->connection, con->request.buf + con->request.read,
|
||||
HEADER_SIZE - con->request.read, NULL, &con->ol)) {
|
||||
bytes = HEADER_SIZE - con->request.read;
|
||||
continue;
|
||||
}
|
||||
if (GetLastError() != ERROR_IO_PENDING) {
|
||||
if (!ReadFile(con->connection, con->request.buf + con->request.read,
|
||||
HEADER_SIZE - con->request.read, NULL, &con->ol)&& (GetLastError() != ERROR_IO_PENDING)) {
|
||||
con->state = DONE;
|
||||
agent_cleanup_connection(con);
|
||||
return;
|
||||
@ -96,24 +85,16 @@ void agent_connection_on_io(struct agent_connection* con, DWORD bytes, OVERLAPPE
|
||||
if (con->request.read == con->request.size) {
|
||||
/* process request and get response */
|
||||
con->state = WRITING;
|
||||
if (WriteFile(con->connection, con->request.buf,
|
||||
con->request.size, NULL, &con->ol)) {
|
||||
bytes = con->request.size;
|
||||
continue;
|
||||
}
|
||||
if (GetLastError() != ERROR_IO_PENDING) {
|
||||
if (!WriteFile(con->connection, con->request.buf,
|
||||
con->request.size, NULL, &con->ol)&& (GetLastError() != ERROR_IO_PENDING) ){
|
||||
con->state = DONE;
|
||||
agent_cleanup_connection(con);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ReadFile(con->connection, con->request.buf + con->request.read,
|
||||
con->request.size - con->request.read, NULL, &con->ol)) {
|
||||
bytes = con->request.size - con->request.read;
|
||||
continue;
|
||||
}
|
||||
if (GetLastError() != ERROR_IO_PENDING) {
|
||||
if (!ReadFile(con->connection, con->request.buf + con->request.read,
|
||||
con->request.size - con->request.read, NULL, &con->ol)&& (GetLastError() != ERROR_IO_PENDING)) {
|
||||
con->state = DONE;
|
||||
agent_cleanup_connection(con);
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user