我的PS1文件刚刚在IE中启动一个网站。由于此网站的安全提示,我无法导航到该URL。我需要绕过此提示,并且我的解决方法不起作用。我认为我可能会通过sslbypass选择更多信息。有别的旁路方法吗?
"Starting Internet Explorer in Background"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$uri = 'https://soti10app1/MobiControl/WebConsole/'
$ie.navigate("$uri")
while($ie.ReadyState -ne 4) {start-sleep -m 100};
if ($ie.document.url -Match "invalidcert")
{
"Bypassing SSL Certificate Error Page";
#$sslbypass=$ie.Document.getElementsByTagName("a") | ?{$_.href -match "javascript:expandCollapse('infoBlockID', true);"}
#$sslbypass.click();
$sslbypass=$ie.Document.getElementsByTagName("a") | where-object {$_.id -eq "overridelink"};
$sslbypass.click();
"sleep for 5 seconds while final page loads";
start-sleep -s 5;
};
if ($ie.Document.domain -Match "soti10app1", "soti10app2", "soti10app3")
{
"Successfully Bypassed SSL Error";
}
else
{
"Bypass failed";
}
get-process iexplore | stop-process
运行脚本时加载的页面。
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="newErrorPageTemplate.css">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This site isn’t secure</title>
<script src="invalidcert.js" language="javascript" type="text/javascript">
</script>
<script src="errorPageStrings.js" language="javascript" type="text/javascript">
</script>
<script src="httpErrorPagesScripts.js" language="javascript" type="text/javascript">
</script>
</head>
<body onLoad="BodyLoad(); initMoreInfo('infoBlockID');">
<div id="contentContainer" class="mainContent">
<div id="invalidcert_mainTitle" class="title" style="color: #a90000;">This site is not secure</div>
<div id="invalidcert_subError" class="BodyTextBlockStyle">
This might mean that someone’s trying to fool you or steal any info you send to the server. You should close this site immediately.<br><br>
</div>
<div class="BaseTextBlockStyle"><a href="javascript:close();"><img class="shieldImage" alt="Recommended icon" src="shieldcheck.ico" width="20px" height="20px"><id id="invalidcert_closeTab">Close this tab</id></a><br></div>
<div id="moreInformationAlign" align="left" aria-labelledby="moreInformation">
<table>
<tr>
<td valign="top" aria-labelledby="infoBlockIDImage">
<a href="#" onclick="javascript:expandCollapse('infoBlockID', true); return false;"><img src="down.png" id="infoBlockIDImage" border="0" class="actionIcon" alt="More information"></a>
</td>
<td valign="top">
<span id="moreInfoContainer"></span>
<noscript><id id="moreInformation">More information</id></noscript>
</td>
</tr>
</table>
<div id="infoBlockID" class="infoBlock" style="display: none">
<br/>
<b><span id="certReason" style="margin-left:20px"></span></b>
<p id="ErrorCode" style="margin-left:20px"></p>
<p class="BaseTextBlockStyle" id="override" style="margin-left:20px"><a href="#" id="overridelink"><img class="shieldImage" alt="Not recommended icon" src="shieldcritical.ico" width="20px" height="20px">Go on to the webpage (not recommended)</a></p>
</div>
</div>
</div>
</body>
</html>
如何绕过此页面并继续使用我的$ uri?
答案 0 :(得分:1)
注意:我正在使用具有自签名证书的Intranet网络进行此工作。我强烈不建议任何人在其他地方实际使用此代码。
我遇到了同样的问题,就像页面文档没有完全加载一样。我用下面的代码绕过了它。
$IE=new-object -com internetexplorer.application
$IE.visible=$true
$IE.FullScreen=$false
$IE.ToolBar = $false
$IE.StatusBar = $false
$IE.MenuBar = $false
$IE.AddressBar = $true
$IE.Resizable = $true
$IE.navigate2("https://URL.com")
$i=0
While ( $IE.busy -eq $true ) {
Start-Sleep -s 1
$i = $i + 1
if ( $i -ge 20 ) { break }
}
$overrideLink = $IE.document.links | where-object {$_.id -eq "overridelink" }
$overrideLink.click()
但是,当您离开此页面时,乐趣似乎仍在继续。我仍然需要登录,并且看起来需要遍历“ $ IE.document.forms”来执行该操作,而不是利用$ IE.document.getElementById(“ username”)。如果还需要执行登录,则可以成功添加以下代码。
#Need to wait for webpage to load after bypassing
$i=0
While ( $IE.busy -eq $true ) {
Start-Sleep -s 1
$i = $i + 1
if ( $i -ge 20 ) { break }
}
$loginForm = $IE.document.forms[0]
$usernameForm = $loginForm.children | Where-Object { $_.innerHTML -match "j_username" } #This contains the HTML for the form, so it will always contain the id
$usernameField = $usernameForm.children | Where-Object {$_.id -eq "j_username" }
$usernameField.value = "USERNAME"
$passwordForm = $loginForm.children | Where-Object { $_.innerHTML -match "j_password" } #This contains the HTML for the form, so it will always contain the id
$passwordField = $passwordForm.children | Where-Object {$_.id -eq "j_password" }
$passwordField.value = "PASSWORD"
$loginForm.submit()