/
example console.au3
64 lines (49 loc) · 1.26 KB
/
example console.au3
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
#include "TCPClient.au3"
#cs
To test this example,
execute a netcat server,
running this commands:
nc -vv -l -p 31337
#ce
Global $Password = "123456"
_TCPClient_OnReceive("receive")
_TCPClient_OnDisconnect("disconnect")
_TCPClient_DebugMode()
Func receive($iSocket, $sIP, $sData, $mPar)
If $mPar = "login" Then
If $sData = $Password Then
; right password, let's change the parameter
_TCPClient_SetParam($iSocket, "logged")
; and now bind
_TCPClient_BindAppToSocket($iSocket, "cmd.exe")
Else
_TCPClient_Send($iSocket, "Wrong password. Try again: ")
EndIf
Else
If $sData = "exit" Then
; unbinds
_TCPClient_UnBindAppToSocket($iSocket)
; says bye
_TCPClient_Send($iSocket, "See you")
; closes connection
_TCPClient_Disconnect($iSocket)
Else
; sends command directly to the process
_TCPClient_SendToBound($iSocket, $sData)
EndIf
EndIf
EndFunc
Func disconnect($iSocket, $sIP)
MsgBox(0, $iSocket, $sIP)
EndFunc
$iSocket = _TCPClient_Connect('127.0.0.1', '31337')
If @error Then
MsgBox(0, "", "could not connect. Error: " & @error)
Exit
EndIf
; Sets parameter to login, so we know what the server is doing
_TCPClient_SetParam($iSocket, "login")
_TCPClient_Send($iSocket, "Please enter password: ")
While True
Sleep(100)
WEnd