Git Product home page Git Product logo

php-xss-attacks's Introduction

php-xss-attacks

1- PHP Security: Include/require file extensions:

Dosya isimleri php uzantılı olmalı, yorumlayıcı sadece php olunca sensitive verileri gizliyor
video-1.

2- PHP Security: XSS (Cross-site Scripting):

Veritabanından alınan veriler ekrana yazdırılırken mutlaka escape edilmeli, db ye bir şekilde inject edilmiş zararlı yazılım varsa bunların kullanıcıda çalıştırılması engellenmesi için gerekli.
video-2.

   functions.php
	<?php
		// escape value
		function e($string){
  			return htmlspecialchars($string, ENT_QUOTES, ‘UTF-8’);
		}
	?>
	form.php {ORNEK BİR FORM SAYFASI İÇİN ORNEK KOD}
	<?php
		require ‘functions.php’
	?>
	<?php echo e($inputValue); ?>
	
        NOT: Sayfalarda head alanında <meta charset=“UTF-8”> olmalı

3- PHP Security: Password hashing:

Şifreler MD5 gibi decrypt edilebilen algoritmala ile db ye kayıt edilmemeli, Şifreler hashlenip db ye kayıt edilmeli, login işleminde şifre hashlenip db de karşılaştırılmalı.
video-3

  functions.php
	<?php
               // password-hash
		function ph($psw){
  			return password_hash($psw, PASSWORD_DEFAULT, [‘cost’ => 12]);
		}
		// password-verify
		function pv($pswDb, $pswSubmited){
  			return password_verify($pswSubmited, $psw);
		}
	?>

4- PHP Security: Directory listing:

Uygulama directory listening protect işlemi için .htaccess dosyası ana dizine eklenmeli video-4

  .htaccess	// root dizinde olmalı
		
		Options -Indexes
    

:5- PHP Security: HttpOnly Cookies:

Cookie de veriler açık şekilde tutulmamalı, mutlaka encrypt edilmiş olmalı video-5, video-6.

6- PHP Security: What you shouldn't store in cookies:

CSRF atakları için ilk önlem, form actionlarında isteklerin gerçekte olması gereken metodlar ile istekte bulunup bulunmadığı kontrol edilmeli.(POST, DELETE, PUT, GET).
video-7

  <?php
		if($_SERVER[‘REQUEST_METHOD’] !== ‘’POST){
			die();
		}
	?>

7- PHP Security: CSRF (Cross-site Request Forgery):

CSRF atakları için ikinci önlem, her sayfa isteğinde bootstrap.php (php bootstrapping) dosyasında sessiona form tokenı oluşturulup eklenmeli. form sayfaları içerisinde hidden alana bu tekken değer eklenmeli. Form action çağrıldığında bootstrap.php dosyasında istek türü post,put,patch,delete olanlar için session içerisindeki form token ile formdan gelen token kontrol edilmeli.

video-7

  bootstrap.php.php {ORNEK BİR bootstrap.php  SAYFASI İÇİN ORNEK KOD}
	<?php
		session_start();
		
		if($_SERVER[‘REQUEST_METHOD’] === ‘’POST){
			if(!isset($_POST[‘’token]) || ($_POST[‘’token] != $_SESSION[‘’_token]))
			die(‘’Invalid CSRF token);
		}	

		$_SESSION[‘’_token] = bin2hex(openssl_random_pseudo_bytes(16));
	?>
  herhangi_form.php
	 <form>
		//...
		<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>" />
		//...
	</form>

8- PHP Security: User defined file includes:

Sensitive (hassas, özel) veri içeren php dosyaları file_get_contents gibi metodlarla dinamik olarak okunmamalı.
video-8

  herhangi_dosya.php
	<?php
	if(!isset($_GET['show'])){
	  die();
	}
	$show = strtolower(trim($_GET['show']));
	
	$allowed = ['product','order','delivery'];
	
	$content = in_array($showi $allowed) ? file_get_contents('content/{$show}.php') : '';
	?>
	
	<!DOCTYPE html>
	<html lang="en">
		<head>
		<meta charset="UTF-8">
		<title>Dynamic file content loading</title>
		</head>
		<body>
			<?php echo $content; ?>
		</body>
	</html>

9- PHP Security: SQL Injection:

form inputlarından gelen veriler ile oluşturulan sql ifadelerinde input verileri doğrudan eklenmemeli video-9

	login.php
	<?php
	$db = new PDO('mysql:host=localhost:127.0.0.1;dbname=website;','root','root_psw');
	if(isset($_GET['email'])){
	  $email=$_GET['email'];
	  
	  // User control code examples are below.
	  
	  if($user->rowCount()){
	  	// login operation success
	  }
	}
	?>
	
	<!DOCTYPE html>
	<html lang="en">
		<head>
		<meta charset="UTF-8">
		<title>Login User</title>
		</head>
		<body>
			<form action="login.php" method="POST" autocomplete="off">
				<label for="email">
					Email
					<input type="text" name="email" id="email">
				</label>
				<input type="submit" value="login">
			</form>
		</body>
	</html>

NOT SECURE

	$user = db->query('SELECT * FROM user WHERE email={$email}');

SECURE

	 $user = db->prepare('SELECT * FROM user WHERE email = :email');
	 $user->execute([
	 	'email' => mysql_real_escape_string($email),
	 ]);

10- PHP Security: Error Reporting:

php.ini konfigurasyon dosyasındaki display_errors özelliğ off olmalı, aksi takdirde sensitive veriler kullanıcı tarafında ele geçirilebilir. Hata durumlarını loglama ile sistem yöneticisi tarafından daha güvenli takibi sağlanabilir video-10

php-xss-attacks's People

Contributors

umutyilmaz44 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.