I have a text box that is used to search for data within the site. What my client wants
1) Enter text in the search field and click the search icon.
2) A request sent to the server using a web proxy tool such as "Burp"
3) Add parameter with script as
test<~script>confirm(123)<~/script>
what is going on here
The XSS script entered by the helper is reflected in the response without input. Please see the image below, you will get an idea: -
! [enter image description here] [1]
Guys, let me know if you need more information related to this. Please help the guys, any help would be greatly appreciated. I want to stop the attack from the server side.
HTML and JS code: -
<asp:TextBox ID="txtSearch" runat="server" class="txtfld-search" oncopy="return false" oncut="return false" onpaste="return false"></asp:TextBox>
JS Code: -
<script type="text/javascript"> $(document).ready(function () { $('#ctl00_topNavigation_txtSearch').keyup(function () { var $th = $(this); $th.val($th.val().replace(/[^.%a-zA-Z0-9 ]/g, function (str) { alert('Special characters not allowed except %'); return ''; })); }); });
Also see the code behind: -
protected void btnSearch_Click(object sender, ImageClickEventArgs e) { Response.Redirect("search.aspx?tx=" + txtSearch.Text); }
Also see code for the search part: -
private void SearchResult() { DataTable dt; if (Session["Search"] == null) { ResXResourceReader reader = new ResXResourceReader(Server.MapPath("~/App_GlobalResources/Strings.en-US.resx")); IDictionaryEnumerator id = reader.GetEnumerator(); string sResourceFile = Server.MapPath("~/App_GlobalResources/Strings.en-US.resx"); XmlDocument xmlResource = new XmlDocument(); xmlResource.Load(sResourceFile); XmlNodeList elmData = xmlResource.SelectNodes("//root/data"); dt = new DataTable(); dt.Columns.Add(new DataColumn("ID", System.Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("Title", System.Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("Description", System.Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("Url", System.Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("Link", System.Type.GetType("System.String"))); foreach (XmlElement element in elmData) { DataRow dr = dt.NewRow(); dr["ID"] = element.GetAttribute("name"); //dr["Title"] = element.GetAttribute("name"); XmlNodeList sDescription = element.SelectNodes("value"); dr["Title"] = sDescription.Count > 0 ? sDescription.Item(0).InnerText : string.Empty; ; dr["Description"] = string.Empty; XmlNodeList sUrl = element.SelectNodes("comment"); if (sUrl.Count > 0) { Int32 sPgTitle = sUrl.Item(0).InnerText.LastIndexOf(".") + 1; if (sPgTitle > 0) { dr["Url"] = sUrl.Item(0).InnerText; //dr["Url"] = Request.Url.Host.ToLower() + "/rbank/" + sUrl.Item(0).InnerText; dr["Link"] = string.Empty; } else { dr["Link"] = sUrl.Item(0).InnerText; } dt.Rows.Add(dr); } } //foreach (DataRow dr in dt.Rows) //{ // DataRow[] rDesc = dt.Select("Link <> ''"); // for (int i = 0; i < rDesc.Length; i++) // { // DataRow[] rTitle = dt.Select("ID = '" + rDesc[i]["Link"] + "'"); // if (rTitle.Count() > 0) // { // rTitle[0]["Description"] = rDesc[i]["Title"]; // } // } //} DataRow[] drDelete = dt.Select("Link <> ''"); foreach (DataRow drCheck in drDelete) { dt.Rows.Remove(drCheck); } dt.TableName = "FilterValues"; reader.Close(); Session["Search"] = dt; } else { dt = Session["Search"] as DataTable; } DataView dv = new DataView(); dv.Table = dt; **dv.RowFilter = "Description LIKE ('%" + Request.QueryString["tx"].Trim().ToLower() + "%') or Title LIKE ('%" + Request.QueryString["tx"].Trim().ToLower() + "%')";** dv.Sort = "Title ASC"; dgrdPages.DataSource = dv; dgrdPages.DataBind(); lblSearchWords.Text = Request.QueryString["tx"].Trim(); lblFilesFound.Text = dv.Count.ToString(); }
I found that dv.RowFilter can be set as some kind of SQL injection. I want to prevent this. Please, help.