update netcat 1.11 to netcat 1.12
//nc -lp port (remote )
//nc ip port -e cmd.exe (local)
//after ctrl+c cmd.exe no exit,socket no shutdown,remote's nc no exit!
//it is a bug!so write netcat 1.12.
//only modify doexec.c by
chengh...@gmail.com
BOOL ConsoleHandler(DWORD CEvent)
{
switch(CEvent)
{
case CTRL_C_EVENT:
TerminateProcess(Session->ProcessHandle,0);
return(TRUE);
break;
case CTRL_BREAK_EVENT:
TerminateProcess(Session->ProcessHandle,0);
return(TRUE);
break;
case CTRL_CLOSE_EVENT:
TerminateProcess(Session->ProcessHandle,0);
return(TRUE);
break;
case CTRL_LOGOFF_EVENT:
TerminateProcess(Session->ProcessHandle,0);
return(TRUE);
break;
case CTRL_SHUTDOWN_EVENT:
TerminateProcess(Session->ProcessHandle,0);
return(TRUE);
break;
}
return TRUE;
}
// **********************************************************************
//
// StartShell
//
// Execs the shell with the specified handle as stdin, stdout/err
//
// Returns process handle or NULL on failure
//
static HANDLE
StartShell(
HANDLE ShellStdinPipeHandle,
HANDLE ShellStdoutPipeHandle
)
{
PROCESS_INFORMATION ProcessInformation;
STARTUPINFO si;
HANDLE ProcessHandle = NULL;
//
// Initialize process startup info
//
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpTitle = NULL;
si.lpDesktop = NULL;
si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
si.wShowWindow = SW_HIDE;
si.lpReserved2 = NULL;
si.cbReserved2 = 0;
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.hStdInput = ShellStdinPipeHandle;
si.hStdOutput = ShellStdoutPipeHandle;
DuplicateHandle(GetCurrentProcess(), ShellStdoutPipeHandle,
GetCurrentProcess(), &si.hStdError,
DUPLICATE_SAME_ACCESS, TRUE, 0);
//no matter if (CreateProcess(NULL, pr00gie, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP, NULL, NULL,
if (CreateProcess(NULL, pr00gie, NULL, NULL, TRUE, 0, NULL, NULL,
&si, &ProcessInformation))
{
//nc -lp port (remote )
//nc ip port -e cmd.exe (local)
//after ctrl+c cmd.exe no exit,socket no shutdown,remote's nc no exit!
//it is a bug!so write netcat 1.12.
//only modify doexec.c by
chengh...@gmail.com
if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler,TRUE)==FALSE)
{
// unable to install handler
// display message to the user
printf("Unable to install handler!\n");
return NULL;
}
ProcessHandle = ProcessInformation.hProcess;
CloseHandle(ProcessInformation.hThread);
}
else
holler("Failed to execute shell, error = %s",
itoa(GetLastError(), smbuff, 10), NULL, NULL, NULL, NULL, NULL);
return(ProcessHandle);
}