From: Ed A. <er...@uc...> - 2003-04-10 21:21:56
|
I'm looking for someone who knows the internals of Expect.pm well enough to tell me if there is a mod I can make which will cause the following program to work. The environment is: solaris-9, Expect-1.15, IO-Stty-.02, IO-Tty-1.02, perl-5.6.0. The following program forks /bin/su and feeds it a password in the hopes of getting a shell with the permissions of another user, in this case user "test". No, this isn't what I really want to do; the application I need this for is a challenge-response thing. I cut the c-r code down to the simpler example below, which reproduces the problem. The problem is that the /bin/sh exec-ed by /bin/su dies almost immediately, as evidenced by control exiting from interact() immediately. I can see the '$ ' prompt from sh, but that's about it. In the debug output, I see an "Attempting interconnection" followed by setting of tty modes on fd 4, and then an immediate close of fd 4 & 5. I tried fooling around with IO::Stty to try to set the tty modes back to cooked, but that didn't help. Perhaps su does something horrible with file descriptors? The petulant code is: #!/local/s/perl-5.6.0/bin/perl use Expect; use IO::Stty; $ENV{PATH} = "/bin"; $ENV{SHELL} = "/bin/sh"; my $user = "test"; my $passwd = "pop,eye"; my $exp = new Expect(); #$exp->manual_stty(1); #$ostty = IO::Stty::stty(\*STDIN,'-g'); $exp->slave->clone_winsize_from(\*STDIN); $exp->log_stdout(0); $exp->exp_internal(0); $Expect::Debug = 1; #$exp->raw_pty(1); # don't go there $exp->spawn("/bin/su",$user); $expstr = "Password: "; $exp->expect(4,$expstr); $got = $exp->exp_match(); print "$expstr TILT!\n" if $got ne $expstr; $exp->send("$passwd\n"); $expstr = "\$ "; $exp->expect(4,$expstr); $got = $exp->exp_match(); print "$expstr TILT!\n" if $got ne $expstr; print "$expstr"; # print sh prompt and interact $exp->interact(); |