Rabu, 15 September 2021

Multi Query MySQL PHP native

MySQL optionally allows having multiple statements in one statement string, but it requires special handling.

Multiple statements or multi queries must be executed with mysqli::multi_query(). The individual statements of the statement string are separated by semicolon. Then, all result sets returned by the executed statements must be fetched.

The MySQL server allows having statements that do return result sets and statements that do not return result sets in one multiple statement. 

Example #1 Multiple Statements

<?php

mysqli_report
(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("example.com", "user", "password", "database");

$mysqli->query("DROP TABLE IF EXISTS test");
$mysqli->query("CREATE TABLE test(id INT)");

$sql = "SELECT COUNT(*) AS _num FROM test;
        INSERT INTO test(id) VALUES (1); 
        SELECT COUNT(*) AS _num FROM test; "
;

$mysqli->multi_query($sql);

do {
    if (
$result = $mysqli->store_result()) {
        
var_dump($result->fetch_all(MYSQLI_ASSOC));
        
$result->free();
    }
} while (
$mysqli->next_result());

 The above example will output:

array(1) {
  [0]=>
  array(1) {
    ["_num"]=>
    string(1) "0"
  }
}
array(1) {
  [0]=>
  array(1) {
    ["_num"]=>
    string(1) "1"
  }
}

Security considerations

The API functions mysqli::query() and mysqli::real_query() do not set a connection flag necessary for activating multi queries in the server. An extra API call is used for multiple statements to reduce the damage of accidental SQL injection attacks. An attacker may try to add statements such as ; DROP DATABASE mysql or ; SELECT SLEEP(999). If the attacker succeeds in adding SQL to the statement string but mysqli::multi_query is not used, the server will not execute the injected and malicious SQL statement. 

Example #2 SQL Injection

<?php
$mysqli 
= new mysqli("example.com", "user", "password", "database");
$result    = $mysqli->query("SELECT 1; DROP TABLE mysql.user");
if (!
$result) {
    echo 
"Error executing query: (" . $mysqli->errno . ") " . $mysqli->error;
}
?>
 
The above example will output:
 
Error executing query: (1064) You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax 
to use near 'DROP TABLE mysql.user' at line 1
 
Sumber :
https://www.php.net/manual/en/mysqli.quickstart.multiple-statement.php
https://www.it-swarm-id.com/id/php/menjalankan-beberapa-query-sql-dalam-satu-pernyataan-dengan-php/1070208427/ 

Minggu, 29 Agustus 2021

Install MobSF Ubuntu 20.04.2 LTS

 Update Repository Ubuntu

$ sudo apt get update

Install git
$ sudo apt install git

Install python package
$ sudo apt install python3-pip python3-venv python3-pip python3-dev build-essential libffi-dev libssl-dev libxml2-dev libxslt1-dev libjpeg8-dev zlib1g-dev

Install jdk
$ sudo apt install default-jre

Clone MobSF from github (15/1/2020)
$ sudo git clone https://github.com/MobSF/Mobile-Security-Framework-MobSF.git

Chdir to MobSF clone dir
$ cd Mobile-Security-Framework-MobSF

Run the Setup
$ ./setup.sh

Run MobSF Service
$ ./run.sh

Open MobSF Interface in browser
http://localhost:8000

HOWTO : Install DVWA on Ubuntu 18.04.1 LTS

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is damn vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, help web developers better understand the processes of securing web applications and aid teachers/students to teach/learn web application security in a class room environment.


Step 1 :

sudo apt install php7.2 php7.2-gd php-mysql mysql-server apache2 git

Set the MySQL server password as prompt.

Step 2 :

sudo mysql -u root -p

CREATE DATABASE dvwadb;

GRANT ALL PRIVILEGES ON dvwadb.* TO ‘dvwa’@’localhost’ IDENTIFIED BY ‘dvwapassword’;


Step 3 :

sudo nano /etc/php/7.2/apache2/php.ini

Change the "Off" to "On" :

allow_url_include = On

Step 4 :

cd /var/www/html

sudo git clone https://github.com/ethicalhack3r/DVWA.git

cd /var/www/html/DVWA

sudo chmod 777 /var/www/html/DVWA/config
sudo chmod 666 /var/www/html/DVWA/external/phpids/0.6/lib/IDS/tmp/phpids_log.txt
sudo chmod 777 /var/www/html/DVWA/hackable/uploads/


Step 5 :

sudo nano /etc/apache2/sites-enabled/000-default.conf

Append "/DVWA" as the end of "/var/www/html" :

DocumentRoot /var/www/html/DVWA

Step 6 :

sudo cp /var/www/html/DVWA/config/config.inc.php.dist /var/www/html/DVWA/config/config.inc.php

sudo nano /var/www/html/DVWA/config/config.inc.php


Make changes as the following :

$_DVWA[ 'db_server' ] = '127.0.0.1';
$_DVWA[ 'db_database' ] = 'dvwadb';
$_DVWA[ 'db_user' ] = 'dvwa';
$_DVWA[ 'db_password' ] = 'dvwapassword';


Step 7 :

Go to https://www.google.com/recaptcha/admin to generate the keys for 'Insecure CAPTCHA' module and add to the related items at "config.inc.php".

Step 8 :

sudo systemctl restart apache2

Step 9 :

http://[server_ip_address]

The username is "admin" while the password is "password".

Beware that the DVWA is vulnerable and do not allow it to be accessed via public.

Step 10 (Optional) :

sudo apt install php7.2-fpm

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.2-fpm


That's all! See you.

Sabtu, 19 Juni 2021

Disable Auto Update Proxmox Environment 5-2-5

 Cara menonaktifkan auto update pada Proxmox 5-2-5

#systemctl status pve-daily-update.timer
Output
● pve-daily-update.timer - Daily PVE download activities
   Loaded: loaded (/lib/systemd/system/pve-daily-update.timer; enabled; vendor p
   Active: active (waiting) since Sat 2021-06-19 21:51:12 WIB; 16min ago

Jun 19 21:51:12 drc-ebanking systemd[1]: pve-daily-update.timer: Adding 3h 42min
Jun 19 21:51:12 drc-ebanking systemd[1]: Started Daily PVE download activities.


#systemctl stop pve-daily-update.timer
#systemctl disable pve-daily-update.timer

Output
● pve-daily-update.timer - Daily PVE download activities
   Loaded: loaded (/lib/systemd/system/pve-daily-update.timer; disabled; vendor
   Active: inactive (dead)

Jun 19 21:51:12 drc-ebanking systemd[1]: pve-daily-update.timer: Adding 3h 42min
Jun 19 21:51:12 drc-ebanking systemd[1]: Started Daily PVE download activities.
Jun 19 22:12:05 drc-ebanking systemd[1]: Stopped Daily PVE download activities.

Senin, 19 April 2021

Menambahkan Swap pada Linux Ubuntu 18.04

 Pada umumnya swap dibuat dalam partisi Linux. Tapi bagaimana jika sistem Linux yang berjalan tidak terdapat partisi swap seperti pada Linux VPS (Virtual Private Server), hanya tersedia partisi / (root) saja. Solusinya adalah dengan membuat swap file.

1. perintah free -h Terlihat nilai total Swap = 0 apabila tidak ada swap akti.
2. Menyiapkan Swap File
   Di sini kita akan membuat swap file sebesar 2GB menggunakan perintah dd. bs=1024 adalah baca dan tulis sebesar 1024 byte dalam    satu waktu. Dan count=(1024×2048) ukuran file/block.

   sudo dd if=/dev/zero of=/swapfile bs=1024 count=2097152

3. Mengaktifkan Swap File
   Selanjutnya menjadikan swapfile sebagai swap dengan perintah mkswap.

   sudo mkswap /swapfile

4. Selanjutnya mengaktifkan swap dengan perintah swapon.

   sudo swapon /swapfile

   sudo swapoff -a bila akan menonaktifkan swap

5. Jalankan perintah free -h untuk melihat RAM dan Swap. Pada gambar di bawah ini, terdapat Swap dengan kapasitas 2GB.

6. Auto mount Swap
   Agar Swap langsung aktif secara otomatis ketika sistem boot, tambahkan konfigurasi pada file /etc/fstab.

   sudo nano /etc/fstab

   Tambahkan
   /swapfile none swap sw 0  0

7. sudo reboot


Salam

Partisi ext4 tambahan pada linux Ubuntu

 Dalam linux terdapat beberapa partisi hampir sama dengan OS Windows yaitu ada C,D,E dan seterusnya
kalau partisi pada OS linux mulai dari sda, sdb, sdc dan seterusnya
apabila kita akan meambahkan Hardware baru ( HDD baru) maka cukup menambahkan perintah sebagai berikut dengan menyesuaikan hdd yang terbaca pada system, sebagai contoh akan memartisi hdd dengan id sdb

mkfs.ext4 /dev/sdb 2>/dev/null

 

salam