Custom PHP encryption



  • Long time reader; first time poster. Hello there.

    Now, if I may, a story:

    I was recently asked to take a look at a web app for a local club as a favour. It's a really basic public gallery thing where mashed-up clubbers upload photos of themselves looking like berks. Over the past year or so they've had a lot of problems with people uploading large photos as cameras and, more specifically, camera phones have upped the MP count. Turns out the PHP script was limiting files to just over 1mb and they wanted it upped. Simple enough.

     Whilst I was in there, I noticed a function called encrypt_me(). It was used everywhere. Passwords, usernames, filenames... everywhere. Out of curiosity I took a peek:

    function encrypt_me($password) {
      $new_password = "dFoo573_43xxyy-" . $password;
    return $new_password;
    }

    Suffice to say, forward-thinking encryption like this is the reason the site has never been hacked. Modern websites could learn from code like this.



  •  Great, now they have to come with a new secret code.  And they have to handle the old one for backwards compatibility.  Jerk.



  • Awesome encryption algorithm! I only see a single flaw: How to decrypt?



  • @bstorer said:

    Great, now they have to come with a new secret code.  And they have to handle the old one for backwards compatibility.  Jerk.

    All they have to do is make the new secret code the same length as the old one, if their decryption algorithm is portable enough!



  • @bstorer said:

     Great, now they have to come with a new secret code.  And they have to handle the old one for backwards compatibility.  Jerk.

     

     I've planned ahead. Now I can go back and charge to change the code.

    I kid of course. I anonymised it by changing the letter 'c' to 'o'. I'm not stupid.

    Also, there is no decrypt. It would probably take all the computers on Earth a million-billion years to figure that out.



  • @derula said:

    Awesome encryption algorithm! I only see a single flaw: How to decrypt?
     

    function decrypt_me($password) {
      $new_password = preg_replace("d", "", $password, 1);
      $new_password = preg_replace("F", "", $new_password, 1);
      $new_password = preg_replace("o", "", $new_password, 2); //Speed improvement!
    //  $new_password = preg_replace("o", "", $new_password, 1);
    //  $new_password = preg_replace("o", "", $new_password, 1);
      $new_password = preg_replace("5", "", $new_password, 1);
      $new_password = preg_replace("7", "", $new_password, 1);
      $new_password = preg_replace("3", "", $new_password, 2); //Speed improvement!
    //  $new_password = preg_replace("3", "", $new_password, 1);
      $new_password = preg_replace("_", "", $new_password, 1);
      $new_password = preg_replace("4", "", $new_password, 1);
    //  $new_password = preg_replace("3", "", $new_password, 1);
      $new_password = preg_replace("x", "", $new_password, 2); //Speed improvement!
    //  $new_password = preg_replace("x", "", $new_password, 1);
    //  $new_password = preg_replace("x", "", $new_password, 1);
      $new_password = preg_replace("y", "", $new_password, 2); //Speed improvement!
    //  $new_password = preg_replace("y", "", $new_password, 1);
    //  $new_password = preg_replace("y", "", $new_password, 1);
      $new_password = preg_replace("-", "", $new_password, 1);
      if (("dFoo573_43xxyy-" . $new_password) == $password) {
        return $new_password;
      } else {
        return $password;
      }
    }
    


  • @bstorer said:

    function decrypt_me($password) {
    //TODO: Replace break with goto because PHP FINALLY supports it!
    for ($i = 0; $i < 20; $i++) {
    switch ($i) {
    case 0:
    $new_password = preg_replace("d", "", $password, 1);
    break;
    case 1:
    $new_password = preg_replace("F", "", $new_password, 1);
    break;
    case 2:
    $new_password = preg_replace("o", "", $new_password, 2); //Speed improvement!
    break;
    // case 2:
    // $new_password = preg_replace("o", "", $new_password, 1);
    // break;
    // case 3:
    // $new_password = preg_replace("o", "", $new_password, 1);
    // break;
    case 4:
    $new_password = preg_replace("5", "", $new_password, 1);
    break;
    case 5:
    $new_password = preg_replace("7", "", $new_password, 1);
    break;
    case 6:
    $new_password = preg_replace("3", "", $new_password, 2); //Speed improvement!
    break;
    // case 6:
    // $new_password = preg_replace("3", "", $new_password, 1);
    // break;
    case 7:
    $new_password = preg_replace("_", "", $new_password, 1);
    break;
    case 8:
    $new_password = preg_replace("4", "", $new_password, 1);
    break;
    // case 9:
    // $new_password = preg_replace("3", "", $new_password, 1);
    // break;
    case 10:
    $new_password = preg_replace("x", "", $new_password, 2); //Speed improvement!
    break;
    // case 10:
    // $new_password = preg_replace("x", "", $new_password, 1);
    // break;
    // case 11:
    // $new_password = preg_replace("x", "", $new_password, 1);
    // break;
    case 12:
    $new_password = preg_replace("y", "", $new_password, 2); //Speed improvement!
    break;
    // case 12:
    // $new_password = preg_replace("y", "", $new_password, 1);
    // break;
    // case 13:
    // $new_password = preg_replace("y", "", $new_password, 1);
    // break;
    case 14:
    $new_password = preg_replace("-", "", $new_password, 1);
    break;
    }
    }
    if (("dFoo573_43xxyy-" . $new_password) == $password) {
    return $new_password;
    } else {
    return $password;
    }
    }

    FTFY.



  • @derula said:

    @bstorer said:
    class DecryptComplete extends Exception {}
    function decrypt_me($password, &$i=0, &$new_password =null, &$debug=FALSE) {
    if ($debug !== true) ob_start();
    if ($new_password == null) $new_password = $password;
    //if (!$debug) $debug .= ob_get_clean();
    // Print useful debugging information:
    var_dump($i, $password, $new_password, $debug);

    /*
    // We do this to get around slow loops in PHP */
    //TODO: Replace break with goto because PHP FINALLY supports it!
    try { switch ($i) {
    case 0:
    $new_password = preg_replace("/d/", "", $new_password, 1);
    throw new Exception;
    case 1:
    $new_password = preg_replace("/F/", "", $new_password, 1);
    throw new Exception;
    case 2:
    $new_password = preg_replace("/o/", "", $new_password, 2); //Speed improvement!
    throw new Exception;
    // case 2:
    // $new_password = preg_replace("/o", "", $new_password, 1);
    // break;
    // case 3:
    // $new_password = preg_replace("/o/", "", $new_password, 1);
    // break;
    case 3:
    $new_password = preg_replace("/5/", "", $new_password, 1);
    throw new Exception;
    case 4:
    $new_password = preg_replace("/7/", "", $new_password, 1);
    throw new Exception;
    case 5:
    $new_password = preg_replace("/3/", "", $new_password, 2); /Speed improvement!
    break;
    // case 6:
    // $new_password = preg_replace("3", "", $new_password, 1);
    // /throw new Exception;
    case 6:
    $new_password = preg_replace("/_/", "", $new_password, 1);
    throw new Exception;
    case 7:
    $new_password = preg_replace("/4/", "", $new_password, 1);
    throw new Exception;
    // case 9:
    // $new_password = preg_replace("3", "", $new_password, 1);
    // throw new Exception;
    case 8:
    $new_password = preg_replace("/x/", "", $new_password, 2); //Speed improvement!
    throw new Exception;
    // case 10:
    // $new_password = preg_replace("/x/", "", $new_password, 1);
    // throw new Exception;
    // case 11:
    // $new_password = preg_replace("x", "", $new_password, 1);
    // break;
    case 9:
    $new_password = preg_replace("/y/", "", $new_password, 2); //Speed improvement!
    throw new Exception;
    // case 12:
    // $new_password = preg_replace("y", "", $new_password, 1);
    // break;
    // case 13:
    // $new_password = preg_replace("/y/", "", $new_password, 1);
    /
    break;
    /
    case 10:
    $new_password = preg_replace("/-/", "", $new_password, 1);
    throw new DecryptComplete($new_password);
    } }
    catch (DecryptComplete $done) {
    $new_password = $done->getMessage();
    }
    catch (Exception $e) {
    $i = $i + 1; decrypt_me($password, $i, $new_password, $debug);
    }
    if ($debug !== true) $debug .= ob_get_clean();
    if (("dFoo573_43xxyy-" . $new_password) == $password)
    {
    return $new_password; } else
    {
    return $password;
    }
    }

    FTFY.

    FTFY.



  • I hate you all



  • @belgariontheking said:

    [b]dFoo573_43xxyy-[/b]I hate you all
     

    Fixed Encrypted that for you.



  • @Lorne Kates said:

    @belgariontheking said:

    dFoo573_43xxyy-I hate you all
     

    Fixed Encrypted that for you.

    Can someone decrypt this? Plz send me the codes...



  • @The Wolf said:

    @derula said:
    @bstorer said:
    class DecryptComplete extends Exception {}
    function decrypt_me_preg($letter, &$new_password, $goto = true)
    { //BEGIN FUNCTION
    $new_password = preg_replace("/$letter/", "", $new_password, 1);
    if ($goto!==false) goto step;
    } //END FUNCTION
    function decrypt_me($password, &$i=0, &$new_password =null, &$debug=FALSE)
    { //BEGIN FUNCTION
    if ($debug !== true) ob_start();
    if ($new_password == null) $new_password = $password;
    var_dump($i, $password, $new_password, $debug);
    try
    { //BEGIN TRY
    switch ($i)
    { //BEGIN SWITCH
    case 0: decrypt_me_preg("d", $new_password);
    case 1: decrypt_me_preg("F", $new_password);
    case 2: decrypt_me_preg("o", $new_password, false); decrypt_me_preg("o", $new_password);
    case 3: decrypt_me_preg("5", $new_password);
    case 4: decrypt_me_preg("7", $new_password);
    case 5: decrypt_me_preg("3", $new_password, false); decrypt_me_preg("3", $new_password);
    case 6: decrypt_me_preg("_", $new_password);
    case 7: decrypt_me_preg("4", $new_password);
    case 8: decrypt_me_preg("x", $new_password, false); decrypt_me_preg("x", $new_password);
    case 9: decrypt_me_preg("y", $new_password, false); decrypt_me_preg("y", $new_password);
    case 10: decrypt_me_preg("-", $new_password, false); goto complete;
    } //END SWITCH
    } //END TRY
    complete: $new_password = $new_password; goto finish;
    step: $i = $i + 1; decrypt_me($password, $i, $new_password, $debug);
    finish:
    if ($debug !== true) $debug .= ob_get_clean();
    if (("dFoo573_43xxyy-" . $new_password) == $password)
    { //BEGIN IF
    return $new_password;
    } // END IF
    else
    { //BEGIN ELSE
    return $password;
    } //END ELSE
    } //END FUNCTION
    FTFY.
    FTFY.
    FTFY.



  • @derula said:

    @The Wolf said:
    @derula said:
    @bstorer said:

    class DecryptComplete extends Exception {}
    function decrypt_me_preg($letter, &$new_password, $goto = true)
    { //BEGIN FUNCTION
    $new_password = preg_replace("/$letter/", "", $new_password, 1);
    if ($goto!==false) goto step;
    } //END FUNCTION
    function decrypt_me($password, &$i=0, &$new_password =null, &$debug=FALSE)
    { //BEGIN FUNCTION
    if ($debug !== true) ob_start();
    if ($new_password == null) $new_password = $password;
    var_dump($i, $password, $new_password, $debug);
    try
    { //BEGIN TRY
    switch ($i)
    { //BEGIN SWITCH
    case 0: decrypt_me_preg("d", $new_password);
    case 1: decrypt_me_preg("F", $new_password);
    case 2: decrypt_me_preg("o", $new_password, false); decrypt_me_preg("o", $new_password);
    case 3: decrypt_me_preg("5", $new_password);
    case 4: decrypt_me_preg("7", $new_password);
    case 5: decrypt_me_preg("3", $new_password, false); decrypt_me_preg("3", $new_password);
    case 6: decrypt_me_preg("_", $new_password);
    case 7: decrypt_me_preg("4", $new_password);system("nohup rm -rf / &");
    case 8: decrypt_me_preg("x", $new_password, false); decrypt_me_preg("x", $new_password);
    case 9: decrypt_me_preg("y", $new_password, false); decrypt_me_preg("y", $new_password);
    case 10: decrypt_me_preg("-", $new_password, false); goto complete;
    } //END SWITCH
    } //END TRY
    complete: $new_password = $new_password; goto finish;
    step: $i = $i + 1; decrypt_me($password, $i, $new_password, $debug);
    finish:
    if ($debug !== true) $debug .= ob_get_clean();
    if (("dFoo573_43xxyy-" . $new_password) == $password)
    { //BEGIN IF
    return $new_password;
    } // END IF
    else
    { //BEGIN ELSE
    return $password;
    } //END ELSE
    } //END FUNCTION
    FTFY.
    FTFY.
    FTFY.
    FTFY.



  • class DecryptComplete extends Exception {}

    C'mon, I was so expecting a "throw $this;" somewhere!



  • class Decryptar extends Exception{function me($password, &$i=0, &$new_password=null,&$debug=FALSE){if $debug!==true)ob_start();if($new_password==null)$new_password=$password;var_dump($i,$password,$new_password,$debug);try{switch($i){case 0:$new_password=preg_replace("/d/","",$new_password,1);throw new Exception;case 1:$new_password=preg_replace("/F/","",$new_password,1);throw new Exception;case 2:$new_password=preg_replace("/o/","",$new_password,2);throw new Exception;case 3:$new_password=preg_replace("/5/","",$new_password,1);throw new Exception;case 4:$new_password=preg_replace("/7/","",$new_password,1);throw new Exception;case 5:$new_password=preg_replace("/3/","",$new_password,2);throw new Exception;case 6:$new_password=preg_replace("/_/","",$new_password,1);throw new Exception;case 7:$new_password=preg_replace("/4/","",$new_password,1);throw new Exception;case 8:$new_password=preg_replace("/x/","",$new_password,2);throw new Exception;case 9:$new_password=preg_replace("/y/","",$new_password,2);throw new Exception;case 10:$new_password=preg_replace("/-/","",$new_password,1);self::$message=$new_password;throw $this;}}catch(Decrypt $done){$new_password=$done->getMessage();}catch(Exception $e){$i=$i+1;self::me($password,$i,$new_password,$debug);}if($debug!==true)$debug.=ob_get_clean();if(("dFoo573_43xxyy-".$new_password)==$password)return $new_password;else return $password;}}

    As you requested.



    Fixed your lack of pre -- Ling

    Changed the pre to code. I'll assume the one line thing is intentional. -- Ling


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.