25#define telnetd_printf printf
50 printf(
"Attempting to start Simple TelnetD\n");
56 ErrorExit(
"Unable to start socket interface\n");
81 WORD wVersionRequested;
85 wVersionRequested =
MAKEWORD( 2, 0 );
94 if ( wsaData.
wVersion != wVersionRequested)
95 ErrorExit(
"requested winsock version not supported\n");
116 ErrorExit(
"Cannot bind address to socket");
131 telnetd_printf(
"user connected on socket %d, port %d, address %lx\n", new_sock,
144 ErrorExit(
"failed to allocate memory for client");
146 client->socket = client_socket;
148 if (threadHandle ==
NULL)
160 char *pwdPrompt =
"\r\npass:";
175 sprintf(welcome,
"\r\nWelcome to %s, please identify yourself\r\n\r\nuser:",
hostname);
249 unsigned char client_reply[256];
251 if (
send(
sock, will_echo,
sizeof(will_echo), 0) < 0) {
265 }
else if (retval == 0) {
296 char asterisk[1] = {
'*' };
310 }
else if (retval == 0) {
340 }
else if (echo ==
Password &&
send(
sock, asterisk,
sizeof(asterisk), 0) < 0) {
380 ErrorExit(
"GetSystemDirectoryA failed\n");
389 if (!
CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0))
390 ErrorExit(
"Stdout pipe creation failed\n");
392 if (!
CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0))
393 ErrorExit(
"Stdin pipe creation failed\n");
399 client->hChildStdinWr = hChildStdinWr;
400 client->hChildStdoutRd = hChildStdoutRd;
444 if (threadHandle !=
NULL)
448 if (threadHandle !=
NULL)
452 if (threadHandle !=
NULL)
471 telnetd_printf(
"Child process terminated with code %lx\n", exitCode);
510 while (!
client->bTerminate) {
515 }
else if (iRead > 0) {
519 if (
send(
client->socket, chBuf, iRead, 0) < 0) {
569 txBuf[to] = chBuf[
from];
570 if (txBuf[to] ==
'\n') {
598 char stop[] =
"\003\r\nexit\r\n";
607 telnetd_printf(
"user shell still active, send Ctrl-Break to group-id %lu\n",
client->dwProcessId );
612 printf(
"CreateEvent error\n");
632 telnetd_printf(
"user shell still active, attempt to terminate it now...\n");
ACPI_SIZE strlen(const char *String)
char * strcpy(char *DstString, const char *SrcString)
char * strchr(const char *String, int ch)
static struct sockaddr_in sa
static VOID del(LPHIST_ENTRY item)
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES
#define ReadFile(a, b, c, d, e)
#define GetEnvironmentVariableA(x, y, z)
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
BOOL WINAPI DECLSPEC_HOTPATCH GenerateConsoleCtrlEvent(DWORD dwCtrlEvent, DWORD dwProcessGroupId)
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
VOID WINAPI ExitProcess(IN UINT uExitCode)
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
static const WCHAR Cleanup[]
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
#define sprintf(buf, format,...)
BOOL WINAPI PeekNamedPipe(HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage)
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
STRSAFEAPI StringCchCatA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
char szDescription[WSADESCRIPTION_LEN+1]
LPVOID lpSecurityDescriptor
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
void syslog(int pri, char *fmt,...)
static BOOLEAN bSocketInterfaceInitialised
static DWORD WINAPI ReadFromPipeThread(LPVOID data)
static VOID ErrorExit(LPTSTR lpszMessage)
static BOOLEAN StartSocketInterface(void)
static void UserLogin(int client_socket)
static void TerminateShell(client_t *client)
int kickoff_telnetd(void)
static DWORD WINAPI MonitorChildThread(LPVOID data)
static DWORD WINAPI UserLoginThread(LPVOID data)
static void RunShell(client_t *client)
static void CreateSocket(void)
static DWORD WINAPI WriteToPipeThread(LPVOID data)
static int ReceiveLine(int sock, char *buffer, int len, EchoMode echo)
static void WaitForConnect(void)
static int DoTelnetHandshake(int sock)
#define SUPPRESS_GO_AHEAD
#define HANDSHAKE_TIMEOUT
#define CREATE_NEW_PROCESS_GROUP
#define STARTF_USESTDHANDLES
int PASCAL FAR WSAGetLastError(void)
int PASCAL FAR WSACleanup(void)