Ethernet over Coax Modem via HTTPMOD auslesen

Begonnen von fhemfreund, 12 März 2025, 20:36:08

Vorheriges Thema - Nächstes Thema

fhemfreund

Versuche gerade Linkspeeds meiner Gigacopper (=MaxLinear) EoC (Ethernet over Coax) Modems via HTTPMOD auszulesen.
Die Modems sind via WebPage erreichbar und durch eine Login Seite geschützt. Setze ich Verbose auf 5 bekomme ich leider im Fhem Log sehr wenig Infos:

2025.03.12 20:13:05 5: GCTest: AddToQueue adds type update to URL http://192.168.0.71, no data, no headers, retry 0, initial queue len: 0
2025.03.12 20:13:05 5: GCTest: HandleSendQueue called from AddToSendQueue, qlen = 1
2025.03.12 20:13:05 4: GCTest: HandleSendQueue sends update with timeout 2 to http://192.168.0.71, No Data, No Header
2025.03.12 20:13:05 5: GCTest: ReadCallback called from HttpUtils_NonblockingGet
2025.03.12 20:13:05 5: GCTest: Read callback Error LogLvl set to 3, regex
2025.03.12 20:13:05 3: GCTest: Read callback: Error: http://192.168.0.71: malformed or unsupported URL
2025.03.12 20:13:05 4: GCTest: Read callback: request type was update retry 0, no headers, no body
2025.03.12 20:13:05 5: GCTest: Read callback: body empty
2025.03.12 20:13:05 4: GCTest: BodyDecode is not decoding the response body (charset not found, bodyDecode defaults to none)
2025.03.12 20:13:05 5: GCTest: GetCookies is looking for Cookies
2025.03.12 20:13:05 5: GCTest: ExtractSid called, context reading, num unknown
2025.03.12 20:13:05 4: GCTest: no header to look for redirects
2025.03.12 20:13:05 5: GCTest: Read callback sets LAST_REQUEST to update
2025.03.12 20:13:05 5: GCTest: CheckAuth decided no authentication required

Habe den Traffic mal via Burp Suite mitgeschnitten:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 15467

<!--
    <legal_notice>
     MaxLinear, Inc. retains all right, title and interest (including all intellectual
     property rights) in and to this computer program, which is protected by applicable
     intellectual property laws.  Unless you have obtained a separate written license from
     MaxLinear, Inc. or an authorized licensee of MaxLinear, Inc., you are not authorized
     to utilize all or a part of this computer program for any purpose (including
     reproduction, distribution, modification, and compilation into object code), and you
     must immediately destroy or return all copies of this computer program.  If you are
     licensed by MaxLinear, Inc. or an authorized licensee of MaxLinear, Inc., your rights
     to utilize this computer program are limited by the terms of that license.
   
     This computer program contains trade secrets owned by MaxLinear, Inc. and, unless
     authorized by MaxLinear, Inc. in writing, you agree to maintain the confidentiality
     of this computer program and related information and to not disclose this computer
     program and related information to any other person or entity.
   
     Misuse of this computer program or any information contained in it may results in
     violations of applicable law.  MaxLinear, Inc. vigorously enforces its copyright,
     trade secret, patent, contractual, and other legal rights.
   
     THIS COMPUTER PROGRAM IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES, AND
      MAXLINEAR, INC.
     EXPRESSLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING THE
     WARRANTIES OF
     MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
     NONINFRINGEMENT.
   
    ***************************************************************************************
                                            Copyright (c) 2020/2022, MaxLinear, Inc.
    ***************************************************************************************
    </legal_notice>
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script language="JavaScript" src="common.js"></script>
<script language="JavaScript">
function onOKClick(form)
{
  //disable all OK buttons after clicking to avoid sending 'OK' to the web server
  //we want to POST only CFL parameters to track last error
  document.getElementById("password_config_ok").disabled = true;

  form.submit();
}
</script>
<title>G4201C Web Configuration - Authentication</title>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="Mon, 06 Jan 1990 00:00:01 GMT">
</head>
<body bgcolor="white">
<table>
<tr><td valign="top" align="center" width=120 style="border-right:4px solid #dddddd">
<a href="http://www.maxlinear.com" target="_blank" name="www.maxlinear.com"><img src="logo_mxl.gif" border=0></a>
</td>
<td>
<div style="padding:10px;font-size:18px"><p>
  <b>G4201C Web Configuration</b>
</p></div>
<script language="JavaScript">
printErrorMsg("");
</script>
<div style="padding:6px" id="login_box">
  <table width=520 style="border:3px solid #dddddd">
  <tr><td colspan=2><b>Authentication</b></td></tr>
  <tr><td colspan=2 style="background:#dddddd"></td></tr>
  <tr><td colspan=2></td></tr>
  <tr><td colspan=2><font size=-1>This unit is password protected. Please enter the correct password to access the web pages</font></td></tr>
  <tr><td colspan=2></td></tr>
  <form name="AUTH_FORM" method="POST">
  <input type="hidden" name=".CSRFTOKEN" value="">
  <input type="hidden" name=".REDIRECT" value="/">
  <tr><td>&#8226;Password</td><td align="right">
  <input type="password" size=30 maxlength=20 name=".PASSWORD" id="password_config_password" autofocus>
  </td></tr>
  <tr><td colspan=2></td></tr>
  <tr><td colspan=2 align="right">
  <input name="OK" value="Ok" type="button" id="password_config_ok" onClick="onOKClick(this.form)">&nbsp;<input name="CANCEL" value="Cancel" type="reset" id="password_config_cancel">
  </td></tr>
  </form>

  </table>
</div>
<script language="Javascript">
if('N'=='Y')
{
  var ce=(navigator.cookieEnabled)?true:false;
  //if not IE4+ nor NS6+
  if(typeof navigator.cookieEnabled=="undefined" && !ce)
  {
    document.cookie="testcookie";
    ce=(document.cookie.indexOf("testcookie")!= -1)?true:false;
  }
  if(!ce)
  {
    document.write('<div style="padding:10px;color:red"><b>This service requires a web browser that supports and accepts cookies.</b></div><div style="padding:10px;">It appears that your browser does not have cookies enabled. Please refer to your browser help for instructions on how to locate and configure your browser preferences to accept cookies. Once you have enabled cookies, reload this page.<br><br> If you are using a browser that does not support cookies, try with a different browser.</div><br><br>');
    document.getElementById("login_box").style.visibility="hidden";
    document.getElementById("login_box").style.height=0;
  }
}
</script>
</td></tr>
</table>
<script language="JavaScript">
if(top.location.href!=self.location.href)
  top.location.replace('index.html');
</script>
</body>
</html>

Es scheint so, dass das via JavaScript geschieht - hat jemand eine Idee wo/wie man da ansetzen könnte?

Andreas

tobi01001

Hi, nimm chrome, edge oder einen browser mit entwicklermodus und zeichne dort deinen Login-Prozess auf.
Da siehst du in den aufrufen den gesendeten payload inkl. evetl erforderlicher Header.

Das ist zumindest oft ein guter Startpunkt für mich.
Wenn ich das zum Beispiel für meine Heizungssteuerung (CMI von TA) mit basic-auth mache, sehe ich
GET / HTTP/1.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate
Accept-Language: de,en-US;q=0.9,en;q=0.8,fr;q=0.7
Authorization: Basic ....
Cache-Control: no-cache
Connection: keep-alive
DNT: 1
Host: 192.168.2.25
Pragma: no-cache
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Diese Header kann ich dann in httpmod eintragen - in dem Beispiel ist die "Authorization: Basic ....." insbesondere relevant.
FHEM@UbuntuServer on Lenovo ThinkCentre M900 [i5-6500T / 8GB RAM] MySQL-DbLog, Grafana, FTUI3 / HmIP incl. CCU3 / LGESS / Wärempumpe über TA CMI und CANoE / Shellies u.v.m.

passibe

Da wird es keinen header geben, weil das nicht über BasicAuth läuft, sondern über irgendein Form-Login (ggfs. mit Javascript). Allenfalls generiert dir das irgendeinen Auth-Header, der dann aber aller Wahrscheinlichkeit nach immer nur für eine Session gültig sein wird und sicherlich nicht unbegrenzt lang. Einfach rauskopieren aus Burp Suite und dann für alle Ewigkeit in HTTPMOD behalten geht also – selbst wenn es irgendeinen Auth-Header gibt – nicht.

@fhemfreund
Der richtige Weg ist aber schon, den Login-Prozess mit Burp Suite aufzuzeichnen und dann zu schauen, was da übermittelt wird. Eventuell kannst du dann das nutzen, was in der HTTPMOD-Commandref unter "Handling sessions and logging in" beschrieben ist.
Am besten du googelst auch mal "site:fhem.de httpmod javascript login" und hangelst dich von da aus weiter, es gibt schon einige Leute, die ähnliches versucht haben.

tobi01001

Da wird es keinen header geben, weil das nicht über BasicAuth läuft, sondern über irgendein Form-Login (ggfs. mit Javascript).
Trotzdem gibt es eine Kommunikation und einen (odere mehrere) Requests. Wie sollen denn die Nutzerdaten sonst vom Browser zum Modem kommen? Und eine Antwort wird es auch geben....

Kann man sicher auch mit burp suite aufzeichnen....

FHEM@UbuntuServer on Lenovo ThinkCentre M900 [i5-6500T / 8GB RAM] MySQL-DbLog, Grafana, FTUI3 / HmIP incl. CCU3 / LGESS / Wärempumpe über TA CMI und CANoE / Shellies u.v.m.

fhemfreund

Zitat von: passibe am 13 März 2025, 11:00:26...
@fhemfreund
Der richtige Weg ist aber schon, den Login-Prozess mit Burp Suite aufzuzeichnen und dann zu schauen, was da übermittelt wird. Eventuell kannst du dann das nutzen, was in der HTTPMOD-Commandref unter "Handling sessions and logging in" beschrieben ist.
Am besten du googelst auch mal "site:fhem.de httpmod javascript login" und hangelst dich von da aus weiter, es gibt schon einige Leute, die ähnliches versucht haben.

Das war tatsächlich ein guter Tipp - Danke !. Habe mal einen kompletten Login Vorgang via Burp geloggt und mir die Requests genauer angeschaut und prompt die passende POST Info zum Login gefunden. Nachdem Login bekomme ich eine SessionID mit der ich dann meine Abfrage starten kann.

Burp gibt einem sogar gleich die Curl Strings aus, sodass es dann eine einfache Task war, das ganze via Shell Script zu implementieren und die Daten zu meinem Mqtt Broker zu publishen (bin dann von HTTPMOD weg).

Andreas