Skip to content

Instantly share code, notes, and snippets.

@kewalaka
Created August 3, 2020 22:42
Show Gist options
  • Save kewalaka/fdaa00059632cad22fb3cc6970080f3a to your computer and use it in GitHub Desktop.
Save kewalaka/fdaa00059632cad22fb3cc6970080f3a to your computer and use it in GitHub Desktop.
<% @ Page Language = "C#" %>
<script runat = "server" >
protected void dumpObject (object o, Table outputTable) {
try {
Type refl_WindowsIdenty = typeof (System.Security.Principal.WindowsIdentity);
System.Reflection.MemberInfo[] refl_WindowsIdenty_members = o.GetType ().FindMembers (
System.Reflection.MemberTypes.Property,
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance,
delegate (System.Reflection.MemberInfo objMemberInfo, Object objSearch) { return true; },
null);
foreach (System.Reflection.MemberInfo currentMemberInfo in refl_WindowsIdenty_members) {
TableRow r = new TableRow ();
TableCell k = new TableCell ();
TableCell v = new TableCell ();
System.Reflection.MethodInfo getAccessorInfo = ((System.Reflection.PropertyInfo) currentMemberInfo).GetGetMethod ();
k.Text = currentMemberInfo.Name;
object value = getAccessorInfo.Invoke (o, null);
if (typeof (IEnumerable).IsInstanceOfType (value) && !typeof (string).IsInstanceOfType (value)) {
foreach (object item in (IEnumerable) value) {
v.Text += item.ToString () + "<br />";
}
} else {
v.Text = value.ToString ();
}
r.Cells.AddRange (new TableCell[] { k, v });
outputTable.Rows.Add (r);
}
} catch { }
}
protected void Page_Load (object sender, EventArgs e) {
AuthMethod.Text = "Anonymous";
AuthUser.Text = "none";
//***** Authentication header type (Basic, Negotiate...etc)
string AUTH_TYPE = Request.ServerVariables["AUTH_TYPE"];
if (AUTH_TYPE.Length > 0) AuthMethod.Text = AUTH_TYPE;
//***** Authenticated user
string AUTH_USER = Request.ServerVariables["AUTH_USER"];
if (AUTH_USER.Length > 0) AuthUser.Text = AUTH_USER;
//***** If NEGOTIATE is used, assume KERBEROS is length of auth. header exceeds 1000 bytes
if (AuthMethod.Text == "Negotiate") {
string auth = Request.ServerVariables.Get ("HTTP_AUTHORIZATION");
if ((auth != null) && (auth.Length > 1000))
AuthMethod.Text = AuthMethod.Text + " (KERBEROS)";
else
AuthMethod.Text = AuthMethod.Text + " (NTLM)";
}
ThreadId.Text = System.Security.Principal.WindowsIdentity.GetCurrent ().Name;
//set the process identity in the corresponding label
dumpObject (System.Security.Principal.WindowsIdentity.GetCurrent (), tblProcessIdentity);
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection ("Server=labsql01;Database=master;Trusted_Connection=True;");
try {
con.Open ();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand ("select spid, uid, login_time, program_name, nt_domain, nt_username, loginame from sys.sysprocesses where spid = @@spid");
// System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select auth_scheme from sys.dm_exec_connections where session_id= @@spid");
cmd.Connection = con;
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter (cmd);
System.Data.DataTable dt = new System.Data.DataTable ();
da.Fill (dt);
TableRow r = new TableRow ();
TableCell k = new TableCell ();
TableCell v = new TableCell ();
k.Text = "SQL";
string sqlResponseBuilder = "";
if (dt.Rows.Count > 0) {
var count = dt.Rows[0].Table.Columns.Count;
for (int i = 0; i < count; i++) {
sqlResponseBuilder += "|| " + Convert.ToString (dt.Rows[0][i]);
}
}
v.Text = sqlResponseBuilder;
r.Cells.AddRange (new TableCell[] { k, v });
tblThreadIdentity.Rows.Add (r);
} catch (Exception ex) {
TableRow r = new TableRow ();
TableCell k = new TableCell ();
TableCell v = new TableCell ();
k.Text = "SQL";
v.Text = ex.Message;
r.Cells.AddRange (new TableCell[] { k, v });
tblThreadIdentity.Rows.Add (r);
}
//set the thread identity in the corresponding lable
dumpObject (System.Threading.Thread.CurrentPrincipal.Identity, tblThreadIdentity);
int loop1, loop2;
NameValueCollection coll;
// Load ServerVariable collection into NameValueCollection object.
coll = Request.ServerVariables;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++) {
TableRow r = new TableRow ();
TableCell k = new TableCell ();
TableCell v = new TableCell ();
k.Text = arr1[loop1];
String[] arr2 = coll.GetValues (arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++) {
v.Text = v.Text + Server.HtmlEncode (arr2[loop2]);
}
v.Text = Server.HtmlEncode (arr2[0]);
r.Cells.AddRange (new TableCell[] { k, v });
tblSrvVar.Rows.Add (r);
}
/*
IEnumerator en = Request.ServerVariables.Keys.GetEnumerator();
en.MoveNext();
foreach (string key in Request.ServerVariables.Keys)
{
TableRow r = new TableRow();
TableCell k = new TableCell();
TableCell v = new TableCell();
k.Text = key;
v.Text=Request.ServerVariables[key];
r.Cells.AddRange(new TableCell[] { k, v });
tblSrvVar.Rows.Add(r);
}*/
}
</script>
<html>
<body>
<font face="Verdana">
<center><H2>WHO Page</H2><br>
<table border=1>
<tr>
<td><img src="img1.gif"></td>
</tr>
</table>
</center>
<table border=1>
<tr><td>Authentication Method </td><td><b><asp:label id=AuthMethod runat=server/></b></td><td>Request.ServerVariables("AUTH_TYPE")</td></tr>
<tr><td>Identity </td><td><b><asp:label id=AuthUser runat=server /></b></td><td>Request.ServerVariables("AUTH_USER") or System.Threading.Thread.CurrentPrincipal.Identity</td></tr>
<tr><td>Windows identity </td><td> <b><asp:label id=ThreadId runat=server /></b></td><td>System.Security.Principal.WindowsIdentity.Getcurrent</td></tr>
</table>
<fieldset>
<label>Identity (System.Threading.Thread.CurrentPrincipal.Identity)</label>
<asp:Table ID="tblThreadIdentity" runat="server"></asp:Table>
</fieldset>
<fieldset>
<label>Windows Identity (System.Security.Principal.WindowsIdentity.GetCurrent)</label>
<asp:Table ID="tblProcessIdentity" runat="server"></asp:Table>
</fieldset>
Dump of server variables :
<br><br>
<asp:Table ID="tblSrvVar" runat="server"></asp:Table>
<form name="form1" method="POST" action="default.aspx">
Sample Form<br>
<input NAME="sometext" TYPE="Text" SIZE="24">
<input TYPE="submit" VALUE="Submit" NAME="SubmitForm" >
</form>
</font>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment