Thursday, July 24, 2014

Launch of My New Web App - QuickVid - Imgur for Videos

It's finally here!

For the past couple of months I've been developing a web application to freely and instantly share videos without the need for an account. Basically Imgur for videos. I've finally got the working build online and you can check it out here http://quickvid.org. So if you ever just need to send a quick video to a friend and don't want to deal with signing into YouTube or creating an account, check it out. Also like the page, and follow the twitter if you want to help support the project!

http://facebook.com/QuickVid
https://twitter.com/quickvidd

Please, if you find any issues report them to me via the feedback page.

Comments, suggestions, and discussions welcome.

Wednesday, July 23, 2014

FFMPEG, Webm, libvpx, and Multithreading / Multiple Core Usage

Okay, so I've been developing a little web app to quickly share videos, and it's located here, if you want to check it out.

I am writing this very quickly, as I am already way passed the time I should be in bed from trying to figure this out! My boss won't be happy tomorrow.

Anyways,

Essentially, if you are trying to get ffmpeg to use multiple cores when converting to webm, and cannot for the life of yourself, figure out why it won't, then read this!

When using -threads <num of threads> you MUST put it right after -codec or wherever you declare your codec.

For example...

The following command will not work!

ffmpeg -threads 5 -i blah.mp4 -c:v libvpx -quality good blah.webm

but if you put the -threads 5 AFTER -cv libvpx it will use all your cores!

ffmpeg -i blah.mp4 -c:v libvpx -threads 5 -quality good blah.webm

I have no idea why this is the case, but I'm sure as hell happy it works.



Thanks to Jernej Virag from the comments on this post for finding this!

Wednesday, April 9, 2014

Avoiding XSS Vulnerability With $_SERVER['PHP_SELF']

Hey all,

Just wanted to add this little post to my blog about avoiding an exploit with using $_SERVER['PHP_SELF'].

For the longest time, I would use $_SERVER['PHP_SELF'] in my form action fields when the form parsing code was on the same page.

However, if not properly sanitized this function can easily be exploited.

Demonstration:

Here is a very simple html form with PHP processing on the same page. You will notice that the action of the form is the PHP_SELF server variable included within PHP.

This variable is pulled from the URL. Can you see the exploit?

<!DOCTYPE html>
<html>
<head>
<title>Form Exploit Demonstration</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" name="foo">
<br>
<button type="submit" name="submit">Submit</button>
</form>
<?php
if(isset($_POST['submit']))
{
echo htmlspecialchars($_POST['foo']);
}
?>
</body>
</html>

If the user edits the URL, the PHP_SELF variable becomes that edited information.



With this, you can escape the action attribute, end the form, and then execute all sorts of nasty bits of code.

Of course, my favorite being the following...

"</form><div style="position: absolute; top: 0px; bottom: 0px; right: 0px; left: 0px; background-color: black; color: white; text-align: center; font-size: 100px;">Hacked :)</div>

Which results in...



This vulnerability can be patched by simply using htmlspecialchars to sanitize the PHP_SELF variable, or by simply just not using it and just hard coding in index.php.

Wednesday, September 12, 2012

Screenshots With PHP (GD2)

Found this neat technique to grab a screenshot of a window using PHP, and after some debugging, I was finally able to get it to work.

Here's how:

Note: I believe this only works on windows boxes. If I find a method for a Linux machine, I'll be sure to write something on that as well.

<?php

$browser 
= new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://www.libgd.org");

/* Still working? */

while ($browser->Busy) 
{
    
com_message_pump(4000);
}


$im = imagegrabwindow($handle, 0);
$browser->Quit();

imagepng($im, "iesnap.png");
imagedestroy($im);

?>

Running just this script alone won't get you the screenshot. You need to go into Windows services and allow whatever web server you are running to interact with the desktop. (If you do not do the below... the images will save as a black filled png file.)

To do this...

Right click 'My Computer' and click Manage.


Find the web server's service (I am using WAMP Server for this demonstration), right click it and hit properties.

Click the 'Log On' tab and check the 'Allow service to interact with desktop' box.

Restart Apache and you should now be able to use the above script. 


Oh, and if you want the image to not have the nasty Internet explorer scroll bars / menus add this to the script:

$browser->Fullscreen = true;

Script credits goes to: http://www.php.net/manual/en/function.imagegrabwindow.php

Thursday, August 23, 2012

WAMP and PHP's cURL Windows 7 x64 bit

I came across, yet another, issue with WAMP server (I'm beginning to question the usability of this application.)

Anyhow; the error I received, even after enabling the php_curl.dll extension, was the following:

'unable to load dynamic library php_curl.dll'

When I checked the Apache error log, I was shown this:


Warning:  PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.3.13/ext/php_curl.dll' - The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. in Unknown on line 0.



The fix was to replace the php_curl.dll file in C:\wamp\bin\php\php5.3.13\ext with one of the following:


php_curl-5.3.13-nts-VC9-x64.zip
php_curl-5.3.13-VC9-x64.zip
php_curl-5.4.3-nts-VC9-x64.zip
php_curl-5.4.3-VC9-x64.zip



Credits go to the owner of this blog (Thank you!): http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/

Saturday, February 18, 2012

WAMP Server and ImageMagick

Update 9/5/18 - This is more than likely widely outdated. You're probably better off using XAMP over WAMP.

Edit: If you're running x64 bit version of Windows 7 you will need to install wamp, imagick, and php_imagick.dll ALL as x32 bit.

I decided to write this tutorial because this gave me a massive headache for three hours and I want others to not have to go through what I did.

There's millions of guides about this on the internet, but they all seem to be missing one crucial thing.



The .dll file (which we will get to later) MUST be compiled in VC9, or it will not work with php 5.3.5.

My Guide to Install ImageMagick on WAMP Server:


1. Download ImageMagick for Windows here: http://www.imagemagick.org/script/binary-releases.php?ImageMagick=p7k0tc2pra2nbmrgs423c5gsh6#windows (Select the first one on the list ImageMagick-6.7.5-6-Q16-windows-dll.exe)

2. Install to directory C:\imagemagick


and when prompted with a list of selections, choose everything but "Install PerlMagick for ActiveState Perl v51412.2 build 1402" as it causes the installation to error out.


3. Download the VC9 compiled .dll for windows here: http://valokuva.org/builds/

4. Move the downloaded VC9 compiled .dll to this directory: C:\wamp\bin\php\php5.3.5\ext
       *Note: This is the default install directory, it may be different for you.

5. Open up php.ini in a text editor by navigating to (default) C:\wamp\bin\php\php5.3.5\php.ini or by clicking on the WAMP tray icon and selecting php then php.ini.

6. Now that you are in php.ini and editing it, scroll til you find a list of extensions (see picture)

7. After finding the list, add "extension=php_imagick.dll" (without quotes) to the list, as I did above.
     *Note: Do not put a ";" in front of it as it will be commented out.

8. Unfortunately ImageMagick also has issues working with Apache version 2.2  so you need to downgrade to 2.0.63. Don't worry, it's a lot easier than it sounds.

9. To downgrade to Apache 2.0.63 click on the WAMP tray icon, hover over Apache, then Version, then click "Get more..."


9. You will be directed to the WAMP server website, (it may be in French so you can click the English button  in the upper right corner to change it.)

10. Locate and click on "Download Apache Add Ons".

11. In the window that comes up, click on Apache 2.0.63.

12. You will be redirected to a download page, let it download and install it.

13. Start WAMP server again, click on the tray icon, hover over Apache, then click Apache 2.0.63 (Like the image above)

14. Restart all services within WAMP. (Click on Icon, select restart all services).

15. You should now be able to use ImageMagick with no problem.


Hopes this helps anyone that is having issues. Took me a while to figure it out, but thanks to a friend of mine and going through all the steps over and over again, I finally figured out a way to get it working.