drhg24275 2014-11-20 14:37
浏览 59
已采纳

PHP访问Speedport w723v

I would like to get access to my router (Speedport w723v) with a php-script.

Actually I only need the cookievalue that will be appended to the URI after a successful login, e.g.: http://speedport.ip/auth/hcti_startseite.php?cookie=SessionID_R3,BxXQc7WSbiS

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL,        "https://speedport.ip/");
curl_setopt( $ch, CURLOPT_REFERER,    "https://speedport.ip/");
curl_setopt( $ch, CURLOPT_COOKIEFILE, "SessionID.txt");
curl_setopt( $ch, CURLOPT_COOKIEJAR,  "SessionID.txt"); # SAME cookiefile.
curl_setopt( $ch, CURLOPT_POST,        1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt( $ch, CURLOPT_POSTFIELDS, "Password=PASSWORD&Username=USERNAME");
curl_setopt( $ch, CURLOPT_HEADER,      1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$getinfo = curl_getinfo($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
var_dump($data);
var_dump($getinfo);
var_dump($errno);
var_dump($error);
curl_close ($ch);  

Password and username are okay, the result thrown out by the script above looks as follows:

string(145) "HTTP/1.1 302 
CACHE-CONTROL: no-cache
Content-Type: text/html
LOCATION: https://speedport.ip/pub/msgerrcode.php?cookie=
Content-Length: 0

"
array(26) {
  ["url"]=>
  string(21) "https://speedport.ip/"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(302)
  ["header_size"]=>
  int(145)
  ["request_size"]=>
  int(187)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(20)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.53)
  ["namelookup_time"]=>
  float(0)
  ["connect_time"]=>
  float(0)
  ["pretransfer_time"]=>
  float(0.53)
  ["size_upload"]=>
  float(34)
  ["size_download"]=>
  float(0)
  ["speed_download"]=>
  float(0)
  ["speed_upload"]=>
  float(64)
  ["download_content_length"]=>
  float(0)
  ["upload_content_length"]=>
  float(34)
  ["starttransfer_time"]=>
  float(0.53)
  ["redirect_time"]=>
  float(0)
  ["redirect_url"]=>
  string(47) "https://speedport.ip/pub/msgerrcode.php?cookie="
  ["primary_ip"]=>
  string(12) "192.168.100.1"
  ["certinfo"]=>
  array(0) {
  }
  ["primary_port"]=>
  int(443)
  ["local_ip"]=>
  string(14) "192.168.100.106"
  ["local_port"]=>
  int(50900)
}
int(0)
string(0) ""

The cookiefile (SessionID.txt) remains empty; I have tried all possible paths.

I have noticed the redirect, but have no idea how to continue.

What am I doing wrong?

  • 写回答

1条回答 默认 最新

  • dongmuyan5638 2014-11-20 17:06
    关注

    The Password needs to be base64 encoded, the URI was wrong - this succeeded finally:

    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt( $ch, CURLOPT_URL,        "https://speedport.ip/index/login.cgi");
    curl_setopt( $ch, CURLOPT_REFERER,    "https://speedport.ip/index/login.cgi");
    curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
    curl_setopt( $ch, CURLOPT_COOKIEFILE, $filename);
    curl_setopt( $ch, CURLOPT_COOKIEJAR,  $filename);
    curl_setopt( $ch, CURLOPT_POST,        TRUE);
    curl_setopt( $ch, CURLOPT_POSTFIELDS, "Password=".base64_encode(PASSWORD)."&Username=admin");
    curl_setopt( $ch, CURLOPT_HEADER,      1);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $data = curl_exec( $ch);
    

    note: Username is always "admin".

    Now you can reconnect or read data like callers...

    Remember to logout again with your SessionID, otherwise you will need to wait several minutes before you can login on https://speedport.ip

    curl_setopt( $ch, CURLOPT_URL, "https://speedport.ip/auth/logout.cgi?cookie=SessionID_R3,".$sid);
    $data .= curl_exec( $ch);
    

    Hope this will help others. Haven't found anything on the internet for the W723V Type A (Huawei). BTW: Had a very (!) bad, long night with JDownloader and the malware distributed with it. Cannot recommend it anymore at all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection