function getSelectedText()

{

  var selectedText = '';

  if (document.selection) 

  {

  var range = document.selection.createRange();

    selectedText = range.text;

    }

    else if (window.getSelection) 

    {

      selectedText = window.getSelection();

    }

  return selectedText;

}

posted @ 2011-08-04 12:30 wiseshrek 阅读(31) 评论(0) 编辑

本文只作为备份,可参考:http://www.cnblogs.com/ptwlw/archive/2011/04/04/2005172.html

Real World XSS Vulnerabilities in ASP.NET Code

http://blogs.msdn.com/b/cisg/archive/2008/09/10/real-world-xss-vulnerabilities-in-asp-net-code.aspx

From couple of weeks we have been seeing some XSS vulnerabilities in asp.net code. Today I wanted to show you guys some real world examples ranging from property assignments, data binding and JavaScript building. For each example, I will offer both the vulnerability and mitigation which is very useful in self reviews. Before I say anything further, I want to caution you by saying that the following code examples must never be used in any application.

Example #1

In this case, we are simply using the user input directly in a label. The following is the vulnerable code.
 
   1: string strUsername =  txtUsername.Text;
   2: string strPassword =  txtPassword.Text;
   3: if (AuthenticationClass.Authenticate(strUsername, strPassword))
   4: {
   5:     //Set auth cookie and redirect, always use FormsAuthentication.SetAuthCookie
   6: }
   7: else
   8:     lblMessage.Text = string.Format("{0} is not found, click here to register!",
   9:                      strUsername);

Line 8, the username is directly being used to output the message. The following code fixes the vulnerability.

   1: lblMessage.Text = string.Format("{0} is not found, click here to register!",
   2:                   AntiXss.HtmlEncode(strUsername))

Example #2

In this case, we are data binding data from a database.

   1: //Probably the most common code that is vulnerable to XSS
   2: //This is persistent XSS vuln, a very dangerous as one
   3: //user attacks and many users will get exploited.
   4:  
   5: <asp:Repeater ID="repFeedback" runat="server" >
   6: <ItemTemplate>
   7: <p><asp:Label runat="server" ID="CommentsLabel" Text='<%# Eval("Comments") %>'/> 
   8: <br /> - <i><asp:Label runat="server" ID="NameLabel" Text='<%# Eval("Name") %>'/>
   9: (<asp:Label runat="server" ID="EmailLabel" Text='<%# Eval("Email") %>'/>)</i></p>
  10: </ItemTemplate>
  11: </asp:Repeater>

Line 7-9 are vulnerable to XSS. Fortunately there is a very simple way to fix, which is shown below.

   1: <asp:Repeater ID="repFeedback" runat="server" >
   2: <ItemTemplate>
   3: <p><asp:Label runat="server" ID="CommentsLabel" 
   4: Text='<%# AntiXss.HtmlEncode(DataBinder.Eval(Container.DataItem, Eval("Comments"))) %>'/> 
   5: <br /> - <i><asp:Label runat="server" ID="NameLabel" 
   6: Text='<%# AntiXss.HtmlEncode(DataBinder.Eval(Container.DataItem, Eval("Name"))) %>'/>
   7: (<asp:Label runat="server" ID="EmailLabel" 
   8: Text='<%# AntiXss.HtmlEncode(DataBinder.Eval(Container.DataItem, Eval("Email"))) %>'/>)
   9: </i></p>
  10: </ItemTemplate>
  11: </asp:Repeater>

Also, please note that DataBinder.Eval and Eval are slow as they use reflection to parse the expression. A better option is to use the Container.DataItem directly as it is a DataRowView object.

   1: <%#Microsoft.Security.Application.AntiXss.HtmlEncode
   2: ((((System.Data.DataRowView)Container.DataItem)["Comments"]).ToString()) %>

Example #3

In this case, we are using a ASP.NET value in the JavaScript.

   1: <script language="javascript">
   2: function showMessage() 
   3: {
   4:     var message='<%=this.strMessage%>';
   5:     var div = document.getElementById('messageLabel');
   6:     div.innerHTML=message;
   7: }
   8: </script>

Line 4 has the vulnerability. Anytime you use .NET variables or data directly into java script, that is a perfect recipe for a disaster. In fact, this vulnerability is so dangerous that neither ASP.NET Request Validation nor Server.HtmlEncode cannot protect you. Only AntiXss has native java script encoding.

   1: var message=<%=AntiXss.JavaScriptEncode(this.strMessage)%>;

Please note that AntiXss.JavaScriptEncode automatically surrounds the input with single quotes to make it a valid string.

We have seen three most common examples but there are many other vulnerable ways. The following is the small list of properties which could return untrusted input. By no means these values should be trusted, they should be validated and encoded during output.

Class name and property
Request.Params
Request.QueryString
Request.Form
Request.Headers
Request.ServerVariables
Request.Cookies
TextBox.Text
HiddenField.Value

Please note that there are other ways in which you can get user input and could result in a XSS attack. The best strategy is to identify user inputs and encode them before sending back to the browser.

posted @ 2011-07-25 17:02 wiseshrek 阅读(218) 评论(0) 编辑

选择该列数据,然后数据—分列—下一步—下一步—列数据格式为“文本”—确定。

posted @ 2011-07-21 10:07 wiseshrek 阅读(165) 评论(0) 编辑

问题:

Today when I tried to add Web Service to My WPF application I was getting following error: 

"The components required to enumerate Web references are not installed on this computerPlease re-install Visual Studio"

解决方案:

Run

"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Devenv /ResetSkipPkgs" , it worked for me

备注:VS2008是安装在C盘的,如果你安装在其他位置,注意切换。此问题发生在vsual studio 2008

原文地址:http://www.dotnetbhupesh.com/post/2008/07/Visual-STudio-2008-The-components-required-to-enumerate-Web-references-are-not-installed-on-this-computer-Please-re-install-Visual-S.aspx

posted @ 2011-06-08 14:05 wiseshrek 阅读(29) 评论(0) 编辑
摘要: 问题描述:通过ODBC3.5.1连接MySQL读取数据,所有VARCHAR字段返回的都是byte[],要用Encoding GetString方法才能转为字符串解决方案:机器上先安装过ODBC5.1.5,后面需要3.5.1时才安装了ODBC3.5.1。卸载2个版本的驱动,按照驱动的顺序从低到高重新安装,问题解决。分析:这个问题有点蛋疼阅读全文
posted @ 2011-06-01 11:51 wiseshrek 阅读(61) 评论(0) 编辑
摘要: 问题:在数据库执行查询 select SUM(col) from Table发生expression 转换为数据类型 int 时出现算术溢出错误解决方案:sum(convert(bigint,col))阅读全文
posted @ 2011-05-12 11:00 wiseshrek 阅读(128) 评论(0) 编辑
摘要: 造成这个错误的原因是:在<head runat="server"></head>里面,使用了<%=xxx%>这样的代码,把Head中使用的<%=.....%>的脚本放到body中,就OK了.当然, 可以根据实际情况用其他方式处理阅读全文
posted @ 2010-12-15 20:48 wiseshrek 阅读(23) 评论(0) 编辑
摘要: 列名数据类型描述fileidsmallint每个数据库的唯一文件标识号。groupidsmallint文件组标识号。sizeint文件大小(以 8 KB 页为单位)。maxsizeint最大文件大小(以 8 KB 页为单位)。0 值表示不增长,–1 值表示文件应一直增长到磁盘已满。growthint数据库的增长大小。0 值表示不增长。根据状态的值,可以是页数或文件大小的百分比。如果status包含 0x100000,则growth是文件大小的百分比;否则,它是页数。statusintgrowth值(以兆字节 (MB) 或千字节 (KB) 为单位)的状态位。0x1 = 默认设备。0x2 = 磁盘阅读全文
posted @ 2010-12-09 16:12 wiseshrek 阅读(28) 评论(0) 编辑
摘要: 本来准备把公司的一些搜索移到RavenDB, 但是发现了一些问题对一些包含中文的字段进行了索引(KeywordAnalyzer)但是在进行搜索的时候 发现以H开都的都搜索不到, B的也搜索不到, 到开发博客发了问题, 开发的OK, 我是为什么?难道是因为中文?PS:后来只用英文测试, 还是一样的问题.阅读全文
posted @ 2010-11-29 11:00 wiseshrek 阅读(199) 评论(3) 编辑
摘要: 示例下载地址thunder://QUFodHRwOi8vbW9iaWxlLjkxLmNvbS9zb2Z0L2Rvd25sb2FkLzEwMTQ2NjkvZmQ3ZTdkYWE4YWJjZjJkNTMzNzI4NmQ1ZGUzMjA5NmEvsbzF3LXE0KG/1sH6IERpbm8gUnVzaC5weGxaWg==解决方案:1。获取thunder://后面部分string thunderDow...阅读全文
posted @ 2010-11-28 17:56 wiseshrek 阅读(221) 评论(0) 编辑
摘要: 转自:http://msdn.microsoft.com/zh-cn/library/ms190384(v=SQL.90).aspx定义自定义权限集时为模块指定执行上下文非常有用。例如,某些操作(如 TRUNCATE TABLE)没有可授予的权限。若要执行 TRUNCATE TABLE,用户必须对指定表具有 ALTER 权限。授予用户对表的 ALTER 权限可能不是最佳方法,因为用户将拥有超出截断...阅读全文
posted @ 2010-10-29 17:27 wiseshrek 阅读(82) 评论(0) 编辑
摘要: 问题:在codebehind.cs文件, 如何获取一个服务端控件的innerHtml解决方案:StringBuilder sb= new StringBuilder();StringWriter sw= new StringWriter(sb);HtmlTextWriter hw= newHtmlTextWriter(sw);yourServerControl.RenderControl(hw);...阅读全文
posted @ 2010-10-27 18:15 wiseshrek 阅读(545) 评论(0) 编辑
摘要: 在web应用中,何时创建DocumentStore?何时创建DocumentSession?从其所带的Sample中可以看到:在Application_Start时创建 DocumentStore在BeginRequest时创建DocumentSession在EndRequest时销毁DocumentSession阅读全文
posted @ 2010-10-26 16:37 wiseshrek 阅读(89) 评论(0) 编辑
摘要: 用SQL:ALTER TABLE table ADD column AS datediff(d,CreatedDate,getdate())通过ssms列属性-> 表设计器 -> 计算所得的列规范 -> 公式阅读全文
posted @ 2010-10-20 20:08 wiseshrek 阅读(285) 评论(0) 编辑
摘要: 原文-http://technet.microsoft.com/zh-cn/library/ms175987(SQL.90).aspxhttp://technet.microsoft.com/zh-cn/library/ms178052(SQL.90).aspxhttp://technet.microsoft.com/zh-cn/library/ms190203(SQL.90).aspx从简单恢复...阅读全文
posted @ 2010-10-17 13:23 wiseshrek 阅读(48) 评论(0) 编辑
摘要: ScriptManager的EnablePageMethods属性用于设定客户端javascript直接调用服务端静态WebMethodaspx<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> </asp:ScriptManager>aspx.cs[System.W...阅读全文
posted @ 2010-10-14 11:11 wiseshrek 阅读(24) 评论(0) 编辑
摘要: INSERT INTO SELECT语句要求目标表必须存在(可以插入常量)SELECT INTO FROM语句要求目标表不存在,在插入时会自动创建表阅读全文
posted @ 2010-10-13 13:36 wiseshrek 阅读(204) 评论(0) 编辑
摘要: 备注: 1 因为测试的时候我用的是本地一个书库内容, 数据写入的代码就省略了 2 中科院分词部分可以到中科院网站下载http://ictclas.org/ 3 上面利用中科院分词的ICTCLASAnalyzer, 已经在项目中应用,效率还可以另: 本来打算用盘古分词来做测试的, 但是盘古分词对lucene 2.9的时候做了些修改, 所以ravendb必须要重新编译, 有点麻烦, 就跳过了, 操作方...阅读全文
posted @ 2010-09-26 13:41 wiseshrek 阅读(281) 评论(0) 编辑
摘要: 问题:应用的一个Lucene.Net搜索程序, Dll从2.4升级到2.9.2.2, 发生异常:Exception: System.FormatException Message: Invalid shift value in prefixCoded string (is encoded value really an INT?)排查:跟踪代码发现searcher.Search(wq, new S...阅读全文
posted @ 2010-09-25 11:50 wiseshrek 阅读(370) 评论(0) 编辑