Advertisement
FlyFar

arduino_wifi_duck.ino

Jul 17th, 2023
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 4.34 KB | Cybersecurity | 0 0
  1. #include <Keyboard.h>
  2. #define BAUD_RATE 57200
  3.  
  4. #define ExternSerial Serial1
  5.  
  6. String bufferStr = "";
  7. String last = "";
  8.  
  9. int defaultDelay = 0;
  10.  
  11. void Line(String _line)
  12. {
  13.   int firstSpace = _line.indexOf(" ");
  14.   if(firstSpace == -1) Press(_line);
  15.   else if(_line.substring(0,firstSpace) == "STRING"){
  16.     for(int i=firstSpace+1;i<_line.length();i++) Keyboard.write(_line[i]);
  17.   }
  18.   else if(_line.substring(0,firstSpace) == "DELAY"){
  19.     int delaytime = _line.substring(firstSpace + 1).toInt();
  20.     delay(delaytime);
  21.   }
  22.   else if(_line.substring(0,firstSpace) == "DEFAULTDELAY") defaultDelay = _line.substring(firstSpace + 1).toInt();
  23.   else if(_line.substring(0,firstSpace) == "REM"){} //nothing :/
  24.   else if(_line.substring(0,firstSpace) == "REPLAY") {
  25.     int replaynum = _line.substring(firstSpace + 1).toInt();
  26.     while(replaynum)
  27.     {
  28.       Line(last);
  29.       --replaynum;
  30.     }
  31.   } else{
  32.       String remain = _line;
  33.  
  34.       while(remain.length() > 0){
  35.         int latest_space = remain.indexOf(" ");
  36.         if (latest_space == -1){
  37.           Press(remain);
  38.           remain = "";
  39.         }
  40.         else{
  41.           Press(remain.substring(0, latest_space));
  42.           remain = remain.substring(latest_space + 1);
  43.         }
  44.         delay(5);
  45.       }
  46.   }
  47.  
  48.   Keyboard.releaseAll();
  49.   delay(defaultDelay);
  50. }
  51.  
  52.  
  53. void Press(String b){
  54.   if(b.length() == 1) Keyboard.press(char(b[0]));
  55.   else if (b.equals("ENTER")) Keyboard.press(KEY_RETURN);
  56.   else if (b.equals("CTRL")) Keyboard.press(KEY_LEFT_CTRL);
  57.   else if (b.equals("SHIFT")) Keyboard.press(KEY_LEFT_SHIFT);
  58.   else if (b.equals("ALT")) Keyboard.press(KEY_LEFT_ALT);
  59.   else if (b.equals("GUI")) Keyboard.press(KEY_LEFT_GUI);
  60.   else if (b.equals("UP") || b.equals("UPARROW")) Keyboard.press(KEY_UP_ARROW);
  61.   else if (b.equals("DOWN") || b.equals("DOWNARROW")) Keyboard.press(KEY_DOWN_ARROW);
  62.   else if (b.equals("LEFT") || b.equals("LEFTARROW")) Keyboard.press(KEY_LEFT_ARROW);
  63.   else if (b.equals("RIGHT") || b.equals("RIGHTARROW")) Keyboard.press(KEY_RIGHT_ARROW);
  64.   else if (b.equals("DELETE")) Keyboard.press(KEY_DELETE);
  65.   else if (b.equals("PAGEUP")) Keyboard.press(KEY_PAGE_UP);
  66.   else if (b.equals("PAGEDOWN")) Keyboard.press(KEY_PAGE_DOWN);
  67.   else if (b.equals("HOME")) Keyboard.press(KEY_HOME);
  68.   else if (b.equals("ESC")) Keyboard.press(KEY_ESC);
  69.   else if (b.equals("BACKSPACE")) Keyboard.press(KEY_BACKSPACE);
  70.   else if (b.equals("INSERT")) Keyboard.press(KEY_INSERT);
  71.   else if (b.equals("TAB")) Keyboard.press(KEY_TAB);
  72.   else if (b.equals("END")) Keyboard.press(KEY_END);
  73.   else if (b.equals("CAPSLOCK")) Keyboard.press(KEY_CAPS_LOCK);
  74.   else if (b.equals("F1")) Keyboard.press(KEY_F1);
  75.   else if (b.equals("F2")) Keyboard.press(KEY_F2);
  76.   else if (b.equals("F3")) Keyboard.press(KEY_F3);
  77.   else if (b.equals("F4")) Keyboard.press(KEY_F4);
  78.   else if (b.equals("F5")) Keyboard.press(KEY_F5);
  79.   else if (b.equals("F6")) Keyboard.press(KEY_F6);
  80.   else if (b.equals("F7")) Keyboard.press(KEY_F7);
  81.   else if (b.equals("F8")) Keyboard.press(KEY_F8);
  82.   else if (b.equals("F9")) Keyboard.press(KEY_F9);
  83.   else if (b.equals("F10")) Keyboard.press(KEY_F10);
  84.   else if (b.equals("F11")) Keyboard.press(KEY_F11);
  85.   else if (b.equals("F12")) Keyboard.press(KEY_F12);
  86.   else if (b.equals("SPACE")) Keyboard.press(' ');
  87.   //else Serial.println("not found :'"+b+"'("+String(b.length())+")");
  88. }
  89.  
  90. void setup() {
  91.  
  92.   Serial.begin(BAUD_RATE);
  93.   ExternSerial.begin(BAUD_RATE);
  94.  
  95.   pinMode(13,OUTPUT);
  96.   digitalWrite(13,HIGH);
  97.  
  98.   Keyboard.begin();
  99. }
  100.  
  101. void loop() {
  102.   if(ExternSerial.available()) {
  103.     bufferStr = ExternSerial.readStringUntil("END");
  104.     Serial.println(bufferStr);
  105.   }
  106.  
  107.   if(bufferStr.length() > 0){
  108.    
  109.     bufferStr.replace("\r","\n");
  110.     bufferStr.replace("\n\n","\n");
  111.    
  112.     while(bufferStr.length() > 0){
  113.       int latest_return = bufferStr.indexOf("\n");
  114.       if(latest_return == -1){
  115.         Serial.println("run: "+bufferStr);
  116.         Line(bufferStr);
  117.         bufferStr = "";
  118.       } else{
  119.         Serial.println("run: '"+bufferStr.substring(0, latest_return)+"'");
  120.         Line(bufferStr.substring(0, latest_return));
  121.         last=bufferStr.substring(0, latest_return);
  122.         bufferStr = bufferStr.substring(latest_return + 1);
  123.       }
  124.     }
  125.    
  126.     bufferStr = "";
  127.     ExternSerial.write(0x99);
  128.     Serial.println("done");
  129.   }
  130. }
  131.  
Tags: Hack Arduino wifi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement