💻
OSWE Everything
💻
OSWE Everything
  • VULNERABILITIES
    • Type Juggling
    • Cross Site Scripting
      • Hunting for files
    • Insecure Deserialization
      • .NET
    • SQL Injection
      • Blind SQL Injection
      • SQLi debugging
      • Code review
      • Errors and additional information
      • Approaches to leverage different databases
    • XML External Entity (XXE)
      • Types of XML Entities
      • Exploitation
      • Wrappers for errors
      • Post Exploitation
    • OS Command Injection
      • Exploitation
    • Server Side Template Injection
      • Exploitation
    • Authentication Bypass
      • Checklist
  • Unsecure Random Function
    • Exploitation
  • Cross Origin Resource Sharing (CORS)
    • Prerequisites of Exploitation
  • Client Side Request Forgery (CSRF)
    • Prerequisites of Exploitation
  • Exploit Writing
    • Cheatsheet
    • Skeleton Scripts
  • Code review
    • Manual code review
      • Routing
      • Searching for exploits
      • Debugging
    • Decompilation
      • Java
      • .NET
    • Managing the application
      • Identifying application file location
      • Restarting web applications
      • Manipulation of Assembly Attributes for Debugging (.NET)
  • Preparation Machines
    • [HTB] Vault
    • Other HTB scripts
  • ADDITIONAL INFORMATION
    • Sources
  • External Resources
    • WhiteBox Pentest
Powered by GitBook
On this page
  • What is Type Juggling
  • Video Explaination
  • How to find it
  • Changing the parameter type
  • Payload creation
  1. VULNERABILITIES

Type Juggling

NextCross Site Scripting

Last updated 2 months ago

What is Type Juggling

PHP is a loosely typed language, which means it tries to predict the programmer's intent and automatically converts variables to different types whenever it seems necessary. For example, a string containing only numbers can be treated as an integer or a float. However, this automatic conversion (or type juggling) can lead to unexpected results, especially when comparing variables using the '==' operator, which only checks for value equality (loose comparison), not type and value equality (strict comparison).

Video Explaination

How to find it

During the code review in PHP applications look for if statements which do not check the type of variable:

Vulnerable code:

if ($variable == $variable_2) {
    // code
}

Not vulnerable code:

if ($variable === $variable_2) {
    // code
}

Changing the parameter type

When it comes to PHP applications they are usually written in Laravel framework. Laravel has Middleware API which is able to handle submitted data both as a parameter and in request body as JSON.

Importance of this information lies in fact that during the JSON submittion we can specify the parameter type which cannot be done while sending the regular parameter in URL.

Attacker can be able deliver boolean instead of string in this way which can cause application misbehaviour leading to some serious vulnerability.

Payload creation

The table below will help you in crafting the payload. It contains the PHP true statements which can be used during the type juggling vulnerability.

Statement
Output

'0010e2' == '1e3'

true

'0xABCdef' == ' 0xABCdef'

true (PHP 5.0) / false (PHP 7.0)

'0xABCdef' == ' 0xABCdef'

true (PHP 5.0) / false (PHP 7.0)

'0x01' == 1

true (PHP 5.0) / false (PHP 7.0)

'0x1234Ab' == '1193131'

true (PHP 5.0) / false (PHP 7.0)

'123' == 123

true

'123a' == 123

true

'abc' == 0

true

'' == 0 == false == NULL

true

'' == 0

true

0 == false

true

false == NULL

true

NULL == ''

true