note 40118 deleted from function.fsockopen by mazzanet
| From: | mazzanet@php.net | Date: | Mon, 04 Jul 2005 10:30:44 +0000 |
| Subject: | note 40118 deleted from function.fsockopen by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-91409@lists.php.net to get a copy of this message | ||
Note Submitter: BIG_Nicky at clansnet dot de
----
And here is some working code for a normal Telnet connection:
<?
# 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