有什么解决方法可以在 Web 浏览器中的另一个域上获取 iFrame 中的文本吗?

发布于 2024-12-05 13:16:47 字数 665 浏览 0 评论 0原文

您可能首先会认为这是不可能的,因为 XSS 限制。但我试图从托管 WebBrowser 的应用程序访问此内容,而不是从网站中的 javascript 代码访问。

我知道不可能也不应该通过非黑客手段从 javascript 访问此内容,因为这将是一个很大的安全问题。但托管 WebBrowser 的应用程序受到此限制是没有意义的。如果我想获取应用程序用户的 Facebook 信息,我可以执行 Navigate("facebook.com") 并在其中执行任何我想要的操作。这是一个托管 WebBrowser 的应用程序,而不是网页。

此外,如果您使用 Google Chrome 访问任何包含源位于另一个域的 iFrame 的网页,右键单击其内容并单击“检查元素”,它将显示该内容。更简单的是,如果您导航到另一个域中包含 iFrame 的任何网页,您将看到其内容。如果您可以在 WebBrowser 上看到它,那么您应该能够以编程方式访问它,因为它必须位于内存中的某个位置。

有没有什么办法,不是来自 DOM 对象,因为它们似乎基于与 javascript 相同的引擎,因此受到 XSS 限制,而是来自一些更底层的对象,例如 MSHTMLSHDocVw,要访问此文本吗?

You will probably first think is not possible because of XSS restrictions. But I'm trying to access this content from an application that hosts a WebBrowser, not from javascript code in a site.

I understand is not possible and should not be possible via non hacky means to access this content from javascript because this would be a big security issue. But it makes no sense to have this restriction from an application that hosts a WebBrowser. If I'd like to steel my application user's Facebook information, I could just do a Navigate("facebook.com") and do whatever I want in it. This is an application that hosts a WebBrowser, not a webpage.

Also, if you go with Google Chrome to any webpage that contains an iFrame whose source is in another domain and right click its content and click Inspect Element, it will show you the content. Even simpler, if you navigate to any webpage that contains an iFrame in another domain, you will see its content. If you can see it on the WebBrowser, then you should be able to access it programmatically, because it have to be somewhere in the memory.

Is there any way, not from the DOM objects because they seem to be based on the same engine as javascript and therefore restricted by XSS restrictions, but from some more low level objects such as MSHTML or SHDocVw, to access this text?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心病无药医 2024-12-12 13:16:47

这对你有用吗?

foreach (HtmlElement elm in webBrowser1.Document.GetElementsByTagName("iframe"))
{
     string src = elm.GetAttribute("src");
     if (src != null && src != "")
     {
          string content = new System.Net.WebClient().DownloadString(src); //or using HttpWebRequest
          MessageBox.Show(content);
     }
}

Can this be useful for you?

foreach (HtmlElement elm in webBrowser1.Document.GetElementsByTagName("iframe"))
{
     string src = elm.GetAttribute("src");
     if (src != null && src != "")
     {
          string content = new System.Net.WebClient().DownloadString(src); //or using HttpWebRequest
          MessageBox.Show(content);
     }
}
御守 2024-12-12 13:16:47

您是否只需要一种从代码请求内容的方法?

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webRequest.URL);
request.UserAgent = webRequest.UserAgent;
request.ContentType = webRequest.ContentType;
request.Method = webRequest.Method;

if (webRequest.BytesToWrite != null && webRequest.BytesToWrite.Length > 0) {
    Stream oStream = request.GetRequestStream();
    oStream.Write(webRequest.BytesToWrite, 0, webRequest.BytesToWrite.Length);
    oStream.Close();
}

// Send the request and get a response
HttpWebResponse resp = (HttpWebResponse)request.GetResponse();

// Read the response
StreamReader sr = new StreamReader(resp.GetResponseStream());

// return the response to the screen
string returnedValue = sr.ReadToEnd();

sr.Close();
resp.Close();

return returnedValue;

Do you just need a way to request content from code?

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webRequest.URL);
request.UserAgent = webRequest.UserAgent;
request.ContentType = webRequest.ContentType;
request.Method = webRequest.Method;

if (webRequest.BytesToWrite != null && webRequest.BytesToWrite.Length > 0) {
    Stream oStream = request.GetRequestStream();
    oStream.Write(webRequest.BytesToWrite, 0, webRequest.BytesToWrite.Length);
    oStream.Close();
}

// Send the request and get a response
HttpWebResponse resp = (HttpWebResponse)request.GetResponse();

// Read the response
StreamReader sr = new StreamReader(resp.GetResponseStream());

// return the response to the screen
string returnedValue = sr.ReadToEnd();

sr.Close();
resp.Close();

return returnedValue;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文