'2009/10'에 해당되는 글 29건
- 2009/10/30 웹 어플리케이션 보안 취약점 테스트 (1)
- 2009/10/29 PhpExpress - PHP loader and accelerator
- 2009/10/28 인코딩을 통한 XSS필터 회피 기술
Developed by the Open Web Application Security Project (OWASP), WebScarab is first and foremost a proxy used to analyze browser requests and server replies. In addition to serving as a tool for packet analysis, you can use it to "fuzz" sites, looking for some of the same exploits mentioned above. To use WebScarab, you first configure proxy settings in your Web browser. For Mozilla Firefox, perform these steps (see Firefox keyboard shortcuts for the alternative accessible steps):
- Click Tools > Options > Advanced > Network.
- Click Settings.
The Connection Settings window opens. - Select the Manual proxy configuration option.
- For both HTTP Proxy and SSL Proxy, type
localhost, and set the port to 8008. - Make sure the No proxy for box is empty, then click OK.
Figure 1. Firefox connection settings
For Windows® Internet Explorer®, perform the following steps (see Internet Explorer keyboard shortcuts in the IE Help menu for the alternative accessible steps):
- Click Tools > Internet Options > Connections.
- Click LAN Settings to open the Proxy Settings window.
- Under Proxy Servers, select the Use a proxy server for your LAN check box, then click Advanced.
- For HTTP and Secure, type
localhostfor the proxy address to use, then type8008for the port. - Make sure the Exceptions box is empty, then click OK.
Figure 2. Setting the proxy
Now, you are ready to scan a Web site.
The following examples use the Hacme Casino site, which is built by Foundstone with certain vulnerabilities so that it can be used for training purposes. The site comes packaged with Apache Tomcat, as well, so you can run it locally if you wish.
Next, open WebScarab. Once you launch it, you will see only two tabs: Summary and Intercept. Because you want to use WebScarab for fuzzing, change the view by clicking Tools > Use full-featured interface > OK. You will then be asked to restart WebScarab. When you have done so, you can begin with the interface shown in Figure 3. (WebScarab provides a list of keyboard shortcuts—unfortunately only two.)
Figure 3. The WebScarab interface
To start your new session, click File > New. You are presented with a box that asks where you would like to save your session. Select or create the storage directory, then click OK. When you use WebScarab with Hacme Casino, start the server before opening your browser. Then, in the browser's address bar, type http://localhost:3000.
Once you open the browser, you should start seeing some activity in WebScarab, because WebScarab is capturing all the requests and replies between the browser and the server. Because you want to use the fuzzing feature to test for vulnerabilities, first look at where the different vulnerabilities can exist. Start by looking at the login as a potential exploit. To test the login, you should record the interaction that takes place between the browser and the server. There is no need for a successful login here, so you can enter whatever you like for the user name and password: For this example, enter casino for both the user name and password, then click Login.
Of course, the login will be unsuccessful, but that is not what you're interested in. Instead, go back to WebScarab. In the Path column, right-click account\login, then click Use as fuzz template, as shown in Figure 4.
Figure 4. The fuzzing template
Perform the following steps:
- Click the Fuzzer tab at the top of the WebScarab interface.
- Click Source.
- Browse to the location of your dictionary. (I used all_attack.txt)
- Provide a description of the source, then click Add.
- Click Close to return to the Fuzzer window.
Now, go to the user_login parameter and click in the area under the Fuzz Source column. Because you have only loaded one source—All attack—select it from the drop-down menu. Do the same for the user_password parameter, as shown in Figure 5.
Figure 5. Selecting the attack file
Now that you have defined the source, click Start to begin the process. The fuzzer inserts the parameters from the file into both the user name and password inputs. You should see some activity on the screen as the tool completes each attempt. Typically, you would need to examine each ID in the results to analyze what takes place with each attempt. However, because you know that the added strings will produce a result, you can see what can happen when the fuzzer is successful.
Double-click the first string in the example, shown in Figure 6.
Figure 6. Finding a vulnerability
Note that in the top circle, the value for user_login and user_password is ‘) OR 1=1--. Next, note that the location has changed from http://localhost:3000, which is the home page, to http://localhost:3000/lobby/games, which is what a user who successfully logged in would see. What does this mean? It means that your site is vulnerable. Because ‘) OR 1=1-- is an SQL string, the site is vulnerable to an SQL injection. Scroll through the results using the Next button, and look for that value. Notice that the location here remains http://localhost:3000. You know from this result that inserting this type of string would not result in a successful login attempt, so the site is not vulnerable to this type of attack.
Another useful tool for security testing is Paros Proxy. Like WebScarab, Paros captures conversations between the browser and the server for analysis. You can also use it to test for vulnerabilities on a site. To run Paros, you must change the port number used in the proxy settings of your browser. For WebScarab, you used 8008; change this port to 8080 before running Paros, or the tool won’t work. For this exercise, the example uses WebGoat, another tool from OWASP. Like Hacme Casino, WebGoat runs using the Tomcat server as a local host. For the purposes of this article, WebGoat shows more vulnerabilities in the Paros scan than would Hacme Casino.
After changing the port, open Paros. Then, perform these steps:
- In the WebGoat folder, double-click WebGoat.ba to start Tomcat.
- Open your browser, then type
http://localhost/WebGoat/attack. - Type
guestfor the user name and password. - Click Start WebGoat.
Now, go back to Paros and start your scan of the WebGoat site. Of course, you can use your own site instead by entering its URL in the address bar.
In Paros, expand the Sites folder to see http://localhost in the tree. Expand this folder to bring up WebGoat. Highlight WebGoat, and then click Analyse Scan. This immediately begins the scan of the site. Large sites may take a while, but this one should only take a few seconds. Once it starts scanning, the bottom pane changes to the Alerts tab automatically (see Figure 7). When the scan is complete, click OK in the pop-up window that tells you where to find the report.
Figure 7. Viewing alerts
You can expand the alerts to show them in greater detail. You can also view the report, which offers much more information. First, however, save the scan results by clicking File > Save As, choosing a location and file name for your scan, and then clicking Save.
To view a report, click Report > Last Scan Report. Click OK in the pop-up window, and a new browser tab opens with the report of the scan results, as shown in Figure 8. This report provides a great deal of information regarding each vulnerability detected, including a reference to the OWASP page that deals with the specific exploit.
Figure 8. The Paros report
Although scanners are a good way to find possible vulnerabilities in a Web site, the best security companies always test possible vulnerabilities by hand for false positives. Testing for these possible exploits means actually going to the areas of your site that were reported as vulnerable, inserting SQL code or a script into the site itself to see what the response is, and then going into the site itself and plugging any exploits. Large firms often hire professional programmers who specialize in this type of testing (called vulnerability validation), but as a developer, you can perform some of these tests yourself. Not only will doing so help you secure your site a bit more, but it will help you as you build future sites.
False positives with SQL injection
Using the Hacme Casino site again, let's look at the vulnerability that WebScarab found: an SQL injection exploit at the login. With Hacme Casino running, enter the SQL code that WebScarab used successfully—‘) OR 1=1--—in the Login input area of the site. When you click Login, the account Andy_Aces is opened. Because 1=1 is going to be true, the most basic form of an SQL injection works here. As for Andy, he has the bad luck of being the first account in the database.
Just how did this work? In the back end, the database runs a query like this:
SELECT * FROM users WHERE (username=username AND password=password) |
The bit of code injected through the Login box turned the valid query into this:
SELECT * FROM users WHERE (username=’’) OR 1=1—AND password=’’) |
This query returns a successful login for the first user of the site, which is unfortunately Andy.
Of course, this example only scratches the surface of an SQL injection. As someone becomes more skilled in attacking Web sites, he or she can actually exploit this vulnerability to create users, change passwords, and extract sensitive data from the site. Protecting your site against these attacks involves taking a few steps:
- Use parameterized queries or stored procedures to access a database as opposed to using string concatenation. Parameterized queries require that you define all the SQL code and then pass in each parameter to the query later. This allows the database to distinguish between code and data, so it doesn't matter what type user input is supplied. Stored procedures are similar to parameterized queries in that they require you to define the SQL code first, then pass in the parameters later. These elements differ in that the SQL code for a stored procedure is defined and stored in the database itself, then called from the application.
- Sanitize user input by "whitelisting" the characters allowed. If you are asking for a name, only allow a-z and A-Z. For phone numbers, limit characters to 0-9. Use the appropriate validation technique supported by your database to do this.
- Escape user-supplied input using the character escaping scheme set up by your database. Escaping special characters tells your database that the characters provided in the query are in fact data, not code. If all user-supplied input is then escaped using the proper scheme, the database will not confuse that input with SQL code you have written.
- Don't give attackers any help. Make sure error messages don't give away information that can be later used against the site.
To demonstrate an example of an XSS attack, turn back to WebGoat. Start this site by clicking Cross Site Scripting > LAB: Cross Site Scripting > Stage 1: Stored XSS. Log in to the demo site—Goat Hills Financial—with a user name of Larry Stooge and the password larry. Now, an attacker would need to find somewhere to input a malicious script. The Search Staff function probably has a text box where someone can enter a name: Click Search Staff to reveal it, as shown in Figure 9.
Figure 9. An XSS entry point
In the Name box, type alert("You got me with XSS");. This script may only show an alert box like you see in Figure 10, but think about what could happen if the script could redirect a user to a fake human resources site where he or she had to enter a social security number, home address, bank information, and so on. Altering the action associated with the OK button can do this. For really creative malicious hackers, the sky is the limit if the user trusts them.
Figure 10. A successful XSS attack
To protect against XSS attacks, you need to scrub all inputs. If the input will later be used as parameters to operating system commands, scripts, and database queries, then it is essential that you do so. You can scrub user inputs by escaping untrusted data before allowing it to be inserted into HTML element content and HTML common attributes. OWASP recommends that all ASCII values less than 256 be escaped in the latter. JavaScript™ data values, HTML-style property values, and HTML value attributes can also be escaped. Of course, before you escape input data, make sure you have validated any input to your Web site. If you are looking for specific input values, numbers, letters, e-mail addresses, and the like, then only allow this type of data and refuse anything else.
원문 : http://www.ibm.com/developerworks
Overview of NuSphere PhpExpress
PhpExpress is NuSphere Free PHP loader and accelerator that provides support for encoded files and also speeds up the execution of regular PHP files.Please note that if you are using PHP files encoded with NuSphere NuCoder PhpExpress is required to be installed on the server.
This is how PhpExpress works:
- When PHP interpreter executes any PHP script it first compiles the script into bytecodes. However NuCoder produces PHP files that have been already compiled into bytecodes.
- PhpExpress loads encoded PHP scripts directly into PHP engine saving time and boosting performance of PHP interpreter
- PhpExpress also implements caching for PHP engine and accelerates execution process even if PHP Script is not encoded
Obtaining PhpExpress
PhpExpress can be downloaded from NuSphere website and distributed Free Of Charge without limitations. Every NuCoder installation also comes with PhpExpress.How to download PhpExpress from NuSphere Website
You can download the archive containing PhpExpress from Free Downloads area of your NuSphere Account. To do that:
- Create NuSphere Account and login
- Click on Free Downloads
- Follow the link to NuSphere PhpExpress for the Operating System of your server to start the download process
- Save
NuSphere-PhpExpress-2.0.zipfile for Windows orNuSphere-PhpExpress-2.0.tag.gzfor Linux/Unix to the disk - For windows - using WinZip or similar program unzip
NuSphere-PhpExpress-2.0.zipin the directory of your choice - For Linux/Unix - use the following command to unfold
NuSphere-PhpExpress-2.0.tag.gz tar -xvfz Nusphere-PhpExpress-2.0.tag.gz - The uncompressed archive will create a directory "NuSphere-PhpExpress" with
phpexpress-php-x.x.dllfiles for Windows or phpexpress-php-x.x.so for Linux/Unix (where x.x is the version of PHP compatible with the module)
PhpExress extensions for all operating systems can be found in the folder "loader" of your NuCoder installation
How to install NuSphere PhpExpress
NuSphere PhpExpress is a regular PHP extension, which makes it easy to install and deploy. To install PhpExpress:- Open php.ini file for editing
- Add line
extension=phpexpress-php-x.x.dllif you are deploying on Windows, extension=phpexpress-php-x.x.so if you are deploying on Unix, Linux or Mac OS operating systems (where x.x is the version of PHP compatible with the module) - Copy
phpexpress-php-x.x.dllorphpexpress-php-x.x.soin the PHP extensions directory specified in php.ini file - Stop and Start Apache if you are running PHP as Apache module
- Execute call to phpinfo() function and make sure that PhpExpress is properly installed
How to monitor PHP Cache implemented by NuSphere PhpExpress
PhpExpress accelerates execution of PHP scripts by caching them and avoiding unnecessary compilation. You can view and control PHP Cache created by PhpExpress with a single function call to the PHP function phpexpress() provided by PhpExpress PHP extension. phpexpress() produces the output similar to phpinfo() with the user Interface to administer PhpExpress cache. The output of phpexpress() is illustrated below:Please note that PHP caching is only enabled when PHP is running as an extension of the Web Server - dll on windows or shared object on Linux/Unix/Mac Operating Systems. Caching of PHP scripts when PHP is running in CGI mode is not useful and therefore disabled.
원문 : http://www.nusphere.com/
예를 들어서, 원래의 XSS 공격 문자열이 <script>alert("XSS")</script> 라고 하자. 그런데, XSS차단필터가 <script>와 같은 문자열을 차단하기 때문에, 이 공격은 성공할 수 없다.
그런데, 만약 서버의 응답 HTML의 Content-Type 선언에서 charset을 변경시킬 수 있다면, 이 XSS차단필터를 통과할 수 있다.
예를 들어, 아래와 같은 문자열은 XSS차단필터에서 보면, 전혀 의미가 없는 문자열일 뿐이다.
%A2%BE%BCscript%BEalert(%A2XSS%A2)%BC/script%BE
그렇지만, 위의 문자열을 US-ASCII charset으로 디코딩을 하면 전혀 얘기가 달라진다. US-ASCII는 7비트만을 사용하기 때문에, 위의 의미없어 보이는 문자열은 다시 원래의 XSS공격 문자열로 디코딩되어 사용자의 브라우저에서 실행될 수 있다.
이렇게 되는 과정을 조금만 더 살펴보자.
위의 문자 중에서 %BC를 2진수로 풀어보면, 10111100 이다. 그런데, US-ASCII에서 7비트만을 사용하므로, 최상위 1비트를 무시하면, %BC는 00111100으로 해석되고 이것은 >문자가 되는 것이다.
이 공격 방법은 현재 Internet Explorer에서 동작하는 것으로 확인이 된다. 그리고 서버의 응답에서 Content-Type 선언의 charset을 변경시킬 수 있어야만 한다.
이 공격 방법이 포스팅된 블로그의 실제 예제를 한번 살펴보자.
이 링크는 별 문제없고, 코드도 실행되지 않는다.
그런데, 이 링크에서 charset을 UTF-8에서 US-ASCII로 변경하게 되면 다른 결과를 보여준다. 소스보기를 해보면, Content-Type선언의 charset이 US-ASCII로 설정된 것을 볼 수 있다.
출처 : youngsam.kr

Web application security - Testing for vulnerabilities.pdf



Prev

Facebook

