Repository navigation
Expand file tree
/
Copy pathgetsocket.ps1
More file actions
77 lines (57 loc) · 1.85 KB
/
Copy pathgetsocket.ps1
File metadata and controls
77 lines (57 loc) · 1.85 KB
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
# name: ReadSocketReturn
# info: Get message from stream
# author: Derek Carter 23/10/2014
# inputs: stream object
# return: message
function ReadSocketReturn ($stream)
{
if($stream.CanRead)
{
$outputBuffer = "" #create empty output buffer
$encoding = new-object System.Text.AsciiEncoding #set encoding to ascii
$buffer = new-object System.Byte[] 1024 # create a 1024 byte buffer
# Keep reading while data is available
do
{
$read = $ns.Read($buffer, 0, 1024)
$outputBuffer += ($encoding.GetString($buffer, 0, $read))
}
while($stream.DataAvailable)
$outputBuffer
}
}
function CallLavaScript
{
# Get WMI envis process
$cm_line_obj = Get-WmiObject win32_process | Where-object {$_.Caption -Contains "envis_gui.exe"} | Select-object Commandline
# Split on "=" to get socket string
$st1 = $cm_line_obj.Commandline -split "="
# Get socket number and convert to int
$socket_id = [int]$st1[1].Substring(0,5)
$socket_id
$sfv = New-Object System.Net.Sockets.TcpClient("localhost", $socket_id)
if(!$sfv.Connected)
{
Write-Host "Failed to locally connect to port"
}
$lava_command = "exit.lava"
$ns = $sfv.GetStream()
$sw = new-object System.IO.StreamWriter($ns);
$sw.AutoFlush = 1
# Enable sending of telnet commands
$sw.Write("t")
# Check if can write
$msg = ReadSocketReturn $ns # Call getoutput function
# Check if return from Envisage is OK using REGEX
if($msg -match "OK")
{
# construct the command to launch lava
$command = "LAUNCH:" + $lava_command + [char]10 # [char]10 is equal to newline char
# Send command
$sw.WriteLine($command)
}
# Close socket
$sfv.Close()
}
CallLavaScript
write-host "does this come out now?"