Website Development: ASP Website Hacking Prevention Techniques
2012-08-19 00:00:00
[Introduction]
To better defend against hacker attacks, I would like to offer my personal opinions. First, do not assume that a "free" program is truly free to use. Since you can share the source code, an attacker can analyze the code just as well. If you pay attention to protection in the details, your website's security will be greatly improved.
To better defend against hacker attacks, I would like to offer my personal opinions. First, do not assume that a "free" program is truly free to use. Since you can share the source code, an attacker can analyze the code just as well. If you pay attention to protection in the details, your website's security will be greatly improved. Even if a vulnerability such as SQL Injection appears, an attacker will not be able to take over your site immediately. Because ASP is convenient and easy to use, more and more website back-end programs use the ASP scripting language. However, because ASP itself has some security flaws, a moment of carelessness can give hackers an opening. In fact, security is not only the job of the webmaster; programmers must also pay attention to certain security details and develop good security habits, otherwise they will bring huge security risks to their own websites. At present, ASP programs on most websites have various security flaws, but if you pay a bit more attention when writing the program, these can still be avoided.

1. Usernames and Passwords Cracked
Attack principle: Usernames and passwords are often the things hackers are most interested in. If the source code is seen through some means, the consequences will be serious.
Prevention techniques: Programs that involve usernames and passwords are best encapsulated on the server side and should appear as little as possible in ASP files. The usernames and passwords used for database connections should be given the minimum privileges. Usernames and passwords that appear frequently can be written in a relatively hidden include file. If a database connection is involved, ideally grant it only the permission to execute stored procedures; never directly give that user permission to modify, insert, or delete records.
2. Authentication Bypassed
Attack principle: Most ASP programs that require authentication add a judgment statement at the top of the page, but this is not enough, and a hacker may bypass authentication and enter directly.
Prevention techniques: For ASP pages that require authentication, you can track the file name of the previous page, and only sessions transferred from that previous page can read the page.
3. inc File Exposure
Attack principle: When an ASP-based homepage is still under construction and has not completed final debugging, it can be actively added as a search target by certain search engines. If someone uses a search engine to find these pages at this time, they will obtain the location of the relevant files and be able to view details of the database location and structure in the browser, thereby revealing the complete source code.
Prevention techniques: Programmers should thoroughly debug a web page before publishing it; security experts, for their part, need to harden ASP files so that external users cannot view them. First, encrypt the contents of the .inc file; second, you can also use .asp files instead of .inc files so that users cannot directly view the source code from the browser. Do not give inc files system-default names or names with special meanings that are easy for users to guess; use irregular English letters as much as possible.
4. Automatic Backups Downloaded
Attack principle: In some tools for editing ASP programs, when you create or modify an ASP file, the editor automatically creates a backup file. For example, UltraEdit backs up a .bak file; if you create or modify some.asp, the editor automatically generates a file called some.asp.bak. If you do not delete this bak file, an attacker can directly download the some.asp.bak file, and the source program of some.asp will be downloaded.
Prevention techniques: Check carefully before uploading a program and delete unnecessary files. Be especially careful with files that have the BAK extension.
5. Special Characters
Attack principle: Input boxes are one target exploited by hackers. They can cause damage to a user's client by entering scripting languages and the like; if the input box involves a data query, they will use special query statements to obtain more database data, or even entire tables. Therefore, input boxes must be filtered. However, if you only validate input on the client side for the sake of efficiency, it can still be bypassed.
Prevention techniques: In ASP programs that handle input boxes such as message boards and BBS, it is best to block HTML, javaScript, and VBScript statements. If there are no special requirements, you can restrict input to letters and numbers only and block special characters. At the same time, limit the length of input characters. Moreover, you should not only validate input on the client side, but also perform similar checks in the server-side program.
6. Database Download Vulnerability
Attack principle: When using Access as the back-end database, if someone learns or guesses the path and database name of the server's Access database through various means, they can also download this Access database file, which is very dangerous.
Prevention techniques:
(1) Give your database file a complex, unconventional name and place it under several levels of directories. By "unconventional," for example, if a database stores information about books, do not name it "book.mdb"; instead give it a strange name such as d34ksfslf.mdb, and place it under several levels of directories such as ./kdslf/i44/studi/. This makes it extremely difficult for a hacker to obtain your Access database file by guessing.
(2) Do not write the database name in the program. Some people like to write the DSN in the program, for example:
DBPath = Server.MapPath("cmddb.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
If someone should happen to obtain the source program, the name of your Access database will be fully exposed. Therefore, it is recommended that you set up a data source in ODBC and then write the following in your program:
conn.open"shujiyuan"
(3) Use Access to encode and encrypt the database file. First, select the database (e.g., employer.mdb) in "Tools → Security → Encrypt/Decrypt Database", then press OK. A "Save Database As After Encryption" window will appear, where you can save it as "employer1.mdb".
It should be noted that the above actions do not set a password on the database; they merely encode the database file, with the aim of preventing others from using other tools to view the contents of the database file.
Next we encrypt the database. First open the encoded employer1.mdb, and when opening it, select the "Exclusive" mode. Then choose "Tools → Security → Set Database Password" from the menu, and then enter the password. In this way, even if someone obtains the employer1.mdb file, without the password they will be unable to see the contents of employer1.mdb.