Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pwnagotchi_pwngrid_spam #207

Merged
merged 69 commits into from
Sep 2, 2024
Merged

Conversation

valentin8709
Copy link
Contributor

@valentin8709 valentin8709 commented Aug 22, 2024

Proposed Changes

I suggest another Pwnagotchi PR, more customized, with Pwngrid spam feature.

This work mainly comes from @7h30th3r0n3, @viniciusbo and @sduenasg.

Types of Changes

Added features:

  • new Pwnagotchi option in WiFi menu;
  • find and act as a Pwnagotchi friend via Pwngrid;
  • run Pwngrid spam:
    • spam many Pwngrid names and faces all around;
    • [option] flood identities: uniq identifiers flooded in Pwngrid logs;
    • [option] run DoScreen: send very long names and faces which override Pwnagotchi screen.
  • Pwngrid spam is set from a customizable configuration file (see commit in sd_files/pwnagotchi/pwngridspam.txt).

Verification

Pwnagotchi should be able to work on any device.

Testing

Running Pwnagotchi should:

  1. Wakeup the pwnagotchi;
  2. Start acting as a friend;
  3. Press select should display Pwnagotchi menu with:
  • Find frens --> return acting as a friend by sending simple Pwngrid payloads;
  • Pwngrid spam --> run Pwngrid spam:
    • press esc to return acting as a friend
    • press next to enable / disable identity flood
    • press select to enable / disable DoScreen.
  • Main Menu --> return to main menu.

Demo here : https://youtu.be/PREiRrVc7Tg

User-Facing Change

Users has to put the config file at the root of the SD card / LittleFS like this:
/pwnagotchi/pwngridspam.txt

If not, it will not load Pwngrid spam feature.

valentin8709 and others added 30 commits August 2, 2024 15:49
@valentin8709
Copy link
Contributor Author

@bmorcelli, I would like to allocate a pwngrid_peer_numer dynamically with the result of ESP.getFreeHeap().
The idea would be to do something like:

pwngrid_peer_number = ESP.getFreeHeap() / pwngrid_peer_size / 2 --> 2 is to keep a minimum of free RAM
pwngrid_peer pwngrid_peers[pwngrid_peer_number];

Did I understand well what you suggest ?
How do I know the memory size of one pwngrid_peer ?

@bmorcelli
Copy link
Collaborator

the size of each object is defined by its struct:

typedef struct {
  int epoch;
  String face;
  String grid_version;
  String identity;
  String name;
  int pwnd_run;
  int pwnd_tot;
  String session_id;
  int timestamp;
  int uptime;
  String version;
  signed int rssi;
  int last_ping;
  bool gone;
} pwngrid_peer;

Strings allocate a lot of memory, in general, so when you reserve 30 pwngrid peers (for example), you reserve space for 6x30 String variable, 6*30 int (4byte size in general each) and 1x30 bool (1 byte) in DRAM memory when declaring it as Global variable in the .cpp file, and the problem is that this allocated memory will only be used for this purpose only.

My suggestion is to get rid of this method
´´´
pwngrid_peer_number = 30;
pwngrid_peer pwngrid_peers[pwngrid_peer_number];
´´´
and use instead

#include <vector>
std::vector<pwngrid_peer> pwngrid_peers;

// to add pwngrid_peers use something like:
void add_new_peer() {
    pwngrid_peer peer; // declare a local object to fill and use
    // fill the object with information
    peer.rssi = rssi;
    peer.last_ping = millis();
    peer.gone = false;
    peer.name = json["name"].as<String>();
    peer.face = json["face"].as<String>();
    peer.epoch = json["epoch"].as<int>();
    peer.grid_version = json["grid_version"].as<String>();
    peer.identity = identity;
    peer.pwnd_run = json["pwnd_run"].as<int>();
    peer.pwnd_tot = json["pwnd_tot"].as<int>();
    peer.session_id = json["session_id"].as<String>();
    peer.timestamp = json["timestamp"].as<int>();
    peer.uptime = json["uptime"].as<int>();
    peer.version = json["version"].as<String>();
    pwngrid_last_friend_name = pwngrid_peers.name;
    // Check if it exists in the list
    bool exists=false;
    for(auto peer_list:pwngrid_peers) {
        if(peer_list.identity==peer.identity) exists=true;
    }
    if(!exists && ESP.getFreeHeap()>1024) { //check if doesn't exists AND there are room in RAM memory to save
        pwngrid_peers.push_back(peer); // add the local object into the vector
    }
}
void delete_peer_gone(){ // delete peers wigh pwngrid_peers.gone = true
    std::vector<int> peer_gone; // create a vector of integers to save the index value of the element to be deleted
    int index = 0;
    for(const auto& peer_list:pwngrid_peers) {
        if(peer_list.gone) peer_gone.push_back(index); // saves the index value into the vector
        index++;
    }
    std::reverse(peer_gone.begin(), peer_gone.end()); // Reverse the vector to iterate from the end to the beginning
    for (auto ind:peer_gone) { 
        pwngrid_peers.erase(pwngrid_peers.begin()+ind); // delete the peer from the list
    }
   peer_gone.clear();
}

This is an example of how to allocate memory in vectors using the RAM as limit.

Once the function ends you must use pwngrid_peers.clear(); to release the RAM memory used in the process

@valentin8709
Copy link
Contributor Author

Wahou thanks a lot ! I'm learning many things with those explanations ❤️
I will try to do my best to implement this !

@bmorcelli
Copy link
Collaborator

Yeah boy!! I'm learning a lot too.. we are pushing these esp32 into another level.. many challenges will appear, but we will learn more and overcome them..

I'm glad this firmware is serving well one of it's purposes, that is for "educational purpose" lol

@valentin8709 valentin8709 marked this pull request as draft September 2, 2024 07:10
@valentin8709
Copy link
Contributor Author

I tried with dynamic allocation, but pwngrid_friends_tot is always zero. Therefore it never discover peers.
Work in progress.

@valentin8709 valentin8709 marked this pull request as ready for review September 2, 2024 15:25
@valentin8709
Copy link
Contributor Author

Working now 😄
@bmorcelli is the code ok with what you were thinking ?

@bmorcelli
Copy link
Collaborator

Yeah boy!! That's what I was talking about!

@pr3y pr3y merged commit 1156d17 into pr3y:main Sep 2, 2024
7 checks passed
@valentin8709 valentin8709 deleted the feature/palnagotchi branch September 3, 2024 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants