Saturday, March 1, 2008

Hackin Upnp


I have been doing lots of research dealing with upnp and php with the goal of making a nice little tool to control any upnp enabled device or program. I have been working on this for a while now and decided to put out some small samples of php code. This snippet will discover all devices and programs in a LAN using upnp. This snippet will only send out a discover packet, you will need to be running a packet sniffer to see the replies.



?php
$host = 'udp://239.255.255.250'; //upnp broadcast address
$port = "1900"; //upnp service address
$fp = @fsockopen($host, $port, $errno, $errstr); //socket to send out packet
//start of discover headers
$soap_out = "M-SEARCH * HTTP/1.1\r\n";
$soap_out .= "HOST: 239.255.255.250:1900\r\n";
$soap_out .= "ST: ssdp:all\r\n";
$soap_out .= "MAN: \"ssdp:discover\"\r\n";
$soap_out .= "MX: 3\r\n\r\n";
//end of discover headers
fputs($fp, $soap_out, strlen($soap_out)); // send request
fclose($fp);
?>

No comments: