Can I run a one-shot telnetd without login prompt?

0

In other words, I want something like telnetd that I start from my shell to bind to a specific IP and serve one connection. I do not want a login prompt.

Basically I want another machine to execute a few commands on this machine. It is directly connected, so i don't want any passwords or encryption. Besides, it doesn't have a keyboard or SSH installed.

Pepijn

Posted 2012-10-08T11:24:40.133

Reputation: 505

Answers

2

I developed a desire to do this same thing some number of years ago. I use Cygwin on Windows a lot, and being able to open simple single-shot telnet windows can be nice.

I have not found any way to do this out-of-the-box. Eventually, I copied the TELNETD source, and hacked a few key parts. It doesn't do login, and only accepts one connection.

This does require you to mess with GCC. I've only done this in cygwin, but it should work in linux, also. See the source DIFFs here:

DIFF for telnetd.c

83a84
> int be_promiscuous = 0;
133c134
< int debug = 0;
---
> int debug = 1;
145c146
<       'd', ':', 'h', 'k', 'n', 'S', ':', 'u', ':', 'U',
---
>       ':', 'h', 'k', 'n', 'S', ':', 'u', ':', 'U',
169a171
>       'g',
239c241
<               case 'd':
---
> /*            case 'd':
245,246c247,248
<                       /* NOTREACHED */
<                       break;
---
>                       /* NOTREACHED * /
>                       break; */
340a343,345
>               case 'g':
>                       be_promiscuous = 1;
>                       break;
395c400
<           if (argc > 1) {
---
>           if (argc != 1) {
417a423
>           if (!be_promiscuous) inet_aton("127.0.0.1",&sin.sin_addr);
546c552
<       fprintf(stderr, "Usage: telnetd");
---
>       fprintf(stderr, "Usage: telnetdeasy");
553c559,560
<       fprintf(stderr, " [-debug]");
---
> /*    fprintf(stderr, " [-debug]"); */
>       fprintf(stderr, " [-g]");
585c592
<       fprintf(stderr, " [port]\n");
---
>       fprintf(stderr, " port\n");
832c839
<        *      set ttyp line security label
---
>        *      set ttyp line security label
1177c1184
<       if (hostinfo && *IM)
---
>       if (*IM)
1447c1454
<
---
>
1523c1530
<                       ixon = tp->c_iflag & IXON;
---
>                       ixon = tp->c_iflag & IXON;

DIFF for sys_term.c

42a43,46
> #include <pwd.h>
>
> extern void
>       start_shell P((char *, int, char *));
1127c1131
<       if (ioctl(t, I_PUSH, "ptem") < 0)
---
>       if (ioctl(t, I_PUSH, "ptem") < 0)
1451c1455,1456
<               start_login(host, autologin, autoname);
---
>               start_shell(host, autologin, autoname);
>               /*start_login(host, autologin, autoname);*/
1560a1566,1614
>  * start_shell(host, autologin, name)
>  *
>  * Assuming that we are now running as a child processes, this
>  * function will turn us into the login process.
>  */
>       void
> start_shell(host, autologin, name)
>       char *host;
>       int autologin;
>       char *name;
> {
>       char *cp, *st, *ar;
>       char **argv;
>       char **addarg();
>       extern char *getenv();
>       struct passwd * uinfo = getpwuid(geteuid());
>
>       cp = uinfo ? uinfo->pw_shell : NULL;
>       if (!cp || !strlen(cp)) cp = "/bin/sh";
>       st = strrchr(cp,'/'); st = st ? st+1 : 0;
>       if (!st || !strlen(st)) st = "sh";
>
>       strcpy( ar = (char*)malloc(strlen(st)+2), "-");
>       strcat(ar,st);
>
>       argv = addarg(0, ar);
>
>       unsetenv("IFS");
>
>       closelog();
>
>       /*
>        * This sleep(1) is in here so that telnetd can
>        * finish up with the tty.  There's a race condition
>        * the login banner message gets lost...
>        */
>       sleep(1);
>
>       execv(cp, argv);
>
>       syslog(LOG_ERR, "%s: %m\n", cp);
>       fatalperror(net, cp);
>       /*NOTREACHED*/
> }
>
>
>
>
> /*
1669c1723
<       } else
---
>       } else
2243c2297
<
---
>

This only works with IPv4 networks, I think. I deleted the "-d" option, and added a "-g" option. This hack of telnetd takes a single numeric argument, which is the listening port. Without the "-g" argument, it binds to 127.0.0.1, otherwise it binds globally.

William

Posted 2012-10-08T11:24:40.133

Reputation: 731

0

Under MacOS you can run

/usr/libexec/telnetd -debug -U 10023

This will give you a one time session on port 10023, albeit with login. According to the manpage there is supposed to be an -a parameter for credentials (providing -a none), but this does not seem to work here, although it may working on Linux (you didn't specify which OS you are using).

collaborator

Posted 2012-10-08T11:24:40.133

Reputation: 216