Windows上的sudo
2021-10-21 01:53:13 Author: mp.weixin.qq.com(查看原文) 阅读量:25 收藏

标题: Windows上的sudo

这不是一篇有效技术文档,完全是两个老年程序员回忆往事时的灌水之作。

有天张宇平微信给我发了个链接:

gsudo - a sudo for Windows
https://github.com/gerardog/gsudo
https://github.com/gerardog/gsudo/releases

$ gsudo.exe -h
gsudo v0.7.2
Copyright(c) 2019-2020 Gerardo Grignoli and GitHub contributors

Usage:
------
gsudo [options]                         Elevates your current shell
gsudo [options] {command} [args]        Runs {command} with elevated permissions
gsudo [-h | --help]                     Shows this help
gsudo [-v | --version]                  Shows gsudo version
gsudo cache [on | off | help]           Starts/Stops an elevated cache session. (reduced UAC popups)
gsudo config                            Show current config settings & values.
gsudo config {key} [--global] [value]   Read or write a user setting
gsudo config {key} [--global] --reset   Reset config to default value
gsudo status                            Show status about current user, security, integrity level or other gsudo relevant data.

General options:
 -n | --new             Starts the command in a new console (and returns immediately).
 -w | --wait            When in new console, force wait for the command to end.
 -s | --system          Run As Local System account ("NT AUTHORITY\SYSTEM").
 -i | --integrity {v}   Specify integrity level: Untrusted, Low, Medium, MediumPlus, High (default), System
 -k | --reset-timestamp Kills all cached credentials. The next time gsudo is run a UAC popup will be appear.
 --copyns               Connect network drives to the elevated user. Warning: Verbose, interactive asks for credentials

Other options:
 --loglevel {val}       Set minimum log level to display: All, Debug, Info, Warning, Error, None
 --debug                Enable debug mode.
 --piped                (deprecated) Set console mode to piped StdIn/Out/Err.
 --vt                   (deprecated) Set console mode to piped VT100 ConPty/PseudoConsole (experimental).
 --attached             (deprecated) Set console mode to attached.
 --copyev               (deprecated) Copy environment variables to the elevated process. (not needed on default console mode)

Learn more about security considerations of using gsudo at: https://bit.ly/gsudoSecurity

对"-s"参数有点兴趣。21世纪初有很多奇技淫巧获取SYSTEM权限,打开regedit,可以直接看SAM。自从"Session 0"出场后,我再没开过SYSTEM的regedit,一是没有这种刚需,二是相应技术方案各有各的不理想。psexec是不是必须安装个服务啊?随口一问,不研究这个方向很久了。

简单做些测试:

$ gsudo.exe -s cmd

#
 whoami
nt authority\system

#
 regedit.exe
# reg.exe query "HKLM\SAM\SAM\Domains\Account\Users\000001F4" /v "F"
# reg.exe query "HKLM\SAM\SAM\Domains\Account\Users\000001F4" /v "V"

或者

$ gsudo.exe -s cmd.exe /c regedit
$ gsudo.exe -s reg.exe query "HKLM\SAM\SAM\Domains\Account\Users\000001F4" /v "F"

若开出SYSTEM的regedit,Process Explorer的Integrity显示System,"User Name"显示"NT AUTHORITY\SYSTEM",可以查看SAM子键。

诡异的是,如下命令开SYSTEM的regedit,时灵时不灵:

$ gsudo.exe -s regedit.exe

所谓不灵是指,没有报错,但开出来的不是SYSTEM的regedit,无法查看SAM子键。应该是gsudo的BUG。有C#源码,懒得看,因为没有刚需。

张宇平给我这个链接,是人肉分布式备份的目的,他自己完全没有测试过,而我误以为他在向我推荐这个工具。不过,即使早知道他的动机,也有兴趣测试一下"-s"参数。

并不向诸君推荐使用gsudo,毕竟未做其他横向对比,只是告知。单就查看SAM子键这个伪需求而言,我甚至没有放狗,想必技术方案如过江之鲫。很多人未做广泛的横向对比,就敢张口"这是最啥啥"的,不要做这种人。

说些更远的题化话。基本不公开给别人推荐调试器、编辑器之类的工具,除非TA直接问到我头上,这是一个主观问题,每个人选用哪款有其不为外人所知的先验假设。

对于老年程序员,在某个方向上的历史经验当作茶余饭后的谈资或可一叙,当成别的什么向年轻人提及,多半是要被拍死在沙滩上。

说起《射雕英雄传》电视剧,不同年代的朋友有自己最爱的版本。人这一生,大概率觉得自己年轻时第一次接触的那个版本最好、最经典,之后的都差点意思甚至是在抹黑经典。这种现象是人性的具像化,此处不论是非,吾辈当一日三省,勿做界中人。

最后,喊一句口号,打倒一切人肉分布式备份的反革命份子!


文章来源: http://mp.weixin.qq.com/s?__biz=MzUzMjQyMDE3Ng==&mid=2247484529&idx=1&sn=5c7542e96fdc98ef8fd6513254a646ff&chksm=fab2c74ecdc54e58c42707de5bc944120c0d62c8e1174afc41278fa71501399a369773494580&mpshare=1&scene=24&srcid=0101jJjsZUvfQvyKIZu0jxRa&sharer_sharetime=1609476857232&sharer_shareid=5191b3dcb328f693d5261ba6bca8d267#rd
如有侵权请联系:admin#unsafe.sh