Skip to content

Commit 53702eb

Browse files
committed
Basic support for internet access
1 parent abb5159 commit 53702eb

File tree

6 files changed

+671
-18
lines changed

6 files changed

+671
-18
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ else ()
107107
endif ()
108108
endif ()
109109

110-
add_library(${PROJECT_NAME}_static STATIC src/exploit.cpp src/packet.cpp)
110+
add_library(${PROJECT_NAME}_static STATIC src/exploit.cpp src/packet.cpp src/gateway.cpp)
111111
set_target_properties(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
112112
target_link_libraries(${PROJECT_NAME}_static PUBLIC ${APP_LINK_LIB})
113113
target_compile_options(${PROJECT_NAME}_static PUBLIC ${APP_BUILD_OPTIONS})

include/exploit.h

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <functional>
44
#include <atomic>
5+
#include <mutex>
6+
#include <unordered_map>
57
#include <PcapLiveDevice.h>
68
#include <PPPoELayer.h>
79

@@ -14,9 +16,77 @@
1416

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

19+
class PortData {
20+
public:
21+
PortData(uint16_t realPort, uint16_t hostPort, int socketFd) : realPort(realPort), hostPort(hostPort),
22+
socketFd(socketFd) {}
23+
24+
uint16_t realPort;
25+
uint16_t hostPort;
26+
int socketFd;
27+
};
28+
29+
class PortMap {
30+
public:
31+
32+
std::shared_ptr<PortData> addMapping(uint16_t realPort, int type);
33+
34+
void removeMapping(uint16_t hostPort);
35+
36+
std::shared_ptr<PortData> getMapByRealPort(uint16_t realPort);
37+
38+
std::shared_ptr<PortData> getMapByHostPort(uint16_t hostPort);
39+
40+
void clear();
41+
42+
~PortMap();
43+
44+
private:
45+
std::unordered_map<uint16_t, std::shared_ptr<PortData>> real2HostMap;
46+
std::unordered_map<uint16_t, std::shared_ptr<PortData>> host2RealMap;
47+
std::mutex map_mutex;
48+
};
49+
50+
class Gateway {
51+
public:
52+
/**
53+
* Constructor
54+
* @param iface_ps4 interface to the PS4
55+
* @param iface_net interface to the internet
56+
*/
57+
Gateway(const std::string &iface_ps4, const std::string &iface_net);
58+
59+
int lcp_negotiation() const;
60+
61+
int ipcp_negotiation() const;
62+
63+
int ppp_negotiation();
64+
65+
void run();
66+
67+
void stop();
68+
69+
~Gateway();
70+
71+
private:
72+
// interface to the PS4
73+
pcpp::PcapLiveDevice *dev{};
74+
// interface to the internet
75+
pcpp::PcapLiveDevice *net_dev{};
76+
// Gateway MAC address
77+
pcpp::MacAddress gateway_mac = pcpp::MacAddress::Zero;
78+
// PS4 MAC address
79+
pcpp::MacAddress ps4_mac = pcpp::MacAddress::Zero;
80+
PortMap portMap;
81+
82+
uint64_t host_uniq{};
83+
84+
bool running{};
85+
};
86+
1787
class PacketBuilder {
1888
public:
19-
static void hexPrint(const uint8_t* data, size_t len);
89+
static void hexPrint(const uint8_t *data, size_t len);
2090

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

@@ -36,9 +106,12 @@ class PacketBuilder {
36106

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

39-
static pcpp::Packet ipcpRequest(const pcpp::MacAddress &source_mac, const pcpp::MacAddress &target_mac);
109+
static pcpp::Packet ipcpRequest(const pcpp::MacAddress &source_mac, const pcpp::MacAddress &target_mac,
110+
const std::string &source_ipv4 = "41.41.41.41");
40111

41-
static pcpp::Packet ipcpNak(const pcpp::MacAddress &source_mac, const pcpp::MacAddress &target_mac, uint8_t id);
112+
static pcpp::Packet ipcpNak(const pcpp::MacAddress &source_mac, const pcpp::MacAddress &target_mac, uint8_t id,
113+
const std::string &target_ipv4 = "42.42.42.42", const std::string &dns1 = "",
114+
const std::string &dns2 = "");
42115

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

0 commit comments

Comments
 (0)