Evasion Basics
Some basic techniques for evasion in WEB APP scenario
Base64 Encoding Evasion
Lets suppose that we want to evade a system that inspects Javascript code For specific keywords like eval, alert, prompt, document.cookie, or other potential malicious strings.
A possible way to escapse these kinds of filters is by using Base64 encoding.
Cookie Stealer
To steal cookies, not marked as HttpOnly is relatively easy and we commonly use this JavaScript payload:
however often the document.cookie keyword may be detected and blocked
Use Base64 encoding, we can hide document.cookie code translating the attack vector into:
perhaps the eval function is blacklisted too, so lets see alternatives:
in Javascript:
Other valid methods are:
URI Obfuscation Techniques
URI (Uniform (local/remote) Resource Identifier
It can not only be handy in byṕassing a filtered system, but also to shorten the vector to respect a length limit.
URL Shortening
Its a technique in which a URL may be shorter in length and still direct to the required page.
Running your own URL shortener is simple and there are multiple services and libraries that allow you to start the service easily, such as:
Preview
Some shortening services implement their technique to show the preview or some information abou the shortened link
bitly uses + signal:
There are services that do not provide this feature, such as:
For this kind of service, online solutions exists:
cURL Link Resolver
U can do it manually:
URL Hostname Obfuscation
normally URLs are used in formats like:
→ https://hack.me/test
but RFC
RFC 3986 tells us that the these are also valid URLs:
https://hack.me:443
https://[this_is_valid]@hack.me
We want to obfuscate the Authority component of a URI: foo://example.com:8042/over/there?name=ferret#nose
The Authority component is structured as follows:
Obfuscating with Userinfo
The userinfo subcomponent is used For authentication. If credentials are required to access a resource, they can be included here, and the login will be automatic:
Example:
https://www.google.com@hack.me/t/xss
hack.me does not implement this kind of authentication and will ignore the www.google.com part (userinfo)
In the userinfo subcomponent, Unicode is allowed, therefore, it does not need other additional clarifications if we want add signals or letter of other languages.
not all browser support this obfuscation technique. Firefox and Opera show alert messages.
Obfuscating with Host
Internet names are translated to IP addresses. But there are other ways to represent the same number, such as: Dword, Octal, Hexadecimal.
Dword - google.com
Double Word is known as Integer IP. IP is translated to an equivalent 16bit number.
Octal - google.com
we can also feed each number by adding leading zeroes without break the original value
Hexadecimal - google.com
its also possible to add zeroes like 0x000000d8 …
Hybrid
these are the basic techniques, however, its also possible to mix these and create a hybrid
this tool apply all the techniques discussed
→ http://www.silisoftware.com/tools/ipconverter.php
Java Obfuscation Techniques
Non-Alphanumeric
Its way to encode Javascript code by using only non-alphanumeric characters.
Booleans
There are many ways to return a Boolean value using non-alphanumeric characters:
![ ]
!![ ]
!{ }
!!{ }
!!” “
!” “
[ ]=={ }
[ ]==””
To extract the true or false string:
Numbers
Can be created. true is 1 and false is 0;
to generate 1 we can do true+false and 2 true+true… etc
Examples: number zero 0:
-“”
-[ ]
![ ]+!{ }
-+-+””
-+-+[ ]
![ ]+!!””
String
How to generate custom strings. For example if we wanna generate the alert string, we need to generate each character separately and then put them together.
Generate alert string
We need to use the string output of native JavaScript objects and extract the characters required. Example:
So to extract the alpha char a we use the Nan String and acces the position 1:
The remaining alpha characters can be generated using the following messages:
Encoding
Based on this technique:
JavaScript Compressing
To make JavaScript run faster, developers often use tools that compile JavaScript into more compact and higher performing code. By using these tools, its also possible to obfuscate code and evade detection. This is what we are going to be looking For in this chapter.
Minifying
The process of minifying JavaScript code is by removing all unnecessary characters without changing the functionality of the original code. Basically, all characters that are used to add readability to the code is removed. These characters are ignored by the interpreter. Examples of these are: whitespaces, new line, comments. Some tools:
Packing
A packer compresses the minified code by shortening variable names, functions and other operations. In other words, it makes the code unreadable.
PHP Obfuncations Techniques
They ways of PHP obfuscation are infinite…
Basic Language Reference
Type Juggling
PHP is a dynamically typed language. PHP does not require/support explicit type definition in variable declaration Basically, we can declare the same variable and as we assign different values (string, int, etc) the type of the variable changes.
Numerical Data Types
Access String / Integer Numbers
How the structure For integer literals are:
decimal
hexadecimal
octal
binary
[1-9][0-9]* or 0
0[xX][0-9a-fA-F]+
0[0-7]+
0b[01]+
Access String / Floating Numbers
How the structure For floating literals are:
LNUM
DNUM
EXPONENT_DNUM
[0-9]+
([0-9]*[.]{LNUM})
({LNUM}[.][0-9]*)
[+-]?(({DNUM}
{DNUM}) [eE][+-]? {LNUM})
Exotic Number Generation
Its possible to use the casting functionalities PHP provides:
String Data Types
In PHP there are four different ways in which its possible to specify a string literal:
Escapes
Variable Parsing
Even arrays, object methods, class functions with numerical obfuscation are allowed.
Heredoc and Nowdoc
the preferred ways among command-line programmers
The identifier must contain only alphanumeric characters and underscores. It must also start with a non-digit char or underscore, thereby making these examples still valid:
Complex (curly) Syntax {…}
These are 3 different ways to define a variable named $Beer:
Example of obfuscation:
Array Data Types
A simple way to evade WAFs is to not only send your payload encrypted by using GET or POST, but also the key to decrypt via a custom header.
Variable Variables
Its a way to set a variable name dynamically:
its possible to add more dollar signs
with this way, its easy to create code very hard to read.
$_SERVER Superglobal
This is way to access the $_SERVER superglobal
PHP Non-Alphanumeric Code
Arithmetic Operators
php follows perls convention:
Character variable can only be incremented and not decremented. Only plain ASCII alphabets and digitsw (a-z, A-Z and 0-9) are supported.
Bitwise Operators
Its possible to use bitwise operators on strings. example:
Native PHP Objects
hackvertor.co.uk - It has 2 options to encode PHP into non-alphanumeric code.
Last updated