Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
McGlockenshire
Dec 16, 2005

GOLLOCKS!
Or at least PBKDF2, an RFC-specified, expert-reviewed mechanism. The circles I wade in tend to prefer it to even blowfish/bcrypt. Here's a library for PHP 5.3+ that implements it well.

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

Bhaal posted:

:negative: Okay now I want to donate all my earthly possessions and go live out my days in a nice cave somewhere.

Wait till you discover SCADA vulns :3:

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
A co-op student at my workplace checked in a method called "addCameraToDatabase". The first thing it does is delete all cameras of that model and manufacturer from the database.

Why.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





ShadoX posted:

And now the real answer: Parameterized queries.

Suspicious Dish posted:

All of which are the wrong solution, and can be bypassed in novel ways. Use prepared statements.
I didn't propose addslashes nor mysql_escape_string as being the right answer. I was relating to how I at least tried to do something when I first heard about SQL injection and the lack of effort in safeguarding the query was terrible. Since prepared statements/parameterized queries have only been in PHP since ~5.0, that's not exactly a solution I could have used.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Strong Sauce posted:

prepared statements/parameterized queries have only been in PHP since ~5.0, that's not exactly a solution I could have used.

:what:

Holy gently caress.

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
Thanks all for the advice. Encryption's never been something I've followed too closely after understanding the basic mathematical concepts behind it. When it comes to choosing an encryption algorithm I just took a "when in Rome" attitude for best practices by going off of big ticket LAMP applications that I've worked in. Apparently "Rome" sucks at encryption best practices, too.

nielsm
Jun 1, 2009



Bhaal posted:

Thanks all for the advice. Encryption's never been something I've followed too closely after understanding the basic mathematical concepts behind it. When it comes to choosing an encryption algorithm I just took a "when in Rome" attitude for best practices by going off of big ticket LAMP applications that I've worked in. Apparently "Rome" sucks at encryption best practices, too.

MD5, SHA-1 et.al. are not encryption algorithms, they are cryptographic hashes. They don't encrypt data, they fingerprint, and are designed to make it very hard to deliberately produce two different inputs that give the same output (generate a collision). However, both MD5 and SHA-1 have been broken, there are known ways of generating collisions with relatively little computation.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Ender.uNF posted:

:what:

Holy gently caress.

Well PHP did have mysql_real_escape_string which works just fine (and still does) in preventing SQL injections as long as you craft the SQL string properly, and there were libraries that emulated parameterized queries that essentially did some scrubbing of the input. Obviously with the new PDO libraries it looks much cleaner and makes it less-prone to developer laziness.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

tef posted:

Wait till you discover SCADA vulns :3:
http://lists.grok.org.uk/pipermail/full-disclosure/2012-April/086652.html
Problem:
An undocumented backdoor account exists within all released versions of RuggedCom's Rugged Operating System (ROS®). The username for the account, which cannot be disabled, is "factory" and its password is dynamically generated based on the device's MAC address. Multiple attempts have been made in the past 12 months to have this backdoor removed and customers notified.

sklnd
Nov 26, 2007

NOT A TRACTOR

nielsm posted:

MD5, SHA-1 et.al. are not encryption algorithms, they are cryptographic hashes. They don't encrypt data, they fingerprint, and are designed to make it very hard to deliberately produce two different inputs that give the same output (generate a collision). However, both MD5 and SHA-1 have been broken, there are known ways of generating collisions with relatively little computation.

The issue with use of hash algorithms like MD5 and SHA-1 for hashing passwords is unrelated to attacks for MD5 and SHA-1. They're both not resource intensive algorithms, which makes brute-force searches for the plaintext feasible for crappy passwords on very parallel hardware.

tef
May 30, 2004

-> some l-system crap ->
No-one tell ShoulderDaemon that you're talking about crypto, he's had enough this week

shrughes
Oct 11, 2008

(call/cc call/cc)

McGlockenshire posted:

Or at least PBKDF2, an RFC-specified, expert-reviewed mechanism. The circles I wade in tend to prefer it to even blowfish/bcrypt. Here's a library for PHP 5.3+ that implements it well.

Here are reasons not to recommend PBKDF2: http://news.ycombinator.com/item?id=3725723 The first one is important.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

shrughes posted:

Here are reasons not to recommend PBKDF2: http://news.ycombinator.com/item?id=3725723 The first one is important.

While that point is true, it's also simple enough to both DIY and verify that it's actually working correctly.

shrughes
Oct 11, 2008

(call/cc call/cc)

McGlockenshire posted:

While that point is true, it's also simple enough to both DIY and verify that it's actually working correctly.

How do you verify that it's actually working correctly?

Opinion Haver
Apr 9, 2007

shrughes posted:

How do you verify that it's actually working correctly?

Prove it in Coq :iamafag:

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

shrughes posted:

How do you verify that it's actually working correctly?

check to see that it generates the correct result for 'hello world'

shrughes
Oct 11, 2008

(call/cc call/cc)

Aleksei Vasiliev posted:

check to see that it generates the correct result for 'hello world'

How do you know what the correct result is?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

shrughes posted:

How do you know what the correct result is?

Verify against the reference implementation?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Suspicious Dish posted:

Verify against the reference implementation?

PBKDF2 is described as agnostic to the underlying cryptographic primitives, as well as being parametric in iteration count and key length. This means that there may not be a "reference implementation" easily available for the particular combination of parameters chosen for your implementation. It is much harder for amateurs to verify correct implementations of PBKDF2 than it has any right to be.

zeekner
Jul 14, 2007

Goddamn, never roll your own crypto implementation. How hard is that? It's literally less work and cheaper to use a professionally written and publicly licensed library.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

shrughes posted:

How do you know what the correct result is?
verify against a previous PHP implementation found on google

tef
May 30, 2004

-> some l-system crap ->
now you have two problems

Vanadium
Jan 8, 2005

Make sure you keep the unhashed passwords around when you find a bug in your DIY cipher, you can fix it and then regenerate all the hashes!

1337JiveTurkey
Feb 17, 2005

Burn everything down and replace it with Kerberos.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Hammerite posted:

Also, I just found out that the PHP development team is planning to deprecate the mysql extension. Well I never.

Based on the speed at which the PHP development team usually moves, I'm assuming that means 20 years from now, bargain basement hosting servers running PHP will finally start logging warnings about how mysql_* has been deprecated since version 9.0 (which will have been released in 2021). The log files will never be read, of course.

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
Well this codebase is just :stonk:

So after bringing this site up to the CTO I luckily didn't get pushback on fixing it because if anything else this falls deep in CYA territory. Now I've got the lovely task this morning of getting the most egregious security flaws scrubbed out of this site. Oh hey, check out their mysql_connect.php:
php:
<?
DEFINE ('DB_USER', 'xxxx');
DEFINE ('DB_PASSWORD', 'xxxx');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'xxxx');

// Make the connnection and then select the database.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );
mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );

// Function for escaping and trimming form data.
/*function escape_data ($data) { 
    global $dbc;
    if (ini_get('magic_quotes_gpc')) {
        $data = stripslashes($data);
    }
    return mysql_real_escape_string (trim ($data), $dbc);
}*/
$images_dir = "images/products";
?>
I've never seen db info registered as global constants but I'm guessing it's not a good idea. The mysql_connect lines are pretty standard if you are using php's mysql_ functions, but I'm guessing they stole it from some tutorial anyway. The weird escape wrapper, plus it being commented out, plus the images variable are just :psypop:

The commented function explains why a lot of their queries needlessly wrap post/get variables around parens, like so:
php:
<?
$query = "SELECT id,blah FROM mytable WHERE id='".($_GET['id'])."'";
?>
I'm guessing they used their silly escape_string function, and then took it out at some point. Why I don't know. There is of course no source control for any of this. That is if you're not counting things like file.php vs. file_ORIG.php, or the copy of the whole app with some minor adjustments under a directory (in public_html) called myapp_BETA.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Bhaal posted:

I've never seen db info registered as global constants but I'm guessing it's not a good idea.

How else would you do it?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
In a configuration file?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

pokeyman posted:

In a configuration file?

Sure, you put that information in a configuration file or define it in a configuration script, I'm not seeing the distinction, other than the fact that having to instruct the scripting engine to parse a file to get the credentials is pointless extra work.

e: ↓ also true.

Hammerite fucked around with this message at 20:36 on Apr 26, 2012

wwb
Aug 17, 2004

Insofar as PHP goes, having the config is a PHP file is typically better because your chances of the server serving that file directly are alot lower than if it is sitting in config.inc or whatever.

Personally I'd use a nested hashtable by environment, YMMV.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Well, you put it in a config file and then you have a different config file locally for the development environment, a different config file for a test environment, a differing config file for a staging environment, etc. Developing against the production database is a practice limited to PHP shops.

Nothing saying the config file itself can't be a PHP file.

(Also, from what I've seen about PHP variables and string interpolation, the last place I'd want my db credentials is in a global constant that all of my lovely scripts have access to and can possibly be teased enough to output.)

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

pokeyman posted:

Well, you put it in a config file and then you have a different config file locally for the development environment, a different config file for a test environment, a differing config file for a staging environment, etc. Developing against the production database is a practice limited to PHP shops.

Nothing saying the config file itself can't be a PHP file.

Yeah, it sounds like we are agreeing with one another as far as that goes.

pokeyman posted:

(Also, from what I've seen about PHP variables and string interpolation, the last place I'd want my db credentials is in a global constant that all of my lovely scripts have access to and can possibly be teased enough to output.)

Apart from doing something braindead like eval'ing untrusted data I have a hard time seeing how that could happen accidentally.

Opinion Haver
Apr 9, 2007

Hammerite posted:

Apart from doing something braindead like eval'ing untrusted data I have a hard time seeing how that could happen accidentally.

Accidentally removing the leading < while editing your script. Live.

This happened to Tumblr a while ago, I don't remember if anything came of it.

ShadoX
Oct 4, 2004
There is no W!

yaoi prophet posted:

Accidentally removing the leading < while editing your script. Live.

This happened to Tumblr a while ago, I don't remember if anything came of it.

I think that qualifies as "absolutely braindead"

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
It just seems to me you shouldn't have that information existing beyond the scope of its need. Not that it's terribly likely something will happen with it, but having your DB connection credentials available anywhere during runtime if there was any upstream DB interaction just seems a little reckless when you can easily have it fall out of scope after the connection's been made, and keep that info at rest somewhere outside the reach of webroot or whatever you happen to be using so it can never accidentally be served up plain.

ShadoX posted:

I think that qualifies as "absolutely braindead"
Murphy's Law. Absolutely braindead and yet it happens. The thing is the cost of some of these pre-emptive damage control measures are so minute that it's pretty easy to justify considering what you could put at stake when a freak accident does come around. When asked to detail exactly what data was compromised and how, when your audience is CEOs, clients, shareholders, and so on all experiencing their own damage control on this, you do not want to be in the category of someone who knew the risk existed and dismissed cheap, additional measures to mitigate that risk becoming a reality. After that they really are not going to care how impossible the chances were.

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
Sorry if I keep making GBS threads up this thread but this site is just.. just... :negative:

php:
<?
$file_path = '/home/betasite/reqsRes/' . $_GET['id'];
if(filesize($file_path) != FALSE){
    $fp = fopen($file_path,"r");
    $contents = fread($fp,filesize($file_path));
     header("Cache-Control: no-cache");
...
    header('Content-Length: '. filesize($file_path)); 
     echo $contents;
}?>

revmoo
May 25, 2006

#basta
Haha well at least it's not exec().

ToxicFrog
Apr 26, 2008


Hammerite posted:

Apart from doing something braindead...

How many PHP sites do you know that don't do something completely braindead somewhere?

MononcQc
May 29, 2007

ToxicFrog posted:

How many PHP sites do you know that don't do something completely braindead somewhere?

I'd extend that to software in general, to be honest. As soon as it's complex enough, at some point, something braindead is bound to be in there.

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

Stealing links from HN: http://stackoverflow.com/questions/4456438/how-can-i-pass-the-string-null-through-wsdl-soap-from-as3-to-coldfusion-web

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply