Examples of AppScan in API security testing
In this project, the API follows the standard REST architecture and the back-end server for communication. Functional testing for the API consists of two parts: one is implemented directly from a Web-based test page, and the other part, due to the limitations of the Web page (such as the inability to modify the HTTP header arbitrarily), is implemented through Shell scripting calls to curl. and the test environment for this API does not have a fixed domain name and IP address. Security testing for WEB applications uses AppScan standard. Several issues are faced during the implementation of the project:
- For non-REST API testing of WEB pages, AppScan Standard can do a good job, but for the API section, the API test page itself has insufficient coverage for the API due to the limitations of the HTTP request for the page under the browser. Therefore, it is difficult to guarantee coverage by AppScan scanning the pages of the API.
- The system does not have a fixed domain name or IP address, resulting in a test task being re-recorded and created each time. A scanned scan file within the starting URL is also shown in a read-only property 1.
Figure 1. Export starting URL
Before you begin to explain the workaround, let's introduce the AppScan recording file. The user is AppScan through a normal WEB program and can collect information through Manual Explorer recording. This generates a manualexplore_1.exd file in the AppScan scan file. The scan file is packaged in Deflate compression, so you can use an Extract tool to view the structure and files in the scan file. Here the user can export the Manualexplore_1.exd file by clicking File-> Export, Recorded Manual Explore in the menu bar, as shown in 2.
Figure 2. Export the Manualexplore_1.exd file
You can then re-import the previously recorded information into a new scan task by re-importing the file when needed. When a tester is testing an identical Web instance, when the instance has a different domain name or IP, and the tester has recorded one of them, it is possible to simply modify the Exd file and import it into a separate test instance.
This file itself is an XML file, this file is roughly structured, such as listing 1.
Listing 1. exd File structure
<?xml version="1.0" encoding="utf-16"?><!--automatically created by AppScan at 1/16/2014 11:20:26 am--><!--do not Edit!--><<</request> ... </requests><!--number of requests in file = 100-->
As we can see from the comments, this file is automatically generated by AppScan, so you should pay special attention to the modification, because the wrong modification may make AppScan unable to recognize the recorded HTTP request, or the wrong way to identify the HTTP request. The last line of comments indicates how many HTTP requests are recorded here.
These requests are placed in <requests>, a request's recording information structure, as shown in Listing 2.
Listing 2: Recording structure of the request
<RequestScheme="HTTPS"host="Www.ibm.com"Path="/"port="443"Method="GET"Sessionrequesttype="Login"Ordinal=">"<Ta1encoding="None" ></Raw><CookiesName="Jsessionid"Value="XXX"Path="/"domain="Www.ibm.com"Secure="False"expires="1/1/0001 12:00:00 AM"/><ParameterName="XXX"captureindex="0"Value=""Type="QUERY"Linkparamtype="Simplelink"separator= "&" operator= "=" reportname= "XXX"/> <sessioncookies> < cookie name= "JSESSIONID" value=" XXX path= "/" domain= "www.ibm.com" secure= "False" expires= "1/1/0001 12:00:00 AM"/></sessioncookies> </REQUEST>
The <raw> part is the original request data, including the HTTP Header and the body part of the entire data. While others are structured data from this raw data, the familiar HTTP should be no stranger to this structured data. For example, scheme is the requested protocol, the session is the session part of the HTTP header, parameter is the parameter in the URL. Here ordinal is a count of the request within this recording file.
Being familiar with the structure of the file, we can modify it or add our own HTTP recording information. To improve the coverage of your tests.
Here's how to fix the two issues mentioned earlier.
For question one, here's a simple example: there is a request for a database query with two parameters Parm1 and Parm2, and there are already exd files scanned for this API as follows:
Listing 3. Existing recording information
<RequestScheme="HTTPS"host="Www.site1.com"Path="/test/api1"port="443"Method="POST"Sessionrequesttype="Login"Ordinal="146" ><Ta1encoding="None" >post/test/api1 http/1.1host:www.site1.comuser-agent:mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) gecko/20100101 firefox/17.0accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q= 0.8accept-language:en-us,en;q=0.7,ja;q=0.3connection:keep-alivecontent-type:application/x-www-form-urlencoded; Charset=utf-8x-requested-with:xmlhttprequestreferer:https://www.site1.com/content-length:83cookie:jsessionid= 0000f7u3iictkf0sir4g9vibiqr:156f4da9-0cc6-4460-9ac9-f791e0aac903pragma:no-cachecache-control:no-cacheparm1= Test1&parm2=test2</Raw><CookiesName="Jsessionid"Value="0000f7u3iictkf0sir4g9vibiqr:156f4da9-0cc6-4460-9ac9-f791e0aac903"Path="/"domain="Www.site1.com"Secure="False"expires="1/1/0001 12:00:00 AM"/><ParameterName="Parm1"captureindex="0"Value="Test1"Type="BODY"Linkparamtype="Simplelink"Separator="&"Operator="="Reportname="Parm1"/><ParameterName="Parm2"captureindex="0"Value="Test2"Type="BODY"Linkparamtype="Simplelink"Separator="&"Operator="="reportname= "Parm2"/> <sessioncookies><cookie name= "Jsessionid" value=" 0000f7u3iictkf0sir4g9vibiqr:156f4da9-0cc6-4460-9ac9-f791e0aac903 "path=< Span class= "hljs-string" "/" domain= "www.site1.com" secure= "False" expires= "1/1/0001 12:00:00 AM"/> </sessioncookies> </REQUEST>
Now, because of the interface changes, the name of one of the parameters is changed from the original Parm1 to the new newparm. If we follow the normal process, we also need to scan the entire structure of the test page. In fact, we only use to get rid of the corresponding parts of the document, the original EXD parameter part of the change to the list 4.
Listing 4. Modified Exd File
<RequestScheme="HTTPS"host="Www.site1.com"Path="/test/api1"port="443"Method="POST"Sessionrequesttype="Login"Ordinal="146" ><Rawencoding="None" >post/test/api1 http/1.1...content-length:23newparm=test1&parm2=test2</RAW> <parameter name= "newparm" captureindex= "0" value= "test1" type= "BODY" linkparamtype= "Simplelink" Span class= "hljs-attr" >separator= "&" operator=" = "reportname=" Newparm "/> .... </REQUEST>
For the second issue, use the method mentioned above to export the Exd file and modify the Supplemental archive backup. When there are new tasks of different domain name or IP, you can make a new scan task, complete the task configuration, copy an already archived exd file, replace all the domain name or IP in the file with the new domain name or IP and save it, then import the recording file in the new scan file.
Through the above method, the problem of the project is well solved, that is, the test coverage is ensured, and the testing flexibility is ensured.
Back to top of page
Summarize
With the extensive application of API, API security testing becomes more and more important, the application of AppScan standard in API security testing is a simple and effective method, which can improve the efficiency of API security testing and improve the test coverage.
AppScan Manual detection of APIs