Skip to content

Commit

Permalink
Basic support for internet access
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Jun 1, 2024
1 parent d210a32 commit 30a1230
Show file tree
Hide file tree
Showing 6 changed files with 672 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ else ()
endif ()
endif ()

add_library(${PROJECT_NAME}_static STATIC src/exploit.cpp src/packet.cpp)
add_library(${PROJECT_NAME}_static STATIC src/exploit.cpp src/packet.cpp src/gateway.cpp)
set_target_properties(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}_static PUBLIC ${APP_LINK_LIB})
target_compile_options(${PROJECT_NAME}_static PUBLIC ${APP_BUILD_OPTIONS})
Expand Down
79 changes: 76 additions & 3 deletions include/exploit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <functional>
#include <atomic>
#include <mutex>
#include <unordered_map>
#include <PcapLiveDevice.h>
#include <PPPoELayer.h>

Expand All @@ -14,9 +16,77 @@

#define hexdump(p) if(PacketBuilder::debug) PacketBuilder::hexPrint(p)

class PortData {
public:
PortData(uint16_t realPort, uint16_t hostPort, int socketFd) : realPort(realPort), hostPort(hostPort),
socketFd(socketFd) {}

uint16_t realPort;
uint16_t hostPort;
int socketFd;
};

class PortMap {
public:

std::shared_ptr<PortData> addMapping(uint16_t realPort, int type);

void removeMapping(uint16_t hostPort);

std::shared_ptr<PortData> getMapByRealPort(uint16_t realPort);

std::shared_ptr<PortData> getMapByHostPort(uint16_t hostPort);

void clear();

~PortMap();

private:
std::unordered_map<uint16_t, std::shared_ptr<PortData>> real2HostMap;
std::unordered_map<uint16_t, std::shared_ptr<PortData>> host2RealMap;
std::mutex map_mutex;
};

class Gateway {
public:
/**
* Constructor
* @param iface_ps4 interface to the PS4
* @param iface_net interface to the internet
*/
Gateway(const std::string &iface_ps4, const std::string &iface_net);

int lcp_negotiation() const;

int ipcp_negotiation() const;

int ppp_negotiation();

void run();

void stop();

~Gateway();

private:
// interface to the PS4
pcpp::PcapLiveDevice *dev{};
// interface to the internet
pcpp::PcapLiveDevice *net_dev{};
// Gateway MAC address
pcpp::MacAddress gateway_mac = pcpp::MacAddress::Zero;
// PS4 MAC address
pcpp::MacAddress ps4_mac = pcpp::MacAddress::Zero;
PortMap portMap;

uint64_t host_uniq{};

bool running{};
};

class PacketBuilder {
public:
static void hexPrint(const uint8_t* data, size_t len);
static void hexPrint(const uint8_t *data, size_t len);

static void hexPrint(const pcpp::Packet &packet);

Expand All @@ -36,9 +106,12 @@ class PacketBuilder {

static pcpp::Packet lcpAck(const pcpp::MacAddress &source_mac, const pcpp::MacAddress &target_mac, uint8_t id);

static pcpp::Packet ipcpRequest(const pcpp::MacAddress &source_mac, const pcpp::MacAddress &target_mac);
static pcpp::Packet ipcpRequest(const pcpp::MacAddress &source_mac, const pcpp::MacAddress &target_mac,
const std::string &source_ipv4 = "41.41.41.41");

static pcpp::Packet ipcpNak(const pcpp::MacAddress &source_mac, const pcpp::MacAddress &target_mac, uint8_t id);
static pcpp::Packet ipcpNak(const pcpp::MacAddress &source_mac, const pcpp::MacAddress &target_mac, uint8_t id,
const std::string &target_ipv4 = "42.42.42.42", const std::string &dns1 = "",
const std::string &dns2 = "");

static pcpp::Packet ipcpAck(const pcpp::MacAddress &source_mac, const pcpp::MacAddress &target_mac, uint8_t id,
const uint8_t *option, size_t option_len);
Expand Down
Loading

0 comments on commit 30a1230

Please sign in to comment.