What is the type of attack called by injecting malicious code in a websites form input?

The Basics of Web Hacking

Josh Pauli, in The Basics of Web Hacking, 2013

Most Common Web Vulnerabilities

Our targets will all be exploited by attacking well-understood vulnerabilities. Although there are several other web-related vulnerabilities, these are the ones we are going to concentrate on as we work through the chapters.

Injection

Injection flaws occur when untrusted user data are sent to the web application as part of a command or query. The attacker’s hostile data can trick the web application into executing unintended commands or accessing unauthorized data. Injection occurs when a hacker feeds malicious, input into the web application that is then acted on (processed) in an unsafe manner. This is one of the oldest attacks against web applications, but it’s still the king of the vulnerabilities because it is still widespread and very damaging.

Injection vulnerabilities can pop up in all sorts of places within the web application that allow the user to provide malicious input. Some of the most common injection attacks target the following functionality:

Structured query language (SQL) queries

Lightweight directory access protocol (LDAP) queries

XML path language (XPATH) queries

Operating system (OS) commands

Anytime that the user’s input is accepted by the web application and processed without the appropriate sanitization, injection may occur. This means that the hacker can influence how the web application’s queries and commands are constructed and what data should be included in the results. This is a very powerful exploit!

Cross-site Scripting (XSS)

Cross-Site Scripting (XSS) occurs when user input is accepted by the application as part of a request and then is used in the output of the response without proper output encoding in place for validation and sanitization. XSS allows attackers to execute scripts in the victim’s browser, which can hijack user sessions, act as a key logger, redirect the user to malicious sites, or anything else a hacker can dream up! A hacker can inject malicious script (often times JavaScript, but it also could be VBScript) that is then rendered in the browser of the victim. Because this script is part of the response from the application, the victim’s browser trusts it and allows the script to run.

XSS comes in two primary “flavors”: reflected and stored. Reflected XSS is much more widespread in web applications and is considered to be less harmful. The reason that reflected XSS is considered less harmful isn’t because of what it can do, but because it’s a one-time attack where the payload sent in a reflected XSS attack is only valid on that one request. Think of reflected XSS as “whoever clicks it, gets it.” Whatever user clicks the link that contains the malicious script will be the only person directly affected by this attack. It is generally a 1:1 hacker to victim ratio. The hacker may send out the same malicious URL to millions of potential victims, but only the ones that click his link are going to be affected and there’s no connection between compromised users.

Stored XSS is harder to find in web applications, but it’s much more damaging because it persists across multiple requests and can exploit numerous users with one attack. This occurs when a hacker is able to inject the malicious script into the application and have it be available to all visiting users. It may be placed in a database that is used to populate a webpage or in a user forum that displays messages or any other mechanism that stores input. As legitimate users request the page, the XSS exploit will run in each of their browsers. This is a 1:many hacker to victim ratio.

Both flavors of XSS have the same payloads; they are just delivered in different ways.

Broken Authentication and Session Management

Sessions are the unique identifiers that are assigned to users after authenticating and have many vulnerabilities or attacks associated with how these identifiers are used by the web application. Sessions are also a key component of hacking the web user.

Application functions related to authentication and session management are often not implemented correctly, allowing attackers to compromise passwords, keys, session tokens, or exploit other implementation flaws to assume other users’ identities. Functionality of the web application that is under the authentication umbrella also includes password reset, password change, and account recovery to name a few.

A web application uses session management to keep track of each user’s requests. Without session management, you would have to log-in after every request you make. Imagine logging in after you search for a product, then again when you want to add it to your shopping cart, then again when you want to check out, and then yet again when you want to supply your payment information. So session management was created so users would only have to login once per visit and the web application would remember what user has added what products to the shopping cart. The bad news is that authentication and session management are afterthoughts compared to the original Internet. There was no need for authentication and session management when there was no shopping or bill paying. So the Internet as we currently know it has been twisted and contorted to make use of authentication and session management.

Cross-site Request Forgery

CSRF occurs when a hacker is able to send a well-crafted, yet malicious, request to an authenticated user that includes the necessary parameters (variables) to complete a valid application request without the victim (user) ever realizing it.

This is similar to reflected XSS in that the hacker must coerce the victim to perform some action on the web application. Malicious script may still run in the victim’s browser, but CSRF may also perform a valid request made to the web application. Some results of CSRF are changing a password, creating a new user, or creating web application content via a CMS. As long as the hacker knows exactly what parameters are necessary to complete the request and the victim is authenticated to the application, the request will execute as if the user made it knowingly.

Security Misconfiguration

This vulnerability category specifically deals with the security (or lack thereof) of the entire application stack. For those not familiar with the term “application stack,” it refers to operating system, web server, and database management systems that run and are accessed by the actual web application code. The risk becomes even more problematic when security hardening practices aren’t followed to best protect the web server from unauthorized access. Examples of vulnerabilities that can plague the web server include:

Out-of-date or unnecessary software

Unnecessary services enabled

Insecure account policies

Verbose error messages

Effective security requires having a secure configuration defined and deployed for the application, frameworks, application server, web server, database server, and operating system. All these settings should be defined, implemented, and maintained, as many are not shipped with secure defaults. This includes keeping all software up to date, including all code libraries used by the application.

Read full chapter

URL: https://www.sciencedirect.com/science/article/pii/B9780124166004000010

Web Application Exploitation with Injection

Josh Pauli, in The Basics of Web Hacking, 2013

Abstract

This chapter covers the most damaging type of web application attack—code injection. These attacks all rely on the web application accepting malicious input and processing it without realizing it may cause harm. SQL injection, operating system command injection, and injectable web shell attacks are introduced in context of how and where they can be exploited. Extensive parts of this chapter are dedicated to using Burp Suite and sqlmap to execute these attacks. The SQL injection process follows very specific steps in which the vulnerability is discovered, authentication is bypassed, data are harvested from the database, and password hashes are cracked offline for future use.

Read full chapter

URL: https://www.sciencedirect.com/science/article/pii/B9780124166004000046

Introduction

Mario Heiderich, ... David Lindsay, in Web Application Obfuscation, 2011

Chapter 8: “Web application firewalls and client-side filters”

WAFs are a common device used to protect Web applications from malicious attacks. Such devices typically use a list of regular expressions to detect malicious input. This makes them prime targets for bypassing and attacking using Web application obfuscation techniques. This chapter will demonstrate the ineffectiveness of many WAFs at defending against even the most basic obfuscation techniques. In addition to traditional WAFs, this chapter also discusses client-side filters built into browsers. These filters will help raise the bar an attacker must clear to perform successful attacks. We will look at the details of how these filters work and see some specific and highly obfuscated ways in which they can be bypassed.

Read full chapter

URL: https://www.sciencedirect.com/science/article/pii/B9781597496049000017

Web Application Recon and Scanning

Josh Pauli, in The Basics of Web Hacking, 2013

Reviewing ZAP Results

Once the active scanning has completed, you can review the findings in the Alerts tab where a tree structure will display the discovered vulnerabilities. It’s not surprising that our DVWA application has several existing vulnerabilities (that’s the whole point!) as illustrated by the SQL injection finding here. ZAP provides a brief description of the vulnerability, what page it was discovered on (login.php in this example), and the parameter’s value that triggered the finding as shown in Figure 3.15.

What is the type of attack called by injecting malicious code in a websites form input?

Figure 3.15. Single item in the Alerts tab in ZAP.

We now have the exact URL to attack and we know the parameter that is vulnerable. Instead of using a benign proof-of-concept request sent to the web application, we can send in malicious input to compromise the web application. We can perform this attack in the actual HTML form field in a browser if we want to type our malicious input there, or we can use a proxy to intercept the request and edit the parameter’s value. We can even use additional tools, such as sqlmap, to exploit the application. We will be doing a little bit of each of these scenarios coming up during the actual web application hacking.

The full report of ZAP Scanner’s findings can be exported as HTML or XML via the Reports menu. As soon as you save the report file as HTML, as shown in Figure 3.16, it will open in your default browser for you to review further.

What is the type of attack called by injecting malicious code in a websites form input?

Figure 3.16. Saving the exported file from ZAP to the root directory.

The full report details the findings for each of the discovered vulnerability in the same format as the Alerts tab view. Below is the report entry for an SQL injection vulnerability on the include.php page. The most important parts are the URL and the parameter value that triggered the vulnerability.

Alert Detail:

High (Suspicious): SQL Injection Fingerprinting

Description: SQL injection may be possible.

URL: http://127.0.0.1/vulnerabilities/fi/?page=include.php'INJECTED_PARAM

Parameter: page=include.php'INJECTED_PARAM

...

Solutions:

Do not trust client side input even if there is client side validation. In general,

If the input string is numeric, type check it.

If the application used JDBC, use PreparedStatement or CallableStatement with parameters passed by '?'

If the application used ASP, use ADO Command Objects with strong type checking and parameterized query.

If stored procedure or bind variables can be used, use it for parameter passing into query. Do not just concatenate string into query in the stored procedure!

Do not create dynamic SQL query by simple string concatentation.

Use minimum database user privilege for the application. This does not eliminate SQL injection but minimize its damage. Eg if the application require reading one table only, grant such access to the application. Avoid using 'sa' or 'db-owner'.

...

Read full chapter

URL: https://www.sciencedirect.com/science/article/pii/B9780124166004000034

Platform-Level Defenses

Justin Clarke, in SQL Injection Attacks and Defense, 2009

Intrusion Detection Capabilities

Lastly, WAFs should be able to monitor application behavior passively, take action in the event of suspicious behavior, and maintain a non-reputable log of events for a forensic analysis following an SQL injection incident. The logs should give you the information to determine whether your application was attacked and provide enough information for reproducing the attack string. Blocking and rejecting malicious input aside, the ability to add intrusion detection features to your application without changing a line of code is a strong argument for the use of WAFs. When performing a forensic analysis following an SQL injection incident, nothing is more frustrating than having to rely on Web server log files, which often contain only a small subset of the data sent in the request.

In summary, with ModSecurity it is possible to stop SQL injection attacks, patch a known SQL injection vulnerability, detect attack attempts, and suppress SQL error messages that often facilitate exploitation of SQL injection vulnerabilities. Now that we've discussed ModSecurity and WAFs in general, we're going to look at some solutions that could be considered a WAF but are not as robust. However, they can be just as effective depending on the scenario, and they can be potentially cheaper in cost and resource requirements to deploy.

Read full chapter

URL: https://www.sciencedirect.com/science/article/pii/B9781597494243000098

Web User Hacking

Josh Pauli, in The Basics of Web Hacking, 2013

Cross-Site Scripting (XSS) Attacks

The classic proof-of-concept for XSS is to use a JavaScript alert box that pops up when the code runs in the victim’s browser. This by itself is certainly not malicious, but it does show that inserted JavaScript is returned by the application to the user’s browser. XSS can spell absolute disaster for an application and its users if an attacker formulates a more malicious payload.

XSS attacks are a good training ground for encoding and decoding schemes as they are used heavily in URL parameters and the input validation routines deployed by application defense mechanisms. It’s not critical that you know the exact encoding scheme being used, but it is critical that you know how to encode and decode your malicious input to work around safeguards that have been put in place. There are several encoding schemes that you will come across when dealing with XSS, but some of the most popular are:

Base64

URL

HTML

ASCII Hexadecimal

UTF-8

Long UTF-8

Binary

UTF-16

UTF-7

Most of the hacking suites available today, including Burp Suite, have built-in tools with the functionality to assist with encoding and decoding parameter values.

One factor that you must understand when working with XSS is the same origin policy in a browser, which permits scripts running on pages originating from the trusted site without restriction, but prevents access to different sites. For example, the same origin policy won’t allow a script from www.l33thacker.net to execute if the user didn’t request a www.l33thacker.net page. The same origin policy provides a clear separation between trusted and untrusted sites in the browser to ensure the integrity of the browsing session on the client side. The browser must trust the site that is responding with a script. This is why, as a hacker, you must find an XSS vulnerability in the application that the user trusts in order for malicious script to be executed in the victim’s browser.

XSS Payloads

There are some very damaging payloads that XSS is capable of delivering. Because JavaScript is such a flexible and powerful language, you are only restricted by your imagination when it comes to considering what is possible with XSS. Some of the most popular XSS payloads include:

Pop-up alert boxes used mostly for proof-of-concept attacks

Hijacking session identifiers

Downloading and installing software

Redirecting the victim’s browser to a different URL

Installing a key logger

Invoking a reverse shell back to the attacker

Launching client-side attacks (attacks on browsers, for example)

I like to think of XSS as hacker input being allowed to run “all natural” in the victim’s browser because of unworthy safeguards coded into the application. Encoding and decoding values play a large part of XSS attacks, so you must have a basic understanding of how to identify and use encoded values. An intercepting proxy will also be a useful tool during XSS as you work to evade the input filters in place on the web application designed to prevent XSS.

Read full chapter

URL: https://www.sciencedirect.com/science/article/pii/B978012416600400006X

Structured Query Language Injection

Mike Shema, in Seven Deadliest Web Application Attacks, 2010

Alternate Attack Vectors

Just as Monty Python didn't expect the Spanish Inquisition, developers may not expect SQL injection vulnerabilities to arise from certain sources. Web-based applications lurk in all sorts of guises and work with data from all manner of sources. For example, consider a Web-driven kiosk that scans bar codes (UPC symbols) to provide information about the item, or a warehouse that scans Radio Frequency Identification (RFID) tags to track inventory in a Web application. Both the bar code and RFID represent user-supplied input, albeit a user in the sense of an inanimate object. Now, a DVD or a book doesn't have agency and won't spontaneously create malicious input. On the other hand, it's not too difficult to print a bar code that contains a single quote – our notorious SQL injection character. Figure 3.1 shows a bar code that contains such a quote. (The image uses Code 128. Not all bar code symbologies are able to represent a single quote or nonnumeric characters.)

What is the type of attack called by injecting malicious code in a websites form input?

FIGURE 3.1. Bar Code of SQL Doom

You can find bar code scanners in movie theaters, concert venues, and airports. In each case, the bar code is used to encapsulate a unique identifier stored in a database. These applications require SQL injection countermeasures as much as the more familiar Web sites with readily accessible URI parameters.

Metainformation within binary files, such as images, documents, and PDFs, may also be a delivery vector for SQL injection exploits. Most modern cameras tag their digital photos with Exchangeable Image File Format (EXIF) data that can include date, time, GPS coordinates, or other textual information about the photo. If a Web site extracts and stores EXIF tags in a database, then it must treat those tags as untrusted data like any other data supplied by a user. Nothing in the EXIF specification prevents a malicious user from crafting tags that carry SQL injection payloads. The metainformation inside binary files poses other risks if not properly validated, as described in Chapter 1, “Cross-Site Scripting.”

Read full chapter

URL: https://www.sciencedirect.com/science/article/pii/B9781597495431000037

SQL Injection & Data Store Manipulation

Mike Shema, in Hacking Web Apps, 2012

Alternate Attack Vectors

Monty Python didn’t expect the Spanish Inquisition. Developers may not expect SQL injection vulnerabilities from certain sources. Web-based applications lurk in all sorts of guises and work with data from all manner of sources. For example, consider a web-driven kiosk that scans bar codes (UPC symbols) in order to provide information about the item or a warehouse that scans RFID tags to track inventory in a web application. Both the bar code and RFID represent user-supplied input, albeit a user in the sense of an inanimate object. Now, a DVD or a book doesn’t have agency and won’t spontaneously create malicious input. On the other hand, it’s not too difficult to print a bar code that contains an apostrophe—our notorious SQL injection character. Figure 4.2 shows a bar code that contains such a quote. (The image uses Code 128. Not all bar code symbologies are able to represent an apostrophe or non-numeric characters.)

What is the type of attack called by injecting malicious code in a websites form input?

Figure 4.2. Bar Code Of SQL Doom

You can find bar code scanners in movie theaters, concert venues, and airports. In each case the bar code is used to encapsulate a unique identifier stored in a database. These applications require SQL injection countermeasures as much as the more familiar web sites with readily-accessible URI parameters.

The explosive growth of mobile devices has made a bar code-like technology popular: the QR code. People have become accustomed to scanning QR codes with their mobile devices, to the point where they would make excellent Trojan images for HTML injection and CSRF attacks. (QR codes may contain links.) The codes can also contain text. So, if there were ever an application that read QR code data into a database insecurely, it could fall prey to an image like Figure 4.3:

What is the type of attack called by injecting malicious code in a websites form input?

Figure 4.3. SQL Injection Via QR Code

Meta-information within binary files such as images, documents, and PDFs may also be a delivery vector for SQL injection exploits. Most modern cameras tag their digital photos with EXIF data that can include date, time, GPS coordinates or other textual information about the photo. If a web site extracts and stores EXIF tags in a database then it must treat those tags as untrusted data like any other data supplied by a user. Nothing in the EXIF specification prevents a malicious user from crafting tags that carry SQL injection payloads. The meta-information inside binary files poses other risks if not properly validated as described in Chapter 2: HTML Injection & Cross-Site Scripting.

Read full chapter

URL: https://www.sciencedirect.com/science/article/pii/B9781597499514000047

Introduction to Metasploit

David Maynor, K.K. Mookhey, in Metasploit Toolkit for Penetration Testing, Exploit Development, and Vulnerability Research, 2007

Overview: Why Is Metasploit Here?

Metasploit came about primarily to provide a framework for penetration testers to develop exploits. The typical life cycle of a vulnerability and its exploitation is as follows:

1.

Discovery A security researcher or the vendor discovers a critical security vulnerability in the software.

2.

Disclosure The security researcher either adheres to a responsible disclosure policy and informs the vendor, or discloses it on a public mailing list. Either way, the vendor needs to come up with a patch for the vulnerability.

3.

Analysis The researcher or others across the world begin analyzing the vulnerability to determine its exploitability. Can it be exploited? Remotely? Would the exploitation result in remote code execution, or would it simply crash the remote service? What is the length of the exploit code that can be injected? This phase also involves debugging the vulnerable application as malicious input is injected to the vulnerable piece of code.

4.

Exploit Development Once the answers to the key questions are determined, the process of developing the exploit begins. This has usually been considered a bit of a black art, requiring an in-depth understanding of the processor's registers, assembly code, offsets, and payloads.

5.

Testing This is the phase where the coder now checks the exploit code against various platforms, service pack, or patches, and possibly even for different processors (e.g., Intel, Sparc, and so on).

6.

Release Once the exploit is tested, and the specific parameters required for its successful execution have been determined, the coder releases the exploit, either privately or on a public forum. Often, the exploit is tweaked so that it does not work right out of the box. This is usually done to dissuade script kiddies from simply downloading the exploit and running it against a vulnerable system.

All of this has undergone a bit of a paradigm shift. With Metasploit it is now quite straightforward for even an amateur coder to be able to write an exploit. The framework already comes with more than 60 exploits pre-packaged to work right out of the box. The development of new exploits is proceeding at a rapid pace, and as the popularity of the tool soars, the availability of exploits is also likely to increase. This is quite similar to the large number of plugins that Nessus now has.

But this is only part of the story. Where Metasploit really comes into its own is in the way it has been architected and developed. It is now likely to become the first free (partially open-source, since it is now distributed under its own Metasploit License) security tool, which covers the entire gamut of security testing—recon modules to determine vulnerable hosts and interface with scanners such as Nmap and Nessus, exploits and payloads to attack the specific vulnerabilities, and post-exploitation goodies to stealthily own the system, and possibly the entire network.

What Is Metasploit Intended for and What Does It Compete with?

The MSF is an open-source tool, which provides a framework for security researchers to develop exploits, payloads, payload encoders, and tools for reconnaissance and other security testing purposes. Although, it initially started off as a collection of exploits and provided the ability for large chunks of code to be re-used across different exploits, in its current form it provides extensive capabilities for the design and development of reconnaissance, exploitation, and post-exploitation security tools.

The MSF was originally written in the Perl scripting language and included various components written in C, assembler, and Python. The project core was dual-licensed under the GPLv2 and Perl Artistic Licenses, allowing it to be used in both open-source and commercial projects. However, the 3.0 version of the product is now completely re-written in Ruby and comes with a wide variety of APIs. It is also now licensed under the MSF License, which is closer to a commercial software End User License Agreement (EULA) than a standard open-source license. The basic intent is to:

Allow the MSF to remain open-source, free to use, and free to distribute.

Allow module and plugin developers to choose their own licensing terms.

Prevent the MSF from being sold in any form or bundled with a commercial product (software, appliance, or otherwise).

Ensure that any patches made to the MSF by a third party are made available to all users.

Provide legal support and indemnification for MSF contributors.

The MSF competes directly with commercial products such as Immunity's CANVAS and Core Security Technology's IMPACT. However, there is a major difference between the MSF and these commercial products in terms of its objectives. The commercial products come with user-friendly graphical user interfaces (GUIs) and extensive reporting capabilities in addition to the exploit modules, whereas the MSF is first and foremost a platform to develop new exploits, payloads, encoders, No Operator (NOP) generators, and reconnaissance tools. Moreover, it is also a platform to design tools and utilities that enable security research and the development of new security testing techniques.

Read full chapter

URL: https://www.sciencedirect.com/science/article/pii/B9781597490740500039

Recent Advances in Model-Based Testing

Mark Utting, ... Alexandre Vernotte, in Advances in Computers, 2016

6.2.3 Fuzzing Approaches

Fuzzing is extensively used in vulnerability testing [137] to introduce malformed data or mutate nominal values to trigger flawed code in applications. Fuzzing techniques are usually very cheap to deploy, do not suffer from false positives, but lack an expected-result model and therefore rely on crashes and fails to assign a verdict. Two main fuzzing techniques exist: mutation based and generation based. Mutation fuzzing consists of altering a sample file or data following specific heuristics, while generation-based fuzzers take the input specification and generate test cases from it. Fuzzing may be used for crafting malicious input data [138], or crafting erroneous communication messages [139].

The approach presented by Duchene [138] consists of modeling the attacker's behavior, and driving this model by a genetic algorithm that evolves SUT input sequences. It requires a state-aware model of the SUT, either derived from an ASLan++ description or inferred from traces of valid/expected SUT execution. This model is then annotated using input taint data-flow analysis, to spot possible reflections. Concrete SUT inputs are generated with respect to an Attack Input Grammar which produces fuzzed values for reflected SUT input parameters. The fitness function depends on the obtained SUT output following the injection of a concrete SUT input. It computes the veracity of an input by looking for correlations, using the string distance between a given input parameter value and a substring of the output. Two genetic operators are used: mutation and cross-over. It is an efficient technique for detecting XSS, as it goes beyond the classical XSS evasion filters that may not be exhaustive. Such a technique also tackles multistep XSS discovery by using a more complex string matching algorithm to generate an annotated FSM, in order to inspect the SUT to find the possibilities of XSS at certain places.

A model-based behavioral fuzzing approach has been designed by Wang et al. [139] to discover vulnerabilities of Database Management Systems (DBMS). A DBMS defines a format rule that specifies packet format and a behavior rule that specifies its semantics and functionality. This approach is based on two main artifacts. The first artifact is a behavioral model, which includes fuzzing patterns and behavioral sequences. This is obtained from a behavior analysis of DBMS (protocol format analysis, attack surface analysis, etc.). A fuzzing pattern expresses the data structure of packets, the needs of security testing, and the design strategy for vulnerability discovery. A behavioral sequence defines the message transfer order between client and DBMS. The second artifact is a DBMS Fuzzer composed of a test instance (a detailed test script based on fuzzing patterns), and a finite state machine model EXT-NSFSM used for semivalid test case generation based on behavioral sequences and test instances. The authors describe a general framework for behavioral fuzzing that has been implemented and used in several experiments. It allows for the generation of thousands of fuzzing instances, and despite a few errors of analysis and script, the tool was able to discover buffer overflow vulnerabilities, 10 of which were not released yet.

Read full chapter

URL: https://www.sciencedirect.com/science/article/pii/S0065245815000650

What type of attack is code injection?

Code injection is the term used to describe attacks that inject code into an application. That injected code is then interpreted by the application, changing the way a program executes. Code injection attacks typically exploit an application vulnerability that allows the processing of invalid data.

What attacks can execute the code injected by attackers?

Description. Code Injection is the general term for attack types which consist of injecting code that is then interpreted/executed by the application. This type of attack exploits poor handling of untrusted data.

What is web injection attack?

In this type of attack, an attacker exploits the failure of the web application to filter data provided by users before it inserts that data into a server-side interpreted HTML file. XPath Injection. Exploits web sites that allow an attacker to inject data into an application in order to execute XPath queries.

What is code injection and its types?

Code injection vulnerabilities occur when an application sends untrusted data to an interpreter. Injection flaws are most often found in SQL, LDAP, XPath, NoSQL queries, OS commands, XML parsers, SMTP headers, program arguments, etc.