web week five

web week five

任务

  1. 学习file inclusion,了解各种伪协议姿势;
  2. 完成dvwa第三个模块file inclusion;
  3. 继续学习php。

File inclusion

File Inclusion,意思是文件包含漏洞,是指当服务器开启allow_url_include选项时,就可以通过php的一些特性函数
include()
require()
include_once()
require_once()
利用url去动态包含文件,此时如果没有对文件来源进行严格审查,就会导致任意文件读取或者任意命令执行。文件包含漏洞分为本地文件包含漏洞与远程文件包含漏洞,远程文件包含漏洞是因为开启了php配置中的allow_url_fopen选项(选项开启之后,服务器允许包含一个远程的文件)。

文件包含漏洞的一般特征如下:

?page=a.PHP

?home=a.html

?file=content
(在DVWA中我们可以见到的是?page=类型的文件包含漏洞。)

几种经典的测试方法:

?file=…/…/…/…/…/etc/passwdd

?page=file:///etc/passwd

?home=main.cgi

?page=http://www.a.com/1.php

http://1.1.1.1/…/…/…/…/dir/file.txt

(通过多个…/可以让目录回到根目录中然后再进入目标目录)

LOW

先看看源代码
在这里插入图片描述
这里服务器端对page参数没有做任何的过滤跟检查。
构造url如下。
http://localhost/DVWA-master/vulnerabilities/fi/?page=/etc/shadow在这里插入图片描述

报错,显示没有这个文件但暴露了服务器文件的绝对路径:
D:\phpStudy32\PHPTutorial\WWW\DVWA-master\vulnerabilities\fi\index.php
所以构造url如下。
http://localhost/DVWA-master/vulnerabilities/fi/?page=D:\phpStudy32\PHPTutorial\WWW\DVWA-master\php.ini
在这里插入图片描述
成功读取了服务器的php.ini文件。

为了增加隐蔽性,可以对http://localhost/DVWAmaster/vulnerabilities/fi/page=http://localhost/phpinfo.txt
进行编码,同样可以执行成功。在这里插入图片描述

Medium

先来看看源代码
在这里插入图片描述
Medium级别的代码增加了str_replace函数,对page参数进行了一定的处理,将
”http:// ”、”https://”、 ” …/”、”…\”替换为空字符,这里只是过滤了远程包含,但没有过滤本地包含。
在这里插入图片描述
使用str_replace函数是极其不安全的,因为可以使用双写绕过替换规则。例如page=htthttp://p://localhost/phpinfo.txt时,str_replace函数会将http://删除,于是page=http://10.10.10.151/phpinfo.txt,成功执行远程命令。
在这里插入图片描述
他这里把…/给过滤了,但是我在进行操作时,发现竟然还可以用,也不知道为啥。
在这里插入图片描述

High

来看源代码
在这里插入图片描述
High级别的代码使用了fnmatch函数检查page参数,要求page参数的开头必须是file,服务器才会去包含相应的文件。

构造如下URL:

http://localhost/DVWA-master/vulnerabilities/fi/page=file:///D:\phpStudy32\PHPTutorial\WWW\DVWA-master\php.ini
在这里插入图片描述
成功读取文件!

php学习

这个周我们来学的的是php的流程控制

流程控制:代码执行的方向。

控制分类:

  1. 顺序结构:基本结构,从上往下依次执行。
  2. 分支结构:根据给定的条件,执行不同的代码块。
  3. 循环结构:在某个条件控制范围内,指定的代码块可以重复执行。

分支结构

if结构

给定一个条件,并设置多个情况,通过判断条件,设置具体的执行块。

最简if:一段代码,决定是否执行。

if(条件表达式){  
//满足条件所执行的代码段 
}else{
//不满足条件执行的代码段
}

复杂if结构:就如同复合结构一般套娃类型。
这里写一段简单的小代码。

<?php



  $day = 'sunday';
  
  if($day == 'sunday'){
  	echo 'go out';
  }else{
  echo 'work' ;
}

在这里插入图片描述
注意:条件特别多采用复合形式,如果嵌套形式过多,感觉会懵。

Switch分支

通过同一条件用多个值来执行对应的代码。
判断方式:将条件放在分支结构内部判断。
基本语法:

switch(条件表达式){
//所有条件判断:逐个执行
	case1:
		要执行的的代码段;
		break//匹配成功,系统不会再次匹配条件,表示中断
	case2:
		要执行的代码段;
		……
		default//匹配失败的代码;
}

这里我们进行实例:

<?php



	$day = 1;
	
	switch($day){
		case 1:
			echo '1';
			break;
		case 2:
			echo '2';
			break;
		case 3:
			echo '3';
			break;
		default:
			echo 'error';
			break;
}

在这里插入图片描述

循环结构

  • for循环:通过条件、起始和终止判断执行;
  • while循环:通过判断条件终止;
  • Do-while循环:跟while差不多;
  • Foreach循环:专门针对数组。

(啊,感觉和C语言差不多,就不写了吧!)

The OpenStack Foundation supported the creation of this book with plane tickets to Austin, lodging (including one adventurous evening without power after a windstorm), and delicious food. For about USD $10,000, we could collaborate intensively for a week in the same room at the Rackspace Austin office. The authors are all members of the OpenStack Foundation, which you can join. Go to the Foundation web site. We want to acknowledge our excellent host Rackers at Rackspace in Austin: Emma Richards of Rackspace Guest Relations took excellent care of our lunch orders and even set aside a pile of sticky notes that had fallen off the walls. Betsy Hagemeier, a Fanatical Executive Assistant, took care of a room reshuffle and helped us settle in for the week. The Real Estate team at Rackspace in Austin, also known as “The Victors,” were super responsive. Adam Powell in Racker IT supplied us with bandwidth each day and second monitors for those of us needing more screens. On Wednesday night we had a fun happy hour with the Austin OpenStack Meetup group and Racker Katie Schmidt took great care of our group. We also had some excellent input from outside of the room: Tim Bell from CERN gave us feedback on the outline before we started and reviewed it mid-week. Sébastien Han has written excellent blogs and generously gave his permission for re-use. Oisin Feeley read it, made some edits, and provided emailed feedback right when we asked. Inside the book sprint room with us each day was our book sprint facilitator Adam Hyde. Without his tireless support and encouragement, we would have thought a book of this scope was impossible in five days. Adam has proven the book sprint method effectively again and again. He creates both tools and faith in collaborative authoring at www.booksprints.net. We couldn’t have pulled it off without so much supportive help and encouragement.
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值