Skip to content

Commit

Permalink
client TCP
Browse files Browse the repository at this point in the history
  • Loading branch information
pr3y committed Jan 10, 2025
1 parent a39166f commit 1e0a6f7
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 68 deletions.
7 changes: 4 additions & 3 deletions src/core/menu_items/WifiMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "modules/pwnagotchi/pwnagotchi.h"
#endif

#include "modules/reverseShell/reverseShell.h"
//#include "modules/reverseShell/reverseShell.h"
// Developed by Fourier (github.com/9dl)
// Use BruceC2 to interact with the reverse shell server
// BruceC2: https://github.com/9dl/Bruce-C2
Expand All @@ -26,7 +26,7 @@

// 32bit: https://github.com/9dl/Bruce-C2/releases/download/v1.0/BruceC2_windows_386.exe
// 64bit: https://github.com/9dl/Bruce-C2/releases/download/v1.0/BruceC2_windows_amd64.exe
#include "modules/wifi/listenTCP.h"
#include "modules/wifi/tcp_utils.h"

void WifiMenu::optionsMenu() {
if(!wifiConnected) {
Expand All @@ -40,8 +40,9 @@ void WifiMenu::optionsMenu() {
}
options.push_back({"Wifi Atks", [=]() { wifi_atk_menu(); }});
options.push_back({"Evil Portal", [=]() { EvilPortal(); }});
options.push_back({"ReverseShell", [=]() { ReverseShell(); }});
//options.push_back({"ReverseShell", [=]() { ReverseShell(); }});
options.push_back({"Listen TCP", [=]() { listenTcpPort(); }});
options.push_back({"Client TCP", [=]() { clientTCP(); }});
#ifndef LITE_VERSION
options.push_back({"TelNET", [=]() { telnet_setup(); }});
options.push_back({"SSH", [=]() { ssh_setup(); }});
Expand Down
65 changes: 0 additions & 65 deletions src/modules/wifi/listenTCP.cpp

This file was deleted.

128 changes: 128 additions & 0 deletions src/modules/wifi/tcp_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// TODO: Be able to read bytes from server in background/task
// so there is no loss of data when inputing
#include "modules/wifi/tcp_utils.h"
#include "core/wifi_common.h"

bool inputMode;

void listenTcpPort() {
if (!wifiConnected) wifiConnectMenu();

WiFiClient tcpClient;
tft.fillScreen(TFT_BLACK);
tft.setTextSize(1);
tft.setTextColor(TFT_WHITE, TFT_BLACK);

String portNumber = keyboard("", 5, "TCP port to listen");
int portNumberInt = atoi(portNumber.c_str());

WiFiServer server(portNumberInt);
server.begin();

tft.println("Listening...");
tft.print(WiFi.localIP().toString().c_str());
tft.println(":" + portNumber);


for (;;) {
WiFiClient client = server.available(); // Wait for a client to connect

if (client) {
Serial.println("Client connected");
tft.println("Client connected");

while (client.connected()) {
if (inputMode) {
String keyString = keyboard("", 16, "send input data");
delay(300);
inputMode = false;
tft.fillScreen(TFT_BLACK);
tft.setCursor(0,0);
if (keyString.length() > 0) {
client.print(keyString); // Send the entire string to the client
Serial.print(keyString);
}
} else {
if (client.available()) {
char incomingChar = client.read(); // Read one byte at time from the client
tft.print(incomingChar);
Serial.print(incomingChar);
}
if (check(SelPress)) {
delay(300);
inputMode = true;
}
}
}
client.stop();
Serial.println("Client disconnected");
displayError("Client disconnected");

}
if (check(EscPress)) {
displayError("Exiting Listener");
server.stop();
break;
}
}
}

void clientTCP() {
if (!wifiConnected) wifiConnectMenu();

String serverIP = keyboard("", 15, "Enter server IP");
String portString = keyboard("", 5, "Enter server Port");
int portNumber = atoi(portString.c_str());

if (serverIP.length() == 0 || portNumber == 0) {
displayError("Invalid IP or Port");
return;
}

WiFiClient client;
if (!client.connect(serverIP.c_str(), portNumber)) {
displayError("Connection failed");
return;
}

tft.fillScreen(TFT_BLACK);
tft.setTextSize(1);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.println("Connected to:");
tft.println(serverIP + ":" + portString);
Serial.println("Connected to server");

while (client.connected()) {
if (inputMode) {
String keyString = keyboard("", 16, "send input data");
inputMode = false;
tft.fillScreen(TFT_BLACK);
tft.setCursor(0,0);
delay(300);
if (keyString.length() > 0) {
client.print(keyString);
Serial.print(keyString);
}
} else {
if (client.available()) {
char incomingChar = client.read();
tft.print(incomingChar);
Serial.print(incomingChar);
}
if (check(SelPress)) {
delay(300);
inputMode = true;
}
}
if (check(EscPress)) {
displayError("Exiting Client");
client.stop();
break;
}
}

displayError("Connection closed.");
Serial.println("Connection closed.");
client.stop();
}

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "core/mykeyboard.h"

void listenTcpPort();
void clientTCP();

0 comments on commit 1e0a6f7

Please sign in to comment.