Eric @ EricBess WebHome

胜不骄,败不馁,胸有激雷而面如平湖

Chinese (Simplified) flagItalian flagKorean flagPortuguese flagEnglish flagGerman flagFrench flagSpanish flagJapanese flagArabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flagCroat flagDanish flagFinnish flagHindi flagPolish flagRumanian flagSwedish flagNorwegian flagCatalan flagFilipino flagHebrew flagIndonesian flagLatvian flagLithuanian flagSerbian flagSlovak flagSlovenian flagUkrainian flagVietnamese flag
By N2H

php防止恶意访问小程序

本来写PAYPAL IPN response 时用来防止反复尝试的函数,保护性很差,后来改成原地址审核($hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);if(!preg_match('/paypal\.com$/', $hostname)) {.....),所以个就弃用了。在删之前记录不来,应该有更好的算法,不知道谁有研究。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if (!avoid_refresh ('15')) die ("Hacking Attempt!!");
.....
.....
.....
function avoid_refresh ($time){
	session_start();
  if (isset($_SESSION["post_sep"])) {
      if (time() - $_SESSION["post_sep"] < $time)  {
      	$_SESSION["post_sep"] = time();
        return false;
      } else {
          $_SESSION["post_sep"] = time();
          return true;
      }
  } else {
      $_SESSION["post_sep"] = time();
      return true;
  }
}

10月 30th, 2008 Posted by eric | Coding | no comments

PHP 数据加密

数据加密在我们生活中的地位已经越来越重要了,尤其是考虑到在网络上发生的大量交易和传输的大量数据。如果对于采用安全措施有兴趣的话,也一定会有兴趣了解PHP提供的一系列安全功能。在本篇文章中,我们将介绍这些功能,提供一些基本的用法,以便你能够为自己的应用软件中增加安全功能。

预备知识

在详细介绍PHP的安全功能之前,我们需要花点时间来向没有接触过这方面内容的读者介绍一些有关密码学的基本知识,如果对密码学的基本概念已经非常熟悉,就可以跳过去这一部分。

密码学可以通俗地被描述为对加/解密的研究和实验,加密是将易懂的资料转换为不易懂资料的过程,解密则是将不易懂的资料转换为原来易懂资料的过程。不易懂的资料被称作密码,易懂的资料被称作明码。

数据的加/解密都需要一定的算法,这些算法可以非常地简单,如著名的凯撒码,但当前的加密算法要相对复杂得多,其中一些利用现有的方法甚至是无法破译的 。

PHP的加密功能只要有一点使用非Windows平台经验的人可能对crypt()也相当熟悉,这一函数完成被称作单向加密的功能,它可以加密一些明码,但不能够将密码转换为原来的明码。尽管从表面上来看这似乎是一个没有什么用处的功能,但它的确被广泛用来保证系统密码的完整性。因为,单向加密的口令一旦落入第三方人的手里,由于不能被还原为明文,因此也没有什么大用处。在验证用户输入的口令时,用户的输入采用的也是单向算法,如果输入与存储的经加密后的口令相匹配,则输入的口信一定是正确的。

crypt()函数

PHP同样提供了使用其crypt()函数完成单向加密功能的可能性。我将在这里简要地介绍该函数:

string crypt (string input_string [, string salt])

其中的input_string参数是需要加密的字符串,第二个可选的salt是一个位字串,它能够影响加密的暗码,进一步地排除被称作预计算攻击的可能性。缺省情况下,PHP使用一个2个字符的DES干扰串,如果你的系统使用的是MD5(我将在以后介绍MD5算法),它会使用一个12个字符的干扰串。顺便说一下,可以通过执行下面的命令发现系统将要使用的干扰串的长度:

print “My system salt size is: ”. CRYPT_SALT_LENGTH;

系统也可能支持其他的加密算法。crypt()支持四 种算法,下面是它支持的算法和相应的salt参数的长度:

算法 Salt长度
CRYPT_STD_DES 2-character (Default)
CRYPT_EXT_DES 9-character
CRYPT_MD5 12-character beginning with $
CRYPT_BLOWFISH 16-character beginning with $

1 2 3

10月 30th, 2008 Posted by eric | Coding, 未分类 | no comments

一些简单JP代码防止内容抄袭

利于简单JP代码就可以降低您的网站被内容抄袭,虽然可以破解但是还是您的站点的版权保护。

复制网站内容的时候自动加入版权信息

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
<script type="text/javascript">
document.body.oncopy = function () {
setTimeout( function () {
  var text = clipboardData.getData("text");
  if (text) {
   text = text + "\r\n本文来自:EricBess.com 详细出处参考:"+location.href; clipboardData.setData("text", text);
  }
    }, 100 )
}
</script>

以wordpress为例在head.php <body>后加上

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
<script type="text/javascript">
	document.body.oncopy=function(){
		event.returnValue=false;
		var t=document.selection.createRange().text;
		var s="本文来源于< ?php bloginfo('name'); ?>, 原文地址: < ?php the_permalink(); ?> ";
		clipboardData.setData('Text','\r\n'+t+'\r\n'+s+'\r\n');
	}
</script>

Click to continue reading

01月 24th, 2008 Posted by eric | 网站技术 | no comments

客户公司SOX关于LINUX帐号的审计要求及本人与redh­at工程师的解决之道。

SOX demand  for linux OS password 

      1. A unique user ID is required in combination with a password to access the system. 
      2. Automatic password changing after 60 days where technically feasible.  If not technically feasible, a compensating control is in place. 
      3. Password minimum length of 8 characters or maximum length allowed by system when the allowable length is less than 8 characters. 
      4. User IDs/Accounts suspended after 6 invalid logins if technically feasible.  If not technically feasible, a compensating control is in place. 
      5. Accounts inactive for 60 days are disabled if technically possible.  If not technically possible, a compensating control is in place. 
      6. Password history of 12 is enabled which prohibits the reuse of the last 12 passwords 
      7. Following a new user's initial logon to the application, the user is prompted to change password.

>From Me

For 2. Expired Setting
[root@localhost]# passwd -x 60 -w 10

For 1.Complexity Setting
Add the following lines to /etc/pam.d/passwd
password requisite       pam_cracklib.so type
="Retype-3-At-least-8-letters-1-capital-1- character" retry=3
minlen=10 ucredit=1 ocredit=1
password required        pam_unix.so use_authtok

Reference Documents
passwd manual
The Linux-PAM System Administrators' Guide
http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/pam.html#toc6

Click to continue reading

11月 15th, 2007 Posted by eric | Unix/BSD/Linux | no comments

扫描之王Nmap

      Nmap ("Network Mapper(网络映射器)") 是一款开放源代码的 网络探测和安全审核的工具。它的设计目标是快速地扫描大型网络,当然用它扫描单个 主机也没有问题。Nmap以新颖的方式使用原始IP报文来发现网络上有哪些主机,那些 主机提供什么服务(应用程序名和版本),那些服务运行在什么操作系统(包括版本信息), 它们使用什么类型的报文过滤器/防火墙,以及一堆其它功能。虽然Nmap通常用于安全审核, 许多系统管理员和网络管理员也用它来做一些日常的工作,比如查看整个网络的信息, 管理服务升级计划,以及监视主机和服务的运行。
     Nmap输出的是扫描目标的列表,以及每个目标的补充信息,至于是哪些信息则依赖于所使用的选项。 "所感兴趣的端口表格"是其中的关键。那张表列出端口号,协议,服务名称和状态。状态可能是open(开放的),filtered(被过滤的),closed(关闭的),或者unfiltered(未被过滤的)。Open(开放的)意味着目标机器上的应用程序正在该端口监听连接/报文。filtered(被过滤的) 意味着防火墙,过滤器或者其它网络障碍阻止了该端口被访问,Nmap无法得知它是open(开放的) 还是closed(关闭的)。closed(关闭的) 端口没有应用程序在它上面监听,但是他们随时可能开放。当端口对Nmap的探测做出响应,但是Nmap无法确定它们是关闭还是开放时,这些端口就被认为是unfiltered(未被过滤的) 如果Nmap报告状态组合open|filteredclosed|filtered时,那说明Nmap无法确定该端口处于两个状态中的哪一个状态。当要求进行版本探测时,端口表也可以包含软件的版本信息。当要求进行IP协议扫描时 (-sO),Nmap提供关于所支持的IP协议而不是正在监听的端口的信息。

      除了所感兴趣的端口表,Nmap还能提供关于目标机的进一步信息,包括反向域名,操作系统猜测,设备类型,和MAC地址。

安装

1
2
3
4
5
wget -P tar/ http://freshmeat.net/redir/nmap/7202/url_bz2/nmap-4.01.tar.bz2tar -zlvf tar/ nmap-4.01.tar.bz2
cd nmap-4.01
./configure --without-nmapfe
make
make install

参数手册
http://www.insecure.org/nmap/man/zh/

我的指令

1
nohup nmap -A -T4 -sS -p T:21-25,69,80,8080,110,65301 {domainname}/24 --host-timeout 600000 --min-hostgroup 50 -oN targets &

03月 9th, 2006 Posted by eric | Unix/BSD/Linux | no comments