Skip to content

Commit

Permalink
update20190324
Browse files Browse the repository at this point in the history
程序优化
  • Loading branch information
shack2 committed Mar 24, 2019
1 parent 463d87e commit fd5c889
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 48 deletions.
6 changes: 3 additions & 3 deletions SNETCracker/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 38 additions & 35 deletions SNETCracker/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public partial class Main : Form
private int retryCount = 0;
private int maxThread = 50;
private int timeOut = 5;
private string dic_username_path = "";
private string dic_password_path = "";
private string dic_target_path = "";

private Boolean crackerOneCount = true;//只检查一个账户
public int successCount = 0;
Expand Down Expand Up @@ -89,7 +86,7 @@ public Main()
/// <param name="text">显示文本</param>
public void LogAppend(Color color, string text)
{
if (this.txt_log.Text.Length > 100000) {
if (this.txt_log.Text.Length > 10000) {
this.txt_log.Clear();
}
this.txt_log.SelectionColor = color;
Expand Down Expand Up @@ -449,7 +446,7 @@ private void cracker()
}
else {
stp.QueueWorkItem<string, string, int>(ScanPort, ip, serviceName, port);
stp.WaitFor(1000);
stp.WaitFor(1);
}
}
}
Expand Down Expand Up @@ -516,7 +513,7 @@ private void cracker()
if (cracker.EndsWith(serviceName))
{
stp.QueueWorkItem<string, string, string>(crackerService, cracker, username, pass);
stp.WaitFor(1000);
stp.WaitFor(1);
}
}
}
Expand All @@ -537,8 +534,8 @@ private void cracker()
public void stopCraker() {
if (stp != null&& !stp.IsShuttingdown&&this.crackerThread!=null) {
LogWarning("等待线程结束...");
this.crackerThread.Abort();
stp.Shutdown();
this.crackerThread.Abort();
while (stp.InUseThreads>0) {
Thread.Sleep(50);
}
Expand All @@ -553,7 +550,7 @@ public void stopCraker() {
}
private Boolean initDic() {

if ("".Equals(this.txt_target.Text) && "".Equals(this.dic_target_path))
if ("".Equals(this.txt_target.Text))
{
MessageBox.Show("请设置需要检查的目标的IP地址或域名!");
return false;
Expand Down Expand Up @@ -649,33 +646,38 @@ private Boolean initDic() {
//加载自定义字典字典
if (notAutoSelectDic)
{
if (!"".Equals(this.dic_username_path))
if (this.txt_username.Text.EndsWith(".txt"))
{
this.list_username = FileTool.readFileToList(this.dic_username_path);
this.list_username = FileTool.readFileToList(this.txt_username.Text);
}

if (!"".Equals(this.dic_password_path))
{
this.list_password = FileTool.readFileToList(this.dic_password_path);
else {
if (this.txt_username.Text.Length > 0)
{
this.list_username.Clear();
this.list_username.Add(this.txt_username.Text);
}
}
if (this.txt_username.Text.Length > 0)

if (this.txt_password.Text.EndsWith(".txt"))
{
this.list_username.Clear();
this.list_username.Add(this.txt_username.Text);
this.list_password = FileTool.readFileToList(this.txt_password.Text);
}
if (this.txt_password.Text.Length > 0)
{
this.list_password.Clear();
this.list_password.Add(this.txt_password.Text);
else {
if (this.txt_password.Text.Length > 0)
{
this.list_password.Clear();
this.list_password.Add(this.txt_password.Text);
}
}

if (this.list_username.Count <= 0)
{
MessageBox.Show("请设置需要检查的用户名!");
return false;
}
else if (this.list_password.Count <= 0)
{
MessageBox.Show("请设置检查的密码字典!");
MessageBox.Show("请设置检查的密码!");
return false;
}
}
Expand Down Expand Up @@ -747,8 +749,8 @@ public void rdpResult(ResponseType type, Server rdp) {
}

}

delegate Server addRDPdelegate(String ip, int port,String username, String password,int timeout);

private Server addRDPClient(String ip,int port,String username,String password,int timeout) {
Server server = new Server();
RdpClient rdp = null;
Expand All @@ -761,6 +763,7 @@ private Server addRDPClient(String ip,int port,String username,String password,i
server.username = username;
server.password = password;
rdp = new RdpClient(server);
rdp.Location = new Point(this.rdp_panle.Location.X+new Random().Next(50), this.rdp_panle.Location.Y+new Random().Next(100));
server.client = rdp;
this.rdp_panle.Controls.Add(rdp);
rdp.OnResponse += rdpResult;
Expand All @@ -781,12 +784,8 @@ private Server addRDPClient(String ip,int port,String username,String password,i
private void ClearRDP(RdpClient rdp){
try
{
if (rdp.IsDisposed == false)
{
rdp.Dispose();
}
rdp.Dispose();
this.rdp_panle.Controls.Remove(rdp);

}
catch (Exception e) {
FileTool.log("RDP资源清理异常-" + e.Message);
Expand All @@ -800,21 +799,25 @@ private Server creackRDP(String ip, int port,String username, String password, i
try {
server = (Server)this.rdp_panle.Invoke(new addRDPdelegate(addRDPClient), ip, port, username, password, timeout);
server.isEndMRE.WaitOne();
server.client.Disconnect();
this.rdp_panle.Invoke(new deleteClearRDP(ClearRDP), server.client);
this.rdp_panle.BeginInvoke(new deleteClearRDP(ClearRDP), server.client);
}catch(Exception e){
FileTool.log("creackRDP错误:" + e.Message);
}
return server;
}





private void btn_cracker_Click(object sender, EventArgs e)
{
this.btn_cracker.Enabled = false;
this.list_success_username.Clear();
this.services_list.Enabled = false;

crackerThread = new Thread(cracker);
crackerThread.Start();
crackerThread.Start();

}

private void initStatusCount()
Expand Down Expand Up @@ -870,7 +873,7 @@ private void btn_importUername_Click(object sender, EventArgs e)
if (ofd.ShowDialog() == DialogResult.OK)
{
if (!string.IsNullOrEmpty(ofd.FileName)) {
this.dic_username_path = ofd.FileName;
this.txt_username.Text = ofd.FileName;
LogInfo("导入用户名成功!");
}
}
Expand All @@ -884,7 +887,7 @@ private void btn_importPassword_Click(object sender, EventArgs e)

if (!string.IsNullOrEmpty(ofd.FileName))
{
this.dic_password_path = ofd.FileName;
this.txt_password.Text = ofd.FileName;
LogInfo("导入密码字典成功!");
}
}
Expand Down Expand Up @@ -1101,7 +1104,7 @@ public static String getSid()
return sid;
}

private static int version = 20190323;
private static int version = 20190324;
public static string versionURL = "http://www.shack2.org/soft/getNewVersion?ENNAME=SNETCracker&NO="+ Uri.EscapeDataString(getSid())+ "&VERSION="+ version;
private void tsmi_help_version_Click(object sender, EventArgs e)
{
Expand Down
3 changes: 3 additions & 0 deletions SNETCracker/Model/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace SNETCracker.Model
{
Expand All @@ -22,5 +23,7 @@ public class Server
public Boolean isConnected = false;
public RdpClient client = null;
public long userTime = 0;
public TabPage tp = null;
public TabControl tc = null;
}
}
2 changes: 1 addition & 1 deletion SNETCracker/SmartThread/WorkItemsQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ private void ValidateNotDisposed()
{
if(_isDisposed)
{
throw new ObjectDisposedException(GetType().ToString(), "The SmartThreadPool has been shutdown");
//throw new ObjectDisposedException(GetType().ToString(), "The SmartThreadPool has been shutdown");
}
}

Expand Down
34 changes: 25 additions & 9 deletions SNETCracker/rdp/RdpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace MyRDP
public class RdpClient : AxMsRdpClient7NotSafeForScripting
{
private Server server = null;
public String name = "";
public delegate void OnResponseDelegate(ResponseType type, Server server);
public event OnResponseDelegate OnResponse;
public System.Timers.Timer timeOutLog = new System.Timers.Timer();
Expand All @@ -36,14 +37,29 @@ public RdpClient(Server cserver)

private void Finished()
{
try
{
if (this.Connected != 0)
{
this.Disconnect();
}
}
catch (Exception ce)
{
FileTool.log("Finished:" + ce.Message);
}
OnResponse(ResponseType.Finished, server);

}
private void TimeOut(object sender, ElapsedEventArgs e)
{
this.timeOutLog.Stop();
Finished();
}




public delegate void deConnect(string ip, int port, string user, string pass);
public void Connect(string ip, int port, string user, string pass)
{
Expand All @@ -54,21 +70,17 @@ public void Connect(string ip, int port, string user, string pass)
this.timeOutLog.Start();
this.Server = ip;
this.ColorDepth = 1;

this.AdvancedSettings.Compress = 1;
this.Password = pass;
this.ColorDepth = 1;
this.Server = ip;
this.UserName = user;
this.AdvancedSettings7.Compress = 1;
this.AdvancedSettings7.EnableMouse = 0;
this.AdvancedSettings7.EnableWindowsKey = 0;
this.AdvancedSettings7.RDPPort = port;
this.AdvancedSettings7.ClearTextPassword = pass;
this.AdvancedSettings7.EncryptionEnabled = 0;
this.AdvancedSettings7.EnableCredSspSupport = true;
this.AdvancedSettings7.ConnectToAdministerServer=true;
this.AdvancedSettings7.ConnectToAdministerServer = true;

this.AdvancedSettings7.EnableMouse = 0;
this.AdvancedSettings7.EnableWindowsKey = 0;
this.AdvancedSettings7.EncryptionEnabled = 0;
this.AdvancedSettings7.AuthenticationLevel = 0;
this.AdvancedSettings7.RedirectClipboard = false;
this.AdvancedSettings7.overallConnectionTimeout = server.timeout;
Expand All @@ -84,8 +96,9 @@ public void Connect(string ip, int port, string user, string pass)
sc.WarnAboutSendingCredentials = false;
sc.WarnAboutClipboardRedirection = false;
sc.ShowRedirectionWarningDialog = false;

this.Connect();

}
catch (Exception e)
{
Expand All @@ -108,13 +121,16 @@ private void Rdp_OnLoginComplete(object sender, EventArgs e)
{
this.server.isSuccess = true;
this.server.banner = this.Version;

Finished();
}

private void Rdp_OnLoginError(object sender, IMsTscAxEvents_OnLogonErrorEvent e)
{
this.server.isSuccess = false;

Finished();

}

private void Rdp_OnWaring(object sender, IMsTscAxEvents_OnWarningEvent e)
Expand Down

0 comments on commit fd5c889

Please sign in to comment.