Skip to content

Commit 866b43f

Browse files
authored
Merge pull request #1 from qtc-de/dev
Merging dev to master [PowerUp]
2 parents c7985c9 + f37a3d1 commit 866b43f

File tree

165 files changed

+56081
-14393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+56081
-14393
lines changed

AntivirusBypass/Find-AVSignature.ps1

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ function Find-AVSignature
55
66
Locate tiny AV signatures.
77
8-
PowerSploit Function: Find-AVSignature
9-
Authors: Chris Campbell (@obscuresec) & Matt Graeber (@mattifestation)
10-
License: BSD 3-Clause
11-
Required Dependencies: None
12-
Optional Dependencies: None
8+
PowerSploit Function: Find-AVSignature
9+
Authors: Chris Campbell (@obscuresec) & Matt Graeber (@mattifestation)
10+
License: BSD 3-Clause
11+
Required Dependencies: None
12+
Optional Dependencies: None
1313
1414
.DESCRIPTION
1515
@@ -37,19 +37,19 @@ Optionally specifies the directory to write the binaries to.
3737
3838
.PARAMETER BufferLen
3939
40-
Specifies the length of the file read buffer . Defaults to 64KB.
40+
Specifies the length of the file read buffer . Defaults to 64KB.
4141
4242
.PARAMETER Force
4343
44-
Forces the script to continue without confirmation.
44+
Forces the script to continue without confirmation.
4545
4646
.EXAMPLE
4747
48-
PS C:\> Find-AVSignature -Startbyte 0 -Endbyte max -Interval 10000 -Path c:\test\exempt\nc.exe
49-
PS C:\> Find-AVSignature -StartByte 10000 -EndByte 20000 -Interval 1000 -Path C:\test\exempt\nc.exe -OutPath c:\test\output\run2 -Verbose
50-
PS C:\> Find-AVSignature -StartByte 16000 -EndByte 17000 -Interval 100 -Path C:\test\exempt\nc.exe -OutPath c:\test\output\run3 -Verbose
51-
PS C:\> Find-AVSignature -StartByte 16800 -EndByte 16900 -Interval 10 -Path C:\test\exempt\nc.exe -OutPath c:\test\output\run4 -Verbose
52-
PS C:\> Find-AVSignature -StartByte 16890 -EndByte 16900 -Interval 1 -Path C:\test\exempt\nc.exe -OutPath c:\test\output\run5 -Verbose
48+
Find-AVSignature -Startbyte 0 -Endbyte max -Interval 10000 -Path c:\test\exempt\nc.exe
49+
Find-AVSignature -StartByte 10000 -EndByte 20000 -Interval 1000 -Path C:\test\exempt\nc.exe -OutPath c:\test\output\run2 -Verbose
50+
Find-AVSignature -StartByte 16000 -EndByte 17000 -Interval 100 -Path C:\test\exempt\nc.exe -OutPath c:\test\output\run3 -Verbose
51+
Find-AVSignature -StartByte 16800 -EndByte 16900 -Interval 10 -Path C:\test\exempt\nc.exe -OutPath c:\test\output\run4 -Verbose
52+
Find-AVSignature -StartByte 16890 -EndByte 16900 -Interval 1 -Path C:\test\exempt\nc.exe -OutPath c:\test\output\run5 -Verbose
5353
5454
.NOTES
5555
@@ -63,10 +63,12 @@ http://www.exploit-monday.com/
6363
http://heapoverflow.com/f0rums/project.php?issueid=34&filter=changes&page=2
6464
#>
6565

66-
[CmdletBinding()] Param(
66+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')]
67+
[CmdletBinding()]
68+
Param(
6769
[Parameter(Mandatory = $True)]
6870
[ValidateRange(0,4294967295)]
69-
[UInt32]
71+
[UInt32]
7072
$StartByte,
7173

7274
[Parameter(Mandatory = $True)]
@@ -75,112 +77,110 @@ http://heapoverflow.com/f0rums/project.php?issueid=34&filter=changes&page=2
7577

7678
[Parameter(Mandatory = $True)]
7779
[ValidateRange(0,4294967295)]
78-
[UInt32]
80+
[UInt32]
7981
$Interval,
8082

8183
[String]
82-
[ValidateScript({Test-Path $_ })]
84+
[ValidateScript({Test-Path $_ })]
8385
$Path = ($pwd.path),
8486

8587
[String]
8688
$OutPath = ($pwd),
87-
88-
89-
[ValidateRange(1,2097152)]
90-
[UInt32]
91-
$BufferLen = 65536,
92-
89+
90+
[ValidateRange(1,2097152)]
91+
[UInt32]
92+
$BufferLen = 65536,
93+
9394
[Switch] $Force
94-
9595
)
9696

9797
#test variables
9898
if (!(Test-Path $Path)) {Throw "File path not found"}
9999
$Response = $True
100100
if (!(Test-Path $OutPath)) {
101101
if ($Force -or ($Response = $psCmdlet.ShouldContinue("The `"$OutPath`" does not exist! Do you want to create the directory?",""))){new-item ($OutPath)-type directory}
102-
}
102+
}
103103
if (!$Response) {Throw "Output path not found"}
104104
if (!(Get-ChildItem $Path).Exists) {Throw "File not found"}
105105
[Int32] $FileSize = (Get-ChildItem $Path).Length
106106
if ($StartByte -gt ($FileSize - 1) -or $StartByte -lt 0) {Throw "StartByte range must be between 0 and $Filesize"}
107107
[Int32] $MaximumByte = (($FileSize) - 1)
108108
if ($EndByte -ceq "max") {$EndByte = $MaximumByte}
109-
110-
#Recast $Endbyte into an Integer so that it can be compared properly.
111-
[Int32]$EndByte = $EndByte
112-
113-
#If $Endbyte is greater than the file Length, use $MaximumByte.
109+
110+
#Recast $Endbyte into an Integer so that it can be compared properly.
111+
[Int32]$EndByte = $EndByte
112+
113+
#If $Endbyte is greater than the file Length, use $MaximumByte.
114114
if ($EndByte -gt $FileSize) {$EndByte = $MaximumByte}
115-
116-
#If $Endbyte is less than the $StartByte, use 1 Interval past $StartByte.
117-
if ($EndByte -lt $StartByte) {$EndByte = $StartByte + $Interval}
118115

119-
Write-Verbose "StartByte: $StartByte"
120-
Write-Verbose "EndByte: $EndByte"
121-
116+
#If $Endbyte is less than the $StartByte, use 1 Interval past $StartByte.
117+
if ($EndByte -lt $StartByte) {$EndByte = $StartByte + $Interval}
118+
119+
Write-Verbose "StartByte: $StartByte"
120+
Write-Verbose "EndByte: $EndByte"
121+
122122
#find the filename for the output name
123123
[String] $FileName = (Split-Path $Path -leaf).Split('.')[0]
124124

125125
#Calculate the number of binaries
126126
[Int32] $ResultNumber = [Math]::Floor(($EndByte - $StartByte) / $Interval)
127127
if (((($EndByte - $StartByte) % $Interval)) -gt 0) {$ResultNumber = ($ResultNumber + 1)}
128-
128+
129129
#Prompt user to verify parameters to avoid writing binaries to the wrong directory
130130
$Response = $True
131131
if ( $Force -or ( $Response = $psCmdlet.ShouldContinue("This script will result in $ResultNumber binaries being written to `"$OutPath`"!",
132132
"Do you want to continue?"))){}
133133
if (!$Response) {Return}
134-
135-
Write-Verbose "This script will now write $ResultNumber binaries to `"$OutPath`"."
134+
135+
Write-Verbose "This script will now write $ResultNumber binaries to `"$OutPath`"."
136136
[Int32] $Number = [Math]::Floor($Endbyte/$Interval)
137-
138-
#Create a Read Buffer and Stream.
139-
#Note: The Filestream class takes advantage of internal .NET Buffering. We set the default internal buffer to 64KB per http://research.microsoft.com/pubs/64538/tr-2004-136.doc.
140-
[Byte[]] $ReadBuffer=New-Object byte[] $BufferLen
141-
[System.IO.FileStream] $ReadStream = New-Object System.IO.FileStream($Path, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read, $BufferLen)
142-
143-
#write out the calculated number of binaries
144-
[Int32] $i = 0
145-
for ($i -eq 0; $i -lt $ResultNumber + 1 ; $i++)
146-
{
147-
# If this is the Final Binary, use $EndBytes, Otherwise calculate based on the Interval
148-
if ($i -eq $ResultNumber) {[Int32]$SplitByte = $EndByte}
149-
else {[Int32] $SplitByte = (($StartByte) + (($Interval) * ($i)))}
150-
151-
Write-Verbose "Byte 0 -> $($SplitByte)"
152-
153-
#Reset ReadStream to beginning of file
154-
$ReadStream.Seek(0, [System.IO.SeekOrigin]::Begin) | Out-Null
155-
156-
#Build a new FileStream for Writing
157-
[String] $outfile = Join-Path $OutPath "$($FileName)_$($SplitByte).bin"
158-
[System.IO.FileStream] $WriteStream = New-Object System.IO.FileStream($outfile, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write, [System.IO.FileShare]::None, $BufferLen)
159-
160-
[Int32] $BytesLeft = $SplitByte
161-
Write-Verbose "$($WriteStream.name)"
162-
163-
#Write Buffer Length to the Writing Stream until the bytes left is smaller than the buffer
164-
while ($BytesLeft -gt $BufferLen){
165-
[Int32]$count = $ReadStream.Read($ReadBuffer, 0, $BufferLen)
166-
$WriteStream.Write($ReadBuffer, 0, $count)
167-
$BytesLeft = $BytesLeft - $count
168-
}
169-
170-
#Write the remaining bytes to the file
171-
do {
172-
[Int32]$count = $ReadStream.Read($ReadBuffer, 0, $BytesLeft)
173-
$WriteStream.Write($ReadBuffer, 0, $count)
174-
$BytesLeft = $BytesLeft - $count
175-
}
176-
until ($BytesLeft -eq 0)
177-
$WriteStream.Close()
178-
$WriteStream.Dispose()
137+
138+
#Create a Read Buffer and Stream.
139+
#Note: The Filestream class takes advantage of internal .NET Buffering. We set the default internal buffer to 64KB per http://research.microsoft.com/pubs/64538/tr-2004-136.doc.
140+
[Byte[]] $ReadBuffer=New-Object byte[] $BufferLen
141+
[System.IO.FileStream] $ReadStream = New-Object System.IO.FileStream($Path, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read, $BufferLen)
142+
143+
#write out the calculated number of binaries
144+
[Int32] $i = 0
145+
for ($i -eq 0; $i -lt $ResultNumber + 1 ; $i++)
146+
{
147+
# If this is the Final Binary, use $EndBytes, Otherwise calculate based on the Interval
148+
if ($i -eq $ResultNumber) {[Int32]$SplitByte = $EndByte}
149+
else {[Int32] $SplitByte = (($StartByte) + (($Interval) * ($i)))}
150+
151+
Write-Verbose "Byte 0 -> $($SplitByte)"
152+
153+
#Reset ReadStream to beginning of file
154+
$ReadStream.Seek(0, [System.IO.SeekOrigin]::Begin) | Out-Null
155+
156+
#Build a new FileStream for Writing
157+
[String] $outfile = Join-Path $OutPath "$($FileName)_$($SplitByte).bin"
158+
[System.IO.FileStream] $WriteStream = New-Object System.IO.FileStream($outfile, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write, [System.IO.FileShare]::None, $BufferLen)
159+
160+
[Int32] $BytesLeft = $SplitByte
161+
Write-Verbose "$($WriteStream.name)"
162+
163+
#Write Buffer Length to the Writing Stream until the bytes left is smaller than the buffer
164+
while ($BytesLeft -gt $BufferLen){
165+
[Int32]$count = $ReadStream.Read($ReadBuffer, 0, $BufferLen)
166+
$WriteStream.Write($ReadBuffer, 0, $count)
167+
$BytesLeft = $BytesLeft - $count
168+
}
169+
170+
#Write the remaining bytes to the file
171+
do {
172+
[Int32]$count = $ReadStream.Read($ReadBuffer, 0, $BytesLeft)
173+
$WriteStream.Write($ReadBuffer, 0, $count)
174+
$BytesLeft = $BytesLeft - $count
179175
}
180-
Write-Verbose "Files written to disk. Flushing memory."
181-
$ReadStream.Dispose()
182-
183-
#During testing using large binaries, memory usage was excessive so lets fix that
184-
[System.GC]::Collect()
185-
Write-Verbose "Completed!"
176+
until ($BytesLeft -eq 0)
177+
$WriteStream.Close()
178+
$WriteStream.Dispose()
179+
}
180+
Write-Verbose "Files written to disk. Flushing memory."
181+
$ReadStream.Dispose()
182+
183+
#During testing using large binaries, memory usage was excessive so lets fix that
184+
[System.GC]::Collect()
185+
Write-Verbose "Completed!"
186186
}

0 commit comments

Comments
 (0)