SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
web coding security
Huỳnh Hải Âu
Công ty ISePRO
Đơn vị tổ chức:

Đơn vị tài trợ:
Contents
• SQL Injection
• XSS
• File upload
SQL Injection
• Introduction
• Bad codes
• Preventing solutions
• Types: 3 types
– Union base
• Inject a union query to extract data from database

– Error base
• Inject SQL characters, queries to make the application
query fail and raise errors
• Use sql errors to extract data from database

– Blind SQLi
• Inject sql characters to ask the database true or false
questions and determines the answer based on the
applications response
– Bad code 1:
if(isset($_POST['user']) && isset($_POST['password']))
{
$u = $_POST['user'];
$p = $_POST['password'];
$u = preg_replace('/union|select|from|where|and|or/i','',$u);
$p = preg_replace('/union|select|from|where|and|or/i','',$p);
$q = mysql_query("select * from user where username='$u' and
password='$p'");
if($r=mysql_fetch_assoc($q))
{
echo "<br>Log in successfully !";
echo "<br>Hello $r[username]";
}
else
echo "<br>Invalid login !";
}
– Bad code 2:
if(isset($_POST['user']) && isset($_POST['password']))
{
$u = $_POST['user'];
$p = $_POST['password'];
$u = preg_replace(“/’/i”,””,$u);
$p = preg_replace(“/’/i”,””,$p);
$q = mysql_query("select * from user where username='$u' and
password='$p'");
if($r=mysql_fetch_assoc($q))
{
echo "<br>Log in successfully !";
echo "<br>Hello $r[username]";
}
else
echo "<br>Invalid login !";
}
– Bad code 3:
if(isset($_GET['id']))
{
$id = $_GET['id'];
$id = mysql_real_escape_string($id);
$q = mysql_query("select * from user where id=$id");
if($r=mysql_fetch_assoc($q))
{
echo "<br>Profile: $r[username]";
echo "<br>Age: $r[Age]";
echo "<br>Phone: $r[Phone]";
echo "<br>Mail: $r[Mail]";
echo "<br>Address: $r[Address]";
}
else
echo "<br>Invalid id !";
}
– Bad code 4:
if(isset($_POST['user']) && isset($_POST['password']))
{
$u = mysql_real_escape_string($_POST['user']);
$p = mysql_real_escape_string($_POST['password']);
$p = hash("whirlpool", $p, true);
$q = mysql_query("select * from user where username='$u' and password='$p'");
if($r=mysql_fetch_assoc($q))
{
echo "<br>Log in successfully !";
echo "<br>Hello $r[username]";
}
else
Echo "<br>Invalid login !";
}
• Preventing solutions:
– Prepare statement
• aka parameterized statement
• Template of sql query structure
– INSERT INTO PRODUCT (name, price) VALUES (?, ?)

• Separation of control flow & data flow
if(isset($_POST['user']) && isset($_POST['password']))
{
$u = $_POST['user'];
$p = $_POST['password'];
$q = $sql->prepare("select * from user where username=? and password=?");
$q->bind_param("ss", $u, $p);
$q->execute();
$res = $q->get_result();
if($r=$res->fetch_assoc())
{
echo "<br>Log in successfully !";
echo "<br>Hello $r[username]";
}
else
echo "<br>Invalid login !";
$q->close();
}
Cross Site Scripting (XSS)
• Introduction
• Bad codes
• Preventing solutions
• TYPES:
1.
2.

Non-Persistent
Persistent
• Non-Persistent:
In this type of XSS vulnerability an attacker is able to
execute his own code into a webpage but no changes
can be done in that website.
•

Persistent:
In this case attacker stores his executable script in the
vulnerable website database which is being executed every
time webpage is showing the data.

•

Common targets are:
–
–
–
–

Comments
Chat messages
E-mail messages
Wall posts, etc.
• Bad codes
– Bad code 1:
if (isset($_GET['color']))
{
$color = $_GET['color'];
$color = htmlspecialchars($color);
echo "<body bgcolor='". $color."'></body>";
}
– Bad code 2:
if (isset($_GET['color']))
{
$color = $_GET['color'];
$color = htmlspecialchars($color, ENT_QUOTES);
echo "<body bgcolor=$color></body>";
}
• Preventing solutions:
– Input validation
– Output encoding
• Input validation
– whitelist of acceptable inputs
– Consider potential input properties: length, type, range
of acceptable values, syntax
function validate($input)
{
if(!is_string($input))
die(“input must be string !”);
if(strlen($input) > 10)
die(“input length must lower than 10”);
if(!pregmatch(“/^city/”,$input))
die(“input must begin with city word”);
$whitelist={“red”, “green”, “blue”};
if(!in_array($input, $whitelist))
die(“bad input”);

}
• Output encoding
– Sanitizing all values before outputing to browser
– Output encoding functions:
• htmlentities: convert all applicable characters to
HTML entities
function encoding($output)
{
return htmlenties($output);

}
$safe_value = encoding($value);
echo $safe_value;
File Upload Attack
• Introduction
• Bad codes
• Preventing solutions
• Allow attacker to upload malicious files to server
• Most of time, it’s web shell to take control over web
server
• Risk:
–
–
–
–
–
–

Web-shell upload
Website deface
XSS
Phishing
Malware upload
…
• Bad codes
– Bad code 1:
if (isset($_POST['submit']))
{
if($_FILES['userfile']['type'] != "image/gif")
{
echo "Sorry, we only allow uploading GIF images";
exit;
}
$uploaddir = 'uploads/';
$uploadfile= $uploaddir.basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
echo "File is valid, and was successfully uploaded.n";
else
echo "File uploading failed.n";
}
– Bad code 2:
if (isset($_POST['submit']))
{
$imageinfo = getimagesize($_FILES['userfile']['tmp_name']);
if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg')
{
echo "Sorry, we only accept GIF and JPEG imagesn";
exit;
}
$uploaddir = 'uploads/';
$uploadfile= $uploaddir.basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
echo "File is valid, and was successfully uploaded.n";
else
echo "File uploading failed.n";
}
– Bad code 3:
if (isset($_POST['submit']))
{
$uploaddir = ‘D:/uploads/';
$uploadfile= $uploaddir.basename($_FILES['userfile']['name']);

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
echo "File is valid, and was successfully uploaded.n";
echo "<IMG SRC='" . $uploadfile . "'>";
}
else
echo "File uploading failed.n";
}
• Preventing solutions
– Keep uploaded files where they cannot be directly accessed
by the users via a direct URL
• Outside of webroot
• Or configure web server to deny access to upload directory

– Use system-generated file names instead of the names
supplied by users when storing files
if (isset($_POST['submit']))
{
$uploaddir = ‘D:/uploads/';
$new_file_name = rand(1,1000);
$uploadfile = $uploaddir . $new_file_name;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
echo "File is valid, and was successfully uploaded.n";
echo "<IMG SRC='" . $uploadfile . "'>";
}
else
echo "File uploading failed.n";
}
The end

Thank you !

Weitere ähnliche Inhalte

Was ist angesagt?

jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentationguestcf600a
 
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzenAndreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzenDevDay Dresden
 
User registration and login using stored procedure in php
User registration and login using stored procedure in phpUser registration and login using stored procedure in php
User registration and login using stored procedure in phpPHPGurukul Blog
 
preventing sqli and xss by ravi rajput in owasp meet ahmedabad
preventing sqli and xss by ravi rajput in owasp meet ahmedabadpreventing sqli and xss by ravi rajput in owasp meet ahmedabad
preventing sqli and xss by ravi rajput in owasp meet ahmedabadRavi Rajput
 
Hidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysHidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysNicholas Dionysopoulos
 
The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)Aaron Gustafson
 
15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilorRazvan Raducanu, PhD
 
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future PastPuppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future PastPuppet
 
Drush. Secrets come out.
Drush. Secrets come out.Drush. Secrets come out.
Drush. Secrets come out.Alex S
 

Was ist angesagt? (17)

Http and security
Http and securityHttp and security
Http and security
 
jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentation
 
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzenAndreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
 
php plus mysql
php plus mysqlphp plus mysql
php plus mysql
 
User registration and login using stored procedure in php
User registration and login using stored procedure in phpUser registration and login using stored procedure in php
User registration and login using stored procedure in php
 
preventing sqli and xss by ravi rajput in owasp meet ahmedabad
preventing sqli and xss by ravi rajput in owasp meet ahmedabadpreventing sqli and xss by ravi rajput in owasp meet ahmedabad
preventing sqli and xss by ravi rajput in owasp meet ahmedabad
 
Daily notes
Daily notesDaily notes
Daily notes
 
P5
P5P5
P5
 
Web security
Web securityWeb security
Web security
 
Hidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysHidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeys
 
Coding website
Coding websiteCoding website
Coding website
 
logic321
logic321logic321
logic321
 
Potential Friend Finder
Potential Friend FinderPotential Friend Finder
Potential Friend Finder
 
The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)
 
15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor
 
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future PastPuppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future Past
 
Drush. Secrets come out.
Drush. Secrets come out.Drush. Secrets come out.
Drush. Secrets come out.
 

Andere mochten auch

Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng CaoBài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng CaoTuan Nguyen
 
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajaxSức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajaxTuyet Tam
 
Bài 10: Custom Tag - Lập Trình Mạng Nâng Cao
Bài 10: Custom Tag - Lập Trình Mạng Nâng CaoBài 10: Custom Tag - Lập Trình Mạng Nâng Cao
Bài 10: Custom Tag - Lập Trình Mạng Nâng CaoTuan Nguyen
 
Bài 12: JSF-2 - Lập Trình Mạng Nâng Cao
Bài 12:  JSF-2 - Lập Trình Mạng Nâng CaoBài 12:  JSF-2 - Lập Trình Mạng Nâng Cao
Bài 12: JSF-2 - Lập Trình Mạng Nâng CaoTuan Nguyen
 
Bài 11: JSF-1 - Lập Trình Mạng Nâng Cao
Bài 11:  JSF-1 - Lập Trình Mạng Nâng CaoBài 11:  JSF-1 - Lập Trình Mạng Nâng Cao
Bài 11: JSF-1 - Lập Trình Mạng Nâng CaoTuan Nguyen
 
[Cntt] bài giảng java khtn hcm
[Cntt] bài giảng java   khtn hcm[Cntt] bài giảng java   khtn hcm
[Cntt] bài giảng java khtn hcmHong Phuoc Nguyen
 
Bài 3: Servlet - Lập Trình Mạng Nâng Cao
Bài 3: Servlet - Lập Trình Mạng Nâng CaoBài 3: Servlet - Lập Trình Mạng Nâng Cao
Bài 3: Servlet - Lập Trình Mạng Nâng CaoTuan Nguyen
 
Bài 2: J2EE - Lập Trình Mạng Nâng Cao
Bài 2: J2EE - Lập Trình Mạng Nâng CaoBài 2: J2EE - Lập Trình Mạng Nâng Cao
Bài 2: J2EE - Lập Trình Mạng Nâng CaoTuan Nguyen
 
Vận dụng kiến thức lập trình web vào môi trường thực tế
Vận dụng kiến thức lập trình web vào môi trường thực tếVận dụng kiến thức lập trình web vào môi trường thực tế
Vận dụng kiến thức lập trình web vào môi trường thực tếVKhang Yang
 
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng CaoBài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng CaoTuan Nguyen
 
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng CaoBài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng CaoTuan Nguyen
 
VCP 21- VMWare VPC 6
VCP 21- VMWare VPC 6VCP 21- VMWare VPC 6
VCP 21- VMWare VPC 6Tuan Nguyen
 
tài liệu Mã nguồn mở Lap trình shells
tài liệu Mã nguồn mở  Lap trình shellstài liệu Mã nguồn mở  Lap trình shells
tài liệu Mã nguồn mở Lap trình shellsThuyet Nguyen
 
Presentation on leadership
Presentation on leadershipPresentation on leadership
Presentation on leadershipsd college
 
Leadership concepts and theories
Leadership concepts and theoriesLeadership concepts and theories
Leadership concepts and theoriesalaguraja76
 

Andere mochten auch (16)

Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng CaoBài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
 
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajaxSức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
 
Bài 10: Custom Tag - Lập Trình Mạng Nâng Cao
Bài 10: Custom Tag - Lập Trình Mạng Nâng CaoBài 10: Custom Tag - Lập Trình Mạng Nâng Cao
Bài 10: Custom Tag - Lập Trình Mạng Nâng Cao
 
Bài 12: JSF-2 - Lập Trình Mạng Nâng Cao
Bài 12:  JSF-2 - Lập Trình Mạng Nâng CaoBài 12:  JSF-2 - Lập Trình Mạng Nâng Cao
Bài 12: JSF-2 - Lập Trình Mạng Nâng Cao
 
Bài 11: JSF-1 - Lập Trình Mạng Nâng Cao
Bài 11:  JSF-1 - Lập Trình Mạng Nâng CaoBài 11:  JSF-1 - Lập Trình Mạng Nâng Cao
Bài 11: JSF-1 - Lập Trình Mạng Nâng Cao
 
[Cntt] bài giảng java khtn hcm
[Cntt] bài giảng java   khtn hcm[Cntt] bài giảng java   khtn hcm
[Cntt] bài giảng java khtn hcm
 
Bài 3: Servlet - Lập Trình Mạng Nâng Cao
Bài 3: Servlet - Lập Trình Mạng Nâng CaoBài 3: Servlet - Lập Trình Mạng Nâng Cao
Bài 3: Servlet - Lập Trình Mạng Nâng Cao
 
Bài 2: J2EE - Lập Trình Mạng Nâng Cao
Bài 2: J2EE - Lập Trình Mạng Nâng CaoBài 2: J2EE - Lập Trình Mạng Nâng Cao
Bài 2: J2EE - Lập Trình Mạng Nâng Cao
 
Vận dụng kiến thức lập trình web vào môi trường thực tế
Vận dụng kiến thức lập trình web vào môi trường thực tếVận dụng kiến thức lập trình web vào môi trường thực tế
Vận dụng kiến thức lập trình web vào môi trường thực tế
 
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng CaoBài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
 
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng CaoBài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
 
VCP 21- VMWare VPC 6
VCP 21- VMWare VPC 6VCP 21- VMWare VPC 6
VCP 21- VMWare VPC 6
 
Linux LPI Bacis
Linux LPI BacisLinux LPI Bacis
Linux LPI Bacis
 
tài liệu Mã nguồn mở Lap trình shells
tài liệu Mã nguồn mở  Lap trình shellstài liệu Mã nguồn mở  Lap trình shells
tài liệu Mã nguồn mở Lap trình shells
 
Presentation on leadership
Presentation on leadershipPresentation on leadership
Presentation on leadership
 
Leadership concepts and theories
Leadership concepts and theoriesLeadership concepts and theories
Leadership concepts and theories
 

Ähnlich wie Security Bootcamp 2013 - Lap trinh web an toan

Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And AnishOSSCube
 
Security: Odoo Code Hardening
Security: Odoo Code HardeningSecurity: Odoo Code Hardening
Security: Odoo Code HardeningOdoo
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksNodejsFoundation
 
Application Security around OWASP Top 10
Application Security around OWASP Top 10Application Security around OWASP Top 10
Application Security around OWASP Top 10Sastry Tumuluri
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Arc & Codementor
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksNodejsFoundation
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Spot the Web Vulnerability
Spot the Web VulnerabilitySpot the Web Vulnerability
Spot the Web VulnerabilityMiroslav Stampar
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by defaultSlawomir Jasek
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by defaultSecuRing
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure codingHaitham Raik
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 

Ähnlich wie Security Bootcamp 2013 - Lap trinh web an toan (20)

Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And Anish
 
Security: Odoo Code Hardening
Security: Odoo Code HardeningSecurity: Odoo Code Hardening
Security: Odoo Code Hardening
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks
 
Application Security around OWASP Top 10
Application Security around OWASP Top 10Application Security around OWASP Top 10
Application Security around OWASP Top 10
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 
Php Security
Php SecurityPhp Security
Php Security
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks
 
Php security
Php securityPhp security
Php security
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Security in Node.JS and Express:
Security in Node.JS and Express:Security in Node.JS and Express:
Security in Node.JS and Express:
 
Spot the Web Vulnerability
Spot the Web VulnerabilitySpot the Web Vulnerability
Spot the Web Vulnerability
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Php security3895
Php security3895Php security3895
Php security3895
 
PHP Security
PHP SecurityPHP Security
PHP Security
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 

Mehr von Security Bootcamp

Ransomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfSecurity Bootcamp
 
Hieupc-The role of psychology in enhancing cybersecurity
Hieupc-The role of psychology in enhancing cybersecurityHieupc-The role of psychology in enhancing cybersecurity
Hieupc-The role of psychology in enhancing cybersecuritySecurity Bootcamp
 
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s viewNguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s viewSecurity Bootcamp
 
Sbc 2020 bao gio vn co anm dua vao cong nghe mo
Sbc 2020 bao gio vn co anm dua vao cong nghe moSbc 2020 bao gio vn co anm dua vao cong nghe mo
Sbc 2020 bao gio vn co anm dua vao cong nghe moSecurity Bootcamp
 
Giam sat thu dong thong tin an toan hang hai su dung sdr
Giam sat thu dong thong tin an toan hang hai su dung sdrGiam sat thu dong thong tin an toan hang hai su dung sdr
Giam sat thu dong thong tin an toan hang hai su dung sdrSecurity Bootcamp
 
Insider threat-what-us-do d-want
Insider threat-what-us-do d-wantInsider threat-what-us-do d-want
Insider threat-what-us-do d-wantSecurity Bootcamp
 
Macro malware common techniques - public
Macro malware   common techniques - publicMacro malware   common techniques - public
Macro malware common techniques - publicSecurity Bootcamp
 
Malware detection-using-machine-learning
Malware detection-using-machine-learningMalware detection-using-machine-learning
Malware detection-using-machine-learningSecurity Bootcamp
 
Tim dieu moi trong nhung dieu cu
Tim dieu moi trong nhung dieu cuTim dieu moi trong nhung dieu cu
Tim dieu moi trong nhung dieu cuSecurity Bootcamp
 
Threat detection with 0 cost
Threat detection with 0 costThreat detection with 0 cost
Threat detection with 0 costSecurity Bootcamp
 
GOLDEN TICKET - Hiểm hoa tiềm ẩn trong hệ thống Active Directory
GOLDEN TICKET -  Hiểm hoa tiềm ẩn trong hệ thống Active DirectoryGOLDEN TICKET -  Hiểm hoa tiềm ẩn trong hệ thống Active Directory
GOLDEN TICKET - Hiểm hoa tiềm ẩn trong hệ thống Active DirectorySecurity Bootcamp
 
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018Security Bootcamp
 
Lannguyen-Detecting Cyber Attacks
Lannguyen-Detecting Cyber AttacksLannguyen-Detecting Cyber Attacks
Lannguyen-Detecting Cyber AttacksSecurity Bootcamp
 
Letrungnghia-gopyluananm2018
Letrungnghia-gopyluananm2018Letrungnghia-gopyluananm2018
Letrungnghia-gopyluananm2018Security Bootcamp
 

Mehr von Security Bootcamp (20)

Ransomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdf
 
Hieupc-The role of psychology in enhancing cybersecurity
Hieupc-The role of psychology in enhancing cybersecurityHieupc-The role of psychology in enhancing cybersecurity
Hieupc-The role of psychology in enhancing cybersecurity
 
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s viewNguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
 
Sbc 2020 bao gio vn co anm dua vao cong nghe mo
Sbc 2020 bao gio vn co anm dua vao cong nghe moSbc 2020 bao gio vn co anm dua vao cong nghe mo
Sbc 2020 bao gio vn co anm dua vao cong nghe mo
 
Deception change-the-game
Deception change-the-gameDeception change-the-game
Deception change-the-game
 
Giam sat thu dong thong tin an toan hang hai su dung sdr
Giam sat thu dong thong tin an toan hang hai su dung sdrGiam sat thu dong thong tin an toan hang hai su dung sdr
Giam sat thu dong thong tin an toan hang hai su dung sdr
 
Sbc2019 luong-cyber startup
Sbc2019 luong-cyber startupSbc2019 luong-cyber startup
Sbc2019 luong-cyber startup
 
Insider threat-what-us-do d-want
Insider threat-what-us-do d-wantInsider threat-what-us-do d-want
Insider threat-what-us-do d-want
 
Macro malware common techniques - public
Macro malware   common techniques - publicMacro malware   common techniques - public
Macro malware common techniques - public
 
Malware detection-using-machine-learning
Malware detection-using-machine-learningMalware detection-using-machine-learning
Malware detection-using-machine-learning
 
Tim dieu moi trong nhung dieu cu
Tim dieu moi trong nhung dieu cuTim dieu moi trong nhung dieu cu
Tim dieu moi trong nhung dieu cu
 
Threat detection with 0 cost
Threat detection with 0 costThreat detection with 0 cost
Threat detection with 0 cost
 
Build SOC
Build SOC Build SOC
Build SOC
 
AD red vs blue
AD red vs blueAD red vs blue
AD red vs blue
 
Securitybox
SecurityboxSecuritybox
Securitybox
 
GOLDEN TICKET - Hiểm hoa tiềm ẩn trong hệ thống Active Directory
GOLDEN TICKET -  Hiểm hoa tiềm ẩn trong hệ thống Active DirectoryGOLDEN TICKET -  Hiểm hoa tiềm ẩn trong hệ thống Active Directory
GOLDEN TICKET - Hiểm hoa tiềm ẩn trong hệ thống Active Directory
 
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018
 
Api security-present
Api security-presentApi security-present
Api security-present
 
Lannguyen-Detecting Cyber Attacks
Lannguyen-Detecting Cyber AttacksLannguyen-Detecting Cyber Attacks
Lannguyen-Detecting Cyber Attacks
 
Letrungnghia-gopyluananm2018
Letrungnghia-gopyluananm2018Letrungnghia-gopyluananm2018
Letrungnghia-gopyluananm2018
 

Kürzlich hochgeladen

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Security Bootcamp 2013 - Lap trinh web an toan

  • 1. web coding security Huỳnh Hải Âu Công ty ISePRO
  • 2. Đơn vị tổ chức: Đơn vị tài trợ:
  • 3. Contents • SQL Injection • XSS • File upload
  • 4. SQL Injection • Introduction • Bad codes • Preventing solutions
  • 5.
  • 6.
  • 7. • Types: 3 types – Union base • Inject a union query to extract data from database – Error base • Inject SQL characters, queries to make the application query fail and raise errors • Use sql errors to extract data from database – Blind SQLi • Inject sql characters to ask the database true or false questions and determines the answer based on the applications response
  • 8. – Bad code 1: if(isset($_POST['user']) && isset($_POST['password'])) { $u = $_POST['user']; $p = $_POST['password']; $u = preg_replace('/union|select|from|where|and|or/i','',$u); $p = preg_replace('/union|select|from|where|and|or/i','',$p); $q = mysql_query("select * from user where username='$u' and password='$p'"); if($r=mysql_fetch_assoc($q)) { echo "<br>Log in successfully !"; echo "<br>Hello $r[username]"; } else echo "<br>Invalid login !"; }
  • 9. – Bad code 2: if(isset($_POST['user']) && isset($_POST['password'])) { $u = $_POST['user']; $p = $_POST['password']; $u = preg_replace(“/’/i”,””,$u); $p = preg_replace(“/’/i”,””,$p); $q = mysql_query("select * from user where username='$u' and password='$p'"); if($r=mysql_fetch_assoc($q)) { echo "<br>Log in successfully !"; echo "<br>Hello $r[username]"; } else echo "<br>Invalid login !"; }
  • 10. – Bad code 3: if(isset($_GET['id'])) { $id = $_GET['id']; $id = mysql_real_escape_string($id); $q = mysql_query("select * from user where id=$id"); if($r=mysql_fetch_assoc($q)) { echo "<br>Profile: $r[username]"; echo "<br>Age: $r[Age]"; echo "<br>Phone: $r[Phone]"; echo "<br>Mail: $r[Mail]"; echo "<br>Address: $r[Address]"; } else echo "<br>Invalid id !"; }
  • 11. – Bad code 4: if(isset($_POST['user']) && isset($_POST['password'])) { $u = mysql_real_escape_string($_POST['user']); $p = mysql_real_escape_string($_POST['password']); $p = hash("whirlpool", $p, true); $q = mysql_query("select * from user where username='$u' and password='$p'"); if($r=mysql_fetch_assoc($q)) { echo "<br>Log in successfully !"; echo "<br>Hello $r[username]"; } else Echo "<br>Invalid login !"; }
  • 12. • Preventing solutions: – Prepare statement • aka parameterized statement • Template of sql query structure – INSERT INTO PRODUCT (name, price) VALUES (?, ?) • Separation of control flow & data flow
  • 13. if(isset($_POST['user']) && isset($_POST['password'])) { $u = $_POST['user']; $p = $_POST['password']; $q = $sql->prepare("select * from user where username=? and password=?"); $q->bind_param("ss", $u, $p); $q->execute(); $res = $q->get_result(); if($r=$res->fetch_assoc()) { echo "<br>Log in successfully !"; echo "<br>Hello $r[username]"; } else echo "<br>Invalid login !"; $q->close(); }
  • 14. Cross Site Scripting (XSS) • Introduction • Bad codes • Preventing solutions
  • 15.
  • 16.
  • 17.
  • 19. • Non-Persistent: In this type of XSS vulnerability an attacker is able to execute his own code into a webpage but no changes can be done in that website.
  • 20. • Persistent: In this case attacker stores his executable script in the vulnerable website database which is being executed every time webpage is showing the data. • Common targets are: – – – – Comments Chat messages E-mail messages Wall posts, etc.
  • 21. • Bad codes – Bad code 1: if (isset($_GET['color'])) { $color = $_GET['color']; $color = htmlspecialchars($color); echo "<body bgcolor='". $color."'></body>"; }
  • 22. – Bad code 2: if (isset($_GET['color'])) { $color = $_GET['color']; $color = htmlspecialchars($color, ENT_QUOTES); echo "<body bgcolor=$color></body>"; }
  • 23. • Preventing solutions: – Input validation – Output encoding
  • 24. • Input validation – whitelist of acceptable inputs – Consider potential input properties: length, type, range of acceptable values, syntax
  • 25. function validate($input) { if(!is_string($input)) die(“input must be string !”); if(strlen($input) > 10) die(“input length must lower than 10”); if(!pregmatch(“/^city/”,$input)) die(“input must begin with city word”); $whitelist={“red”, “green”, “blue”}; if(!in_array($input, $whitelist)) die(“bad input”); }
  • 26. • Output encoding – Sanitizing all values before outputing to browser – Output encoding functions: • htmlentities: convert all applicable characters to HTML entities
  • 28. File Upload Attack • Introduction • Bad codes • Preventing solutions
  • 29. • Allow attacker to upload malicious files to server • Most of time, it’s web shell to take control over web server • Risk: – – – – – – Web-shell upload Website deface XSS Phishing Malware upload …
  • 30. • Bad codes – Bad code 1: if (isset($_POST['submit'])) { if($_FILES['userfile']['type'] != "image/gif") { echo "Sorry, we only allow uploading GIF images"; exit; } $uploaddir = 'uploads/'; $uploadfile= $uploaddir.basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) echo "File is valid, and was successfully uploaded.n"; else echo "File uploading failed.n"; }
  • 31. – Bad code 2: if (isset($_POST['submit'])) { $imageinfo = getimagesize($_FILES['userfile']['tmp_name']); if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg') { echo "Sorry, we only accept GIF and JPEG imagesn"; exit; } $uploaddir = 'uploads/'; $uploadfile= $uploaddir.basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) echo "File is valid, and was successfully uploaded.n"; else echo "File uploading failed.n"; }
  • 32. – Bad code 3: if (isset($_POST['submit'])) { $uploaddir = ‘D:/uploads/'; $uploadfile= $uploaddir.basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.n"; echo "<IMG SRC='" . $uploadfile . "'>"; } else echo "File uploading failed.n"; }
  • 33. • Preventing solutions – Keep uploaded files where they cannot be directly accessed by the users via a direct URL • Outside of webroot • Or configure web server to deny access to upload directory – Use system-generated file names instead of the names supplied by users when storing files
  • 34. if (isset($_POST['submit'])) { $uploaddir = ‘D:/uploads/'; $new_file_name = rand(1,1000); $uploadfile = $uploaddir . $new_file_name; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.n"; echo "<IMG SRC='" . $uploadfile . "'>"; } else echo "File uploading failed.n"; }