Page 1 of 1

PHP tunnel for Telnet

Posted: Thu May 20, 2004 1:21 pm
by SonicComKid
Hi,

I'm completely new to PHP, and only have the know-how of basic HTML to work with right now so far.

I have been searching all over the internet with no luck for what I'm looking for in PHP. What I'm trying to do is get a PHP web page on my server that will act as a tunnel to use Telnet. I found that http://www.ftp2net.com uses PHP as a tunnel to use FTP, and I'm hopeing to find some PHP webpage that will tunnel to use Telnet.

The telnet server and the http server are both being run on my server, but I need some kind of PHP web page to do a localhost HTTP tunnel to use get to my telnet server.

Does anyone know where I can get a PHP(http) tunnel to get to my Telnet server, similar to the way net2ftp works for PHP(http) to FTP?

Please help.

Is this what you want?

Posted: Fri May 21, 2004 9:36 am
by jimbodebnetwork
Here's an example of a telnet connection via php. I'm quoting it off the comments section for the fsockopen() documentation on php.net as contributed by BIG_Nicky at clansnet dot de.


And here is some working code for a normal Telnet connection:

Code: Select all

<?
# This is the difficult part, the Telnet header
$header1=chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).
chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).
chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).chr(0xFF).chr(0xFB).
chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).
chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).
chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).chr(0xFF).
chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).
chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).
chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).
chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).
chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).
chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0);
$header2=chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).
chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21);

# connecting
$fp=pfsockopen("127.0.0.1",23);

# sending the Telnet header
fputs($fp,$header1);
sleep(1);
fputs($fp,$header2);
sleep(1);

# login
fputs($fp,"user\r");
sleep(1);
fputs($fp,"users.pass\r");
sleep(1);
# root looks nice
fputs($fp,"su\r");
sleep(1); # takes some time, we had to wait
fputs($fp,"root.pass\r");

# some tests
fputs($fp,"ifconfig\r");        
fputs($fp,"echo year telnet php connect works|wall\r");

# we had to wait
sleep(1);

# show the output
#while (!feof($fp)) {
#$output = fgets($fp, 128)."<BR>\n";
#}
$output=fread($fp,128);
$stat=socket_get_status($fp);
$output.=fread($fp, $stat["unread_bytes"]);

# Uncomment these 3 lines to cut out the first line
#$output = explode("\n", $output);
#unset($output['0']); 
#$output = implode("\n", $output);

$output = str_replace("\n", "<br>", $output);
echo $output;
fclose($fp);
?>
The header part is the difficult thing, this is testet on win and linux, its working fine, you can also use usleep on your linux system, and a work around function on win systems instead of sleep, if you want to speed up you script. I hope I could help you! And sorry for my bad English


It's not a full-blown web interface for telnet sessions. But, it may be useful as a foundation to build one.

Jimbo

Posted: Fri May 21, 2004 11:50 am
by launchcode
Or you could use Curl and let it do all of that for you :)

Posted: Fri May 21, 2004 7:06 pm
by SonicComKid
Whats Curl?, and I'll need the Telnet to act as a tunnel. So that my server gets and forwards information back and forth from the server that I want to connect to useing the telnet, and also have the telnet interfact completely http based. The computes I'm trying to use telnet on are extreamly limited, locked for quite a few things and a http-only proxy.

Posted: Fri May 21, 2004 7:17 pm
by feyd
[php_man]curl[/php_man]

Posted: Fri May 21, 2004 7:31 pm
by SonicComKid
oohh boy.... this is definetly over my head. Basic HTML, and Simple Visual Basic I can do, but I can't even find a start on understanding PHP to make a telnet tunnel.