Git Product home page Git Product logo

xpath-injection's Introduction

XPath injection sample written in PHP

This sample is created to show XPath Injection vulnerability, exploit and patch it.

Base XPath Query

//users/user[username = '$username' and password = '$password']

Exploit

  • Bypass Authentication using supplied password

    Username: admin (or any valid username)

    Password: ' or username = 'admin

    You can use this technique for both bypass authentication and username enumeration.

  • Get password length

    Username: admin

    Password: ' or string-length(password) = 1 and username = 'admin

    If admin password length equals to 1 character, you will be logged in (and receive status code 200) otherwise won't (and receive status code 401). You should increase value password length until you get the correct reponse (status code 200).

  • Extract password character by character

    Username: admin

    Password: ' or username = 'admin' and substring(password,1,1) = 'a

    If the first character of the admin password equals to 'a' character, you will be logged in (and receive status code 200) otherwise won't (and receive status code 401).

You could use python script xpath-injection-exploit.py to exploit this target more easily.

Patch

The user input should be checked against a whitelist of acceptable characters. The best approach is to reject any input that does not match the whitelist and not sanitize it therefore characters that may be used to interfere with the XPath query should be blocked, including ( ) [ ] ' = : , * / .

In this sample uncomment line 23 & 24 to patch the vulnerability.

Patch at the code level:

function prevent_xpath_injection(string $input){
    $input = trim($input);
    if (preg_match('/[^a-zA-Z0-9]/',$input)){
        // input is malformed
        return false
    }
    else {
        return true;
    }
}

xpath-injection's People

Contributors

amir-h-fallahi avatar

Stargazers

Amir Hossein Fallahi avatar AVA avatar Maria Ushakova avatar  avatar AmirAbbas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.