Invoke-WebRequest - получение следующего URI после входа в систему (реферер?) - PullRequest
0 голосов
/ 15 ноября 2018

Первая часть входа на устройство с локальным веб-сервером в качестве инструмента конфигурации / мониторинга была выполнена (я думал).

$r = Invoke-WebRequest -URI "http://$server" -SessionVariable sv -UseDefaultCredentials -Method Default 

$form = $r.Forms[0]
$form.Fields['user'] = 'username'
$form.Fields['pwd'] = 'pw'        #$form.Action is the right one as returned in the form
$r = Invoke-WebRequest -Uri ("http://$server" + $form.Action)  -WebSession $sv -Method $form.Method -Body $form.Fields -TimeoutSec 20

Теперь проблема; o)

Ведение журналавручную на веб-странице, приводит к другому URL-адресу с динамическим идентификатором сеанса, например:

http://$server/xyz.asp;session_id=7a7ff613d48ac87927edf66a356e90e1

В инструментах мониторинга я вижу, что новый URL возвращается и используетсябраузер, но я понятия не имею, как «поймать» новый URL для доступа к следующей странице в скрипте.Содержимое ответа на второй запрос все еще остается на странице входа в систему, поэтому я полагаю, что вход не так успешен, как говорится в возвращенном StatusCode / Description.

Любые предложения приветствуются!Спасибо и хорошего дня!


первый результат для $ r:

StatusCode        : 200
StatusDescription : Ok
Content           : <html>
                    <head>
                    <title>Login Page</title>
                    <!--[if lt IE 7.]>
                    <script defer type="text/javascript" src="/pngfix.js"></script>
                    <![endif]-->
                    <script type="text/javascript" src="/md5.js"></script>
                    <script t...
RawContent        : HTTP/1.1 200 Ok
                    Pragma: no-cache
                    Connection: close
                    Cache-Control: no-cache
                    Content-Type: text/html
                    Date: Sun, 18 Nov 2018 21:41:16 GMT
                    Expires: 0
                    Server: httpd

                    <html>
                    <head>
                    <title>Login Pag...
Forms             : {frm}
Headers           : {[Pragma, no-cache], [Connection, close], [Cache-Control, no-cache], [Content-Type, text/html]...}
Images            : {@{innerHTML=; innerText=; outerHTML=<IMG style="POSITION: absolute; Z-INDEX: -1" src="/image/pg.jpg" width="100%">; outerText=; tagName=IMG; style=POSITION: absolute; Z-INDEX: -1; 
                    src=/image/pg.jpg; width=100%}, @{innerHTML=; innerText=; outerHTML=<IMG src="/image/cisco_logo_about.png">; outerText=; tagName=IMG; src=/image/cisco_logo_about.png}, @{innerHTML=; 
                    innerText=; outerHTML=<IMG src="/image/ContextMessageArrow_DownT.gif">; outerText=; tagName=IMG; src=/image/ContextMessageArrow_DownT.gif}, @{innerHTML=; innerText=; outerHTML=<IMG 
                    id=log class=LOGINIMG style="DISPLAY: none" src="/image/login_progress.gif">; outerText=; tagName=IMG; id=log; class=LOGINIMG; style=DISPLAY: none; src=/image/login_progress.gif}}
InputFields       : {@{innerHTML=; innerText=; outerHTML=<INPUT type=hidden name=submit_button>; outerText=; tagName=INPUT; type=hidden; name=submit_button}, @{innerHTML=; innerText=; outerHTML=<INPUT 
                    type=hidden name=keep_name>; outerText=; tagName=INPUT; type=hidden; name=keep_name}, @{innerHTML=; innerText=; outerHTML=<INPUT type=hidden value=1 name=enc>; outerText=; 
                    tagName=INPUT; type=hidden; value=1; name=enc}, @{innerHTML=; innerText=; outerHTML=<INPUT type=input name=user>; outerText=; tagName=INPUT; type=input; name=user}...}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 5800

SessionVariable:

Id     : frm
Method : post
Action : /login.cgi
Fields : {[submit_button, ], [keep_name, ], [enc, 1], [user, ]...}

second Invoke:

# here I'm not sure, the "enc" field is 1 when I read it (don't know if it's read-only)
# and I also tried a secure string for "pwd" but it didn't work either
# so I tried this with "pwd" as simple string and "enc"=0
$form.Fields['user'] = '<user>'        
$form.Fields['pwd'] = '<pw>'       
$form.Fields['enc'] = '0'
$r = Invoke-WebRequest -Uri ("http://$server" + $form.Action)  -WebSession $sv -Method $form.Method -Body $form.Fields -TimeoutSec 20 -Debug

отладочный вывод:

VERBOSE: POST http://10.122.154.34/login.cgi with -1-byte payload
VERBOSE: received -1-byte response of content type text/html
# a 1-byte response doesn't look like it worked as expected, right?

второй результат для $ r:

StatusCode        : 200
StatusDescription : Ok
Content           : <html>
                    <head>
                    <title>Login Page</title>
                    <!--[if lt IE 7.]>
                    <script defer type="text/javascript" src="/pngfix.js"></script>
                    <![endif]-->
                    <script type="text/javascript" src="/md5.js"></script>
                    <script t...
RawContent        : HTTP/1.1 200 Ok
                    Pragma: no-cache
                    Connection: close
                    Cache-Control: no-cache
                    Content-Type: text/html
                    Date: Sun, 18 Nov 2018 21:43:34 GMT
                    Expires: 0
                    Server: httpd

                    <html>
                    <head>
                    <title>Login Pag...
Forms             : {frm}
Headers           : {[Pragma, no-cache], [Connection, close], [Cache-Control, no-cache], [Content-Type, text/html]...}
Images            : {@{innerHTML=; innerText=; outerHTML=<IMG style="POSITION: absolute; Z-INDEX: -1" src="/image/pg.jpg" width="100%">; outerText=; tagName=IMG; style=POSITION: absolute; Z-INDEX: -1; 
                    src=/image/pg.jpg; width=100%}, @{innerHTML=; innerText=; outerHTML=<IMG src="/image/cisco_logo_about.png">; outerText=; tagName=IMG; src=/image/cisco_logo_about.png}, @{innerHTML=; 
                    innerText=; outerHTML=<IMG src="/image/ContextMessageArrow_DownT.gif">; outerText=; tagName=IMG; src=/image/ContextMessageArrow_DownT.gif}, @{innerHTML=; innerText=; outerHTML=<IMG 
                    id=log class=LOGINIMG style="DISPLAY: none" src="/image/login_progress.gif">; outerText=; tagName=IMG; id=log; class=LOGINIMG; style=DISPLAY: none; src=/image/login_progress.gif}}
InputFields       : {@{innerHTML=; innerText=; outerHTML=<INPUT type=hidden name=submit_button>; outerText=; tagName=INPUT; type=hidden; name=submit_button}, @{innerHTML=; innerText=; outerHTML=<INPUT 
                    type=hidden name=keep_name>; outerText=; tagName=INPUT; type=hidden; name=keep_name}, @{innerHTML=; innerText=; outerHTML=<INPUT type=hidden value=1 name=enc>; outerText=; 
                    tagName=INPUT; type=hidden; value=1; name=enc}, @{innerHTML=; innerText=; outerHTML=<INPUT type=input name=user>; outerText=; tagName=INPUT; type=input; name=user}...}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 5800

тот же ответ, кроме даты ...


зашифрованная строкас помощью веб-интерфейса: 0fa58742e186c8e5ce52ba133f8714cb

1035 * зашифрованная строка из PowerShell: 01000000d08c9ddf0115d1118c7a00c04fc297eb010000004beb616727b69b4e8264e7cc798eb93d0000000002000000000003660000c0000000100000003ab6ebeb97f783cb9b5a49187ddf72600000000004800000a000000010000 0008df253a8f5995d2dc9b00e5efb7f878510000000fe9616971b02305ee332dd9c3bf6b620140000006809524b3f5eba666022bb70f1eebcea43b57e0b
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...