惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
博客园 - 【当耐特】
量子位
博客园 - 叶小钗
有赞技术团队
有赞技术团队
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
博客园 - 司徒正美
爱范儿
爱范儿
美团技术团队
小众软件
小众软件
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
罗磊的独立博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
I
InfoQ
D
DataBreaches.Net
宝玉的分享
宝玉的分享

Posts on Noah Bailey

How to turn anything into a router Deploy to Cloudfront from GitHub using OpenID Connect Backup Postgres databases with Kubernetes CronJobs The spelling error made 200 billion times a day Restarting Kubernetes pods using a CronJob You've just bought a new domain. Now what? Who Sawed My Motherboard??? Linux on the P8 Aliexpress Mini Laptop Recovering Mysql/Mariadb after a nasty crash Using EXIF data to pick my next lens Converting and developing RAW photos on Linux automatically Thank you, 2016 iPhone Don't Make It Work Self-hosted Surveillance with ZoneMinder Backups, Monitoring, and Security for small Mastodon servers Block web scanners with ipset & iptables Executing commands over SSH with GitHub Actions Debian Sid on encrypted ZFS Protect your dangerously insecure redis server Debian: the luxurious boring lifestyle Monitor radiation with a Raspberry Pi Simple Linux server alerts: Know your performance, errors, security, syslog, and security NUC crashes on debian 11 - How I fixed it Basic Linux server security with fail2ban, ossec, and firewall Windows 11 will create heaps of needless trash Domesticated Kubernetes Networking The Cursed Certificate Our mostly disposable and entirely stupid world Trying out OpenBSD (as a Linux geek) Making VoIP Calls with Antique Rotary Phones
Stealing Windows Sessions
2019-02-02 · via Posts on Noah Bailey

Editor’s note (2021-01): This particular hacking method no longer works after 2019-11 windows update. I had this article on ice for a very long time and feel confident that it won’t be abused at this time.

Preface

I feel like I shouldn’t have to say this, but please use your powers for good and not evil. The methods I’ll reveal here have quite impressive post-exploit abilities for lateral movement. If you’re thinking about getting arrested for something dumb, please don’t bring up my website at your trial. I don’t like lawyers very much (no offense lawyers).

This is an interesting technique where a priviledged user on a Windows system can take control of other user’s sessions. To be clear, this is not a vulnerability or exploit for the following reasons:

  • Requires elevated priviledges
  • Requires physical access to the system, or a sophisticated remote access toolkit

Either way, it’s a fun way to learn more about the inner workings of Windows, and how to use and abuse it’s quirks and features.

The Windows Display Manager

Before we get too far ahead of ourselves, let’s start with what the Windows DM is and briefly how it works. This is a quick rundown at best; if you’re looking for full blown documentation you’ll want to get a job at Microsoft. Or read Mark Russonivich’s book, that might be the closest you’ll get…

There are three primary components of the Windows Display Manager that you should know about. For more information about these, go visit the the Windows Performance Team on Technet.

  • Desktops
    • Contains userspace processes, applications, runtimes, and background tasks
    • Generally one desktop per user, though that can be changed in more recent versions.
  • Sessions
    • Sessions >0 act as containers for userspace desktops
    • Session 0 contains interactive services, usermode drivers, and other vestigial leftovers from the pre-vista age. In most recent versions of Windows it is locked away, difficult to tamper with, and isolated in many ways from sensitive processes.
  • Window Stations
    • Represent connections to a session. Most commonly this is the physical keyboard, mouse, and monitor attached to a PC, however it can also represent RDP connections.

Inspecting Sessions

The first part of the puzzle is figuring out which session contains useful information. There are generally two things to look for, processes and user accounts. From here on out, Admin access is needed to do anything useful.

Users

Getting a list of logged in users is quite simple, and probably familiar to most admins:

net session 

Put a screenshot here?

Then, compare that to the list of window stations active:

qwinsta

Another one here?

Processes

Getting a process list is also quite straightforward. It requires an administrative powershell session:

Get-Process *[filter-keyword]* -IncludeUserName

Once a valuable session has been found, a priviledged user can then take control of the Display Manager to seize that session.

Switching Sessions

Because of the heavily ACL-integrated nature of the NT operating system, all objects including sessions and desktops have a set of securables. In most cases, the “owner” of a desktop is the user that created it with all other users having no access at all, other than being able to see that it exists (think about the login screen, that’s a desktop too!).

Fortunately, as with most securables, the NT AUTHORITY\SYSTEM account has full access to desktops and sessions. And this makes sense, since the operating system itself needs a way to manipulate the session manager to allow non-logged-in users to start their own sessions. However, it also means that those with more nefarious intent can seize control of sessions by elevating to SYSTEM level.

With both methods, it is required to already have a shell as Administrator; the difference is in the tools used.

Method 1: PSEXEC

This method requires the ability to download and run executables. In many cases this is not possible (for good reason), but most of the time it works just fine.

First, using the methods above locate the target session.

Then, execute tscon as system to link the target session ID to the console window station:

.\psexec.exe -s tscon /dest:CONSOLE <ID>

Within a second, the display will blank then connect to the target session. Easy!

Method 2: Scheduled Tasks

This method requires no additional binaries! Just register a scheduled task on the sytem that will trigger a tscon operation. For extra sneak factor, this task can be buried deep in the library with an inconspicuous name… Think “xbox-service-updater” or something along those lines.

schtasks.exe /create /tn sessionswap /ru "SYSTEM" /Z /tr "tscon" "/dest:CONSOLE <ID>"

schtasks.exe /run /tn sessionswap

Method 3: Service Manager

This method is my favourite, simply for the absurdity of it. There’s something delightful about creating a service that will immediately crash and land you in somebody else’s desktop. Of all these methonds, this is the least likely to work in the future, as Microsoft is actively working on securing the service control manager, and increasing the auditing ability of the system to detect tampering with services. So don’t try this if you don’t want to get caught… Hypothetically of course.

sc create sessionswap type= own type= interact start= demand binpath= C:\Windows\System32\tscon.exe /dest:CONSOLE <ID>

sc start sessionswap

Depending on the log level of the system, this service exiting will likely leave warn or error messages in the system event log.

Conclusion

With a bit of tinkering and poking, one can fairly easily traverse logged on sessions on a Windows PC or Server. If nothing else, this highlights the need to physically secure any endpoints, and secure the virtual console of any virtual machines. Though it may be possile to accomplish the same thing over RDP, I have not been able to do so (And of course please tell me if you can!).

And most importantly, always remember that admin=full control. It’s trivial to elevate to system, especially for a single task. If nothing else, this highlights the importance of the “Principal of Least Priviledge” approach to delegation.

Happy hacking!