SlideShare a Scribd company logo
HTTP AND SECURITY
AGENDA
HTTP basics
 HTTP methods
 PHP and HTTP
 Security threats and attacks
 Security in PHP

HTTP
The Hypertext Transfer Protocol (HTTP) is
an application protocol for distributed,
collaborative, hypermedia information systems
 HTTP is the foundation of data communication
for the World Wide Web.

HTTP
HTTP functions as a request-response protocol in
the client-server computing model
 The response contains completion status
information about the request and may also
contain requested content in its message body
 HTTP is an application layer protocol (mostly
TCP, but can use UDP)

HTTP SESSIONS
An HTTP session is a sequence of network
request-response transactions
 Every session has an ID and reflects conversation
between one client and server
 In PHP $_SESSION variable can hold session
parameters

HTTP METHODS













GET - Requests a representation of the specified resource
HEAD - likeGET request, but without the response body
POST - Requests that the server accept the entity enclosed
in the request as a new subordinate of the web resource
identified by the URI
PUT - Requests that the enclosed entity be stored under
the supplied URI
DELETE - Deletes the specified resource.
TRACE - Echoes back the received request so that a client
can see what changes or additions have been made by
intermediate servers.
OPTIONS - Returns the HTTP methods that the server
supports for the specified URL
CONNECT - Converts the request connection to a
transparent TCP/IP tunnel
PATCH - Is used to apply partial modifications to a
resource
HTTP GET
/test/demo_form.php?name1=value1&name2=val
ue2
 GET requests can be cached
 GET requests remain in the browser history
 GET requests can be bookmarked
 GET requests should never be used when dealing
with sensitive data
 GET requests have length restrictions (2048)
 GET requests should be used only to retrieve
data

HTTP POST
POST /test/demo_form.asp HTTP/1.1
 Host: w3schools.com
 name1=value1&name2=value2


POST requests are never cached
 POST requests do not remain in the browser
history
 POST requests cannot be bookmarked
 POST requests have no restrictions on data
length

PHP METHODS FOR POST AND GET
GET - $_GET variable
 POST - $_POST variable
 $_REQUEST for both + $_COOKIE


if (isset($_GET['user']) && isset($_GET['gen']))
{
 $user = $_GET['user'];
 $gen = $_GET['gen'];
 echo 'User: '. $user. ' - gender: '. $gen;
}

AND WORDPRESS
Wordpress core does not use sessions
 Wordpress core uses only cookies
 However plugins can use sessions

SECURITY INTRODUCTION
Weakest part of site is entry point
 Write your code secure!
 Don’t be victim of laziness and get hacked (or put
users in risk)
 It’s easier to protect then to heal

CROSS SITE SCRIPTING (XSS)
Adding additional HTML or javascript to source
of page
 Injectiong trough url parameters, requests or
form fields
 Stored XSS, Reflected, DOM based

XSS PROTECTION
Stripping tags
 Transform characters like <,>,/,’,” etc to html
entities
 Php functions:






string strip_tags ( string $str [, string
$allowable_tags ] )
string htmlentities ( string $string)
string htmlspecialchars( string $string)
SQL INJECTION
SQL injection is a code injection technique,
used to attack data driven applications, in which
malicious SQL statements are inserted into an
entry field for execution
 Types:





Classic SQLI
Blind or Inference SQL injection
SQL INJECTION EXAMPLE
statement = "SELECT * FROM users WHERE
name ='" + userName + "';“
 Attacker input 1: ' or '1'='1
 Attacker input 2: ' or '1'='1' -- '
 Executed query:
 1: SELECT * FROM users WHERE name = '' OR
'1'='1';
 2: SELECT * FROM users WHERE name = '' OR
'1'='1' -- ';
 Consider input:
 a';DROP TABLE users; SELECT * FROM
userinfo WHERE 't' = 't

SQL INJECTION PROTECTION
Filter user input
 Way 1:












$stmt = $dbConnection->prepare('SELECT * FROM employees WHERE
name = ?');
$stmt->bind_param('s', $name);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc())
{ // do something with $row }

Way2:
$unsafe_variable = $_POST["user-input"] ;
 $safe_variable = mysql_real_escape_string($unsafe_variable);
 mysql_query("INSERT INTO table (column) VALUES ('" .
$safe_variable . "')");

SQL INJECTION WORDPRESS PROTECTION
Use prepare function with parameters
 $wpdb->query(
 $wpdb->prepare(





" DELETE FROM $wpdb->postmeta WHERE post_id
= %d AND meta_key = %s ",
13, 'gargle' )

);
 Prepare function filters parameters and is safe
from sql injection

SENSITIVE DATA EXPOSURE
All data that are stored should be stored hased or
encrypted
 Try to protect also transport layer (best using ssl)

CROSS SITE REQUEST FORGERY (CSRF)
Cross-site request forgery, also known as a
one-click attack or session riding and
abbreviated as CSRF, is a type of malicious
exploit of a website whereby unauthorized
commands are transmitted from a user that the
website trusts.
 Attacker creates page that request some action
that only authorized user can execute
 Attacker sends link of the page to the victim
 Victim clicks on link and execute command as
authorized user

PROTECTION AGAINST CSRF
Use token when sending every action
 Token should be created for each request or at
least per session
 In wordpres you may use wp_nonce_field and
wp_verify_nonce, wp_create_nonce





<form method="post">
<!-- some inputs here ... -->



<?php
wp_nonce_field('name_of_my_action','name_of_nonce_field'); ?>



</form>
INSECURE DIRECT OBJECT REFERENCES
Http and security

More Related Content

PDF
PHP Data Objects
PDF
Future of HTTP in CakePHP
PDF
New in cakephp3
KEY
Php 101: PDO
PPT
Quebec pdo
PDF
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
PDF
Dependency Injection with PHP and PHP 5.3
PHP Data Objects
Future of HTTP in CakePHP
New in cakephp3
Php 101: PDO
Quebec pdo
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Dependency Injection with PHP and PHP 5.3

What's hot (20)

PDF
Quebec pdo
PDF
Advanced Querying with CakePHP 3
ODP
PHP Data Objects
PDF
Pemrograman Web 9 - Input Form DB dan Session
PDF
Agile database access with CakePHP 3
PPT
PHP - PDO Objects
PDF
Solr integration in Magento Enterprise
PPT
Corephpcomponentpresentation 1211425966721657-8
PDF
Service intergration
PDF
Using web2py's DAL in other projects or frameworks
TXT
Excelsheet
PDF
Debugging: Rules And Tools - PHPTek 11 Version
PPT
Introducing PHP Data Objects
PDF
Teaching Your Machine To Find Fraudsters
PDF
MySQL server security
PDF
Web2py Code Lab
PDF
Offensive PowerShell Cheat Sheet
PPTX
User registration and login using stored procedure in php
PPSX
Php session
PDF
Check username availability with vue.js and PHP
Quebec pdo
Advanced Querying with CakePHP 3
PHP Data Objects
Pemrograman Web 9 - Input Form DB dan Session
Agile database access with CakePHP 3
PHP - PDO Objects
Solr integration in Magento Enterprise
Corephpcomponentpresentation 1211425966721657-8
Service intergration
Using web2py's DAL in other projects or frameworks
Excelsheet
Debugging: Rules And Tools - PHPTek 11 Version
Introducing PHP Data Objects
Teaching Your Machine To Find Fraudsters
MySQL server security
Web2py Code Lab
Offensive PowerShell Cheat Sheet
User registration and login using stored procedure in php
Php session
Check username availability with vue.js and PHP
Ad

Viewers also liked (19)

PDF
Ch12 Encryption
PPT
HTTP protocol and Streams Security
PDF
PDF
Web Security – I: HTTP Protocol++
PPTX
HTTP Services & REST API Security
PPTX
Equity forecast: Predicting long term stock market prices using machine learning
PPT
HyperText Transfer Protocol
PPTX
Machine learning prediction of stock markets
PPSX
Hypertext Transfer Protocol
PPTX
PDF
HTTP Plugin for MySQL!
PDF
Computer Security and Safety, Ethics & Privacy
PPTX
Introduction to HTTP protocol
PPT
HTTP Basics
PPTX
Basic concepts in computer security
PPTX
Http Vs Https .
PPTX
HTTP request and response
PDF
Computer Security
PPTX
HyperText Transfer Protocol (HTTP)
Ch12 Encryption
HTTP protocol and Streams Security
Web Security – I: HTTP Protocol++
HTTP Services & REST API Security
Equity forecast: Predicting long term stock market prices using machine learning
HyperText Transfer Protocol
Machine learning prediction of stock markets
Hypertext Transfer Protocol
HTTP Plugin for MySQL!
Computer Security and Safety, Ethics & Privacy
Introduction to HTTP protocol
HTTP Basics
Basic concepts in computer security
Http Vs Https .
HTTP request and response
Computer Security
HyperText Transfer Protocol (HTTP)
Ad

Similar to Http and security (20)

PPT
Parameter Passing & Session Tracking in PHP
PDF
How to Create Login and Registration API in PHP.pdf
PPTX
Web Techniques like Cookies and Sessions
PPT
Php Security By Mugdha And Anish
PPTX
PPTX
Rest with Java EE 6 , Security , Backbone.js
PDF
May 2010 - RestEasy
PDF
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
PDF
Debugging: Rules & Tools
PDF
PPTX
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
PDF
Web Scraping with PHP
ODP
Web Scraping with PHP
PPTX
07 application security fundamentals - part 2 - security mechanisms - data ...
PPTX
Hack ASP.NET website
PPTX
TO Hack an ASP .NET website?
PDF
Php summary
PPT
General Principles of Web Security
PPTX
Web Technologies - forms and actions
PDF
The Zen of Lithium
Parameter Passing & Session Tracking in PHP
How to Create Login and Registration API in PHP.pdf
Web Techniques like Cookies and Sessions
Php Security By Mugdha And Anish
Rest with Java EE 6 , Security , Backbone.js
May 2010 - RestEasy
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Debugging: Rules & Tools
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
Web Scraping with PHP
Web Scraping with PHP
07 application security fundamentals - part 2 - security mechanisms - data ...
Hack ASP.NET website
TO Hack an ASP .NET website?
Php summary
General Principles of Web Security
Web Technologies - forms and actions
The Zen of Lithium

More from Nikola Milosevic (20)

PPTX
Classifying intangible social innovation concepts using machine learning and ...
PPTX
Machine learning (ML) and natural language processing (NLP)
PPTX
Veštačka inteligencija
PPTX
AI an the future of society
PPTX
BelBi2016 presentation: Hybrid methodology for information extraction from ta...
PPTX
Extracting patient data from tables in clinical literature
PPTX
Supporting clinical trial data curation and integration with table mining
PPTX
Mobile security, OWASP Mobile Top 10, OWASP Seraphimdroid
PPTX
PPTX
Table mining and data curation from biomedical literature
PDF
PDF
Sentiment analysis for Serbian language
PDF
Android business models
ODP
Android(1)
PPT
Sigurnosne prijetnje i mjere zaštite IT infrastrukture
PPTX
Mašinska analiza sentimenta rečenica na srpskom jeziku
PPT
PDF
Software Freedom day Serbia - Owasp - informaciona bezbednost u Srbiji open s...
PPT
Software Freedom day Serbia - Owasp open source resenja
PPT
OWASP Serbia - A6 security misconfiguration
Classifying intangible social innovation concepts using machine learning and ...
Machine learning (ML) and natural language processing (NLP)
Veštačka inteligencija
AI an the future of society
BelBi2016 presentation: Hybrid methodology for information extraction from ta...
Extracting patient data from tables in clinical literature
Supporting clinical trial data curation and integration with table mining
Mobile security, OWASP Mobile Top 10, OWASP Seraphimdroid
Table mining and data curation from biomedical literature
Sentiment analysis for Serbian language
Android business models
Android(1)
Sigurnosne prijetnje i mjere zaštite IT infrastrukture
Mašinska analiza sentimenta rečenica na srpskom jeziku
Software Freedom day Serbia - Owasp - informaciona bezbednost u Srbiji open s...
Software Freedom day Serbia - Owasp open source resenja
OWASP Serbia - A6 security misconfiguration

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Cell Structure & Organelles in detailed.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Cell Structure & Organelles in detailed.
Final Presentation General Medicine 03-08-2024.pptx
Supply Chain Operations Speaking Notes -ICLT Program
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
O5-L3 Freight Transport Ops (International) V1.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Microbial disease of the cardiovascular and lymphatic systems
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
GDM (1) (1).pptx small presentation for students
VCE English Exam - Section C Student Revision Booklet
01-Introduction-to-Information-Management.pdf
Microbial diseases, their pathogenesis and prophylaxis
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

Http and security

  • 2. AGENDA HTTP basics  HTTP methods  PHP and HTTP  Security threats and attacks  Security in PHP 
  • 3. HTTP The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems  HTTP is the foundation of data communication for the World Wide Web. 
  • 4. HTTP HTTP functions as a request-response protocol in the client-server computing model  The response contains completion status information about the request and may also contain requested content in its message body  HTTP is an application layer protocol (mostly TCP, but can use UDP) 
  • 5. HTTP SESSIONS An HTTP session is a sequence of network request-response transactions  Every session has an ID and reflects conversation between one client and server  In PHP $_SESSION variable can hold session parameters 
  • 6. HTTP METHODS          GET - Requests a representation of the specified resource HEAD - likeGET request, but without the response body POST - Requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI PUT - Requests that the enclosed entity be stored under the supplied URI DELETE - Deletes the specified resource. TRACE - Echoes back the received request so that a client can see what changes or additions have been made by intermediate servers. OPTIONS - Returns the HTTP methods that the server supports for the specified URL CONNECT - Converts the request connection to a transparent TCP/IP tunnel PATCH - Is used to apply partial modifications to a resource
  • 7. HTTP GET /test/demo_form.php?name1=value1&name2=val ue2  GET requests can be cached  GET requests remain in the browser history  GET requests can be bookmarked  GET requests should never be used when dealing with sensitive data  GET requests have length restrictions (2048)  GET requests should be used only to retrieve data 
  • 8. HTTP POST POST /test/demo_form.asp HTTP/1.1  Host: w3schools.com  name1=value1&name2=value2  POST requests are never cached  POST requests do not remain in the browser history  POST requests cannot be bookmarked  POST requests have no restrictions on data length 
  • 9. PHP METHODS FOR POST AND GET GET - $_GET variable  POST - $_POST variable  $_REQUEST for both + $_COOKIE  if (isset($_GET['user']) && isset($_GET['gen'])) {  $user = $_GET['user'];  $gen = $_GET['gen'];  echo 'User: '. $user. ' - gender: '. $gen; } 
  • 10. AND WORDPRESS Wordpress core does not use sessions  Wordpress core uses only cookies  However plugins can use sessions 
  • 11. SECURITY INTRODUCTION Weakest part of site is entry point  Write your code secure!  Don’t be victim of laziness and get hacked (or put users in risk)  It’s easier to protect then to heal 
  • 12. CROSS SITE SCRIPTING (XSS) Adding additional HTML or javascript to source of page  Injectiong trough url parameters, requests or form fields  Stored XSS, Reflected, DOM based 
  • 13. XSS PROTECTION Stripping tags  Transform characters like <,>,/,’,” etc to html entities  Php functions:     string strip_tags ( string $str [, string $allowable_tags ] ) string htmlentities ( string $string) string htmlspecialchars( string $string)
  • 14. SQL INJECTION SQL injection is a code injection technique, used to attack data driven applications, in which malicious SQL statements are inserted into an entry field for execution  Types:    Classic SQLI Blind or Inference SQL injection
  • 15. SQL INJECTION EXAMPLE statement = "SELECT * FROM users WHERE name ='" + userName + "';“  Attacker input 1: ' or '1'='1  Attacker input 2: ' or '1'='1' -- '  Executed query:  1: SELECT * FROM users WHERE name = '' OR '1'='1';  2: SELECT * FROM users WHERE name = '' OR '1'='1' -- ';  Consider input:  a';DROP TABLE users; SELECT * FROM userinfo WHERE 't' = 't 
  • 16. SQL INJECTION PROTECTION Filter user input  Way 1:         $stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?'); $stmt->bind_param('s', $name); $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) { // do something with $row } Way2: $unsafe_variable = $_POST["user-input"] ;  $safe_variable = mysql_real_escape_string($unsafe_variable);  mysql_query("INSERT INTO table (column) VALUES ('" . $safe_variable . "')"); 
  • 17. SQL INJECTION WORDPRESS PROTECTION Use prepare function with parameters  $wpdb->query(  $wpdb->prepare(    " DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s ", 13, 'gargle' ) );  Prepare function filters parameters and is safe from sql injection 
  • 18. SENSITIVE DATA EXPOSURE All data that are stored should be stored hased or encrypted  Try to protect also transport layer (best using ssl) 
  • 19. CROSS SITE REQUEST FORGERY (CSRF) Cross-site request forgery, also known as a one-click attack or session riding and abbreviated as CSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts.  Attacker creates page that request some action that only authorized user can execute  Attacker sends link of the page to the victim  Victim clicks on link and execute command as authorized user 
  • 20. PROTECTION AGAINST CSRF Use token when sending every action  Token should be created for each request or at least per session  In wordpres you may use wp_nonce_field and wp_verify_nonce, wp_create_nonce    <form method="post"> <!-- some inputs here ... -->  <?php wp_nonce_field('name_of_my_action','name_of_nonce_field'); ?>  </form>