![]() |
|
PHP Audit - The art of finding 0days in webapps Part 2 - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Hacks, Exploits, and Various Discussions (https://hackforums.net/forumdisplay.php?fid=45) +--- Forum: Grayhat • Purple Team • Hybrid Security (https://hackforums.net/forumdisplay.php?fid=449) +---- Forum: Website Hacking (https://hackforums.net/forumdisplay.php?fid=43) +---- Thread: PHP Audit - The art of finding 0days in webapps Part 2 (/showthread.php?tid=3108156) |
PHP Audit - The art of finding 0days in webapps Part 2 - JoinSeventh - Dec 22, 2012 Note: Go to Part 1 of this tutorial: https://hackforums.net/showthread.php?tid=3116315 PHP Audit - The art of finding 0days in webapps Part 2 0x04 - Useful tools, scripts and techniques [+] Text Editors Sublime Text 2 is one of my favourite Text Editors out there. It functionalities includes, but are not limited to syntax highlighting, opening directories as 'Projects' (Very useful) and a nice search function. If you don't like it or have another one you like better, feel free to use it instead. [+] grep Quote:grep is a command-line utility for searching plain-text data sets for lines matching a regular expression. Grep was originally developed for the Unix operating system, but is available today for all Unix-like systems. Its name comes from the ed command g/re/p (global / regular expression / print). grep is a very useful tool when it comes to auditing webapps. Let's say we have the following code at app.php: PHP Code We could use a command like: Code $ grep _GET app.phpPHP Code ![]() Finding mysql_* functions: Code grep mysql_ app.phpPHP Code Finding include() function: Code grep include app.phpPHP Code ![]() Now let's say we have 3 PHP applications in a folder and we wish to search for the include function in all of them, then we could do something like this: Code grep include *.phpPHP Code ![]() If we wish to output the line number we can use the -n argument like this: Code grep include *.php -nPHP Code Now we wish to check if the words 'SELECT' and 'FROM' can be found: Code grep 'SELECT\|FROM' app.php -nPHP Code ![]() If we want to match a string and ignore case sensitivity we use the -i argument: Code grep 'sEleCt\|FroM' app.php -n -iPHP Code ![]() [+] Automated tools and why you shouldn't use them They suck. Most of them use regex and pattern matching but they miss the logical understanding of an application. You'll do just fine with a good text editor and grep. If you still wish to take a look at some different tools: http://www.hotscripts.com/blog/6-free-php-security-auditing-tools/ 0x05 - Let's Audit - Real world example We're going to take a look at a real world example, a public exploit, and see if we can find the vulnerabilities: [+] MyBB DyMy User Agent SQL Injection Code http://www.exploit-db.com/exploits/23359/We'll download the vulnerable application and place it into our plugins folder. The first thing we do is to open it in our Text Editor: ![]() We'll now start out with some basic searching for possible vulnerable functions and similar stuff: Code grep "\$_GET" dymy_ua.php -i -nPHP Code ![]() Why doesn't it find anything? Are we doing something wrong? The answer is in the source code, let's take a look: PHP Code If you've ever seen MyBB plugin source before you'll now what's going on here. Take a look at the following documents to get a better understanding about what's wrong here: http://docs.mybb.com/Plugins-Globals.html http://docs.mybb.com/Database_Methods.html So when we audit MyBB Plugins we need to change our audit methods a bit. We're going to search for $db->*, since that is used in MyBB Plugins for Database interactions. Let's go back to the terminal and test some new stuff. Code joinse7en@box /v/w/m/i/plugins> grep "\$db" dymy_ua.php -i -nPHP Code ![]() Since this isn't much we can tamper with, we'll go to line 127 and see what's up: PHP Code In this we notice something very nice, take a look at this: PHP Code We see here that the application inserts the user_agent without any kind of sanitization. Let's fire up our MyBB forum on our localhost and try this shit out. Activate the Plugin in your Admin Panel and then go to a thread and post something with Live HTTP Headers running. We'll see this next to our post: ![]() So now, we'll try some basic test to see if the SQL Injection vulnerability actually exists: ![]() Ah, wonderful! Now we'll play around with it until we get a nice query to inject. I'm not going to teach you SQL Injection, that's your job. After some testing and we'll come out with this query: Code ' and(select 1 from(select count(*),concat((select username from mybb_users where uid=1),floor(Rand(0)*2))a from information_schema.tables group by a)b)); #![]() 0x06 - Publish of a new 0day - MyFlags MyBB plugins SQL Injection MyFlags MyBB plugins SQL Injection (Merry Christmas faggots :3) The SQL Injection vulnerability exists in the MyBB Plugin HM_My Country Flags: Code http://mods.mybb.com/view/hm-my-country-flagsWhen this plugins is activated a user can go to his Control Panel and see this: ![]() Whenever the user now posts the Nationalidad will show up next to his posts: ![]() Start Live HTTP Headers and press the country, in HTTP Live Headers, copy the URL ('localhost/mybb/misc.php?action=hmflags&cnam=Belgium&pf=5') and paste this into a new tab. Now put a ' after the country: Code http://localhost/mybb/misc.php?action=hmflags&cnam=Belgium'&pf=5PHP Code Tweak around abit and you'll figure out it's UNION Based with ALOT of columns: ![]() Hope you like my tutorial and will find the 0day useful. * - VipVince - Dec 22, 2012 Awesome tutorial man. Nice to see this on HF. * - tux1 - Dec 22, 2012 This is a pretty good and detailed tutorial, bookmarked for later! * - The Ion - Dec 22, 2012 You are one awesome man ! THanks for the HQ article wish i could REP you more but i already gave out the rep for you :) * - Dyme - Dec 22, 2012 It's really strange how I go through an almost identical process when I look for 0days. Great tutorial, hopefully many will use it and post they're findings here. * - SIM-111414 - Dec 22, 2012 Your series is really awesome. I expect some more knowledge about finding bugs in web app manually. Thanks again for sharing it. :) * - Suved - Dec 22, 2012 HQ Tutorial Respect 🤝 Thanks for tutorial. * - Illicit - Dec 23, 2012 Never used tools before, I prefer to sift through the code.Nice tutorial though :3 * - Phizo - Dec 23, 2012 It's rare for me to give positive feedback on tutorials, but this is one amazing tutorial. You did a very good job putting the tutorial together (both parts). Keep up the good work. * - laurenEB - Dec 23, 2012 Your post is most informative. I really like all the pictures :) * - JoinSeventh - Dec 24, 2012 Thanks for all the feedback guys, glad you liked it. * - Oxy - Dec 24, 2012 Awesome information. Even though i don't use allot of tools. Only when it comes to metasploit and stuff :). Anyways will check this seems verry promassing. Greetings InQontroll. * - SoLong - Dec 24, 2012 This tutorial is HIGHLY awesome, good job on it. * - rcvrcv - Dec 25, 2012 good job, nice tutorial and methods. * - aBlackAulaeum - Dec 25, 2012 Cool :-) It's an awesome tutorial! Thank you very much indeed! |