Создайте волшебный пакет при переполнении стека

Я пытаюсь создать Волшебный пакет для применения WOL на определенном ПК, я пытался сделать это в том же формате, точно так же, как пакет выглядит в перехвате Wireshark, но ПК не распознает принимающий пакет как магический пакет

вот код:

UINT8*  CTestCase::CreateMagicPacket(IN OUT UINT8* p_buffer, IN int  size, IN MACAddress src, IN MACAddress dst)
{

UINT8 *my_buff_to_send = new UINT8[size]{ 0 }; //create new buffer with the size we wantfor (int i = 0; i < 6; i++) //broadcast address
{
my_buff_to_send[i] = 0xFF;
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[i]));
}

int m = 5;
for (size_t i = 6; i < 12; i++) //insert source mac adress to the new buffer
{

my_buff_to_send[i] = src.Get(m);
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[i]));
m--;
}my_buff_to_send[12] = 0x08;
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[12]));
my_buff_to_send[13] = 0x00;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[13]));
my_buff_to_send[14] =  0x45;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[14]));
my_buff_to_send[15] = 0x00;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[15]));
my_buff_to_send[16] = 0x00;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[16]));
my_buff_to_send[17] =  0x90;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[17]));
my_buff_to_send[18] = 0x48;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[18]));
my_buff_to_send[19] = 0x91;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[19]));
my_buff_to_send[20] = 0x00;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[20]));
my_buff_to_send[21] = 0x00;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[21]));
my_buff_to_send[22] = 0x80;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[22]));
my_buff_to_send[23] = 0x11;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[23]));
my_buff_to_send[24] = 0x00;  //insert permanent type to the buffer OR dd
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[24]));
my_buff_to_send[25] = 0x00;  //insert permanent type to the buffer OR bd
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[25]));
my_buff_to_send[26] = 0x0a;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[26]));
my_buff_to_send[27] = 0x0a;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[27]));
my_buff_to_send[28] = 0x0a;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[28]));
my_buff_to_send[29] = 0x05;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[29]));
my_buff_to_send[30] = 0xff;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[30]));
my_buff_to_send[31] = 0xff;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[31]));
my_buff_to_send[32] = 0xff;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[32]));
my_buff_to_send[33] = 0xff;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[33]));
my_buff_to_send[34] = 0xd0;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[34]));
my_buff_to_send[35] = 0x28;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[35]));
my_buff_to_send[36] = 0xff;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[36]));
my_buff_to_send[37] = 0xff;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[37]));
my_buff_to_send[38] = 0x00;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[38]));
my_buff_to_send[39] = 0x7c;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[39]));
my_buff_to_send[40] = 0x14;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[40]));
my_buff_to_send[41] = 0x9c;  //insert permanent type to the buffer
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[41]));for (int i = 42; i < 48; i++)
{
my_buff_to_send[i] = 0xFF;
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[i]));
}

int r = 5;
for (size_t i = 48; i < 54; i++) //insert source mac adress to the new buffer
{
my_buff_to_send[i] = dst.Get(r);
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[i]));
r--;
}

for (int i = 54; i < 60; i++)
{
my_buff_to_send[i] = 0xFF;
m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[i]));
}for (size_t j = 0; j < 16; j++)
{

for (int k = 5; k >= 0; k--) //insert destination mac adress to the buffer
{
int i = 60;
my_buff_to_send[i] = dst.Get(k);

m_pLog->AddMessage(" |");
m_pLog->AddMessage("%d ", UINT32(my_buff_to_send[i]));
i++;
}

}return my_buff_to_send;};

-1

Решение

Вам действительно нужно создать необработанный пакет Ethernet самостоятельно?

Когда я это сделал, я просто встроил волшебный пакет в нечто вроде UDP-пакета и передал его. Например:

#include "sock2/sock2.h"
int main() {
std::string MAC_address("\x00\x00\x00\x00\x00\x00", 6);
std::string buffer("\xff\xff\xff\xff\xff\xff");

for (int i=0; i<16; i++)
buffer.append(MAC_address);

IP::UDP::socket s;
s.setopt(SO_BROADCAST);

IP::address addr(192, 168, 0, 255, 5);
s.send(buffer, addr);
}

Это довольно минималистично (например, жестко закодированные адреса, практически без проверки ошибок), но с соответствующими байтами для MAC-адреса работает просто отлично. Я не пытался подробно проанализировать весь ваш код, но, похоже, он включает в себя гораздо больше, чем я ожидал бы, как правило, необходимо.

2

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]