如何制作一个PHP串行代码系统


How to make a PHP serial code system

我正在考虑实现一个具有有效串行代码的MySQL数据库,该数据库将根据用户输入进行检查,并在检查返回true时授予应用程序的使用权限,但我知道这太基本了,因为用户(将使用基于本地主机的应用程序)可以很容易地破解数据库并添加自己的串行(或至少告诉其他对PHP有基本了解的人);SQL(如果他们认为应用程序是从"魔盒"里出来的)。

由于我以前没有这样做过,有什么流行的方法吗?如果你能给我一些建议就更好了。

如果他们有纯文本的PHP源代码,他们可以绕过你设置的任何保护。

也就是说,像ionCube (google it)这样的服务会混淆(编译?)代码,并且需要一个密钥(来自某个远程服务器)来解锁代码以执行。

或者您可以为客户托管软件,这样他们就不能直接访问应用程序。

您可以实现一个"call home",它发送用户在其站点上输入的序列。然后在数据库中检查该序列,并发送一个适当的回复,无论用户是否有权访问他的系统。您可以在用户登录他们的站点时执行此操作。

这样做的问题是,由于使用Zend Guard之类的工具在未加密/编码时很容易更改php文件,因此用户可以通过更改不进行调用来规避此问题,并始终返回true。或者他们可以改变他们的web服务器的hosts-file,将请求重新路由到他们自己的服务器,并在那里放置一个文件,接受你的检查,也总是返回true。

为了防止这种情况,你必须加密你的php文件,并实现一个质询-响应系统来检查它们的序列。

如果我明白你的意思。: - p

永远不可能有100%牢不可破的方法。任何都可以逆向工程,如果你有时间和技术。

但是你能做的最大限度地提高你不被破解的机会是使用某种预编译器/混淆器,如Zend Guard或ionCube(和其他)来保护你的代码。其中大多数(全部?)都带有预构建的许可功能,这绝对是推荐的方法。

问题是它们不是免费的…

编辑

想想看,你可以自己实现这样的东西,安全的,在一组非常选定的情况下。如果您正在开发可以分发HipHop二进制文件的东西,那么您可以实现一些东西,而不必担心它会被不太了解自己在做什么的人破解。HipHop可以从github免费下载。

远程数据库检查仍然是一个坏主意,因为人们可以嗅探网络流量并反向工程密钥,或者学习如何欺骗响应(简单的hosts文件编辑可以拦截网络流量)。您最好为每个实例硬编码密钥,并在每次调用时使用某种算法进行验证—本网站和Google可以在此帮助您。

主机上有mysql数据库客户应用连接到它,对吧?

首先,我将在数据库和客户之间添加一个层。http远程接口,如SOAP或使用json的其他接口。

你应该加密到它的连接(https),或者至少使用一些挑战响应方法。

但是当你的应用程序是开源的,总有办法绕过它。即使不是;-).

看这里http://dev.michaelnorris.co.uk/tests/random_string.php

<?php 
function makePin($lenth=10) { 
// makes a random alpha numeric string of a given lenth 
$aZ09 = array_merge(range('A', 'Z'), range('a', 'z'),range(0, 9));
//$aZ09 = array_merge(range('A', 'Z'), range(0, 9)); 
$out =''; 
for($c=0;$c < $lenth;$c++) { 
   $out .= $aZ09[mt_rand(0,count($aZ09)-1)]; 
} 
return $out; 
}
$obscure = makePin();
echo $obscure;
?>

我认为这实际上对你更好。看看这里http://dev.michaelnorris.co.uk/tests/random_password.php

我不能把这个例子归功于我,因为我把它从网上的其他来源拼凑在一起,我不记得了,但不管怎样,这里是。

<?php
// just so we know it is broken
error_reporting(E_ALL);
//string passType can be alpha, numeric, or alphanumeric defaults to alphanumeric int $length is the length of the password, defaults to eight
class randomPassword{
    function __construct($passType='alphanumeric', $length=8, $rangeLength=9){
        $this->setLength($length);
        $this->setRangeLength($rangeLength);
        $this->passType = $this->setPassType($passType);
    }
    function setRangeLength($rangeLength){
        $this->rangeLength=$rangeLength;
    }
    // set the length of the password
    private function setLength($length){
        $this->length=$length;
    }

    // set the type of password
    private function setPassType($passType){
        return $passType.'Chars';
    }
    // return an array of numbers
    private function numericChars(){
        return range(0, $this->rangeLength);
    }
    // return an array of chars
    private function alphaChars(){
        return range('a', 'z');
    }
    // return an array of alphanumeric chars
    private function alphaNumericChars(){
        return array_merge($this->numericChars(), $this->alphaChars());
    }
    // return a string of chars
    private function makeString(){
        // here we set the function to call based on the password type
        $funcName = $this->passType;
        return implode($this->$funcName());
    }
    // shuffle the chars and return $length of chars
    public function makePassword(){
        return substr(str_shuffle($this->makeString()), 1, $this->length);
    }
} // end class
function randomPassword($length) {
    // create an array of chars to use as password
    $chars = implode(array_merge(range(0,9), range('a', 'z')));
    // randomly snarf $length number of array keys
    return substr(str_shuffle($chars), 1, $length);
}
/*
try
{
$obj = new randomPassword('alphanumeric', 16, 100);
echo $obj->makePassword().'<br />';
}
catch(Exception $ex)
{
echo $ex->getMessage();
}
*/
echo strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5));
?>