开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 532|回复: 8
收起左侧

[已解决] 求一个使用CreateProcessWithLogonW提权的源码

 关闭 [复制链接]
结帖率:67% (2/3)
发表于 2024-7-15 01:09:26 | 显示全部楼层 |阅读模式   四川省成都市
20精币
在域环境下,有管理员帐号和密码,求一个使用CreateProcessWithLogonW提权,可用的代码示例,相关API:
https://e.125.la/api-7800.html
https://e.125.la/datatype-385.html
https://e.125.la/datatype-355.html

最佳答案

查看完整内容

查了一下,发现这个创建外部程序还需要 LogonUserW等,你试一下运行外部程序 (“用户名”, “域名”, “密码”, 0, “C:\Windows\System32\cmd.exe”)看看。能行就行了,不能行我也没有办法

回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区 可获得加分喔。
友情提醒:本版被采纳的主题可在 申请荣誉值 页面申请荣誉值,获得 1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道:申请荣誉值无答案申请取消悬赏投诉有答案未采纳为最佳

签到天数: 9 天

发表于 2024-7-15 01:09:27 | 显示全部楼层   广东省广州市
myogoo 发表于 2024-7-15 14:14
你好,
我通过修改,指定用户名信息后:
运行外部程序 (“用户名”, “域名”, “密码”, #LOGON_WITH_PRO ...

查了一下,发现这个创建外部程序还需要 LogonUserW等,你试一下运行外部程序 (“用户名”, “域名”, “密码”, 0, “C:\Windows\System32\cmd.exe”)看看。能行就行了,不能行我也没有办法

评分

参与人数 1荣誉 +1 收起 理由
笨潴 + 1 热心帮助他人,荣誉+1,希望继续努力(*^__^*) 嘻嘻!

查看全部评分

回复

使用道具 举报

签到天数: 9 天

发表于 2024-7-15 09:18:36 | 显示全部楼层   广东省广州市
CreateProcessA用得比较多,这个还没有用过,但估计也是差不多

CreateProcessWithLogonW.e

955.37 KB, 下载次数: 13

回复

使用道具 举报

结帖率:67% (2/3)
 楼主| 发表于 2024-7-15 14:14:23 | 显示全部楼层   四川省成都市
baitso 发表于 2024-7-15 09:18
CreateProcessA用得比较多,这个还没有用过,但估计也是差不多

你好,
我通过修改,指定用户名信息后:
运行外部程序 (“用户名”, “域名”, “密码”, #LOGON_WITH_PROFILE, “C:\Windows\System32\cmd.exe”)
编译执行,系统中并没有以指定的用户名权限运行的cmd.exe进程出现,麻烦请再帮忙修改一下!
回复

使用道具 举报

结帖率:67% (2/3)
 楼主| 发表于 2024-7-15 20:46:40 | 显示全部楼层   四川省成都市
baitso 发表于 2024-7-15 16:19
查了一下,发现这个创建外部程序还需要 LogonUserW等,你试一下运行外部程序 (“用户名”, “域名”, “ ...

如果你懂C++,可以看看

// miniRunAs  -  A minimalist "run as" for Windows (a runas.exe alternative)
//
// Home page: www.source-code.biz/snippets/c/1.htm
// License: GNU/LGPL (www.gnu.org/licenses/lgpl.html)
// Copyright 2008 Christian d'Heureuse, Inventec Informatik AG, Switzerland.
// This software is provided "as is" without warranty of any kind.
//
// Version history:
// 2008-03-09 Christian d'Heureuse (chdh@inventec.ch)
//   Module created.
// 2011-07-05 Christian d'Heureuse (chdh@inventec.ch)
//   lpDomain parameter of CreateProcessWithLogonW changed from L"." to NULL.


#define UNICODE
#define _WIN32_WINNT 0x0500                                // Win2K and later
#include <stdio.h>
#include <Windows.h>

static const char*           programVersion = "2008-03-09";

static wchar_t               user[64];
static wchar_t               password[64];
static wchar_t               commandLine[1024];

static void displayHelp() {
   printf ("\n");
   printf ("miniRunAs  -  A minimalist \"run as\"\n");
   printf ("\n");
   printf ("Usage:   miniRunAs <user> <password> <commandline>\n");
   printf ("Example: miniRunAs administrator sesame ping localhost\n");
   printf ("Author:  Christian d'Heureuse, www.source-code.biz, chdh@inventec.ch\n");
   printf ("License: GNU/LGPL (www.gnu.org/licenses/lgpl.html)\n");
   printf ("Version: %s\n", programVersion); }

static void displayWin32ApiError (const char* routineName) {
   DWORD errorCode = GetLastError();
   wchar_t* msg = NULL;
   int i = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
         NULL, errorCode, 0, (LPWSTR)&msg, 0, NULL);
   if (i == 0) {
      fprintf (stderr, "FormatMessage failed for error code %i.\n", errorCode); return; }
   fwprintf (stderr, L"Error code %i returned from %S.\n%s\n", errorCode, routineName, msg);
   LocalFree (msg); }

static const wchar_t* skipBlanks (const wchar_t* s) {
   while (*s == L' ') s++;
   return s; }

static const wchar_t* skipNonBlanks (const wchar_t* s) {
   while (*s != 0 && *s != L' ') s++;
   return s; }

static const wchar_t* skipPastChar (const wchar_t* s, wchar_t c) {
   while (*s != 0) {
      if (*s == c) {s++; break; }
      s++; }
   return s; }

static const wchar_t* parseNextWord (const wchar_t* s, wchar_t* wBuf, int wBufSize) {
   const wchar_t* s1 = skipBlanks(s);
   const wchar_t* s2 = skipNonBlanks(s1);
   wcsncpy_s (wBuf, wBufSize, s1, s2-s1);
   return s2; }

static bool parseCommandLineParms() {
   const wchar_t* s = GetCommandLine();
   s = skipBlanks(s);
   if (*s == L'"')
      s = skipPastChar(s+1, L'"');                         // if the commandline starts with a quote, we have to skip past the next quote
    else
      s = skipNonBlanks(s);                                // otherwise the program path does not contain blanks and we skip to the next blank
   s = skipBlanks(s);
   if (*s == 0) {                                          // no command-line parameters
      displayHelp();
      return false; }
   s = parseNextWord(s, user, sizeof(user)/2);
   s = parseNextWord(s, password, sizeof(password)/2);
   s = skipBlanks(s);
   wcscpy_s (commandLine, s);
   if (commandLine[0] == 0) {
      fprintf (stderr, "Missing command-line arguments.\n");
      return false; }
   return true; }

int main() {
   if (!parseCommandLineParms()) return 9;
   STARTUPINFOW si;
   memset (&si, 0, sizeof(si));
   si.cb = sizeof(si);
   PROCESS_INFORMATION pi;
   BOOL ok = CreateProcessWithLogonW (
      user,
      NULL,                                                // change to L"." to use local account database only
      password,
      LOGON_WITH_PROFILE,
      NULL,
      commandLine,
      0,
      NULL,
      NULL,
      &si,
      &pi);
   if (ok == 0) {
      displayWin32ApiError ("CreateProcessWithLogonW");
      return 9; }
   return 0; }
回复

使用道具 举报

签到天数: 9 天

发表于 2024-7-15 21:58:29 | 显示全部楼层   广东省广州市
运行外部程序 (“用户名”, “.”, “密码”, #LOGON_WITH_PROFILE, “C:\Windows\System32\cmd.exe”)  我这样是正常的
回复

使用道具 举报

签到天数: 9 天

发表于 2024-7-15 22:01:20 | 显示全部楼层   广东省广州市
特意建了一个帐号试了
1.jpg
回复

使用道具 举报

结帖率:67% (2/3)
 楼主| 发表于 2024-7-16 00:31:15 | 显示全部楼层   四川省成都市
baitso 发表于 2024-7-15 22:01
特意建了一个帐号试了

你好,我也测试成功了,但之前不确实是哪弄错,导致以为没有运行起来,能否完善下displayWin32ApiError,方便排错,谢谢!
回复

使用道具 举报

结帖率:67% (2/3)
 楼主| 发表于 2024-7-16 09:04:21 | 显示全部楼层   四川省成都市
myogoo 发表于 2024-7-16 00:31
你好,我也测试成功了,但之前不确实是哪弄错,导致以为没有运行起来,能否完善下displayWin32ApiError, ...

lpCommandLine是我写错了吗,参数不生效,有个文档,C:\test.txt,文档中有内容,把它做为参数,在CMD下使用notepad.exe C:\test.txt是可以正常打开的,但在API内不行,我参数是这样写的
编码_ASCII到Unicode ("C:\test.txt")
lpApplicationName写的是
编码_ASCII到Unicode ("C:\Windows\notepad.exe")
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
网站简介:精易论坛成立于2009年,是一个程序设计学习交流技术论坛,隶属于揭阳市揭东区精易科技有限公司所有。
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表