Scripting

BetterCAP has a builtin Javascript engine based on Otto that you can use to interact with the session and automate tasks.

Session scripts can be loaded using the -script FILENAME command line argument:

  1. sudo bettercap -script /path/to/script.js

Once loaded the script can run session commands:

  1. run('net.probe on');

or shell commands:

  1. run('!touch /tmp/yo');

register for specific events:

  1. onEvent('wifi.client.handshake', function(event){
  2. var data = event.data;
  3. var gps = session.GPS; // session is a global object with all the session data
  4. var what = 'handshake';
  5. if(data.pmkid != null) {
  6. what = "RSN PMKID";
  7. } else if(data.full) {
  8. what += " (full)";
  9. } else if(data.half) {
  10. what += " (half)";
  11. }
  12. log('💰 Captured ' + what + ':');
  13. log(' station: ' + data.station);
  14. log(' ap: ' + data.ap);
  15. log(' lat:' + gps.Latitude + ' lon:' + gps.Longitude + ' updated_at:' + gps.Updated.String());
  16. });

register for any event:

  1. onEvent(function(event){
  2. log(event.tag);
  3. });

perform HTTP queries:

  1. var resp = http.Get(url, {});
  2. if( resp.Error ) {
  3. log(resp.Error.Error());
  4. } else {
  5. log(resp.JSON.something);
  6. }

and a variety of other tasks depending on your imagination :D Check the scripts repository for some example scripts.