java的windows脱机,Win32 API LogonUser对本地帐户的脱机访问

2023-11-09

是否有一系列标志允许 LogonUser 在计算机未连接到网络时返回可用于冒充本地用户的令牌(但所有帐户已在本地存在) .

我有域帐户执行应用程序

MYDOMAIN \ FooUser

而我正试图获得一个假冒令牌

MYLAPTOP \ TestUser

然后我读了一个文件夹中的一系列文本文件,这些文件都可以被 FooUser 读取,但有些文件文件的 TestUser 读取权限被拒绝了 .

如果我登录到Windows并从 TestUser 运行应用程序,则权限映射正确,并且文件上的权限被拒绝 . 如果我已连接到我的域并从 FooUser 运行应用程序,我还可以模拟 TestUser 和文件权限再次正确拒绝访问(使用 LOGON32_LOGON_INTERACTIVE ) .

当我的以太网电缆被拔出并且我尝试为 TestUser 调用 LogonUser 时会出现问题,我希望我能以某种方式验证本地凭据......本地?

使用 LOGON32_LOGON_INTERACTIVE :

输入 TestUser 的凭据将返回错误,指示"Bad username or password"

输入 FooUser 的凭据返回错误,指示"No logon servers available"(有道理,我不是在抱怨......除非我没有连接到我的域时如何首先登录Windows?)

使用 LOGON32_LOGON_NEW_CREDENTIALS :

输入乱码凭据会返回一个与 FooUser 具有相同访问权限的令牌

using System;

using System.ComponentModel;

using System.Runtime.InteropServices;

using System.Security;

using System.Security.Principal;

using Common.NativeMethods.Enumerations;

namespace Common.NativeMethods

{

public static class AdvApi32

{

// http://www.pinvoke.net/default.aspx/advapi32.logonuser

// http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.securestringtoglobalallocunicode(v=vs.100).aspx

// PInvoke into the Win32 API to provide access to the

// LogonUser and CloseHandle functions.

[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]

internal static extern bool LogonUser(

IntPtr username,

IntPtr domain,

IntPtr password,

LogonType logonType,

LogonProvider logonProvider,

ref IntPtr token

);

public static WindowsIdentity LogonUser(SecureString p_userName, SecureString p_password, SecureString p_domainName)

{

IntPtr UserAccountToken = IntPtr.Zero;

IntPtr UserNamePointer = IntPtr.Zero;

IntPtr PasswordPointer = IntPtr.Zero;

IntPtr DomainNamePointer = IntPtr.Zero;

try

{

// Marshal the SecureString to unmanaged memory.

UserNamePointer = Marshal.SecureStringToGlobalAllocUnicode(p_password);

PasswordPointer = Marshal.SecureStringToGlobalAllocUnicode(p_userName);

DomainNamePointer = Marshal.SecureStringToGlobalAllocUnicode(p_domainName);

// Call LogonUser, passing the unmanaged (and decrypted) copy of the SecureString password.

bool ReturnValue =

AdvApi32

.LogonUser(

UserNamePointer,

DomainNamePointer,

PasswordPointer,

LogonType.LOGON32_LOGON_INTERACTIVE, //.LOGON32_LOGON_NEW_CREDENTIALS,

LogonProvider.LOGON32_PROVIDER_DEFAULT, //.LOGON32_PROVIDER_WINNT50,

ref UserAccountToken);

// Get the Last win32 Error and throw an exception.

if (!ReturnValue && UserAccountToken == IntPtr.Zero)

{

int error = Marshal.GetLastWin32Error();

throw

new Win32Exception(error);

}

// The token that is passed to the following constructor must

// be a primary token in order to use it for impersonation.

return

new WindowsIdentity(UserAccountToken);

}

finally

{

// Zero-out and free the unmanaged string reference.

Marshal.ZeroFreeGlobalAllocUnicode(UserNamePointer);

Marshal.ZeroFreeGlobalAllocUnicode(PasswordPointer);

Marshal.ZeroFreeGlobalAllocUnicode(DomainNamePointer);

// Close the token handle.

Kernel32.CloseHandle(UserAccountToken);

}

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Runtime.InteropServices;

using System.Runtime.ConstrainedExecution;

using System.Security;

namespace Common.NativeMethods

{

// http://msdn.microsoft.com/en-us/library/system.security.principal.windowsimpersonationcontext%28v=vs.100%29.aspx

public static class Kernel32

{

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]

[SuppressUnmanagedCodeSecurity]

[return: MarshalAs(UnmanagedType.Bool)]

internal extern static bool CloseHandle(IntPtr handle);

}

}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

java的windows脱机,Win32 API LogonUser对本地帐户的脱机访问 的相关文章

  • Python + Jenkins + Selenium-Grid实现分布式web-ui自动化测试(centos+win10为例)

    简介 Selenium分布式运行 SeleniumGrid 环境配置 jenkins win10 ip 100 100 100 101 selenium hub win10 ip 100 100 100 101 selenium node1
  • R语言—数组

    文章目录 数组 数组的生成 array 使用dim函数生成数组 多维数组的子集操作 数组 向量是1维数组 矩阵是二维数组 数组的维数可以大于2 数组的生成 array 格式 数组名 lt array 数组元素 dim c 第一下标个数 第二
  • 桂林电子科技大学校园网自动登录

    桂电的校园网自动登录十分十分十分简单 1 原理 懒得说原理 2 步骤 网上有 3 结论和方法 1 结论 直接访问特定的url就能登录了 这里给出校园网登录的和联通的url 校园网url http 10 0 1 5 drcom login c
  • 【源码+文档】数据库设计医药销售管理系统之Java

    开发环境和开发工具 操作系统 win8 1 开发环境 Mysql Web 开发工具 Workbench Eclipse JDBC 功能需求分析 员工有权查看 添加会员 查看 添加供应商 查询药品 输入药品编号或名称 类别等查询该药品或该类药
  • 【Spring Boot 源码学习】深入 FilteringSpringBootCondition

    Spring Boot 源码学习系列 深入 FilteringSpringBootCondition 引言 往期内容 主要内容 1 match 方法 2 ClassNameFilter 枚举类 3 filter 方法 总结 引言 前两篇博文
  • UCENTER简单使用 GVINS配置C-RTK9P

    首先去 https www u blox com en product u center 下载ucenter 把C RTK9P通过USB连接到电脑 在Tool gt Receiver Configuration 里面 选好你要更改到RTK里
  • Qt之QGraphicsView实战篇

    前言 前面的章节介绍了 Graphics View 绘图架构 终于到实战了 真的是千呼万唤始出来 这一章节就用 Graphics View 绘图架构来做一个绘图工具 实现一些基础图形的绘制 废话不多说先来看一下结果演示 本文福利 莬费领取Q
  • c语言指针用法及实际应用详解,通俗易懂超详细!

    大家好 我是无际 今天给大家来讲解一下指针 我会由浅到深 最后结合实际应用讲解 让大家学会指针的同时 知道大佬们都用指针来干嘛 长文预警 全文大约5200多字 学指针看这篇文章就够了 很多人跟我刚学习c语言一样 都害怕指针 我也是后面做了一
  • 【2021最新版】Java多线程&并发面试题总结(108道题含答案解析)

    文章目录 JAVA并发知识库 1 Java中实现多线程有几种方法 2 继承Thread类 3 实现Runnable接口 4 ExecutorService Callable Future有返回值线程 5 基于线程池的方式 6 4 种线程池
  • mips-openwrt交叉编译 undefined reference to `__stack_chk_guard 错误

    最近在mips openwrt的工具链中交叉编译可执行程序时 出现了以下的错误 undefined reference to stack chk guard undefined reference to stack chk fail 百度一
  • CUDA编程 之 二进制工具与反编译

    两个 反编译工具 cuobjdump and nvdisasm 参考 http blog csdn net dark5669 article details 62264312
  • python中的copy和deepcopy

    数据处理经常会用到引用或者赋值 Python中的可变类型变量在操作时需要注意拷贝的方式 特别在实现复杂功能的函数时 一不小心就会改变原来的数据内容 data name anne age 18 scores 语文 130 数学 150 英语
  • CUDA和cuDNN各版本下载及版本对应关系

    CUDA和cnDNN是支持NVIDIA支持GPU的两个库 分别用于高性能计算和深度神经网络计算的支持 CUDA Compute Unified Device Architecture 是NVIDIA支持GPU的通用并行计算架构 该架构使GP
  • Python中常用的处理数据的方法——replace()方法

    replace 方法 描述 Python replace 方法用于把字符串中指定的旧子字符串替换成指定的新子字符串 如果指定 count 可选参数则替换指定的次数 默认全部替换 replace 方法语法 S replace old new
  • R包安装记录

    因为重复安装会引起某些问题以及冲突 已安装 library pheatmap 热图包 library corrplot 热图包 library Hmisc library dplyr
  • 一起学大数据|最详细的大数据学习资源教程,呕心沥血全部分享

    跟大家已经分享了这么长时间的大数据文章了 我们的一起来学大数据系列已经将Java和Linux全部做了一次基础的分享 今天 我把我整理的全套大数据资源分享给大家 一起共同学习 记得关注呦 很多初学者 对大数据的概念都是模糊不清的 大数据是什么
  • 常用设计模式-观察者模式

    观察者模式定义对象间的一种一对多的依赖关系 当一个对象的状态发生改变时 所有依赖于它的对象都得到通知并被自动更新 它还有两个别名 依赖 Dependents 发布 订阅 Publish Subsrcibe 当观察者观察到事件到来之后 通知对
  • hive —— 分区表

    hive 分区表 为了对表进行合理的管理以及提高查询效率 Hive可以将表组织成 分区 一个分区实际上就是表下的一个目录 一个表可以在多个维度上进行分区 分区之间的关系就是目录树的关系 通过PARTITIONED BY子句指定 分区的顺序决
  • zookeeper集群搭建

    一 安装zookeeper Zookeeper的下载地址http mirror bit edu cn apache zookeeper zookeeper 3 4 10 zookeeper集群需要java环境支持 所以要提前安装好JDK 在

随机推荐