Skip to content

Instantly share code, notes, and snippets.

@Zepheus
Created December 4, 2013 22:03
Show Gist options
  • Save Zepheus/7796422 to your computer and use it in GitHub Desktop.
Save Zepheus/7796422 to your computer and use it in GitHub Desktop.
Quick & dirty script C# script to fetch WLAN passwords without Admin rights.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Diagnostics;
namespace WlanPasswords
{
class Program
{
static List<string> GetProfiles()
{
var list = new List<string>();
using (var p = new Process())
{
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = "wlan show profiles";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output;
bool dumping = false;
while ((output = p.StandardOutput.ReadLine()) != null)
{
if (!dumping)
{
if (output.StartsWith("User profiles"))
{
p.StandardOutput.ReadLine();
dumping = true;
}
}
else
{
var splitted = output.Trim().Split(' ');
if (splitted.Length > 3)
{
list.Add(string.Join(" ", splitted, 8, splitted.Length - 8));
}
}
}
}
return list;
}
static string GetPassword(string profile)
{
using (var p = new Process())
{
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = string.Format("wlan show profiles name=\"{0}\" key=clear", profile);
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
if (output.Contains("not found on the"))
return "NONE";
var keyOffset = output.IndexOf("Key Content") + "Key Content".Length;
if (keyOffset < 0)
return "NONE";
keyOffset = output.IndexOf(':', keyOffset) + 2;
var keyStop = output.IndexOf('\n', keyOffset) - 1;
return output.Substring(keyOffset, keyStop - keyOffset);
}
}
static void Main(string[] args)
{
Console.Title = "WLAN Dumper";
Console.WriteLine("WLAN Password Dumper (c) 2013 Cedric Van Goethem");
Console.WriteLine("---------------------");
foreach (var profile in GetProfiles())
{
Console.WriteLine("{0}:\t{1}", profile, GetPassword(profile));
}
Console.WriteLine("---------------------");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment